Compare commits
4 commits
next
...
keep-loade
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0f7322a85 | ||
|
|
9b5eda71d6 | ||
|
|
057d02454f | ||
|
|
9f3e879f0e |
5 changed files with 22 additions and 3 deletions
|
|
@ -19,6 +19,7 @@ export class WorldDataEmitter extends EventEmitter {
|
|||
private readonly lastPos: Vec3
|
||||
private eventListeners: Record<string, any> = {}
|
||||
private readonly emitter: WorldDataEmitter
|
||||
keepChunksDistance = 0
|
||||
|
||||
constructor (public world: typeof __type_bot['world'], public viewDistance: number, position: Vec3 = new Vec3(0, 0, 0)) {
|
||||
super()
|
||||
|
|
@ -191,14 +192,14 @@ export class WorldDataEmitter extends EventEmitter {
|
|||
const [botX, botZ] = chunkPos(pos)
|
||||
if (lastX !== botX || lastZ !== botZ || force) {
|
||||
this.emitter.emit('chunkPosUpdate', { pos })
|
||||
const newView = new ViewRect(botX, botZ, this.viewDistance)
|
||||
const newViewToUnload = new ViewRect(botX, botZ, this.viewDistance + this.keepChunksDistance)
|
||||
const chunksToUnload: Vec3[] = []
|
||||
for (const coords of Object.keys(this.loadedChunks)) {
|
||||
const x = parseInt(coords.split(',')[0], 10)
|
||||
const z = parseInt(coords.split(',')[1], 10)
|
||||
const p = new Vec3(x, 0, z)
|
||||
const [chunkX, chunkZ] = chunkPos(p)
|
||||
if (!newView.contains(chunkX, chunkZ)) {
|
||||
if (!newViewToUnload.contains(chunkX, chunkZ)) {
|
||||
chunksToUnload.push(p)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import './reactUi'
|
|||
import { contro, onBotCreate } from './controls'
|
||||
import './dragndrop'
|
||||
import { possiblyCleanHandle, resetStateAfterDisconnect } from './browserfs'
|
||||
import { watchOptionsAfterViewerInit } from './watchOptions'
|
||||
import { watchOptionsAfterViewerInit, watchOptionsAfterWorldViewInit } from './watchOptions'
|
||||
import downloadAndOpenFile from './downloadAndOpenFile'
|
||||
|
||||
import fs from 'fs'
|
||||
|
|
@ -690,6 +690,7 @@ async function connect (connectOptions: ConnectOptions) {
|
|||
const center = bot.entity.position
|
||||
|
||||
const worldView = window.worldView = new WorldDataEmitter(bot.world, renderDistance, center)
|
||||
watchOptionsAfterWorldViewInit()
|
||||
|
||||
bot.on('physicsTick', () => updateCursor())
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ export const guiOptionsScheme: {
|
|||
},
|
||||
starfieldRendering: {},
|
||||
renderEntities: {},
|
||||
keepChunksDistance: {
|
||||
max: 5,
|
||||
unit: '',
|
||||
tooltip: 'Additional distance to keep the chunks loading before unloading them by marking them as too far',
|
||||
},
|
||||
},
|
||||
],
|
||||
main: [
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { omitObj } from '@zardoy/utils'
|
|||
|
||||
const defaultOptions = {
|
||||
renderDistance: 3,
|
||||
keepChunksDistance: 1,
|
||||
multiplayerRenderDistance: 3,
|
||||
closeConfirmation: true,
|
||||
autoFullScreen: false,
|
||||
|
|
|
|||
|
|
@ -63,3 +63,14 @@ export const watchOptionsAfterViewerInit = () => {
|
|||
viewer.world.starField.enabled = o.starfieldRendering
|
||||
})
|
||||
}
|
||||
|
||||
let viewWatched = false
|
||||
export const watchOptionsAfterWorldViewInit = () => {
|
||||
worldView!.keepChunksDistance = options.keepChunksDistance
|
||||
if (viewWatched) return
|
||||
viewWatched = true
|
||||
watchValue(options, o => {
|
||||
if (!worldView) return
|
||||
worldView.keepChunksDistance = o.keepChunksDistance
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue