Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo: emulate culling & effective updates #152

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions prismarine-viewer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>

abstract outputFormat: 'threeJs' | 'webgl'

constructor(public config: WorldRendererConfig) {
constructor (public config: WorldRendererConfig) {
// this.initWorkers(1) // preload script on page load
this.snapshotInitialValues()
}
Expand Down Expand Up @@ -221,6 +221,28 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>

}

getHighestTerrainBlock (x, z) {
//@ts-ignore
const chunk: import('prismarine-chunk').PCChunk = bot.world.getColumn(x / 16, z / 16)
let y_res = [] as number[]
const computeBlock = (x, z) => {
for (let y = this.worldConfig.worldHeight - 1; y >= this.worldConfig.minY; y--) {
const block = chunk.getBlock(new Vec3(x, y, z))
const ignoreBlocks = ['air', /* 'water', 'lava', */'log', 'leaves', 'tallgrass', 'deadbush', 'waterlily', 'reeds', 'vine', 'lilypad', 'nether_wart', 'fire', 'magma', 'portal', 'end_portal', 'end_portal_frame', 'end_gateway', 'end_rod', 'chorus_flower', 'chorus_plant', 'beetroots', 'carrots', 'potatoes', 'wheat', 'cactus', 'sugar_cane', 'deadbush', 'grass', 'fern', 'tallgrass', 'seagrass', 'tall_seagrass', 'kelp', 'short_grass']
if (!ignoreBlocks.includes(block.name)) {
y_res.push(y)
break
}
}
}
computeBlock(x, z)
computeBlock(x + 16, z)
computeBlock(x, z + 16)
computeBlock(x + 16, z + 16)
// console.log('y_res', y_res)
return y_res
}

addColumn (x: number, z: number, chunk: any, isLightUpdate: boolean) {
if (!this.active) return
if (this.workers.length === 0) throw new Error('workers not initialized yet')
Expand All @@ -230,14 +252,15 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
// todo optimize
worker.postMessage({ type: 'chunk', x, z, chunk })
}
for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) {
const highestTerrainBlock = this.getHighestTerrainBlock(x, z)
for (const y of highestTerrainBlock) {
const loc = new Vec3(x, y, z)
this.setSectionDirty(loc)
if (!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))
this.setSectionDirty(loc.offset(0, 0, 16))
// this.setSectionDirty(loc.offset(-16, 0, 0))
// this.setSectionDirty(loc.offset(16, 0, 0))
// this.setSectionDirty(loc.offset(0, 0, -16))
// this.setSectionDirty(loc.offset(0, 0, 16))
}
}
}
Expand Down
Loading