improve fps in some scenarios by not spamming with setTimeout calls
This commit is contained in:
parent
4fd607c17c
commit
c7a8c34d89
6 changed files with 16 additions and 11 deletions
|
|
@ -128,7 +128,7 @@ setInterval(() => {
|
|||
//@ts-ignore
|
||||
postMessage({ type: 'geometry', key, geometry }, transferable)
|
||||
} else {
|
||||
console.info('[mesher] Missing section', x, y, z)
|
||||
// console.info('[mesher] Missing section', x, y, z)
|
||||
}
|
||||
const dirtyTimes = dirtySections.get(key)
|
||||
if (!dirtyTimes) throw new Error('dirtySections.get(key) is falsy')
|
||||
|
|
|
|||
|
|
@ -623,7 +623,7 @@ export function getSectionGeometry (sx, sy, sz, world: World) {
|
|||
delete attr.t_colors
|
||||
delete attr.t_uvs
|
||||
|
||||
attr.positions = new Int8Array(attr.positions) as any
|
||||
attr.positions = new Float32Array(attr.positions) as any
|
||||
attr.normals = new Uint8ClampedArray(attr.normals) as any
|
||||
attr.colors = new Float32Array(attr.colors) as any
|
||||
attr.uvs = new Float32Array(attr.uvs) as any
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ export class ViewerWrapper {
|
|||
renderIntervalUnfocused: number | undefined
|
||||
fpsInterval
|
||||
|
||||
constructor(public canvas: HTMLCanvasElement, public renderer?: THREE.WebGLRenderer) {
|
||||
constructor (public canvas: HTMLCanvasElement, public renderer?: THREE.WebGLRenderer) {
|
||||
if (this.renderer) this.globalObject.renderer = this.renderer
|
||||
}
|
||||
addToPage (startRendering = true) {
|
||||
if (this.addedToPage) throw new Error('Already added to page')
|
||||
|
|
@ -30,7 +31,6 @@ export class ViewerWrapper {
|
|||
this.canvas.id = 'viewer-canvas'
|
||||
document.body.appendChild(this.canvas)
|
||||
|
||||
if (this.renderer) this.globalObject.renderer = this.renderer
|
||||
this.addedToPage = true
|
||||
|
||||
let max = 0
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class WorldDataEmitter extends EventEmitter {
|
|||
private eventListeners: Record<string, any> = {};
|
||||
private emitter: WorldDataEmitter
|
||||
|
||||
constructor(public world: import('prismarine-world').world.World | typeof __type_bot['world'], public viewDistance: number, position: Vec3 = new Vec3(0, 0, 0)) {
|
||||
constructor (public world: typeof __type_bot['world'], public viewDistance: number, position: Vec3 = new Vec3(0, 0, 0)) {
|
||||
super()
|
||||
this.loadedChunks = {}
|
||||
this.lastPos = new Vec3(0, 0, 0).update(position)
|
||||
|
|
@ -123,10 +123,15 @@ export class WorldDataEmitter extends EventEmitter {
|
|||
}
|
||||
|
||||
async _loadChunks (positions: Vec3[], sliceSize = 5, waitTime = 0) {
|
||||
for (let i = 0; i < positions.length; i += sliceSize) {
|
||||
await new Promise((resolve) => setTimeout(resolve, waitTime))
|
||||
await Promise.all(positions.slice(i, i + sliceSize).map((p) => this.loadChunk(p)))
|
||||
}
|
||||
let i = 0
|
||||
const interval = setInterval(() => {
|
||||
if (i >= positions.length) {
|
||||
clearInterval(interval)
|
||||
return
|
||||
}
|
||||
this.loadChunk(positions[i])
|
||||
i++
|
||||
}, 1)
|
||||
}
|
||||
|
||||
readdDebug () {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ const plugins = [
|
|||
})
|
||||
|
||||
const removeNodeModulesSourcemaps = (map) => {
|
||||
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft']
|
||||
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft', 'three']
|
||||
map.sourcesContent.forEach((_, i) => {
|
||||
if (map.sources[i].includes('node_modules') && !doNotRemove.some(x => map.sources[i].includes(x))) {
|
||||
map.sourcesContent[i] = null
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ body {
|
|||
background: rgba(0, 0, 0, 0.3) !important;
|
||||
opacity: 0.7 !important;
|
||||
position: fixed !important;
|
||||
bottom: 60px;
|
||||
bottom: 60px !important;
|
||||
}
|
||||
|
||||
.dirt-bg {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue