mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Improve (rendering-) performance in DEV mode
This commit is contained in:
parent
0238de1260
commit
bba29b8a8b
@ -4,6 +4,7 @@ import { GameRoot } from "./root";
|
||||
import { Entity } from "./entity";
|
||||
import { BasicSerializableObject, types } from "../savegame/serialization";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { globalConfig } from "../core/config";
|
||||
|
||||
const logger = createLogger("entity_manager");
|
||||
|
||||
@ -61,7 +62,9 @@ export class EntityManager extends BasicSerializableObject {
|
||||
* @param {number=} uid Optional predefined uid
|
||||
*/
|
||||
registerEntity(entity, uid = null) {
|
||||
assert(this.entities.indexOf(entity) < 0, `RegisterEntity() called twice for entity ${entity}`);
|
||||
if (G_IS_DEV && !globalConfig.debug.disableSlowAsserts) {
|
||||
assert(this.entities.indexOf(entity) < 0, `RegisterEntity() called twice for entity ${entity}`);
|
||||
}
|
||||
assert(!entity.destroyed, `Attempting to register destroyed entity ${entity}`);
|
||||
|
||||
if (G_IS_DEV && uid !== null) {
|
||||
@ -92,18 +95,6 @@ export class EntityManager extends BasicSerializableObject {
|
||||
this.root.signals.entityAdded.dispatch(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts all entitiy lists after a resync
|
||||
*/
|
||||
sortEntityLists() {
|
||||
this.entities.sort((a, b) => a.uid - b.uid);
|
||||
this.destroyList.sort((a, b) => a.uid - b.uid);
|
||||
|
||||
for (const key in this.componentToEntity) {
|
||||
this.componentToEntity[key].sort((a, b) => a.uid - b.uid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new uid
|
||||
* @returns {number}
|
||||
|
@ -6,6 +6,7 @@ import { Entity } from "./entity";
|
||||
import { GameRoot } from "./root";
|
||||
import { GameSystem } from "./game_system";
|
||||
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
||||
import { globalConfig } from "../core/config";
|
||||
|
||||
export class GameSystemWithFilter extends GameSystem {
|
||||
/**
|
||||
@ -44,7 +45,11 @@ export class GameSystemWithFilter extends GameSystem {
|
||||
}
|
||||
}
|
||||
|
||||
assert(this.allEntities.indexOf(entity) < 0, "entity already in list: " + entity);
|
||||
// This is slow!
|
||||
if (G_IS_DEV && !globalConfig.debug.disableSlowAsserts) {
|
||||
assert(this.allEntities.indexOf(entity) < 0, "entity already in list: " + entity);
|
||||
}
|
||||
|
||||
this.internalRegisterEntity(entity);
|
||||
}
|
||||
|
||||
|
@ -9,14 +9,30 @@ import { MapChunkView } from "../map_chunk_view";
|
||||
export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
super(root, [ItemAcceptorComponent]);
|
||||
|
||||
// Well ... it's better to be verbose I guess?
|
||||
this.accumulatedTicksWhileInMapOverview = 0;
|
||||
}
|
||||
|
||||
update() {
|
||||
// This system doesn't render anything while in map overview,
|
||||
// so simply accumulate ticks
|
||||
if (this.root.camera.getIsMapOverlayActive()) {
|
||||
++this.accumulatedTicksWhileInMapOverview;
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute how much ticks we missed
|
||||
const numTicks = 1 + this.accumulatedTicksWhileInMapOverview;
|
||||
const progress =
|
||||
this.root.dynamicTickrate.deltaSeconds *
|
||||
2 *
|
||||
this.root.hubGoals.getBeltBaseSpeed() *
|
||||
globalConfig.itemSpacingOnBelts; // * 2 because its only a half tile
|
||||
globalConfig.itemSpacingOnBelts * // * 2 because its only a half tile
|
||||
numTicks;
|
||||
|
||||
// Reset accumulated ticks
|
||||
this.accumulatedTicksWhileInMapOverview = 0;
|
||||
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
|
@ -149,8 +149,6 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
}
|
||||
}
|
||||
|
||||
update() {}
|
||||
|
||||
/**
|
||||
* Draws a given entity
|
||||
* @param {DrawParameters} parameters
|
||||
|
@ -41,7 +41,7 @@ export class SavegameSerializer {
|
||||
beltPaths: root.systemMgr.systems.belt.serializePaths(),
|
||||
};
|
||||
|
||||
if (!G_IS_RELEASE) {
|
||||
if (G_IS_DEV) {
|
||||
if (sanityChecks) {
|
||||
// Sanity check
|
||||
const sanity = this.verifyLogicalErrors(data);
|
||||
@ -64,7 +64,7 @@ export class SavegameSerializer {
|
||||
return ExplainedResult.bad("Savegame has no entities");
|
||||
}
|
||||
|
||||
const seenUids = [];
|
||||
const seenUids = new Set();
|
||||
|
||||
// Check for duplicate UIDS
|
||||
for (let i = 0; i < savegame.entities.length; ++i) {
|
||||
@ -75,10 +75,10 @@ export class SavegameSerializer {
|
||||
if (!Number.isInteger(uid)) {
|
||||
return ExplainedResult.bad("Entity has invalid uid: " + uid);
|
||||
}
|
||||
if (seenUids.indexOf(uid) >= 0) {
|
||||
if (seenUids.has(uid)) {
|
||||
return ExplainedResult.bad("Duplicate uid " + uid);
|
||||
}
|
||||
seenUids.push(uid);
|
||||
seenUids.add(uid);
|
||||
|
||||
// Verify components
|
||||
if (!entity.components) {
|
||||
|
Loading…
Reference in New Issue
Block a user