1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

changed belt reader to make it more precise

This commit is contained in:
Sense101 2021-04-16 13:06:07 +01:00
parent 64546d6554
commit 14eaa2d9aa
2 changed files with 22 additions and 25 deletions

View File

@ -40,5 +40,7 @@ export class BeltReaderComponent extends Component {
* @type {number}
*/
this.lastThroughputComputation = 0;
this.lastRemovedItemTime = 0;
}
}

View File

@ -16,45 +16,40 @@ export class BeltReaderSystem extends GameSystemWithFilter {
const entity = this.allEntities[i];
const readerComp = entity.components.BeltReader;
const lastItemTimes = readerComp.lastItemTimes;
const pinsComp = entity.components.WiredPins;
// Remove outdated items
while (readerComp.lastItemTimes[0] < minimumTime) {
readerComp.lastItemTimes.shift();
}
pinsComp.slots[1].value = readerComp.lastItem;
if (
(readerComp.lastItemTimes[readerComp.lastItemTimes.length - 1] || 0) >
minimumTimeForThroughput
) {
pinsComp.slots[0].value = BOOL_TRUE_SINGLETON;
} else {
pinsComp.slots[0].value = BOOL_FALSE_SINGLETON;
if (entity.components.ItemEjector.canEjectOnSlot(0)) {
readerComp.lastItem = null;
}
while (lastItemTimes[0] < minimumTime) {
readerComp.lastRemovedItemTime = lastItemTimes.shift();
}
if (now - readerComp.lastThroughputComputation > 0.5) {
// Compute throughput
readerComp.lastThroughputComputation = now;
const oneItem = lastItemTimes.length == 1;
let throughput = 0;
if (readerComp.lastItemTimes.length < 2) {
throughput = 0;
} else {
let averageSpacing = 0;
let averageSpacingNum = 0;
for (let i = 0; i < readerComp.lastItemTimes.length - 1; ++i) {
averageSpacing += readerComp.lastItemTimes[i + 1] - readerComp.lastItemTimes[i];
if (lastItemTimes.length > 0) {
let averageSpacing = oneItem ? lastItemTimes[0] - readerComp.lastRemovedItemTime : 0;
let averageSpacingNum = oneItem ? 1 : 0;
for (let i = 0; i < lastItemTimes.length - 1; ++i) {
averageSpacing += lastItemTimes[i + 1] - lastItemTimes[i];
++averageSpacingNum;
}
throughput = 1 / (averageSpacing / averageSpacingNum);
throughput = 1 / (averageSpacing / averageSpacingNum) + 0.01;
}
readerComp.lastThroughput = Math.min(globalConfig.beltSpeedItemsPerSecond * 23.9, throughput);
readerComp.lastThroughput = Math.min(globalConfig.beltSpeedItemsPerSecond, throughput);
}
if (readerComp.lastThroughput > 0) {
pinsComp.slots[0].value = BOOL_TRUE_SINGLETON;
pinsComp.slots[1].value = readerComp.lastItem;
} else {
pinsComp.slots[0].value = BOOL_FALSE_SINGLETON;
pinsComp.slots[1].value = null;
}
}
}