Skip to content

Commit

Permalink
feat: add a setting to either completely hide perf stats or enable mo…
Browse files Browse the repository at this point in the history
…re advanced display

can be used for demos like: `?setting=renderDebug:"none"`
  • Loading branch information
zardoy committed Oct 20, 2024
1 parent a1c41e8 commit c53ba87
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions prismarine-viewer/examples/baseScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class BasePlaygroundScene {
// Create viewer
const viewer = new Viewer(renderer, { numWorkers: 1, showChunkBorders: false, })
window.viewer = viewer
viewer.world.isPlayground = true
viewer.addChunksBatchWaitTime = 0
viewer.world.blockstatesModels = blockstatesModels
viewer.entities.setDebugMode('basic')
Expand Down
1 change: 0 additions & 1 deletion prismarine-viewer/viewer/lib/mesher/test/tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ test('Known blocks are not rendered', () => {
"end_gateway": true,
"end_portal": true,
"structure_void": true,
"trial_spawner": true,
}
`)
expect(erroredBlocks).toMatchInlineSnapshot('{}')
Expand Down
3 changes: 3 additions & 0 deletions prismarine-viewer/viewer/lib/ui/newStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) =
return {
updateText (text: string) {
pane.innerText = text
},
setVisibility (visible: boolean) {
pane.style.display = visible ? 'block' : 'none'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions prismarine-viewer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type CustomTexturesData = {
}

export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any> {
isPlayground = false
displayStats = true
worldConfig = { minY: 0, worldHeight: 256 }
// todo need to cleanup
material = new THREE.MeshLambertMaterial({ vertexColors: true, transparent: true, alphaTest: 0.1 })
Expand Down
5 changes: 4 additions & 1 deletion prismarine-viewer/viewer/lib/worldrendererThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export class WorldRendererThree extends WorldRendererCommon {
this.debugOverlayAdded = true
const pane = addNewStat('debug-overlay')
setInterval(() => {
pane.updateText(`C: ${this.renderer.info.render.calls} TR: ${this.renderer.info.render.triangles} TE: ${this.renderer.info.memory.textures} F: ${this.tilesRendered} B: ${this.blocksRendered}`)
pane.setVisibility(this.displayStats)
if (this.displayStats) {
pane.updateText(`C: ${this.renderer.info.render.calls} TR: ${this.renderer.info.render.triangles} TE: ${this.renderer.info.memory.textures} F: ${this.tilesRendered} B: ${this.blocksRendered}`)
}
}, 100)
}

Expand Down
7 changes: 7 additions & 0 deletions src/optionsGuiScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export const guiOptionsScheme: {
},
handDisplay: {},
neighborChunkUpdates: {},
renderDebug: {
values: [
'advanced',
'basic',
'none'
],
},
},
],
main: [
Expand Down
2 changes: 2 additions & 0 deletions src/optionsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { proxy, subscribe } from 'valtio/vanilla'
import { subscribeKey } from 'valtio/utils'
import { omitObj } from '@zardoy/utils'

const isDev = process.env.NODE_ENV === 'development'
const defaultOptions = {
renderDistance: 3,
keepChunksDistance: 1,
Expand Down Expand Up @@ -75,6 +76,7 @@ const defaultOptions = {
autoJump: 'auto' as 'auto' | 'always' | 'never',
autoParkour: false,
vrSupport: true, // doesn't directly affect the VR mode, should only disable the button which is annoying to android users
renderDebug: (isDev ? 'basic' : 'advanced') as 'none' | 'advanced' | 'basic',

// advanced bot options
autoRespawn: false,
Expand Down
2 changes: 2 additions & 0 deletions src/react/PauseScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@ export default () => {
</Button>
{(navigator.share as typeof navigator.share | undefined) ? (
<Button
title="Share Join Link"
className="button"
icon="pixelarticons:arrow-up"
style={{ width: '20px' }}
onClick={async () => clickWebShareButton()}
/>
) : null}
<Button
title='Display QR for the Join Link'
className="button"
icon="pixelarticons:dice"
style={{ width: '20px' }}
Expand Down
16 changes: 13 additions & 3 deletions src/topRightStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ if (hasRamPanel) {
addStat(stats2.dom)
}

export const toggleStatsVisibility = (visible: boolean) => {
if (visible) {
stats.dom.style.display = 'block'
stats2.dom.style.display = 'block'
statsGl.container.style.display = 'block'
} else {
stats.dom.style.display = 'none'
stats2.dom.style.display = 'none'
statsGl.container.style.display = 'none'
}
}

const hideStats = localStorage.hideStats || isCypress()
if (hideStats) {
stats.dom.style.display = 'none'
stats2.dom.style.display = 'none'
statsGl.container.style.display = 'none'
toggleStatsVisibility(false)
}

export const initWithRenderer = (canvas) => {
Expand Down
15 changes: 15 additions & 0 deletions src/watchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isMobile } from 'prismarine-viewer/viewer/lib/simpleUtils'
import { options, watchValue } from './optionsStorage'
import { reloadChunks } from './utils'
import { miscUiState } from './globalState'
import { toggleStatsVisibility } from './topRightStats'

subscribeKey(options, 'renderDistance', reloadChunks)
subscribeKey(options, 'multiplayerRenderDistance', reloadChunks)
Expand Down Expand Up @@ -44,6 +45,20 @@ export const watchOptionsAfterViewerInit = () => {
viewer.entities.setRendering(o.renderEntities)
})

if (options.renderDebug === 'none') {
toggleStatsVisibility(false)
}
subscribeKey(options, 'renderDebug', () => {
if (options.renderDebug === 'none') {
toggleStatsVisibility(false)
} else {
toggleStatsVisibility(true)
}
})
watchValue(options, o => {
viewer.world.displayStats = o.renderDebug === 'advanced'
})

// viewer.world.mesherConfig.smoothLighting = options.smoothLighting
viewer.world.mesherConfig.smoothLighting = false // todo not supported for now
subscribeKey(options, 'smoothLighting', () => {
Expand Down

0 comments on commit c53ba87

Please sign in to comment.