1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Placing blueprints no longer triggers the redirection of belts.

This commit is contained in:
hexagonhexagon 2020-06-24 21:01:12 -04:00
parent affac62a66
commit 03670eb403
3 changed files with 42 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import { findNiceIntegerValue } from "../../../core/utils";
import { Math_pow } from "../../../core/builtins";
import { blueprintShape } from "../../upgrades";
import { globalConfig } from "../../../core/config";
import { Rectangle } from "../../../core/rectangle";
const logger = createLogger("blueprint");
@ -176,6 +177,15 @@ export class Blueprint {
tryPlace(root, tile) {
return root.logic.performBulkOperation(() => {
let anyPlaced = false;
/**
* To avoid recomputing belt direction when belts are placed, we manually
* recompute the belt cache without redirecting the belts by calculating the
* area that needs to update.
* @type {Rectangle?}
*/
let rectCoveredByBlueprint = null;
for (let i = 0; i < this.entities.length; ++i) {
let placeable = true;
const entity = this.entities[i];
@ -216,9 +226,21 @@ export class Blueprint {
root.map.placeStaticEntity(clone);
root.entityMgr.registerEntity(clone);
if (rectCoveredByBlueprint === null) {
rectCoveredByBlueprint = rect.clone();
} else {
rectCoveredByBlueprint = rectCoveredByBlueprint.getUnion(rect);
}
anyPlaced = true;
}
}
if (anyPlaced) {
logger.log(rectCoveredByBlueprint);
root.signals.blueprintPlacedUpdateBeltCache.dispatch(
rectCoveredByBlueprint.expandedInAllDirections(1)
);
}
return anyPlaced;
});
}

View File

@ -1,6 +1,7 @@
/* eslint-disable no-unused-vars */
import { Signal } from "../core/signal";
import { Rectangle } from "../core/rectangle";
import { RandomNumberGenerator } from "../core/rng";
import { createLogger } from "../core/logging";
@ -133,6 +134,9 @@ export class GameRoot {
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityDestroyed: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
// Special case for updating when a blueprint is placed.
blueprintPlacedUpdateBeltCache: /** @type {TypedSignal<[Rectangle]>} */ (new Signal()),
// Global
resized: /** @type {TypedSignal<[number, number]>} */ (new Signal()),
readyToRender: /** @type {TypedSignal<[]>} */ (new Signal()),

View File

@ -61,7 +61,8 @@ export class BeltSystem extends GameSystemWithFilter {
],
};
this.root.signals.entityAdded.add(this.updateSurroundingBeltPlacement, this);
this.root.signals.entityManuallyPlaced.add(this.updateSurroundingBeltPlacement, this);
this.root.signals.blueprintPlacedUpdateBeltCache.add(this.updateAreaToRecompute, this);
this.root.signals.entityDestroyed.add(this.updateSurroundingBeltPlacement, this);
this.root.signals.postLoadHook.add(this.computeBeltCache, this);
@ -69,6 +70,19 @@ export class BeltSystem extends GameSystemWithFilter {
this.areaToRecompute = null;
}
/**
* Queue the recomputation of the belt cache for the given affected area the change happened
* @param {Rectangle} affectedArea
*/
updateAreaToRecompute(affectedArea) {
if (this.areaToRecompute) {
this.areaToRecompute = this.areaToRecompute.getUnion(affectedArea);
} else {
this.areaToRecompute = affectedArea.clone();
}
logger.log("Queuing recompute:", this.areaToRecompute);
}
/**
* Updates the belt placement after an entity has been added / deleted
* @param {Entity} entity
@ -123,12 +137,7 @@ export class BeltSystem extends GameSystemWithFilter {
}
if (anythingChanged) {
if (this.areaToRecompute) {
this.areaToRecompute = this.areaToRecompute.getUnion(affectedArea);
} else {
this.areaToRecompute = affectedArea.clone();
}
logger.log("Queuing recompute:", this.areaToRecompute);
this.updateAreaToRecompute(affectedArea);
}
}