1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-15 19:21:49 +00:00

Fix bugs with ejector and minor changes to processor

This commit is contained in:
Sense101 2022-01-24 15:49:24 +00:00
parent 21df7583f1
commit a00c3c6ef3
5 changed files with 31 additions and 14 deletions

View File

@ -130,13 +130,19 @@ export class BeltPath extends BasicSerializableObject {
/** /**
* Tries to accept the item * Tries to accept the item
* @param {BaseItem} item * @param {BaseItem} item
* @param {number} startProgress
*/ */
tryAcceptItem(item, startProgress = 0) { tryAcceptItem(item) {
if (this.spacingToFirstItem >= globalConfig.itemSpacingOnBelts) { 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* // First, compute how much progress we can make *at max*
const maxProgress = Math.max(0, this.spacingToFirstItem - globalConfig.itemSpacingOnBelts); 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.items.unshift([this.spacingToFirstItem - initialProgress, item]);
this.spacingToFirstItem = initialProgress; this.spacingToFirstItem = initialProgress;

View File

@ -115,6 +115,11 @@ export class ItemAcceptorComponent extends Component {
tryAcceptItem(slotIndex, item, startProgress = 0.0) { tryAcceptItem(slotIndex, item, startProgress = 0.0) {
const slot = this.slots[slotIndex]; 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++) { for (let i = 0; i < this.completedInputs.length; i++) {
if (this.completedInputs[i].slotIndex == slotIndex) { if (this.completedInputs[i].slotIndex == slotIndex) {
return false; return false;

View File

@ -36,7 +36,8 @@ export const enumItemProcessorRequirements = {
* }} EjectorItemToEject */ * }} EjectorItemToEject */
/** @typedef {{ /** @typedef {{
* remainingProgress: number, * progress: number,
* targetProgress: number,
* items: Array<EjectorItemToEject>, * items: Array<EjectorItemToEject>,
* }} EjectorCharge * }} EjectorCharge
* *

View File

@ -180,7 +180,9 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
const destPath = sourceSlot.cachedBeltPath; const destPath = sourceSlot.cachedBeltPath;
if (destPath) { if (destPath) {
// Try passing the item over // 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; sourceSlot.item = null;
} }
@ -200,7 +202,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress) targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress)
) { ) {
// unique duplicated code for storage - hacky :( // unique duplicated code for storage - hacky :(
return true; sourceSlot.item = null;
return;
} }
if (targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress)) { if (targetAcceptorComp.tryAcceptItem(destSlot.index, item, extraProgress)) {
// Handover successful, clear slot // Handover successful, clear slot

View File

@ -91,16 +91,16 @@ 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.remainingProgress > 0.0) { if (currentCharge.progress < targetProgress) {
currentCharge.remainingProgress -= progressGrowth; 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 // 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 itemsToEject = currentCharge.items;
const extraProgress = -currentCharge.remainingProgress; const extraProgress = currentCharge.progress - targetProgress;
console.log(extraProgress);
// 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) {
@ -270,10 +270,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
} }
// Queue Charge // 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 = { processorComp.currentCharge = {
items: outItems, items: outItems,
remainingProgress: progress - extraProgress, targetProgress,
progress: extraProgress,
}; };
acceptorComp.completedInputs = []; acceptorComp.completedInputs = [];
@ -546,7 +548,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
assert(hubComponent, "Hub item processor has no hub component"); assert(hubComponent, "Hub item processor has no hub component");
// Hardcoded // 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)); const item = /** @type {ShapeItem} */ (payload.items.get(i));
if (!item) { if (!item) {
continue; continue;