[gnome-games/gnibbles-clutter] Changing & loading new level properly, code clean up & minor tweak



commit 7ccf130274f195dc041fb00f65b954a67ccd575d
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Thu Aug 13 23:21:38 2009 -0400

    Changing & loading new level properly, code clean up & minor tweak

 gnibbles/board.c       |    8 ++-
 gnibbles/boni.c        |    4 +-
 gnibbles/main.c        |  121 +++++++++++++++++++++++++-----------------------
 gnibbles/main.h        |    8 ++--
 gnibbles/warpmanager.c |    4 +-
 5 files changed, 78 insertions(+), 67 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index f6703af..b8294ba 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -92,9 +92,11 @@ gnibbles_board_load_level (GnibblesBoard *board)
   ClutterActor *tmp;  
   gboolean is_wall = TRUE;
 
-  if (board->level)
-    g_object_unref (board->level);
-
+  if (board->level) {
+    clutter_group_remove_all (CLUTTER_GROUP (board->level));
+    clutter_container_remove_actor (CLUTTER_CONTAINER (stage), board->level);
+  }
+  
   board->level = clutter_group_new ();
 
   /* Load wall_pixmaps onto the surface*/
diff --git a/gnibbles/boni.c b/gnibbles/boni.c
index ccec913..c896bce 100644
--- a/gnibbles/boni.c
+++ b/gnibbles/boni.c
@@ -60,8 +60,10 @@ gnibbles_boni_destroy (GnibblesBoni * boni)
 {
   int i;
 
-  for (i = 0; i < boni->numbonuses; i++)
+  for (i = 0; i < boni->numbonuses; i++) {
+    clutter_actor_hide (boni->bonuses[i]->actor);
     free (boni->bonuses[i]);
+  }
   boni->numbonuses = 0;
   free (boni);
 }
diff --git a/gnibbles/main.c b/gnibbles/main.c
index f4b4a7a..2cfd585 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -315,7 +315,7 @@ configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
 }
 
 #ifdef GGZ_CLIENT
-static gint
+static gboolean
 network_loop (gpointer data)
 {
   if (ggz_network_mode) { 
@@ -325,7 +325,7 @@ network_loop (gpointer data)
 }
 #endif
 
-static gint
+static gboolean
 new_game_2_cb (GtkWidget * widget, gpointer data)
 {
   if (!paused) {
@@ -356,10 +356,10 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
 
   dummy_id = 0;
 
-  return (FALSE);
+  return FALSE;
 }
 
-gint
+gboolean
 new_game (void)
 {
   gtk_action_set_sensitive (new_network_action, FALSE);
@@ -425,7 +425,7 @@ new_game_cb (GtkAction * action, gpointer data)
   new_game ();
 }
 
-gint
+gboolean
 pause_game_cb (GtkAction * action, gpointer data)
 {
   if (paused) {
@@ -439,7 +439,7 @@ pause_game_cb (GtkAction * action, gpointer data)
 	      main_id = 0;
       }
       if (keyboard_id) {
-	      g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+	      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
 	      keyboard_id = 0;
       }
       if (add_bonus_id) {
@@ -472,7 +472,7 @@ end_game (gboolean show_splash)
   }
 
   if (keyboard_id) {
-    g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+    g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
     keyboard_id = 0;
   }
 
@@ -510,7 +510,7 @@ end_game (gboolean show_splash)
 
 }
 
-static gint
+static gboolean
 end_game_cb (GtkAction * action, gpointer data)
 {
 
@@ -522,22 +522,24 @@ end_game_cb (GtkAction * action, gpointer data)
 #endif
 
   end_game (TRUE);
-  return (FALSE);
+  return FALSE;
 }
 
-static gint
+static gboolean
 add_bonus_cb (gpointer data)
 {
   gnibbles_board_level_add_bonus (board, 0);
-  return (TRUE);
+  return TRUE;
 }
 
-static gint
+static gboolean
 restart_game (gpointer data)
 {
+  int i;
+
   gnibbles_board_level_new (board, current_level);
   gnibbles_board_level_add_bonus (board, 1);
-  int i;
+  
   for (i = 0; i < properties->numworms; i++) {
     clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
     gnibbles_worm_show (worms[i]);
@@ -552,7 +554,7 @@ restart_game (gpointer data)
   return FALSE;
 }
 
-static gint
+static gboolean
 erase_worms_cb (gpointer datap)
 {
   gint data = GPOINTER_TO_INT (datap);
@@ -568,10 +570,10 @@ erase_worms_cb (gpointer datap)
                   			      GINT_TO_POINTER (data - 1));
   }
 
-  return (FALSE);
+  return FALSE;
 }
 
-gint
+gboolean
 main_loop (gpointer data)
 {
   gint status;
@@ -584,6 +586,7 @@ main_loop (gpointer data)
   if (status == VICTORY) {
     end_game (TRUE);
     winner = gnibbles_get_winner ();
+
     if (winner == -1)
       return FALSE;
 
@@ -595,16 +598,16 @@ main_loop (gpointer data)
     g_free (str);
 
     if (keyboard_id) {
-      g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
       keyboard_id = 0;
     }
     if (main_id) {
       g_source_remove (main_id);
       main_id = 0;
     }
-    if (add_bonus_id) {
+    if (add_bonus_id) 
       g_source_remove (add_bonus_id);
-    }
+
     add_bonus_id = 0;
     erase_id = g_timeout_add_seconds (3,
 			                                (GSourceFunc) erase_worms_cb,
@@ -617,13 +620,13 @@ main_loop (gpointer data)
   if (status == GAMEOVER) {
 
     if (keyboard_id) {
-      g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
       keyboard_id = 0;
     }
     main_id = 0;
-    if (add_bonus_id) {
+    if (add_bonus_id)
       g_source_remove (add_bonus_id);
-    }
+    
     add_bonus_id = 0;
     erase_id = g_timeout_add_seconds (3,
 			                                (GSourceFunc) erase_worms_cb,
@@ -632,7 +635,38 @@ main_loop (gpointer data)
     return (FALSE);
   }
 
+  if (boni->numleft == 0) {
+    if (restart_id)
+      return TRUE;
+
+    if (keyboard_id) 
+      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
+
+    keyboard_id = 0;
+
+    if (add_bonus_id)
+      g_source_remove (add_bonus_id);
+
+    add_bonus_id = 0;
+    if (main_id) {
+      g_source_remove (main_id);
+      main_id = 0;
+    }
+    if ((current_level < MAXLEVEL) && (!properties->random
+				                               || ggz_network_mode)) {
+      current_level++;
+    } else if (properties->random && !ggz_network_mode) {
+      tmp = rand () % MAXLEVEL + 1;
+      while (tmp == current_level)
+	      tmp = rand () % MAXLEVEL + 1;
+      current_level = tmp;
+    }
+    restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
+    return FALSE;
+  }
+
   if (status == NEWROUND) {
+
 #ifdef GGZ_CLIENT
     if (ggz_network_mode) {
       end_game (TRUE);
@@ -642,54 +676,25 @@ main_loop (gpointer data)
 #endif
 
     if (keyboard_id) {
-      g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+      g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
       keyboard_id = 0;
     }
-    if (add_bonus_id) {
+    if (add_bonus_id)
       g_source_remove (add_bonus_id);
-    }
+    
     if (main_id) {
       g_source_remove (main_id);
       main_id = 0;
     }
     add_bonus_id = 0;
     erase_id = g_timeout_add (ERASETIME / ERASESIZE,
-			      (GSourceFunc) erase_worms_cb,
-			      (gpointer) ERASESIZE);
+			                       (GSourceFunc) erase_worms_cb,
+			                       (gpointer) ERASESIZE);
     restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
-    return (FALSE);
-  }
-
-  if (boni->numleft == 0) {
-    if (restart_id) {
-      return TRUE;
-    }
-    if (keyboard_id) {
-      g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
-    }
-    keyboard_id = 0;
-    if (add_bonus_id) {
-      g_source_remove (add_bonus_id);
-    }
-    add_bonus_id = 0;
-    if (main_id) {
-      g_source_remove (main_id);
-      main_id = 0;
-    }
-    if ((current_level < MAXLEVEL) && (!properties->random
-				                               || ggz_network_mode))
-      current_level++;
-    else if (properties->random && !ggz_network_mode) {
-      tmp = rand () % MAXLEVEL + 1;
-      while (tmp == current_level)
-	      tmp = rand () % MAXLEVEL + 1;
-      current_level = tmp;
-    }
-    restart_id = g_timeout_add_seconds (1, (GSourceFunc) restart_game, NULL);
-    return (FALSE);
+    return FALSE;
   }
 
-  return (TRUE);
+  return TRUE;
 }
 
 static gboolean
diff --git a/gnibbles/main.h b/gnibbles/main.h
index 66a2076..c904a18 100644
--- a/gnibbles/main.h
+++ b/gnibbles/main.h
@@ -36,12 +36,12 @@ int seat;
 int seats[NUMWORMS];
 char names[NUMWORMS][17];
 
-gint game_running (void);
-gint pause_game_cb (GtkAction * action, gpointer data);
+gboolean game_running (void);
+gboolean pause_game_cb (GtkAction * action, gpointer data);
 void end_game (gboolean);
 
-gint new_game (void);
-gint main_loop (gpointer data);
+gboolean new_game (void);
+gboolean main_loop (gpointer data);
 
 extern GamesScores *highscores;
 extern GtkWidget *notebook;
diff --git a/gnibbles/warpmanager.c b/gnibbles/warpmanager.c
index 1a4078e..9d34622 100644
--- a/gnibbles/warpmanager.c
+++ b/gnibbles/warpmanager.c
@@ -58,8 +58,10 @@ gnibbles_warpmanager_destroy (GnibblesWarpManager * warpmanager)
 {
   gint i;
 
-  for (i = 0; i < warpmanager->numwarps; i++)
+  for (i = 0; i < warpmanager->numwarps; i++) {
+    clutter_actor_hide (warpmanager->warps[i]->actor);
     free (warpmanager->warps[i]);
+  }
   warpmanager->numwarps = 0;
   free (warpmanager);
 }



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