Loading src/tiling.ts +12 −10 Changes for src/tiling.ts: 12 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -171,7 +171,7 @@ export class TileTree implements TextureSource { abort: AbortSignal, ) => Promise<DataPair<ImageBitmap>>; private _activeTiles = new Set<Tile>(); private loadingTextures = new Array<Promise<TexturePair>>(); private loadingTextures = new Array<Promise<TexturePair | null>>(); private _unloadArea!: Rect; private _loadArea!: Rect; private _targetLevel: number; Loading Loading @@ -244,9 +244,8 @@ export class TileTree implements TextureSource { async updateTiles(dezoom: number, area: Rect, now: boolean): Promise<void> { const nextUpdate = this.lastUpdate + TileTree.DEBOUNCE_MS - Date.now(); if (!now && this.debounceUpdate || nextUpdate > 0) { if (!this.debounceUpdate) setTimeout(() => this.debounceUpdate && this.debounceUpdate(), nextUpdate); if (!now && (this.debounceUpdate || nextUpdate > 0)) { if (!this.debounceUpdate) setTimeout(() => this.debounceUpdate && this.debounceUpdate(), nextUpdate); this.debounceUpdate = () => this.updateTiles(dezoom, area, true); return; } else { Loading @@ -256,7 +255,7 @@ export class TileTree implements TextureSource { this._targetLevel = dezoom; this.loadArea = area; this.root.update(); console.debug( console.log( `Updating tree with dezoom:`, dezoom, `activeTiles:`, Loading @@ -272,16 +271,19 @@ export class TileTree implements TextureSource { } } async loadTile(tile: Tile): Promise<TexturePair> { async loadTile(tile: Tile): Promise<TexturePair | null> { if (!(tile.texture instanceof AbortController)) throw new Error('loadTile: tile.texture should be an AbortController'); console.debug(`Loading tile ${tile}`); const tex = this.loadTileFunc(this.zoomDepth - tile.dezoomLevel, tile.x, tile.y, tile.texture.signal).then( ({ albedo, normals }) => ({ const tex = this.loadTileFunc(this.zoomDepth - tile.dezoomLevel, tile.x, tile.y, tile.texture.signal) .then(({ albedo, normals }) => ({ albedo: loadTexture(this.gl, albedo), normals: loadTexture(this.gl, normals), }), ); })) .catch((e) => { if (e instanceof DOMException && e.name === 'AbortError') return null; else throw e; }); this.loadingTextures.push(tex); return tex.finally(() => { this.loadingTextures.splice(this.loadingTextures.indexOf(tex), 1); Loading Loading
src/tiling.ts +12 −10 Changes for src/tiling.ts: 12 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -171,7 +171,7 @@ export class TileTree implements TextureSource { abort: AbortSignal, ) => Promise<DataPair<ImageBitmap>>; private _activeTiles = new Set<Tile>(); private loadingTextures = new Array<Promise<TexturePair>>(); private loadingTextures = new Array<Promise<TexturePair | null>>(); private _unloadArea!: Rect; private _loadArea!: Rect; private _targetLevel: number; Loading Loading @@ -244,9 +244,8 @@ export class TileTree implements TextureSource { async updateTiles(dezoom: number, area: Rect, now: boolean): Promise<void> { const nextUpdate = this.lastUpdate + TileTree.DEBOUNCE_MS - Date.now(); if (!now && this.debounceUpdate || nextUpdate > 0) { if (!this.debounceUpdate) setTimeout(() => this.debounceUpdate && this.debounceUpdate(), nextUpdate); if (!now && (this.debounceUpdate || nextUpdate > 0)) { if (!this.debounceUpdate) setTimeout(() => this.debounceUpdate && this.debounceUpdate(), nextUpdate); this.debounceUpdate = () => this.updateTiles(dezoom, area, true); return; } else { Loading @@ -256,7 +255,7 @@ export class TileTree implements TextureSource { this._targetLevel = dezoom; this.loadArea = area; this.root.update(); console.debug( console.log( `Updating tree with dezoom:`, dezoom, `activeTiles:`, Loading @@ -272,16 +271,19 @@ export class TileTree implements TextureSource { } } async loadTile(tile: Tile): Promise<TexturePair> { async loadTile(tile: Tile): Promise<TexturePair | null> { if (!(tile.texture instanceof AbortController)) throw new Error('loadTile: tile.texture should be an AbortController'); console.debug(`Loading tile ${tile}`); const tex = this.loadTileFunc(this.zoomDepth - tile.dezoomLevel, tile.x, tile.y, tile.texture.signal).then( ({ albedo, normals }) => ({ const tex = this.loadTileFunc(this.zoomDepth - tile.dezoomLevel, tile.x, tile.y, tile.texture.signal) .then(({ albedo, normals }) => ({ albedo: loadTexture(this.gl, albedo), normals: loadTexture(this.gl, normals), }), ); })) .catch((e) => { if (e instanceof DOMException && e.name === 'AbortError') return null; else throw e; }); this.loadingTextures.push(tex); return tex.finally(() => { this.loadingTextures.splice(this.loadingTextures.indexOf(tex), 1); Loading