mapserver/mapobjectdb/accessor.go

86 lines
1.8 KiB
Go
Raw Normal View History

2019-01-18 17:51:10 +03:00
package mapobjectdb
2019-01-18 15:50:59 +03:00
import (
"mapserver/coords"
2019-01-24 10:26:28 +03:00
"time"
2019-02-06 20:28:24 +03:00
"github.com/sirupsen/logrus"
2019-01-18 15:50:59 +03:00
)
2019-01-23 10:20:27 +03:00
/*
sqlite perf: https://stackoverflow.com/questions/1711631/improve-insert-per-second-performance-of-sqlite?rq=1
PRAGMA synchronous = OFF
PRAGMA journal_mode = MEMORY
*/
2019-01-21 17:13:33 +03:00
type Tile struct {
Pos *coords.TileCoords
Data []byte
Mtime int64
}
2019-01-18 17:51:10 +03:00
type MapObject struct {
2019-01-18 15:50:59 +03:00
//mapblock position
2019-01-25 13:18:35 +03:00
MBPos *coords.MapBlockCoords `json:"mapblock"`
2019-01-18 17:18:42 +03:00
2019-01-18 15:50:59 +03:00
//block position
2019-01-25 13:02:36 +03:00
X int `json:"x"`
Y int `json:"y"`
Z int `json:"z"`
2019-01-18 17:10:46 +03:00
2019-01-25 13:18:35 +03:00
Type string `json:"type"`
Mtime int64 `json:"mtime"`
2019-01-25 13:02:36 +03:00
Attributes map[string]string `json:"attributes"`
2019-01-18 15:50:59 +03:00
}
2019-01-24 10:26:28 +03:00
func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject {
2019-02-05 23:17:14 +03:00
2019-02-06 20:28:24 +03:00
fields := logrus.Fields{
"mbpos": MBPos,
"x": x,
"y": y,
"z": z,
"type": _type,
2019-02-05 23:17:14 +03:00
}
2019-02-06 20:28:24 +03:00
log.WithFields(fields).Debug("NewMapObject")
2019-02-05 23:17:14 +03:00
2019-01-24 10:26:28 +03:00
o := MapObject{
2019-01-24 15:55:29 +03:00
MBPos: MBPos,
Type: _type,
2019-02-05 23:17:14 +03:00
X: (MBPos.X * 16) + x,
Y: (MBPos.Y * 16) + y,
Z: (MBPos.Z * 16) + z,
2019-01-24 15:55:29 +03:00
Mtime: time.Now().Unix(),
2019-01-24 10:26:28 +03:00
Attributes: make(map[string]string),
}
return &o
}
type SearchAttributeLike struct {
Key string `json:"key"`
Value string `json:"value"`
}
2019-01-18 15:50:59 +03:00
type SearchQuery struct {
2019-01-25 12:39:17 +03:00
//mapblock position
Pos1 *coords.MapBlockCoords `json:"pos1"`
Pos2 *coords.MapBlockCoords `json:"pos2"`
Type string `json:"type"`
AttributeLike *SearchAttributeLike `json:"attributelike"`
2019-01-18 15:50:59 +03:00
}
type DBAccessor interface {
2019-01-29 20:00:00 +03:00
//migrates the database
2019-01-18 15:50:59 +03:00
Migrate() error
2019-01-21 17:13:33 +03:00
//Generic map objects (poi, etc)
2019-02-22 20:30:38 +03:00
GetMapData(q *SearchQuery) ([]*MapObject, error)
2019-01-24 10:26:28 +03:00
RemoveMapData(pos *coords.MapBlockCoords) error
AddMapData(data *MapObject) error
2019-01-21 17:13:33 +03:00
2019-02-07 10:21:19 +03:00
//Settings
GetSetting(key string, defaultvalue string) (string, error)
SetSetting(key string, value string) error
2019-01-18 15:50:59 +03:00
}