From 1c7fdc21a6b3c997a2cece632bf40184a02e57d7 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 7 Sep 2024 19:33:16 +0300 Subject: [PATCH] add a way to to disable neighbor chunk updates and all the UI (needed for perf testing) --- .../viewer/lib/worldrendererCommon.ts | 17 ++++++++++------- src/optionsGuiScheme.tsx | 7 ++++--- src/optionsStorage.ts | 1 + src/reactUi.tsx | 2 +- src/watchOptions.ts | 4 ++++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/prismarine-viewer/viewer/lib/worldrendererCommon.ts b/prismarine-viewer/viewer/lib/worldrendererCommon.ts index 49de2ca01..92fc96819 100644 --- a/prismarine-viewer/viewer/lib/worldrendererCommon.ts +++ b/prismarine-viewer/viewer/lib/worldrendererCommon.ts @@ -100,6 +100,7 @@ export abstract class WorldRendererCommon x: number z: number } + neighborChunkUpdates = true abstract outputFormat: 'threeJs' | 'webgpu' @@ -321,7 +322,7 @@ export abstract class WorldRendererCommon for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) { const loc = new Vec3(x, y, z) this.setSectionDirty(loc) - if (!isLightUpdate || this.mesherConfig.smoothLighting) { + if (this.neighborChunkUpdates && (!isLightUpdate || this.mesherConfig.smoothLighting)) { this.setSectionDirty(loc.offset(-16, 0, 0)) this.setSectionDirty(loc.offset(16, 0, 0)) this.setSectionDirty(loc.offset(0, 0, -16)) @@ -357,12 +358,14 @@ export abstract class WorldRendererCommon worker.postMessage({ type: 'blockUpdate', pos, stateId }) } this.setSectionDirty(pos) - if ((pos.x & 15) === 0) this.setSectionDirty(pos.offset(-16, 0, 0)) - if ((pos.x & 15) === 15) this.setSectionDirty(pos.offset(16, 0, 0)) - if ((pos.y & 15) === 0) this.setSectionDirty(pos.offset(0, -16, 0)) - if ((pos.y & 15) === 15) this.setSectionDirty(pos.offset(0, 16, 0)) - if ((pos.z & 15) === 0) this.setSectionDirty(pos.offset(0, 0, -16)) - if ((pos.z & 15) === 15) this.setSectionDirty(pos.offset(0, 0, 16)) + if (this.neighborChunkUpdates) { + if ((pos.x & 15) === 0) this.setSectionDirty(pos.offset(-16, 0, 0)) + if ((pos.x & 15) === 15) this.setSectionDirty(pos.offset(16, 0, 0)) + if ((pos.y & 15) === 0) this.setSectionDirty(pos.offset(0, -16, 0)) + if ((pos.y & 15) === 15) this.setSectionDirty(pos.offset(0, 16, 0)) + if ((pos.z & 15) === 0) this.setSectionDirty(pos.offset(0, 0, -16)) + if ((pos.z & 15) === 15) this.setSectionDirty(pos.offset(0, 0, 16)) + } } queueAwaited = false diff --git a/src/optionsGuiScheme.tsx b/src/optionsGuiScheme.tsx index fc9e347ea..015013d15 100644 --- a/src/optionsGuiScheme.tsx +++ b/src/optionsGuiScheme.tsx @@ -91,6 +91,7 @@ export const guiOptionsScheme: { tooltip: 'Additional distance to keep the chunks loading before unloading them by marking them as too far', }, handDisplay: {}, + neighborChunkUpdates: {}, }, ], main: [ @@ -429,15 +430,15 @@ const Category = ({ children }) =>
{ const { disabledUiParts } = useSnapshot(options) - const currentlyEnabled = disabledUiParts.includes(name) + const currentlyDisabled = disabledUiParts.includes(name) if (addUiText) label = `${label} UI` return + >{currentlyDisabled ? 'Enable' : 'Disable'} {label} } export const tryFindOptionConfig = (option: keyof AppOptions) => { diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index 936d5bfc3..d5a9e5aa8 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -84,6 +84,7 @@ const defaultOptions = { wysiwygSignEditor: 'auto' as 'auto' | 'always' | 'never', displayBossBars: false, // boss bar overlay was removed for some reason, enable safely disabledUiParts: [] as string[], + neighborChunkUpdates: true } function getDefaultTouchControlsPositions () { diff --git a/src/reactUi.tsx b/src/reactUi.tsx index 599a18f7c..2fb63c197 100644 --- a/src/reactUi.tsx +++ b/src/reactUi.tsx @@ -104,7 +104,7 @@ const InGameUi = () => { const { disabledUiParts, displayBossBars } = useSnapshot(options) const hasModals = useSnapshot(activeModalStack).length > 0 const showUI = showUIRaw || hasModals - if (!gameLoaded || !bot) return + if (!gameLoaded || !bot || disabledUiParts.includes('*')) return return <> diff --git a/src/watchOptions.ts b/src/watchOptions.ts index d26d2b90d..926c6be1d 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -62,6 +62,10 @@ export const watchOptionsAfterViewerInit = () => { if (!(viewer.world instanceof WorldRendererThree)) return viewer.world.starField.enabled = o.starfieldRendering }) + + watchValue(options, o => { + viewer.world.neighborChunkUpdates = o.neighborChunkUpdates + }) } let viewWatched = false