...

Package mapping

import "github.com/Diarkis/diarkis/room/mapping"
Overview
Index

Overview ▾

Package mapping ▷

Room Mapping - MMO Style Mapping For Room

Allows the room members to "see" each other based on positions (x, y).

[IMPORTANT]: There is a known edge case with position value calculation with negative values. If x and/or y are negative, it they will not be considered within the field of vision with positive values.

func ConvertToMap

func ConvertToMap(m *Mapping) map[string]interface{}

ConvertToMap converts a mapping struct instance to a map for transport via mesh

type Entity

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

type Mapping struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func ConvertFromMap

func ConvertFromMap(m map[string]interface{}) *Mapping

ConvertFromMap converts a mapping map to a struct instance of mapping.

func New

func New(fieldOfVisionSize int64) *Mapping

New creates a new mapping struct instance.

The parameter represents the field of vision of each members.

func (*Mapping) Add

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 (*Mapping) AddAndFind

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 (*Mapping) Find

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 (*Mapping) OnRemoved

func (m *Mapping) OnRemoved(callback func(*Entity))

OnRemoved registers a callback: The event is triggered by Remove

func (*Mapping) 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.