mapdb stub
This commit is contained in:
parent
49a7de02fc
commit
08407ce0da
@ -7,11 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port int `json:"port"`
|
||||
EnableInitialRendering bool `json:"enableinitialrendering"`
|
||||
EnableIncrementalUpdate bool `json:"enableincrementalupdate"`
|
||||
Webdev bool `json:"webdev"`
|
||||
WebApi WebApiConfig `json:"webapi"`
|
||||
Port int `json:"port"`
|
||||
EnableInitialRendering bool `json:"enableinitialrendering"`
|
||||
EnableIncrementalUpdate bool `json:"enableincrementalupdate"`
|
||||
Webdev bool `json:"webdev"`
|
||||
WebApi WebApiConfig `json:"webapi"`
|
||||
}
|
||||
|
||||
type WebApiConfig struct {
|
||||
@ -24,11 +24,11 @@ func ParseConfig(filename string) (*Config, error) {
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
Port: 8080,
|
||||
EnableInitialRendering: true,
|
||||
Port: 8080,
|
||||
EnableInitialRendering: true,
|
||||
EnableIncrementalUpdate: true,
|
||||
Webdev: false,
|
||||
WebApi: webapi,
|
||||
Webdev: false,
|
||||
WebApi: webapi,
|
||||
}
|
||||
|
||||
info, err := os.Stat(filename)
|
||||
|
4
main.go
4
main.go
@ -2,14 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"mapserver/app"
|
||||
"mapserver/initialrenderer"
|
||||
"mapserver/layerconfig"
|
||||
"mapserver/params"
|
||||
"mapserver/web"
|
||||
"mapserver/tileupdate"
|
||||
"fmt"
|
||||
"mapserver/web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -29,7 +29,7 @@ func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser.
|
||||
a.c.Set(key, mb, cache.DefaultExpiration)
|
||||
}
|
||||
|
||||
func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error){
|
||||
func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error) {
|
||||
blocks, err := a.accessor.FindLatestBlocks(mintime, limit)
|
||||
|
||||
if err != nil {
|
||||
@ -38,7 +38,7 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map
|
||||
|
||||
mblist := make([]*mapblockparser.MapBlock, 0)
|
||||
|
||||
for _, block := range(blocks) {
|
||||
for _, block := range blocks {
|
||||
key := getKey(block.Pos)
|
||||
|
||||
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime)
|
||||
|
@ -6,7 +6,7 @@ type MapBlock struct {
|
||||
Mapdata []byte `json:"mapdata"`
|
||||
Metadata Metadata `json:"metadata"`
|
||||
BlockMapping map[int]string `json:"blockmapping"`
|
||||
Mtime int64 `json:"mtime"`
|
||||
Mtime int64 `json:"mtime"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
|
27
mapdb/accessor.go
Normal file
27
mapdb/accessor.go
Normal file
@ -0,0 +1,27 @@
|
||||
package mapdb
|
||||
|
||||
import (
|
||||
"mapserver/coords"
|
||||
)
|
||||
|
||||
type MapData struct {
|
||||
//mapblock position
|
||||
MBPos coords.MapBlockCoords
|
||||
//block position
|
||||
X, Y, Z int
|
||||
Type string
|
||||
Data string
|
||||
Mtime int64
|
||||
}
|
||||
|
||||
type SearchQuery struct {
|
||||
//block position (not mapblock)
|
||||
Pos1, Pos2 coords.MapBlockCoords
|
||||
Type string
|
||||
}
|
||||
|
||||
type DBAccessor interface {
|
||||
Migrate() error
|
||||
GetMapData(q SearchQuery) ([]MapData, error)
|
||||
SetMapData(pos coords.MapBlockCoords, data []MapData) error
|
||||
}
|
@ -1,38 +1,38 @@
|
||||
package tileupdate
|
||||
|
||||
import (
|
||||
"mapserver/app"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
"github.com/sirupsen/logrus"
|
||||
"mapserver/app"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Job(ctx *app.App){
|
||||
t := time.Now().Unix()
|
||||
func Job(ctx *app.App) {
|
||||
t := time.Now().Unix()
|
||||
|
||||
fields := logrus.Fields{
|
||||
"time": t,
|
||||
}
|
||||
logrus.WithFields(fields).Info("Starting incremental update")
|
||||
fields := logrus.Fields{
|
||||
"time": t,
|
||||
}
|
||||
logrus.WithFields(fields).Info("Starting incremental update")
|
||||
|
||||
for true {
|
||||
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000)
|
||||
for true {
|
||||
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fields = logrus.Fields{
|
||||
"count": len(mblist),
|
||||
"time": t,
|
||||
}
|
||||
logrus.WithFields(fields).Info("incremental update")
|
||||
for _, mb := range mblist {
|
||||
if mb.Mtime > t {
|
||||
t = mb.Mtime + 1
|
||||
}
|
||||
}
|
||||
|
||||
for _, mb := range(mblist) {
|
||||
if mb.Mtime > t {
|
||||
t = mb.Mtime+1
|
||||
}
|
||||
}
|
||||
fields = logrus.Fields{
|
||||
"count": len(mblist),
|
||||
"time": t,
|
||||
}
|
||||
logrus.WithFields(fields).Info("incremental update")
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user