Improved handling of textures that arrive too late.
This commit is contained in:
parent
54a1e74e27
commit
beca78d7a7
@ -34,6 +34,7 @@ export default class Logging {
|
||||
*/
|
||||
static warn(message) {
|
||||
if (!logMessages.has(message)) {
|
||||
logMessages.add(message)
|
||||
if (ipc) {
|
||||
ipc.send('warn', message)
|
||||
} else {
|
||||
@ -49,6 +50,7 @@ export default class Logging {
|
||||
*/
|
||||
static error(message) {
|
||||
if (!logMessages.has(message)) {
|
||||
logMessages.add(message)
|
||||
if (ipc) {
|
||||
ipc.send('error', message)
|
||||
} else {
|
||||
|
@ -2,10 +2,10 @@
|
||||
/* globals PIXI, console*/
|
||||
|
||||
const registeredTiles = new Map()
|
||||
// const pendingTiles = new Map()
|
||||
/** Implements a baseTexture cache. The last textures are kept for reuse */
|
||||
let keepTextures = 0
|
||||
const keptTextures = []
|
||||
const lateTextures = new Map()
|
||||
|
||||
/** The current Tile implementation simply uses PIXI.Sprites.
|
||||
*
|
||||
@ -30,43 +30,6 @@ export default class Tile extends PIXI.Sprite {
|
||||
keepTextures = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the given url as pending. Pending tiles should not be destroyed
|
||||
*
|
||||
* @static
|
||||
* @param {*} url
|
||||
* @memberof Tile
|
||||
*/
|
||||
/* static schedule(url) {
|
||||
let count = 0
|
||||
if (pendingTiles.has(url)) {
|
||||
count = pendingTiles.get(url)
|
||||
}
|
||||
pendingTiles.set(url, count + 1)
|
||||
// console.log("Tile.scheduled", url, pendingTiles.size)
|
||||
} */
|
||||
|
||||
/**
|
||||
* Removes the given url from pending urls.
|
||||
*
|
||||
* @static
|
||||
* @param {*} url
|
||||
* @memberof Tile
|
||||
*/
|
||||
/* static unschedule(url) {
|
||||
if (pendingTiles.has(url)) {
|
||||
let count = pendingTiles.get(url)
|
||||
if (count > 1) {
|
||||
pendingTiles.set(url, count - 1)
|
||||
}
|
||||
else {
|
||||
pendingTiles.clear(url)
|
||||
}
|
||||
}
|
||||
// console.log("Tile.unscheduled", url, pendingTiles.size)
|
||||
} */
|
||||
|
||||
|
||||
/**
|
||||
* Returns true iff the url is pending
|
||||
*
|
||||
@ -214,15 +177,44 @@ export default class Tile extends PIXI.Sprite {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes lately arrived texture if they have not been touched in the meanwhile.
|
||||
*
|
||||
* @static
|
||||
* @memberof Tile
|
||||
*/
|
||||
static sweepLateTextures() {
|
||||
let now = performance.now()
|
||||
if (now > lastSweepTime + sweepInterval) {
|
||||
lastSweepTime = now
|
||||
let count = 0
|
||||
for (let [url, texture] of lateTextures.entries()) {
|
||||
if (texture) {
|
||||
let base = texture.baseTexture
|
||||
if (base != null && base.touched == 0) {
|
||||
texture.destroy(true)
|
||||
//console.info("Sweeping ", url)
|
||||
count += 1
|
||||
lateTextures.delete(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0)
|
||||
console.log("Sweeping textures", count)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Texture received too late. We do not need it.
|
||||
* @param {*} url
|
||||
* @param {*} texture
|
||||
*/
|
||||
static lateTexture(url, texture) {
|
||||
let destroyBase = Tile.isObsolete(url)
|
||||
console.log("Tile.lateTexture", destroyBase)
|
||||
texture.destroy(destroyBase)
|
||||
lateTextures.set(url, texture)
|
||||
//console.warn("Tile.lateTexture")
|
||||
// We cannot destroy the texture since we got errors in t.renderWebGL.
|
||||
// Perhaps we can destroy unsed textures later on
|
||||
Tile.sweepLateTextures()
|
||||
}
|
||||
|
||||
static printInfos() {
|
||||
|
Loading…
Reference in New Issue
Block a user