From: Brendan Hansen Date: Fri, 23 Oct 2020 22:25:22 +0000 (-0500) Subject: small refactor X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=edee62485fde4ec28da2a682ce558d8f2f89204c;p=csc718.git small refactor --- diff --git a/src/sim.cpp b/src/sim.cpp index c0fb768..19de0be 100644 --- a/src/sim.cpp +++ b/src/sim.cpp @@ -149,6 +149,24 @@ struct SimState Array 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 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(); - // NOTE(Brendan): Need to initialize the array since it does not get constructed because I refuse to use the 'new' keyword. alloc 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);