commit d184dfdfaff147da80faa72cde8b6409a2878a56
parent c38bb08524b3e1ee02c312fbd64925fd76d6d44a
Author: Amin Mesbah <dev@aminmesbah.com>
Date: Wed, 24 Apr 2019 14:45:40 -0700
Capture more info about tunneling bug
I'm just going to stop claiming I've fixed it. I've set up gdb to run
the game with appropriate breakpoints. When the player hits the tile
directly north, after a while, the breakpoint will trigger. It happens
when `player.max.y` is exactly equal to `tile.min.y`.
Diffstat:
3 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/.gdbinit b/.gdbinit
@@ -0,0 +1,9 @@
+break game.c:126 if wall.min.y > 7 && entity_p_final.y > wall.min.y && entity_p_final.x < wall.max.x && entity_p_final.x > wall.min.x && !result.collision_occurred
+
+break game.c:550
+commands
+print player_aabb
+print tile_aabb
+end
+
+r
diff --git a/Makefile b/Makefile
@@ -12,7 +12,7 @@ LIB_NAME = game.so
DBGDIR = out/debug
DBGEXE = $(DBGDIR)/$(EXE_FILE)
-DBGCFLAGS = -g -Og -Werror
+DBGCFLAGS = -g -O0 -Werror
RELDIR = out/release
RELEXE = $(RELDIR)/$(EXE_FILE)
@@ -20,6 +20,8 @@ RELLIB = $(RELDIR)/$(LIB_NAME)
RELLIBTMP = $(RELLIB).tmp
RELCFLAGS = -DPLATFORM_HOTLOAD_GAME_CODE -O2 -Os
+DEBUGGER = gdb
+
.PHONY: default all build_debug build_lib build_release clean debug dir_debug dir_release memcheck run todo
default: build_release
@@ -40,7 +42,7 @@ clean:
rm -f $(RELDIR)/* $(DBGDIR)/*
debug: build_debug
- gdb --tui $(DBGEXE)
+ $(DEBUGGER) $(DBGEXE)
dir_debug:
@mkdir -p $(DBGDIR)
diff --git a/src/game.c b/src/game.c
@@ -268,8 +268,6 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
if (player_is_in_tile && tile_id > 0)
{
color = (v3) {0.8f, 0.4f, 0.4f};
- printf("!!!!!!!!!!!!!!!!\n");
- assert(false);
}
}
@@ -288,6 +286,14 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
{
struct Entity *player = &game_state->player;
f32 dt = game_input->dt;
+ if (dt >= 0.5f)
+ {
+ // NOTE(amin): If our dt is 0.5 seconds, we've probably been
+ // debugging and sitting at a breakpoint, and should just update as
+ // if we've been going at a steady 60fps.
+ printf("WARNING: Clamping frame dt to 1/60\n");
+ dt = 1.0f / 60.0f;
+ }
f32 max_meters_per_second = 5.0f;
f32 acceleration_rate = 50.0f;
f32 friction = 0.7f;
@@ -320,6 +326,9 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
player->velocity.x = player->velocity.x * friction;
}
+ // TODO: remove this constant acceleration with is just for debugging
+ player->acceleration = (v2) {0.0f, 50.0f};
+
// Semi implicit Euler integration: https://gafferongames.com/post/integration_basics/
player->velocity = glmth_v2_a(player->velocity, glmth_v2f_m(player->acceleration, dt));
glmth_clamp(&player->velocity.x, -max_meters_per_second, max_meters_per_second);
@@ -517,12 +526,35 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
remaining_time_factor -= smallest_distance_scale_factor;
}
+
+ {
+ v2 tile_pos = {12.0f, 8.0f};
+ f32 half_w = 0.5f * player->dimensions.width;
+ f32 half_h = 0.5f * player->dimensions.height;
+ rect player_aabb = {
+ .min = {player->pos.x - half_w, player->pos.y - half_h},
+ .max = {player->pos.x + half_w, player->pos.y + half_h},
+ };
+ rect tile_aabb = {
+ .min = tile_pos,
+ .max = {tile_pos.x + tile_size, tile_pos.y + tile_size},
+ };
+ bool player_is_in_tile = glmth_intersect_aabb_aabb(player_aabb, tile_aabb);
+ if (player_is_in_tile)
+ {
+ printf("!!!!!!!!!!!!!!!!\n");
+ printf("player aabb: ");
+ glmth_print(player_aabb);
+ printf("tile aabb: ");
+ glmth_print(tile_aabb);
+ printf("!!!!!!!!!!!!!!!!\n");
+ }
+ }
}
#undef RENDER_COLLISION_DEBUG_QUAD
#endif
glmth_clamp(&player->pos.x, 0.0f, ROOM_TILE_DIM_X);
glmth_clamp(&player->pos.y, 0.0f, ROOM_TILE_DIM_Y);
-
}
// render player