commit 73a03d9d40cdd393a8d70d493de5869ccf43da6e
parent 05b02e41bad2755dfca4325ed29859582f2f99a5
Author: amin <dev@aminmesbah.com>
Date: Fri, 14 Jun 2019 02:08:14 +0000
Treat tiles in nonexistent rooms as solid
FossilOrigin-Name: b342a977bb55907ab6b8ba0118aaa3b01e0e2cf7005482f69b0e3fb153b6856d
Diffstat:
2 files changed, 10 insertions(+), 40 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -382,16 +382,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
.local = (v2) {tile_x, tile_y},
});
- bool tile_is_past_world_edge = false;
- if (!math_v2i_eq(tile_pos.room, current_room_i))
- {
- if (!world_room_get(game_state->world, tile_pos.room))
- {
- tile_is_past_world_edge = true;
- }
- }
-
- if ((!tile_is_past_world_edge) && world_tile_is_solid(game_state->world, tile_pos))
+ if (world_tile_is_solid(game_state->world, tile_pos))
{
rect tile_aabb = {
.min = {tile_x, tile_y},
@@ -481,32 +472,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
}
#undef RENDER_COLLISION_DEBUG_QUAD
- struct AbsolutePos new_player_p = world_pos_recanonicalize(player->pos);
-
- if (world_room_get(game_state->world, new_player_p.room))
- {
- player->pos = new_player_p;
- }
- else
- {
- if(player->pos.local.x < 0.0f && !world_room_get(game_state->world, (v2i) {current_room_i.x - 1, current_room_i.y}))
- {
- player->pos.local.x = 0.0f;
- }
- else if (player->pos.local.x > ROOM_TILE_DIM_X && !world_room_get(game_state->world, (v2i) {current_room_i.x + 1, current_room_i.y}))
- {
- player->pos.local.x = ROOM_TILE_DIM_X;
- }
- if(player->pos.local.y < 0.0f && !world_room_get(game_state->world, (v2i) {current_room_i.x, current_room_i.y - 1}))
- {
- player->pos.local.y = 0.0f;
- }
- else if (player->pos.local.y > ROOM_TILE_DIM_Y && !world_room_get(game_state->world, (v2i) {current_room_i.x, current_room_i.y + 1}))
- {
- player->pos.local.y = ROOM_TILE_DIM_Y;
- }
- player->pos = world_pos_recanonicalize(player->pos);
- }
+ player->pos = world_pos_recanonicalize(player->pos);
}
// render_player
diff --git a/src/world.c b/src/world.c
@@ -257,13 +257,17 @@ internal bool world_tile_in_room_is_solid(u32 *tiles, v2 tile_pos)
internal bool world_tile_is_solid(struct World *world, struct AbsolutePos abs_tile_p)
{
+ bool is_solid = true;
assert(world);
struct AbsolutePos p = world_tile_pos_recanonicalize(abs_tile_p);
struct Room *r = world_room_get(world, p.room);
- // TODO: we have the opportunity here to just make every 'tile' beyond the
- // edge of the world solid.
- assert(r);
- bool is_solid = world_tile_in_room_is_solid(r->tiles, p.local);
+ // NOTE(amin): If we don't get a room back here, we will just treat the
+ // 'tile' as solid so we can collide with it rather than entering the
+ // nonexistent room.
+ if (r)
+ {
+ is_solid = world_tile_in_room_is_solid(r->tiles, p.local);
+ }
return is_solid;
}