Parallel Programming - Trivial
[matches/honours.git] / course / semester2 / pprog / assignment1 / single-thread / graphics.c
index e3722e9..7a7d213 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "graphics.h" //Function declarations
 #include "nbody.h" //The simulation
+#include <GL/freeglut.h>
 
 // --- Variable definitions --- //
 double previousTime, eyeTheta, eyePhi, eyeRho;
@@ -106,40 +107,20 @@ void Graphics_Run(int argc, char ** argv)
  */
 void Graphics_Display() 
 {
-
-
-       if (options.verbosity != 0 && universe.steps % options.verbosity == 1)
-               DisplayStatistics();
+       //Check whether the program should quit due to steps being computed, or a timeout
+       if (ExitCondition())
+       {
+               //printf("Leave graphics loop\n");
+               glutLeaveMainLoop();    
+               return;
+       }
 
        #ifdef SINGLE_THREADED
+               if (options.verbosity != 0 && universe.steps % options.verbosity == 1)
+                       DisplayStatistics();
                System_Compute(&universe);
-
-               //Check whether the program should quit due to steps being computed, or a timeout
-               if (options.timeout > 0.0)
-               {
-                       if ((unsigned)(time(NULL) - options.start_time.tv_sec) >= options.timeout)
-                               exit(EXIT_SUCCESS);
-               }
-               if (options.num_steps > 0 && universe.steps > options.num_steps)
-                       exit(EXIT_SUCCESS);
-
-
        #endif
 
-
-       //Check whether the runstate has been set to quit the program
-       switch (runstate)
-       {
-               case RUN:
-                       break;
-               case QUIT:
-                       exit(EXIT_SUCCESS);
-                       break;
-               case QUIT_ERROR:
-                       exit(EXIT_FAILURE);
-                       break;
-       }
-
        if (options.draw_graphics == false)
                return;
        
@@ -172,7 +153,8 @@ void Graphics_Keyboard(unsigned char theKey, int mouseX, int mouseY)
 {
        if (theKey == 'x' || theKey == 'X') 
        {
-               exit(EXIT_SUCCESS);
+               QuitProgram(false);
+               return;
        }
 
                if (theKey == 'i' || theKey == 'I') {

UCC git Repository :: git.ucc.asn.au