Skip to content

Commit 1cbb81d

Browse files
committed
Make server/client distinction environment-agnostic
1 parent 0b5f817 commit 1cbb81d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ function Game(opts) {
3131
if (!opts) opts = {}
3232
if (process.browser && this.notCapable(opts)) return
3333

34+
// is this a client or a headless server
35+
this.isClient = Boolean( (typeof opts.isClient !== 'undefined') ? opts.isClient : process.browser )
36+
3437
if (!('generateChunks' in opts)) opts.generateChunks = true
3538
this.generateChunks = opts.generateChunks
3639
this.setConfigurablePositions(opts)
@@ -100,12 +103,12 @@ function Game(opts) {
100103
self.removeFarChunks()
101104
})
102105

103-
if (process.browser) this.materials.load(this.materialNames)
106+
if (this.isClient) this.materials.load(this.materialNames)
104107

105108
if (this.generateChunks) this.handleChunkGeneration()
106109

107110
// client side only after this point
108-
if (!process.browser) return
111+
if (!this.isClient) return
109112

110113
this.paused = true
111114
this.initializeRendering(opts)
@@ -518,7 +521,7 @@ Game.prototype.loadPendingChunks = function(count) {
518521
var chunkPos = pendingChunks[i].split('|')
519522
var chunk = this.voxels.generateChunk(chunkPos[0]|0, chunkPos[1]|0, chunkPos[2]|0)
520523

521-
if (process.browser) this.showChunk(chunk)
524+
if (this.isClient) this.showChunk(chunk)
522525
}
523526

524527
if (count) pendingChunks.splice(0, count)
@@ -538,7 +541,7 @@ Game.prototype.showChunk = function(chunk) {
538541
this.voxels.chunks[chunkIndex] = chunk
539542
if (this.voxels.meshes[chunkIndex]) this.scene.remove(this.voxels.meshes[chunkIndex][this.meshType])
540543
this.voxels.meshes[chunkIndex] = mesh
541-
if (process.browser) {
544+
if (this.isClient) {
542545
if (this.meshType === 'wireMesh') mesh.createWireMesh()
543546
else mesh.createSurfaceMesh(this.materials.material)
544547
this.materials.paint(mesh)

0 commit comments

Comments
 (0)