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:
parent
64546d6554
commit
14eaa2d9aa
@ -40,5 +40,7 @@ export class BeltReaderComponent extends Component {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.lastThroughputComputation = 0;
|
this.lastThroughputComputation = 0;
|
||||||
|
|
||||||
|
this.lastRemovedItemTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,45 +16,40 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
|
|
||||||
const readerComp = entity.components.BeltReader;
|
const readerComp = entity.components.BeltReader;
|
||||||
|
const lastItemTimes = readerComp.lastItemTimes;
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
// Remove outdated items
|
// Remove outdated items
|
||||||
while (readerComp.lastItemTimes[0] < minimumTime) {
|
while (lastItemTimes[0] < minimumTime) {
|
||||||
readerComp.lastItemTimes.shift();
|
readerComp.lastRemovedItemTime = 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now - readerComp.lastThroughputComputation > 0.5) {
|
if (now - readerComp.lastThroughputComputation > 0.5) {
|
||||||
// Compute throughput
|
// Compute throughput
|
||||||
readerComp.lastThroughputComputation = now;
|
readerComp.lastThroughputComputation = now;
|
||||||
|
|
||||||
|
const oneItem = lastItemTimes.length == 1;
|
||||||
let throughput = 0;
|
let throughput = 0;
|
||||||
if (readerComp.lastItemTimes.length < 2) {
|
if (lastItemTimes.length > 0) {
|
||||||
throughput = 0;
|
let averageSpacing = oneItem ? lastItemTimes[0] - readerComp.lastRemovedItemTime : 0;
|
||||||
} else {
|
let averageSpacingNum = oneItem ? 1 : 0;
|
||||||
let averageSpacing = 0;
|
for (let i = 0; i < lastItemTimes.length - 1; ++i) {
|
||||||
let averageSpacingNum = 0;
|
averageSpacing += lastItemTimes[i + 1] - lastItemTimes[i];
|
||||||
for (let i = 0; i < readerComp.lastItemTimes.length - 1; ++i) {
|
|
||||||
averageSpacing += readerComp.lastItemTimes[i + 1] - readerComp.lastItemTimes[i];
|
|
||||||
++averageSpacingNum;
|
++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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user