[gnome-nibbles] Removes the splash screen which greatly improves performance



commit bdd6e7bbd95ad1c0ebdfabb5bd6c062b32796c1d
Author: Bryan Quigley <bryanquigs src gnome org>
Date:   Thu Apr 18 01:13:01 2013 -0400

    Removes the splash screen which greatly improves performance
    
    The splash screen was resized on every window reize event.  This
    would result in very bad performance.  Had to make some other minor
    changes like disabling clicking New Game, when a game is running.
    Closes: bgo#641235

 src/gnibbles.c    |  13 ----
 src/gnibbles.h    |   1 -
 src/main.c        | 194 ++++--------------------------------------------------
 src/main.h        |   3 +-
 src/preferences.c |   2 -
 5 files changed, 16 insertions(+), 197 deletions(-)
---
diff --git a/src/gnibbles.c b/src/gnibbles.c
index d5ee12a..eaa1409 100644
--- a/src/gnibbles.c
+++ b/src/gnibbles.c
@@ -48,8 +48,6 @@ GnibblesWorm *worms[NUMWORMS];
 GnibblesBoni *boni = NULL;
 GnibblesWarpManager *warpmanager;
 
-GdkPixbuf *logo_pixmap = NULL;
-
 GdkPixbuf *wall_pixmaps[11] = { NULL, NULL, NULL, NULL, NULL,
   NULL, NULL, NULL, NULL, NULL,
   NULL
@@ -172,17 +170,6 @@ gnibbles_error (gchar *message)
 }
 
 void
-gnibbles_load_logo (gint tilesize)
-{
-  if (logo_pixmap)
-    g_object_unref (logo_pixmap);
-
-  logo_pixmap = gnibbles_load_pixmap_file ("gnome-nibbles-logo.svg",
-                                           board->width * tilesize,
-                                           board->height * tilesize);
-}
-
-void
 gnibbles_init (void)
 {
   gint i;
diff --git a/src/gnibbles.h b/src/gnibbles.h
index 9554026..dc8a5f9 100644
--- a/src/gnibbles.h
+++ b/src/gnibbles.h
@@ -57,7 +57,6 @@ extern GnibblesWarpManager *warpmanager;
 
 void gnibbles_load_pixmap (gint tilesize);
 void gnibbles_error (gchar *message);
-void gnibbles_load_logo (gint tilesize);
 void gnibbles_init (void);
 void gnibbles_add_bonus (gint regular);
 gint gnibbles_move_worms (void);
diff --git a/src/main.c b/src/main.c
index 1471f93..ce1713d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,8 +74,6 @@ static const GamesScoresCategory scorecats[] = {
 
 GamesScores *highscores;
 
-extern GdkPixbuf *logo_pixmap;
-
 GnibblesProperties *properties;
 
 GnibblesBoard *board;
@@ -98,9 +96,7 @@ gint current_level;
 
 static gint add_bonus_cb (gpointer data);
 
-static void render_logo (void);
 static gint end_game_cb (GtkAction * action, gpointer data);
-static void hide_logo (void);
 
 static GtkAction *new_game_action;
 GtkAction *pause_action;
@@ -109,8 +105,6 @@ static GtkAction *preferences_action;
 static GtkAction *scores_action;
 static GtkAction *fullscreen_action;
 
-static ClutterActor *logo;
-
 static void
 hide_cursor (void)
 {
@@ -206,7 +200,6 @@ configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
   tilesize = MIN (ts_x, ts_y);
 
   gnibbles_load_pixmap (tilesize);
-  gnibbles_load_logo (tilesize);
 
   clutter_actor_set_size (CLUTTER_ACTOR (stage),
                           BOARDWIDTH * tilesize,
@@ -222,23 +215,9 @@ configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
       if (warpmanager)
         gnibbles_warpmanager_rescale (warpmanager, tilesize);
     }
-  } else {
-    if (logo)
-      hide_logo ();
-
-    if (board)
+  } else
       gnibbles_board_rescale (board, tilesize);
 
-    render_logo ();
-  }
-
-  /* But, has the tile size changed? */
-  if (properties->tilesize == tilesize) {
-    /* We must always re-load the logo. */
-    gnibbles_load_logo (tilesize);
-    return FALSE;
-  }
-
   properties->tilesize = tilesize;
   gnibbles_properties_set_tile_size (tilesize);
 
@@ -275,10 +254,10 @@ new_game (void)
   int i;
   gtk_action_set_sensitive (pause_action, TRUE);
   gtk_action_set_sensitive (end_game_action, TRUE);
+  gtk_action_set_sensitive (new_game_action, FALSE);
   gtk_action_set_sensitive (preferences_action, TRUE);
 
   if (game_running ()) {
-    end_game (FALSE);
     main_id = 0;
   }
 
@@ -288,7 +267,6 @@ new_game (void)
     current_level = rand () % MAXLEVEL + 1;
   }
 
-  hide_logo ();
   gnibbles_init ();
   gnibbles_board_level_new (board, current_level);
   gnibbles_board_level_add_bonus (board, 1);
@@ -356,7 +334,7 @@ show_scores_cb (GtkAction * action, gpointer data)
 }
 
 void
-end_game (gboolean show_splash)
+end_game (void)
 {
   if (main_id) {
     g_source_remove (main_id);
@@ -383,12 +361,12 @@ end_game (gboolean show_splash)
     restart_id = 0;
   }
 
-  if (show_splash) {
-    render_logo ();
-    gtk_action_set_sensitive (pause_action, FALSE);
-    gtk_action_set_sensitive (end_game_action, FALSE);
-    gtk_action_set_sensitive (preferences_action, TRUE);
-  }
+  animate_end_game ();
+
+  gtk_action_set_sensitive (pause_action, FALSE);
+  gtk_action_set_sensitive (end_game_action, FALSE);
+  gtk_action_set_sensitive (new_game_action, TRUE);
+  gtk_action_set_sensitive (preferences_action, TRUE);
 
   games_pause_action_set_is_paused (GAMES_PAUSE_ACTION (pause_action), FALSE);
 }
@@ -396,7 +374,7 @@ end_game (gboolean show_splash)
 static gboolean
 end_game_cb (GtkAction * action, gpointer data)
 {
-  end_game (TRUE);
+  end_game ();
   return FALSE;
 }
 
@@ -430,14 +408,7 @@ restart_game (gpointer data)
   return FALSE;
 }
 
-static void
-end_game_anim_cb (ClutterAnimation *animation, ClutterActor *actor)
-{
-  if (!restart_id)
-    end_game (TRUE);
-}
-
-static void
+void
 animate_end_game (void)
 {
   int i;
@@ -461,14 +432,11 @@ animate_end_game (void)
 
   }
 
-  g_signal_connect_after (
-    clutter_actor_animate (board->level, CLUTTER_EASE_IN_QUAD, 700,
+  clutter_actor_animate (board->level, CLUTTER_EASE_IN_QUAD, 700,
                            "scale-x", 0.4, "scale-y", 0.4,
                            "fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
                            "opacity", 0,
-                           NULL),
-    "completed", G_CALLBACK (end_game_anim_cb), NULL);
-
+                           NULL);
 }
 
 gboolean
@@ -482,7 +450,7 @@ main_loop (gpointer data)
   gnibbles_scoreboard_update (scoreboard);
 
   if (status == VICTORY) {
-    end_game (TRUE);
+    end_game ();
     winner = gnibbles_get_winner ();
 
     if (winner == -1)
@@ -750,139 +718,6 @@ setup_window (void)
   scoreboard = gnibbles_scoreboard_new (statusbar);
 }
 
-static void
-render_logo (void)
-{
-  ClutterActor *image;
-  ClutterActor *text, *text_shadow;
-  ClutterActor *desc, *desc_shadow;
-  ClutterColor actor_color = {0xff,0xff,0xff,0xff};
-  ClutterColor shadow_color = {0x00, 0x00, 0x00, 0x88};
-  ClutterActor *text_group;
-  static gint width, height;
-  gint size;
-  gfloat stage_w, stage_h;
-  PangoFontDescription *pfd;
-  PangoLayout *layout;
-  PangoContext *context;
-  GError *error = NULL;
-
-  gchar *nibbles = _("Nibbles");
-  /* Translators: This string will be included in the intro screen, so don't make sure it fits! */
-  gchar *description = _("A worm game for GNOME.");
-
-  logo = clutter_group_new ();
-  text_group = clutter_group_new ();
-
-  if (!logo_pixmap)
-    gnibbles_load_logo (properties->tilesize);
-
-  image = gtk_clutter_texture_new ();
-  gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE (image), logo_pixmap, &error);
-
-  stage_w = board->width * properties->tilesize;
-  stage_h = board->height * properties->tilesize;
-
-  clutter_actor_set_size (CLUTTER_ACTOR (image), stage_w, stage_h);
-
-  clutter_actor_set_position (CLUTTER_ACTOR (image), 0, 0);
-  clutter_actor_show (image);
-
-  text = clutter_text_new ();
-  clutter_text_set_color (CLUTTER_TEXT (text), &actor_color);
-
-  context = gdk_pango_context_get ();
-  layout = clutter_text_get_layout (CLUTTER_TEXT (text));
-  pfd = pango_context_get_font_description (context);
-  size = pango_font_description_get_size (pfd);
-
-  pango_font_description_set_size (pfd, (size * stage_w) / 100);
-  pango_font_description_set_family (pfd, "Sans");
-  pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
-  pango_layout_set_font_description (layout, pfd);
-  pango_layout_set_text (layout, nibbles, -1);
-  pango_layout_get_pixel_size (layout, &width, &height);
-
-  text_shadow = clutter_text_new ();
-  clutter_text_set_color (CLUTTER_TEXT (text_shadow), &shadow_color);
-
-  layout = clutter_text_get_layout (CLUTTER_TEXT (text_shadow));
-  pango_layout_set_font_description (layout, pfd);
-  pango_layout_set_text (layout, nibbles, -1);
-
-  clutter_actor_set_position (CLUTTER_ACTOR (text),
-                              (stage_w - width) * 0.5 ,
-                              stage_h * .72);
-  clutter_actor_set_position (CLUTTER_ACTOR (text_shadow),
-                              (stage_w - width) * 0.5 + 5,
-                              stage_h * .72 + 5);
-
-  desc = clutter_text_new ();
-  layout = clutter_text_get_layout (CLUTTER_TEXT (desc));
-
-  clutter_text_set_color (CLUTTER_TEXT (desc), &actor_color);
-  pango_font_description_set_size (pfd, (size * stage_w) / 400);
-  pango_layout_set_font_description (layout, pfd);
-  pango_layout_set_text (layout, description, -1);
-  pango_layout_get_pixel_size(layout, &width, &height);
-
-  desc_shadow = clutter_text_new ();
-  layout = clutter_text_get_layout (CLUTTER_TEXT (desc_shadow));
-  clutter_text_set_color (CLUTTER_TEXT (desc_shadow), &shadow_color);
-
-  pango_font_description_set_size (pfd, (size * stage_w) / 400);
-  pango_layout_set_font_description (layout, pfd);
-  pango_layout_set_text (layout, description, -1);
-
-  clutter_actor_set_position (CLUTTER_ACTOR (desc),
-                              (stage_w - width) * 0.5,
-                              stage_h* .93);
-  clutter_actor_set_position (CLUTTER_ACTOR (desc_shadow),
-                              (stage_w - width) * 0.5 + 3,
-                              stage_h * .93 + 3);
-
-  clutter_container_add (CLUTTER_CONTAINER (text_group),
-                         CLUTTER_ACTOR (text_shadow),
-                         CLUTTER_ACTOR (text),
-                         CLUTTER_ACTOR (desc_shadow),
-                         CLUTTER_ACTOR (desc),
-                         NULL);
-  clutter_container_add (CLUTTER_CONTAINER (logo),
-                         CLUTTER_ACTOR (image),
-                         CLUTTER_ACTOR (text_group),
-                         NULL);
-
-  clutter_actor_set_opacity (CLUTTER_ACTOR (text_group), 0);
-  clutter_actor_set_scale (CLUTTER_ACTOR (text_group), 0.0, 0.0);
-  clutter_actor_animate (text_group, CLUTTER_EASE_OUT_CIRC, 800,
-                          "opacity", 0xff,
-                          "scale-x", 1.0,
-                          "scale-y", 1.0,
-                          "fixed::scale-center-y", stage_w / 2,
-                          "fixed::scale-center-x", stage_h / 2,
-                          NULL);
-
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage),
-                               CLUTTER_ACTOR (logo));
-}
-
-static void
-on_hide_logo_completed (ClutterAnimation *animation, ClutterActor *actor)
-{
-  clutter_actor_hide (actor);
-  clutter_group_remove_all (CLUTTER_GROUP (actor));
-}
-
-static void
-hide_logo (void)
-{
-  g_signal_connect_after (
-    clutter_actor_animate (logo, CLUTTER_EASE_IN_QUAD, 150,
-                           "opacity", 0,
-                           NULL),
-    "completed", G_CALLBACK (on_hide_logo_completed), logo);
-}
-
 int
 main (int argc, char **argv)
 {
@@ -944,7 +779,6 @@ main (int argc, char **argv)
   properties = gnibbles_properties_new ();
   setup_window ();
   gnibbles_load_pixmap (properties->tilesize);
-  gnibbles_load_logo (properties->tilesize);
 
   gtk_action_set_sensitive (pause_action, FALSE);
   gtk_action_set_sensitive (end_game_action, FALSE);
diff --git a/src/main.h b/src/main.h
index 258d860..011e067 100644
--- a/src/main.h
+++ b/src/main.h
@@ -35,7 +35,8 @@ char names[NUMWORMS][17];
 extern GtkAction *pause_action;
 
 gboolean game_running (void);
-void end_game (gboolean);
+void end_game (void);
+void animate_end_game (void);
 
 gboolean new_game (void);
 gboolean main_loop (gpointer data);
diff --git a/src/preferences.c b/src/preferences.c
index c6d5b79..4d75cd2 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -80,8 +80,6 @@ start_level_cb (GtkWidget * widget, gpointer data)
   if (!pref_dialog)
     return;
 
-  end_game (FALSE);
-
   level = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (data));
   gnibbles_properties_set_start_level (level);
 }


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