mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
send filename, line number and function name to PrintConsole and FatalError for verbose debug output
This commit is contained in:
parent
942fd043fd
commit
6684847424
4 changed files with 13 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
11
src/utils.c
11
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++;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue