[Freeciv-Dev] (PR#12646) make load_sprite static
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12646 >
This patch makes load_sprite, unload_sprite, and sprite_exists static
within tilespec.c.
Rather than add prototypes I just moved the functions up above where
sprite loading is done. Rather than remove or comment out the unused
sprite_exists, I changed one load_sprite call to use sprite_exists so
now it has a user.
-jason
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.276
diff -u -r1.276 tilespec.c
--- client/tilespec.c 25 Mar 2005 18:26:04 -0000 1.276
+++ client/tilespec.c 25 Mar 2005 19:09:11 -0000
@@ -1505,7 +1505,93 @@
return c;
}
-
+
+/**************************************************************************
+ Loads the sprite. If the sprite is already loaded a reference
+ counter is increased. Can return NULL if the sprite couldn't be
+ loaded.
+**************************************************************************/
+static struct Sprite *load_sprite(struct tileset *t, const char *tag_name)
+{
+ /* Lookup information about where the sprite is found. */
+ struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
+
+ freelog(LOG_DEBUG, "load_sprite(tag='%s')", tag_name);
+ if (!ss) {
+ return NULL;
+ }
+
+ assert(ss->ref_count >= 0);
+
+ if (!ss->sprite) {
+ /* If the sprite hasn't been loaded already, then load it. */
+ assert(ss->ref_count == 0);
+ if (ss->file) {
+ ss->sprite = load_gfx_file(ss->file);
+ if (!ss->sprite) {
+ freelog(LOG_FATAL, _("Couldn't load gfx file %s for sprite %s"),
+ ss->file, tag_name);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ int sf_w, sf_h;
+
+ ensure_big_sprite(ss->sf);
+ get_sprite_dimensions(ss->sf->big_sprite, &sf_w, &sf_h);
+ if (ss->x < 0 || ss->x + ss->width > sf_w
+ || ss->y < 0 || ss->y + ss->height > sf_h) {
+ freelog(LOG_ERROR,
+ "Sprite '%s' in file '%s' isn't within the image!",
+ tag_name, ss->sf->file_name);
+ return NULL;
+ }
+ ss->sprite =
+ crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width, ss->height,
+ NULL, -1, -1);
+ }
+ }
+
+ /* Track the reference count so we know when to free the sprite. */
+ ss->ref_count++;
+
+ return ss->sprite;
+}
+
+/**************************************************************************
+ Unloads the sprite. Decrease the reference counter. If the last
+ reference is removed the sprite is freed.
+**************************************************************************/
+static void unload_sprite(struct tileset *t, const char *tag_name)
+{
+ struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
+
+ assert(ss);
+ assert(ss->ref_count >= 1);
+ assert(ss->sprite);
+
+ ss->ref_count--;
+
+ if (ss->ref_count == 0) {
+ /* Nobody's using the sprite anymore, so we should free it. We know
+ * where to find it if we need it again. */
+ freelog(LOG_DEBUG, "freeing sprite '%s'", tag_name);
+ free_sprite(ss->sprite);
+ ss->sprite = NULL;
+ }
+}
+
+/**************************************************************************
+ Return TRUE iff the specified sprite exists in the tileset (whether
+ or not it is currently loaded).
+**************************************************************************/
+static bool sprite_exists(struct tileset *t, const char *tag_name)
+{
+ /* Lookup information about where the sprite is found. */
+ struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
+
+ return (ss != NULL);
+}
+
/* Not very safe, but convenient: */
#define SET_SPRITE(field, tag) \
do { \
@@ -1795,7 +1881,7 @@
}
t->sprites.unit.select[0] = NULL;
- if (load_sprite(t, "unit.select0")) {
+ if (sprite_exists(t, "unit.select0")) {
for (i = 0; i < NUM_TILES_SELECT; i++) {
my_snprintf(buffer, sizeof(buffer), "unit.select%d", i);
SET_SPRITE(unit.select[i], buffer);
@@ -4273,89 +4359,3 @@
return NULL;
}
}
-
-/**************************************************************************
- Loads the sprite. If the sprite is already loaded a reference
- counter is increased. Can return NULL if the sprite couldn't be
- loaded.
-**************************************************************************/
-struct Sprite *load_sprite(struct tileset *t, const char *tag_name)
-{
- /* Lookup information about where the sprite is found. */
- struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
-
- freelog(LOG_DEBUG, "load_sprite(tag='%s')", tag_name);
- if (!ss) {
- return NULL;
- }
-
- assert(ss->ref_count >= 0);
-
- if (!ss->sprite) {
- /* If the sprite hasn't been loaded already, then load it. */
- assert(ss->ref_count == 0);
- if (ss->file) {
- ss->sprite = load_gfx_file(ss->file);
- if (!ss->sprite) {
- freelog(LOG_FATAL, _("Couldn't load gfx file %s for sprite %s"),
- ss->file, tag_name);
- exit(EXIT_FAILURE);
- }
- } else {
- int sf_w, sf_h;
-
- ensure_big_sprite(ss->sf);
- get_sprite_dimensions(ss->sf->big_sprite, &sf_w, &sf_h);
- if (ss->x < 0 || ss->x + ss->width > sf_w
- || ss->y < 0 || ss->y + ss->height > sf_h) {
- freelog(LOG_ERROR,
- "Sprite '%s' in file '%s' isn't within the image!",
- tag_name, ss->sf->file_name);
- return NULL;
- }
- ss->sprite =
- crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width, ss->height,
- NULL, -1, -1);
- }
- }
-
- /* Track the reference count so we know when to free the sprite. */
- ss->ref_count++;
-
- return ss->sprite;
-}
-
-/**************************************************************************
- Unloads the sprite. Decrease the reference counter. If the last
- reference is removed the sprite is freed.
-**************************************************************************/
-void unload_sprite(struct tileset *t, const char *tag_name)
-{
- struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
-
- assert(ss);
- assert(ss->ref_count >= 1);
- assert(ss->sprite);
-
- ss->ref_count--;
-
- if (ss->ref_count == 0) {
- /* Nobody's using the sprite anymore, so we should free it. We know
- * where to find it if we need it again. */
- freelog(LOG_DEBUG, "freeing sprite '%s'", tag_name);
- free_sprite(ss->sprite);
- ss->sprite = NULL;
- }
-}
-
-/**************************************************************************
- Return TRUE iff the specified sprite exists in the tileset (whether
- or not it is currently loaded).
-**************************************************************************/
-bool sprite_exists(struct tileset *t, const char *tag_name)
-{
- /* Lookup information about where the sprite is found. */
- struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
-
- return (ss != NULL);
-}
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.137
diff -u -r1.137 tilespec.h
--- client/tilespec.h 25 Mar 2005 18:26:04 -0000 1.137
+++ client/tilespec.h 25 Mar 2005 19:09:11 -0000
@@ -253,8 +253,4 @@
const char *tileset_mini_intro_filename(struct tileset *t);
int tileset_num_city_colors(struct tileset *t);
-struct Sprite *load_sprite(struct tileset *t, const char *tag_name);
-void unload_sprite(struct tileset *t, const char *tag_name);
-bool sprite_exists(struct tileset *t, const char *tag_name);
-
#endif /* FC__TILESPEC_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12646) make load_sprite static,
Jason Short <=
|
|