mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-06-19 17:27:41 +02:00
👷 preparing benchmark, moving output to main & headless mode
This commit is contained in:
parent
69b946b85c
commit
0bc0d3a980
@ -81,6 +81,10 @@ module.exports = class Renderer
|
|||||||
labelBuffer: null
|
labelBuffer: null
|
||||||
tileSource: null
|
tileSource: null
|
||||||
|
|
||||||
|
terminal:
|
||||||
|
CLEAR: "\x1B[2J"
|
||||||
|
MOVE: "\x1B[?6h"
|
||||||
|
|
||||||
constructor: (@output, @tileSource) ->
|
constructor: (@output, @tileSource) ->
|
||||||
@labelBuffer = new LabelBuffer()
|
@labelBuffer = new LabelBuffer()
|
||||||
|
|
||||||
@ -94,8 +98,6 @@ module.exports = class Renderer
|
|||||||
return Promise.reject() if @isDrawing
|
return Promise.reject() if @isDrawing
|
||||||
@isDrawing = true
|
@isDrawing = true
|
||||||
|
|
||||||
@notify "rendering..."
|
|
||||||
|
|
||||||
@labelBuffer.clear()
|
@labelBuffer.clear()
|
||||||
|
|
||||||
if color = @styler.styleById['background']?.paint['background-color']
|
if color = @styler.styleById['background']?.paint['background-color']
|
||||||
@ -110,15 +112,17 @@ module.exports = class Renderer
|
|||||||
.map (tile) => @_getTile tile
|
.map (tile) => @_getTile tile
|
||||||
.map (tile) => @_getTileFeatures tile
|
.map (tile) => @_getTileFeatures tile
|
||||||
.then (tiles) => @_renderTiles tiles
|
.then (tiles) => @_renderTiles tiles
|
||||||
.then => @_writeFrame()
|
.then => @_getFrame()
|
||||||
|
|
||||||
.catch (e) ->
|
.catch (e) ->
|
||||||
console.log e
|
console.log e
|
||||||
|
|
||||||
.finally =>
|
.finally (frame) =>
|
||||||
@isDrawing = false
|
@isDrawing = false
|
||||||
@lastDrawAt = Date.now()
|
@lastDrawAt = Date.now()
|
||||||
|
|
||||||
|
frame
|
||||||
|
|
||||||
_visibleTiles: (center, zoom) ->
|
_visibleTiles: (center, zoom) ->
|
||||||
z = Math.min @config.maxZoom, Math.max 0, Math.floor zoom
|
z = Math.min @config.maxZoom, Math.max 0, Math.floor zoom
|
||||||
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
|
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
|
||||||
@ -192,7 +196,6 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
for layer in @config.drawOrder
|
for layer in @config.drawOrder
|
||||||
short = layer.split(":")[0]
|
short = layer.split(":")[0]
|
||||||
@notify "rendering #{layer}.."
|
|
||||||
|
|
||||||
for tile in tiles
|
for tile in tiles
|
||||||
continue unless tile.features[layer]?.length
|
continue unless tile.features[layer]?.length
|
||||||
@ -208,12 +211,12 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
@canvas.restore()
|
@canvas.restore()
|
||||||
|
|
||||||
_writeFrame: ->
|
_getFrame: ->
|
||||||
unless @lastDrawAt
|
frame = ""
|
||||||
@_clearScreen()
|
frame += @terminal.CLEAR unless @lastDrawAt
|
||||||
|
frame += @terminal.MOVE
|
||||||
@output.write "\x1B[?6h"
|
frame += @canvas.frame()
|
||||||
@output.write @canvas.frame()
|
frame
|
||||||
|
|
||||||
featuresAt: (x, y) ->
|
featuresAt: (x, y) ->
|
||||||
@labelBuffer.featuresAt x, y
|
@labelBuffer.featuresAt x, y
|
||||||
@ -224,12 +227,6 @@ module.exports = class Renderer
|
|||||||
[tiles.maxX, tiles.maxY] = utils.ll2tile bbox[2], bbox[3], Math.floor zoom
|
[tiles.maxX, tiles.maxY] = utils.ll2tile bbox[2], bbox[3], Math.floor zoom
|
||||||
tiles
|
tiles
|
||||||
|
|
||||||
_clearScreen: ->
|
|
||||||
@output.write "\x1B[2J"
|
|
||||||
|
|
||||||
_write: (output) ->
|
|
||||||
@output.write output
|
|
||||||
|
|
||||||
_scaleAtZoom: (zoom) ->
|
_scaleAtZoom: (zoom) ->
|
||||||
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
||||||
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)
|
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)
|
||||||
@ -296,7 +293,3 @@ module.exports = class Renderer
|
|||||||
scaled.push [x, y]
|
scaled.push [x, y]
|
||||||
|
|
||||||
scaled
|
scaled
|
||||||
|
|
||||||
|
|
||||||
notify: (text) ->
|
|
||||||
@_write "\r\x1B[K"+text
|
|
||||||
|
@ -21,15 +21,20 @@ module.exports = class Termap
|
|||||||
source: "http://nachbar.io/data/osm2vectortiles/"
|
source: "http://nachbar.io/data/osm2vectortiles/"
|
||||||
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
||||||
styleFile: __dirname+"/../styles/bright.json"
|
styleFile: __dirname+"/../styles/bright.json"
|
||||||
|
|
||||||
zoomStep: 0.2
|
zoomStep: 0.2
|
||||||
|
maxZoom: 18
|
||||||
|
|
||||||
|
headless: false
|
||||||
|
|
||||||
width: null
|
width: null
|
||||||
height: null
|
height: null
|
||||||
canvas: null
|
canvas: null
|
||||||
mouse: null
|
mouse: null
|
||||||
|
|
||||||
mousePosition: [0, 0]
|
|
||||||
mouseDragging: false
|
mouseDragging: false
|
||||||
|
mousePosition:
|
||||||
|
x: 0, y: 0
|
||||||
|
|
||||||
tileSource: null
|
tileSource: null
|
||||||
renderer: null
|
renderer: null
|
||||||
@ -37,18 +42,13 @@ module.exports = class Termap
|
|||||||
zoom: 0
|
zoom: 0
|
||||||
rotation: 0
|
rotation: 0
|
||||||
center:
|
center:
|
||||||
# sf
|
# sf lat: 37.787946, lon: -122.407522
|
||||||
# lat: 37.787946
|
# iceland lat: 64.124229, lon: -21.811552
|
||||||
# lon: -122.407522
|
|
||||||
# iceland
|
|
||||||
# lat: 64.124229
|
|
||||||
# lon: -21.811552
|
|
||||||
# rgbg
|
# rgbg
|
||||||
lat: 49.0189
|
lat: 49.0189
|
||||||
lon: 12.0990
|
lon: 12.0990
|
||||||
|
|
||||||
minZoom: null
|
minZoom: null
|
||||||
maxZoom: 18
|
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
@config[key] = val for key, val of options
|
@config[key] = val for key, val of options
|
||||||
@ -57,6 +57,7 @@ module.exports = class Termap
|
|||||||
Promise
|
Promise
|
||||||
.resolve()
|
.resolve()
|
||||||
.then =>
|
.then =>
|
||||||
|
unless @config.headless
|
||||||
@_initKeyboard()
|
@_initKeyboard()
|
||||||
@_initMouse()
|
@_initMouse()
|
||||||
|
|
||||||
@ -99,8 +100,12 @@ module.exports = class Termap
|
|||||||
@zoom = @minZoom
|
@zoom = @minZoom
|
||||||
|
|
||||||
_resizeRenderer: (cb) ->
|
_resizeRenderer: (cb) ->
|
||||||
|
unless @config.headless
|
||||||
@width = @config.output.columns >> 1 << 2
|
@width = @config.output.columns >> 1 << 2
|
||||||
@height = @config.output.rows * 4 - 4
|
@height = @config.output.rows * 4 - 4
|
||||||
|
else
|
||||||
|
@width = 256
|
||||||
|
@height = 152
|
||||||
|
|
||||||
@minZoom = 4-Math.log(4096/@width)/Math.LN2
|
@minZoom = 4-Math.log(4096/@width)/Math.LN2
|
||||||
|
|
||||||
@ -139,8 +144,7 @@ module.exports = class Termap
|
|||||||
|
|
||||||
# update internal mouse tracker
|
# update internal mouse tracker
|
||||||
@mousePosition = x: event.x, y: event.y
|
@mousePosition = x: event.x, y: event.y
|
||||||
@renderer.notify @_getFooter()
|
@notify @_getFooter()
|
||||||
|
|
||||||
|
|
||||||
_onKey: (key) ->
|
_onKey: (key) ->
|
||||||
# check if the pressed key is configured
|
# check if the pressed key is configured
|
||||||
@ -166,15 +170,16 @@ module.exports = class Termap
|
|||||||
@_draw()
|
@_draw()
|
||||||
else
|
else
|
||||||
# display debug info for unhandled keys
|
# display debug info for unhandled keys
|
||||||
@renderer.notify JSON.stringify key
|
@notify JSON.stringify key
|
||||||
|
|
||||||
_draw: ->
|
_draw: ->
|
||||||
@renderer
|
@renderer
|
||||||
.draw @center, @zoom, @rotation
|
.draw @center, @zoom, @rotation
|
||||||
.then =>
|
.then (frame) =>
|
||||||
@renderer.notify @_getFooter()
|
@_write frame
|
||||||
|
@notify @_getFooter()
|
||||||
.catch =>
|
.catch =>
|
||||||
@renderer.notify "renderer is busy"
|
@notify "renderer is busy"
|
||||||
|
|
||||||
_getFooter: ->
|
_getFooter: ->
|
||||||
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
||||||
@ -184,7 +189,7 @@ module.exports = class Termap
|
|||||||
# type: f.feature.properties.type
|
# type: f.feature.properties.type
|
||||||
# rank: f.feature.properties.scalerank
|
# rank: f.feature.properties.scalerank
|
||||||
# ).join(", ")+"] "+
|
# ).join(", ")+"] "+
|
||||||
# "#{@mousePosition.x} #{@mousePosition.y}"
|
"#{@mousePosition.x} #{@mousePosition.y} " +
|
||||||
#"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}]}"
|
#"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}]}"
|
||||||
# bbox = @_getBBox()
|
# bbox = @_getBBox()
|
||||||
# tiles = @_tilesInBBox(bbox)
|
# tiles = @_tilesInBBox(bbox)
|
||||||
@ -195,9 +200,15 @@ module.exports = class Termap
|
|||||||
|
|
||||||
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
||||||
|
|
||||||
|
notify: (text) ->
|
||||||
|
@_write "\r\x1B[K"+text
|
||||||
|
|
||||||
|
_write: (output) ->
|
||||||
|
@config.output.write output
|
||||||
|
|
||||||
zoomBy: (step) ->
|
zoomBy: (step) ->
|
||||||
return @zoom = @minZoom if @zoom+step < @minZoom
|
return @zoom = @minZoom if @zoom+step < @minZoom
|
||||||
return @zoom = @maxZoom if @zoom+step > @maxZoom
|
return @zoom = @config.maxZoom if @zoom+step > @config.maxZoom
|
||||||
|
|
||||||
@zoom += step
|
@zoom += step
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user