[Xbubble-commits] xbubble-sdl/src game.c,1.6,1.7

Martin Quinson mquinson at alioth.debian.org
Thu Sep 14 09:05:30 UTC 2006


Update of /cvsroot/xbubble/xbubble-sdl/src
In directory haydn:/tmp/cvs-serv11835

Modified Files:
	game.c 
Log Message:
decorelate the frame duration from the time flow in board animation. This way, if the renderer is too slow to achieve all frames, we still animate the board at the same speed

Index: game.c
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/game.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- game.c	14 Sep 2006 08:57:49 -0000	1.6
+++ game.c	14 Sep 2006 09:05:27 -0000	1.7
@@ -86,6 +86,8 @@
   board_t board[2];
   opponent_t opponent[2];
   ruleset_t ruleset[2];
+   
+  Uint32 lastanimated; /* To keep the board animation smooth even if rendering suffers */
 };
 
 sigjmp_buf restart_thinking;
@@ -176,6 +178,7 @@
   game->mode = mode;
   game->score = score;
   game->round = round;
+  game->lastanimated = SDL_GetTicks();
   for ( i = 0; i < 2; i++ ) {
     game->computer_state[i] = opponent_idle;
     game->computer_thinking_time[i] = COMPUTER_DELAY;
@@ -332,8 +335,13 @@
    }   
 }
 
-static void game_animate( game_t game, int dt ) {
+static void game_animate( game_t game ) {
   int i, color, lost=0;
+   
+  Uint32 now = SDL_GetTicks();
+  Uint32 dt = now - game->lastanimated;
+  game->lastanimated = now;
+   
   for ( i = 0; i < game->nb_boards; i++ ) { 
     board_animate( game->board[i], dt );
     lost = lost || board_get_state( game->board[i] ) == board_state_lost;
@@ -521,7 +529,7 @@
       break;
     }
 
-    game_animate( game, fps_frame_duration );
+    game_animate( game );
 
     /* check if game is not over */
     if ( game->multi_player ) {
@@ -565,6 +573,7 @@
   case game_state_paused:
     if ( game->pause_pressed ) {
       game->state = game_state_playing;
+      game->lastanimated = SDL_GetTicks();
       for ( i = 0; i < game->nb_boards; i++ )
 	game_msg_hide(game);
     }
@@ -578,7 +587,7 @@
 	 ( board_get_state( game->board[1] ) == board_state_frozen )))
       game->state = game_state_finished;
     else
-      game_animate( game, fps_frame_duration );
+      game_animate( game );
     break;
 
   default:




More information about the Xbubble-commits mailing list