From 5f932db5f618af6854402dda9f4180684deec24a Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 17 Apr 2019 00:40:03 -0500 Subject: [PATCH] perf: various opts --- server/traits/informed.trait.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/server/traits/informed.trait.js b/server/traits/informed.trait.js index 6c79673..7edea24 100644 --- a/server/traits/informed.trait.js +++ b/server/traits/informed.trait.js @@ -142,25 +142,20 @@ export class Informed extends decorate(Trait) { const room = this.entity.room; const camera = this.entity.camera; // Blow up camera rectangle to compensate for camera desync. - const position = Rectangle.position(camera.rectangle); const size = Rectangle.size(camera.rectangle); - const visibleArea = Rectangle.compose( - Vector.sub( - position, - Vector.scale(size, 0.25), - ), + const visibleArea = Rectangle.expand( + camera.rectangle, Vector.scale(size, 1.5), ); // Write over entity list for every layer. for (const {index, layer} of room.layers) { const visibleEntities = layer.visibleEntities(visibleArea); - let reducedEntityList = I.Map(); - for (const entity of visibleEntities) { - reducedEntityList = reducedEntityList.set( - entity.instanceUuid, - entity.state, - ); + const reduceEntityListRaw = {}; + for (let i = 0; i < visibleEntities.length; ++i) { + const entity = visibleEntities[i]; + reduceEntityListRaw[entity.instanceUuid] = entity.state; } + let reducedEntityList = I.Map(reduceEntityListRaw); const entityListPath = ['room', 'layers', index, 'entityList']; state = state.setIn(entityListPath, reducedEntityList); }