Fixed minor problems.

This commit is contained in:
Uwe Oestermeier 2019-06-03 08:55:33 +02:00
parent 304818dc13
commit 0c46c4e656

View File

@ -2,7 +2,7 @@
const registeredTiles = new Map()
const pendingTiles = new Map()
/** Implements a baseTexture cache. The last textures are kept for reuse */
const keepTextures = 0
let keepTextures = 0
const keptTextures = []
/** The current Tile implementation simply uses PIXI.Sprites.
@ -56,6 +56,13 @@ export default class Tile extends PIXI.Sprite {
return pendingTiles.has(url) && pendingTiles.get(url) > 0
}
static isObsolete(url) {
if (registeredTiles.has(url) && registeredTiles.get(url) > 0) {
return false
}
return true
}
/**
* Removes the given url from pending urls.
*
@ -121,6 +128,7 @@ export default class Tile extends PIXI.Sprite {
tiles.delete(this)
if (tiles.size == 0) {
registeredTiles.delete(this.url)
return 0
}
return tiles.size
}
@ -143,8 +151,7 @@ export default class Tile extends PIXI.Sprite {
while(keptTextures.length > keepTextures) {
let {url, texture} = keptTextures.shift()
let tiles = registeredTiles.get(url)
if (tiles.size > 0 && !Tile.isPending(url)) {
if (Tile.isObsolete(url)) {
texture.destroy(true) // Destroy base as well
if (debug) console.log("Destroying texture and baseTexture", url)
}