gnome-games r8813 - trunk/aisleriot



Author: nroberts
Date: Sun Mar  8 20:33:38 2009
New Revision: 8813
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8813&view=rev

Log:
[aisleriot] Avoid drawing unexposed cards that are being moved

When detecting animations it would previously only check exposed cards
at the top of the slot. However sometimes unexposed cards can be moved
as well, such as when the waste slot is flipped over to the draw slot
in Canfield. The unexposed cards were just being moved instantly while
the exposed cards were animated. Now it keeps track of the number of
exposed cards that have moved and doesn't draw them during an
animation so that it should appear as if they are being moved with the
exposed cards.

Modified:
   trunk/aisleriot/board.c
   trunk/aisleriot/slot-renderer.c
   trunk/aisleriot/slot-renderer.h

Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c	(original)
+++ trunk/aisleriot/board.c	Sun Mar  8 20:33:38 2009
@@ -896,6 +896,10 @@
   }
 
   for (slot_num = 0; slot_num < slots->len; slot_num++) {
+    /* Number of extra cards that aren't visible to include in the
+       animation */
+    guint n_unexposed_animated_cards = 0;
+
     slot = slots->pdata[slot_num];
 
     g_array_set_size (animations, 0);
@@ -956,11 +960,22 @@
           }
         }
       }
+
+      /* Check if any extra unexposed cards are included in the
+         animation. There's no point in drawing these because they
+         will be hidden by the exposed cards but we don't want to draw
+         them at the slot either. This will for example happen in
+         Canfield when the discard pile is flipped over into the draw
+         pile */
+      if (animations->len == slot->exposed)
+        n_unexposed_animated_cards = (slot->cards->len - slot->old_cards->len
+                                      - slot->exposed);
     }
 
     aisleriot_slot_renderer_set_animations
       (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
-       animations->len, (const AisleriotAnimStart *) animations->data);
+       animations->len, (const AisleriotAnimStart *) animations->data,
+       n_unexposed_animated_cards);
 
     /* Set the old cards back to the new cards */
     aisleriot_game_reset_old_cards (slot);
@@ -1033,7 +1048,7 @@
   }
 
   aisleriot_slot_renderer_set_animations
-    (AISLERIOT_SLOT_RENDERER (slot->slot_renderer), 0, NULL);
+    (AISLERIOT_SLOT_RENDERER (slot->slot_renderer), 0, NULL, 0);
 
   aisleriot_slot_renderer_set_highlight
     (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),

Modified: trunk/aisleriot/slot-renderer.c
==============================================================================
--- trunk/aisleriot/slot-renderer.c	(original)
+++ trunk/aisleriot/slot-renderer.c	Sun Mar  8 20:33:38 2009
@@ -72,6 +72,7 @@
   ClutterTimeline *timeline;
   guint completed_handler;
   GArray *animations;
+  guint n_unexposed_animated_cards;
 
   ClutterContainer *animation_layer;
 };
@@ -201,7 +202,7 @@
   aisleriot_slot_renderer_set_cache (self, NULL);
 
   /* Get rid of any running animations */
-  aisleriot_slot_renderer_set_animations (self, 0, NULL);
+  aisleriot_slot_renderer_set_animations (self, 0, NULL, 0);
 
   if (priv->timeline) {
     g_object_unref (priv->timeline);
@@ -376,7 +377,7 @@
 {
   AisleriotSlotRenderer *srend = (AisleriotSlotRenderer *) actor;
   AisleriotSlotRendererPrivate *priv = srend->priv;
-  guint n_cards;
+  guint n_cards, n_animated_cards;
   guint8 *cards;
   guint i;
 
@@ -385,17 +386,19 @@
 
   cards = priv->slot->cards->data;
   n_cards = priv->slot->cards->len;
+  n_animated_cards = priv->animations->len + priv->n_unexposed_animated_cards;
 
   g_assert (n_cards >= priv->slot->exposed);
-  g_assert (n_cards >= priv->animations->len);
+  g_assert (priv->n_unexposed_animated_cards == 0 || priv->animations->len > 0);
+  g_assert (n_cards >= n_animated_cards);
 
-  if (priv->slot->cards->len <= priv->animations->len) {
+  if (n_cards <= n_animated_cards) {
     CoglHandle cogl_tex;
     guint tex_width, tex_height;
 
     cogl_tex = games_card_textures_cache_get_slot_texture (priv->cache);
     if (G_UNLIKELY (cogl_tex == COGL_INVALID_HANDLE))
-      goto paint_cards;
+      return;
 
     tex_width = cogl_texture_get_width (cogl_tex);
     tex_height = cogl_texture_get_height (cogl_tex);
@@ -415,16 +418,12 @@
                               CLUTTER_INT_TO_FIXED (tex_height),
                               0, 0, CFX_ONE, CFX_ONE);
     }
-  }
-
-paint_cards:
-
-  if (n_cards > priv->animations->len) {
+  } else {
     guint first_card, last_card;
 
-    first_card = MIN (n_cards - priv->animations->len - 1,
+    first_card = MIN (n_cards - n_animated_cards - 1,
                       n_cards - priv->slot->exposed);
-    last_card = n_cards - priv->animations->len;
+    last_card = n_cards - n_animated_cards;
 
     for (i = first_card; i < last_card; i++)
       if (i != priv->revealed_card)
@@ -541,7 +540,8 @@
 void
 aisleriot_slot_renderer_set_animations (AisleriotSlotRenderer *srend,
                                         guint n_anims,
-                                        const AisleriotAnimStart *anims)
+                                        const AisleriotAnimStart *anims,
+                                        guint n_unexposed_animated_cards)
 {
   AisleriotSlotRendererPrivate *priv;
   guint i;
@@ -651,6 +651,8 @@
     clutter_timeline_start (priv->timeline);
   }
 
+  priv->n_unexposed_animated_cards = n_unexposed_animated_cards;
+
   clutter_actor_queue_redraw (CLUTTER_ACTOR (srend));
 }
 
@@ -658,7 +660,7 @@
 completed_cb (AisleriotSlotRenderer *srend)
 {
   /* Get rid of all animation actors */
-  aisleriot_slot_renderer_set_animations (srend, 0, NULL);
+  aisleriot_slot_renderer_set_animations (srend, 0, NULL, 0);
 
   /* Redraw so that the animated actors will be drawn as part of the
      renderer instead */

Modified: trunk/aisleriot/slot-renderer.h
==============================================================================
--- trunk/aisleriot/slot-renderer.h	(original)
+++ trunk/aisleriot/slot-renderer.h	Sun Mar  8 20:33:38 2009
@@ -94,7 +94,8 @@
 
 void aisleriot_slot_renderer_set_animations (AisleriotSlotRenderer *srend,
                                              guint n_anims,
-                                             const AisleriotAnimStart *anims);
+                                             const AisleriotAnimStart *anims,
+                                             guint n_unexposed_animated_cards);
 
 G_END_DECLS
 



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