diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 27a0d5b..62b2366 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -95,6 +95,7 @@ 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); diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 029b43c..5619099 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -86,6 +86,7 @@ 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; diff --git a/src/utils.c b/src/utils.c index d77b098..8b2d198 100644 --- a/src/utils.c +++ b/src/utils.c @@ -197,7 +197,7 @@ SYMBOL_EXPORT ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename return target; } -__attribute__((__format__(__printf__, 3, 0))) SYMBOL_EXPORT void FatalError(struct Game* game, bool exit, char* format, ...) { +__attribute__((__format__(__printf__, 6, 0))) SYMBOL_EXPORT void FatalErrorWithContext(struct Game* game, int line, const char* file, const char* func, bool exit, char* format, ...) { // TODO: interrupt and take over loading thread when it happens char text[1024] = {0}; PrintConsole(game, "Fatal Error, displaying Blue Screen of Derp..."); @@ -205,7 +205,7 @@ __attribute__((__format__(__printf__, 3, 0))) SYMBOL_EXPORT void FatalError(stru va_start(vl, format); vsnprintf(text, 1024, format, vl); va_end(vl); - fprintf(stderr, "%s\n", text); + fprintf(stderr, "%s:%d [%s]\n%s\n", file, line, func, text); // TODO: synchronize with loading thread @@ -386,7 +386,7 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) { ALLEGRO_DEBUG_CHANNEL("libsuperderpy") -__attribute__((__format__(__printf__, 2, 0))) SYMBOL_EXPORT void PrintConsole(struct Game* game, char* format, ...) { +__attribute__((__format__(__printf__, 5, 0))) SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...) { va_list vl; va_start(vl, format); char* text = game->_priv.console[game->_priv.console_pos]; @@ -401,7 +401,10 @@ __attribute__((__format__(__printf__, 2, 0))) SYMBOL_EXPORT void PrintConsole(st if (game->config.debug) #endif { - printf("%s\n", text); + if (game->config.verbose) { + printf("%s:%d ", file, line); + } + printf("[%s] %s\n", func, text); fflush(stdout); } game->_priv.console_pos++; diff --git a/src/utils.h b/src/utils.h index 7e5d412..1e399bc 100644 --- a/src/utils.h +++ b/src/utils.h @@ -67,15 +67,17 @@ ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, i /*! \brief Finds path for data file. */ char* GetDataFilePath(struct Game* game, const char* filename); +void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...); /*! \brief Print some message on game console. * * Draws message on console bitmap, so it'll be displayed when calling DrawConsole. * If game->debug is true, then it also prints given message on stdout. * It needs to be called in printf style. */ -void PrintConsole(struct Game* game, char* format, ...); +#define PrintConsole(game, format, ...) PrintConsoleWithContext(game, __LINE__, __FILE__, __func__, format, ##__VA_ARGS__) -void FatalError(struct Game* game, bool exit, char* format, ...); +void FatalErrorWithContext(struct Game* game, int line, const char* file, const char* func, bool exit, char* format, ...); +#define FatalError(game, exit, format, ...) FatalErrorWithContext(game, __LINE__, __FILE__, __func__, exit, format, ##__VA_ARGS__) void SetupViewport(struct Game* game, struct Viewport config);