horizontal wall generation testing

This commit is contained in:
jacob 2025-05-21 17:52:25 -05:00
parent 478f077030
commit c15f52032f
4 changed files with 36 additions and 26 deletions

View File

@ -561,26 +561,18 @@ struct v2 sim_pos_from_world_tile_index(struct v2i32 world_tile_index)
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT; f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
res.x = (f32)world_tile_index.x * tile_size; res.x = (f32)world_tile_index.x * tile_size;
res.y = (f32)world_tile_index.y * tile_size; res.y = (f32)world_tile_index.y * tile_size;
if (world_tile_index.x < 0) {
res.x += tile_size;
}
if (world_tile_index.y < 0) {
res.y += tile_size;
}
return res; return res;
} }
struct v2i32 sim_local_tile_index_from_world_tile_index(struct v2i32 world_tile_index) struct v2i32 sim_local_tile_index_from_world_tile_index(struct v2i32 world_tile_index)
{ {
struct v2i32 res = ZI; struct v2i32 res = world_tile_index;
res.x = world_tile_index.x % SIM_TILES_PER_CHUNK_SQRT; res.x += res.x < 0;
res.y = world_tile_index.y % SIM_TILES_PER_CHUNK_SQRT; res.y += res.y < 0;
if (world_tile_index.x < 0) { res.x = res.x % SIM_TILES_PER_CHUNK_SQRT;
res.x = SIM_TILES_PER_CHUNK_SQRT + res.x - 1; res.y = res.y % SIM_TILES_PER_CHUNK_SQRT;
} res.x += (world_tile_index.x < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1);
if (world_tile_index.y < 0) { res.y += (world_tile_index.y < 0) * (SIM_TILES_PER_CHUNK_SQRT - 1);
res.y = SIM_TILES_PER_CHUNK_SQRT + res.y - 1;
}
return res; return res;
} }
@ -594,9 +586,11 @@ struct v2i32 sim_world_tile_index_from_local_tile_index(struct v2i32 tile_chunk_
struct v2i32 sim_tile_chunk_index_from_world_tile_index(struct v2i32 world_tile_index) struct v2i32 sim_tile_chunk_index_from_world_tile_index(struct v2i32 world_tile_index)
{ {
struct v2i32 res = ZI; struct v2i32 res = world_tile_index;
res.x = world_tile_index.x / SIM_TILES_PER_CHUNK_SQRT; res.x += res.x < 0;
res.y = world_tile_index.y / SIM_TILES_PER_CHUNK_SQRT; res.y += res.y < 0;
res.x = res.x / SIM_TILES_PER_CHUNK_SQRT;
res.y = res.y / SIM_TILES_PER_CHUNK_SQRT;
res.x -= world_tile_index.x < 0; res.x -= world_tile_index.x < 0;
res.y -= world_tile_index.y < 0; res.y -= world_tile_index.y < 0;
return res; return res;

View File

@ -566,11 +566,17 @@ void sim_ent_apply_torque(struct sim_ent *ent, f32 torque)
* Tile * Tile
* ========================== */ * ========================== */
struct sim_ent *sim_tile_chunk_from_chunk_index(struct sim_snapshot *ss, struct v2i32 chunk_index)
{
struct sim_ent_id chunk_id = sim_ent_tile_chunk_id_from_tile_chunk_index(chunk_index);
struct sim_ent *chunk_ent = sim_ent_from_id(ss, chunk_id);
return chunk_ent;
}
struct sim_ent *sim_tile_chunk_from_world_tile_index(struct sim_snapshot *ss, struct v2i32 world_tile_index) struct sim_ent *sim_tile_chunk_from_world_tile_index(struct sim_snapshot *ss, struct v2i32 world_tile_index)
{ {
struct v2i32 chunk_index = sim_tile_chunk_index_from_world_tile_index(world_tile_index); struct v2i32 chunk_index = sim_tile_chunk_index_from_world_tile_index(world_tile_index);
struct sim_ent_id chunk_id = sim_ent_tile_chunk_id_from_tile_chunk_index(chunk_index); struct sim_ent *chunk_ent = sim_tile_chunk_from_chunk_index(ss, chunk_index);
struct sim_ent *chunk_ent = sim_ent_from_id(ss, chunk_id);
return chunk_ent; return chunk_ent;
} }

View File

@ -543,6 +543,7 @@ void sim_ent_apply_angular_impulse(struct sim_ent *ent, f32 impulse);
void sim_ent_apply_torque(struct sim_ent *ent, f32 torque); void sim_ent_apply_torque(struct sim_ent *ent, f32 torque);
/* Tile */ /* Tile */
struct sim_ent *sim_tile_chunk_from_chunk_index(struct sim_snapshot *ss, struct v2i32 chunk_index);
struct sim_ent *sim_tile_chunk_from_world_tile_index(struct sim_snapshot *ss, struct v2i32 world_tile_index); struct sim_ent *sim_tile_chunk_from_world_tile_index(struct sim_snapshot *ss, struct v2i32 world_tile_index);
enum sim_tile_kind sim_get_chunk_tile(struct sim_ent *chunk_ent, struct v2i32 local_tile_index); enum sim_tile_kind sim_get_chunk_tile(struct sim_ent *chunk_ent, struct v2i32 local_tile_index);

View File

@ -429,8 +429,8 @@ INTERNAL void test_generate_walls(struct sim_ent *parent)
if (!chunk->valid) continue; if (!chunk->valid) continue;
if (sim_ent_has_prop(chunk, SEPROP_TILE_CHUNK)) { if (sim_ent_has_prop(chunk, SEPROP_TILE_CHUNK)) {
struct v2i32 chunk_index = chunk->tile_chunk_index; struct v2i32 chunk_index = chunk->tile_chunk_index;
struct sim_ent *top_chunk = sim_tile_chunk_from_world_tile_index(world, V2I32(chunk_index.x, chunk_index.y - 1)); 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_world_tile_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) */ /* 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 y_iterations = SIM_TILES_PER_CHUNK_SQRT + !bottom_chunk->valid;
i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1; i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1;
@ -439,20 +439,29 @@ INTERNAL void test_generate_walls(struct sim_ent *parent)
i32 wall_end = -1; i32 wall_end = -1;
for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) { for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) {
enum sim_tile_kind tile = SIM_TILE_KIND_NONE; enum sim_tile_kind tile = SIM_TILE_KIND_NONE;
enum sim_tile_kind top_tile = SIM_TILE_KIND_NONE;
if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) { 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)); tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y));
} }
if (tile == SIM_TILE_KIND_NONE && tile_x < SIM_TILES_PER_CHUNK_SQRT) { 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 (tile_y == 0) {
if (top_chunk->valid) { if (top_chunk->valid) {
top_tile = sim_get_chunk_tile(top_chunk, V2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1)); 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 { } else {
top_tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y - 1)); 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 (top_tile == SIM_TILE_KIND_WALL && tile != SIM_TILE_KIND_WALL) { }
if (should_have_top_wall) {
if (wall_start < 0) { if (wall_start < 0) {
/* Start wall */ /* Start wall */
wall_start = tile_x; wall_start = tile_x;