[Tux4kids-commits] r1087 - tuxmath/trunk/src

Tim Holy tholy-guest at alioth.debian.org
Wed Jun 24 03:42:56 UTC 2009


Author: tholy-guest
Date: 2009-06-24 03:42:55 +0000 (Wed, 24 Jun 2009)
New Revision: 1087

Modified:
   tuxmath/trunk/src/fileops.c
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/mathcards.c
   tuxmath/trunk/src/mathcards.h
   tuxmath/trunk/src/setup.c
Log:
Put quite a lot of code under the new debug controls. Now there is much less command-line output when running TuxMath.


Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c	2009-06-24 02:23:28 UTC (rev 1086)
+++ tuxmath/trunk/src/fileops.c	2009-06-24 03:42:55 UTC (rev 1087)
@@ -1967,6 +1967,8 @@
   char filepath1[PATH_MAX];
   char filepath2[PATH_MAX];
 
+  DEBUGMSG(debug_fileops,"Entering write_pregame_summary.\n")
+
   /* Make sure tuxmath dir exists or can be created: */
   if (!find_tuxmath_dir())
   {
@@ -1986,9 +1988,7 @@
   fp = fopen(filepath1, "r");
   if (fp)
   {
-    #ifdef TUXMATH_DEBUG
-    printf("\nIn write_pregame_summary() - removing oldest summary file\n");
-    #endif
+    DEBUGMSG(debug_fileops,"\nIn write_pregame_summary() - removing oldest summary file\n")
 
     fclose(fp);
     remove(filepath1);
@@ -2038,10 +2038,12 @@
     fprintf(fp, "\n\nNumber of Questions: %d", MC_StartingListLength());
 
     fclose(fp);
+    DEBUGMSG(debug_fileops,"Leaving write_pregame_summary.\n")
     return 1;
   }
   else /* Couldn't write file for some reason: */
   {
+    DEBUGMSG(debug_fileops,"Can't write_pregame_summary.\n")
     return 0;
   }
 }

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2009-06-24 02:23:28 UTC (rev 1086)
+++ tuxmath/trunk/src/game.c	2009-06-24 03:42:55 UTC (rev 1087)
@@ -186,10 +186,8 @@
 
 void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
 
-#ifdef TUXMATH_DEBUG
 static void print_exit_conditions(void);
 static void print_status(void);
-#endif
 
 /* --- MAIN GAME FUNCTION!!! --- */
 
@@ -296,9 +294,7 @@
   while(GAME_IN_PROGRESS == game_status);
   /* END OF MAIN GAME LOOP! */
 
-#ifdef TUXMATH_DEBUG
-  print_exit_conditions();
-#endif
+  DEBUGCODE(debug_game) print_exit_conditions();
 
   /* TODO: need better "victory" screen with animation, special music, etc., */
   /* as well as options to review missed questions, play again using missed  */
@@ -386,9 +382,7 @@
 
     case GAME_OVER_ERROR:
     {
-#ifdef TUXMATH_DEBUG
       printf("\ngame() exiting with error");
-#endif
     }
     case GAME_OVER_LOST:
     case GAME_OVER_OTHER:
@@ -484,7 +478,7 @@
 {
   int i,img;
   
-  tmdprintf("Entering game_initialize()\n");
+  DEBUGMSG(debug_game,"Entering game_initialize()\n");
 
   /* Clear window: */
   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -501,10 +495,10 @@
   /* (for example) to all math operations being deselected */
   if (!MC_StartGame())
   {
-    tmdprintf("\nMC_StartGame() failed!");
     fprintf(stderr, "\nMC_StartGame() failed!");
     return 0;
   }
+  DEBUGMSG(debug_mathcards | debug_game,"MC_StartGame() finished.\n")
 
   /* Allocate memory */
   comets = NULL;  // set in case allocation fails partway through
@@ -530,7 +524,9 @@
         }
       }
   }
-  
+
+  DEBUGMSG(debug_game,"Flashcards allocated.\n");
+
   cities = (city_type *) malloc(NUM_CITIES * sizeof(city_type));
   if (cities == NULL) {
     printf("Allocation of cities failed");
@@ -553,7 +549,7 @@
   {
     write_pregame_summary();
   }
-
+  
   /* Prepare to start the game: */
   city_expl_height = screen->h - images[IMG_CITY_BLUE]->h;
 
@@ -619,7 +615,7 @@
 
   if (Opts_BonusCometInterval()) {
     bonus_comet_counter = Opts_BonusCometInterval() + 1;
-    tmdprintf("\nInitializing with bonus_comet_counter = %d\n",bonus_comet_counter);
+    DEBUGMSG(debug_game,"\nInitializing with bonus_comet_counter = %d\n",bonus_comet_counter)
   }
   extra_life_earned = 0;
   cloud.status = EXTRA_LIFE_OFF;
@@ -656,6 +652,8 @@
   help_controls.extra_life_is_blinking = 0;
   help_controls.laser_enabled = 1;
 
+  DEBUGMSG(debug_game,"Exiting game_initialize()\n");
+
   return 1;
 }
 
@@ -1247,7 +1245,6 @@
   s2.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
   s3.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
   s4.alpha -= SDL_ALPHA_OPAQUE / LEVEL_START_WAIT_START;
-  tmdprintf("alpha = %d\n", s1.alpha);
 
   level_start_wait--;
   if (level_start_wait > LEVEL_START_WAIT_START / 4)
@@ -1857,13 +1854,13 @@
     fgcolor = SDL_MapRGB(screen->format, 64, 96, 64);
   if (old_wave != wave)
   {
-    tmdprintf("Wave %d\n", wave);
+    DEBUGMSG(debug_game,"Wave %d\n", wave)
     old_wave = wave;
     bgcolor = SDL_MapRGB(screen->format,
                          64,
                          64 + ((wave * 32) % 192),
                          128 - ((wave * 16) % 128) );
-    tmdprintf("Filling screen with color %d\n", bgcolor);
+    DEBUGMSG(debug_game,"Filling screen with color %d\n", bgcolor);
   }
 
   if (current_bkgd() == NULL || (current_bkgd()->w != screen->w && 
@@ -2226,7 +2223,7 @@
         user_quit_received != GAME_OVER_ESCAPE &&
         user_quit_received != GAME_OVER_CHEATER)
     {
-    	 tmdprintf("Unexpected value %d for user_quit_received\n", user_quit_received);
+    	 fprintf(stderr,"Unexpected value %d for user_quit_received\n", user_quit_received);
     	 return GAME_OVER_OTHER;
     }
     return user_quit_received;    
@@ -2245,7 +2242,7 @@
   /* determine if game won (i.e. all questions in mission answered correctly): */
   if (MC_MissionAccomplished())
   {
-    tmdprintf("Mission accomplished!\n");
+    DEBUGMSG(debug_game,"Mission accomplished!\n");
     return GAME_OVER_WON;
   }
 
@@ -2279,7 +2276,6 @@
   return GAME_IN_PROGRESS;
 }
 
-#ifdef TUXMATH_DEBUG
 void print_exit_conditions(void)
 {
   printf("\ngame_status:\t");
@@ -2329,7 +2325,6 @@
     }
   }
 }
-#endif
 
 /* Reset stuff for the next level! */
 void reset_level(void)
@@ -3368,7 +3363,7 @@
 void add_score(int inc)
 {
   score += inc;
-  tmdprintf("Score is now: %d\n", score);
+  DEBUGMSG(debug_game,"Score is now: %d\n", score)
 }
 
 
@@ -3431,7 +3426,7 @@
   int i, img;
   int old_city_expl_height = city_expl_height;
 
-  tmdprintf("Recalculating positions\n");
+  DEBUGMSG(debug_game,"Recalculating positions\n")
 
   if (Opts_GetGlobalOpt(USE_IGLOOS))
     img = IMG_IGLOO_INTACT;
@@ -3445,7 +3440,7 @@
     {
       cities[i].x = (((screen->w / (NUM_CITIES + 1)) * i) +
                      ((images[img] -> w) / 2));
-      tmdprintf("%d,", cities[i].x);
+      DEBUGMSG(debug_game,"%d,", cities[i].x)
     }
     else
     {
@@ -3453,7 +3448,7 @@
                    (screen->w / (NUM_CITIES + 1) *
                    (i - NUM_CITIES / 2) +
                     images[img]->w / 2);
-      tmdprintf("%d,", cities[i].x);
+      DEBUGMSG(debug_game,"%d,", cities[i].x);
     }
 
     penguins[i].x = cities[i].x;

Modified: tuxmath/trunk/src/mathcards.c
===================================================================
--- tuxmath/trunk/src/mathcards.c	2009-06-24 02:23:28 UTC (rev 1086)
+++ tuxmath/trunk/src/mathcards.c	2009-06-24 03:42:55 UTC (rev 1087)
@@ -22,6 +22,7 @@
 #include <math.h>
 #include <time.h>
 
+#include "globals.h"
 #include "mathcards.h"
 
 /* extern'd constants */
@@ -231,12 +232,10 @@
 void print_vect_list(FILE* fp, MC_MathQuestion** vect, int length);
 
 /* these functions are dead code unless compiling with debug turned on: */
-#ifdef MC_DEBUG
 static void print_card(MC_FlashCard card);
 static void print_counters(void);
 //static MC_MathQuestion* create_node_copy(MC_MathQuestion* other);
 //static MC_FlashCard    create_card_from_node(MC_MathQuestion* node);
-#endif
 
 /* Functions for new mathcards architecture */
 static void free_node(MC_MathQuestion* mq); //wrapper for free() that also frees card
@@ -267,11 +266,11 @@
   if (initialized)
   {
 
-    #ifdef MC_DEBUG
-    printf("\nAlready initialized");
-    MC_PrintMathOptions(stdout, 0);
-    printf("\nLeaving MC_Initialize()\n");
-    #endif
+    if (debug_status & debug_mathcards) {
+      printf("\nAlready initialized");
+      MC_PrintMathOptions(stdout, 0);
+      printf("\nLeaving MC_Initialize()\n");
+    }
 
     return 1;
   }
@@ -301,10 +300,10 @@
 
   initialized = 1;
 
-  #ifdef MC_DEBUG
-  MC_PrintMathOptions(stdout, 0);
-  printf("\nLeaving MC_Initialize()\n");
-  #endif
+  if (debug_status & debug_mathcards) {
+    MC_PrintMathOptions(stdout, 0);
+    printf("\nLeaving MC_Initialize()\n");
+  }
 
   return 1;
 }
@@ -378,9 +377,9 @@
   answered_wrong = 0;
   questions_pending = 0;
 
-  #ifdef MC_DEBUG
-  print_counters();
-  #endif
+  if (debug_status & debug_mathcards) {
+    print_counters();
+  }
 
   /* make sure list now exists and has non-zero length: */
   if (question_list && quest_list_length)
@@ -437,11 +436,11 @@
     answered_wrong = 0;
     questions_pending = 0;
 
-    #ifdef MC_DEBUG
-    print_counters();
-    print_list(stdout, question_list);
-    printf("\nLeaving MC_StartGameUsingWrongs()\n");
-    #endif
+    if (debug_status & debug_mathcards) {
+      print_counters();
+      print_list(stdout, question_list);
+      printf("\nLeaving MC_StartGameUsingWrongs()\n");
+    }
 
     return 1;
   }
@@ -497,12 +496,12 @@
   quest_list_length--;
   questions_pending++;
 
-  #ifdef MC_DEBUG
-  printf("\nnext question is:");
-  print_card(*fc);
-  print_counters();
-  printf("\n\nLeaving MC_NextQuestion()\n");
-  #endif
+  if (debug_status & debug_mathcards) {
+    printf("\nnext question is:");
+    print_card(*fc);
+    print_counters();
+    printf("\n\nLeaving MC_NextQuestion()\n");
+  }
 
   return 1;
 }
@@ -524,10 +523,10 @@
     return 0;
   }
 
-  #ifdef MC_DEBUG
-  printf("\nQuestion was:");
-  print_card(*fc);
-  #endif
+  if (debug_status & debug_mathcards) {
+    printf("\nQuestion was:");
+    print_card(*fc);
+  }
 
   answered_correctly++;
   questions_pending--;
@@ -555,10 +554,10 @@
     unanswered--;
   }
 
-  #ifdef MC_DEBUG
-  print_counters();
-  printf("\nLeaving MC_AnsweredCorrectly()\n");
-  #endif
+  if (debug_status & debug_mathcards) {
+    print_counters();
+    printf("\nLeaving MC_AnsweredCorrectly()\n");
+  }
 
   return 1;
 }
@@ -582,10 +581,10 @@
     return 0;
   }
 
-  #ifdef MC_DEBUG
-  printf("\nQuestion was:");
-  print_card(*fc);
-  #endif
+  if (debug_status & debug_mathcards) {
+    printf("\nQuestion was:");
+    print_card(*fc);
+  }
 
   answered_wrong++;
   questions_pending--;
@@ -634,10 +633,10 @@
     unanswered--;
   }
 
-  #ifdef MC_DEBUG
-  print_counters();
-  printf("\nLeaving MC_NotAnswered_Correctly()\n");
-  #endif
+  if (debug_status & debug_mathcards) {
+    print_counters();
+    printf("\nLeaving MC_NotAnswered_Correctly()\n");
+  }
 
   return 1;
 
@@ -696,9 +695,7 @@
       newsize = 100;
     newlist = realloc(time_per_question_list, newsize*sizeof(float));
     if (newlist == NULL) {
-      #ifdef MC_DEBUG
-      printf("\nError: allocation for time_per_question_list failed\n");
-      #endif
+      DEBUGMSG(debug_mathcards,"\nError: allocation for time_per_question_list failed\n");
       return 0;
     }
     time_per_question_list = newlist;
@@ -1134,14 +1131,14 @@
 {
   if (!list)
   {
-    fprintf(fp, "\nprint_list(): list empty or pointer invalid\n");
+    fprintf(stderr, "\nprint_list(): list empty or pointer invalid\n");
     return;
   }
 
   MC_MathQuestion* ptr = list;
   while (ptr)
   {
-    fprintf(stderr, "%s\n", ptr->card.formula_string);
+    fprintf(fp, "%s\n", ptr->card.formula_string);
     ptr = ptr->next;
   }
 }
@@ -1162,7 +1159,6 @@
   mcdprintf("Leaving print_vect_list()\n");
 }
 
-#ifdef MC_DEBUG
 void print_card(MC_FlashCard card)
 {
   printf("\nprint_card():");
@@ -1207,7 +1203,6 @@
 //   copy_card(&(node->card), &fc);
 //   return fc;
 // }
-#endif
 
 int list_length(MC_MathQuestion* list)
 {
@@ -1505,9 +1500,9 @@
                     +  MC_GetOpt(MIN_FORMULA_NUMS);
     mcdprintf(" of length %d", length);
     ret = generate_random_ooo_card_of_length(length, 1);
-    #ifdef MC_DEBUG
-    print_card(ret);
-    #endif
+    if (debug_status & debug_mathcards) {
+      print_card(ret);
+    }
   }
   //TODO comparison problems (e.g. "6 ? 9", "<")
 
@@ -1711,7 +1706,8 @@
   MC_MathQuestion* end_of_list = NULL;
   MC_MathQuestion* tnode = NULL;
 
-  MC_PrintMathOptions(stdout, 0);
+  if (debug_status & debug_mathcards)
+    MC_PrintMathOptions(stdout, 0);
   if (!(MC_GetOpt(ARITHMETIC_ALLOWED) ||
       MC_GetOpt(TYPING_PRACTICE_ALLOWED) ||
       MC_GetOpt(COMPARISON_ALLOWED) ) )

Modified: tuxmath/trunk/src/mathcards.h
===================================================================
--- tuxmath/trunk/src/mathcards.h	2009-06-24 02:23:28 UTC (rev 1086)
+++ tuxmath/trunk/src/mathcards.h	2009-06-24 03:42:55 UTC (rev 1087)
@@ -15,12 +15,12 @@
 #ifndef MATHCARDS_H
 #define MATHCARDS_H
 
-#define MC_DEBUG
-#ifdef MC_DEBUG
-#define mcdprintf(...) printf(__VA_ARGS__)
-#else
-#define mcdprintf(...) 0
-#endif
+//#define MC_DEBUG
+//#ifdef MC_DEBUG
+#define mcdprintf(...) DEBUGMSG(debug_mathcards,__VA_ARGS__)
+//#else
+//#define mcdprintf(...) 0
+//#endif
 
 #define MC_USE_NEWARC
 

Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c	2009-06-24 02:23:28 UTC (rev 1086)
+++ tuxmath/trunk/src/setup.c	2009-06-24 03:42:55 UTC (rev 1087)
@@ -489,6 +489,7 @@
     }
   }/* end of command-line args */
 
+  DEBUGMSG(debug_setup,"debug_status: %x", debug_status);
 
   if (Opts_DemoMode() && Opts_GetGlobalOpt(USE_KEYPAD))
   {




More information about the Tux4kids-commits mailing list