diff --git a/src/js/game/components/item_acceptor.js b/src/js/game/components/item_acceptor.js index 0b492843..3f3a59eb 100644 --- a/src/js/game/components/item_acceptor.js +++ b/src/js/game/components/item_acceptor.js @@ -82,7 +82,7 @@ export class ItemAcceptorComponent extends Component { /** @type {ItemAcceptorInputs} */ this.inputs = []; /** @type {ItemAcceptorCompletedInputs} */ - this.completedInputs = []; // @SENSETODO does this need to be saved? + this.completedInputs = []; this.setSlots(slots); } diff --git a/src/js/game/components/item_processor.js b/src/js/game/components/item_processor.js index 35b63452..2d85b93f 100644 --- a/src/js/game/components/item_processor.js +++ b/src/js/game/components/item_processor.js @@ -30,17 +30,17 @@ export const enumItemProcessorRequirements = { /** * @typedef {{ * item: BaseItem, - * extraProgress?: number, + * extraProgress?: number * requiredSlot?: number, * preferredSlot?: number * }} EjectorItemToEject */ /** @typedef {{ - * progress: number, - * targetProgress: number, + * remainingTime: number, * items: Array, * }} EjectorCharge * + * * @typedef {{ * item: BaseItem * extraProgress: number diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index d1e0dda8..531a6643 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -509,9 +509,9 @@ export class HubGoals extends BasicSerializableObject { /** * Processor time to process * @param {enumItemProcessorTypes} processorType - * @returns {number} progress in tiles + * @returns {number} process time in seconds */ - getProcessingProgress(processorType) { + getProcessingTime(processorType) { if (this.root.gameMode.throughputDoesNotMatter()) { return 0; } @@ -531,20 +531,12 @@ export class HubGoals extends BasicSerializableObject { case enumItemProcessorTypes.painter: case enumItemProcessorTypes.painterDouble: case enumItemProcessorTypes.painterQuad: { - assert( - globalConfig.buildingRatios[processorType], - "Processor type has no speed set in globalConfig.buildingRatios: " + processorType - ); - return (globalConfig.buildingRatios[processorType] - 1) / this.upgradeImprovements.painting; + return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.painting, processorType); } case enumItemProcessorTypes.cutter: case enumItemProcessorTypes.cutterQuad: case enumItemProcessorTypes.stacker: { - assert( - globalConfig.buildingRatios[processorType], - "Processor type has no speed set in globalConfig.buildingRatios: " + processorType - ); - return (globalConfig.buildingRatios[processorType] - 1) / this.upgradeImprovements.processors; + return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.processors, processorType); } default: if (MOD_ITEM_PROCESSOR_SPEEDS[processorType]) { @@ -556,16 +548,31 @@ export class HubGoals extends BasicSerializableObject { return 0; } + /** + * @param {number} upgrade + * @param {enumItemProcessorTypes} processorType + */ + getProcessorTimeWithUpgrades(upgrade, processorType) { + assert( + globalConfig.buildingRatios[processorType], + "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType + ); + + const processorTime = + globalConfig.buildingRatios[processorType] / globalConfig.beltSpeedItemsPerSecond; + return processorTime / upgrade; + } + /** * Processor speed * @param {enumItemProcessorTypes} processorType * @returns {number} items/sec */ getProcessorBaseSpeed(processorType) { - const progress = this.getProcessingProgress(processorType); - if (!progress) { + const time = this.getProcessingTime(processorType); + if (!time) { return this.getBeltBaseSpeed(); } - return globalConfig.beltSpeedItemsPerSecond / (progress + 1); + return 1 / time; } } diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 8e0c94d3..c780f1a7 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -163,6 +163,24 @@ export class ItemEjectorSystem extends GameSystemWithFilter { if (sourceSlot.progress < maxProgress) { // Advance items on the slot sourceSlot.progress += progressGrowth; + + // limit the progress to stop items being too close + if (sourceSlot.cachedTargetEntity && sourceSlot.cachedDestSlot) { + const acceptorComp = sourceSlot.cachedTargetEntity.components.ItemAcceptor; + let acceptorInput = null; + for (let i = 0; i < acceptorComp.inputs.length; i++) { + const input = acceptorComp.inputs[i]; + if (input.slotIndex == sourceSlot.cachedDestSlot.index) { + acceptorInput = input; + } + } + + if (acceptorInput) { + const maxProgress = + 0.5 + acceptorInput.animProgress - globalConfig.itemSpacingOnBelts; + sourceSlot.progress = Math.min(maxProgress, sourceSlot.progress); + } + } } if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) { @@ -293,6 +311,11 @@ export class ItemEjectorSystem extends GameSystemWithFilter { progress = Math.min(maxProgress, progress); } + // Skip if the item would barely be visible + if (progress < 0.05) { + continue; + } + const realPosition = staticComp.localTileToWorld(slot.pos); if (!chunk.tileSpaceRectangle.containsPoint(realPosition.x, realPosition.y)) { // Not within this chunk diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 6e44bb5b..c4ead3af 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -71,11 +71,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } update() { - const progressGrowth = - this.root.dynamicTickrate.deltaSeconds * - globalConfig.beltSpeedItemsPerSecond * - globalConfig.itemSpacingOnBelts; - for (let i = 0; i < this.allEntities.length; ++i) { const entity = this.allEntities[i]; @@ -91,16 +86,19 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const currentCharge = processorComp.currentCharge; if (currentCharge) { - const targetProgress = currentCharge.targetProgress; // Process next charge - if (currentCharge.progress < targetProgress) { - currentCharge.progress += progressGrowth; + if (currentCharge.remainingTime > 0.0) { + currentCharge.remainingTime -= this.root.dynamicTickrate.deltaSeconds; } - // Check if it finished - but don't finish another charge if there are still items queued to eject, or we might keep backing up - if (currentCharge.progress >= targetProgress && processorComp.queuedEjects.length < 1) { + // Check if it finished + if (currentCharge.remainingTime <= 0.0 && processorComp.queuedEjects.length < 1) { const itemsToEject = currentCharge.items; - const extraProgress = currentCharge.progress - targetProgress; + //@SENSETODO not sure this is correct + const extraProgress = + -currentCharge.remainingTime * + globalConfig.beltSpeedItemsPerSecond * + globalConfig.itemSpacingOnBelts; // Go over all items and try to eject them for (let j = 0; j < itemsToEject.length; ++j) { @@ -249,6 +247,10 @@ export class ItemProcessorSystem extends GameSystemWithFilter { extraProgress = Math.max(extraProgress, input.extraProgress); } + //@SENSETODO not sure if this is right + const extraTime = + extraProgress / (globalConfig.beltSpeedItemsPerSecond * globalConfig.itemSpacingOnBelts); + const outItems = []; /** @type {function(ProcessorImplementationPayload) : void} */ @@ -270,12 +272,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } // Queue Charge - const targetProgress = this.root.hubGoals.getProcessingProgress(processorComp.type); - //console.log("target progress:" + targetProgress + ", type: " + processorComp.type); + const originalTime = this.root.hubGoals.getProcessingTime(processorComp.type); + const timeToProcess = originalTime - extraTime; + processorComp.currentCharge = { items: outItems, - targetProgress, - progress: extraProgress, + remainingTime: timeToProcess, }; acceptorComp.completedInputs = [];