1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 02:01:51 +00:00

revert processor back to using time, and convert progress both ways

This commit is contained in:
Sense101 2022-01-25 11:41:52 +00:00
parent b9e09dfb3b
commit b39d129152
5 changed files with 66 additions and 34 deletions

View File

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

View File

@ -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<EjectorItemToEject>,
* }} EjectorCharge
*
*
* @typedef {{
* item: BaseItem
* extraProgress: number

View File

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

View File

@ -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

View File

@ -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 = [];