Skip to content

Commit

Permalink
Speed up object erasure in the Editor
Browse files Browse the repository at this point in the history
No need to update map information for each town and hero.

relates to #6845
  • Loading branch information
ihhub committed May 18, 2024
1 parent d097964 commit b5ef755
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/fheroes2/editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,12 @@ namespace
}

bool needRedraw = false;
bool updateMapPlayerInformation = false;

// Filter objects by group and remove them from '_mapFormat'.
for ( size_t mapTileIndex = 0; mapTileIndex < mapFormat.tiles.size(); ++mapTileIndex ) {
Maps::Map_Format::TileInfo & mapTile = mapFormat.tiles[mapTileIndex];

if ( mapTile.objects.empty() ) {
continue;
}

for ( auto objectIter = mapTile.objects.begin(); objectIter != mapTile.objects.end(); ) {
// LANDSCAPE_FLAGS and LANDSCAPE_TOWN_BASEMENTS are special objects that should be erased only when erasing the main object.
if ( objectIter->group == Maps::ObjectGroup::LANDSCAPE_FLAGS || objectIter->group == Maps::ObjectGroup::LANDSCAPE_TOWN_BASEMENTS
Expand Down Expand Up @@ -281,10 +278,7 @@ namespace
}

needRedraw = true;

if ( !Maps::updateMapPlayers( mapFormat ) ) {
assert( 0 );
}
updateMapPlayerInformation = true;
}
else if ( objectIter->group == Maps::ObjectGroup::ROADS ) {
assert( mapTileIndex < world.getSize() );
Expand All @@ -308,9 +302,7 @@ namespace
objectIter = mapTile.objects.erase( objectIter );
needRedraw = true;

if ( !Maps::updateMapPlayers( mapFormat ) ) {
assert( 0 );
}
updateMapPlayerInformation = true;
}
else if ( objectIter->group == Maps::ObjectGroup::MONSTERS ) {
assert( mapFormat.standardMetadata.find( objectIter->id ) != mapFormat.standardMetadata.end() );
Expand Down Expand Up @@ -375,6 +367,12 @@ namespace
}
}

if ( updateMapPlayerInformation ) {
if ( !Maps::updateMapPlayers( mapFormat ) ) {
assert( 0 );
}
}

return needRedraw;
}

Expand Down

0 comments on commit b5ef755

Please sign in to comment.