From 5405d34c217c70cf2b0aa4e231d559b26a1398b0 Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Fri, 16 Apr 2021 13:11:27 +0100 Subject: [PATCH] comments and prettier added --- src/js/game/components/belt_reader.js | 4 ++++ src/js/game/systems/belt_reader.js | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/js/game/components/belt_reader.js b/src/js/game/components/belt_reader.js index 4eeb76a9..a91ae2c4 100644 --- a/src/js/game/components/belt_reader.js +++ b/src/js/game/components/belt_reader.js @@ -41,6 +41,10 @@ export class BeltReaderComponent extends Component { */ this.lastThroughputComputation = 0; + /** + * Stores the entry time of the latest removed item + * @type {number} + */ this.lastRemovedItemTime = 0; } } diff --git a/src/js/game/systems/belt_reader.js b/src/js/game/systems/belt_reader.js index 9ffb3ca3..449defc1 100644 --- a/src/js/game/systems/belt_reader.js +++ b/src/js/game/systems/belt_reader.js @@ -11,7 +11,6 @@ export class BeltReaderSystem extends GameSystemWithFilter { update() { const now = this.root.time.now(); const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds; - const minimumTimeForThroughput = now - 1; for (let i = 0; i < this.allEntities.length; ++i) { const entity = this.allEntities[i]; @@ -19,16 +18,19 @@ export class BeltReaderSystem extends GameSystemWithFilter { const lastItemTimes = readerComp.lastItemTimes; const pinsComp = entity.components.WiredPins; - // Remove outdated items + // Remove outdated items and set lastRemovedItemTime while (lastItemTimes[0] < minimumTime) { readerComp.lastRemovedItemTime = lastItemTimes.shift(); } - + if (now - readerComp.lastThroughputComputation > 0.5) { // Compute throughput readerComp.lastThroughputComputation = now; + //if only one item is in the list, use the time from the last removed item + //to allow for much lower numbers to be correctly calculated const oneItem = lastItemTimes.length == 1; + let throughput = 0; if (lastItemTimes.length > 0) { let averageSpacing = oneItem ? lastItemTimes[0] - readerComp.lastRemovedItemTime : 0; @@ -44,6 +46,7 @@ export class BeltReaderSystem extends GameSystemWithFilter { readerComp.lastThroughput = Math.min(globalConfig.beltSpeedItemsPerSecond, throughput); } + // Set the pins value - shape output consistent with the boolean output if (readerComp.lastThroughput > 0) { pinsComp.slots[0].value = BOOL_TRUE_SINGLETON; pinsComp.slots[1].value = readerComp.lastItem;