diff --git a/src/character.c b/src/character.c index c825e11..e55a6b3 100644 --- a/src/character.c +++ b/src/character.c @@ -111,7 +111,7 @@ SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* charact } for (int i = 0; i < tmp->frameCount; i++) { if ((!tmp->frames[i].source) && (tmp->frames[i].file)) { - if (game->config.debug) { + if (game->config.debug.enabled) { PrintConsole(game, " - %s", tmp->frames[i].file); } char filename[255] = {0}; diff --git a/src/internal.c b/src/internal.c index c43f94b..e483c33 100644 --- a/src/internal.c +++ b/src/internal.c @@ -249,7 +249,7 @@ SYMBOL_INTERNAL void* GamestateLoadingThread(void* arg) { data->gamestate->data = data->gamestate->api->Gamestate_Load(data->game, &GamestateProgress); if (data->game->_priv.loading.progress != data->gamestate->progressCount) { PrintConsole(data->game, "[%s] WARNING: Gamestate_ProgressCount does not match the number of progress invokations (%d)!", data->gamestate->name, data->game->_priv.loading.progress); - if (data->game->config.debug) { + if (data->game->config.debug.enabled) { PrintConsole(data->game, "(sleeping for 3 seconds...)"); data->game->_priv.showconsole = true; al_rest(3.0); @@ -277,7 +277,7 @@ SYMBOL_INTERNAL void* ScreenshotThread(void* arg) { SYMBOL_INTERNAL void CalculateProgress(struct Game* game) { struct Gamestate* tmp = game->_priv.loading.current; float progress = ((game->_priv.loading.progress / (float)(tmp->progressCount + 1)) / (float)game->_priv.loading.toLoad) + (game->_priv.loading.loaded / (float)game->_priv.loading.toLoad); - if (game->config.debug) { + if (game->config.debug.enabled) { PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, tmp->progressCount + 1); } game->loading.progress = progress; diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index ddb5bb0..d5b04c4 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -108,17 +108,17 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->config.voice = strtol(GetConfigOptionDefault(game, "SuperDerpy", "voice", "10"), NULL, 10); game->config.fx = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fx", "10"), NULL, 10); game->config.mute = strtol(GetConfigOptionDefault(game, "SuperDerpy", "mute", "0"), NULL, 10); - game->config.debug = strtol(GetConfigOptionDefault(game, "SuperDerpy", "debug", "0"), NULL, 10); + game->config.debug.enabled = strtol(GetConfigOptionDefault(game, "SuperDerpy", "debug", "0"), NULL, 10); game->config.width = strtol(GetConfigOptionDefault(game, "SuperDerpy", "width", GetDefaultWindowWidth(game)), NULL, 10); if (game->config.width < 100) { game->config.width = 100; } game->config.height = strtol(GetConfigOptionDefault(game, "SuperDerpy", "height", GetDefaultWindowHeight(game)), NULL, 10); if (game->config.height < 100) { game->config.height = 100; } - game->_priv.debug.verbose = strtol(GetConfigOptionDefault(game, "debug", "verbose", "0"), NULL, 10); - game->_priv.debug.livereload = strtol(GetConfigOptionDefault(game, "debug", "livereload", "1"), NULL, 10); - game->_priv.debug.autopause = strtol(GetConfigOptionDefault(game, "debug", "autopause", "1"), NULL, 10); + game->config.debug.verbose = strtol(GetConfigOptionDefault(game, "debug", "verbose", "0"), NULL, 10); + game->config.debug.livereload = strtol(GetConfigOptionDefault(game, "debug", "livereload", "1"), NULL, 10); + game->config.debug.autopause = strtol(GetConfigOptionDefault(game, "debug", "autopause", "1"), NULL, 10); - game->_priv.showconsole = game->config.debug; + game->_priv.showconsole = game->config.debug.enabled; game->_priv.showtimeline = false; if (!al_init_image_addon()) { diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index e3a69b1..4a2845e 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -157,9 +157,14 @@ struct Game { int voice; /*!< Voice volume. */ bool mute; /*!< Whether audio should be muted globally. */ bool fullscreen; /*!< Fullscreen toggle. */ - bool debug; /*!< Toggles debug mode. */ int width; /*!< Width of window as being set in configuration. */ int height; /*!< Height of window as being set in configuration. */ + struct { + bool enabled; /*!< Toggles debug mode. */ + bool verbose; /*!< Prints file names and line numbers with every message. */ + bool livereload; /*!< Automatically reloads gamestates on window focus. */ + bool autopause; /*!< Pauses/resumes the game when the window loses/gains focus. */ + } debug; /*!< Debug mode settings. */ } config; /*!< Configuration values from the config file. */ struct { @@ -237,10 +242,6 @@ struct Game { bool shutting_down; /*!< If true then shut down of the game is pending. */ bool restart; /*!< If true then restart of the game is pending. */ - struct { - bool verbose, livereload, autopause; - } debug; - ALLEGRO_TRANSFORM projection; /*!< Projection of the game canvas into the actual game window. */ #ifdef ALLEGRO_MACOSX diff --git a/src/mainloop.c b/src/mainloop.c index aa73419..1ccfa0a 100644 --- a/src/mainloop.c +++ b/src/mainloop.c @@ -59,7 +59,7 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) { if ((ev->keyboard.keycode == ALLEGRO_KEY_TILDE) || (ev->keyboard.keycode == ALLEGRO_KEY_BACKQUOTE)) { #endif game->_priv.showconsole = !game->_priv.showconsole; - if ((ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) && (game->config.debug)) { + if ((ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) && (game->config.debug.enabled)) { game->_priv.showtimeline = game->_priv.showconsole; } } @@ -131,15 +131,15 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) { static inline void HandleDebugEvent(struct Game* game, ALLEGRO_EVENT* ev) { switch (ev->type) { case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: - if (game->_priv.debug.autopause) { + if (game->config.debug.autopause) { PrintConsole(game, "DEBUG: autopause"); PauseExecution(game); } break; case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: - if (game->_priv.debug.autopause) { - if (game->_priv.debug.livereload) { + if (game->config.debug.autopause) { + if (game->config.debug.livereload) { ReloadCode(game); } ResumeExecution(game); @@ -424,7 +424,7 @@ static inline bool MainloopEvents(struct Game* game) { HandleEvent(game, &ev); - if (game->config.debug) { + if (game->config.debug.enabled) { HandleDebugEvent(game, &ev); } diff --git a/src/utils.c b/src/utils.c index f0c6b20..6f2de9e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -429,10 +429,10 @@ SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const ch SUPPRESS_END #if !defined(__EMSCRIPTEN__) && !defined(ALLEGRO_ANDROID) - if (game->config.debug) + if (game->config.debug.enabled) #endif { - if (game->_priv.debug.verbose) { + if (game->config.debug.verbose) { printf("%s:%d ", file, line); } printf("[%s] %s\n", func, text);