perf and update fixes
This commit is contained in:
parent
a5a281cc21
commit
438ca52211
@ -37,7 +37,7 @@ var RealtimeTileLayer = L.TileLayer.extend({
|
|||||||
|
|
||||||
createTile: function(coords){
|
createTile: function(coords){
|
||||||
var tile = document.createElement('img');
|
var tile = document.createElement('img');
|
||||||
tile.src = this.getTileSource(coords.x, coords.y, coords.z);
|
tile.src = this.getTileSource(coords.x, coords.y, coords.z, true);
|
||||||
tile.id = this.getImageId(coords.x, coords.y, coords.z);
|
tile.id = this.getImageId(coords.x, coords.y, coords.z);
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
@ -44,63 +44,48 @@ const (
|
|||||||
IMG_SIZE = 256
|
IMG_SIZE = 256
|
||||||
)
|
)
|
||||||
|
|
||||||
func (tr *TileRenderer) Render(tc *coords.TileCoords, recursionDepth int) ([]byte, error) {
|
func (tr *TileRenderer) Render(tc *coords.TileCoords) ([]byte, error) {
|
||||||
|
//No tile in db
|
||||||
|
img, data, err := tr.RenderImage(tc, 2)
|
||||||
|
|
||||||
//Check cache
|
|
||||||
tile, err := tr.tdb.GetTile(tc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tile == nil {
|
if img == nil {
|
||||||
|
//empty tile
|
||||||
if recursionDepth == 0 {
|
return nil, nil
|
||||||
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Skip image")
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//No tile in db
|
|
||||||
img, data, err := tr.RenderImage(tc, recursionDepth)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if img == nil {
|
|
||||||
//empty tile
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tile.Data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (*image.NRGBA, []byte, error) {
|
func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (*image.NRGBA, []byte, error) {
|
||||||
|
|
||||||
cachedtile, err := tr.tdb.GetTile(tc)
|
if recursionDepth < 2 {
|
||||||
if err != nil {
|
cachedtile, err := tr.tdb.GetTile(tc)
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if cachedtile != nil {
|
|
||||||
reader := bytes.NewReader(cachedtile.Data)
|
|
||||||
cachedimg, err := png.Decode(reader)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rect := image.Rectangle{
|
if cachedtile != nil {
|
||||||
image.Point{0, 0},
|
reader := bytes.NewReader(cachedtile.Data)
|
||||||
image.Point{IMG_SIZE, IMG_SIZE},
|
cachedimg, err := png.Decode(reader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rect := image.Rectangle{
|
||||||
|
image.Point{0, 0},
|
||||||
|
image.Point{IMG_SIZE, IMG_SIZE},
|
||||||
|
}
|
||||||
|
|
||||||
|
img := image.NewNRGBA(rect)
|
||||||
|
draw.Draw(img, rect, cachedimg, image.ZP, draw.Src)
|
||||||
|
|
||||||
|
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Cached image")
|
||||||
|
return img, cachedtile.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
img := image.NewNRGBA(rect)
|
|
||||||
draw.Draw(img, rect, cachedimg, image.ZP, draw.Src)
|
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Cached image")
|
|
||||||
return img, cachedtile.Data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if recursionDepth == 0 {
|
if recursionDepth == 0 {
|
||||||
|
@ -7,11 +7,8 @@ import (
|
|||||||
|
|
||||||
func worker(ctx *app.App, coords <-chan *coords.TileCoords) {
|
func worker(ctx *app.App, coords <-chan *coords.TileCoords) {
|
||||||
for tc := range coords {
|
for tc := range coords {
|
||||||
//remove tile
|
|
||||||
ctx.Objectdb.RemoveTile(tc)
|
|
||||||
|
|
||||||
//render tile
|
//render tile
|
||||||
_, err := ctx.Tilerenderer.Render(tc, 5)
|
_, err := ctx.Tilerenderer.Render(tc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"mapserver/vfs"
|
"mapserver/vfs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Serve(ctx *app.App) {
|
func Serve(ctx *app.App) {
|
||||||
@ -18,7 +19,10 @@ func Serve(ctx *app.App) {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||||
mux.Handle("/api/tile/", &Tiles{ctx: ctx})
|
|
||||||
|
tiles := &Tiles{ctx: ctx}
|
||||||
|
tiles.Init()
|
||||||
|
mux.Handle("/api/tile/", tiles)
|
||||||
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
|
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
|
||||||
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
||||||
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
||||||
|
@ -11,7 +11,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Tiles struct {
|
type Tiles struct {
|
||||||
ctx *app.App
|
ctx *app.App
|
||||||
|
blank []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tiles) Init() {
|
||||||
|
t.blank = tilerenderer.CreateBlankTile(color.RGBA{255, 255, 255, 255})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
@ -40,7 +45,7 @@ func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
|||||||
resp.Header().Add("content-type", "image/png")
|
resp.Header().Add("content-type", "image/png")
|
||||||
|
|
||||||
if tile == nil {
|
if tile == nil {
|
||||||
resp.Write(tilerenderer.CreateBlankTile(color.RGBA{255, 255, 255, 255}))
|
resp.Write(t.blank)
|
||||||
//TODO: cache/layer color
|
//TODO: cache/layer color
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user