improved terminal/logfile output of automatic tape replay (progress/summary)
authorHolger Schemel <info@artsoft.org>
Fri, 3 Feb 2017 19:41:29 +0000 (20:41 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 3 Feb 2017 19:41:29 +0000 (20:41 +0100)
src/libgame/misc.c
src/libgame/misc.h
src/tape.c

index bd069f921a93ad629d1e61e1d0d3995672f59639..0c0e82c2bc45e6621f104f9bd0947e3ff3dfa269 100644 (file)
@@ -222,6 +222,18 @@ void Print(char *format, ...)
   va_end(ap);
 }
 
+void PrintNoLog(char *format, ...)
+{
+  FILE *file = program.log_file_default[LOG_OUT_ID];
+  va_list ap;
+
+  va_start(ap, format);
+  vfprintf(file, format, ap);
+  va_end(ap);
+
+  fflush(file);
+}
+
 void PrintLine(char *line_chars, int line_length)
 {
   int i;
index 1e8f039d3274cc9e6e7472fa6ae1b317c8a63ec2..6c654cb5a5e0666db8344ec7f9d892ba511a3621 100644 (file)
@@ -119,6 +119,7 @@ void printf_line(char *, int);
 void printf_line_with_prefix(char *, char *, int);
 
 void Print(char *, ...);
+void PrintNoLog(char *, ...);
 void PrintLine(char *, int);
 void PrintLineWithPrefix(char *, char *, int);
 
index 8c1e059b15f7d49416749c66cfc5615715aa800b..f0a8f02dce18ea2ae838c46840d7c67a80e7a106 100644 (file)
@@ -455,6 +455,44 @@ void TapeDeactivateDisplayOff(boolean redraw_display)
 }
 
 
+/* ========================================================================= */
+/* tape logging functions                                                    */
+/* ========================================================================= */
+
+void PrintTapeReplayProgress(boolean replay_finished)
+{
+  static unsigned int counter_last = -1;
+  unsigned int counter = Counter();
+  unsigned int counter_seconds  = counter / 1000;
+
+  if (!replay_finished)
+  {
+    unsigned int counter_delay = 50;
+
+    if (counter > counter_last + counter_delay)
+    {
+      PrintNoLog("\r");
+      PrintNoLog("Level %03d [%02d:%02d]: [%02d:%02d] - playing tape ... ",
+                level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
+                TapeTime / 60, TapeTime % 60);
+
+      counter_last = counter;
+    }
+  }
+  else
+  {
+    PrintNoLog("\r");
+    Print("Level %03d [%02d:%02d]: (%02d:%02d.%03d / %.2f %%) - %s.\n",
+         level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
+         counter_seconds / 60, counter_seconds % 60, counter % 1000,
+         (float)counter / tape.length_seconds / 10,
+         tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
+
+    counter_last = -1;
+  }
+}
+
+
 /* ========================================================================= */
 /* tape control functions                                                    */
 /* ========================================================================= */
@@ -854,6 +892,9 @@ byte *TapePlayAction()
     tape.delay_played = 0;
   }
 
+  if (tape.auto_play)
+    PrintTapeReplayProgress(FALSE);
+
   return action;
 }
 
@@ -1052,7 +1093,7 @@ void AutoPlayTape()
   if (autoplay_initialized)
   {
     /* just finished auto-playing tape */
-    Print("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
+    PrintTapeReplayProgress(TRUE);
 
     num_levels_played++;
 
@@ -1109,18 +1150,18 @@ void AutoPlayTape()
 
     TapeErase();
 
-    Print("Level %03d: ", level_nr);
-
     LoadLevel(level_nr);
+
     if (level.no_level_file || level.no_valid_file)
     {
-      Print("(no level)\n");
+      Print("Level %03d: (no level)\n", level_nr);
+
       continue;
     }
 
 #if 0
     /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
-    Print("(only testing level)\n");
+    Print("Level %03d: (only testing level)\n", level_nr);
     continue;
 #endif
 
@@ -1133,12 +1174,12 @@ void AutoPlayTape()
     {
       num_tape_missing++;
 
-      Print("(no tape)\n");
+      Print("Level %03d: (no tape)\n", level_nr);
 
       continue;
     }
 
-    Print("playing tape ... ");
+    InitCounter();
 
     TapeStartGamePlaying();
     TapeStartWarpForward(global.autoplay_mode);