comment
This commit is contained in:
parent
15d3efe346
commit
6c884a2228
@ -406,25 +406,13 @@ INTERNAL void test_generate_walls(struct sim_snapshot *world)
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
|
||||
|
||||
/* Gather tile chunks and release existing walls.
|
||||
/* Release existing walls and gather tile chunks.
|
||||
* NOTE: We sort tile chunks before iterating so that chunk-edge tiles only
|
||||
* need to check for adjacent walls to merge with in one direction */
|
||||
struct sim_ent **x_sorted_tile_chunks = NULL;
|
||||
struct sim_ent **y_sorted_tile_chunks = NULL;
|
||||
u64 sorted_tile_chunks_count = 0;
|
||||
{
|
||||
/* NOTE: We sort x & y separately because of the possibility for diagonal
|
||||
* tile chunks to depend on each other.
|
||||
*
|
||||
* For example: In a horizontal iteration, if 2 chunks exist diagonally
|
||||
* with one to the bottom-left and one to the top-right and the top-right
|
||||
* chunk has no chunk below it, then the processing of the top-right chunk
|
||||
* will have to iterate an extra row at the bottom to create bottom walls (since
|
||||
* walls are created at the tops of tiles). When creating a wall at the bottom-left
|
||||
* tile of the top-right chunk, it needs to know whether any walls exist at
|
||||
* the left of that tile that it may need to merge with. If it was iterating
|
||||
* an array sorted with top-bottom priority, then the bottom-left chunk will not
|
||||
* have been processed yet, meaning no walls will have been generated to merge with. */
|
||||
x_sorted_tile_chunks = arena_dry_push(scratch.arena, struct sim_ent *);
|
||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||
struct sim_ent *ent = &world->ents[ent_index];
|
||||
@ -434,12 +422,15 @@ INTERNAL void test_generate_walls(struct sim_snapshot *world)
|
||||
*arena_push_no_zero(scratch.arena, struct sim_ent *) = ent;
|
||||
++sorted_tile_chunks_count;
|
||||
} else if (sim_ent_has_prop(ent, SEPROP_WALL)) {
|
||||
/* Release existing wall */
|
||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
||||
}
|
||||
}
|
||||
y_sorted_tile_chunks = arena_push_array_no_zero(scratch.arena, struct sim_ent *, sorted_tile_chunks_count);
|
||||
MEMCPY(y_sorted_tile_chunks, x_sorted_tile_chunks, sizeof(*x_sorted_tile_chunks) * sorted_tile_chunks_count);
|
||||
|
||||
/* NOTE: We sort x & y separately because it's possible that a wall
|
||||
* should merge with another wall that was generated from a diagonal chunk. */
|
||||
merge_sort(x_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*x_sorted_tile_chunks), tile_chunk_sort_x, NULL);
|
||||
merge_sort(y_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*y_sorted_tile_chunks), tile_chunk_sort_y, NULL);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user