mapobjects stub

This commit is contained in:
NatureFreshMilk 2019-01-18 15:10:46 +01:00
parent 9f9e50329c
commit 0a702d240c
6 changed files with 61 additions and 14 deletions

View File

@ -26,12 +26,11 @@ func Render(tr *tilerenderer.TileRenderer,
jobs := make(chan coords.TileCoords, 100)
fields := logrus.Fields{
"workers": runtime.NumCPU(),
"workers": runtime.NumCPU(),
}
logrus.WithFields(fields).Info("Starting initial render progress")
for i := 0; i<runtime.NumCPU(); i++ {
for i := 0; i < runtime.NumCPU(); i++ {
go worker(tr, jobs)
}

View File

@ -10,13 +10,13 @@ import (
)
type MapBlockAccessor struct {
accessor db.DBAccessor
c *cache.Cache
accessor db.DBAccessor
c *cache.Cache
listeners []MapBlockListener
}
type MapBlockListener interface {
OnParsedMapBlock(block *mapblockparser.MapBlock)
OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords)
}
func getKey(pos coords.MapBlockCoords) string {
@ -55,8 +55,8 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map
return nil, err
}
for _, listener := range(a.listeners) {
listener.OnParsedMapBlock(mapblock)
for _, listener := range a.listeners {
listener.OnParsedMapBlock(mapblock, block.Pos)
}
a.c.Set(key, mapblock, cache.DefaultExpiration)
@ -88,8 +88,8 @@ func (a *MapBlockAccessor) GetMapBlock(pos coords.MapBlockCoords) (*mapblockpars
return nil, err
}
for _, listener := range(a.listeners) {
listener.OnParsedMapBlock(mapblock)
for _, listener := range a.listeners {
listener.OnParsedMapBlock(mapblock, pos)
}
a.c.Set(key, mapblock, cache.DefaultExpiration)

View File

@ -6,9 +6,11 @@ import (
type MapData struct {
//mapblock position
MBPos coords.MapBlockCoords
MBPos coords.MapBlockCoords
//block position
X, Y, Z int
Type string
Data string
Mtime int64
@ -17,11 +19,12 @@ type MapData struct {
type SearchQuery struct {
//block position (not mapblock)
Pos1, Pos2 coords.MapBlockCoords
Type string
Type string
}
type DBAccessor interface {
Migrate() error
GetMapData(q SearchQuery) ([]MapData, error)
SetMapData(pos coords.MapBlockCoords, data []MapData) error
RemoveMapData(pos coords.MapBlockCoords) error
AddMapData(data MapData) error
}

18
mapobject/clearmapdata.go Normal file
View File

@ -0,0 +1,18 @@
package mapobject
import (
"mapserver/coords"
"mapserver/mapblockparser"
"mapserver/mapdb"
)
type ClearMapData struct {
db mapdb.DBAccessor
}
func (this *ClearMapData) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) {
err := this.db.RemoveMapData(pos)
if err != nil {
panic(err)
}
}

27
mapobject/poi.go Normal file
View File

@ -0,0 +1,27 @@
package mapobject
import (
"mapserver/coords"
"mapserver/mapblockparser"
"mapserver/mapdb"
)
type POI struct {
db mapdb.DBAccessor
}
func (this *POI) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) {
var found bool
for _, v := range(block.BlockMapping) {
if v == "mapserver:poi" {
found = true
break
}
}
if !found {
return
}
panic("OK") //XXX
}

View File

@ -7,7 +7,7 @@ import (
type ParamsType struct {
Help bool
Version bool
Debug bool
Debug bool
Dumpconfig bool
}