mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
fixing silly mistakes in iteration
This commit is contained in:
parent
54e4f45bcd
commit
6f76246df8
@ -670,3 +670,41 @@ export function safeModulo(n, m) {
|
||||
export function smoothPulse(time) {
|
||||
return Math.sin(time * 4) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
let logIntervals = {};
|
||||
const intervalStyle = "color: grey; font-style: inherit";
|
||||
const keyStyle = "color: purple; font-style: italic";
|
||||
const revertStyle = "color: inherit; font-style: inherit";
|
||||
|
||||
export function logInterval(key, frames, message, ...args) {
|
||||
let interval = logIntervals[key] || 0;
|
||||
if (++interval > frames) {
|
||||
console.log(
|
||||
`%clogInterval [%c${key}%c]: \t%c` + message,
|
||||
intervalStyle,
|
||||
keyStyle,
|
||||
intervalStyle,
|
||||
revertStyle,
|
||||
...args
|
||||
);
|
||||
interval = 0;
|
||||
}
|
||||
logIntervals[key] = interval;
|
||||
}
|
||||
|
||||
export function dirInterval(key, frames, object, premessage, ...args) {
|
||||
let interval = logIntervals[key] || 0;
|
||||
if (++interval > frames) {
|
||||
console.log(
|
||||
`%cdirInterval [%c${key}%c]: \t%c` + (premessage || ""),
|
||||
intervalStyle,
|
||||
keyStyle,
|
||||
intervalStyle,
|
||||
revertStyle,
|
||||
...args
|
||||
);
|
||||
console.dir(object);
|
||||
interval = 0;
|
||||
}
|
||||
logIntervals[key] = interval;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import { Entity } from "./entity";
|
||||
|
||||
import { GameRoot } from "./root";
|
||||
import { GameSystem } from "./game_system";
|
||||
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
||||
import { arrayDelete, arrayDeleteValue, fastArrayDelete } from "../core/utils";
|
||||
|
||||
export class GameSystemWithFilter extends GameSystem {
|
||||
/**
|
||||
@ -36,15 +36,8 @@ export class GameSystemWithFilter extends GameSystem {
|
||||
this.root.signals.bulkOperationFinished.add(this.refreshCaches, this);
|
||||
}
|
||||
|
||||
getUpdateEntitiesArray() {
|
||||
if (!this.allEntitiesArrayIsOutdated) {
|
||||
return this.allEntitiesArray;
|
||||
}
|
||||
|
||||
tryUpdateEntitiesArray() {
|
||||
this.allEntitiesArray = [...this.allEntitiesSet.values()];
|
||||
|
||||
this.allEntitiesArrayIsOutdated = true;
|
||||
return this.allEntitiesArray;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,22 +91,15 @@ export class GameSystemWithFilter extends GameSystem {
|
||||
|
||||
refreshCaches() {
|
||||
//this.allEntities.sort((a, b) => a.uid - b.uid);
|
||||
|
||||
// Remove all entities which are queued for destroy
|
||||
// for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
// const entity = this.allEntities[i];
|
||||
// if (entity.queuedForDestroy || entity.destroyed) {
|
||||
// this.allEntities.splice(i, 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
for (
|
||||
let arr = [...this.allEntitiesSet.values()], i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
this.tryUpdateEntitiesArray();
|
||||
|
||||
for (let i = 0; i < this.allEntitiesArray.length; ++i) {
|
||||
const entity = this.allEntitiesArray[i];
|
||||
if (entity.queuedForDestroy || entity.destroyed) {
|
||||
this.allEntitiesArrayIsOutdated = this.allEntitiesSet.delete(entity);
|
||||
this.allEntitiesSet.delete(this.allEntitiesArray[i]);
|
||||
fastArrayDelete(this.allEntitiesArray, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +117,7 @@ export class GameSystemWithFilter extends GameSystem {
|
||||
*/
|
||||
internalRegisterEntity(entity) {
|
||||
this.allEntitiesSet.add(entity);
|
||||
this.allEntitiesArrayIsOutdated = true;
|
||||
this.allEntitiesArray.push(entity);
|
||||
|
||||
// if (this.root.gameInitialized && !this.root.bulkOperationRunning) {
|
||||
// // Sort entities by uid so behaviour is predictable
|
||||
|
||||
@ -14,8 +14,8 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
||||
const minimumTimeForThroughput = now - 1;
|
||||
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const readerComp = entity.components.BeltReader;
|
||||
|
||||
@ -20,8 +20,8 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
update() {
|
||||
// Set signals
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
@ -21,8 +21,8 @@ export class FilterSystem extends GameSystemWithFilter {
|
||||
const requiredProgress = 1 - progress;
|
||||
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const filterComp = entity.components.Filter;
|
||||
|
||||
@ -26,8 +26,8 @@ export class HubSystem extends GameSystemWithFilter {
|
||||
*/
|
||||
draw(parameters) {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
this.drawEntity(parameters, entity);
|
||||
@ -36,8 +36,8 @@ export class HubSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
@ -40,8 +40,8 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
this.accumulatedTicksWhileInMapOverview = 0;
|
||||
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const aceptorComp = entity.components.ItemAcceptor;
|
||||
|
||||
@ -3,6 +3,7 @@ import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { createLogger } from "../../core/logging";
|
||||
import { Rectangle } from "../../core/rectangle";
|
||||
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
||||
import { dirInterval } from "../../core/utils";
|
||||
import { enumDirection, enumDirectionToVector } from "../../core/vector";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { BeltComponent } from "../components/belt";
|
||||
@ -61,8 +62,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
recomputeCacheFull() {
|
||||
logger.log("Full cache recompute in post load hook");
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
this.recomputeSingleEntityCache(entity);
|
||||
@ -149,9 +150,10 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
// Go over all cache entries
|
||||
dirInterval("ejectorItems", 30, this.allEntitiesArray);
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, sourceEntity;
|
||||
(sourceEntity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, sourceEntity;
|
||||
(sourceEntity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
||||
|
||||
@ -69,8 +69,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const processorComp = entity.components.ItemProcessor;
|
||||
|
||||
@ -15,8 +15,8 @@ export class LeverSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const leverComp = entity.components.Lever;
|
||||
|
||||
@ -3,8 +3,9 @@ import { enumColors } from "../colors";
|
||||
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
||||
import { enumPinSlotType } from "../components/wired_pins";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem } from "../items/boolean_item";
|
||||
import { COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { BooleanItem, BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem } from "../items/boolean_item";
|
||||
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
|
||||
export class LogicGateSystem extends GameSystemWithFilter {
|
||||
@ -30,8 +31,8 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const logicComp = entity.components.LogicGate;
|
||||
|
||||
@ -37,8 +37,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const minerComp = entity.components.Miner;
|
||||
|
||||
@ -27,8 +27,8 @@ export class StorageSystem extends GameSystemWithFilter {
|
||||
|
||||
update() {
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const storageComp = entity.components.Storage;
|
||||
|
||||
@ -224,8 +224,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
update() {
|
||||
this.staleAreaWatcher.update();
|
||||
for (
|
||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
||||
(entity = arr[i]) && i >= 0;
|
||||
let i = this.allEntitiesArray.length - 1, entity;
|
||||
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||
--i
|
||||
) {
|
||||
const undergroundComp = entity.components.UndergroundBelt;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user