mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Huge performance improvements
This commit is contained in:
parent
2ac570f6d8
commit
4636080dd7
@ -86,27 +86,30 @@ export class BufferMaintainer {
|
|||||||
// Make sure our backlog never gets too big
|
// Make sure our backlog never gets too big
|
||||||
clearBufferBacklog();
|
clearBufferBacklog();
|
||||||
|
|
||||||
const bufferStats = getBufferStats();
|
// @ts-ignore
|
||||||
const mbUsed = round1Digit(bufferStats.vramUsage / (1024 * 1024));
|
if (G_IS_DEV && false) {
|
||||||
logger.log(
|
const bufferStats = getBufferStats();
|
||||||
"GC: Remove",
|
const mbUsed = round1Digit(bufferStats.vramUsage / (1024 * 1024));
|
||||||
(deletedKeys + "").padStart(4),
|
logger.log(
|
||||||
", Remain",
|
"GC: Remove",
|
||||||
(totalKeys + "").padStart(4),
|
(deletedKeys + "").padStart(4),
|
||||||
"(",
|
", Remain",
|
||||||
(bufferStats.bufferCount + "").padStart(4),
|
(totalKeys + "").padStart(4),
|
||||||
"total",
|
"(",
|
||||||
")",
|
(bufferStats.bufferCount + "").padStart(4),
|
||||||
|
"total",
|
||||||
|
")",
|
||||||
|
|
||||||
"(",
|
"(",
|
||||||
(bufferStats.backlogSize + "").padStart(4),
|
(bufferStats.backlogSize + "").padStart(4),
|
||||||
"backlog",
|
"backlog",
|
||||||
")",
|
")",
|
||||||
|
|
||||||
"VRAM:",
|
"VRAM:",
|
||||||
mbUsed,
|
mbUsed,
|
||||||
"MB"
|
"MB"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
++this.iterationIndex;
|
++this.iterationIndex;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,11 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
onPathChanged() {
|
onPathChanged() {
|
||||||
this.acceptorTarget = this.computeAcceptingEntityAndSlot();
|
this.acceptorTarget = this.computeAcceptingEntityAndSlot();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many items past the first item are compressed
|
||||||
|
*/
|
||||||
|
this.numCompressedItemsAfterFirstItem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,6 +431,26 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check first nonzero offset
|
||||||
|
let firstNonzero = 0;
|
||||||
|
for (let i = this.items.length - 2; i >= 0; --i) {
|
||||||
|
if (this.items[i][_nextDistance] < globalConfig.itemSpacingOnBelts + 1e-5) {
|
||||||
|
++firstNonzero;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should warn, but this check isn't actually accurate
|
||||||
|
// if (firstNonzero !== this.numCompressedItemsAfterFirstItem) {
|
||||||
|
// console.warn(
|
||||||
|
// "First nonzero index is " +
|
||||||
|
// firstNonzero +
|
||||||
|
// " but stored is " +
|
||||||
|
// this.numCompressedItemsAfterFirstItem
|
||||||
|
// );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dev:end */
|
/* dev:end */
|
||||||
@ -1038,11 +1063,15 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
// Store how much velocity (strictly its distance, not velocity) we have to distribute over all items
|
// Store how much velocity (strictly its distance, not velocity) we have to distribute over all items
|
||||||
let remainingVelocity = beltSpeed;
|
let remainingVelocity = beltSpeed;
|
||||||
|
|
||||||
for (let i = this.items.length - 1; i >= 0; --i) {
|
// Store the last item we processed, so we can skip clashed ones
|
||||||
const nextDistanceAndItem = this.items[i];
|
let lastItemProcessed;
|
||||||
|
|
||||||
|
for (lastItemProcessed = this.items.length - 1; lastItemProcessed >= 0; --lastItemProcessed) {
|
||||||
|
const nextDistanceAndItem = this.items[lastItemProcessed];
|
||||||
|
|
||||||
// Compute how much spacing we need at least
|
// Compute how much spacing we need at least
|
||||||
const minimumSpacing = i === this.items.length - 1 ? 0 : globalConfig.itemSpacingOnBelts;
|
const minimumSpacing =
|
||||||
|
lastItemProcessed === this.items.length - 1 ? 0 : globalConfig.itemSpacingOnBelts;
|
||||||
|
|
||||||
// Compute how much we can advance
|
// Compute how much we can advance
|
||||||
const clampedProgress = Math.max(
|
const clampedProgress = Math.max(
|
||||||
@ -1067,9 +1096,19 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
// Try to directly get rid of the item
|
// Try to directly get rid of the item
|
||||||
if (this.tryHandOverItem(nextDistanceAndItem[_item], excessVelocity)) {
|
if (this.tryHandOverItem(nextDistanceAndItem[_item], excessVelocity)) {
|
||||||
this.items.pop();
|
this.items.pop();
|
||||||
|
|
||||||
|
this.numCompressedItemsAfterFirstItem = Math.max(
|
||||||
|
0,
|
||||||
|
this.numCompressedItemsAfterFirstItem - 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isFirstItemProcessed) {
|
||||||
|
// Skip N null items after first items
|
||||||
|
lastItemProcessed -= this.numCompressedItemsAfterFirstItem;
|
||||||
|
}
|
||||||
|
|
||||||
isFirstItemProcessed = false;
|
isFirstItemProcessed = false;
|
||||||
this.spacingToFirstItem += clampedProgress;
|
this.spacingToFirstItem += clampedProgress;
|
||||||
if (remainingVelocity < 0.01) {
|
if (remainingVelocity < 0.01) {
|
||||||
@ -1077,11 +1116,22 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute compressed item count
|
||||||
|
this.numCompressedItemsAfterFirstItem = Math.max(
|
||||||
|
0,
|
||||||
|
this.numCompressedItemsAfterFirstItem,
|
||||||
|
this.items.length - 2 - lastItemProcessed
|
||||||
|
);
|
||||||
|
|
||||||
// Check if we have an item which is ready to be emitted
|
// Check if we have an item which is ready to be emitted
|
||||||
const lastItem = this.items[this.items.length - 1];
|
const lastItem = this.items[this.items.length - 1];
|
||||||
if (lastItem && lastItem[_nextDistance] === 0 && this.acceptorTarget) {
|
if (lastItem && lastItem[_nextDistance] === 0 && this.acceptorTarget) {
|
||||||
if (this.tryHandOverItem(lastItem[_item])) {
|
if (this.tryHandOverItem(lastItem[_item])) {
|
||||||
this.items.pop();
|
this.items.pop();
|
||||||
|
this.numCompressedItemsAfterFirstItem = Math.max(
|
||||||
|
0,
|
||||||
|
this.numCompressedItemsAfterFirstItem - 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1205,6 +1255,11 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
worldPos.y + 2
|
worldPos.y + 2
|
||||||
);
|
);
|
||||||
progress += nextDistanceAndItem[_nextDistance];
|
progress += nextDistanceAndItem[_nextDistance];
|
||||||
|
|
||||||
|
if (this.items.length - 1 - this.numCompressedItemsAfterFirstItem === i) {
|
||||||
|
parameters.context.fillStyle = "red";
|
||||||
|
parameters.context.fillRect(worldPos.x + 5, worldPos.y, 20, 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this.entityPath.length; ++i) {
|
for (let i = 0; i < this.entityPath.length; ++i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user