mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-15 11:11: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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const noSimplifiedBelts = !this.root.app.settings.getAllSettings().simplifiedBelts;
|
|
||||||
|
|
||||||
DEBUG && !debug_Silent && logger.log(" Found target entity", targetEntity.uid);
|
DEBUG && !debug_Silent && logger.log(" Found target entity", targetEntity.uid);
|
||||||
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
||||||
const targetBeltComp = targetEntity.components.Belt;
|
const targetBeltComp = targetEntity.components.Belt;
|
||||||
@ -270,6 +268,11 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
const matchingDirection = enumInvertedDirections[ejectingDirection];
|
const matchingDirection = enumInvertedDirections[ejectingDirection];
|
||||||
|
|
||||||
return function (item, startProgress = 0.0) {
|
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)) {
|
if (targetAcceptorComp.tryAcceptItem(matchingSlotIndex, matchingDirection, item, startProgress)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { typeItemSingleton } from "../item_resolver";
|
|||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* item: BaseItem,
|
* item: BaseItem,
|
||||||
* progress: number
|
* extraProgress: number
|
||||||
* }} PendingFilterItem
|
* }} PendingFilterItem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -24,14 +24,14 @@ export class FilterComponent extends Component {
|
|||||||
pendingItemsToLeaveThrough: types.array(
|
pendingItemsToLeaveThrough: types.array(
|
||||||
types.structured({
|
types.structured({
|
||||||
item: typeItemSingleton,
|
item: typeItemSingleton,
|
||||||
progress: types.ufloat,
|
extraProgress: types.ufloat,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
pendingItemsToReject: types.array(
|
pendingItemsToReject: types.array(
|
||||||
types.structured({
|
types.structured({
|
||||||
item: typeItemSingleton,
|
item: typeItemSingleton,
|
||||||
progress: types.ufloat,
|
extraProgress: types.ufloat, //@SENSETODO will need save migration
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -56,34 +56,13 @@ export class UndergroundBeltComponent extends Component {
|
|||||||
this.consumptionAnimations = [];
|
this.consumptionAnimations = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used on both receiver and sender.
|
* Used only on reciever
|
||||||
* Reciever: Used to store the next item to transfer, and to block input while doing this
|
* Reciever: Used to store which items are currently "travelling"
|
||||||
* Sender: Used to store which items are currently "travelling"
|
|
||||||
* @type {Array<[BaseItem, number]>} Format is [Item, ingame time to eject the item]
|
* @type {Array<[BaseItem, number]>} Format is [Item, ingame time to eject the item]
|
||||||
*/
|
*/
|
||||||
this.pendingItems = [];
|
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
|
* Tries to accept a tunneled item
|
||||||
* @param {BaseItem} item
|
* @param {BaseItem} item
|
||||||
|
|||||||
@ -13,32 +13,27 @@ export class FilterSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
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) {
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
const filterComp = entity.components.Filter;
|
const filterComp = entity.components.Filter;
|
||||||
|
const acceptorComp = entity.components.ItemAcceptor;
|
||||||
const ejectorComp = entity.components.ItemEjector;
|
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];
|
const slotsAndLists = [filterComp.pendingItemsToLeaveThrough, filterComp.pendingItemsToReject];
|
||||||
for (let slotIndex = 0; slotIndex < slotsAndLists.length; ++slotIndex) {
|
for (let slotIndex = 0; slotIndex < slotsAndLists.length; ++slotIndex) {
|
||||||
const pendingItems = slotsAndLists[slotIndex];
|
const pendingItems = slotsAndLists[slotIndex];
|
||||||
|
|
||||||
for (let j = 0; j < pendingItems.length; ++j) {
|
for (let j = 0; j < pendingItems.length; ++j) {
|
||||||
const nextItem = pendingItems[j];
|
const nextItem = pendingItems[j];
|
||||||
// Advance next item
|
if (ejectorComp.tryEject(slotIndex, nextItem.item)) {
|
||||||
nextItem.progress = Math.min(requiredProgress, nextItem.progress + progress);
|
pendingItems.shift();
|
||||||
// Check if it's ready to eject
|
|
||||||
if (nextItem.progress >= requiredProgress - 1e-5) {
|
|
||||||
if (ejectorComp.tryEject(slotIndex, nextItem.item)) {
|
|
||||||
pendingItems.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,10 +43,11 @@ export class FilterSystem extends GameSystemWithFilter {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} slot
|
* @param {Object} param0
|
||||||
* @param {BaseItem} item
|
* @param {BaseItem} param0.item
|
||||||
|
* @param {number} param0.extraProgress
|
||||||
*/
|
*/
|
||||||
tryAcceptItem(entity, slot, item) {
|
tryAcceptItem(entity, { item, extraProgress }) {
|
||||||
const network = entity.components.WiredPins.slots[0].linkedNetwork;
|
const network = entity.components.WiredPins.slots[0].linkedNetwork;
|
||||||
if (!network || !network.hasValue()) {
|
if (!network || !network.hasValue()) {
|
||||||
// Filter is not connected
|
// Filter is not connected
|
||||||
@ -78,7 +74,7 @@ export class FilterSystem extends GameSystemWithFilter {
|
|||||||
// Actually accept item
|
// Actually accept item
|
||||||
listToCheck.push({
|
listToCheck.push({
|
||||||
item,
|
item,
|
||||||
progress: 0.0,
|
extraProgress,
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -191,6 +191,12 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
const destEntity = slot.cachedTargetEntity;
|
const destEntity = slot.cachedTargetEntity;
|
||||||
const destSlot = slot.cachedDestSlot;
|
const destSlot = slot.cachedDestSlot;
|
||||||
if (destEntity && destSlot) {
|
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;
|
const targetAcceptorComp = destEntity.components.ItemAcceptor;
|
||||||
if (
|
if (
|
||||||
targetAcceptorComp.tryAcceptItem(
|
targetAcceptorComp.tryAcceptItem(
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import { ShapeItem } from "../items/shape_item";
|
|||||||
/**
|
/**
|
||||||
* We need to allow queuing charges, otherwise the throughput will stalls
|
* 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;
|
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 the charge was entirely emptied to the outputs, start the next charge
|
||||||
if (itemsToEject.length === 0) {
|
if (itemsToEject.length === 0) {
|
||||||
processorComp.ongoingCharges.shift();
|
processorComp.ongoingCharges.shift();
|
||||||
|
|||||||
@ -30,6 +30,21 @@ export class StorageSystem extends GameSystemWithFilter {
|
|||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
const storageComp = entity.components.Storage;
|
const storageComp = entity.components.Storage;
|
||||||
const pinsComp = entity.components.WiredPins;
|
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
|
// Eject from storage
|
||||||
if (storageComp.storedItem && storageComp.storedCount > 0) {
|
if (storageComp.storedItem && storageComp.storedCount > 0) {
|
||||||
|
|||||||
@ -308,22 +308,18 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have any items to eject
|
const input = acceptorComp.completedInputs.get(0);
|
||||||
const nextItemAndDuration = undergroundComp.pendingItems[0];
|
if (input) {
|
||||||
if (nextItemAndDuration) {
|
|
||||||
assert(undergroundComp.pendingItems.length === 1, "more than 1 pending");
|
|
||||||
|
|
||||||
// Check if the receiver can accept it
|
// Check if the receiver can accept it
|
||||||
if (
|
if (
|
||||||
cacheEntry.entity.components.UndergroundBelt.tryAcceptTunneledItem(
|
cacheEntry.entity.components.UndergroundBelt.tryAcceptTunneledItem(
|
||||||
nextItemAndDuration[0],
|
input.item,
|
||||||
cacheEntry.distance,
|
cacheEntry.distance,
|
||||||
this.root.hubGoals.getUndergroundBeltBaseSpeed(),
|
this.root.hubGoals.getUndergroundBeltBaseSpeed(),
|
||||||
this.root.time.now()
|
this.root.time.now()
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// Drop this item
|
acceptorComp.completedInputs.delete(0);
|
||||||
fastArrayDelete(undergroundComp.pendingItems, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user