diff options
author | peter1138 <peter1138@openttd.org> | 2005-10-04 21:42:00 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2005-10-04 21:42:00 +0000 |
commit | abe60acbbb18414c088a77958eb04d5d68a7f9cc (patch) | |
tree | 8a9d84ea55620c79439c18989514cb8167dfcbb6 /engine.c | |
parent | c655e13e92aefef1503e7869b3dc3185cc1b2757 (diff) | |
download | openttd-abe60acbbb18414c088a77958eb04d5d68a7f9cc.tar.xz |
(svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
Diffstat (limited to 'engine.c')
-rw-r--r-- | engine.c | 47 |
1 files changed, 44 insertions, 3 deletions
@@ -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 */ |