mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Make miners cache mined item
Saves two chunk+tile lookups per update, and one chunk+tile lookup per draw.
This commit is contained in:
@@ -24,10 +24,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
// Check if miner is above an actual tile
|
||||
|
||||
const minerComp = entity.components.Miner;
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
const tileBelow = this.root.map.getLowerLayerContentXY(staticComp.origin.x, staticComp.origin.y);
|
||||
if (!tileBelow) {
|
||||
if (!minerComp.minedItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -40,20 +38,9 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
if (this.root.time.isIngameTimerExpired(minerComp.lastMiningTime, 1 / miningSpeed)) {
|
||||
const lowerLayerItem = this.root.map.getLowerLayerContentXY(
|
||||
staticComp.origin.x,
|
||||
staticComp.origin.y
|
||||
);
|
||||
|
||||
// TODO: Should not be required actually
|
||||
if (!lowerLayerItem) {
|
||||
// Nothing below;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.tryPerformMinerEject(entity, lowerLayerItem)) {
|
||||
if (this.tryPerformMinerEject(entity, minerComp.minedItem)) {
|
||||
// Analytics hook
|
||||
this.root.signals.itemProduced.dispatch(lowerLayerItem);
|
||||
this.root.signals.itemProduced.dispatch(minerComp.minedItem);
|
||||
|
||||
// Actually mine
|
||||
minerComp.lastMiningTime = this.root.time.now();
|
||||
@@ -114,18 +101,14 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
|
||||
if (entity && entity.components.Miner) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const minerComp = entity.components.Miner;
|
||||
if (!staticComp.shouldBeDrawn(parameters)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const lowerLayerItem = this.root.map.getLowerLayerContentXY(
|
||||
staticComp.origin.x,
|
||||
staticComp.origin.y
|
||||
);
|
||||
|
||||
if (lowerLayerItem) {
|
||||
if (minerComp.minedItem) {
|
||||
const padding = 3;
|
||||
parameters.context.fillStyle = lowerLayerItem.getBackgroundColorAsResource();
|
||||
parameters.context.fillStyle = minerComp.minedItem.getBackgroundColorAsResource();
|
||||
parameters.context.fillRect(
|
||||
staticComp.origin.x * globalConfig.tileSize + padding,
|
||||
staticComp.origin.y * globalConfig.tileSize + padding,
|
||||
@@ -134,8 +117,8 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
);
|
||||
}
|
||||
|
||||
if (lowerLayerItem) {
|
||||
lowerLayerItem.draw(
|
||||
if (minerComp.minedItem) {
|
||||
minerComp.minedItem.draw(
|
||||
(0.5 + staticComp.origin.x) * globalConfig.tileSize,
|
||||
(0.5 + staticComp.origin.y) * globalConfig.tileSize,
|
||||
parameters
|
||||
|
||||
Reference in New Issue
Block a user