From 18bcc93a61a6e65c34323888acdb5b4bd69c9cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 13 May 2021 16:12:18 +0200 Subject: [PATCH] graceful shutdown method --- code/game/header/game.h | 1 + code/game/header/platform.h | 13 +++++++------ code/game/header/profiler.h | 1 + code/game/source/debug_ui_actions.c | 3 ++- code/game/source/game.c | 4 ++++ code/game/source/platform_raylib.c | 9 +++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/code/game/header/game.h b/code/game/header/game.h index a3b87cc..f892679 100644 --- a/code/game/header/game.h +++ b/code/game/header/game.h @@ -11,6 +11,7 @@ typedef enum { void game_init(game_kind play_mode, uint32_t num_viewers, int32_t seed, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled); void game_shutdown(); +void game_request_close(); uint8_t game_is_running(); int8_t game_is_networked(); diff --git a/code/game/header/platform.h b/code/game/header/platform.h index 98dfc20..99509a6 100644 --- a/code/game/header/platform.h +++ b/code/game/header/platform.h @@ -1,12 +1,13 @@ #pragma once #include "system.h" -void platform_init(); -void platform_shutdown(); -float platform_frametime(); -uint8_t platform_is_running(); +void platform_init(void); +void platform_shutdown(void); +void platform_request_close(void); +float platform_frametime(void); +uint8_t platform_is_running(void); float platform_zoom_get(void); -void platform_input(); -void platform_render(); +void platform_input(void); +void platform_render(void); diff --git a/code/game/header/profiler.h b/code/game/header/profiler.h index 226464f..912df40 100644 --- a/code/game/header/profiler.h +++ b/code/game/header/profiler.h @@ -3,6 +3,7 @@ typedef enum { PROF_MAIN_LOOP, + PROF_WORLD_WRITE, PROF_RENDER, PROF_UPDATE_SYSTEMS, diff --git a/code/game/source/debug_ui_actions.c b/code/game/source/debug_ui_actions.c index 1b71c9f..7db24be 100644 --- a/code/game/source/debug_ui_actions.c +++ b/code/game/source/debug_ui_actions.c @@ -1,7 +1,8 @@ #include "debug_ui.h" #include "raylib.h" +#include "game.h" static inline void ActExitGame(void) { - CloseWindow(); + game_request_close(); } \ No newline at end of file diff --git a/code/game/source/game.c b/code/game/source/game.c index d2922eb..db91e3d 100644 --- a/code/game/source/game.c +++ b/code/game/source/game.c @@ -197,3 +197,7 @@ void game_world_cleanup_entities(void) { } #endif } + +void game_request_close() { + platform_request_close(); +} \ No newline at end of file diff --git a/code/game/source/platform_raylib.c b/code/game/source/platform_raylib.c index b4b37b2..fd4e7c4 100644 --- a/code/game/source/platform_raylib.c +++ b/code/game/source/platform_raylib.c @@ -17,6 +17,7 @@ uint16_t screenWidth = 1600; uint16_t screenHeight = 900; float target_zoom = 4.0f; float zoom_overlay_tran = 0.0f; +bool request_shutdown; #define CAM_OVERLAY_ZOOM_LEVEL 0.80f @@ -138,6 +139,10 @@ void platform_render() { } debug_draw(); EndDrawing(); + + if (request_shutdown) { + CloseWindow(); + } } void display_conn_status() { @@ -271,4 +276,8 @@ void do_entity_fadeinout(uint64_t key, entity_view * data) { float platform_zoom_get(void) { return target_zoom; +} + +void platform_request_close(void) { + request_shutdown = true; } \ No newline at end of file