event bus
This commit is contained in:
parent
93d61ae784
commit
72a03ee064
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"mapserver/colormapping"
|
||||
"mapserver/db"
|
||||
"mapserver/event"
|
||||
"mapserver/mapblockaccessor"
|
||||
"mapserver/mapblockrenderer"
|
||||
"mapserver/mapobjectdb"
|
||||
@ -27,4 +28,5 @@ type App struct {
|
||||
Colormapping *colormapping.ColorMapping
|
||||
Mapblockrenderer *mapblockrenderer.MapBlockRenderer
|
||||
Tilerenderer *tilerenderer.TileRenderer
|
||||
Events event.EventConsumer
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ type WebApiConfig struct {
|
||||
|
||||
type RenderStateType struct {
|
||||
//Initial rendering flag (true=still active)
|
||||
InitialRun bool `json:"initialrun"`
|
||||
LegacyProcessed int `json:"legacyprocessed"`
|
||||
InitialRun bool `json:"initialrun"`
|
||||
LegacyProcessed int `json:"legacyprocessed"`
|
||||
|
||||
//Last initial rendering coords
|
||||
LastX int `json:"lastx"`
|
||||
|
@ -36,5 +36,5 @@ func testCoordConvert(t *testing.T, mb MapBlockCoords) {
|
||||
}
|
||||
|
||||
func TestZeorCoord(t *testing.T) {
|
||||
testCoordConvert(t, NewMapBlockCoords(0,0,0))
|
||||
testCoordConvert(t, NewMapBlockCoords(0, 0, 0))
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"mapserver/coords"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
sqlite extract: https://stackoverflow.com/questions/15448373/how-to-dump-a-file-stored-in-a-sqlite-database-as-a-blob
|
||||
sqlite3 my.db "SELECT writefile('object0.gz', MyBlob) FROM MyTable WHERE id = 1"
|
||||
@ -112,7 +113,7 @@ const countLegacyBlocksQuery = `
|
||||
select count(*) from blocks b where b.mtime = 0
|
||||
`
|
||||
|
||||
func (db *Sqlite3Accessor) CountLegacyBlocks() (int, error){
|
||||
func (db *Sqlite3Accessor) CountLegacyBlocks() (int, error) {
|
||||
rows, err := db.db.Query(countLegacyBlocksQuery)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -96,16 +96,16 @@ func Job(ctx *app.App) {
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
|
||||
progress := int( float64(rstate.LegacyProcessed) / float64(totalLegacyCount) * 100 )
|
||||
progress := int(float64(rstate.LegacyProcessed) / float64(totalLegacyCount) * 100)
|
||||
|
||||
fields = logrus.Fields{
|
||||
"count": len(result.List),
|
||||
"count": len(result.List),
|
||||
"processed": rstate.LegacyProcessed,
|
||||
"progress%": progress,
|
||||
"X": lastcoords.X,
|
||||
"Y": lastcoords.Y,
|
||||
"Z": lastcoords.Z,
|
||||
"elapsed": elapsed,
|
||||
"X": lastcoords.X,
|
||||
"Y": lastcoords.Y,
|
||||
"Z": lastcoords.Z,
|
||||
"elapsed": elapsed,
|
||||
}
|
||||
logrus.WithFields(fields).Info("Initial rendering")
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser.
|
||||
}
|
||||
|
||||
type LegacyMapBlocksResult struct {
|
||||
HasMore bool
|
||||
LastPos *coords.MapBlockCoords
|
||||
List []*mapblockparser.MapBlock
|
||||
HasMore bool
|
||||
LastPos *coords.MapBlockCoords
|
||||
List []*mapblockparser.MapBlock
|
||||
UnfilteredCount int
|
||||
}
|
||||
|
||||
|
@ -107,8 +107,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
||||
txt := scanner.Text()
|
||||
offset += len(txt) + 1
|
||||
|
||||
log.WithFields(logrus.Fields{"txt":txt, "position":position}).Trace("Parsing inventory")
|
||||
|
||||
log.WithFields(logrus.Fields{"txt": txt, "position": position}).Trace("Parsing inventory")
|
||||
|
||||
if strings.HasPrefix(txt, INVENTORY_START) {
|
||||
pairs := strings.Split(txt, " ")
|
||||
|
@ -1,10 +1,10 @@
|
||||
package mapblockparser
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mapserver/coords"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
@ -23,9 +23,9 @@ type MapObject struct {
|
||||
//block position
|
||||
X, Y, Z int
|
||||
|
||||
Type string
|
||||
Data string
|
||||
Mtime int64
|
||||
Type string
|
||||
Data string
|
||||
Mtime int64
|
||||
Attributes map[string]string
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,24 @@
|
||||
package tilerenderer
|
||||
|
||||
|
||||
import (
|
||||
"image"
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"image/color"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
func CreateBlankTile(c color.RGBA) ([]byte){
|
||||
rect := image.Rectangle{
|
||||
image.Point{0, 0},
|
||||
image.Point{IMG_SIZE, IMG_SIZE},
|
||||
}
|
||||
func CreateBlankTile(c color.RGBA) []byte {
|
||||
rect := image.Rectangle{
|
||||
image.Point{0, 0},
|
||||
image.Point{IMG_SIZE, IMG_SIZE},
|
||||
}
|
||||
|
||||
img := image.NewNRGBA(rect)
|
||||
draw.Draw(img, rect, &image.Uniform{c}, image.ZP, draw.Src)
|
||||
img := image.NewNRGBA(rect)
|
||||
draw.Draw(img, rect, &image.Uniform{c}, image.ZP, draw.Src)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
png.Encode(buf, img)
|
||||
buf := new(bytes.Buffer)
|
||||
png.Encode(buf, img)
|
||||
|
||||
return buf.Bytes()
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ func Serve(ctx *app.App) {
|
||||
ws := NewWS(ctx)
|
||||
mux.Handle("/api/ws", ws)
|
||||
|
||||
ctx.Events = ws
|
||||
ctx.Tilerenderer.AddListener(ws)
|
||||
|
||||
if ctx.Config.WebApi.EnableMapblock {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"mapserver/app"
|
||||
"mapserver/coords"
|
||||
"mapserver/tilerenderer"
|
||||
"image/color"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -39,7 +39,7 @@ func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Add("content-type", "image/png")
|
||||
|
||||
if tile == nil {
|
||||
resp.Write(tilerenderer.CreateBlankTile(color.RGBA{0,0,0,0}))
|
||||
resp.Write(tilerenderer.CreateBlankTile(color.RGBA{0, 0, 0, 0}))
|
||||
//TODO: cache/layer color
|
||||
|
||||
} else {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"mapserver/app"
|
||||
"mapserver/coords"
|
||||
@ -8,7 +9,6 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"sync"
|
||||
"bytes"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
@ -50,7 +50,7 @@ func (t *WS) OnRenderedTile(tc *coords.TileCoords) {
|
||||
t.SendJSON("rendered-tile", tc)
|
||||
}
|
||||
|
||||
func (t *WS) SendJSON(eventtype string, o interface{}){
|
||||
func (t *WS) SendJSON(eventtype string, o interface{}) {
|
||||
data, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user