1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Improve mass deletion performance

This commit is contained in:
tobspr
2020-09-19 08:51:28 +02:00
parent b7c773a70e
commit 5bdf6386a1
4 changed files with 269 additions and 239 deletions

View File

@@ -48,6 +48,9 @@ export class HUDMassSelector extends BaseHUDPart {
* @param {Entity} entity
*/
onEntityDestroyed(entity) {
if (this.root.bulkOperationRunning) {
return;
}
this.selectedUids.delete(entity.uid);
}
@@ -90,14 +93,30 @@ export class HUDMassSelector extends BaseHUDPart {
doDelete() {
const entityUids = Array.from(this.selectedUids);
for (let i = 0; i < entityUids.length; ++i) {
const uid = entityUids[i];
const entity = this.root.entityMgr.findByUid(uid);
if (!this.root.logic.tryDeleteBuilding(entity)) {
logger.error("Error in mass delete, could not remove building");
this.selectedUids.delete(uid);
// Build mapping from uid to entity
/**
* @type {Map<number, Entity>}
*/
const mapUidToEntity = this.root.entityMgr.getFrozenUidSearchMap();
this.root.logic.performBulkOperation(() => {
for (let i = 0; i < entityUids.length; ++i) {
const uid = entityUids[i];
const entity = mapUidToEntity.get(uid);
if (!entity) {
logger.error("Entity not found by uid:", uid);
continue;
}
if (!this.root.logic.tryDeleteBuilding(entity)) {
logger.error("Error in mass delete, could not remove building");
}
}
}
});
// Clear uids later
this.selectedUids = new Set();
}
startCopy() {