vertical wall generation

This commit is contained in:
jacob 2025-05-21 18:23:01 -05:00
parent c15f52032f
commit 4bc6ca6679
3 changed files with 107 additions and 47 deletions

View File

@ -39,7 +39,7 @@
#define SPACE_CELL_BINS_SQRT (64)
#define SPACE_CELL_SIZE (1)
#define SIM_TILES_PER_UNIT_SQRT (4)
#define SIM_TILES_PER_UNIT_SQRT (2)
#define SIM_TILES_PER_CHUNK_SQRT (16)
#define SIM_TICKS_PER_SECOND 50

View File

@ -429,6 +429,8 @@ INTERNAL void test_generate_walls(struct sim_ent *parent)
if (!chunk->valid) continue;
if (sim_ent_has_prop(chunk, SEPROP_TILE_CHUNK)) {
struct v2i32 chunk_index = chunk->tile_chunk_index;
/* Generate horizontal wall nodes */
{
struct sim_ent *top_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x, chunk_index.y - 1));
struct sim_ent *bottom_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x, chunk_index.y + 1));
/* If there's no chunk below this one, then do an extra iteration (since walls are created at the top of each tile) */
@ -483,6 +485,64 @@ INTERNAL void test_generate_walls(struct sim_ent *parent)
}
}
}
/* Generate vertical wall nodes */
{
struct sim_ent *left_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x - 1, chunk_index.y));
struct sim_ent *right_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x + 1, chunk_index.y));
/* If there's no chunk to the right of this one, then do an extra iteration (since walls are created on the left of each tile) */
i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + 1;
i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + !right_chunk->valid;
for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) {
i32 wall_start = -1;
i32 wall_end = -1;
for (i32 tile_y = 0; tile_y < y_iterations; ++tile_y) {
enum sim_tile_kind tile = SIM_TILE_KIND_NONE;
if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) {
tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y));
}
b32 should_have_left_wall = false;
if (tile_y < SIM_TILES_PER_CHUNK_SQRT) {
enum sim_tile_kind left_tile = SIM_TILE_KIND_NONE;
if (tile_x == 0) {
if (left_chunk->valid) {
struct v2i32 left_tile_local_index = V2I32(SIM_TILES_PER_CHUNK_SQRT - 1, tile_y);
left_tile = sim_get_chunk_tile(left_chunk, left_tile_local_index);
}
} else {
left_tile = sim_get_chunk_tile(chunk, V2I32(tile_x - 1, tile_y));
}
if (tile == SIM_TILE_KIND_WALL) {
/* Process wall tile */
should_have_left_wall = left_tile != SIM_TILE_KIND_WALL;
} else {
/* Process non-wall tile */
should_have_left_wall = left_tile == SIM_TILE_KIND_WALL;
}
}
if (should_have_left_wall) {
if (wall_start < 0) {
/* Start wall */
wall_start = tile_y;
}
/* Extend wall */
wall_end = tile_y + 1;
} else if (wall_end >= 0) {
/* Stop wall */
struct v2i32 start = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(tile_x, wall_start));
struct v2i32 end = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(tile_x, wall_end));
struct wall_node *node = arena_push(scratch.arena, struct wall_node);
node->start = start;
node->end = end;
node->next = first_wall;
first_wall = node;
wall_start = -1;
wall_end = -1;
}
}
}
}
}
}
/* Create wall entities */

View File

@ -1690,7 +1690,7 @@ INTERNAL void user_update(void)
if (walls_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_WALLS_TEST;
}
if (tile_state.num_presses_and_repeats) {
if (tile_state.num_presses || tile_state.is_held) {
control.flags |= SIM_CONTROL_FLAG_TILE_TEST;
}
if (explode_state.num_presses_and_repeats) {