Changeset - r7749:a9958b789e3c
[Not reviewed]
master
0 1 0
rubidium - 17 years ago 2007-10-17 16:09:04
rubidium@openttd.org
(svn r11286) -Fix (r11228): NewGRF industries assume that the order of animation always stays the same. Patch by Csaboka.
1 file changed with 19 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/texteff.cpp
Show inline comments
 
@@ -432,14 +432,17 @@ static uint _animated_tile_allocated = 0
 
 * @param tile the tile to remove
 
 */
 
void DeleteAnimatedTile(TileIndex tile)
 
{
 
	for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
 
		if (tile == *ti) {
 
			/* Remove the hole */
 
			*ti = _animated_tile_list[_animated_tile_count - 1];
 
			/* Remove the hole
 
			 * The order of the remaining elements must stay the same, otherwise the animation loop
 
			 * may miss a tile; that's why we must use memmove instead of just moving the last element.
 
			 */
 
			memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
 
			_animated_tile_count--;
 
			MarkTileDirtyByTile(tile);
 
			return;
 
		}
 
	}
 
}
 
@@ -469,14 +472,26 @@ void AddAnimatedTile(TileIndex tile)
 

	
 
/**
 
 * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
 
 */
 
void AnimateAnimatedTiles()
 
{
 
	for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
 
		AnimateTile(*ti);
 
	const TileIndex *ti = _animated_tile_list;
 
	while (ti < _animated_tile_list + _animated_tile_count) {
 
		const TileIndex curr = *ti;
 
		AnimateTile(curr);
 
		/* During the AnimateTile call, DeleteAnimatedTile could have been called,
 
		 * deleting an element we've already processed and pushing the rest one
 
		 * slot to the left. We can detect this by checking whether the index
 
		 * in the current slot has changed - if it has, an element has been deleted,
 
		 * and we should process the current slot again instead of going forward.
 
		 * NOTE: this will still break if more than one animated tile is being
 
		 *       deleted during the same AnimateTile call, but no code seems to
 
		 *       be doing this anyway.
 
		 */
 
		if (*ti == curr) ++ti;
 
	}
 
}
 

	
 
/**
 
 * Initialize all animated tile variables to some known begin point
 
 */
0 comments (0 inline, 0 general)