gnome-games r7393 - trunk/aisleriot



Author: chpe
Date: Tue Feb 19 13:00:10 2008
New Revision: 7393
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7393&view=rev

Log:
2008-02-19  Christian Persch  <chpe gnome org>

	* game.c: (set_game_state), (update_statistics),
	(aisleriot_game_init), (aisleriot_game_finalize),
	(aisleriot_game_set_paused): Stop the game time when the game is over.
	Fixes bug #514239.

Modified:
   trunk/aisleriot/ChangeLog
   trunk/aisleriot/game.c

Modified: trunk/aisleriot/game.c
==============================================================================
--- trunk/aisleriot/game.c	(original)
+++ trunk/aisleriot/game.c	Tue Feb 19 13:00:10 2008
@@ -62,7 +62,7 @@
   guint32 seed;
   guint delayed_call_timeout_id;
 
-  time_t start_time;
+  GTimer *timer;
 
   double width;
   double height;
@@ -141,8 +141,11 @@
     game->state = state;
 
     if (state == GAME_RUNNING) {
-      /* Record start time */
-      game->start_time = time (NULL);
+      /* Reset the timer */
+      g_timer_start (game->timer);
+    } else if (state >= GAME_OVER) {
+      /* Stop the timer now so we will record the right time. See bug #FIXME */
+      g_timer_stop (game->timer);
     }
 
     g_object_notify (G_OBJECT (game), "state");
@@ -210,12 +213,7 @@
   if (game->state == GAME_WON) {
     current_stats.wins++;
 
-    if (game->paused) {
-      t = game->start_time;
-    } else {
-      t = time (NULL) - game->start_time;
-    }
-
+    t = (time_t) (g_timer_elapsed (game->timer, NULL) + 0.5);
     if (t > 0) {
       if ((current_stats.best == 0) || (t < current_stats.best)) {
 	current_stats.best = t;
@@ -1108,6 +1106,8 @@
 
   game->slots = g_ptr_array_sized_new (SLOT_CARDS_N_PREALLOC);
 
+  game->timer = g_timer_new ();
+
   game->timeout = 60 * 60;
 }
 
@@ -1145,6 +1145,8 @@
 
   g_free (game->game_file);
 
+  g_timer_destroy (game->timer);
+
   app_game = NULL;
 
   G_OBJECT_CLASS (aisleriot_game_parent_class)->finalize (object);
@@ -1419,8 +1421,11 @@
 
   game->paused = paused;
 
-  /* (Re)store the start time */
-  game->start_time = time (NULL) - game->start_time;
+  if (paused) {
+    g_timer_stop (game->timer);
+  } else {
+    g_timer_continue (game->timer);
+  }
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]