mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Speed up belt rendering
This commit is contained in:
parent
755f4bd2ea
commit
18fb9cb04f
@ -1109,14 +1109,45 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let progress = this.spacingToFirstItem;
|
if (this.items.length === 0) {
|
||||||
for (let i = 0; i < this.items.length; ++i) {
|
// Early out
|
||||||
const nextDistanceAndItem = this.items[i];
|
return;
|
||||||
const worldPos = this.computePositionFromProgress(progress).toWorldSpaceCenterOfTile();
|
}
|
||||||
|
|
||||||
|
let currentItemPos = this.spacingToFirstItem;
|
||||||
|
let currentItemIndex = 0;
|
||||||
|
|
||||||
|
let trackPos = 0.0;
|
||||||
|
|
||||||
|
// Iterate whole track and check items
|
||||||
|
for (let i = 0; i < this.entityPath.length; ++i) {
|
||||||
|
const entity = this.entityPath[i];
|
||||||
|
const beltComp = entity.components.Belt;
|
||||||
|
const beltLength = beltComp.getEffectiveLengthTiles();
|
||||||
|
|
||||||
|
// Check if the item is on the current belt
|
||||||
|
if (trackPos + beltLength >= currentItemPos) {
|
||||||
|
// Its on the belt, render it now
|
||||||
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
const localPos = beltComp.transformBeltToLocalSpace(currentItemPos - trackPos);
|
||||||
|
const worldPos = staticComp.localTileToWorld(localPos).toWorldSpaceCenterOfTile();
|
||||||
|
|
||||||
|
const distanceAndItem = this.items[currentItemIndex];
|
||||||
if (parameters.visibleRect.containsCircle(worldPos.x, worldPos.y, 10)) {
|
if (parameters.visibleRect.containsCircle(worldPos.x, worldPos.y, 10)) {
|
||||||
nextDistanceAndItem[_item].draw(worldPos.x, worldPos.y, parameters);
|
distanceAndItem[_item].draw(worldPos.x, worldPos.y, parameters);
|
||||||
}
|
}
|
||||||
progress += nextDistanceAndItem[_nextDistance];
|
|
||||||
|
// Check for the next item
|
||||||
|
currentItemPos += distanceAndItem[_nextDistance];
|
||||||
|
++currentItemIndex;
|
||||||
|
|
||||||
|
if (currentItemIndex >= this.items.length) {
|
||||||
|
// We rendered all items
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trackPos += beltLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user