1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

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).
This commit is contained in:
Frode Austvik 2020-12-10 00:51:37 +01:00
parent c9cee9d22b
commit a9d7698700

View File

@ -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);
}
}
}
}