generated from rpuzonas/raylib-cpp-template
fix crash when there are a lot of interactions
This commit is contained in:
parent
7c8a972228
commit
c86e1f86bc
@ -5,3 +5,4 @@
|
|||||||
-DRPROF_IMPLEMENTATION
|
-DRPROF_IMPLEMENTATION
|
||||||
-DRAYGUI_IMPLEMENTATION
|
-DRAYGUI_IMPLEMENTATION
|
||||||
-DDEBUG
|
-DDEBUG
|
||||||
|
-DSIMD256
|
||||||
|
@ -285,17 +285,27 @@ static void world_calc_distances_and_angles(World *world, BoidList *local_boids,
|
|||||||
RPROF_STOP();
|
RPROF_STOP();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define B2B_CAPACITY 2048*10
|
||||||
|
#define B2B_THRESHOLD B2B_CAPACITY * 0.5
|
||||||
|
|
||||||
|
static inline void append_b2b_cmp(World *world, BoidList *local_boids, boid_pair *b2b_cmps, int *b2b_cmps_count, boid_pair b2b_cmp) {
|
||||||
|
if (*b2b_cmps_count == B2B_CAPACITY) {
|
||||||
|
world_calc_distances_and_angles(world, local_boids, b2b_cmps, b2b_cmps_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
b2b_cmps[(*b2b_cmps_count)++] = b2b_cmp;
|
||||||
|
}
|
||||||
|
|
||||||
static void world_compute_local_boids(BoidList *local_boids, World *world, ChunkGrid *chunks) {
|
static void world_compute_local_boids(BoidList *local_boids, World *world, ChunkGrid *chunks) {
|
||||||
Boid *boids = world->boids.data();
|
Boid *boids = world->boids.data();
|
||||||
int boid_count = world->boids.size();
|
int boid_count = world->boids.size();
|
||||||
MemoryArena *arena = &world->frame_arena;
|
MemoryArena *arena = &world->frame_arena;
|
||||||
|
|
||||||
int b2b_padding = 8;
|
int b2b_padding = 8;
|
||||||
int b2b_capacity = 2048*10;
|
boid_pair b2b_cmps[B2B_CAPACITY + b2b_padding];
|
||||||
boid_pair b2b_cmps[b2b_capacity + b2b_padding];
|
|
||||||
int b2b_cmps_count = 0;
|
int b2b_cmps_count = 0;
|
||||||
for (int i = 0; i < b2b_padding; i++) {
|
for (int i = 0; i < b2b_padding; i++) {
|
||||||
memset(&b2b_cmps[b2b_capacity + i], 0, sizeof(boid_pair));
|
memset(&b2b_cmps[B2B_CAPACITY + i], 0, sizeof(boid_pair));
|
||||||
}
|
}
|
||||||
|
|
||||||
RPROF_START("Move chunk data to static arrays");
|
RPROF_START("Move chunk data to static arrays");
|
||||||
@ -324,12 +334,11 @@ static void world_compute_local_boids(BoidList *local_boids, World *world, Chunk
|
|||||||
uboid_t to_boids_count = chunk->count-i-1;
|
uboid_t to_boids_count = chunk->count-i-1;
|
||||||
|
|
||||||
for (int j = 0; j < to_boids_count; j++) {
|
for (int j = 0; j < to_boids_count; j++) {
|
||||||
// TODO:
|
boid_pair b2b_cmp = {
|
||||||
DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1);
|
|
||||||
b2b_cmps[b2b_cmps_count++] = {
|
|
||||||
.from = from_boid,
|
.from = from_boid,
|
||||||
.to = to_boids[j]
|
.to = to_boids[j]
|
||||||
};
|
};
|
||||||
|
append_b2b_cmp(world, local_boids, b2b_cmps, &b2b_cmps_count, b2b_cmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,17 +356,16 @@ static void world_compute_local_boids(BoidList *local_boids, World *world, Chunk
|
|||||||
uboid_t *neighbour_boids = static_chunks[neighbour_idx];
|
uboid_t *neighbour_boids = static_chunks[neighbour_idx];
|
||||||
for (int i = 0; i < chunk->count; i++) {
|
for (int i = 0; i < chunk->count; i++) {
|
||||||
for (int j = 0; j < neighbour_chunk->count; j++) {
|
for (int j = 0; j < neighbour_chunk->count; j++) {
|
||||||
// TODO:
|
boid_pair b2b_cmp = {
|
||||||
DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1);
|
|
||||||
b2b_cmps[b2b_cmps_count++] = {
|
|
||||||
.from = chunk_boids[i],
|
.from = chunk_boids[i],
|
||||||
.to = neighbour_boids[j]
|
.to = neighbour_boids[j]
|
||||||
};
|
};
|
||||||
|
append_b2b_cmp(world, local_boids, b2b_cmps, &b2b_cmps_count, b2b_cmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b2b_cmps_count > 2048*3) {
|
if (b2b_cmps_count > B2B_THRESHOLD) {
|
||||||
world_calc_distances_and_angles(world, local_boids, b2b_cmps, &b2b_cmps_count);
|
world_calc_distances_and_angles(world, local_boids, b2b_cmps, &b2b_cmps_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user