Codechange: Store animated tile state in map to improve performance.

This allows animated tiles to be added and removed without searching in the animated tile list, providing a performance improvement when there are lots of animated tiles.

Save game version is bumped so that animated tile state can be converted.
This commit is contained in:
2024-11-27 19:33:32 +00:00
committed by Peter Nelson
parent 44de8d77bf
commit 6a07f28103
7 changed files with 110 additions and 28 deletions

View File

@@ -43,6 +43,7 @@
#include "../game/game.hpp"
#include "../town.h"
#include "../economy_base.h"
#include "../animated_tile_map.h"
#include "../animated_tile_func.h"
#include "../subsidy_base.h"
#include "../subsidy_func.h"
@@ -2225,6 +2226,23 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(SLV_ANIMATED_TILE_STATE_IN_MAP)) {
/* Animated tile state is stored in the map array, allowing
* quicker addition and deletion of animated tiles. */
extern std::vector<TileIndex> _animated_tiles;
for (auto t : Map::Iterate()) {
/* Ensure there is no spurious animated tile state. */
if (MayAnimateTile(t)) SetAnimatedTileState(t, AnimatedTileState::None);
}
/* Set animated flag for all valid animated tiles. */
for (const TileIndex &tile : _animated_tiles) {
if (tile != INVALID_TILE) SetAnimatedTileState(tile, AnimatedTileState::Animated);
}
}
if (IsSavegameVersionBefore(SLV_124) && !IsSavegameVersionBefore(SLV_1)) {
/* The train station tile area was added, but for really old (TTDPatch) it's already valid. */
for (Waypoint *wp : Waypoint::Iterate()) {