a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit d166bd2e12fa8d3ff778ffde7817cea06dd4e23c
parent cd3370ddbf739ad76efa3e4a62a031624c78f05d
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Sun,  2 Jun 2019 15:42:56 -0700

Explicitly floor rather than zero truncate

Diffstat:
Msrc/am_math.h | 6++++++
Msrc/game.c | 8++++----
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/am_math.h b/src/am_math.h @@ -38,6 +38,12 @@ internal inline f32 math_wrap(f32 n, f32 min, f32 max) } } +internal inline i32 math_floor(f32 x) +{ + i32 result = floorf(x); + return result; +} + internal inline f32 math_rand(f32 min, f32 max) { assert(min < max); diff --git a/src/game.c b/src/game.c @@ -372,12 +372,12 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga rect tile_search_range = { .min = { - (i32)math_max(0.0f, player_traversal_occupancy_bb.min.x - 1), - (i32)math_max(0.0f, player_traversal_occupancy_bb.min.y - 1), + math_floor(math_max(0.0f, player_traversal_occupancy_bb.min.x - 1)), + math_floor(math_max(0.0f, player_traversal_occupancy_bb.min.y - 1)), }, .max = { - (i32)math_min(ROOM_TILE_DIM_X, player_traversal_occupancy_bb.max.x + 2), - (i32)math_min(ROOM_TILE_DIM_Y, player_traversal_occupancy_bb.max.y + 2), + math_floor(math_min(ROOM_TILE_DIM_X, player_traversal_occupancy_bb.max.x + 2)), + math_floor(math_min(ROOM_TILE_DIM_Y, player_traversal_occupancy_bb.max.y + 2)), }, };