1
0
forked from MTSR/mapserver
mapserver/server/mapobjectdb/accessor.go

65 lines
1.2 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-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-23 10:37:40 +03:00
MBPos *coords.MapBlockCoords
2019-01-18 17:18:42 +03:00
2019-01-18 15:50:59 +03:00
//block position
X, Y, Z int
2019-01-18 17:10:46 +03:00
2019-01-23 15:13:32 +03:00
Type string
Mtime int64
2019-01-23 10:37:40 +03:00
Attributes map[string]string
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 {
o := MapObject{
2019-01-24 15:55:29 +03:00
MBPos: MBPos,
Type: _type,
X: MBPos.X + x,
Y: MBPos.Y + y,
Z: MBPos.Z + z,
Mtime: time.Now().Unix(),
2019-01-24 10:26:28 +03:00
Attributes: make(map[string]string),
}
return &o
}
2019-01-18 15:50:59 +03:00
type SearchQuery struct {
//block position (not mapblock)
Pos1, Pos2 coords.MapBlockCoords
2019-01-18 17:10:46 +03:00
Type string
2019-01-18 15:50:59 +03:00
}
type DBAccessor interface {
Migrate() error
2019-01-21 17:13:33 +03:00
//Generic map objects (poi, etc)
2019-01-18 17:51:10 +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
//tile data
GetTile(pos *coords.TileCoords) (*Tile, error)
SetTile(tile *Tile) error
RemoveTile(pos *coords.TileCoords) error
2019-01-18 15:50:59 +03:00
}