mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-22 08:03:07 +01:00
⚡ only keep 16 tiles in memory
This commit is contained in:
parent
0e5ce02e79
commit
3dffcde3b5
@ -25,6 +25,9 @@ catch
|
|||||||
|
|
||||||
module.exports = class TileSource
|
module.exports = class TileSource
|
||||||
cache: {}
|
cache: {}
|
||||||
|
cacheSize: 16
|
||||||
|
cached: []
|
||||||
|
|
||||||
modes:
|
modes:
|
||||||
MBTiles: 1
|
MBTiles: 1
|
||||||
VectorTile: 2
|
VectorTile: 2
|
||||||
@ -67,6 +70,10 @@ module.exports = class TileSource
|
|||||||
if cached = @cache[[z,x,y].join("-")]
|
if cached = @cache[[z,x,y].join("-")]
|
||||||
return Promise.resolve cached
|
return Promise.resolve cached
|
||||||
|
|
||||||
|
if @cached.length > @cacheSize
|
||||||
|
for tile in @cached.splice 0, Math.abs(@cacheSize-@cached.length)
|
||||||
|
delete @cache[tile]
|
||||||
|
|
||||||
switch @mode
|
switch @mode
|
||||||
when @modes.MBTiles then @_getMBTile z, x, y
|
when @modes.MBTiles then @_getMBTile z, x, y
|
||||||
when @modes.HTTP then @_getHTTP z, x, y
|
when @modes.HTTP then @_getHTTP z, x, y
|
||||||
@ -93,7 +100,10 @@ module.exports = class TileSource
|
|||||||
resolve @_createTile z, x, y, buffer
|
resolve @_createTile z, x, y, buffer
|
||||||
|
|
||||||
_createTile: (z, x, y, buffer) ->
|
_createTile: (z, x, y, buffer) ->
|
||||||
tile = @cache[[z,x,y].join("-")] = new Tile @styler
|
name = [z,x,y].join("-")
|
||||||
|
@cached.push name
|
||||||
|
|
||||||
|
tile = @cache[name] = new Tile @styler
|
||||||
tile.load buffer
|
tile.load buffer
|
||||||
|
|
||||||
_initPersistence: ->
|
_initPersistence: ->
|
||||||
|
Loading…
Reference in New Issue
Block a user