Skip to content

Commit

Permalink
fix: revert smooth fps patch to fix render issues (regression)
Browse files Browse the repository at this point in the history
fix: forcefully cleanup the scene from chunks with f3+a
  • Loading branch information
zardoy committed Nov 23, 2023
1 parent fa68006 commit d2b59f5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
28 changes: 15 additions & 13 deletions prismarine-viewer/viewer/lib/worldrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class WorldRenderer {
lastCamUpdate = 0
droppedFpsPercentage = 0
initialChunksLoad = true
enableChunksLoadDelay = false

texturesVersion?: string

Expand Down Expand Up @@ -66,19 +67,19 @@ export class WorldRenderer {
const chunkCoords = data.key.split(',')
if (!this.loadedChunks[chunkCoords[0] + ',' + chunkCoords[2]] || !data.geometry.positions.length || !this.active) return

if (!this.initialChunksLoad) {
const newPromise = new Promise(resolve => {
if (this.droppedFpsPercentage > 0.5) {
setTimeout(resolve, 1000 / 50 * this.droppedFpsPercentage)
} else {
setTimeout(resolve)
}
})
this.promisesQueue.push(newPromise)
for (const promise of this.promisesQueue) {
await promise
}
}
// if (!this.initialChunksLoad && this.enableChunksLoadDelay) {
// const newPromise = new Promise(resolve => {
// if (this.droppedFpsPercentage > 0.5) {
// setTimeout(resolve, 1000 / 50 * this.droppedFpsPercentage)
// } else {
// setTimeout(resolve)
// }
// })
// this.promisesQueue.push(newPromise)
// for (const promise of this.promisesQueue) {
// await promise
// }
// }

const geometry = new THREE.BufferGeometry()
geometry.setAttribute('position', new THREE.BufferAttribute(data.geometry.positions, 3))
Expand All @@ -95,6 +96,7 @@ export class WorldRenderer {
const boxHelper = new THREE.BoxHelper(mesh, 0xffff00)
boxHelper.name = 'helper'
object.add(boxHelper)
object.name = 'chunk'
if (!this.showChunkBorders) {
boxHelper.visible = false
}
Expand Down
18 changes: 17 additions & 1 deletion src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,17 @@ contro.on('trigger', ({ command }) => {
openPlayerInventory()
break
case 'general.drop':
if (bot.heldItem) bot.tossStack(bot.heldItem)
// if (bot.heldItem/* && ctrl */) bot.tossStack(bot.heldItem)
bot._client.write('block_dig', {
'status': 4,
'location': {
'x': 0,
'z': 0,
'y': 0
},
'face': 0,
sequence: 0
})
break
case 'general.chat':
document.getElementById('hud').shadowRoot.getElementById('chat').enableChat()
Expand Down Expand Up @@ -235,6 +245,12 @@ export const f3Keybinds = [
for (const [x, z] of loadedChunks) {
worldView!.unloadChunk({ x, z })
}
for (const child of viewer.scene.children) {
if (child.name === 'chunk') { // should not happen
viewer.scene.remove(child)
console.warn('forcefully removed chunk from scene')
}
}
if (localServer) {
//@ts-expect-error not sure why it is private... maybe revisit api?
localServer.players[0].world.columns = {}
Expand Down
2 changes: 1 addition & 1 deletion src/react/Singleplayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default ({ worldData, onGeneralAction, onWorldAction }: Props) => {
</div>
<div style={{ display: 'flex', flexDirection: 'column', minWidth: 400 }}>
<div>
<Button ref={firstButton} disabled={!focusedWorld} onClick={() => onWorldAction('load', focusedWorld)}>LOAD WORLD</Button>
<Button rootRef={firstButton} disabled={!focusedWorld} onClick={() => onWorldAction('load', focusedWorld)}>LOAD WORLD</Button>
<Button onClick={() => onGeneralAction('create')}>Create New World</Button>
</div>
<div>
Expand Down

0 comments on commit d2b59f5

Please sign in to comment.