diff --git a/src/config.h b/src/config.h index e3bee223..56d5c1f0 100644 --- a/src/config.h +++ b/src/config.h @@ -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 diff --git a/src/sim_step.c b/src/sim_step.c index ae0525df..58a85264 100644 --- a/src/sim_step.c +++ b/src/sim_step.c @@ -429,56 +429,116 @@ 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; - 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) */ - i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + !bottom_chunk->valid; - i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1; - for (i32 tile_y = 0; tile_y < y_iterations; ++tile_y) { - i32 wall_start = -1; - i32 wall_end = -1; - for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) { - 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_top_wall = false; - if (tile_x < SIM_TILES_PER_CHUNK_SQRT) { - enum sim_tile_kind top_tile = SIM_TILE_KIND_NONE; - if (tile_y == 0) { - if (top_chunk->valid) { - struct v2i32 top_tile_local_index = V2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1); - top_tile = sim_get_chunk_tile(top_chunk, top_tile_local_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) */ + i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + !bottom_chunk->valid; + i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1; + for (i32 tile_y = 0; tile_y < y_iterations; ++tile_y) { + i32 wall_start = -1; + i32 wall_end = -1; + for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) { + 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_top_wall = false; + if (tile_x < SIM_TILES_PER_CHUNK_SQRT) { + enum sim_tile_kind top_tile = SIM_TILE_KIND_NONE; + if (tile_y == 0) { + if (top_chunk->valid) { + struct v2i32 top_tile_local_index = V2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1); + top_tile = sim_get_chunk_tile(top_chunk, top_tile_local_index); + } + } else { + top_tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y - 1)); + } + if (tile == SIM_TILE_KIND_WALL) { + /* Process wall tile */ + should_have_top_wall = top_tile != SIM_TILE_KIND_WALL; + } else { + /* Process non-wall tile */ + should_have_top_wall = top_tile == SIM_TILE_KIND_WALL; } - } else { - top_tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y - 1)); } - if (tile == SIM_TILE_KIND_WALL) { - /* Process wall tile */ - should_have_top_wall = top_tile != SIM_TILE_KIND_WALL; - } else { - /* Process non-wall tile */ - should_have_top_wall = top_tile == SIM_TILE_KIND_WALL; + if (should_have_top_wall) { + if (wall_start < 0) { + /* Start wall */ + wall_start = tile_x; + } + /* Extend wall */ + wall_end = tile_x + 1; + } else if (wall_end >= 0) { + /* Stop wall */ + struct v2i32 start = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_start, tile_y)); + struct v2i32 end = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_end, tile_y)); + 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; } } - if (should_have_top_wall) { - if (wall_start < 0) { - /* Start wall */ - wall_start = tile_x; + } + } + /* 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; } - /* Extend wall */ - wall_end = tile_x + 1; - } else if (wall_end >= 0) { - /* Stop wall */ - struct v2i32 start = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_start, tile_y)); - struct v2i32 end = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_end, tile_y)); - 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; } } } diff --git a/src/user.c b/src/user.c index ed1ac310..dd008c04 100644 --- a/src/user.c +++ b/src/user.c @@ -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) {