summaryrefslogtreecommitdiff
path: root/engine.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-10-04 21:42:00 +0000
committerpeter1138 <peter1138@openttd.org>2005-10-04 21:42:00 +0000
commit13d02ca96515a1a1b70722a83ce78212002c66e9 (patch)
tree8a9d84ea55620c79439c18989514cb8167dfcbb6 /engine.c
parentf614b8611440519f42b0a5b2209fd2588b5b2a60 (diff)
downloadopenttd-13d02ca96515a1a1b70722a83ce78212002c66e9.tar.xz
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
Diffstat (limited to 'engine.c')
-rw-r--r--engine.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/engine.c b/engine.c
index 2668e9271..b2f369d01 100644
--- a/engine.c
+++ b/engine.c
@@ -294,6 +294,28 @@ static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, byte overri
return NULL;
}
+/**
+ * Unload all wagon override sprite groups.
+ */
+void UnloadWagonOverrides(void)
+{
+ WagonOverrides *wos;
+ WagonOverride *wo;
+ EngineID engine;
+ int i;
+
+ for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
+ wos = &_engine_wagon_overrides[engine];
+ for (i = 0; i < wos->overrides_count; i++) {
+ wo = &wos->overrides[i];
+ UnloadSpriteGroup(&wo->group);
+ free(wo->train_id);
+ }
+ free(wos->overrides);
+ wos->overrides_count = 0;
+ wos->overrides = NULL;
+ }
+}
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
// (It isn't and shouldn't be like this in the GRF files since new cargo types
@@ -303,13 +325,32 @@ static SpriteGroup *engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_GLOBAL_CID];
void SetCustomEngineSprites(EngineID engine, byte cargo, SpriteGroup *group)
{
- /* FIXME: If we are replacing an override, release original SpriteGroup
- * to prevent leaks. But first we need to refcount the SpriteGroup.
- * --pasky */
+ if (engine_custom_sprites[engine][cargo] != NULL) {
+ DEBUG(grf, 6)("SetCustomEngineSprites: engine `%d' cargo `%d' already has group -- removing.", engine, cargo);
+ UnloadSpriteGroup(&engine_custom_sprites[engine][cargo]);
+ }
engine_custom_sprites[engine][cargo] = group;
group->ref_count++;
}
+/**
+ * Unload all engine sprite groups.
+ */
+void UnloadCustomEngineSprites(void)
+{
+ EngineID engine;
+ CargoID cargo;
+
+ for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
+ for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) {
+ if (engine_custom_sprites[engine][cargo] != NULL) {
+ DEBUG(grf, 6)("UnloadCustomEngineSprites: Unloading group for engine `%d' cargo `%d'.", engine, cargo);
+ UnloadSpriteGroup(&engine_custom_sprites[engine][cargo]);
+ }
+ }
+ }
+}
+
typedef SpriteGroup *(*resolve_callback)(const SpriteGroup *spritegroup,
const Vehicle *veh, uint16 callback_info, void *resolve_func); /* XXX data pointer used as function pointer */