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) {
|
export function smoothPulse(time) {
|
||||||
return Math.sin(time * 4) * 0.5 + 0.5;
|
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 { GameRoot } from "./root";
|
||||||
import { GameSystem } from "./game_system";
|
import { GameSystem } from "./game_system";
|
||||||
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
import { arrayDelete, arrayDeleteValue, fastArrayDelete } from "../core/utils";
|
||||||
|
|
||||||
export class GameSystemWithFilter extends GameSystem {
|
export class GameSystemWithFilter extends GameSystem {
|
||||||
/**
|
/**
|
||||||
@ -36,15 +36,8 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
this.root.signals.bulkOperationFinished.add(this.refreshCaches, this);
|
this.root.signals.bulkOperationFinished.add(this.refreshCaches, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUpdateEntitiesArray() {
|
tryUpdateEntitiesArray() {
|
||||||
if (!this.allEntitiesArrayIsOutdated) {
|
|
||||||
return this.allEntitiesArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.allEntitiesArray = [...this.allEntitiesSet.values()];
|
this.allEntitiesArray = [...this.allEntitiesSet.values()];
|
||||||
|
|
||||||
this.allEntitiesArrayIsOutdated = true;
|
|
||||||
return this.allEntitiesArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,22 +91,15 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
|
|
||||||
refreshCaches() {
|
refreshCaches() {
|
||||||
//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
|
||||||
// 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 (
|
this.tryUpdateEntitiesArray();
|
||||||
let arr = [...this.allEntitiesSet.values()], i = arr.length - 1, entity;
|
|
||||||
(entity = arr[i]) && i >= 0;
|
for (let i = 0; i < this.allEntitiesArray.length; ++i) {
|
||||||
--i
|
const entity = this.allEntitiesArray[i];
|
||||||
) {
|
|
||||||
if (entity.queuedForDestroy || entity.destroyed) {
|
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) {
|
internalRegisterEntity(entity) {
|
||||||
this.allEntitiesSet.add(entity);
|
this.allEntitiesSet.add(entity);
|
||||||
this.allEntitiesArrayIsOutdated = true;
|
this.allEntitiesArray.push(entity);
|
||||||
|
|
||||||
// if (this.root.gameInitialized && !this.root.bulkOperationRunning) {
|
// if (this.root.gameInitialized && !this.root.bulkOperationRunning) {
|
||||||
// // Sort entities by uid so behaviour is predictable
|
// // Sort entities by uid so behaviour is predictable
|
||||||
|
|||||||
@ -14,8 +14,8 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
const minimumTimeForThroughput = now - 1;
|
const minimumTimeForThroughput = now - 1;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const readerComp = entity.components.BeltReader;
|
const readerComp = entity.components.BeltReader;
|
||||||
|
|||||||
@ -20,8 +20,8 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
|||||||
update() {
|
update() {
|
||||||
// Set signals
|
// Set signals
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|||||||
@ -21,8 +21,8 @@ export class FilterSystem extends GameSystemWithFilter {
|
|||||||
const requiredProgress = 1 - progress;
|
const requiredProgress = 1 - progress;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const filterComp = entity.components.Filter;
|
const filterComp = entity.components.Filter;
|
||||||
|
|||||||
@ -26,8 +26,8 @@ export class HubSystem extends GameSystemWithFilter {
|
|||||||
*/
|
*/
|
||||||
draw(parameters) {
|
draw(parameters) {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
this.drawEntity(parameters, entity);
|
this.drawEntity(parameters, entity);
|
||||||
@ -36,8 +36,8 @@ export class HubSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|||||||
@ -40,8 +40,8 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|||||||
this.accumulatedTicksWhileInMapOverview = 0;
|
this.accumulatedTicksWhileInMapOverview = 0;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const aceptorComp = entity.components.ItemAcceptor;
|
const aceptorComp = entity.components.ItemAcceptor;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { DrawParameters } from "../../core/draw_parameters";
|
|||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
||||||
|
import { dirInterval } from "../../core/utils";
|
||||||
import { enumDirection, enumDirectionToVector } from "../../core/vector";
|
import { enumDirection, enumDirectionToVector } from "../../core/vector";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { BeltComponent } from "../components/belt";
|
import { BeltComponent } from "../components/belt";
|
||||||
@ -61,8 +62,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 arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
this.recomputeSingleEntityCache(entity);
|
this.recomputeSingleEntityCache(entity);
|
||||||
@ -149,9 +150,10 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go over all cache entries
|
// Go over all cache entries
|
||||||
|
dirInterval("ejectorItems", 30, this.allEntitiesArray);
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, sourceEntity;
|
let i = this.allEntitiesArray.length - 1, sourceEntity;
|
||||||
(sourceEntity = arr[i]) && i >= 0;
|
(sourceEntity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
||||||
|
|||||||
@ -69,8 +69,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const processorComp = entity.components.ItemProcessor;
|
const processorComp = entity.components.ItemProcessor;
|
||||||
|
|||||||
@ -15,8 +15,8 @@ export class LeverSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const leverComp = entity.components.Lever;
|
const leverComp = entity.components.Lever;
|
||||||
|
|||||||
@ -3,8 +3,9 @@ import { enumColors } from "../colors";
|
|||||||
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
||||||
import { enumPinSlotType } from "../components/wired_pins";
|
import { enumPinSlotType } from "../components/wired_pins";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem } from "../items/boolean_item";
|
import { BooleanItem, BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem } from "../items/boolean_item";
|
||||||
import { COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||||
|
import { ShapeItem } from "../items/shape_item";
|
||||||
import { ShapeDefinition } from "../shape_definition";
|
import { ShapeDefinition } from "../shape_definition";
|
||||||
|
|
||||||
export class LogicGateSystem extends GameSystemWithFilter {
|
export class LogicGateSystem extends GameSystemWithFilter {
|
||||||
@ -30,8 +31,8 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const logicComp = entity.components.LogicGate;
|
const logicComp = entity.components.LogicGate;
|
||||||
|
|||||||
@ -37,8 +37,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const minerComp = entity.components.Miner;
|
const minerComp = entity.components.Miner;
|
||||||
|
|||||||
@ -27,8 +27,8 @@ export class StorageSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const storageComp = entity.components.Storage;
|
const storageComp = entity.components.Storage;
|
||||||
|
|||||||
@ -224,8 +224,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
update() {
|
update() {
|
||||||
this.staleAreaWatcher.update();
|
this.staleAreaWatcher.update();
|
||||||
for (
|
for (
|
||||||
let arr = this.getUpdateEntitiesArray(), i = arr.length - 1, entity;
|
let i = this.allEntitiesArray.length - 1, entity;
|
||||||
(entity = arr[i]) && i >= 0;
|
(entity = this.allEntitiesArray[i]) && i >= 0;
|
||||||
--i
|
--i
|
||||||
) {
|
) {
|
||||||
const undergroundComp = entity.components.UndergroundBelt;
|
const undergroundComp = entity.components.UndergroundBelt;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user