map obj stub

This commit is contained in:
NatureFreshMilk 2019-01-24 08:26:28 +01:00
parent 641cea560e
commit 65197c2a45
6 changed files with 37 additions and 6 deletions

View File

@ -6,5 +6,20 @@ import (
)
func onPoiBlock(id int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
for x:=0; x<16; x++ {
for y:=0; y<16; y++ {
for z:=0; z<16; z++ {
name := block.GetNodeName(x,y,z)
if name == "mapserver:poi" {
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "poi")
o.Attributes["name"] = "test"
odb.AddMapData(o)
}
}
}
}
panic("OK") //XXX
}

View File

@ -10,7 +10,7 @@ type Listener struct {
}
func (this *Listener) OnParsedMapBlock(block *mapblockparser.MapBlock) {
err := this.ctx.Objectdb.RemoveMapData(block.Pos)
err := this.ctx.Objectdb.RemoveMapData(&block.Pos)
if err != nil {
panic(err)
}

View File

@ -2,6 +2,7 @@ package mapobjectdb
import (
"mapserver/coords"
"time"
)
/*
@ -28,6 +29,20 @@ type MapObject struct {
Attributes map[string]string
}
func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject {
o := MapObject{
MBPos: MBPos,
Type: _type,
X: x,
Y: y,
Z: z,
Mtime: time.Now().Unix(),
Attributes: make(map[string]string),
}
return &o
}
type SearchQuery struct {
//block position (not mapblock)
Pos1, Pos2 coords.MapBlockCoords
@ -39,8 +54,8 @@ type DBAccessor interface {
//Generic map objects (poi, etc)
GetMapData(q SearchQuery) ([]MapObject, error)
RemoveMapData(pos coords.MapBlockCoords) error
AddMapData(data MapObject) error
RemoveMapData(pos *coords.MapBlockCoords) error
AddMapData(data *MapObject) error
//tile data
GetTile(pos *coords.TileCoords) (*Tile, error)

View File

@ -12,7 +12,7 @@ const removeMapDataQuery = `
delete from objects where posx = ? and posy = ? and posz = ?
`
func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error {
func (db *Sqlite3Accessor) RemoveMapData(pos *coords.MapBlockCoords) error {
_, err := db.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z)
return err
}
@ -29,7 +29,7 @@ object_attributes(objectid, key, value)
values(?, ?, ?)
`
func (db *Sqlite3Accessor) AddMapData(data MapObject) error {
func (db *Sqlite3Accessor) AddMapData(data *MapObject) error {
tx, err := db.db.Begin()
if err != nil {

View File

@ -96,7 +96,7 @@ func TestMapObjects(t *testing.T) {
Attributes: attrs,
}
err = db.AddMapData(o)
err = db.AddMapData(&o)
if err != nil {
panic(err)
}

View File

@ -68,6 +68,7 @@ func (db *Sqlite3Accessor) RemoveTile(pos *coords.TileCoords) error {
}
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {
//TODO: flag/config for unsafe db access
db, err := sql.Open("sqlite3", filename+"?_timeout=500&_journal_mode=MEMORY&_synchronous=OFF")
if err != nil {
return nil, err