2019-01-10 19:50:31 +03:00
|
|
|
package mapblockaccessor
|
|
|
|
|
|
|
|
import (
|
2019-01-13 18:37:03 +03:00
|
|
|
"fmt"
|
2019-01-10 19:50:31 +03:00
|
|
|
"mapserver/coords"
|
|
|
|
"mapserver/db"
|
2019-01-28 15:31:48 +03:00
|
|
|
"mapserver/eventbus"
|
2019-01-21 18:27:31 +03:00
|
|
|
"mapserver/mapblockparser"
|
2019-01-28 15:31:48 +03:00
|
|
|
|
2019-01-11 11:07:31 +03:00
|
|
|
"time"
|
2019-01-19 18:44:46 +03:00
|
|
|
|
|
|
|
cache "github.com/patrickmn/go-cache"
|
2019-01-10 19:50:31 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type MapBlockAccessor struct {
|
2019-01-28 15:31:48 +03:00
|
|
|
accessor db.DBAccessor
|
|
|
|
c *cache.Cache
|
|
|
|
Eventbus *eventbus.Eventbus
|
2019-01-11 11:07:31 +03:00
|
|
|
}
|
|
|
|
|
2019-02-06 10:38:08 +03:00
|
|
|
func getKey(pos *coords.MapBlockCoords) string {
|
2019-01-11 11:07:31 +03:00
|
|
|
return fmt.Sprintf("Coord %d/%d/%d", pos.X, pos.Y, pos.Z)
|
2019-01-10 19:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMapBlockAccessor(accessor db.DBAccessor) *MapBlockAccessor {
|
2019-01-22 15:17:30 +03:00
|
|
|
c := cache.New(500*time.Millisecond, 1000*time.Millisecond)
|
2019-01-11 11:07:31 +03:00
|
|
|
|
2019-01-28 15:31:48 +03:00
|
|
|
return &MapBlockAccessor{
|
|
|
|
accessor: accessor,
|
|
|
|
c: c,
|
|
|
|
Eventbus: eventbus.New(),
|
|
|
|
}
|
2019-01-18 16:43:34 +03:00
|
|
|
}
|
2019-01-10 19:50:31 +03:00
|
|
|
|
2019-01-24 09:24:28 +03:00
|
|
|
type FindMapBlocksResult struct {
|
2019-01-23 15:13:32 +03:00
|
|
|
HasMore bool
|
|
|
|
LastPos *coords.MapBlockCoords
|
2019-01-24 09:52:25 +03:00
|
|
|
LastMtime int64
|
2019-01-23 15:13:32 +03:00
|
|
|
List []*mapblockparser.MapBlock
|
2019-01-23 14:46:45 +03:00
|
|
|
UnfilteredCount int
|
|
|
|
}
|