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;
|
||||
|
||||
const entityLength = beltComp.getEffectiveLengthTiles();
|
||||
assert(this.entityPath.indexOf(entity) >= 0, "Entity not contained for split");
|
||||
assert(this.entityPath.indexOf(entity) !== 0, "Entity is first");
|
||||
assert(this.entityPath.indexOf(entity) !== this.entityPath.length - 1, "Entity is last");
|
||||
const index = this.entityPath.indexOf(entity);
|
||||
assert(index >= 0, "Entity not contained for split");
|
||||
assert(index !== 0, "Entity is first");
|
||||
assert(index !== this.entityPath.length - 1, "Entity is last");
|
||||
|
||||
let firstPathEntityCount = 0;
|
||||
let firstPathLength = 0;
|
||||
|
@ -37,7 +37,10 @@ export class GameSystemWithFilter extends GameSystem {
|
||||
}
|
||||
|
||||
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);
|
||||
// Remove all entities which are queued for destroy
|
||||
|
||||
this.tryUpdateEntitiesArray();
|
||||
|
||||
for (let i = 0; i < this.allEntitiesArray.length; ++i) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
if (entity.queuedForDestroy || entity.destroyed) {
|
||||
this.allEntitiesSet.delete(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 minimumTimeForThroughput = now - 1;
|
||||
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const readerComp = entity.components.BeltReader;
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
|
@ -19,11 +19,8 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
// Set signals
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
pinsComp.slots[0].value = signalComp.signal;
|
||||
|
@ -20,11 +20,8 @@ export class FilterSystem extends GameSystemWithFilter {
|
||||
|
||||
const requiredProgress = 1 - progress;
|
||||
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const filterComp = entity.components.Filter;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
|
@ -25,21 +25,15 @@ export class HubSystem extends GameSystemWithFilter {
|
||||
* @param {DrawParameters} parameters
|
||||
*/
|
||||
draw(parameters) {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
this.drawEntity(parameters, entity);
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition(
|
||||
this.root.hubGoals.currentGoal.definition
|
||||
|
@ -39,11 +39,8 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
// Reset accumulated ticks
|
||||
this.accumulatedTicksWhileInMapOverview = 0;
|
||||
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const aceptorComp = entity.components.ItemAcceptor;
|
||||
const animations = aceptorComp.itemConsumptionAnimations;
|
||||
|
||||
|
@ -61,11 +61,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
*/
|
||||
recomputeCacheFull() {
|
||||
logger.log("Full cache recompute in post load hook");
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
this.recomputeSingleEntityCache(entity);
|
||||
}
|
||||
}
|
||||
@ -150,11 +147,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
// Go over all cache entries
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, sourceEntity;
|
||||
(sourceEntity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const sourceEntity = this.allEntitiesArray[i];
|
||||
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
||||
|
||||
const slots = sourceEjectorComp.slots;
|
||||
|
@ -68,11 +68,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
update() {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const processorComp = entity.components.ItemProcessor;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
|
@ -14,11 +14,8 @@ export class LeverSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
update() {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const leverComp = entity.components.Lever;
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
|
@ -30,11 +30,8 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
update() {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const logicComp = entity.components.LogicGate;
|
||||
const slotComp = entity.components.WiredPins;
|
||||
|
||||
|
@ -36,11 +36,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
miningSpeed *= 100;
|
||||
}
|
||||
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const minerComp = entity.components.Miner;
|
||||
|
||||
// Reset everything on recompute
|
||||
|
@ -26,11 +26,8 @@ export class StorageSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
update() {
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const storageComp = entity.components.Storage;
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
|
@ -223,11 +223,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
this.staleAreaWatcher.update();
|
||||
for (
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
const undergroundComp = entity.components.UndergroundBelt;
|
||||
if (undergroundComp.mode === enumUndergroundBeltMode.sender) {
|
||||
this.handleSender(entity);
|
||||
|
Loading…
Reference in New Issue
Block a user