1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Major performance improvements

This commit is contained in:
tobspr
2020-05-18 17:40:20 +02:00
parent 260ba892c8
commit 2c48cb72aa
18 changed files with 194 additions and 60 deletions

View File

@@ -145,6 +145,57 @@ export class StaticMapEntityComponent extends Component {
return this.unapplyRotationToVector(localUnrotated);
}
/**
* Returns whether the entity should be drawn for the given parameters
* @param {DrawParameters} parameters
*/
shouldBeDrawn(parameters) {
let x = 0;
let y = 0;
let w = 0;
let h = 0;
switch (this.rotation) {
case 0: {
x = this.origin.x;
y = this.origin.y;
w = this.tileSize.x;
h = this.tileSize.y;
break;
}
case 90: {
x = this.origin.x - this.tileSize.y + 1;
y = this.origin.y;
w = this.tileSize.y;
h = this.tileSize.x;
break;
}
case 180: {
x = this.origin.x - this.tileSize.x + 1;
y = this.origin.y - this.tileSize.y + 1;
w = this.tileSize.x;
h = this.tileSize.y;
break;
}
case 270: {
x = this.origin.x;
y = this.origin.y - this.tileSize.x + 1;
w = this.tileSize.y;
h = this.tileSize.x;
break;
}
default:
assert(false, "Invalid rotation");
}
return parameters.visibleRect.containsRect4Params(
x * globalConfig.tileSize,
y * globalConfig.tileSize,
w * globalConfig.tileSize,
h * globalConfig.tileSize
);
}
/**
* Draws a sprite over the whole space of the entity
* @param {DrawParameters} parameters
@@ -156,6 +207,10 @@ export class StaticMapEntityComponent extends Component {
const worldX = this.origin.x * globalConfig.tileSize;
const worldY = this.origin.y * globalConfig.tileSize;
if (!this.shouldBeDrawn(parameters)) {
return;
}
if (this.rotation === 0) {
// Early out, is faster
sprite.drawCached(
@@ -164,7 +219,7 @@ export class StaticMapEntityComponent extends Component {
worldY - extrudePixels * this.tileSize.y,
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
clipping
false
);
} else {
const rotationCenterX = worldX + globalConfig.halfTileSize;