Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12390) loading the intro graphics
Home

[Freeciv-Dev] (PR#12390) loading the intro graphics

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12390) loading the intro graphics
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Feb 2005 20:25:22 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12390 >

Loading the intro graphics is ugly and complicated.

This patch simplifies that at a cost in memory.

* The intro graphics are loaded by the tilespec code as regular sprites.
* The GUI code still must draw the text on manually.
* The intro graphics are never freed after they are loaded (and thus 
never need to be reloaded).

This takes an additional 1 MB of memory (about an extra 3%).  With 
swapping on any modern-ish computer this should have no impact on the 
runtime.  However it would be nice to have a general mechanism for 
unloading sprites (or loading them on demand) so this is something we 
might look into in the future.

I'm not sure if this patch is a good idea.  On the one hand the 
unloading mechanism is fairly complicated and has little benefit; on the 
other hand it's already in place.  In making this patch I originally 
just wanted to encapsulate the tileset data (the intro file graphics 
names).  But I ended up rewriting large parts of the system.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.473
diff -u -r1.473 packhand.c
--- client/packhand.c   23 Feb 2005 03:34:05 -0000      1.473
+++ client/packhand.c   1 Mar 2005 04:09:18 -0000
@@ -353,7 +353,6 @@
     /* Find something sensible to display instead of the intro gfx. */
     center_on_something();
     
-    free_intro_radar_sprites();
     agents_game_start();
   }
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.248
diff -u -r1.248 tilespec.c
--- client/tilespec.c   28 Feb 2005 20:24:38 -0000      1.248
+++ client/tilespec.c   1 Mar 2005 04:09:19 -0000
@@ -1273,6 +1273,9 @@
   
   assert(sprite_hash != NULL);
 
+  SET_SPRITE(intro.main, "intro.main");
+  SET_SPRITE(intro.mini, "intro.mini");
+
   SET_SPRITE(treaty_thumb[0], "treaty.disagree_thumb_down");
   SET_SPRITE(treaty_thumb[1], "treaty.agree_thumb_up");
 
@@ -3518,6 +3521,22 @@
   }
 }
 
+/****************************************************************************
+  Return a sprite for the main intro graphics.
+****************************************************************************/
+struct Sprite *get_main_intro_sprite(void)
+{
+  return sprites.intro.main;
+}
+
+/****************************************************************************
+  Return a sprite for the "mini" intro graphics (aka the radar sprite).
+****************************************************************************/
+struct Sprite *get_mini_intro_sprite(void)
+{
+  return sprites.intro.mini;
+}
+
 /**************************************************************************
   Return a sprite for the given citizen.  The citizen's type is given,
   as well as their index (in the range [0..pcity->size)).  The
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.112
diff -u -r1.112 tilespec.h
--- client/tilespec.h   28 Feb 2005 20:24:38 -0000      1.112
+++ client/tilespec.h   1 Mar 2005 04:09:19 -0000
@@ -338,6 +338,11 @@
   struct {
     struct Sprite *player[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   } colors;
+  struct {
+    struct Sprite
+      *main,
+      *mini;
+  } intro;
 
   struct terrain_drawing_data *terrain[MAX_NUM_TERRAINS];
 };
@@ -352,6 +357,8 @@
 };
 extern enum fog_style fogstyle;
 
+struct Sprite *get_main_intro_sprite(void);
+struct Sprite *get_mini_intro_sprite(void);
 struct Sprite *get_citizen_sprite(struct citizen_type type,
                                  int citizen_index,
                                  const struct city *pcity);
@@ -360,10 +367,6 @@
 struct Sprite *get_tax_sprite(Output_type_id otype);
 struct Sprite *get_treaty_thumb_sprite(bool on_off);
 
-/* full pathnames: */
-extern char *main_intro_filename;
-extern char *minimap_intro_filename;
-
 /* These variables contain the size of the tiles used within the game.
  *
  * "normal" tiles include most mapview graphics, particularly the basic
Index: client/gui-ftwl/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/graphics.c,v
retrieving revision 1.1
diff -u -r1.1 graphics.c
--- client/gui-ftwl/graphics.c  29 Jul 2004 14:10:13 -0000      1.1
+++ client/gui-ftwl/graphics.c  1 Mar 2005 04:09:19 -0000
@@ -47,16 +47,6 @@
 }
 
 /**************************************************************************
-  Load the introductory graphics.
-**************************************************************************/
-void load_intro_gfx(void)
-{
-  /* PORTME */
-  intro_gfx_sprite = load_gfxfile(main_intro_filename);
-  radar_gfx_sprite = load_gfxfile(minimap_intro_filename);
-}
-
-/**************************************************************************
   Load the cursors (mouse substitute sprites), including a goto cursor,
   an airdrop cursor, a nuke cursor, and a patrol cursor.
 **************************************************************************/
@@ -66,21 +56,6 @@
 }
 
 /**************************************************************************
-  Frees the introductory sprites.
-**************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite) {
-    free_sprite(intro_gfx_sprite);
-    intro_gfx_sprite = NULL;
-  }
-  if (radar_gfx_sprite) {
-    free_sprite(radar_gfx_sprite);
-    radar_gfx_sprite = NULL;
-  }
-}
-
-/**************************************************************************
   Return a NULL-terminated, permanently allocated array of possible
   graphics types extensions.  Extensions listed first will be checked
   first.
Index: client/gui-ftwl/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/graphics.h,v
retrieving revision 1.1
diff -u -r1.1 graphics.h
--- client/gui-ftwl/graphics.h  29 Jul 2004 14:10:13 -0000      1.1
+++ client/gui-ftwl/graphics.h  1 Mar 2005 04:09:19 -0000
@@ -16,4 +16,6 @@
 
 #include "graphics_g.h"
 
+void load_cursors(void);
+
 #endif                         /* FC__GRAPHICS_H */
Index: client/gui-gtk/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.c,v
retrieving revision 1.53
diff -u -r1.53 graphics.c
--- client/gui-gtk/graphics.c   24 Mar 2004 06:18:18 -0000      1.53
+++ client/gui-gtk/graphics.c   1 Mar 2005 04:09:19 -0000
@@ -117,7 +117,7 @@
 
   /* Main graphic */
 
-  intro_gfx_sprite = load_gfxfile(main_intro_filename);
+  intro_gfx_sprite = get_main_intro_sprite();
   tot=intro_gfx_sprite->width;
 
   face_gc = gdk_gc_new(root_window);
@@ -133,7 +133,7 @@
 
   /* Minimap graphic */
 
-  radar_gfx_sprite = load_gfxfile(minimap_intro_filename);
+  radar_gfx_sprite = get_mini_intro_sprite();
   tot = radar_gfx_sprite->width;
 
   my_snprintf(s, sizeof(s), "%d.%d.%d%s",
@@ -407,22 +407,6 @@
 }
 
 /***************************************************************************
-  This function is so that packhand.c can be gui-independent, and
-  not have to deal with Sprites itself.
-***************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite) {
-    free_sprite(intro_gfx_sprite);
-    intro_gfx_sprite=NULL;
-  }
-  if (radar_gfx_sprite) {
-    free_sprite(radar_gfx_sprite);
-    radar_gfx_sprite=NULL;
-  }
-}
-
-/***************************************************************************
  Draws a black border around the sprite. This is done by parsing the
  mask and replacing the first and last pixel in every column and row
  by a black one.
Index: client/gui-gtk/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.h,v
retrieving revision 1.13
diff -u -r1.13 graphics.h
--- client/gui-gtk/graphics.h   18 Jul 2003 01:12:09 -0000      1.13
+++ client/gui-gtk/graphics.h   1 Mar 2005 04:09:19 -0000
@@ -51,4 +51,7 @@
                             int *start_y, int *end_x, int *end_y);
 SPRITE *crop_blankspace(SPRITE *s);
 
+void load_intro_gfx(void);
+void load_cursors(void);
+
 #endif  /* FC__GRAPHICS_H */
Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.36
diff -u -r1.36 graphics.c
--- client/gui-gtk-2.0/graphics.c       16 Feb 2005 23:14:58 -0000      1.36
+++ client/gui-gtk-2.0/graphics.c       1 Mar 2005 04:09:19 -0000
@@ -405,22 +405,6 @@
 }
 
 /***************************************************************************
-  This function is so that packhand.c can be gui-independent, and
-  not have to deal with Sprites itself.
-***************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite) {
-    free_sprite(intro_gfx_sprite);
-    intro_gfx_sprite=NULL;
-  }
-  if (radar_gfx_sprite) {
-    free_sprite(radar_gfx_sprite);
-    radar_gfx_sprite=NULL;
-  }
-}
-
-/***************************************************************************
   Scales a sprite. If the sprite contains a mask, the mask is scaled
   as as well.
 ***************************************************************************/
Index: client/gui-gtk-2.0/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.h,v
retrieving revision 1.12
diff -u -r1.12 graphics.h
--- client/gui-gtk-2.0/graphics.h       16 Feb 2005 23:14:58 -0000      1.12
+++ client/gui-gtk-2.0/graphics.h       1 Mar 2005 04:09:19 -0000
@@ -61,5 +61,7 @@
 GdkPixbuf *sprite_get_pixbuf(SPRITE *sprite);
 GdkBitmap *sprite_get_mask(struct Sprite *sprite);
 
+void load_cursors(void);
+
 #endif  /* FC__GRAPHICS_H */
 
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.17
diff -u -r1.17 pages.c
--- client/gui-gtk-2.0/pages.c  5 Feb 2005 07:15:36 -0000       1.17
+++ client/gui-gtk-2.0/pages.c  1 Mar 2005 04:09:19 -0000
@@ -151,6 +151,7 @@
 **************************************************************************/
 GtkWidget *create_main_page(void)
 {
+  struct Sprite *intro_sprite;
   GtkWidget *align, *box, *sbox, *bbox, *frame, *image;
 
   GtkWidget *button;
@@ -169,7 +170,10 @@
   gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);
   gtk_container_add(GTK_CONTAINER(align), frame);
 
-  image = gtk_image_new_from_file(main_intro_filename);
+  /* Note this won't work if the intro graphics have an alpha channel. */
+  intro_sprite = get_main_intro_sprite();
+  image = gtk_image_new_from_pixmap(intro_sprite->pixmap,
+                                   intro_sprite->mask);
   g_signal_connect_after(image, "expose_event",
       G_CALLBACK(intro_expose), NULL);
   gtk_container_add(GTK_CONTAINER(frame), image);
Index: client/gui-sdl/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/graphics.c,v
retrieving revision 1.33
diff -u -r1.33 graphics.c
--- client/gui-sdl/graphics.c   14 Feb 2005 17:52:56 -0000      1.33
+++ client/gui-sdl/graphics.c   1 Mar 2005 04:09:22 -0000
@@ -3526,14 +3526,6 @@
 }
 
 /**************************************************************************
-    Now it setup only paths to those files.
- **************************************************************************/
-void load_intro_gfx(void)
-{
-  
-}
-
-/**************************************************************************
   Load the cursors (mouse substitute sprites), including a goto cursor,
   an airdrop cursor, a nuke cursor, and a patrol cursor.
 **************************************************************************/
@@ -3763,12 +3755,3 @@
   /*s->psurface=NULL;*/
   free(s);
 }
-
-
-/**************************************************************************
-  Frees the introductory sprites.
-**************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  FREESURFACE(pIntro_gfx);
-}
Index: client/gui-sdl/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/graphics.h,v
retrieving revision 1.19
diff -u -r1.19 graphics.h
--- client/gui-sdl/graphics.h   10 Feb 2005 18:35:17 -0000      1.19
+++ client/gui-sdl/graphics.h   1 Mar 2005 04:09:22 -0000
@@ -322,4 +322,6 @@
     }                                                                  \
 } while(0)
 
+void load_cursors(void);
+
 #endif                         /* FC__GRAPHICS_H */
Index: client/gui-stub/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/graphics.c,v
retrieving revision 1.13
diff -u -r1.13 graphics.c
--- client/gui-stub/graphics.c  4 Feb 2005 02:07:06 -0000       1.13
+++ client/gui-stub/graphics.c  1 Mar 2005 04:09:22 -0000
@@ -21,9 +21,6 @@
 
 #include "graphics.h"
 
-struct Sprite *intro_gfx_sprite;
-struct Sprite *radar_gfx_sprite;
-
 /****************************************************************************
   Return whether the client supports isometric view (isometric tilesets).
 ****************************************************************************/
@@ -43,16 +40,6 @@
 }
 
 /****************************************************************************
-  Load the introductory graphics.
-****************************************************************************/
-void load_intro_gfx(void)
-{
-  /* PORTME */
-  intro_gfx_sprite = load_gfxfile(main_intro_filename);
-  radar_gfx_sprite = load_gfxfile(minimap_intro_filename);
-}
-
-/****************************************************************************
   Load the cursors (mouse substitute sprites), including a goto cursor,
   an airdrop cursor, a nuke cursor, and a patrol cursor.
 ****************************************************************************/
@@ -62,21 +49,6 @@
 }
 
 /****************************************************************************
-  Frees the introductory sprites.
-****************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite) {
-    free_sprite(intro_gfx_sprite);
-    intro_gfx_sprite = NULL;
-  }
-  if (radar_gfx_sprite) {
-    free_sprite(radar_gfx_sprite);
-    radar_gfx_sprite = NULL;
-  }
-}
-
-/****************************************************************************
   Return a NULL-terminated, permanently allocated array of possible
   graphics types extensions.  Extensions listed first will be checked
   first.
Index: client/gui-win32/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/graphics.c,v
retrieving revision 1.24
diff -u -r1.24 graphics.c
--- client/gui-win32/graphics.c 14 Feb 2005 02:39:49 -0000      1.24
+++ client/gui-win32/graphics.c 1 Mar 2005 04:09:22 -0000
@@ -80,8 +80,8 @@
 void
 load_intro_gfx(void)
 {
-  intro_gfx_sprite=load_gfxfile(main_intro_filename);
-  radar_gfx_sprite = load_gfxfile(minimap_intro_filename);     
+  intro_gfx_sprite = get_main_intro_sprite();
+  radar_gfx_sprite = get_mini_intro_sprite();
 }
 
 /**************************************************************************
@@ -196,24 +196,6 @@
 /**************************************************************************
 
 **************************************************************************/
-void
-free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite)
-    {
-      free_sprite(intro_gfx_sprite);
-      intro_gfx_sprite=NULL;
-    }
-  if (radar_gfx_sprite)
-    {
-      free_sprite(radar_gfx_sprite);
-      radar_gfx_sprite=NULL;
-    }
-}
-
-/**************************************************************************
-
-**************************************************************************/
 const char **
 gfx_fileextensions(void)
 {
Index: client/gui-win32/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/graphics.h,v
retrieving revision 1.11
diff -u -r1.11 graphics.h
--- client/gui-win32/graphics.h 14 Feb 2005 02:39:49 -0000      1.11
+++ client/gui-win32/graphics.h 1 Mar 2005 04:09:22 -0000
@@ -65,5 +65,7 @@
 extern SPRITE *intro_gfx_sprite;
 extern SPRITE *radar_gfx_sprite;
 
+void load_intro_gfx(void);
+void load_cursors(void);
 
 #endif  /* FC__GRAPHICS_H */
Index: client/gui-xaw/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.c,v
retrieving revision 1.54
diff -u -r1.54 graphics.c
--- client/gui-xaw/graphics.c   1 Dec 2004 18:56:53 -0000       1.54
+++ client/gui-xaw/graphics.c   1 Mar 2005 04:09:22 -0000
@@ -112,7 +112,7 @@
 
   /* Main graphic */
 
-  intro_gfx_sprite=load_gfxfile(main_intro_filename);
+  intro_gfx_sprite = get_main_intro_sprite();
   tot=intro_gfx_sprite->width;
 
   y=intro_gfx_sprite->height-(2*lin);
@@ -126,7 +126,7 @@
 
   /* Minimap graphic */
 
-  radar_gfx_sprite=load_gfxfile(minimap_intro_filename);
+  radar_gfx_sprite = get_mini_intro_sprite();
   tot=radar_gfx_sprite->width;
 
   y = radar_gfx_sprite->height - (lin +
@@ -592,20 +592,3 @@
 
   return(pm);
 }
-
-
-/***************************************************************************
-  This function is so that packhand.c can be gui-independent, and
-  not have to deal with Sprites itself.
-***************************************************************************/
-void free_intro_radar_sprites(void)
-{
-  if (intro_gfx_sprite) {
-    free_sprite(intro_gfx_sprite);
-    intro_gfx_sprite=NULL;
-  }
-  if (radar_gfx_sprite) {
-    free_sprite(radar_gfx_sprite);
-    radar_gfx_sprite=NULL;
-  }
-}
Index: client/gui-xaw/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.h,v
retrieving revision 1.10
diff -u -r1.10 graphics.h
--- client/gui-xaw/graphics.h   8 Mar 2004 07:20:50 -0000       1.10
+++ client/gui-xaw/graphics.h   1 Mar 2005 04:09:22 -0000
@@ -37,4 +37,7 @@
 extern Cursor         nuke_cursor;
 extern Cursor         patrol_cursor;
 
+void load_intro_gfx(void);
+void load_cursors(void);
+
 #endif  /* FC__GRAPHICS_H */
Index: client/include/graphics_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/graphics_g.h,v
retrieving revision 1.10
diff -u -r1.10 graphics_g.h
--- client/include/graphics_g.h 24 Mar 2004 06:18:19 -0000      1.10
+++ client/include/graphics_g.h 1 Mar 2005 04:09:22 -0000
@@ -18,11 +18,6 @@
 bool isometric_view_supported(void);
 bool overhead_view_supported(void);
 
-void load_intro_gfx(void);
-void load_cursors(void);
-
-void free_intro_radar_sprites(void);
-
 struct Sprite;                 /* opaque type, real type is gui-dep */
 
 const char **gfx_fileextensions(void);
Index: data/misc/small.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/small.spec,v
retrieving revision 1.9
diff -u -r1.9 small.spec
--- data/misc/small.spec        1 Dec 2004 19:21:17 -0000       1.9
+++ data/misc/small.spec        1 Mar 2005 04:09:22 -0000
@@ -119,3 +119,11 @@
   1, 9,  "ev.wonderwillbebuilt"
   1, 10, "ev.wonderbuilt"
 }
+
+; Intro graphics added here because there's no good place for them
+[extra]
+sprites =
+       {       "file", "tag"
+               "misc/intro", "intro.main"
+               "misc/radar", "intro.mini"
+       }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12390) loading the intro graphics, Jason Short <=