2008-04-20 08:22:59 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-04-20 08:22:59 +00:00
|
|
|
/** @file animated_tile.cpp Everything related to animated tiles. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "core/alloc_func.hpp"
|
2018-04-14 23:15:26 +00:00
|
|
|
#include "core/smallvec_type.hpp"
|
2011-02-07 22:29:47 +00:00
|
|
|
#include "tile_cmd.h"
|
|
|
|
#include "viewport_func.h"
|
2018-07-19 19:17:07 +00:00
|
|
|
#include "framerate_type.h"
|
2008-04-20 08:22:59 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2008-04-20 08:22:59 +00:00
|
|
|
/** The table/list with animated tiles. */
|
2019-03-03 17:30:09 +00:00
|
|
|
std::vector<TileIndex> _animated_tiles;
|
2008-04-20 08:22:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the given tile from the animated tile table.
|
|
|
|
* @param tile the tile to remove
|
|
|
|
*/
|
|
|
|
void DeleteAnimatedTile(TileIndex tile)
|
|
|
|
{
|
2018-09-24 19:18:16 +00:00
|
|
|
auto to_remove = std::find(_animated_tiles.begin(), _animated_tiles.end(), tile);
|
|
|
|
if (to_remove != _animated_tiles.end()) {
|
2018-04-14 23:15:26 +00:00
|
|
|
/* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */
|
2018-09-24 19:18:16 +00:00
|
|
|
_animated_tiles.erase(to_remove);
|
2018-04-14 23:15:26 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2008-04-20 08:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
MarkTileDirtyByTile(tile);
|
2019-02-20 21:35:41 +00:00
|
|
|
include(_animated_tiles, tile);
|
2008-04-20 08:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
|
|
|
|
*/
|
|
|
|
void AnimateAnimatedTiles()
|
|
|
|
{
|
2018-07-19 19:17:07 +00:00
|
|
|
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
|
|
|
|
2019-02-17 11:20:52 +00:00
|
|
|
const TileIndex *ti = _animated_tiles.data();
|
|
|
|
while (ti < _animated_tiles.data() + _animated_tiles.size()) {
|
2008-04-20 08:22:59 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
void InitializeAnimatedTiles()
|
|
|
|
{
|
2018-09-20 22:44:14 +00:00
|
|
|
_animated_tiles.clear();
|
2008-04-20 08:22:59 +00:00
|
|
|
}
|