code cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Dec 2020 20:26:14 +0000 (14:26 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Dec 2020 20:26:14 +0000 (14:26 -0600)
sim_omp
sim_seq
src/sim.cpp
src/sim_omp.cpp
src/sim_seq.cpp

diff --git a/sim_omp b/sim_omp
index 1d898823040defda7527b1e66c8c118d141af414..ccfe3f2a3cee400129d335fbc6600baa1678efad 100755 (executable)
Binary files a/sim_omp and b/sim_omp differ
diff --git a/sim_seq b/sim_seq
index b5823647c292d3ba5113972e9701df11c1e81a83..f088541cb20ba3f1bf513df865e5fdd6204be46b 100755 (executable)
Binary files a/sim_seq and b/sim_seq differ
index 0803ca3488081f07ba55e5afe0073822d6e3fc90..c4d5ecc0d95c7639d66321f5973b6af495454e08 100644 (file)
@@ -299,7 +299,6 @@ loop(SimState* state)
 
     f64 frame_delta = 0.0;
     i32 frame_count = 0;
-    clock_t total_clock_delta = 0;
 
     while (!glfwWindowShouldClose(window))
     {
@@ -307,10 +306,7 @@ loop(SimState* state)
         delta = curr_time - last_time;
         last_time = curr_time;
 
-        clock_t before_update = clock();
         update(state, delta);
-        clock_t after_update = clock();
-        total_clock_delta += (after_update - before_update);
 
         frame_count += 1;
         draw(state);
@@ -318,7 +314,6 @@ loop(SimState* state)
         frame_delta += delta;
         if (frame_delta >= 1.0)
         {
-            total_clock_delta = 0;
             frame_delta -= 1.0;
             frame_rate = frame_count;
             frame_count = 0;
index b09fbeed7a214fa795ea8b692ecd8949f0ebcb7e..8bd1a7cb8dfdab86c298f3887adc22f5981dd5a1 100644 (file)
@@ -143,9 +143,6 @@ struct SimState
     Camera camera;
 };
 
-// @CLEANUP
-internal f64 TEMP_dt = 0;
-
 internal void
 sim_state_init(SimState* state)
 {
@@ -227,21 +224,18 @@ loop(SimState* state)
 
     f64 frame_delta = 0.0;
     i32 frame_count = 0;
-    clock_t total_clock_delta = 0;
-    clock_t before_update, after_update;
 
     #pragma omp parallel
     {
         while (!glfwWindowShouldClose(window))
         {
+            // NOTE(Brendan): Compute the delta time and update camera variables.
             #pragma omp master
             {
                 curr_time = glfwGetTime();
                 delta = curr_time - last_time;
                 last_time = curr_time;
 
-                before_update = clock();
-
                 glfwGetWindowSize(window, &state->camera.window_width, &state->camera.window_height);
 
                 persist const f32 camera_move_speed = 6;
@@ -251,30 +245,27 @@ loop(SimState* state)
                 if (glfwGetKey(window, GLFW_KEY_RIGHT)) state->camera.offset.x += camera_move_speed;
                 if (glfwGetKey(window, GLFW_KEY_Q))     state->camera.scale *= 1.02f;
                 if (glfwGetKey(window, GLFW_KEY_A))     state->camera.scale /= 1.02f;
-
-                TEMP_dt = delta;
             }
 
+            // NOTE(Brendan): Calculate how each body will move.
             #pragma omp for
             for (int i = 0; i < global_settings.body_count; i++)
-                body_accumulate_move(&state->bodies[i], &state->qt_bodies, TEMP_dt);
+                body_accumulate_move(&state->bodies[i], &state->qt_bodies, delta);
 
+            // NOTE(Brendan): Move each of the bodies.
             #pragma omp for
             for (int i = 0; i < global_settings.body_count; i++)
-                body_apply_move(&state->bodies[i], TEMP_dt);
+                body_apply_move(&state->bodies[i], delta);
 
+            // NOTE(Brendan): Draw the scene.
             #pragma omp master
             {
-                after_update = clock();
-                total_clock_delta += (after_update - before_update);
-
                 frame_count += 1;
                 draw(state);
 
                 frame_delta += delta;
                 if (frame_delta >= 1.0)
                 {
-                    total_clock_delta = 0;
                     frame_delta -= 1.0;
                     frame_rate = frame_count;
                     frame_count = 0;
@@ -283,6 +274,7 @@ loop(SimState* state)
                 glfwPollEvents();
             }
 
+            // NOTE(Brendan): One of the threads recompute the Quad Tree.
             #pragma omp single
             {
                 state->qt_bodies.init(AABB { -2000, -2000, 4000, 4000 });
index 37f3e494b8f06531d6937aa1cb5469d42fb905a2..abc51ba5624e5bea089c810c6de8dd5452912936 100644 (file)
@@ -258,7 +258,6 @@ loop(SimState* state)
 
     f64 frame_delta = 0.0;
     i32 frame_count = 0;
-    clock_t total_clock_delta = 0;
 
     while (!glfwWindowShouldClose(window))
     {
@@ -266,10 +265,7 @@ loop(SimState* state)
         delta = curr_time - last_time;
         last_time = curr_time;
 
-        clock_t before_update = clock();
         update(state, delta);
-        clock_t after_update = clock();
-        total_clock_delta += (after_update - before_update);
 
         frame_count += 1;
         draw(state);
@@ -277,7 +273,6 @@ loop(SimState* state)
         frame_delta += delta;
         if (frame_delta >= 1.0)
         {
-            total_clock_delta = 0;
             frame_delta -= 1.0;
             frame_rate = frame_count;
             frame_count = 0;