mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-24 17:26:41 +00:00
fix long-standing editor bug that would cause entities to be moved around
This was caused by early deletion of entities. If new ones were spawned upon further editing of a map, it could re-use entity IDs and cause both new and old entities to be spawned in the position of the new entity (due to EntitySaveData of the old one still intact). This is now prevented by not touching the ID range of map entities. Should probably make an offline tool to recompress entity IDs...
This commit is contained in:
parent
9fd024dadd
commit
fc38d375bb
2 changed files with 8 additions and 2 deletions
|
@ -228,6 +228,7 @@ Game::Game() : StateObject()
|
|||
doScreenTrans = false;
|
||||
noSceneTransitionFadeout = false;
|
||||
fullTilesetReload = false;
|
||||
highestLoadedEntityID = 0;
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
|
@ -943,7 +944,7 @@ EntitySaveData *Game::getEntitySaveDataForEntity(Entity *e)
|
|||
int Game::findUnusedEntityID(bool temporary) const
|
||||
{
|
||||
const int inc = temporary ? -1 : 1;
|
||||
int id = 0;
|
||||
int id = temporary ? 0 : highestLoadedEntityID + 1; // never touch entity IDs that were in use in the map xml
|
||||
retry:
|
||||
id += inc;
|
||||
FOR_ENTITIES(i)
|
||||
|
@ -1845,9 +1846,11 @@ bool Game::loadSceneXML(std::string scene)
|
|||
void Game::spawnEntities(const EntitySaveData *sav, size_t n)
|
||||
{
|
||||
std::vector<size_t> conflicting, usable;
|
||||
int highest = 0;
|
||||
for(size_t i = 0; i < n; ++i)
|
||||
{
|
||||
const EntitySaveData& es = sav[i];
|
||||
highest = std::max(es.id, highest);
|
||||
|
||||
// check for ID conflicts
|
||||
int id = es.id;
|
||||
|
@ -1870,6 +1873,8 @@ void Game::spawnEntities(const EntitySaveData *sav, size_t n)
|
|||
conflicting.push_back(i);
|
||||
}
|
||||
|
||||
highestLoadedEntityID = highest;
|
||||
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Game::spawnEntities: Spawning " << usable.size() << " entities";
|
||||
|
@ -1888,7 +1893,7 @@ void Game::spawnEntities(const EntitySaveData *sav, size_t n)
|
|||
}
|
||||
|
||||
// spawn and renumber the rest
|
||||
int lastid = 0;
|
||||
int lastid = highest;
|
||||
for(size_t i = 0; i < conflicting.size(); ++i)
|
||||
{
|
||||
// find an unused ID
|
||||
|
|
|
@ -422,6 +422,7 @@ public:
|
|||
void onContinuityReset();
|
||||
|
||||
protected:
|
||||
unsigned highestLoadedEntityID;
|
||||
|
||||
void toggleHelpScreen(bool on, const std::string &label="");
|
||||
void onToggleHelpScreen();
|
||||
|
|
Loading…
Reference in a new issue