From 36f125e6d75e56258c7e86b0f35183931ee97af0 Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Thu, 20 Jan 2022 21:50:11 +0000 Subject: [PATCH] most of the requested changes --- src/js/game/components/item_processor.js | 4 ++-- src/js/game/systems/filter.js | 9 ++++----- src/js/game/systems/item_acceptor.js | 4 +++- src/js/game/systems/item_ejector.js | 9 --------- src/js/game/systems/item_processor.js | 16 +++++----------- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/js/game/components/item_processor.js b/src/js/game/components/item_processor.js index 830e2382..59a9f6d6 100644 --- a/src/js/game/components/item_processor.js +++ b/src/js/game/components/item_processor.js @@ -99,9 +99,9 @@ export class ItemProcessorComponent extends Component { * What we are currently processing, empty if we don't produce anything rn * requiredSlot: Item *must* be ejected on this slot * preferredSlot: Item *can* be ejected on this slot, but others are fine too if the one is not usable - * @type {Array} + * @type {EjectorCharge|null} */ - this.ongoingCharges = []; + this.currentCharge = null; /** * How much processing time we have left from the last tick diff --git a/src/js/game/systems/filter.js b/src/js/game/systems/filter.js index 4e0d5dc4..507bf2f8 100644 --- a/src/js/game/systems/filter.js +++ b/src/js/game/systems/filter.js @@ -20,7 +20,7 @@ export class FilterSystem extends GameSystemWithFilter { // Take items from acceptor const input = acceptorComp.completedInputs.get(0); - if (input && this.tryAcceptItem(entity, input)) { + if (input && this.tryAcceptItem(entity, input.item, input.extraProgress)) { acceptorComp.completedInputs.delete(0); } @@ -42,11 +42,10 @@ export class FilterSystem extends GameSystemWithFilter { /** * * @param {Entity} entity - * @param {Object} param0 - * @param {BaseItem} param0.item - * @param {number} param0.extraProgress + * @param {BaseItem} item + * @param {number} extraProgress */ - tryAcceptItem(entity, { item, extraProgress }) { + tryAcceptItem(entity, item, extraProgress) { const network = entity.components.WiredPins.slots[0].linkedNetwork; if (!network || !network.hasValue()) { // Filter is not connected diff --git a/src/js/game/systems/item_acceptor.js b/src/js/game/systems/item_acceptor.js index 075e2040..23d4605d 100644 --- a/src/js/game/systems/item_acceptor.js +++ b/src/js/game/systems/item_acceptor.js @@ -26,7 +26,9 @@ export class ItemAcceptorSystem extends GameSystemWithFilter { inputs.forEach((values, index) => { values.animProgress += progressGrowth; - if (values.animProgress < maxProgress) return; + if (values.animProgress < maxProgress) { + return; + } inputs.delete(index); acceptorComp.completedInputs.set(index, { diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 1e544814..858a1fba 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -300,15 +300,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter { ^ ^ item @ 0.9 ^ max progress = 0.3 - Because now our range actually only goes to the end of the building, and not towards the center of the building, we need to multiply - all values by 2: <--------- except max progress is now 0.5 rather than 1, so this isn't needed anymore - - Building Belt - | X | X | - | 0.........1.........2 | - ^ ^ item @ 1.8 - ^ max progress = 0.6 - And that's it! If you summarize the calculations from above into a formula, you get the one below. */ diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 1b18c01d..bde78572 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -13,12 +13,6 @@ import { isTruthyItem } from "../items/boolean_item"; import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item"; import { ShapeItem } from "../items/shape_item"; -/** - * We need to allow queuing charges, otherwise the throughput will stalls - */ -//@SENSETODO not sure if this needs to be two anymore -const MAX_QUEUED_CHARGES = 1; - /** * Whole data for a produced item * @@ -85,13 +79,13 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const ejectorComp = entity.components.ItemEjector; // Check if we have an empty queue and can start a new charge - do this first so we don't waste a tick - if (processorComp.ongoingCharges.length < MAX_QUEUED_CHARGES) { + if (!processorComp.currentCharge) { if (this.canProcess(entity)) { this.startNewCharge(entity); } } - const currentCharge = processorComp.ongoingCharges[0]; + const currentCharge = processorComp.currentCharge; if (currentCharge) { // Process next charge if (currentCharge.remainingTime > 0.0) { @@ -111,7 +105,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { processorComp.queuedEjects.push(itemsToEject[j]); } - processorComp.ongoingCharges.shift(); + processorComp.currentCharge = null; } } @@ -267,10 +261,10 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const timeToProcess = originalTime - bonusTimeToApply; processorComp.bonusTime -= bonusTimeToApply; - processorComp.ongoingCharges.push({ + processorComp.currentCharge = { items: outItems, remainingTime: timeToProcess, - }); + }; acceptorComp.completedInputs.clear(); }