X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fsingle-thread%2Fgraphics.c;h=864ff915fe1a19e6c95cf62352cce71e93b264f2;hb=83cf58f62ddc5ce9fe44de27327fde27f767ebb6;hp=7a7d21341e765e130a09f6900e5ecd71f6922bad;hpb=19e590cc4f7dbc186cad9418bf5a2321bfa3fe1a;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/single-thread/graphics.c b/course/semester2/pprog/assignment1/single-thread/graphics.c index 7a7d2134..864ff915 100644 --- a/course/semester2/pprog/assignment1/single-thread/graphics.c +++ b/course/semester2/pprog/assignment1/single-thread/graphics.c @@ -33,10 +33,9 @@ void Graphics_Run(int argc, char ** argv) { if (options.draw_graphics == false) { - while (true) - Graphics_Display(); - - return; + // This message is left here for when I inevitably accidentally call the function + fprintf(stderr, "Graphics_Run should not be called if graphics are disabled!\n"); + exit(EXIT_FAILURE); } glutInit(&argc, argv); @@ -107,23 +106,20 @@ void Graphics_Run(int argc, char ** argv) */ void Graphics_Display() { - //Check whether the program should quit due to steps being computed, or a timeout - if (ExitCondition()) + + if (options.draw_graphics == false) { - //printf("Leave graphics loop\n"); - glutLeaveMainLoop(); - return; + // This message is left here for when I inevitably accidentally call the function + fprintf(stderr, "Graphics_Display should not be called if graphics are disabled!\n"); + exit(EXIT_FAILURE); } - #ifdef SINGLE_THREADED - if (options.verbosity != 0 && universe.steps % options.verbosity == 1) - DisplayStatistics(); - System_Compute(&universe); - #endif - - if (options.draw_graphics == false) + //Check whether the graphics thread should exit for any reason + if (ExitCondition()) + { + glutLeaveMainLoop(); // original glut does not have this, which makes "nicely" exiting a bit annoying return; - + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); @@ -131,6 +127,11 @@ void Graphics_Display() gluLookAt(eyeRho * sin(eyePhi) * sin(eyeTheta), eyeRho * cos(eyePhi), eyeRho * sin(eyePhi) * cos(eyeTheta),look[0], look[1], look[2], 0, upY, 0); + BeforeDraw(); // Stuff to do before graphics is allowed to draw + // Single-thread - perform a computation step, obviously! It's not done anywhere else + // Multiple threads - ensure that all body positions are updated (ie: not halfway through step). + // (We don't care about the force and velocity variables though) + for (int i = 0; i < universe.N; ++i) { Body * b = universe.body+i; @@ -141,6 +142,11 @@ void Graphics_Display() glPopMatrix(); // restore the previous matrix } glFlush(); + + AfterDraw(); // Stuff to do after graphics is done drawing + // Single-thread - Nothing at all + // Multiple threads - signal threads it is safe to change position variables + } /**