Files
@ r24498:e9114d9ab04a
Branch filter:
Location: cpp/openttd-patchpack/source/src/animated_tile.cpp - annotation
r24498:e9114d9ab04a
2.7 KiB
text/x-c
Fix #6468: don't store version of AIs-started-via-console in name
You can do: "startai myai.3", which starts version 3 of "myai".
This is very useful for testing save/load code between different
versions of your AI.
However, when using this syntax, the AI got saved as "myai.3" as
name of the AI, instead of "myai". This caused several problems,
like indicating to the user the AI could not be found, but still
load the AI. But in all cases, the AI never got the chance to
load the saved data, making the whole reason this exists pointless.
By splitting the name and version already in the console command,
the code becomes simpler and AIs started this way now follow the
normal flow after initialization.
You can do: "startai myai.3", which starts version 3 of "myai".
This is very useful for testing save/load code between different
versions of your AI.
However, when using this syntax, the AI got saved as "myai.3" as
name of the AI, instead of "myai". This caused several problems,
like indicating to the user the AI could not be found, but still
load the AI. But in all cases, the AI never got the chance to
load the saved data, making the whole reason this exists pointless.
By splitting the name and version already in the console command,
the code becomes simpler and AIs started this way now follow the
normal flow after initialization.
r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r22807:e6e3e3473802 r17267:4f82ca9bd495 r17267:4f82ca9bd495 r22959:8c769e762c2f r9005:e59c0b10c56a r21383:942c32fb8b0e r21383:942c32fb8b0e r9005:e59c0b10c56a r23538:8df50944b27a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r23525:e8acc751d575 r23525:e8acc751d575 r22807:e6e3e3473802 r23525:e8acc751d575 r22807:e6e3e3473802 r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r23535:9604c18808f0 r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r22959:8c769e762c2f r22959:8c769e762c2f r23536:ce42deb0b32d r23536:ce42deb0b32d r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r9005:e59c0b10c56a r23517:1a32c3c14728 r9005:e59c0b10c56a | /*
* 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/>.
*/
/** @file animated_tile.cpp Everything related to animated tiles. */
#include "stdafx.h"
#include "core/alloc_func.hpp"
#include "core/smallvec_type.hpp"
#include "tile_cmd.h"
#include "viewport_func.h"
#include "framerate_type.h"
#include "safeguards.h"
/** The table/list with animated tiles. */
std::vector<TileIndex> _animated_tiles;
/**
* Removes the given tile from the animated tile table.
* @param tile the tile to remove
*/
void DeleteAnimatedTile(TileIndex tile)
{
auto to_remove = std::find(_animated_tiles.begin(), _animated_tiles.end(), tile);
if (to_remove != _animated_tiles.end()) {
/* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */
_animated_tiles.erase(to_remove);
MarkTileDirtyByTile(tile);
}
}
/**
* 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);
include(_animated_tiles, tile);
}
/**
* Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
*/
void AnimateAnimatedTiles()
{
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
const TileIndex *ti = _animated_tiles.data();
while (ti < _animated_tiles.data() + _animated_tiles.size()) {
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()
{
_animated_tiles.clear();
}
|