func ConvertToMap(m *Mapping) map[string]interface{}
ConvertToMap converts a mapping struct instance to a map for transport via mesh
Entity represents an entity in mapping with its own position (x and y)
type Entity struct {
ID string
Value interface{}
X int64
Y int64
Distance int64
}
type Mapping struct {
sync.RWMutex
// contains filtered or unexported fields
}
func ConvertFromMap(m map[string]interface{}) *Mapping
ConvertFromMap converts a mapping map to a struct instance of mapping.
func New(fieldOfVisionSize int64) *Mapping
New creates a new mapping struct instance.
The parameter represents the field of vision of each members.
func (m *Mapping) Add(id string, x int64, y int64, val interface{})
Add adds or updates the Entity and its position (x and y)
[NOTE] Uses mutex lock internally.
func (m *Mapping) AddAndFind(id string, x int64, y int64, val interface{}, limit int) []*Entity
AddAndFind combines Add() and Find() together
[NOTE] Uses mutex lock internally.
func (m *Mapping) Find(finderID string, x int64, y int64, limit int) []*Entity
Find returns an array of Entities in the view area - finderID will be excluded from the results
limit - Controls the maximum number of remote entities to synchronize with.
[NOTE] Uses mutex lock internally.
func (m *Mapping) OnRemoved(callback func(*Entity))
OnRemoved registers a callback: The event is triggered by Remove
func (m *Mapping) Remove(id string) (string, *Entity)
Remove removes the Entity that matches id and returns the removed posKey
[NOTE] Uses mutex lock internally.