commit a5f2ac1ed1d4f53c019e186aa6fa02a8c021809b
parent c79354bf54276bc99002fc404dda161925b127ee
Author: amin <dev@aminmesbah.com>
Date: Thu, 25 Apr 2019 20:07:35 +0000
Cull walls on screen edge
FossilOrigin-Name: 04e4edb370e97d07d1439a7f662dcfa7a864eb9554a7a7fd4afae0e6d974e87e
Diffstat:
M | src/game.c | | | 82 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
1 file changed, 52 insertions(+), 30 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -150,7 +150,7 @@ internal bool tile_is_solid(u32 tiles[][ROOM_TILE_DIM_X], v2 tile_pos)
assert(tile_index.x >= 0);
assert(tile_index.x < ROOM_TILE_DIM_X);
assert(tile_index.y >= 0);
- assert(tile_index.y < ROOM_TILE_DIM_X);
+ assert(tile_index.y < ROOM_TILE_DIM_Y);
u32 tile_value = tiles[tile_index.y][tile_index.x];
is_solid = tile_value > 0;
@@ -158,6 +158,28 @@ internal bool tile_is_solid(u32 tiles[][ROOM_TILE_DIM_X], v2 tile_pos)
return is_solid;
}
+internal bool wall_is_screen_edge(u32 tiles[][ROOM_TILE_DIM_X], segment wall)
+{
+ bool is_screen_edge = false;
+ bool wall_is_horizontal = wall.min.y == wall.max.y;
+ bool wall_is_vertical = wall.min.x == wall.max.x;
+
+ assert(wall_is_vertical || wall_is_horizontal);
+ assert(wall.min.x >= 0.0f && wall.min.y >= 0.0f);
+ assert(wall.min.x <= ROOM_TILE_DIM_X && wall.max.y <= ROOM_TILE_DIM_Y);
+
+ if (wall_is_vertical)
+ {
+ is_screen_edge = wall.min.x == 0.0f || wall.min.x == ROOM_TILE_DIM_X;
+ }
+ else
+ {
+ is_screen_edge = wall.min.y == 0.0f || wall.min.y == ROOM_TILE_DIM_Y;
+ }
+
+ return is_screen_edge;
+}
+
internal bool wall_is_internal(u32 tiles[][ROOM_TILE_DIM_X], segment wall)
{
bool is_internal = false;
@@ -240,35 +262,35 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
m4 projection = glmth_projection_ortho(0.0f, framebuffer.width, framebuffer.height, 0.0f, -1.0f, 0.0f);
// the little hanging fly village from knytt
- //u32 tiles[ROOM_TILE_DIM_Y][ROOM_TILE_DIM_X] = {
- // { 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
- // { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
- // { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
- // { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
- // { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 },
-
- // { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 },
- // { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 },
- // { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- // { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
- // { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
- //};
-
- // collision and physics testing map
u32 tiles[ROOM_TILE_DIM_Y][ROOM_TILE_DIM_X] = {
+ { 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1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0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0 },
+ // { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0 },
+ // { 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 },
+ // { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ //};
+
// render tiles
{
@@ -499,7 +521,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
v2 norm_l = {-1.0f, 0.0f};
v2 norm_r = {1.0f, 0.0f};
- if (!wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_BOTTOM)))
+ if (!wall_is_screen_edge(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_BOTTOM)) && !wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_BOTTOM)))
{
struct WallCollision bottom = get_wall_collision(player->pos, new_p, tile_sum_b, norm_b);
if (bottom.collision_occurred)
@@ -516,7 +538,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
RENDER_COLLISION_DEBUG_QUAD(collision, ((v3) {1.0f, 0.0f, 0.0f}));
}
}
- if (!wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_TOP)))
+ if (!wall_is_screen_edge(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_TOP)) && !wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_TOP)))
{
struct WallCollision top = get_wall_collision(player->pos, new_p, tile_sum_t, norm_t);
if (top.collision_occurred)
@@ -533,7 +555,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
RENDER_COLLISION_DEBUG_QUAD(collision, ((v3) {0.0f, 1.0f, 0.0f}));
}
}
- if (!wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_LEFT)))
+ if (!wall_is_screen_edge(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_LEFT)) && !wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_LEFT)))
{
struct WallCollision left = get_wall_collision(player->pos, new_p, tile_sum_l, norm_l);
if (left.collision_occurred)
@@ -550,7 +572,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
RENDER_COLLISION_DEBUG_QUAD(collision, ((v3) {0.0f, 0.0f, 1.0f}));
}
}
- if (!wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_RIGHT)))
+ if (!wall_is_screen_edge(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_RIGHT)) && !wall_is_internal(tiles, glmth_rect_get_edge(tile_aabb, RECT_EDGE_RIGHT)))
{
struct WallCollision right = get_wall_collision(player->pos, new_p, tile_sum_r, norm_r);
if (right.collision_occurred)