👷 preparing benchmark, moving output to main & headless mode

pull/7/head
Michael Straßburger 2016-11-05 17:45:25 +01:00
rodzic 69b946b85c
commit 0bc0d3a980
2 zmienionych plików z 45 dodań i 41 usunięć

Wyświetl plik

@ -81,6 +81,10 @@ module.exports = class Renderer
labelBuffer: null
tileSource: null
terminal:
CLEAR: "\x1B[2J"
MOVE: "\x1B[?6h"
constructor: (@output, @tileSource) ->
@labelBuffer = new LabelBuffer()
@ -94,8 +98,6 @@ module.exports = class Renderer
return Promise.reject() if @isDrawing
@isDrawing = true
@notify "rendering..."
@labelBuffer.clear()
if color = @styler.styleById['background']?.paint['background-color']
@ -110,15 +112,17 @@ module.exports = class Renderer
.map (tile) => @_getTile tile
.map (tile) => @_getTileFeatures tile
.then (tiles) => @_renderTiles tiles
.then => @_writeFrame()
.then => @_getFrame()
.catch (e) ->
console.log e
.finally =>
.finally (frame) =>
@isDrawing = false
@lastDrawAt = Date.now()
frame
_visibleTiles: (center, zoom) ->
z = Math.min @config.maxZoom, Math.max 0, Math.floor zoom
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
@ -192,7 +196,6 @@ module.exports = class Renderer
for layer in @config.drawOrder
short = layer.split(":")[0]
@notify "rendering #{layer}.."
for tile in tiles
continue unless tile.features[layer]?.length
@ -208,12 +211,12 @@ module.exports = class Renderer
@canvas.restore()
_writeFrame: ->
unless @lastDrawAt
@_clearScreen()
@output.write "\x1B[?6h"
@output.write @canvas.frame()
_getFrame: ->
frame = ""
frame += @terminal.CLEAR unless @lastDrawAt
frame += @terminal.MOVE
frame += @canvas.frame()
frame
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
_clearScreen: ->
@output.write "\x1B[2J"
_write: (output) ->
@output.write output
_scaleAtZoom: (zoom) ->
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)
@ -296,7 +293,3 @@ module.exports = class Renderer
scaled.push [x, y]
scaled
notify: (text) ->
@_write "\r\x1B[K"+text

Wyświetl plik

@ -21,15 +21,20 @@ module.exports = class Termap
source: "http://nachbar.io/data/osm2vectortiles/"
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
styleFile: __dirname+"/../styles/bright.json"
zoomStep: 0.2
maxZoom: 18
headless: false
width: null
height: null
canvas: null
mouse: null
mousePosition: [0, 0]
mouseDragging: false
mousePosition:
x: 0, y: 0
tileSource: null
renderer: null
@ -37,18 +42,13 @@ module.exports = class Termap
zoom: 0
rotation: 0
center:
# sf
# lat: 37.787946
# lon: -122.407522
# iceland
# lat: 64.124229
# lon: -21.811552
# sf lat: 37.787946, lon: -122.407522
# iceland lat: 64.124229, lon: -21.811552
# rgbg
lat: 49.0189
lon: 12.0990
minZoom: null
maxZoom: 18
constructor: (options) ->
@config[key] = val for key, val of options
@ -57,8 +57,9 @@ module.exports = class Termap
Promise
.resolve()
.then =>
@_initKeyboard()
@_initMouse()
unless @config.headless
@_initKeyboard()
@_initMouse()
@_initTileSource()
@ -99,8 +100,12 @@ module.exports = class Termap
@zoom = @minZoom
_resizeRenderer: (cb) ->
@width = @config.output.columns >> 1 << 2
@height = @config.output.rows * 4 - 4
unless @config.headless
@width = @config.output.columns >> 1 << 2
@height = @config.output.rows * 4 - 4
else
@width = 256
@height = 152
@minZoom = 4-Math.log(4096/@width)/Math.LN2
@ -139,8 +144,7 @@ module.exports = class Termap
# update internal mouse tracker
@mousePosition = x: event.x, y: event.y
@renderer.notify @_getFooter()
@notify @_getFooter()
_onKey: (key) ->
# check if the pressed key is configured
@ -166,15 +170,16 @@ module.exports = class Termap
@_draw()
else
# display debug info for unhandled keys
@renderer.notify JSON.stringify key
@notify JSON.stringify key
_draw: ->
@renderer
.draw @center, @zoom, @rotation
.then =>
@renderer.notify @_getFooter()
.then (frame) =>
@_write frame
@notify @_getFooter()
.catch =>
@renderer.notify "renderer is busy"
@notify "renderer is busy"
_getFooter: ->
# 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
# rank: f.feature.properties.scalerank
# ).join(", ")+"] "+
# "#{@mousePosition.x} #{@mousePosition.y}"
"#{@mousePosition.x} #{@mousePosition.y} " +
#"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}]}"
# bbox = @_getBBox()
# tiles = @_tilesInBBox(bbox)
@ -195,9 +200,15 @@ module.exports = class Termap
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
notify: (text) ->
@_write "\r\x1B[K"+text
_write: (output) ->
@config.output.write output
zoomBy: (step) ->
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