Fix 03cc0d6: Mark level crossings dirty when removing road from them, not from bridge...
[openttd-github.git] / src / animated_tile.cpp
blob5329b2b5068f01568ba8d36c908f28a063b84628
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file animated_tile.cpp Everything related to animated tiles. */
10 #include "stdafx.h"
11 #include "core/alloc_func.hpp"
12 #include "core/smallvec_type.hpp"
13 #include "tile_cmd.h"
14 #include "viewport_func.h"
15 #include "framerate_type.h"
17 #include "safeguards.h"
19 /** The table/list with animated tiles. */
20 std::vector<TileIndex> _animated_tiles;
22 /**
23 * Removes the given tile from the animated tile table.
24 * @param tile the tile to remove
26 void DeleteAnimatedTile(TileIndex tile)
28 auto to_remove = std::find(_animated_tiles.begin(), _animated_tiles.end(), tile);
29 if (to_remove != _animated_tiles.end()) {
30 /* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */
31 _animated_tiles.erase(to_remove);
32 MarkTileDirtyByTile(tile);
36 /**
37 * Add the given tile to the animated tile table (if it does not exist
38 * on that table yet). Also increases the size of the table if necessary.
39 * @param tile the tile to make animated
41 void AddAnimatedTile(TileIndex tile)
43 MarkTileDirtyByTile(tile);
44 include(_animated_tiles, tile);
47 /**
48 * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
50 void AnimateAnimatedTiles()
52 PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
54 const TileIndex *ti = _animated_tiles.data();
55 while (ti < _animated_tiles.data() + _animated_tiles.size()) {
56 const TileIndex curr = *ti;
57 AnimateTile(curr);
58 /* During the AnimateTile call, DeleteAnimatedTile could have been called,
59 * deleting an element we've already processed and pushing the rest one
60 * slot to the left. We can detect this by checking whether the index
61 * in the current slot has changed - if it has, an element has been deleted,
62 * and we should process the current slot again instead of going forward.
63 * NOTE: this will still break if more than one animated tile is being
64 * deleted during the same AnimateTile call, but no code seems to
65 * be doing this anyway.
67 if (*ti == curr) ++ti;
71 /**
72 * Initialize all animated tile variables to some known begin point
74 void InitializeAnimatedTiles()
76 _animated_tiles.clear();