From 7d4575308d46e87a98b70d17e4da348e5c9ef93b Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 9 Aug 2018 00:05:25 +0200 Subject: [PATCH] add config switches for various debug options --- src/internal.c | 2 +- src/libsuperderpy.c | 9 ++++++--- src/libsuperderpy.h | 5 ++++- src/utils.c | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/internal.c b/src/internal.c index f7de112..e960cca 100644 --- a/src/internal.c +++ b/src/internal.c @@ -558,7 +558,7 @@ SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { PrintConsole(game, "DEBUG: reloading the gamestates..."); struct Gamestate* tmp = game->_priv.gamestates; while (tmp) { - if (tmp->fromlib) { + if (game->_priv.debug.livereload && tmp->fromlib) { char* name = strdup(tmp->name); CloseGamestate(game, tmp); tmp->name = name; diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index c76a88b..747f8d4 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -95,12 +95,15 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* 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.verbose = strtol(GetConfigOptionDefault(game, "SuperDerpy", "verbose", "0"), NULL, 10); game->config.width = strtol(GetConfigOptionDefault(game, "SuperDerpy", "width", "1280"), NULL, 10); if (game->config.width < 320) { game->config.width = 320; } game->config.height = strtol(GetConfigOptionDefault(game, "SuperDerpy", "height", "720"), NULL, 10); if (game->config.height < 180) { game->config.height = 180; } + 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->_priv.showconsole = game->config.debug; game->_priv.showtimeline = false; @@ -567,9 +570,9 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) { } else if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { al_acknowledge_resize(game->display); SetupViewport(game, game->viewport_config); - } else if ((game->config.debug) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT)) { + } else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT)) { PauseExecution(game); - } else if ((game->config.debug) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN)) { + } else if ((game->config.debug) && (game->_priv.debug.autopause) && (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN)) { ResumeExecution(game); } #ifdef ALLEGRO_ANDROID diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 5619099..bf7e241 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -86,7 +86,6 @@ struct Game { bool mute; /*!< Whether audio should be muted globally. */ bool fullscreen; /*!< Fullscreen toggle. */ bool debug; /*!< Toggles debug mode. */ - bool verbose; /*!< Toggles verbose debug. */ int width; /*!< Width of window as being set in configuration. */ int height; /*!< Height of window as being set in configuration. */ } config; @@ -151,6 +150,10 @@ struct Game { ALLEGRO_MUTEX* texture_sync_mutex; ALLEGRO_COND* texture_sync_cond; + struct { + bool verbose, livereload, autopause; + } debug; + #ifdef ALLEGRO_MACOSX char cwd[MAXPATHLEN]; #endif diff --git a/src/utils.c b/src/utils.c index 8b2d198..9e706bf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -401,7 +401,7 @@ __attribute__((__format__(__printf__, 5, 0))) SYMBOL_EXPORT void PrintConsoleWit if (game->config.debug) #endif { - if (game->config.verbose) { + if (game->_priv.debug.verbose) { printf("%s:%d ", file, line); } printf("[%s] %s\n", func, text);