mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix click and drag
Clicking and dragging can trigger up to 4 add/destroy signals, and it's a common case.
This commit is contained in:
parent
2341772425
commit
da24c472d7
@ -65,9 +65,8 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
this.root.signals.entityDestroyed.add(this.updateSurroundingBeltPlacement, this);
|
this.root.signals.entityDestroyed.add(this.updateSurroundingBeltPlacement, this);
|
||||||
|
|
||||||
this.cacheNeedsUpdate = true;
|
this.cacheNeedsUpdate = true;
|
||||||
/** @type {Rectangle} */
|
/** @type {Rectangle[]} */
|
||||||
this.singleUpdateArea = null;
|
this.smallUpdateAreas = [];
|
||||||
this.isMultiUpdate = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,15 +118,10 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optimize for the common case of adding or removing one belt.
|
// Optimize for the common case of adding or removing buildings one at a time.
|
||||||
|
// Clicking and dragging can fire up to 4 create/destroy signals.
|
||||||
if (this.cacheNeedsUpdate) {
|
if (this.cacheNeedsUpdate) {
|
||||||
if (this.isMultiUpdate || this.singleUpdateArea) {
|
this.smallUpdateAreas.push(affectedArea.expandedInAllDirections(1));
|
||||||
// This isn't the common case.
|
|
||||||
// The singleUpdateArea will be cleared by the cache update.
|
|
||||||
this.isMultiUpdate = true;
|
|
||||||
} else {
|
|
||||||
this.singleUpdateArea = affectedArea.expandedInAllDirections(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +170,15 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
computeBeltCache() {
|
computeBeltCache() {
|
||||||
logger.log("Updating belt cache");
|
logger.log("Updating belt cache");
|
||||||
|
|
||||||
if (this.singleUpdateArea && !this.isMultiUpdate) {
|
if (this.smallUpdateAreas.length <= 4) {
|
||||||
for (let x = this.singleUpdateArea.x; x < this.singleUpdateArea.right(); ++x) {
|
for (let i = 0; i < this.smallUpdateAreas.length; ++i) {
|
||||||
for (let y = this.singleUpdateArea.y; y < this.singleUpdateArea.bottom(); ++y) {
|
const area = this.smallUpdateAreas[i];
|
||||||
const tile = this.root.map.getTileContentXY(x, y);
|
for (let x = area.x; x < area.right(); ++x) {
|
||||||
if (tile && tile.components.Belt) {
|
for (let y = area.y; y < area.bottom(); ++y) {
|
||||||
tile.components.Belt.followUpCache = this.findFollowUpEntity(tile);
|
const tile = this.root.map.getTileContentXY(x, y);
|
||||||
|
if (tile && tile.components.Belt) {
|
||||||
|
tile.components.Belt.followUpCache = this.findFollowUpEntity(tile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,8 +188,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
entity.components.Belt.followUpCache = this.findFollowUpEntity(entity);
|
entity.components.Belt.followUpCache = this.findFollowUpEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isMultiUpdate = false;
|
this.smallUpdateAreas = [];
|
||||||
this.singleUpdateArea = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
|
Loading…
Reference in New Issue
Block a user