mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
move autopause feature out of debug events
This commit is contained in:
parent
d0316cd789
commit
2ad77b071f
4 changed files with 27 additions and 22 deletions
|
@ -53,6 +53,12 @@
|
||||||
#define SUPPRESS_END
|
#define SUPPRESS_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#define IS_EMSCRIPTEN true
|
||||||
|
#else
|
||||||
|
#define IS_EMSCRIPTEN false
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ALLEGRO_WINDOWS
|
#ifdef ALLEGRO_WINDOWS
|
||||||
#define LIBRARY_EXTENSION ".dll"
|
#define LIBRARY_EXTENSION ".dll"
|
||||||
#elif defined(__EMSCRIPTEN__)
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
|
|
@ -105,18 +105,18 @@ 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.voice = strtol(GetConfigOptionDefault(game, "SuperDerpy", "voice", "10"), NULL, 10);
|
||||||
game->config.fx = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fx", "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.mute = strtol(GetConfigOptionDefault(game, "SuperDerpy", "mute", "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);
|
game->config.width = strtol(GetConfigOptionDefault(game, "SuperDerpy", "width", GetDefaultWindowWidth(game)), NULL, 10);
|
||||||
if (game->config.width < 100) { game->config.width = 100; }
|
if (game->config.width < 100) { game->config.width = 100; }
|
||||||
game->config.height = strtol(GetConfigOptionDefault(game, "SuperDerpy", "height", GetDefaultWindowHeight(game)), NULL, 10);
|
game->config.height = strtol(GetConfigOptionDefault(game, "SuperDerpy", "height", GetDefaultWindowHeight(game)), NULL, 10);
|
||||||
if (game->config.height < 100) { game->config.height = 100; }
|
if (game->config.height < 100) { game->config.height = 100; }
|
||||||
|
game->config.autopause = strtol(GetConfigOptionDefault(game, "SuperDerpy", "autopause", IS_EMSCRIPTEN ? "1" : "0"), NULL, 10);
|
||||||
|
|
||||||
|
game->config.debug.enabled = strtol(GetConfigOptionDefault(game, "SuperDerpy", "debug", "0"), NULL, 10);
|
||||||
game->config.debug.verbose = strtol(GetConfigOptionDefault(game, "debug", "verbose", "0"), 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.livereload = strtol(GetConfigOptionDefault(game, "debug", "livereload", "1"), NULL, 10);
|
||||||
game->config.debug.autopause = strtol(GetConfigOptionDefault(game, "debug", "autopause", "1"), NULL, 10);
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
game->config.fullscreen = false;
|
game->config.fullscreen = false; // we can't start fullscreen on emscripten
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
game->_priv.showconsole = game->config.debug.enabled;
|
game->_priv.showconsole = game->config.debug.enabled;
|
||||||
|
|
|
@ -159,11 +159,11 @@ struct Game {
|
||||||
bool fullscreen; /*!< Fullscreen toggle. */
|
bool fullscreen; /*!< Fullscreen toggle. */
|
||||||
int width; /*!< Width of window as being set in configuration. */
|
int width; /*!< Width of window as being set in configuration. */
|
||||||
int height; /*!< Height of window as being set in configuration. */
|
int height; /*!< Height of window as being set in configuration. */
|
||||||
|
bool autopause; /*!< Pauses/resumes the game when the window loses/gains focus. */
|
||||||
struct {
|
struct {
|
||||||
bool enabled; /*!< Toggles debug mode. */
|
bool enabled; /*!< Toggles debug mode. */
|
||||||
bool verbose; /*!< Prints file names and line numbers with every message. */
|
bool verbose; /*!< Prints file names and line numbers with every message. */
|
||||||
bool livereload; /*!< Automatically reloads gamestates on window focus. */
|
bool livereload; /*!< Automatically reloads gamestates on window focus. */
|
||||||
bool autopause; /*!< Pauses/resumes the game when the window loses/gains focus. */
|
|
||||||
} debug; /*!< Debug mode settings. */
|
} debug; /*!< Debug mode settings. */
|
||||||
} config; /*!< Configuration values from the config file. */
|
} config; /*!< Configuration values from the config file. */
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,22 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
||||||
ResumeExecution(game);
|
ResumeExecution(game);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
|
||||||
|
if (game->config.autopause) {
|
||||||
|
PrintConsole(game, "Focus lost, autopausing...");
|
||||||
|
PauseExecution(game);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
|
||||||
|
if (game->config.autopause) {
|
||||||
|
if (game->config.debug.enabled && game->config.debug.livereload) {
|
||||||
|
ReloadCode(game);
|
||||||
|
}
|
||||||
|
ResumeExecution(game);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case ALLEGRO_EVENT_DISPLAY_RESIZE:
|
case ALLEGRO_EVENT_DISPLAY_RESIZE:
|
||||||
#ifdef LIBSUPERDERPY_IMGUI
|
#ifdef LIBSUPERDERPY_IMGUI
|
||||||
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
||||||
|
@ -121,24 +137,7 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
||||||
|
|
||||||
static inline void HandleDebugEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
static inline void HandleDebugEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
||||||
switch (ev->type) {
|
switch (ev->type) {
|
||||||
case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
|
|
||||||
if (game->config.debug.autopause) {
|
|
||||||
PrintConsole(game, "DEBUG: autopause");
|
|
||||||
PauseExecution(game);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
|
|
||||||
if (game->config.debug.autopause) {
|
|
||||||
if (game->config.debug.livereload) {
|
|
||||||
ReloadCode(game);
|
|
||||||
}
|
|
||||||
ResumeExecution(game);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ALLEGRO_EVENT_KEY_DOWN:
|
case ALLEGRO_EVENT_KEY_DOWN:
|
||||||
|
|
||||||
switch (ev->keyboard.keycode) {
|
switch (ev->keyboard.keycode) {
|
||||||
case ALLEGRO_KEY_F1:
|
case ALLEGRO_KEY_F1:
|
||||||
if (!game->_priv.paused) {
|
if (!game->_priv.paused) {
|
||||||
|
@ -181,7 +180,7 @@ static inline bool MainloopEvents(struct Game* game) {
|
||||||
do {
|
do {
|
||||||
ALLEGRO_EVENT ev;
|
ALLEGRO_EVENT ev;
|
||||||
|
|
||||||
if (game->_priv.paused) {
|
if (game->_priv.paused && !IS_EMSCRIPTEN) {
|
||||||
// there's no frame flipping when paused, so avoid pointless busylooping
|
// there's no frame flipping when paused, so avoid pointless busylooping
|
||||||
al_wait_for_event(game->_priv.event_queue, &ev);
|
al_wait_for_event(game->_priv.event_queue, &ev);
|
||||||
} else if (!al_get_next_event(game->_priv.event_queue, &ev)) {
|
} else if (!al_get_next_event(game->_priv.event_queue, &ev)) {
|
||||||
|
|
Loading…
Reference in a new issue