From a9d7698700f0c6a77c6b8f64724ee9e8f8b7c5b5 Mon Sep 17 00:00:00 2001 From: Frode Austvik Date: Thu, 10 Dec 2020 00:51:37 +0100 Subject: [PATCH] Change item processor to not wait for ejection to finish This allows it to start processing the next charge immediately, and thus not lose any time even if there are multiple items to eject (as for the double painter). --- src/js/game/systems/item_processor.js | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 9775afde..30e56052 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -74,12 +74,28 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const processorComp = entity.components.ItemProcessor; const ejectorComp = entity.components.ItemEjector; - const currentCharge = processorComp.ongoingCharges[0]; + for (let chargeIndex = 0; true; chargeIndex++) { + + // Check if we have an open queue spot and can start a new charge + if (processorComp.ongoingCharges.length < MAX_QUEUED_CHARGES) { + if (this.canProcess(entity)) { + this.startNewCharge(entity); + } + } + + if (chargeIndex >= processorComp.ongoingCharges.length) { + break; + } + + const currentCharge = processorComp.ongoingCharges[chargeIndex]; - if (currentCharge) { // Process next charge if (currentCharge.remainingTime > 0.0) { currentCharge.remainingTime -= this.root.dynamicTickrate.deltaSeconds; + if (currentCharge.remainingTime > 0.0) { + // This charge is not finished, so don't process the next one + break; + } if (currentCharge.remainingTime < 0.0) { // Add bonus time, this is the time we spent too much processorComp.bonusTime += -currentCharge.remainingTime; @@ -87,7 +103,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } // Check if it finished - if (currentCharge.remainingTime <= 0.0) { + if (chargeIndex === 0 && currentCharge.remainingTime <= 0.0) { const itemsToEject = currentCharge.items; // Go over all items and try to eject them @@ -128,16 +144,10 @@ export class ItemProcessorSystem extends GameSystemWithFilter { // If the charge was entirely emptied to the outputs, start the next charge if (itemsToEject.length === 0) { processorComp.ongoingCharges.shift(); + chargeIndex--; } } } - - // Check if we have an empty queue and can start a new charge - if (processorComp.ongoingCharges.length < MAX_QUEUED_CHARGES) { - if (this.canProcess(entity)) { - this.startNewCharge(entity); - } - } } }