[Freeciv-Dev] (PR#12741) remove unit sprites from the unittype struct
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12741 >
This patch moves the unit sprites out of the unittype struct and into
the tileset. This is the same as has been done for tech, building, and
government sprites.
-jason
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.286
diff -u -r1.286 tilespec.c
--- client/tilespec.c 8 Apr 2005 06:32:27 -0000 1.286
+++ client/tilespec.c 8 Apr 2005 06:44:39 -0000
@@ -131,6 +131,7 @@
struct sprite *tech[A_LAST];
struct sprite *building[B_LAST];
struct sprite *government[G_MAGIC];
+ struct sprite *unittype[U_LAST];
struct citizen_graphic {
/* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
@@ -2220,9 +2221,10 @@
void tileset_setup_unit_type(struct tileset *t, int id)
{
struct unit_type *ut = get_unit_type(id);
-
- ut->sprite = lookup_sprite_tag_alt(t, ut->graphic_str, ut->graphic_alt,
- TRUE, "unit_type", ut->name);
+
+ t->sprites.unittype[id]
+ = lookup_sprite_tag_alt(t, ut->graphic_str, ut->graphic_alt,
+ TRUE, "unit_type", ut->name);
/* should maybe do something if NULL, eg generic default? */
}
@@ -2647,7 +2649,7 @@
}
}
- ADD_SPRITE(unit_type(punit)->sprite, TRUE,
+ ADD_SPRITE(t->sprites.unittype[punit->type], TRUE,
FULL_TILE_X_OFFSET + t->unit_offset_x,
FULL_TILE_Y_OFFSET + t->unit_offset_y);
@@ -4223,7 +4225,6 @@
return t->sprites.building[b];
}
-
/****************************************************************************
Return the sprite for the government.
****************************************************************************/
@@ -4237,6 +4238,18 @@
return t->sprites.government[gov->index];
}
+/****************************************************************************
+ Return the sprite for the unit type (the base "unit" sprite).
+****************************************************************************/
+struct sprite *get_unittype_sprite(const struct tileset *t, Unit_Type_id id)
+{
+ if (id < 0 || id >= game.num_unit_types) {
+ assert(0);
+ return NULL;
+ }
+ return t->sprites.unittype[id];
+}
+
/**************************************************************************
Return a "sample" sprite for this city style.
**************************************************************************/
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.145
diff -u -r1.145 tilespec.h
--- client/tilespec.h 8 Apr 2005 06:32:27 -0000 1.145
+++ client/tilespec.h 8 Apr 2005 06:44:39 -0000
@@ -184,6 +184,7 @@
struct sprite *get_building_sprite(const struct tileset *t, Impr_Type_id b);
struct sprite *get_government_sprite(const struct tileset *t,
const struct government *gov);
+struct sprite *get_unittype_sprite(const struct tileset *t, Unit_Type_id id);
struct sprite *get_sample_city_sprite(const struct tileset *t,
int city_style);
struct sprite *get_arrow_sprite(const struct tileset *t);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.123
diff -u -r1.123 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 6 Apr 2005 17:36:15 -0000 1.123
+++ client/gui-gtk-2.0/citydlg.c 8 Apr 2005 06:44:40 -0000
@@ -1575,9 +1575,8 @@
cid_decode(items[item].cid, &is_unit, &id);
if (is_unit) {
- struct unit_type *unit_type = get_unit_type(id);
- name = unit_type->name;
- sprite = unit_type->sprite;
+ name = unit_name(id);
+ sprite = get_unittype_sprite(tileset, id);
} else {
name = get_improvement_name(id);
sprite = get_building_sprite(tileset, id);
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.44
diff -u -r1.44 graphics.c
--- client/gui-gtk-2.0/graphics.c 28 Mar 2005 16:59:14 -0000 1.44
+++ client/gui-gtk-2.0/graphics.c 8 Apr 2005 06:44:40 -0000
@@ -106,9 +106,9 @@
{
int x1, x2, y1, y2;
int width, height;
- struct unit_type *type = get_unit_type(i);
+ struct sprite *sprite = get_unittype_sprite(tileset, i);
- sprite_get_bounding_box(type->sprite, &x1, &y1, &x2, &y2);
+ sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2);
if (pcanvas->type == CANVAS_PIXBUF) {
width = gdk_pixbuf_get_width(pcanvas->v.pixbuf);
height = gdk_pixbuf_get_height(pcanvas->v.pixbuf);
@@ -124,7 +124,7 @@
}
/* Finally, put a picture of the unit in the tile */
- canvas_put_sprite(pcanvas, 0, 0, type->sprite,
+ canvas_put_sprite(pcanvas, 0, 0, sprite,
(x2 + x1 - width) / 2, (y1 + y2 - height) / 2,
tileset_full_tile_width(tileset) - (x2 + x1 - width) / 2,
tileset_full_tile_height(tileset) - (y1 + y2 - height) / 2);
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/wldlg.c,v
retrieving revision 1.44
diff -u -r1.44 wldlg.c
--- client/gui-gtk-2.0/wldlg.c 6 Apr 2005 17:36:15 -0000 1.44
+++ client/gui-gtk-2.0/wldlg.c 8 Apr 2005 06:44:41 -0000
@@ -82,10 +82,10 @@
max_unit_width = 0;
unit_type_iterate(i) {
- struct unit_type *type = get_unit_type(i);
int x1, x2, y1, y2;
+ struct sprite *sprite = get_unittype_sprite(tileset, i);
- sprite_get_bounding_box(type->sprite, &x1, &y1, &x2, &y2);
+ sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2);
max_unit_width = MAX(max_unit_width, x2 - x1);
max_unit_height = MAX(max_unit_height, y2 - y1);
} unit_type_iterate_end;
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.43
diff -u -r1.43 unittype.h
--- common/unittype.h 4 Apr 2005 21:45:48 -0000 1.43
+++ common/unittype.h 8 Apr 2005 06:44:41 -0000
@@ -17,8 +17,6 @@
#include "fc_types.h"
-struct sprite; /* opaque; client-gui specific */
-
typedef int Unit_Type_id;
/*
Above typedef replaces old "enum unit_type_id" (since no longer
@@ -179,7 +177,6 @@
char sound_move_alt[MAX_LEN_NAME];
char sound_fight[MAX_LEN_NAME];
char sound_fight_alt[MAX_LEN_NAME];
- struct sprite *sprite;
enum unit_move_type move_type;
int build_cost; /* Use wrappers to access this. */
int pop_cost; /* number of workers the unit contains (e.g., settlers,
engineers)*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12741) remove unit sprites from the unittype struct,
Jason Short <=
|
|