[gnome-games] Fixed some compiler warning, integrating the logic to start a new game



commit 34cc871adc31cab511c6d9c5aba2d3e74b75976e
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Wed Jul 1 23:09:02 2009 -0400

    Fixed some compiler warning, integrating the logic to start a new game
    
    .. and updating my clutter copy once again broke the whole thing, kindof

 gnibbles/board.c    |    4 ++--
 gnibbles/gnibbles.c |   32 +++++++++++++++-----------------
 gnibbles/gnibbles.h |    5 +++--
 gnibbles/level.c    |   24 ++++++++++++++++--------
 gnibbles/main.c     |   42 +++++++++++++++++++++---------------------
 gnibbles/main.h     |    2 +-
 6 files changed, 58 insertions(+), 51 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 329760d..d566c5e 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -61,8 +61,8 @@ gnibbles_board_new (gint t_w, gint t_h)
 
   clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE); 
   clutter_actor_set_size (CLUTTER_ACTOR (stage), 
-                        properties->tilesize * BOARDWIDTH,
-                        properties->tilesize * BOARDHEIGHT);
+                          properties->tilesize * BOARDWIDTH,
+                          properties->tilesize * BOARDHEIGHT);
   clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
   clutter_actor_show (stage);
 
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 3870431..d4b7a3d 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -284,21 +284,14 @@ gnibbles_draw_big_pixmap_buffer (gint which, gint x, gint y)
 }
 
 void
-gnibbles_load_logo (GtkWidget * window)
+gnibbles_load_logo (void)
 {
-  gfloat width; 
-  gfloat height;
-
-  ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
-  clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
-  if (GTK_WIDGET_REALIZED (clutter_board->clutter_widget) == FALSE)
-    return;
-
   if (logo_pixmap)
     g_object_unref (logo_pixmap);
 
   logo_pixmap = gnibbles_clutter_load_pixmap_file ("gnibbles-logo.svg",
-                               			       (gint)width, (gint)height);
+                               			            clutter_board->width, 
+                                                clutter_board->height);
 }
 
 void
@@ -474,24 +467,29 @@ gnibbles_load_level (GtkWidget * window, gint level)
 void
 gnibbles_clutter_init ()
 {
-  gint i;
+  if (clutter_board == NULL)
+    return;
 
+  gint i;
+/*
   for (i = 0; i < properties->numworms; i++)
     if (cworms[i])
       gnibbles_cworm_destroy (cworms[i]);
-
+*/
   gnibbles_scoreboard_clear (scoreboard);
 
   for (i = 0; i < properties->numworms; i++) {
-    worms[i] = gnibbles_worm_new (i);
-    gnibbles_scoreboard_register (scoreboard, worms[i], 
-	                 colorval_name (properties->wormprops[i]->color));
+    //gnibbles_scoreboard_register (scoreboard, cworms[i], 
+	  //               colorval_name (properties->wormprops[i]->color));
   }
 
   ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
+
   for (i = 0; i < properties->numworms; i++) {
-    clutter_container_add_actor (CLUTTER_CONTAINER (stage), cworms[i]->actors);
-    clutter_actor_raise_top (cworms[i]->actors);
+    if (cworms[i]) {
+      clutter_container_add_actor (CLUTTER_CONTAINER (stage), cworms[i]->actors);
+      clutter_actor_raise_top (cworms[i]->actors);
+    }
   }
 
   gnibbles_scoreboard_update (scoreboard);
diff --git a/gnibbles/gnibbles.h b/gnibbles/gnibbles.h
index 75dd1b0..d69402c 100644
--- a/gnibbles/gnibbles.h
+++ b/gnibbles/gnibbles.h
@@ -56,15 +56,16 @@
 #define MAXLEVEL 26
 
 extern GnibblesWarpManager *warpmanager;
-void gnibbles_clutter_init ();
+
 void gnibbles_draw_pixmap (gint which, gint x, gint y);
 void gnibbles_draw_big_pixmap (gint which, gint x, gint y);
 void gnibbles_draw_pixmap_buffer (gint which, gint x, gint y);
 void gnibbles_draw_big_pixmap_buffer (gint which, gint x, gint y);
 void gnibbles_clutter_load_pixmap (gint tilesize);
 void gnibbles_load_pixmap (GtkWidget * window);
-void gnibbles_load_logo ();
+void gnibbles_load_logo (void);
 void gnibbles_load_level (GtkWidget * window, gint level);
+void gnibbles_clutter_init (void);
 void gnibbles_init (void);
 void gnibbles_clutter_add_bonus (gint regular);
 void gnibbles_add_bonus (gint regular);
diff --git a/gnibbles/level.c b/gnibbles/level.c
index 9926801..bc65579 100644
--- a/gnibbles/level.c
+++ b/gnibbles/level.c
@@ -80,23 +80,31 @@ gnibbles_level_new (gint level)
       switch (lvl->walls[j][i]) {
         case 'm':
           lvl->walls[j][i] = EMPTYCHAR;
-          if (count < properties->numworms)
-            cworms[count] = gnibbles_cworm_new (count++, j, i, WORMUP);
+          if (count < properties->numworms) {
+            cworms[count] = gnibbles_cworm_new (count, j, i, WORMUP);
+            count++;
+          }
           break;
         case 'n':
           lvl->walls[j][i] = EMPTYCHAR;
-          if (count < properties->numworms)
-            cworms[count] = gnibbles_cworm_new (count++, j, i, WORMLEFT);
+          if (count < properties->numworms) {
+            cworms[count] = gnibbles_cworm_new (count, j, i, WORMLEFT);
+            count++;
+          }
           break;
         case 'o':
           lvl->walls[j][i] = EMPTYCHAR;
-          if (count < properties->numworms)
-            cworms[count] = gnibbles_cworm_new (count++, j, i, WORMDOWN);
+          if (count < properties->numworms) {
+            cworms[count] = gnibbles_cworm_new (count, j, i, WORMDOWN);
+            count++;
+          }
           break;
         case 'p':
           lvl->walls[j][i] = EMPTYCHAR;
-          if (count < properties->numworms)
-            cworms[count] = gnibbles_cworm_new (count++, j, i, WORMRIGHT);
+          if (count < properties->numworms) {
+            cworms[count] = gnibbles_cworm_new (count, j, i, WORMRIGHT);
+            count++;
+          }
           break;
         case 'Q':
           gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 41f754f..883b4cb 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -115,7 +115,7 @@ NULL};
 
 static gint add_bonus_cb (gpointer data);
 static void render_logo (void);
-static void render_logo_clutter ();
+static void render_logo_clutter (void);
 static gint end_game_cb (GtkAction * action, gpointer data);
 
 static GtkAction *new_game_action;
@@ -346,8 +346,7 @@ configure_clutter_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpoin
   int i;
 
   if (game_running ()) {
-    if (data) {
-      GnibblesBoard *clutter_board = (GnibblesBoard *)data;
+    if (clutter_board) {
       gnibbles_board_resize (clutter_board, tilesize);
       for (i=0; i<properties->numworms; i++)
         gnibbles_cworm_resize (cworms[i], tilesize);
@@ -359,7 +358,7 @@ configure_clutter_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpoin
   /* But, has the tile size changed? */
   if (properties->tilesize == tilesize) {
     /* We must always re-load the logo. */
-    gnibbles_load_logo (window);
+    gnibbles_load_logo ();
     return FALSE;
   }
 
@@ -368,7 +367,7 @@ configure_clutter_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpoin
   properties->tilesize = tilesize;
   gnibbles_properties_set_tile_size (tilesize);
 
-  gnibbles_load_logo (window);
+  gnibbles_load_logo ();
   
   return FALSE;
 }
@@ -400,7 +399,7 @@ configure_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data
   if (properties->tilesize == tilesize) {
 
     /* We must always re-load the logo. */
-    gnibbles_load_logo (window);
+    //gnibbles_load_logo (window);
     return FALSE;
   }
 
@@ -408,7 +407,7 @@ configure_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data
   gnibbles_properties_set_tile_size (tilesize);
 
   /* Reload the images pixmap. */
-  gnibbles_load_logo (window);
+  //gnibbles_load_logo (window);
   gnibbles_load_pixmap (window);
 
   /* Recreate the buffer pixmap. */
@@ -585,7 +584,6 @@ new_game_clutter (void)
     main_id = 0;
   }
 
-  gnibbles_clutter_init ();
 
   if (ggz_network_mode || !properties->random) {
     current_level = properties->startlevel;
@@ -595,7 +593,8 @@ new_game_clutter (void)
 
   level = gnibbles_level_new (current_level);
   gnibbles_board_load_level (clutter_board, level);
-  gnibbles_clutter_add_bonus (1);
+  //gnibbles_clutter_add_bonus (1);
+  gnibbles_clutter_init ();
 
   paused = 0;
   gtk_action_set_visible (pause_action, !paused);
@@ -1138,10 +1137,10 @@ setup_window_clutter ()
 #endif
 
   g_signal_connect (G_OBJECT (clutter_board->clutter_widget), "configure_event",
-		    G_CALLBACK (configure_clutter_event_cb), clutter_board);
+		    G_CALLBACK (configure_clutter_event_cb), NULL);
 
-  g_signal_connect (G_OBJECT (window), "focus_out_event",
-		    G_CALLBACK (show_cursor_cb), NULL);
+  //g_signal_connect (G_OBJECT (window), "focus_out_event",
+	//	    G_CALLBACK (show_cursor_cb), NULL);
 
   main_vbox = gtk_vbox_new (FALSE, 0);
   gtk_box_pack_start (GTK_BOX (main_vbox), notebook, TRUE, TRUE, 0);
@@ -1153,7 +1152,6 @@ setup_window_clutter ()
 
   gtk_container_add (GTK_CONTAINER (window), main_vbox);
 
-
   gtk_widget_show_all (window);
 #ifdef GGZ_CLIENT
   gtk_widget_hide (chat);
@@ -1241,7 +1239,7 @@ setup_window (void)
 			       BOARDWIDTH * 5, BOARDHEIGHT * 5);
   g_signal_connect (G_OBJECT (drawing_area), "expose_event",
 		    G_CALLBACK (expose_event_cb), NULL);
-  /* We do our own double-buffering. */
+  // We do our own double-buffering. 
   gtk_widget_set_double_buffered (GTK_WIDGET (drawing_area), FALSE);
   gtk_widget_set_events (drawing_area, GDK_BUTTON_PRESS_MASK |
 			 GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK);
@@ -1268,7 +1266,7 @@ setup_window (void)
 }
 
 static void 
-render_logo_clutter ()
+render_logo_clutter (void)
 {
   
   guint width, height;
@@ -1279,9 +1277,13 @@ render_logo_clutter ()
 
   ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
 
+
   clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
-  
+ 
+  if (!logo_pixmap)
+    gnibbles_load_logo ();
   logo = gtk_clutter_texture_new_from_pixbuf (logo_pixmap);
+
   clutter_actor_set_size (CLUTTER_ACTOR (logo), width, height);
   clutter_actor_set_position (CLUTTER_ACTOR (logo), 0, 0);
   clutter_actor_show (logo);
@@ -1365,6 +1367,7 @@ render_logo (void)
 
 
 }
+
 int
 main (int argc, char **argv)
 {
@@ -1409,17 +1412,14 @@ main (int argc, char **argv)
                                  GAMES_SCORES_STYLE_PLAIN_DESCENDING);
 
   games_conf_initialise ("Gnibbles");
-
-  properties = gnibbles_properties_new ();
+  properties = gnibbles_properties_new (); 
 
   gnibbles_clutter_load_pixmap (properties->tilesize);
+
   clutter_board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
   setup_window_clutter ();
-  
   gnibbles_load_logo ();
 
-  gtk_widget_show (window);
-
 #ifdef GGZ_CLIENT
   network_init ();
   network_gui_update ();
diff --git a/gnibbles/main.h b/gnibbles/main.h
index 6a31227..3156555 100644
--- a/gnibbles/main.h
+++ b/gnibbles/main.h
@@ -39,7 +39,7 @@ gint game_running (void);
 gint pause_game_cb (GtkAction * action, gpointer data);
 void end_game (gboolean);
 
-gint new_game_clutter ();
+gint new_game_clutter (void);
 gint new_game (void);
 gint main_loop (gpointer data);
 



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