mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
assignments in loops can be slower
This commit is contained in:
parent
be7d3c2c4f
commit
922a6680e5
@ -565,9 +565,10 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
beltComp.assignedPath = null;
|
beltComp.assignedPath = null;
|
||||||
|
|
||||||
const entityLength = beltComp.getEffectiveLengthTiles();
|
const entityLength = beltComp.getEffectiveLengthTiles();
|
||||||
assert(this.entityPath.indexOf(entity) >= 0, "Entity not contained for split");
|
const index = this.entityPath.indexOf(entity);
|
||||||
assert(this.entityPath.indexOf(entity) !== 0, "Entity is first");
|
assert(index >= 0, "Entity not contained for split");
|
||||||
assert(this.entityPath.indexOf(entity) !== this.entityPath.length - 1, "Entity is last");
|
assert(index !== 0, "Entity is first");
|
||||||
|
assert(index !== this.entityPath.length - 1, "Entity is last");
|
||||||
|
|
||||||
let firstPathEntityCount = 0;
|
let firstPathEntityCount = 0;
|
||||||
let firstPathLength = 0;
|
let firstPathLength = 0;
|
||||||
|
@ -37,7 +37,10 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tryUpdateEntitiesArray() {
|
tryUpdateEntitiesArray() {
|
||||||
this.allEntitiesArray = [...this.allEntitiesSet.values()];
|
if (this.allEntitiesArrayIsOutdated) {
|
||||||
|
this.allEntitiesArray = [...this.allEntitiesSet.values()];
|
||||||
|
this.allEntitiesArrayIsOutdated = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,15 +96,16 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
//this.allEntities.sort((a, b) => a.uid - b.uid);
|
//this.allEntities.sort((a, b) => a.uid - b.uid);
|
||||||
// Remove all entities which are queued for destroy
|
// Remove all entities which are queued for destroy
|
||||||
|
|
||||||
this.tryUpdateEntitiesArray();
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
|
|
||||||
for (let i = 0; i < this.allEntitiesArray.length; ++i) {
|
|
||||||
const entity = this.allEntitiesArray[i];
|
const entity = this.allEntitiesArray[i];
|
||||||
if (entity.queuedForDestroy || entity.destroyed) {
|
if (entity.queuedForDestroy || entity.destroyed) {
|
||||||
this.allEntitiesSet.delete(this.allEntitiesArray[i]);
|
this.allEntitiesSet.delete(this.allEntitiesArray[i]);
|
||||||
fastArrayDelete(this.allEntitiesArray, i);
|
fastArrayDelete(this.allEntitiesArray, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// called here in case a delete executed mid frame
|
||||||
|
this.tryUpdateEntitiesArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,11 +13,8 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds;
|
const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds;
|
||||||
const minimumTimeForThroughput = now - 1;
|
const minimumTimeForThroughput = now - 1;
|
||||||
|
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const readerComp = entity.components.BeltReader;
|
const readerComp = entity.components.BeltReader;
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
|
@ -19,11 +19,8 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
// Set signals
|
// Set signals
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
const signalComp = entity.components.ConstantSignal;
|
const signalComp = entity.components.ConstantSignal;
|
||||||
pinsComp.slots[0].value = signalComp.signal;
|
pinsComp.slots[0].value = signalComp.signal;
|
||||||
|
@ -20,11 +20,8 @@ export class FilterSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
const requiredProgress = 1 - progress;
|
const requiredProgress = 1 - progress;
|
||||||
|
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const filterComp = entity.components.Filter;
|
const filterComp = entity.components.Filter;
|
||||||
const ejectorComp = entity.components.ItemEjector;
|
const ejectorComp = entity.components.ItemEjector;
|
||||||
|
|
||||||
|
@ -25,21 +25,15 @@ export class HubSystem extends GameSystemWithFilter {
|
|||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
*/
|
*/
|
||||||
draw(parameters) {
|
draw(parameters) {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
this.drawEntity(parameters, entity);
|
this.drawEntity(parameters, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition(
|
pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition(
|
||||||
this.root.hubGoals.currentGoal.definition
|
this.root.hubGoals.currentGoal.definition
|
||||||
|
@ -39,11 +39,8 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|||||||
// Reset accumulated ticks
|
// Reset accumulated ticks
|
||||||
this.accumulatedTicksWhileInMapOverview = 0;
|
this.accumulatedTicksWhileInMapOverview = 0;
|
||||||
|
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const aceptorComp = entity.components.ItemAcceptor;
|
const aceptorComp = entity.components.ItemAcceptor;
|
||||||
const animations = aceptorComp.itemConsumptionAnimations;
|
const animations = aceptorComp.itemConsumptionAnimations;
|
||||||
|
|
||||||
|
@ -61,11 +61,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
*/
|
*/
|
||||||
recomputeCacheFull() {
|
recomputeCacheFull() {
|
||||||
logger.log("Full cache recompute in post load hook");
|
logger.log("Full cache recompute in post load hook");
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
this.recomputeSingleEntityCache(entity);
|
this.recomputeSingleEntityCache(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,11 +147,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go over all cache entries
|
// Go over all cache entries
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, sourceEntity;
|
const sourceEntity = this.allEntitiesArray[i];
|
||||||
(sourceEntity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
||||||
|
|
||||||
const slots = sourceEjectorComp.slots;
|
const slots = sourceEjectorComp.slots;
|
||||||
|
@ -68,11 +68,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const processorComp = entity.components.ItemProcessor;
|
const processorComp = entity.components.ItemProcessor;
|
||||||
const ejectorComp = entity.components.ItemEjector;
|
const ejectorComp = entity.components.ItemEjector;
|
||||||
|
|
||||||
|
@ -14,11 +14,8 @@ export class LeverSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const leverComp = entity.components.Lever;
|
const leverComp = entity.components.Lever;
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
|
@ -30,11 +30,8 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const logicComp = entity.components.LogicGate;
|
const logicComp = entity.components.LogicGate;
|
||||||
const slotComp = entity.components.WiredPins;
|
const slotComp = entity.components.WiredPins;
|
||||||
|
|
||||||
|
@ -36,11 +36,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
|||||||
miningSpeed *= 100;
|
miningSpeed *= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const minerComp = entity.components.Miner;
|
const minerComp = entity.components.Miner;
|
||||||
|
|
||||||
// Reset everything on recompute
|
// Reset everything on recompute
|
||||||
|
@ -26,11 +26,8 @@ export class StorageSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const storageComp = entity.components.Storage;
|
const storageComp = entity.components.Storage;
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
|
@ -223,11 +223,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.staleAreaWatcher.update();
|
this.staleAreaWatcher.update();
|
||||||
for (
|
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||||
let i = this.allEntitiesArray.length - 1, entity;
|
const entity = this.allEntitiesArray[i];
|
||||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
|
||||||
--i
|
|
||||||
) {
|
|
||||||
const undergroundComp = entity.components.UndergroundBelt;
|
const undergroundComp = entity.components.UndergroundBelt;
|
||||||
if (undergroundComp.mode === enumUndergroundBeltMode.sender) {
|
if (undergroundComp.mode === enumUndergroundBeltMode.sender) {
|
||||||
this.handleSender(entity);
|
this.handleSender(entity);
|
||||||
|
Loading…
Reference in New Issue
Block a user