Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites
Home

[Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Mar 2005 17:46:03 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch (badly) encapsulates the spaceship sprites.  These are an 
entry in the named_sprite structure.  An accessor function is added that 
simply returns the whole spaceship struct within the named_sprites struct.

This is bad because it means the spaceship struct must remain public, 
unlike the named_sprites struct which should be made private.  However 
for now I think it will have to do.

-jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.206
diff -u -r1.206 mapview_common.c
--- client/mapview_common.c     5 Mar 2005 23:51:05 -0000       1.206
+++ client/mapview_common.c     6 Mar 2005 01:43:44 -0000
@@ -2481,7 +2481,9 @@
 ****************************************************************************/
 void get_spaceship_dimensions(int *width, int *height)
 {
-  get_sprite_dimensions(sprites.spaceship.habitation, width, height);
+  struct Sprite *sprite = get_spaceship_sprites()->habitation;
+
+  get_sprite_dimensions(sprite, width, height);
   *width *= 7;
   *height *= 7;
 }
@@ -2495,8 +2497,9 @@
   int i, x, y;  
   const struct player_spaceship *ship = &pplayer->spaceship;
   int w, h;
+  struct spaceship_sprites *space = get_spaceship_sprites();
 
-  get_sprite_dimensions(sprites.spaceship.habitation, &w, &h);
+  get_sprite_dimensions(space->habitation, &w, &h);
 
   canvas_put_rectangle(pcanvas, COLOR_STD_BLACK, 0, 0, w * 7, h * 7);
 
@@ -2513,9 +2516,9 @@
     x = modules_info[i].x * w / 4 - w / 2;
     y = modules_info[i].y * h / 4 - h / 2;
 
-    sprite = (k == 0 ? sprites.spaceship.habitation
-             : k == 1 ? sprites.spaceship.life_support
-             : sprites.spaceship.solar_panels);
+    sprite = (k == 0 ? space->habitation
+             : k == 1 ? space->life_support
+             : space->solar_panels);
     canvas_put_sprite_full(pcanvas, x, y, sprite);
   }
 
@@ -2531,8 +2534,8 @@
     x = components_info[i].x * w / 4 - w / 2;
     y = components_info[i].y * h / 4 - h / 2;
 
-    sprite = ((k == 0) ? sprites.spaceship.fuel
-             : sprites.spaceship.propulsion);
+    sprite = ((k == 0) ? space->fuel
+             : space->propulsion);
 
     canvas_put_sprite_full(pcanvas, x, y, sprite);
   }
@@ -2544,6 +2547,6 @@
     x = structurals_info[i].x * w / 4 - w / 2;
     y = structurals_info[i].y * h / 4 - h / 2;
 
-    canvas_put_sprite_full(pcanvas, x, y, sprites.spaceship.structural);
+    canvas_put_sprite_full(pcanvas, x, y, space->structural);
   }
 }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.258
diff -u -r1.258 tilespec.c
--- client/tilespec.c   5 Mar 2005 23:51:05 -0000       1.258
+++ client/tilespec.c   6 Mar 2005 01:43:44 -0000
@@ -3709,6 +3709,16 @@
 }
 
 /**************************************************************************
+  Return the sprites for drawing the spaceship.
+
+  FIXME: this method of returning a struct pointer is rather a hack.
+**************************************************************************/
+struct spaceship_sprites *get_spaceship_sprites(void)
+{
+  return &sprites.spaceship;
+}
+
+/**************************************************************************
   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
   citizen's city can be used to determine which sprite to use (a NULL
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.121
diff -u -r1.121 tilespec.h
--- client/tilespec.h   5 Mar 2005 23:51:05 -0000       1.121
+++ client/tilespec.h   6 Mar 2005 01:43:44 -0000
@@ -241,7 +241,7 @@
     int count;
     struct Sprite *sprite[MAX_NUM_CITIZEN_SPRITES];
   } citizen[NUM_TILES_CITIZEN], specialist[SP_MAX];
-  struct {
+  struct spaceship_sprites {
     struct Sprite
       *solar_panels,
       *life_support,
@@ -363,6 +363,7 @@
 
 extern struct named_sprites sprites;
 
+struct spaceship_sprites *get_spaceship_sprites(void);
 struct Sprite *get_citizen_sprite(struct citizen_type type,
                                  int citizen_index,
                                  const struct city *pcity);

[Prev in Thread] Current Thread [Next in Thread]