mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 02:01:51 +00:00
Got all buildings working - storage and tunnel still aren't exact
This commit is contained in:
parent
56a2aa5e0f
commit
d01341bb4f
@ -220,8 +220,6 @@ export class BeltPath extends BasicSerializableObject {
|
||||
return;
|
||||
}
|
||||
|
||||
const noSimplifiedBelts = !this.root.app.settings.getAllSettings().simplifiedBelts;
|
||||
|
||||
DEBUG && !debug_Silent && logger.log(" Found target entity", targetEntity.uid);
|
||||
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
||||
const targetBeltComp = targetEntity.components.Belt;
|
||||
@ -270,6 +268,11 @@ export class BeltPath extends BasicSerializableObject {
|
||||
const matchingDirection = enumInvertedDirections[ejectingDirection];
|
||||
|
||||
return function (item, startProgress = 0.0) {
|
||||
// storage has to have its own duplicated logic, as it's the ONLY building which the acceptor can't filter for it
|
||||
const storageComp = targetEntity.components.Storage;
|
||||
if (storageComp && !storageComp.canAcceptItem(item)) {
|
||||
return false;
|
||||
}
|
||||
if (targetAcceptorComp.tryAcceptItem(matchingSlotIndex, matchingDirection, item, startProgress)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import { typeItemSingleton } from "../item_resolver";
|
||||
/**
|
||||
* @typedef {{
|
||||
* item: BaseItem,
|
||||
* progress: number
|
||||
* extraProgress: number
|
||||
* }} PendingFilterItem
|
||||
*/
|
||||
|
||||
@ -24,14 +24,14 @@ export class FilterComponent extends Component {
|
||||
pendingItemsToLeaveThrough: types.array(
|
||||
types.structured({
|
||||
item: typeItemSingleton,
|
||||
progress: types.ufloat,
|
||||
extraProgress: types.ufloat,
|
||||
})
|
||||
),
|
||||
|
||||
pendingItemsToReject: types.array(
|
||||
types.structured({
|
||||
item: typeItemSingleton,
|
||||
progress: types.ufloat,
|
||||
extraProgress: types.ufloat, //@SENSETODO will need save migration
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
@ -56,34 +56,13 @@ export class UndergroundBeltComponent extends Component {
|
||||
this.consumptionAnimations = [];
|
||||
|
||||
/**
|
||||
* Used on both receiver and sender.
|
||||
* Reciever: Used to store the next item to transfer, and to block input while doing this
|
||||
* Sender: Used to store which items are currently "travelling"
|
||||
* Used only on reciever
|
||||
* Reciever: Used to store which items are currently "travelling"
|
||||
* @type {Array<[BaseItem, number]>} Format is [Item, ingame time to eject the item]
|
||||
*/
|
||||
this.pendingItems = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to accept an item from an external source like a regular belt or building
|
||||
* @param {BaseItem} item
|
||||
* @param {number} beltSpeed How fast this item travels
|
||||
*/
|
||||
tryAcceptExternalItem(item, beltSpeed) {
|
||||
if (this.mode !== enumUndergroundBeltMode.sender) {
|
||||
// Only senders accept external items
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.pendingItems.length > 0) {
|
||||
// We currently have a pending item
|
||||
return false;
|
||||
}
|
||||
|
||||
this.pendingItems.push([item, 0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to accept a tunneled item
|
||||
* @param {BaseItem} item
|
||||
|
||||
@ -13,32 +13,27 @@ export class FilterSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
update() {
|
||||
const progress =
|
||||
this.root.dynamicTickrate.deltaSeconds *
|
||||
this.root.hubGoals.getBeltBaseSpeed() *
|
||||
globalConfig.itemSpacingOnBelts;
|
||||
|
||||
const requiredProgress = 1 - progress;
|
||||
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const filterComp = entity.components.Filter;
|
||||
const acceptorComp = entity.components.ItemAcceptor;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
// Process payloads
|
||||
// Take items from acceptor
|
||||
const input = acceptorComp.completedInputs.get(0);
|
||||
if (input && this.tryAcceptItem(entity, input)) {
|
||||
acceptorComp.completedInputs.delete(0);
|
||||
}
|
||||
|
||||
// Output to ejector
|
||||
const slotsAndLists = [filterComp.pendingItemsToLeaveThrough, filterComp.pendingItemsToReject];
|
||||
for (let slotIndex = 0; slotIndex < slotsAndLists.length; ++slotIndex) {
|
||||
const pendingItems = slotsAndLists[slotIndex];
|
||||
|
||||
for (let j = 0; j < pendingItems.length; ++j) {
|
||||
const nextItem = pendingItems[j];
|
||||
// Advance next item
|
||||
nextItem.progress = Math.min(requiredProgress, nextItem.progress + progress);
|
||||
// Check if it's ready to eject
|
||||
if (nextItem.progress >= requiredProgress - 1e-5) {
|
||||
if (ejectorComp.tryEject(slotIndex, nextItem.item)) {
|
||||
pendingItems.shift();
|
||||
}
|
||||
if (ejectorComp.tryEject(slotIndex, nextItem.item)) {
|
||||
pendingItems.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,10 +43,11 @@ export class FilterSystem extends GameSystemWithFilter {
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} slot
|
||||
* @param {BaseItem} item
|
||||
* @param {Object} param0
|
||||
* @param {BaseItem} param0.item
|
||||
* @param {number} param0.extraProgress
|
||||
*/
|
||||
tryAcceptItem(entity, slot, item) {
|
||||
tryAcceptItem(entity, { item, extraProgress }) {
|
||||
const network = entity.components.WiredPins.slots[0].linkedNetwork;
|
||||
if (!network || !network.hasValue()) {
|
||||
// Filter is not connected
|
||||
@ -78,7 +74,7 @@ export class FilterSystem extends GameSystemWithFilter {
|
||||
// Actually accept item
|
||||
listToCheck.push({
|
||||
item,
|
||||
progress: 0.0,
|
||||
extraProgress,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -191,6 +191,12 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
const destEntity = slot.cachedTargetEntity;
|
||||
const destSlot = slot.cachedDestSlot;
|
||||
if (destEntity && destSlot) {
|
||||
// storage has to have its own duplicated logic, as it's the ONLY building which the acceptor can't filter for it
|
||||
const storageComp = destEntity.components.Storage;
|
||||
if (storageComp && !storageComp.canAcceptItem(item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetAcceptorComp = destEntity.components.ItemAcceptor;
|
||||
if (
|
||||
targetAcceptorComp.tryAcceptItem(
|
||||
|
||||
@ -16,7 +16,7 @@ import { ShapeItem } from "../items/shape_item";
|
||||
/**
|
||||
* We need to allow queuing charges, otherwise the throughput will stalls
|
||||
*/
|
||||
//@SENSETODO not sure if this is true anymore
|
||||
//@SENSETODO not sure if this needs to be two anymore
|
||||
const MAX_QUEUED_CHARGES = 1;
|
||||
|
||||
/**
|
||||
@ -141,8 +141,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
}
|
||||
|
||||
//@SENSETODO add code in here that handles queued outputs -rearrange where this is too
|
||||
|
||||
// If the charge was entirely emptied to the outputs, start the next charge
|
||||
if (itemsToEject.length === 0) {
|
||||
processorComp.ongoingCharges.shift();
|
||||
|
||||
@ -30,6 +30,21 @@ export class StorageSystem extends GameSystemWithFilter {
|
||||
const entity = this.allEntities[i];
|
||||
const storageComp = entity.components.Storage;
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
const acceptorComp = entity.components.ItemAcceptor;
|
||||
|
||||
// Take items from acceptor
|
||||
const input1 = acceptorComp.completedInputs.get(0);
|
||||
const input2 = acceptorComp.completedInputs.get(1);
|
||||
if (input1) {
|
||||
storageComp.storedItem = input1.item;
|
||||
storageComp.storedCount++;
|
||||
acceptorComp.completedInputs.delete(0);
|
||||
}
|
||||
if (input2) {
|
||||
storageComp.storedItem = input2.item;
|
||||
storageComp.storedCount++;
|
||||
acceptorComp.completedInputs.delete(1);
|
||||
}
|
||||
|
||||
// Eject from storage
|
||||
if (storageComp.storedItem && storageComp.storedCount > 0) {
|
||||
|
||||
@ -308,22 +308,18 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we have any items to eject
|
||||
const nextItemAndDuration = undergroundComp.pendingItems[0];
|
||||
if (nextItemAndDuration) {
|
||||
assert(undergroundComp.pendingItems.length === 1, "more than 1 pending");
|
||||
|
||||
const input = acceptorComp.completedInputs.get(0);
|
||||
if (input) {
|
||||
// Check if the receiver can accept it
|
||||
if (
|
||||
cacheEntry.entity.components.UndergroundBelt.tryAcceptTunneledItem(
|
||||
nextItemAndDuration[0],
|
||||
input.item,
|
||||
cacheEntry.distance,
|
||||
this.root.hubGoals.getUndergroundBeltBaseSpeed(),
|
||||
this.root.time.now()
|
||||
)
|
||||
) {
|
||||
// Drop this item
|
||||
fastArrayDelete(undergroundComp.pendingItems, 0);
|
||||
acceptorComp.completedInputs.delete(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user