From 65197c2a45606dbc39c582b105a9991462403cb0 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 24 Jan 2019 08:26:28 +0100 Subject: [PATCH] map obj stub --- server/mapobject/poi.go | 15 +++++++++++++++ server/mapobject/setup.go | 2 +- server/mapobjectdb/accessor.go | 19 +++++++++++++++++-- server/mapobjectdb/sqlite_mapobjects.go | 4 ++-- server/mapobjectdb/sqlite_test.go | 2 +- server/mapobjectdb/sqlite_tiles.go | 1 + 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/server/mapobject/poi.go b/server/mapobject/poi.go index 031aeaf..1cb0972 100644 --- a/server/mapobject/poi.go +++ b/server/mapobject/poi.go @@ -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 } diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index 3a221ea..694f636 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -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) } diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index b8846cf..69d6d0b 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -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) diff --git a/server/mapobjectdb/sqlite_mapobjects.go b/server/mapobjectdb/sqlite_mapobjects.go index 99f4407..930d734 100644 --- a/server/mapobjectdb/sqlite_mapobjects.go +++ b/server/mapobjectdb/sqlite_mapobjects.go @@ -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 { diff --git a/server/mapobjectdb/sqlite_test.go b/server/mapobjectdb/sqlite_test.go index 7dcbe3d..d2f2b70 100644 --- a/server/mapobjectdb/sqlite_test.go +++ b/server/mapobjectdb/sqlite_test.go @@ -96,7 +96,7 @@ func TestMapObjects(t *testing.T) { Attributes: attrs, } - err = db.AddMapData(o) + err = db.AddMapData(&o) if err != nil { panic(err) } diff --git a/server/mapobjectdb/sqlite_tiles.go b/server/mapobjectdb/sqlite_tiles.go index 7107c43..b341005 100644 --- a/server/mapobjectdb/sqlite_tiles.go +++ b/server/mapobjectdb/sqlite_tiles.go @@ -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