Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Dec 17, 2024
1 parent a66ee33 commit 5fe4b9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
9 changes: 3 additions & 6 deletions prismarine-viewer/viewer/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ export class Viewer {
})
}

addColumn (x, z, chunk, isLightUpdate = false) {
this.world.addColumn(x, z, chunk, isLightUpdate)
}

removeColumn (x: string, z: string) {
this.world.removeColumn(x, z)
}
Expand Down Expand Up @@ -221,9 +217,10 @@ export class Viewer {
timeout
data
} | null
worldEmitter.on('loadChunk', ({ x, z, chunk, worldConfig, isLightUpdate }) => {
worldEmitter.on('loadChunk', ({ x, z, column, worldConfig, isLightUpdate }) => {
this.world.worldConfig = worldConfig
this.world.queuedChunks.add(`${x},${z}`)
const chunk = column.toJson() // todo use export
const args = [x, z, chunk, isLightUpdate]
if (!currentLoadChunkBatch) {
// add a setting to use debounce instead
Expand All @@ -232,7 +229,7 @@ export class Viewer {
timeout: setTimeout(() => {
for (const args of currentLoadChunkBatch!.data) {
this.world.queuedChunks.delete(`${args[0]},${args[1]}`)
this.addColumn(...args as Parameters<typeof this.addColumn>)
this.world.addColumn(...args as Parameters<typeof this.world.addColumn>)
}
currentLoadChunkBatch = null
}, this.addChunksBatchWaitTime)
Expand Down
6 changes: 1 addition & 5 deletions prismarine-viewer/viewer/lib/worldDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,11 @@ export class WorldDataEmitter extends EventEmitter {
// const latency = Math.floor(performance.now() - this.lastTime)
// this.debugGotChunkLatency.push(latency)
// this.lastTime = performance.now()
// todo optimize toJson data, make it clear why it is used
const chunk = column.toJson()
// TODO: blockEntities
const worldConfig = {
minY: column['minY'] ?? 0,
worldHeight: column['worldHeight'] ?? 256,
}
//@ts-expect-error
this.emitter.emit('loadChunk', { x: pos.x, z: pos.z, chunk, blockEntities: column.blockEntities, worldConfig, isLightUpdate })
this.emitter.emit('loadChunk', { x: pos.x, z: pos.z, column, worldConfig, isLightUpdate })
this.loadedChunks[`${pos.x},${pos.z}`] = true
} else if (this.isPlayground) { // don't allow in real worlds pre-flag chunks as loaded to avoid race condition when the chunk might still be loading. In playground it's assumed we always pre-load all chunks first
this.emitter.emit('markAsLoaded', { x: pos.x, z: pos.z })
Expand Down
4 changes: 3 additions & 1 deletion prismarine-viewer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
workersProcessAverageTimeCount = 0
maxWorkersProcessTime = 0
geometryReceiveCount = 0
geometryReceiveCountPerSec = 0
allLoadedIn: undefined | number
messagesDelay = 0
messageDelayCount = 0
Expand Down Expand Up @@ -151,6 +152,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
})

setInterval(() => {
this.geometryReceiveCountPerSec = this.geometryReceiveCount
this.geometryReceiveCount = 0
this.updateChunksStatsText()
}, 1000)
Expand Down Expand Up @@ -377,7 +379,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
}

updateChunksStatsText () {
updateStatText('downloaded-chunks', `${Object.keys(this.loadedChunks).length}/${this.chunksLength} chunks D (${this.workers.length}:${this.workersProcessAverageTime.toFixed(0)}ms/${this.geometryReceiveCount}ss/${this.allLoadedIn?.toFixed(1) ?? '-'}s)`)
updateStatText('downloaded-chunks', `${Object.keys(this.loadedChunks).length}/${this.chunksLength} chunks D (${this.workers.length}:${this.workersProcessAverageTime.toFixed(0)}ms/${this.geometryReceiveCountPerSec}ss/${this.allLoadedIn?.toFixed(1) ?? '-'}s)`)
}

addColumn (x: number, z: number, chunk: any, isLightUpdate: boolean) {
Expand Down

0 comments on commit 5fe4b9d

Please sign in to comment.