From 132eff5f587e2700c6811e0c5b7eb9c19b5e05a3 Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Sat, 22 Jan 2022 18:40:46 +0000 Subject: [PATCH 1/3] adjust hub goals --- src/js/core/config.js | 19 +++++------- src/js/game/hub_goals.js | 67 +++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/js/core/config.js b/src/js/core/config.js index b451e848..602e0c82 100644 --- a/src/js/core/config.js +++ b/src/js/core/config.js @@ -87,17 +87,14 @@ export const globalConfig = { puzzleMaxBoundsSize: 20, puzzleValidationDurationSeconds: 30, - buildingSpeeds: { - cutter: 1 / 4, - cutterQuad: 1 / 4, - rotater: 1 / 1, - rotaterCCW: 1 / 1, - rotater180: 1 / 1, - painter: 1 / 6, - painterDouble: 1 / 8, - painterQuad: 1 / 2, - mixer: 1 / 5, - stacker: 1 / 8, + buildingRatios: { + cutter: 4, + cutterQuad: 4, + painter: 6, + painterDouble: 8, + painterQuad: 2, + mixer: 5, + stacker: 8, }, // Zooming diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 9f9c63be..4fe267d8 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -507,55 +507,37 @@ export class HubGoals extends BasicSerializableObject { } /** - * Processor speed + * Processor time to process * @param {enumItemProcessorTypes} processorType - * @returns {number} items / sec + * @returns {number} progress in tiles */ - getProcessorBaseSpeed(processorType) { + getProcessingProgress(processorType) { if (this.root.gameMode.throughputDoesNotMatter()) { - return globalConfig.beltSpeedItemsPerSecond * globalConfig.puzzleModeSpeed * 10; + return 0; } switch (processorType) { case enumItemProcessorTypes.trash: case enumItemProcessorTypes.hub: case enumItemProcessorTypes.goal: - return 1e30; case enumItemProcessorTypes.balancer: - return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt * 2; case enumItemProcessorTypes.reader: - return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt; + case enumItemProcessorTypes.rotater: + case enumItemProcessorTypes.rotaterCCW: + case enumItemProcessorTypes.rotater180: + return 0; case enumItemProcessorTypes.mixer: case enumItemProcessorTypes.painter: case enumItemProcessorTypes.painterDouble: case enumItemProcessorTypes.painterQuad: { - assert( - globalConfig.buildingSpeeds[processorType], - "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType - ); - return ( - globalConfig.beltSpeedItemsPerSecond * - this.upgradeImprovements.painting * - globalConfig.buildingSpeeds[processorType] - ); + return this.getProgressWithUpgrades(this.upgradeImprovements.painting, processorType); } case enumItemProcessorTypes.cutter: case enumItemProcessorTypes.cutterQuad: - case enumItemProcessorTypes.rotater: - case enumItemProcessorTypes.rotaterCCW: - case enumItemProcessorTypes.rotater180: case enumItemProcessorTypes.stacker: { - assert( - globalConfig.buildingSpeeds[processorType], - "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType - ); - return ( - globalConfig.beltSpeedItemsPerSecond * - this.upgradeImprovements.processors * - globalConfig.buildingSpeeds[processorType] - ); + return this.getProgressWithUpgrades(this.upgradeImprovements.processors, processorType); } default: if (MOD_ITEM_PROCESSOR_SPEEDS[processorType]) { @@ -564,6 +546,33 @@ export class HubGoals extends BasicSerializableObject { assertAlways(false, "invalid processor type: " + processorType); } - return 1 / globalConfig.beltSpeedItemsPerSecond; + return 0; + } + + /** + * @param {number} upgrade + * @param {number} upgrade + */ + getProgressWithUpgrades(upgrade, processorType) { + assert( + globalConfig.buildingRatios[processorType], + "Processor type has no speed set in globalConfig.buildingRatios: " + processorType + ); + + const progress = globalConfig.buildingRatios[processorType] - 1; + return progress / upgrade; + } + + /** + * Processor speed + * @param {enumItemProcessorTypes} processorType + * @returns {number} items/sec + */ + getProcessorBaseSpeed(processorType) { + const progress = this.getProcessingProgress(processorType); + if (!progress) { + return this.getBeltBaseSpeed(); + } + return globalConfig.beltSpeedItemsPerSecond / (progress + 1); } } From 3bd86aa6d09354127239b6eff619279b1795e555 Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Sat, 22 Jan 2022 19:18:40 +0000 Subject: [PATCH 2/3] half ejector progress --- src/js/game/systems/item_ejector.js | 43 ++++++++++------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 8c7468ad..57d577b0 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -138,13 +138,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter { update() { this.staleAreaDetector.update(); - // Precompute effective belt speed - let progressGrowth = 2 * this.root.dynamicTickrate.deltaSeconds; - - if (G_IS_DEV && globalConfig.debug.instantBelts) { - progressGrowth = 1; - } - // Go over all cache entries for (let i = 0; i < this.allEntities.length; ++i) { const sourceEntity = this.allEntities[i]; @@ -154,26 +147,27 @@ export class ItemEjectorSystem extends GameSystemWithFilter { for (let j = 0; j < slots.length; ++j) { const sourceSlot = slots[j]; const item = sourceSlot.item; + const maxProgress = 0.5; + if (!item) { // No item available to be ejected continue; } - // Advance items on the slot - sourceSlot.progress = Math.min( - 1, - sourceSlot.progress + - progressGrowth * - this.root.hubGoals.getBeltBaseSpeed() * - globalConfig.itemSpacingOnBelts - ); + if (sourceSlot.progress < maxProgress) { + // Advance items on the slot + sourceSlot.progress += + this.root.dynamicTickrate.deltaSeconds * + this.root.hubGoals.getBeltBaseSpeed() * + globalConfig.itemSpacingOnBelts; + } if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) { - sourceSlot.progress = 1.0; + sourceSlot.progress = maxProgress; } // Check if we are still in the process of ejecting, can't proceed then - if (sourceSlot.progress < 1.0) { + if (sourceSlot.progress < maxProgress) { continue; } @@ -368,20 +362,11 @@ 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: - - 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. */ const maxProgress = - (0.5 + nextBeltPath.spacingToFirstItem - globalConfig.itemSpacingOnBelts) * 2; + 0.5 + nextBeltPath.spacingToFirstItem - globalConfig.itemSpacingOnBelts; progress = Math.min(maxProgress, progress); } @@ -399,8 +384,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter { const realDirection = staticComp.localDirectionToWorld(slot.direction); const realDirectionVector = enumDirectionToVector[realDirection]; - const tileX = realPosition.x + 0.5 + realDirectionVector.x * 0.5 * progress; - const tileY = realPosition.y + 0.5 + realDirectionVector.y * 0.5 * progress; + const tileX = realPosition.x + 0.5 + realDirectionVector.x * progress; + const tileY = realPosition.y + 0.5 + realDirectionVector.y * progress; const worldX = tileX * globalConfig.tileSize; const worldY = tileY * globalConfig.tileSize; From 93daf53b0f5ec031619bf81bdd90a766491a2ebd Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Sat, 22 Jan 2022 21:06:06 +0000 Subject: [PATCH 3/3] test --- src/js/game/components/item_processor.js | 8 +------- src/js/game/hub_goals.js | 2 +- src/js/game/systems/item_ejector.js | 2 +- src/js/game/systems/item_processor.js | 25 ++++++++++-------------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/js/game/components/item_processor.js b/src/js/game/components/item_processor.js index f7dddec1..fbe03391 100644 --- a/src/js/game/components/item_processor.js +++ b/src/js/game/components/item_processor.js @@ -34,7 +34,7 @@ export const enumItemProcessorRequirements = { * }} EjectorItemToEject */ /** @typedef {{ - * remainingTime: number, + * remainingProgress: number, * items: Array, * }} EjectorCharge */ @@ -103,12 +103,6 @@ export class ItemProcessorComponent extends Component { * @type {Array} */ this.ongoingCharges = []; - - /** - * How much processing time we have left from the last tick - * @type {number} - */ - this.bonusTime = 0; } /** diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 4fe267d8..b013530d 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -560,7 +560,7 @@ export class HubGoals extends BasicSerializableObject { ); const progress = globalConfig.buildingRatios[processorType] - 1; - return progress / upgrade; + return progress + 0.5 / upgrade; } /** diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 57d577b0..c735c7bd 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -327,7 +327,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter { } // Limit the progress to the maximum available space on the next belt (also see #1000) - let progress = slot.progress; + let progress = Math.min(0.5, slot.progress); const nextBeltPath = slot.cachedBeltPath; if (nextBeltPath) { /* diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 36c837fb..9b746e44 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -76,6 +76,11 @@ 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]; @@ -86,16 +91,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter { if (currentCharge) { // Process next charge - if (currentCharge.remainingTime > 0.0) { - currentCharge.remainingTime -= this.root.dynamicTickrate.deltaSeconds; - if (currentCharge.remainingTime < 0.0) { - // Add bonus time, this is the time we spent too much - processorComp.bonusTime += -currentCharge.remainingTime; - } + if (currentCharge.remainingProgress > 0.0) { + currentCharge.remainingProgress -= progressGrowth; } // Check if it finished - if (currentCharge.remainingTime <= 0.0) { + if (currentCharge.remainingProgress <= 0.0) { const itemsToEject = currentCharge.items; // Go over all items and try to eject them @@ -286,16 +287,10 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } // Queue Charge - const baseSpeed = this.root.hubGoals.getProcessorBaseSpeed(processorComp.type); - const originalTime = 1 / baseSpeed; - - const bonusTimeToApply = Math.min(originalTime, processorComp.bonusTime); - const timeToProcess = originalTime - bonusTimeToApply; - - processorComp.bonusTime -= bonusTimeToApply; + const progress = this.root.hubGoals.getProcessingProgress(processorComp.type); processorComp.ongoingCharges.push({ items: outItems, - remainingTime: timeToProcess, + remainingProgress: progress, // + Math.min(extra progress' of inputs) }); processorComp.inputSlots.clear();