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

Reduce savegame size by not storing the tileSize in the static entity

This commit is contained in:
tobspr
2020-08-10 22:13:26 +02:00
parent 8d329990ef
commit bb431b8490
6 changed files with 45 additions and 66 deletions

View File

@@ -24,6 +24,14 @@ export class StaticMapEntityComponent extends Component {
};
}
/**
* Returns the effective tile size
* @returns {Vector}
*/
getTileSize() {
return getBuildingDataFromCode(this.code).tileSize;
}
/**
* Returns the sprite
* @returns {AtlasSprite}
@@ -51,7 +59,6 @@ export class StaticMapEntityComponent extends Component {
duplicateWithoutContents() {
return new StaticMapEntityComponent({
origin: this.origin.copy(),
tileSize: this.tileSize.copy(),
rotation: this.rotation,
originalRotation: this.originalRotation,
code: this.code,
@@ -81,7 +88,6 @@ export class StaticMapEntityComponent extends Component {
);
this.origin = origin;
this.tileSize = tileSize;
this.rotation = rotation;
this.code = code;
this.originalRotation = originalRotation;
@@ -92,30 +98,16 @@ export class StaticMapEntityComponent extends Component {
* @returns {Rectangle}
*/
getTileSpaceBounds() {
const size = this.getTileSize();
switch (this.rotation) {
case 0:
return new Rectangle(this.origin.x, this.origin.y, this.tileSize.x, this.tileSize.y);
return new Rectangle(this.origin.x, this.origin.y, size.x, size.y);
case 90:
return new Rectangle(
this.origin.x - this.tileSize.y + 1,
this.origin.y,
this.tileSize.y,
this.tileSize.x
);
return new Rectangle(this.origin.x - size.y + 1, this.origin.y, size.y, size.x);
case 180:
return new Rectangle(
this.origin.x - this.tileSize.x + 1,
this.origin.y - this.tileSize.y + 1,
this.tileSize.x,
this.tileSize.y
);
return new Rectangle(this.origin.x - size.x + 1, this.origin.y - size.y + 1, size.x, size.y);
case 270:
return new Rectangle(
this.origin.x,
this.origin.y - this.tileSize.x + 1,
this.tileSize.y,
this.tileSize.x
);
return new Rectangle(this.origin.x, this.origin.y - size.x + 1, size.y, size.x);
default:
assert(false, "Invalid rotation");
}
@@ -186,34 +178,35 @@ export class StaticMapEntityComponent extends Component {
let y = 0;
let w = 0;
let h = 0;
const size = this.getTileSize();
switch (this.rotation) {
case 0: {
x = this.origin.x;
y = this.origin.y;
w = this.tileSize.x;
h = this.tileSize.y;
w = size.x;
h = size.y;
break;
}
case 90: {
x = this.origin.x - this.tileSize.y + 1;
x = this.origin.x - size.y + 1;
y = this.origin.y;
w = this.tileSize.y;
h = this.tileSize.x;
w = size.y;
h = size.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;
x = this.origin.x - size.x + 1;
y = this.origin.y - size.y + 1;
w = size.x;
h = size.y;
break;
}
case 270: {
x = this.origin.x;
y = this.origin.y - this.tileSize.x + 1;
w = this.tileSize.y;
h = this.tileSize.x;
y = this.origin.y - size.x + 1;
w = size.y;
h = size.x;
break;
}
default:
@@ -233,19 +226,13 @@ export class StaticMapEntityComponent extends Component {
* @param {DrawParameters} parameters
* @param {AtlasSprite} sprite
* @param {number=} extrudePixels How many pixels to extrude the sprite
* @param {boolean=} clipping Whether to clip
* @param {Vector=} overridePosition Whether to drwa the entity at a different location
*/
drawSpriteOnFullEntityBounds(
parameters,
sprite,
extrudePixels = 0,
clipping = true,
overridePosition = null
) {
drawSpriteOnFullEntityBounds(parameters, sprite, extrudePixels = 0, overridePosition = null) {
if (!this.shouldBeDrawn(parameters) && !overridePosition) {
return;
}
const size = this.getTileSize();
let worldX = this.origin.x * globalConfig.tileSize;
let worldY = this.origin.y * globalConfig.tileSize;
@@ -258,10 +245,10 @@ export class StaticMapEntityComponent extends Component {
// Early out, is faster
sprite.drawCached(
parameters,
worldX - extrudePixels * this.tileSize.x,
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,
worldX - extrudePixels * size.x,
worldY - extrudePixels * size.y,
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
false
);
} else {
@@ -273,10 +260,10 @@ export class StaticMapEntityComponent extends Component {
sprite.drawCached(
parameters,
-globalConfig.halfTileSize - extrudePixels * this.tileSize.x,
-globalConfig.halfTileSize - extrudePixels * this.tileSize.y,
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
-globalConfig.halfTileSize - extrudePixels * size.x,
-globalConfig.halfTileSize - extrudePixels * size.y,
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
false
);