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

David Bruce dbruce-guest at alioth.debian.org
Mon Oct 12 18:50:10 UTC 2009


Author: dbruce-guest
Date: 2009-10-12 18:50:07 +0000 (Mon, 12 Oct 2009)
New Revision: 1585

Modified:
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/mathcards.c
   tuxmath/trunk/src/mathcards.h
   tuxmath/trunk/src/network.c
   tuxmath/trunk/src/network.h
   tuxmath/trunk/src/server.c
   tuxmath/trunk/src/testclient.c
Log:
Support for server-side tracking of answer times, both for LAN and local games

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/game.c	2009-10-12 18:50:07 UTC (rev 1585)
@@ -1408,20 +1408,21 @@
   /* If there was a comet with this answer, destroy it! */
   if (lowest != -1)  /* -1 means no comet had this answer */
   {
+    float t;
+    /* Store the time the question was present on screen (do this */
+    /* in a way that avoids storing it if the time wrapped around */
+    ctime = SDL_GetTicks();
+    if (ctime > comets[lowest].time_started)
+      t = ((float)(ctime - comets[lowest].time_started)/1000);
+    else
+      t = -1;   //Mathcards will ignore t == -1
     /* Tell Mathcards or the server that we answered correctly: */
     if(Opts_LanMode())
-      LAN_AnsweredCorrectly(comets[lowest].flashcard.question_id);
+      LAN_AnsweredCorrectly(comets[lowest].flashcard.question_id, t);
     else
-      MC_AnsweredCorrectly(comets[lowest].flashcard.question_id);
+      MC_AnsweredCorrectly(comets[lowest].flashcard.question_id, t);
 
-    /* Store the time the question was present on screen (do this */
-    /* in a way that avoids storing it if the time wrapped around */
-    ctime = SDL_GetTicks();
-    if (ctime > comets[lowest].time_started) {
-      MC_AddTimeToList((float)(ctime - comets[lowest].time_started)/1000);
-    }
 
-
     /* Destroy comet: */
     comets[lowest].expl = 0;
     comets[lowest].zapped = 1;

Modified: tuxmath/trunk/src/mathcards.c
===================================================================
--- tuxmath/trunk/src/mathcards.c	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/mathcards.c	2009-10-12 18:50:07 UTC (rev 1585)
@@ -512,7 +512,7 @@
 /*  MC_AnsweredCorrectly() is how the user interface      */
 /*  tells MathCards that the question has been answered   */
 /*  correctly. Returns 1 if no errors.                    */
-int MC_AnsweredCorrectly(int id)
+int MC_AnsweredCorrectly(int id, float t)
 {
   DEBUGMSG(debug_mathcards, "\nEntering MC_AnsweredCorrectly()");
 
@@ -576,7 +576,10 @@
     print_counters();
     printf("\nLeaving MC_AnsweredCorrectly()\n");
   }
-  
+
+  /* Record the time it took to answer: */ 
+  MC_AddTimeToList(t);
+
   return 1;
 }
 
@@ -725,6 +728,10 @@
   int newsize = 0;
   float *newlist;
 
+  //Bail if time invalid:
+  if(t < 0)
+    return 0;
+
   /* This list will be allocated in an STL-like manner: when the       */
   /* list gets full, allocate an additional amount of storage equal    */
   /* to the current size of the list, so that only O(logN) allocations */

Modified: tuxmath/trunk/src/mathcards.h
===================================================================
--- tuxmath/trunk/src/mathcards.h	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/mathcards.h	2009-10-12 18:50:07 UTC (rev 1585)
@@ -204,8 +204,9 @@
 
 /*  MC_AnsweredCorrectly() is how the user interface      */
 /*  tells MathCards that the question has been answered   */
-/*  correctly. Returns 1 if no errors.                    */
-int MC_AnsweredCorrectly(int id);
+/*  correctly, and how long the student took to answer.   */
+/*  Returns 1 if no errors.                               */
+int MC_AnsweredCorrectly(int id, float t);
 //int MC_AnsweredCorrectly_id(int id);
 
 /*  MC_NotAnsweredCorrectly() is how the user interface    */

Modified: tuxmath/trunk/src/network.c
===================================================================
--- tuxmath/trunk/src/network.c	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/network.c	2009-10-12 18:50:07 UTC (rev 1585)
@@ -54,7 +54,7 @@
     servers[i].ip.host = 0;
 
   /* Docs say we are supposed to call SDL_Init() before SDLNet_Init(): */
-  if(SDL_Init(0)==-1)
+  if(SDL_Init(0) == -1)
   {
     printf("SDL_Init: %s\n", SDL_GetError());
     return 0;;
@@ -404,10 +404,10 @@
 }
 
 
-int LAN_AnsweredCorrectly(int id)
+int LAN_AnsweredCorrectly(int id, float t)
 {
   char buffer[NET_BUF_LEN];
-  snprintf(buffer, NET_BUF_LEN, "%s\t%d", "CORRECT_ANSWER", id);
+  snprintf(buffer, NET_BUF_LEN, "%s\t%d\t%f", "CORRECT_ANSWER", id, t);
   return say_to_server(buffer);
 }
 

Modified: tuxmath/trunk/src/network.h
===================================================================
--- tuxmath/trunk/src/network.h	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/network.h	2009-10-12 18:50:07 UTC (rev 1585)
@@ -40,7 +40,7 @@
 /* Network replacement functions for mathcards "API": */
 /* These functions are how the client tells things to the server: */
 int LAN_StartGame(void);
-int LAN_AnsweredCorrectly(int id);
+int LAN_AnsweredCorrectly(int id, float t);
 int LAN_NotAnsweredCorrectly(int id);
 int LAN_LeaveGame(void);
 /* This is how the client receives messages from the server: */

Modified: tuxmath/trunk/src/server.c
===================================================================
--- tuxmath/trunk/src/server.c	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/server.c	2009-10-12 18:50:07 UTC (rev 1585)
@@ -799,6 +799,7 @@
   char outbuf[NET_BUF_LEN];
   char* p;
   int id;
+  float t;
 
   if(!inbuf)
     return;
@@ -809,17 +810,24 @@
     return; 
   p++;
   id = atoi(p);
+  //Now get time player took to answer:
+  p = strchr(inbuf, '\t');
+  if(!p)
+    return; 
+  p++;
+  t = atof(p);
 
+
   //Tell mathcards so lists get updated:
-  if(!MC_AnsweredCorrectly(id))
+  if(!MC_AnsweredCorrectly(id, t))
     return;
   //If we get to here, the id was successfully parsed out of inbuf
   //and the corresponding question was found.
 
   //Announcement for server and all clients:
   snprintf(outbuf, NET_BUF_LEN, 
-          "question id %d was answered correctly by %s\n",
-          id, client[i].name);             
+          "question id %d was answered in %f seconds by %s\n",
+          id, t, client[i].name);             
   broadcast_msg(outbuf);
   //Tell all players to remove that question:
   remove_question(id);

Modified: tuxmath/trunk/src/testclient.c
===================================================================
--- tuxmath/trunk/src/testclient.c	2009-10-12 18:49:57 UTC (rev 1584)
+++ tuxmath/trunk/src/testclient.c	2009-10-12 18:50:07 UTC (rev 1585)
@@ -405,7 +405,8 @@
         {  
           printf("%s is correct!\nAwait next question...\n>\n", buf);
           //Tell server we answered it right:
-          LAN_AnsweredCorrectly(fc->question_id);
+          //NOTE the '-1' means we aren't tracking times for testclient
+          LAN_AnsweredCorrectly(fc->question_id, -1);
           erase_flashcard(fc);  
           print_current_quests();
         }




More information about the Tux4kids-commits mailing list