mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 10:11:50 +00:00
revert processor back to using time, and convert progress both ways
This commit is contained in:
parent
b9e09dfb3b
commit
b39d129152
@ -82,7 +82,7 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
/** @type {ItemAcceptorInputs} */
|
/** @type {ItemAcceptorInputs} */
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
/** @type {ItemAcceptorCompletedInputs} */
|
/** @type {ItemAcceptorCompletedInputs} */
|
||||||
this.completedInputs = []; // @SENSETODO does this need to be saved?
|
this.completedInputs = [];
|
||||||
this.setSlots(slots);
|
this.setSlots(slots);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,17 +30,17 @@ export const enumItemProcessorRequirements = {
|
|||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* item: BaseItem,
|
* item: BaseItem,
|
||||||
* extraProgress?: number,
|
* extraProgress?: number
|
||||||
* requiredSlot?: number,
|
* requiredSlot?: number,
|
||||||
* preferredSlot?: number
|
* preferredSlot?: number
|
||||||
* }} EjectorItemToEject */
|
* }} EjectorItemToEject */
|
||||||
|
|
||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* progress: number,
|
* remainingTime: number,
|
||||||
* targetProgress: number,
|
|
||||||
* items: Array<EjectorItemToEject>,
|
* items: Array<EjectorItemToEject>,
|
||||||
* }} EjectorCharge
|
* }} EjectorCharge
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* item: BaseItem
|
* item: BaseItem
|
||||||
* extraProgress: number
|
* extraProgress: number
|
||||||
|
|||||||
@ -509,9 +509,9 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
/**
|
/**
|
||||||
* Processor time to process
|
* Processor time to process
|
||||||
* @param {enumItemProcessorTypes} processorType
|
* @param {enumItemProcessorTypes} processorType
|
||||||
* @returns {number} progress in tiles
|
* @returns {number} process time in seconds
|
||||||
*/
|
*/
|
||||||
getProcessingProgress(processorType) {
|
getProcessingTime(processorType) {
|
||||||
if (this.root.gameMode.throughputDoesNotMatter()) {
|
if (this.root.gameMode.throughputDoesNotMatter()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -531,20 +531,12 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
case enumItemProcessorTypes.painter:
|
case enumItemProcessorTypes.painter:
|
||||||
case enumItemProcessorTypes.painterDouble:
|
case enumItemProcessorTypes.painterDouble:
|
||||||
case enumItemProcessorTypes.painterQuad: {
|
case enumItemProcessorTypes.painterQuad: {
|
||||||
assert(
|
return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.painting, processorType);
|
||||||
globalConfig.buildingRatios[processorType],
|
|
||||||
"Processor type has no speed set in globalConfig.buildingRatios: " + processorType
|
|
||||||
);
|
|
||||||
return (globalConfig.buildingRatios[processorType] - 1) / this.upgradeImprovements.painting;
|
|
||||||
}
|
}
|
||||||
case enumItemProcessorTypes.cutter:
|
case enumItemProcessorTypes.cutter:
|
||||||
case enumItemProcessorTypes.cutterQuad:
|
case enumItemProcessorTypes.cutterQuad:
|
||||||
case enumItemProcessorTypes.stacker: {
|
case enumItemProcessorTypes.stacker: {
|
||||||
assert(
|
return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.processors, processorType);
|
||||||
globalConfig.buildingRatios[processorType],
|
|
||||||
"Processor type has no speed set in globalConfig.buildingRatios: " + processorType
|
|
||||||
);
|
|
||||||
return (globalConfig.buildingRatios[processorType] - 1) / this.upgradeImprovements.processors;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (MOD_ITEM_PROCESSOR_SPEEDS[processorType]) {
|
if (MOD_ITEM_PROCESSOR_SPEEDS[processorType]) {
|
||||||
@ -556,16 +548,31 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
return 0;
|
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
|
* Processor speed
|
||||||
* @param {enumItemProcessorTypes} processorType
|
* @param {enumItemProcessorTypes} processorType
|
||||||
* @returns {number} items/sec
|
* @returns {number} items/sec
|
||||||
*/
|
*/
|
||||||
getProcessorBaseSpeed(processorType) {
|
getProcessorBaseSpeed(processorType) {
|
||||||
const progress = this.getProcessingProgress(processorType);
|
const time = this.getProcessingTime(processorType);
|
||||||
if (!progress) {
|
if (!time) {
|
||||||
return this.getBeltBaseSpeed();
|
return this.getBeltBaseSpeed();
|
||||||
}
|
}
|
||||||
return globalConfig.beltSpeedItemsPerSecond / (progress + 1);
|
return 1 / time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,6 +163,24 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
if (sourceSlot.progress < maxProgress) {
|
if (sourceSlot.progress < maxProgress) {
|
||||||
// Advance items on the slot
|
// Advance items on the slot
|
||||||
sourceSlot.progress += progressGrowth;
|
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) {
|
if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) {
|
||||||
@ -293,6 +311,11 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
progress = Math.min(maxProgress, progress);
|
progress = Math.min(maxProgress, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip if the item would barely be visible
|
||||||
|
if (progress < 0.05) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const realPosition = staticComp.localTileToWorld(slot.pos);
|
const realPosition = staticComp.localTileToWorld(slot.pos);
|
||||||
if (!chunk.tileSpaceRectangle.containsPoint(realPosition.x, realPosition.y)) {
|
if (!chunk.tileSpaceRectangle.containsPoint(realPosition.x, realPosition.y)) {
|
||||||
// Not within this chunk
|
// Not within this chunk
|
||||||
|
|||||||
@ -71,11 +71,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const progressGrowth =
|
|
||||||
this.root.dynamicTickrate.deltaSeconds *
|
|
||||||
globalConfig.beltSpeedItemsPerSecond *
|
|
||||||
globalConfig.itemSpacingOnBelts;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
|
|
||||||
@ -91,16 +86,19 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
const currentCharge = processorComp.currentCharge;
|
const currentCharge = processorComp.currentCharge;
|
||||||
if (currentCharge) {
|
if (currentCharge) {
|
||||||
const targetProgress = currentCharge.targetProgress;
|
|
||||||
// Process next charge
|
// Process next charge
|
||||||
if (currentCharge.progress < targetProgress) {
|
if (currentCharge.remainingTime > 0.0) {
|
||||||
currentCharge.progress += progressGrowth;
|
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
|
// Check if it finished
|
||||||
if (currentCharge.progress >= targetProgress && processorComp.queuedEjects.length < 1) {
|
if (currentCharge.remainingTime <= 0.0 && processorComp.queuedEjects.length < 1) {
|
||||||
const itemsToEject = currentCharge.items;
|
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
|
// Go over all items and try to eject them
|
||||||
for (let j = 0; j < itemsToEject.length; ++j) {
|
for (let j = 0; j < itemsToEject.length; ++j) {
|
||||||
@ -249,6 +247,10 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
extraProgress = Math.max(extraProgress, input.extraProgress);
|
extraProgress = Math.max(extraProgress, input.extraProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@SENSETODO not sure if this is right
|
||||||
|
const extraTime =
|
||||||
|
extraProgress / (globalConfig.beltSpeedItemsPerSecond * globalConfig.itemSpacingOnBelts);
|
||||||
|
|
||||||
const outItems = [];
|
const outItems = [];
|
||||||
|
|
||||||
/** @type {function(ProcessorImplementationPayload) : void} */
|
/** @type {function(ProcessorImplementationPayload) : void} */
|
||||||
@ -270,12 +272,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Queue Charge
|
// Queue Charge
|
||||||
const targetProgress = this.root.hubGoals.getProcessingProgress(processorComp.type);
|
const originalTime = this.root.hubGoals.getProcessingTime(processorComp.type);
|
||||||
//console.log("target progress:" + targetProgress + ", type: " + processorComp.type);
|
const timeToProcess = originalTime - extraTime;
|
||||||
|
|
||||||
processorComp.currentCharge = {
|
processorComp.currentCharge = {
|
||||||
items: outItems,
|
items: outItems,
|
||||||
targetProgress,
|
remainingTime: timeToProcess,
|
||||||
progress: extraProgress,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
acceptorComp.completedInputs = [];
|
acceptorComp.completedInputs = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user