OpenTTD
animated_tile.cpp
Go to the documentation of this file.
1 /* $Id: animated_tile.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "core/alloc_func.hpp"
14 #include "tile_cmd.h"
15 #include "viewport_func.h"
16 
17 #include "safeguards.h"
18 
25 
31 {
33  if (tile == *ti) {
34  /* Remove the hole
35  * The order of the remaining elements must stay the same, otherwise the animation loop
36  * may miss a tile; that's why we must use memmove instead of just moving the last element.
37  */
38  memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
39  _animated_tile_count--;
40  MarkTileDirtyByTile(tile);
41  return;
42  }
43  }
44 }
45 
52 {
53  MarkTileDirtyByTile(tile);
54 
56  if (tile == *ti) return;
57  }
58 
59  /* Table not large enough, so make it larger */
60  if (_animated_tile_count == _animated_tile_allocated) {
63  }
64 
66  _animated_tile_count++;
67 }
68 
73 {
74  const TileIndex *ti = _animated_tile_list;
76  const TileIndex curr = *ti;
77  AnimateTile(curr);
78  /* During the AnimateTile call, DeleteAnimatedTile could have been called,
79  * deleting an element we've already processed and pushing the rest one
80  * slot to the left. We can detect this by checking whether the index
81  * in the current slot has changed - if it has, an element has been deleted,
82  * and we should process the current slot again instead of going forward.
83  * NOTE: this will still break if more than one animated tile is being
84  * deleted during the same AnimateTile call, but no code seems to
85  * be doing this anyway.
86  */
87  if (*ti == curr) ++ti;
88  }
89 }
90 
95 {
96  _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
99 }