Skip to content

Commit

Permalink
limit data updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Dec 5, 2024
1 parent 3da0e68 commit 36daed9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions prismarine-viewer/examples/chunksStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class ChunksStorage {
chunksMap = new Map<string, number>()
// flatBuffer = new Uint32Array()

maxDataUpdate = 10_000
awaitingUpdateStart: number | undefined
awaitingUpdateEnd: number | undefined
// dataSize = 0
Expand Down Expand Up @@ -38,9 +39,14 @@ export class ChunksStorage {
this.lastFetchedSize = this.dataSize
if (this.awaitingUpdateStart === undefined) return
const { awaitingUpdateStart } = this
const awaitingUpdateEnd = this.awaitingUpdateEnd!
this.awaitingUpdateStart = undefined
this.awaitingUpdateEnd = undefined
let awaitingUpdateEnd = this.awaitingUpdateEnd!
if (awaitingUpdateEnd - awaitingUpdateStart > this.maxDataUpdate) {
this.awaitingUpdateStart = awaitingUpdateStart + this.maxDataUpdate
awaitingUpdateEnd = awaitingUpdateStart + this.maxDataUpdate
} else {
this.awaitingUpdateStart = undefined
this.awaitingUpdateEnd = undefined
}
return {
allBlocks: this.allBlocks,
chunks: this.chunks,
Expand Down Expand Up @@ -103,7 +109,7 @@ export class ChunksStorage {
removeChunk (chunkPosKey: string) {
if (!this.chunksMap.has(chunkPosKey)) return
let currentStart = 0
let chunkIndex = this.chunksMap.get(chunkPosKey)!
const chunkIndex = this.chunksMap.get(chunkPosKey)!
const chunk = this.chunks[chunkIndex]
for (let i = 0; i < chunkIndex; i++) {
const chunk = this.chunks[i]!
Expand Down

0 comments on commit 36daed9

Please sign in to comment.