summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-19 21:55:38 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-11-19 21:55:38 -0800
commit150436a59771ce18483305e05a1599988ae78df4 (patch)
tree8a1d45d73fb66fc69d4ed7cde96c26acd227a5e4
parent6d77e0f78aa203c44661d8b88e489a65bbc4b56c (diff)
downloadohsp-150436a59771ce18483305e05a1599988ae78df4.zip
ohsp-150436a59771ce18483305e05a1599988ae78df4.tar.gz
Add ability to skip screen clearing
- t key toggles 'trace' Note that this exposes the non-determinism of the current game loop. The lag compensation while-loop updates the game state, but not the input. The variance in the number of these updates causes divergent results even when identical input is played over a given initial state.
-rw-r--r--src/platform_sdl.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index 8682b4a..c7bfbb3 100644
--- a/src/platform_sdl.c
+++ b/src/platform_sdl.c
@@ -17,6 +17,7 @@ extern bool PAUSED;
static struct SDLOffscreenBuffer global_back_buffer = {0};
static struct SDLInputRecord input_record = {0};
+static bool TRACE = false;
struct SDLWindowDimension sdl_get_window_dimension(SDL_Window *window)
@@ -117,6 +118,10 @@ bool sdl_handle_event(SDL_Event *event, struct GameControllerInput *controller_i
{
PAUSED = !PAUSED;
}
+ else if (key_code == SDLK_t)
+ {
+ TRACE = !TRACE;
+ }
else if (key_code == SDLK_r)
{
if (input_record.state == INACTIVE)
@@ -397,7 +402,10 @@ int main(int argc, char *argv[])
}
}
- clear_screen(&global_back_buffer, COLOR_BACKGROUND);
+ if (!TRACE)
+ {
+ clear_screen(&global_back_buffer, COLOR_BACKGROUND);
+ }
game_code.game_render(&buffer, lag/SECOND, &game_state);
sdl_update_window(renderer, &global_back_buffer);
if (elapsed_ms <= MS_PER_FRAME)