From 9b2e3cafeb2b4b0377610341f41a2c1023e9a2c0 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 21 Jul 2023 22:54:34 +0300 Subject: [PATCH] improve performance by not trying to save doing distance checks --- src/main.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5a23018..ca97b9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -194,17 +194,13 @@ static void assign_local_boids(World *world, BoidsListNode *local_boids, uint16_ // Simplified from: float dot_threshold = Vector2DotProduct(dir, Vector2Rotate(dir, world->view_angle/2)); float dot_threshold = cosf(world->view_angle/2); - Vector2 offset = Vector2Subtract(boids[boid1].pos, boids[boid2].pos); + Vector2 offset = Vector2Subtract(boids[boid2].pos, boids[boid1].pos); bool with_in_range = Vector2LengthSqr(offset) <= (world->view_radius * world->view_radius); if (with_in_range) { float dot = Vector2DotProduct(boids[boid1].dir, Vector2Normalize(offset)); - - if (-dot >= dot_threshold) { - boid_list_append_unique(&world->frame_arena, &local_boids[boid1], &local_boid_counts[boid1], boid2); - } if (dot >= dot_threshold) { - boid_list_append_unique(&world->frame_arena, &local_boids[boid2], &local_boid_counts[boid2], boid1); + boid_list_append(&world->frame_arena, &local_boids[boid1], &local_boid_counts[boid1], boid2); } } } @@ -612,7 +608,7 @@ int main() { world_init(&g_world, screen_width, screen_height); float border = g_world.collision_avoidance_distance; - for (int i = 0; i < 20000; i++) { + for (int i = 0; i < 30000; i++) { Boid boid; boid_rand_init(&g_world, &boid, border); g_world.boids.push_back(boid);