diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index fa65c11c..25a1b20c 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -130,13 +130,19 @@ export class BeltPath extends BasicSerializableObject { /** * Tries to accept the item * @param {BaseItem} item - * @param {number} startProgress */ - tryAcceptItem(item, startProgress = 0) { + tryAcceptItem(item) { if (this.spacingToFirstItem >= globalConfig.itemSpacingOnBelts) { + // So, since we already need one tick to accept this item we will add this directly. + // this means we are moving it forwards twice in one tick, but otherwise belts won't be full :( + const beltProgressPerTick = + this.root.hubGoals.getBeltBaseSpeed() * + this.root.dynamicTickrate.deltaSeconds * + globalConfig.itemSpacingOnBelts; + // First, compute how much progress we can make *at max* const maxProgress = Math.max(0, this.spacingToFirstItem - globalConfig.itemSpacingOnBelts); - const initialProgress = Math.min(maxProgress, startProgress); + const initialProgress = Math.min(maxProgress, beltProgressPerTick); this.items.unshift([this.spacingToFirstItem - initialProgress, item]); this.spacingToFirstItem = initialProgress; diff --git a/src/js/game/components/item_acceptor.js b/src/js/game/components/item_acceptor.js index fa30d281..0b492843 100644 --- a/src/js/game/components/item_acceptor.js +++ b/src/js/game/components/item_acceptor.js @@ -115,6 +115,11 @@ export class ItemAcceptorComponent extends Component { tryAcceptItem(slotIndex, item, startProgress = 0.0) { const slot = this.slots[slotIndex]; + for (let i = 0; i < this.inputs.length; i++) { + if (this.inputs[i].slotIndex == slotIndex) { + return false; + } + } for (let i = 0; i < this.completedInputs.length; i++) { if (this.completedInputs[i].slotIndex == slotIndex) { return false; diff --git a/src/js/game/components/item_processor.js b/src/js/game/components/item_processor.js index f5b412cd..35b63452 100644 --- a/src/js/game/components/item_processor.js +++ b/src/js/game/components/item_processor.js @@ -36,7 +36,8 @@ export const enumItemProcessorRequirements = { * }} EjectorItemToEject */ /** @typedef {{ - * remainingProgress: number, + * progress: number, + * targetProgress: number, * items: Array, * }} EjectorCharge * diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 8968a383..8e0c94d3 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -180,7 +180,9 @@ export class ItemEjectorSystem extends GameSystemWithFilter { const destPath = sourceSlot.cachedBeltPath; if (destPath) { // Try passing the item over - if (destPath.tryAcceptItem(item, extraProgress)) { + // note - no extra progress is relevant here, as we have to push items up to the ones in front to ensure minimum spacing + // it's close enough though, and doesn't break at high speeds + if (destPath.tryAcceptItem(item)) { sourceSlot.item = null; } @@ -200,7 +202,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter { targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress) ) { // unique duplicated code for storage - hacky :( - return true; + sourceSlot.item = null; + return; } if (targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress)) { // Handover successful, clear slot diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index a40403aa..12d7978b 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -91,16 +91,16 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const currentCharge = processorComp.currentCharge; if (currentCharge) { + const targetProgress = currentCharge.targetProgress; // Process next charge - if (currentCharge.remainingProgress > 0.0) { - currentCharge.remainingProgress -= progressGrowth; + if (currentCharge.progress < targetProgress) { + currentCharge.progress += progressGrowth; } // 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.remainingProgress <= 0.0 && processorComp.queuedEjects.length < 1) { + if (currentCharge.progress >= targetProgress && processorComp.queuedEjects.length < 1) { const itemsToEject = currentCharge.items; - const extraProgress = -currentCharge.remainingProgress; - console.log(extraProgress); + const extraProgress = currentCharge.progress - targetProgress; // Go over all items and try to eject them for (let j = 0; j < itemsToEject.length; ++j) { @@ -270,10 +270,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } // Queue Charge - const progress = this.root.hubGoals.getProcessingProgress(processorComp.type); + const targetProgress = this.root.hubGoals.getProcessingProgress(processorComp.type); + //console.log("target progress:" + targetProgress + ", type: " + processorComp.type); processorComp.currentCharge = { items: outItems, - remainingProgress: progress - extraProgress, + targetProgress, + progress: extraProgress, }; acceptorComp.completedInputs = []; @@ -546,7 +548,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { assert(hubComponent, "Hub item processor has no hub component"); // Hardcoded - for (let i = 0; i < payload.items.size; ++i) { + for (let i = 0; i < 16; ++i) { const item = /** @type {ShapeItem} */ (payload.items.get(i)); if (!item) { continue;