From: Holger Schemel Date: Fri, 18 Sep 2020 23:58:47 +0000 (+0200) Subject: added multi-part line debug logging functions X-Git-Tag: 4.2.0.3~20 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1e606dd0963695c0b9ef24497c979f8b6bc1035b;p=rocksndiamonds.git added multi-part line debug logging functions --- diff --git a/src/game.c b/src/game.c index 859cf24e..0d28b40b 100644 --- a/src/game.c +++ b/src/game.c @@ -11661,9 +11661,8 @@ static void GameActionsExt(void) byte mapped_action[MAX_PLAYERS]; #if DEBUG_PLAYER_ACTIONS - Print(":::"); for (i = 0; i < MAX_PLAYERS; i++) - Print(" %d, ", stored_player[i].effective_action); + DebugContinued("", "%d, ", stored_player[i].effective_action); #endif for (i = 0; i < MAX_PLAYERS; i++) @@ -11673,19 +11672,18 @@ static void GameActionsExt(void) stored_player[i].effective_action = mapped_action[i]; #if DEBUG_PLAYER_ACTIONS - Print(" =>"); + DebugContinued("", "=> "); for (i = 0; i < MAX_PLAYERS; i++) - Print(" %d, ", stored_player[i].effective_action); - Print("\n"); + DebugContinued("", "%d, ", stored_player[i].effective_action); + DebugContinued("game:playing:player", "\n"); #endif } #if DEBUG_PLAYER_ACTIONS else { - Print(":::"); for (i = 0; i < MAX_PLAYERS; i++) - Print(" %d, ", stored_player[i].effective_action); - Print("\n"); + DebugContinued("", "%d, ", stored_player[i].effective_action); + DebugContinued("game:playing:player", "\n"); } #endif #endif diff --git a/src/libgame/misc.c b/src/libgame/misc.c index a09bc20e..e499e77a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -363,6 +363,38 @@ static void Log(int log_level, char *mode, char *format, ...) va_end(ap); } +void DebugContinued(char *mode, char *format, ...) +{ + static char message[MAX_LINE_LEN] = { 0 }; + + // initialize message (optional) + if (strEqual(format, "")) + { + message[0] = '\0'; + + return; + } + + char *message_ptr = message + strlen(message); + int size_left = MAX_LINE_LEN - strlen(message); + va_list ap; + + // append message + va_start(ap, format); + vsnprintf(message_ptr, size_left, format, ap); + va_end(ap); + + // finalize message + if (strSuffix(format, "\n")) + { + message[strlen(message) - 1] = '\0'; + + Debug(mode, message); + + message[0] = '\0'; + } +} + void Debug(char *mode, char *format, ...) { va_list ap; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 1c51888f..d9cc4e7b 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -106,6 +106,7 @@ void PrintNoLog(char *, ...); void PrintLine(char *, int); void PrintLineWithPrefix(char *, char *, int); +void DebugContinued(char *, char *, ...); void Debug(char *, char *, ...); void Info(char *, ...); void Warn(char *, ...); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 4b28476a..9f82d3a0 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1361,18 +1361,18 @@ void dumpTreeInfo(TreeInfo *node, int depth) { int i; - Print("Dumping TreeInfo:\n"); + Debug("tree", "Dumping TreeInfo:"); while (node) { for (i = 0; i < (depth + 1) * 3; i++) - Print(" "); + DebugContinued("", " "); - Print("'%s' / '%s'\n", node->identifier, node->name); + DebugContinued("tree", "'%s' / '%s'\n", node->identifier, node->name); /* // use for dumping artwork info tree - Print("subdir == '%s' ['%s', '%s'] [%d])\n", + Debug("tree", "subdir == '%s' ['%s', '%s'] [%d])", node->subdir, node->fullpath, node->basepath, node->in_user_dir); */ diff --git a/src/netserv.c b/src/netserv.c index 1f0663fd..636fbf23 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -385,19 +385,19 @@ void dumpNetworkBuffer(struct NetworkBuffer *nb) { int i; - Print("::: network buffer maximum size: %d\n", nb->max_size); - Print("::: network buffer size: %d\n", nb->size); - Print("::: network buffer position : %d\n", nb->pos); + Debug("network:buffer", "network buffer maximum size: %d\n", nb->max_size); + Debug("network:buffer", "network buffer size: %d\n", nb->size); + Debug("network:buffer", "network buffer position : %d\n", nb->pos); for (i = 0; i < nb->size; i++) { if ((i % 16) == 0) - Print("\n::: "); + DebugContinued("network:buffer", "\n"); - Print("%02x ", nb->buffer[i]); + DebugContinued("", "%02x ", nb->buffer[i]); } - Print("\n"); + DebugContinued("network:buffer", "\n"); } static void SendNetworkBufferToAllButOne(struct NetworkBuffer *nb, diff --git a/src/tape.c b/src/tape.c index ac96ef96..9f815143 100644 --- a/src/tape.c +++ b/src/tape.c @@ -894,10 +894,10 @@ byte *TapePlayAction(void) action[i] = tape.pos[tape.counter].action[i]; #if DEBUG_TAPE_WHEN_PLAYING - Print("%05d", FrameCounter); + DebugContinued("", "%05d", FrameCounter); for (i = 0; i < MAX_TAPE_ACTIONS; i++) - Print(" %08x", action[i]); - Print("\n"); + DebugContinued("", " %08x", action[i]); + DebugContinued("tape:play", "\n"); #endif tape.set_centered_player = FALSE;