small refactor
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 23 Oct 2020 22:25:22 +0000 (17:25 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 23 Oct 2020 22:25:22 +0000 (17:25 -0500)
src/sim.cpp

index c0fb768697d8d43cdcfda116ae191f8aab2aca3e..19de0be9f5ab96452ea792a8fabeffb6c20fcbe7 100644 (file)
@@ -149,6 +149,24 @@ struct SimState
     Array<Body> bodies;
 };
 
+internal void
+sim_state_init(SimState* state)
+{
+    // NOTE(Brendan): Need to initialize the array since it does not get constructed because I refuse to use the 'new' keyword. alloc<T> uses malloc under the hood and cannot initialize the result.
+    state->bodies.init();
+    state->bodies.ensure_capacity(1024);
+    
+    foreach (i, 0, 1024)
+    {
+        Body tmp_body;
+        tmp_body.pos = V2f{ randf(0, 800), randf(0, 800) };
+        tmp_body.vel = V2f{ randf(-50.0f, 50.0f), randf(-50.0f, 50.0f) };
+        tmp_body.mass = randf(2.0f, 10.0f);
+        tmp_body.color_idx = rand() % 4;
+        state->bodies.push(tmp_body);
+    }
+}
+
 
 
 #define CIRCLE_POINT_COUNT 36 // NOTE(Brendan): Treat a circle as a many-sided polygon.
@@ -290,19 +308,7 @@ main(i32 argc, char* argv[])
     glUniform4fv(planet_colors_loc, 4, planet_colors);
     
     auto state = alloc<SimState>();
-    // NOTE(Brendan): Need to initialize the array since it does not get constructed because I refuse to use the 'new' keyword. alloc<T> uses malloc under the hood and cannot initialize the result.
-    state->bodies.init();
-    state->bodies.ensure_capacity(1024);
-    
-    foreach (i, 0, 1024)
-    {
-        Body tmp_body;
-        tmp_body.pos = V2f{ randf(0, 800), randf(0, 800) };
-        tmp_body.vel = V2f{ randf(-50.0f, 50.0f), randf(-50.0f, 50.0f) };
-        tmp_body.mass = randf(2.0f, 10.0f);
-        tmp_body.color_idx = rand() % 4;
-        state->bodies.push(tmp_body);
-    }
+    sim_state_init(state);
     
     {
         glBindVertexArray(circle_mesh);