return false;
}
- void query(AABB r, Array<T*>& point_list) const // NOTE(Brendan): By reference may be a terrible idea here.
+ void query(AABB r, Array<T*>* point_list) const
{
if (!region.intersects(r)) return;
foreach (i, 0, point_count)
- if (r.contains(points[i]->pos.x, points[i]->pos.y)) point_list.push(points[i]);
+ if (r.contains(points[i]->pos.x, points[i]->pos.y)) point_list->push(points[i]);
if (nw == nullptr) return;
V2f force = { 0.0f, 0.0f };
other_bodies.clear();
- qt_bodies.query(AABB { body->pos.x - 300, body->pos.y - 300, 600, 600 }, other_bodies);
+ qt_bodies.query(AABB { body->pos.x - 200, body->pos.y - 200, 400, 400 }, &other_bodies);
For (other_bodies)
{
{
// 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);
+ state->bodies.ensure_capacity(2048);
- foreach (i, 0, 1024)
+ foreach (i, 0, 2048)
{
Body tmp_body;
tmp_body.pos = V2f{ randf(0, 1200), randf(0, 1200) };
state->bodies.push(tmp_body);
}
- state->qt_body_allocator.init(1024);
+ state->qt_body_allocator.init(2048);
}
internal f64 left_over_dt = 0.0;
For (state->bodies) state->qt_bodies.insert(&it, &state->qt_body_allocator);
For (state->bodies) body_accumulate_move(&it, state->qt_bodies, step);
- For (state->bodies) body_apply_move(&it);
+ For (state->bodies) {
+ body_apply_move(&it);
+ /*
+ if (it.pos.x < -window_width) it.pos.x = -window_width;
+ else if (it.pos.x >= window_width * 2) it.pos.x = window_width * 2;
+
+ if (it.pos.y < -window_height) it.pos.y = -window_height;
+ else if (it.pos.y >= window_height * 2) it.pos.y = window_height * 2;
+*/
+
+ if (it.pos.x < 0) it.pos.x = 0;
+ else if (it.pos.x >= window_width) it.pos.x = window_width;
+
+ if (it.pos.y < 0) it.pos.y = 0;
+ else if (it.pos.y >= window_height) it.pos.y = window_height;
+ }
left_over_dt -= step;
}
f64 frame_delta = 0.0;
i32 frame_count = 0;
+ clock_t total_clock_delta = 0;
while (!glfwWindowShouldClose(window))
{
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);
frame_delta += delta;
if (frame_delta >= 1.0)
{
+ logprint(LOG_LEVEL_INFO, "AVG UPD CLK: %10.6f", (f64) (total_clock_delta / frame_count) / CLOCKS_PER_SEC);
+
+ total_clock_delta = 0;
frame_delta -= 1.0;
logprint(LOG_LEVEL_INFO, "FPS: %d", frame_count);
frame_count = 0;