mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-11 18:39:21 +00:00
Fix throughput at high speeds and allow multiple items to be stored in an acceptor slot before it's full
This commit is contained in:
parent
9f7c95aec3
commit
cd72da5023
@ -130,8 +130,9 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
/**
|
/**
|
||||||
* Tries to accept the item
|
* Tries to accept the item
|
||||||
* @param {BaseItem} item
|
* @param {BaseItem} item
|
||||||
|
* @param {number} extraProgress
|
||||||
*/
|
*/
|
||||||
tryAcceptItem(item) {
|
tryAcceptItem(item, extraProgress = 0) {
|
||||||
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.
|
// 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 :(
|
// this means we are moving it forwards twice in one tick, but otherwise belts won't be full :(
|
||||||
@ -142,7 +143,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
|
|
||||||
// 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, beltProgressPerTick);
|
const initialProgress = Math.min(maxProgress, beltProgressPerTick + extraProgress);
|
||||||
|
|
||||||
this.items.unshift([this.spacingToFirstItem - initialProgress, item]);
|
this.items.unshift([this.spacingToFirstItem - initialProgress, item]);
|
||||||
this.spacingToFirstItem = initialProgress;
|
this.spacingToFirstItem = initialProgress;
|
||||||
|
|||||||
@ -75,8 +75,9 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Array<ItemAcceptorSlotConfig>} param0.slots The slots from which we accept items
|
* @param {Array<ItemAcceptorSlotConfig>} param0.slots The slots from which we accept items
|
||||||
|
* @param {number=} param0.maxSlotInputs The maximum amount of items one slot can accept before it is full
|
||||||
*/
|
*/
|
||||||
constructor({ slots = [] }) {
|
constructor({ slots = [], maxSlotInputs = 2 }) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/** @type {ItemAcceptorInputs} */
|
/** @type {ItemAcceptorInputs} */
|
||||||
@ -84,6 +85,9 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
/** @type {ItemAcceptorCompletedInputs} */
|
/** @type {ItemAcceptorCompletedInputs} */
|
||||||
this.completedInputs = [];
|
this.completedInputs = [];
|
||||||
this.setSlots(slots);
|
this.setSlots(slots);
|
||||||
|
|
||||||
|
// setting this to 1 will cause throughput issues at very high speeds
|
||||||
|
this.maxSlotInputs = maxSlotInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,17 +119,22 @@ 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];
|
||||||
|
|
||||||
|
let existingInputs = 0;
|
||||||
for (let i = 0; i < this.inputs.length; i++) {
|
for (let i = 0; i < this.inputs.length; i++) {
|
||||||
if (this.inputs[i].slotIndex == slotIndex) {
|
if (this.inputs[i].slotIndex == slotIndex) {
|
||||||
return false;
|
existingInputs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
existingInputs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (existingInputs >= this.maxSlotInputs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (slot.filter && slot.filter != item.getItemType()) {
|
if (slot.filter && slot.filter != item.getItemType()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,9 +180,7 @@ 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
|
||||||
// note - no extra progress is relevant here, as we have to push items up to the ones in front to ensure minimum spacing
|
if (destPath.tryAcceptItem(item, extraProgress)) {
|
||||||
// it's close enough though, and doesn't break at high speeds
|
|
||||||
if (destPath.tryAcceptItem(item)) {
|
|
||||||
sourceSlot.item = null;
|
sourceSlot.item = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -232,7 +232,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
const acceptorComp = entity.components.ItemAcceptor;
|
const acceptorComp = entity.components.ItemAcceptor;
|
||||||
const processorComp = entity.components.ItemProcessor;
|
const processorComp = entity.components.ItemProcessor;
|
||||||
|
|
||||||
// First, take inputs - but only ones that are completed
|
// First, take inputs - but only one from each
|
||||||
const inputs = acceptorComp.completedInputs;
|
const inputs = acceptorComp.completedInputs;
|
||||||
|
|
||||||
// split inputs efficiently
|
// split inputs efficiently
|
||||||
@ -282,7 +282,17 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
remainingTime: timeToProcess,
|
remainingTime: timeToProcess,
|
||||||
};
|
};
|
||||||
|
|
||||||
acceptorComp.completedInputs = [];
|
// only remove one item from each slot - we don't want to delete extra items!
|
||||||
|
let usedSlots = [];
|
||||||
|
for (let i = 0; i < acceptorComp.completedInputs.length; i++) {
|
||||||
|
const slot = acceptorComp.completedInputs[i].slotIndex;
|
||||||
|
|
||||||
|
if (!usedSlots.includes(slot)) {
|
||||||
|
usedSlots.push(slot);
|
||||||
|
acceptorComp.completedInputs.splice(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user