Skip to content

Commit c251ef1

Browse files
committed
updateCellsAroundPlayer only if it is needed
1 parent 78bac98 commit c251ef1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/client/scripts/World/World.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var World = class World {
5858
blocksDef: this.blocksDef,
5959
},
6060
});
61+
this.lastPlayerChunk = "";
6162
}
6263
/**
6364
* Updates render order of chunk meshes
@@ -158,6 +159,7 @@ var World = class World {
158159
_this.cellMesh[cellId].onAfterRender = function () {};
159160
};
160161
this.game.scene.add(this.cellMesh[cellId]);
162+
this.updateRenderOrder(JSON.parse(this.lastPlayerChunk));
161163
} else {
162164
this.cellMesh[cellId].geometry = geometry;
163165
}
@@ -288,15 +290,18 @@ var World = class World {
288290
Math.floor(pos.y + 0.5),
289291
Math.floor(pos.z + 0.5)
290292
);
291-
this.updateRenderOrder(cell);
292-
if (
293-
this.cellUpdateTime !== null &&
294-
performance.now() - this.cellUpdateTime > this.renderTime
295-
) {
296-
this.chunkWorker.postMessage({
297-
type: "updateCellsAroundPlayer",
298-
data: [cell, radius],
299-
});
293+
if (this.lastPlayerChunk != JSON.stringify(cell)) {
294+
if (
295+
this.cellUpdateTime !== null &&
296+
performance.now() - this.cellUpdateTime > this.renderTime
297+
) {
298+
this.updateRenderOrder(cell);
299+
this.lastPlayerChunk = JSON.stringify(cell);
300+
this.chunkWorker.postMessage({
301+
type: "updateCellsAroundPlayer",
302+
data: [cell, radius],
303+
});
304+
}
300305
}
301306
}
302307
/**

0 commit comments

Comments
 (0)