diff --git a/src/internal.c b/src/internal.c index 9a7a0b9..1d21282 100644 --- a/src/internal.c +++ b/src/internal.c @@ -195,6 +195,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) { for (int i = 0; i < size; i++) { al_draw_filled_rectangle(0, 0, al_get_display_width(game->display), al_get_font_line_height(game->_priv.font_console) * (size - i), al_map_rgba(0, 0, 0, 80)); } + al_lock_mutex(game->_priv.mutex); int cur = game->_priv.console_pos + size; for (int i = 0; i < size; i++) { if (cur >= size) { @@ -203,6 +204,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) { al_draw_text(game->_priv.font_console, al_map_rgb(255, 255, 255), (int)(al_get_display_width(game->display) * 0.005), al_get_font_line_height(game->_priv.font_console) * i, ALLEGRO_ALIGN_LEFT, game->_priv.console[cur]); cur++; } + al_unlock_mutex(game->_priv.mutex); char sfps[16] = {0}; snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps); diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 1295a4b..967fb17 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -109,6 +109,8 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->_priv.bsod_cond = al_create_cond(); game->_priv.bsod_mutex = al_create_mutex(); + game->_priv.mutex = al_create_mutex(); + game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10); game->config.music = strtol(GetConfigOptionDefault(game, "SuperDerpy", "music", "10"), NULL, 10); game->config.voice = strtol(GetConfigOptionDefault(game, "SuperDerpy", "voice", "10"), NULL, 10); @@ -497,6 +499,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) { al_destroy_mutex(game->_priv.texture_sync_mutex); al_destroy_cond(game->_priv.bsod_cond); al_destroy_mutex(game->_priv.bsod_mutex); + al_destroy_mutex(game->_priv.mutex); al_uninstall_audio(); DeinitConfig(game); #ifndef __EMSCRIPTEN__ diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 3bb9273..77ea328 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -191,6 +191,8 @@ struct Game { ALLEGRO_MUTEX* bsod_mutex; ALLEGRO_COND* bsod_cond; + ALLEGRO_MUTEX* mutex; + struct { bool verbose, livereload, autopause; } debug; diff --git a/src/utils.c b/src/utils.c index 865cd43..61412d1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -417,6 +417,7 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) { ALLEGRO_DEBUG_CHANNEL("libsuperderpy") SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...) { + al_lock_mutex(game->_priv.mutex); va_list vl; va_start(vl, format); char* text = game->_priv.console[game->_priv.console_pos]; @@ -444,6 +445,7 @@ SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const ch if (game->_priv.console_pos >= (sizeof(game->_priv.console) / sizeof(game->_priv.console[0]))) { game->_priv.console_pos = 0; } + al_unlock_mutex(game->_priv.mutex); } SYMBOL_EXPORT void SetupViewport(struct Game* game, struct Viewport config) {