#define WINDOW_TITLE "N-Body Simulation"
// :ArbitraryConstant
-#define PARTICLE_COUNT 3000
+#define PARTICLE_COUNT 2500
// :ArbitraryConstant
-#define NUM_THREADS 2
+#define NUM_THREADS 4
// TODO(Brendan): Maybe this can be removed because it isn't really necessary?
internal void
pthread_barrier_wait(&thread_sync_barrier);
update_bodies_partial(state, thread_id + 1);
pthread_barrier_wait(&thread_sync_barrier);
+ if (thread_id == 0)
+ {
+ state->qt_bodies.init(AABB { -2000, -2000, 4000, 4000 });
+ state->qt_body_allocator.reset();
+ For (state->bodies) state->qt_bodies.insert(&it, &state->qt_body_allocator);
+ }
pthread_barrier_wait(&thread_sync_barrier);
}
foreach (i, 0, PARTICLE_COUNT)
{
Body tmp_body;
- tmp_body.pos = V2f{ randf(0, 1200), randf(0, 1200) };
+ tmp_body.pos = V2f{ randf(-1000, 1000), randf(-1000, 1000) };
tmp_body.vel = V2f{ 0.0f, 0.0f };
tmp_body.mass = randf(3.0f, 6.0f);
tmp_body.body_type = static_cast<BodyType> ((rand() % 4));
}
state->qt_body_allocator.init(PARTICLE_COUNT);
+ state->qt_bodies.init(AABB { -2000, -2000, 4000, 4000 });
state->camera.scale = 1.0f;
if (glfwGetKey(window, GLFW_KEY_DOWN)) state->camera.offset.y += camera_move_speed;
if (glfwGetKey(window, GLFW_KEY_LEFT)) state->camera.offset.x -= camera_move_speed;
if (glfwGetKey(window, GLFW_KEY_RIGHT)) state->camera.offset.x += camera_move_speed;
- if (glfwGetKey(window, GLFW_KEY_Q)) state->camera.scale *= 1.01f;
- if (glfwGetKey(window, GLFW_KEY_A)) state->camera.scale /= 1.01f;
+ if (glfwGetKey(window, GLFW_KEY_Q)) state->camera.scale *= 1.02f;
+ if (glfwGetKey(window, GLFW_KEY_A)) state->camera.scale /= 1.02f;
- state->qt_bodies.init(AABB { -2000, -2000, 4000, 4000 });
- state->qt_body_allocator.reset();
- For (state->bodies) state->qt_bodies.insert(&it, &state->qt_body_allocator);
pthread_barrier_wait(&thread_sync_barrier);
update_bodies_partial(state, 0);