# HG changeset patch # User rubidium # Date 1191873381 0 # Node ID efd1f3b110a2622adec5c1de6cbf0e078e4a7247 # Parent cb69489204516f19b4778feead71ff7a03fb0d32 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries. diff -r cb6948920451 -r efd1f3b110a2 src/functions.h --- a/src/functions.h Mon Oct 08 18:45:33 2007 +0000 +++ b/src/functions.h Mon Oct 08 19:56:21 2007 +0000 @@ -78,7 +78,7 @@ uint InteractiveRandomRange(uint max); /* texteff.cpp */ -bool AddAnimatedTile(TileIndex tile); +void AddAnimatedTile(TileIndex tile); void DeleteAnimatedTile(TileIndex tile); void AnimateAnimatedTiles(); void InitializeAnimatedTiles(); diff -r cb6948920451 -r efd1f3b110a2 src/newgrf.cpp --- a/src/newgrf.cpp Mon Oct 08 18:45:33 2007 +0000 +++ b/src/newgrf.cpp Mon Oct 08 19:56:21 2007 +0000 @@ -4705,7 +4705,7 @@ | (1 << 0x19) // newhouses | (1 << 0x1A) // newbridges | (1 << 0x1B) // newtownnames - | (0 << 0x1C) // moreanimations + | (1 << 0x1C) // moreanimation | ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D) // wagonspeedlimits | (1 << 0x1E) // newshistory | (0 << 0x1F); // custombridgeheads diff -r cb6948920451 -r efd1f3b110a2 src/oldloader.cpp --- a/src/oldloader.cpp Mon Oct 08 18:45:33 2007 +0000 +++ b/src/oldloader.cpp Mon Oct 08 19:56:21 2007 +0000 @@ -376,7 +376,8 @@ #define REMAP_TOWN_IDX(x) ((x) - (0x0459154 - 0x0458EF0)) / 94 #define REMAP_ORDER_IDX(x) ((x) - (0x045AB08 - 0x0458EF0)) / 2 -extern TileIndex _animated_tile_list[256]; +extern TileIndex *_animated_tile_list; +extern uint _animated_tile_count; extern char _name_array[512][32]; static byte _old_vehicle_multiplier; @@ -1422,7 +1423,7 @@ OCL_CHUNK(5000, LoadOldOrder ), OCL_ASSERT( 0x4328 ), - OCL_VAR ( OC_TILE, 256, &_animated_tile_list[0] ), + OCL_VAR ( OC_TILE, 256, _animated_tile_list ), OCL_NULL( 4 ), ///< old end-of-order-list-pointer, no longer in use OCL_CHUNK( 255, LoadOldDepot ), @@ -1553,6 +1554,10 @@ _m[i].m4 = _old_map3[i * 2 + 1]; } + for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) { + if (_animated_tile_list[_animated_tile_count] == 0) break; + } + for (i = 0; i < OLD_MAP_SIZE; i ++) { switch (GetTileType(i)) { case MP_STATION: diff -r cb6948920451 -r efd1f3b110a2 src/saveload.cpp --- a/src/saveload.cpp Mon Oct 08 18:45:33 2007 +0000 +++ b/src/saveload.cpp Mon Oct 08 19:56:21 2007 +0000 @@ -29,7 +29,7 @@ #include "strings.h" #include -extern const uint16 SAVEGAME_VERSION = 79; +extern const uint16 SAVEGAME_VERSION = 80; uint16 _sl_version; ///< the major savegame version identifier byte _sl_minor_version; ///< the minor savegame version, DO NOT USE! diff -r cb6948920451 -r efd1f3b110a2 src/texteff.cpp --- a/src/texteff.cpp Mon Oct 08 18:45:33 2007 +0000 +++ b/src/texteff.cpp Mon Oct 08 19:56:21 2007 +0000 @@ -25,7 +25,6 @@ MAX_TEXTMESSAGE_LENGTH = 200, INIT_NUM_TEXT_MESSAGES = 20, MAX_CHAT_MESSAGES = 10, - MAX_ANIMATED_TILES = 256, }; struct TextEffect { @@ -50,7 +49,6 @@ /* used for text effects */ static TextEffect *_text_effect_list = NULL; static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES; -TileIndex _animated_tile_list[MAX_ANIMATED_TILES]; /* used for chat window */ static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES]; @@ -422,62 +420,112 @@ } } +/** The table/list with animated tiles. */ +TileIndex *_animated_tile_list = NULL; +/** The number of animated tiles in the current state. */ +uint _animated_tile_count = 0; +/** The number of slots for animated tiles allocated currently. */ +static uint _animated_tile_allocated = 0; + +/** + * Removes the given tile from the animated tile table. + * @param tile the tile to remove + */ void DeleteAnimatedTile(TileIndex tile) { - TileIndex *ti; - - for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) { + for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) { if (tile == *ti) { - /* remove the hole */ - memmove(ti, ti + 1, (lastof(_animated_tile_list) - ti) * sizeof(*ti)); - /* and clear last item */ - *lastof(_animated_tile_list) = 0; + /* Remove the hole */ + *ti = _animated_tile_list[_animated_tile_count - 1]; + _animated_tile_count--; MarkTileDirtyByTile(tile); return; } } } -bool AddAnimatedTile(TileIndex tile) +/** + * Add the given tile to the animated tile table (if it does not exist + * on that table yet). Also increases the size of the table if necessary. + * @param tile the tile to make animated + */ +void AddAnimatedTile(TileIndex tile) { - TileIndex *ti; + MarkTileDirtyByTile(tile); - for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) { - if (tile == *ti || *ti == 0) { - *ti = tile; - MarkTileDirtyByTile(tile); - return true; - } + for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) { + if (tile == *ti) return; } - return false; + /* Table not large enough, so make it larger */ + if (_animated_tile_count == _animated_tile_allocated) { + _animated_tile_allocated *= 2; + _animated_tile_list = ReallocT(_animated_tile_list, _animated_tile_allocated); + } + + _animated_tile_list[_animated_tile_count] = tile; + _animated_tile_count++; } +/** + * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them. + */ void AnimateAnimatedTiles() { - const TileIndex* ti; - - for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) { + for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) { AnimateTile(*ti); } } +/** + * Initialize all animated tile variables to some known begin point + */ void InitializeAnimatedTiles() { - memset(_animated_tile_list, 0, sizeof(_animated_tile_list)); + _animated_tile_list = ReallocT(_animated_tile_list, 256); + _animated_tile_count = 0; + _animated_tile_allocated = 256; } -static void SaveLoad_ANIT() +/** + * Save the ANIT chunk. + */ +static void Save_ANIT() { - /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */ - if (CheckSavegameVersion(6)) { - SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32); - } else { - SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32); - } + SlSetLength(_animated_tile_count * sizeof(*_animated_tile_list)); + SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32); } +/** + * Load the ANIT chunk; the chunk containing the animated tiles. + */ +static void Load_ANIT() +{ + /* Before version 80 we did NOT have a variable length animated tile table */ + if (CheckSavegameVersion(80)) { + /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */ + SlArray(_animated_tile_list, 256, CheckSavegameVersion(6) ? (SLE_FILE_U16 | SLE_VAR_U32) : SLE_UINT32); + for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) { + if (_animated_tile_list[_animated_tile_count] == 0) break; + } + return; + } + + _animated_tile_count = SlGetFieldLength() / sizeof(*_animated_tile_list); + + /* Determine a nice rounded size for the amount of allocated tiles */ + _animated_tile_allocated = 256; + while (_animated_tile_allocated < _animated_tile_count) _animated_tile_allocated *= 2; + + _animated_tile_list = ReallocT(_animated_tile_list, _animated_tile_allocated); + SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32); +} + +/** + * "Definition" imported by the saveload code to be able to load and save + * the animated tile table. + */ extern const ChunkHandler _animated_tile_chunk_handlers[] = { - { 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST}, + { 'ANIT', Save_ANIT, Load_ANIT, CH_RIFF | CH_LAST}, };