Skip to content

Commit

Permalink
add a way to to disable neighbor chunk updates and all the UI (needed…
Browse files Browse the repository at this point in the history
… for perf testing)
  • Loading branch information
zardoy committed Sep 7, 2024
1 parent a301063 commit 1c7fdc2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
17 changes: 10 additions & 7 deletions prismarine-viewer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
x: number
z: number
}
neighborChunkUpdates = true

abstract outputFormat: 'threeJs' | 'webgpu'

Expand Down Expand Up @@ -321,7 +322,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
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))
Expand Down Expand Up @@ -357,12 +358,14 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
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
Expand Down
7 changes: 4 additions & 3 deletions src/optionsGuiScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -429,15 +430,15 @@ const Category = ({ children }) => <div style={{
const UiToggleButton = ({ name, addUiText = false, label = noCase(name) }) => {
const { disabledUiParts } = useSnapshot(options)

const currentlyEnabled = disabledUiParts.includes(name)
const currentlyDisabled = disabledUiParts.includes(name)
if (addUiText) label = `${label} UI`
return <Button
inScreen
onClick={() => {
const newDisabledUiParts = currentlyEnabled ? disabledUiParts.filter(x => x !== name) : [...disabledUiParts, name]
const newDisabledUiParts = currentlyDisabled ? disabledUiParts.filter(x => x !== name) : [...disabledUiParts, name]
options.disabledUiParts = newDisabledUiParts
}}
>{currentlyEnabled ? 'Disable' : 'Enable'} {label}</Button>
>{currentlyDisabled ? 'Enable' : 'Disable'} {label}</Button>
}

export const tryFindOptionConfig = (option: keyof AppOptions) => {
Expand Down
1 change: 1 addition & 0 deletions src/optionsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/reactUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <>
<RobustPortal to={document.querySelector('#ui-root')}>
Expand Down
4 changes: 4 additions & 0 deletions src/watchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c7fdc2

Please sign in to comment.