generated from rpuzonas/raylib-cpp-template
improve performance by not trying to save doing distance checks
This commit is contained in:
parent
cabc63c2c2
commit
9b2e3cafeb
10
src/main.cpp
10
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);
|
||||
|
Loading…
Reference in New Issue
Block a user