entity

package
v0.0.0-...-fae5011 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2017 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SPACE_ENTITY_TYPE   = "__space__"
	SPACE_KIND_ATTR_KEY = "_K"

	DEFAULT_AOI_DISTANCE = 100
)
View Source
const (
	RF_SERVER       = 1 << iota
	RF_OWN_CLIENT   = 1 << iota
	RF_OTHER_CLIENT = 1 << iota
)

Variables

This section is empty.

Functions

func CreateEntityAnywhere

func CreateEntityAnywhere(typeName string)

func CreateEntityLocally

func CreateEntityLocally(typeName string, data map[string]interface{}, client *GameClient) EntityID

func CreateSpaceAnywhere

func CreateSpaceAnywhere(kind int)

func CreateSpaceLocally

func CreateSpaceLocally(kind int) EntityID

func LoadEntityAnywhere

func LoadEntityAnywhere(typeName string, entityID EntityID)

func LoadEntityLocally

func LoadEntityLocally(typeName string, entityID EntityID)

func OnCall

func OnCall(id EntityID, method string, args [][]byte, clientID ClientID)

func OnClientDisconnected

func OnClientDisconnected(clientid ClientID)

func OnDeclareService

func OnDeclareService(serviceName string, entityid EntityID)

func OnGameTerminating

func OnGameTerminating()

func OnGateDisconnected

func OnGateDisconnected(gateid uint16)

func OnMigrateRequestAck

func OnMigrateRequestAck(entityID EntityID, spaceID EntityID, spaceLoc uint16)

func OnRealMigrate

func OnRealMigrate(entityID EntityID, spaceID EntityID, x, y, z float32, typeName string,
	migrateData map[string]interface{}, timerData []byte,
	clientid ClientID, clientsrv uint16)

func OnUndeclareService

func OnUndeclareService(serviceName string, entityid EntityID)

func OnUpdatePositionYawFromClient

func OnUpdatePositionYawFromClient(eid EntityID, x, y, z Coord, yaw Yaw, clientid ClientID)

func RegisterSpace

func RegisterSpace(spacePtr ISpace)

func RestoreFreezedEntities

func RestoreFreezedEntities(freeze *FreezeData) (err error)

func SaveAllEntities

func SaveAllEntities()

func SetSaveInterval

func SetSaveInterval(duration time.Duration)

Types

type AOI

type AOI struct {
	// contains filtered or unexported fields
}

type AOICalculator

type AOICalculator interface {
	Enter(aoi *AOI, pos Position)
	Leave(aoi *AOI)
	Move(aoi *AOI, newPos Position)
	Interested(aoi *AOI) AOISet
}

type AOISet

type AOISet map[*AOI]struct{}

func (AOISet) Add

func (aoiset AOISet) Add(aoi *AOI)

func (AOISet) Contains

func (aoiset AOISet) Contains(aoi *AOI) bool

func (AOISet) Del

func (aoiset AOISet) Del(aoi *AOI)

func (AOISet) Join

func (aoiset AOISet) Join(other AOISet) AOISet

type Coord

type Coord float32

type Entity

type Entity struct {
	ID       EntityID
	TypeName string
	I        IEntity
	IV       reflect.Value

	Space *Space

	Attrs *MapAttr
	// contains filtered or unexported fields
}

func GetEntity

func GetEntity(id EntityID) *Entity

func (*Entity) AddCallback

func (e *Entity) AddCallback(d time.Duration, method string, args ...interface{}) EntityTimerID

func (*Entity) AddTimer

func (e *Entity) AddTimer(d time.Duration, method string, args ...interface{}) EntityTimerID

func (*Entity) Call

func (e *Entity) Call(id EntityID, method string, args ...interface{})

Call other entities

func (*Entity) CallClient

func (e *Entity) CallClient(method string, args ...interface{})

func (*Entity) CallFitleredClients

func (e *Entity) CallFitleredClients(key string, val string, method string, args ...interface{})

Call the filtered clients with prop key = value The message is broadcast to filtered clientproxies directly without going through entities

func (*Entity) CallService

func (e *Entity) CallService(serviceName string, method string, args ...interface{})

func (*Entity) CancelTimer

func (e *Entity) CancelTimer(tid EntityTimerID)

func (*Entity) DeclareService

func (e *Entity) DeclareService(serviceName string)

Register for global service

func (*Entity) Destroy

func (e *Entity) Destroy()

func (*Entity) EnterSpace

func (e *Entity) EnterSpace(spaceID EntityID, pos Position)

Enter target space

func (*Entity) ForAllClients

func (e *Entity) ForAllClients(f func(client *GameClient))

func (*Entity) GetClient

func (e *Entity) GetClient() *GameClient

Get client

func (*Entity) GetFloat

func (e *Entity) GetFloat(key string) float64

func (*Entity) GetFreezeData

func (e *Entity) GetFreezeData() *entityFreezeData

func (*Entity) GetInt

func (e *Entity) GetInt(key string) int

Fast access to attrs

func (*Entity) GetListAttr

func (e *Entity) GetListAttr(key string) *ListAttr

func (*Entity) GetMapAttr

func (e *Entity) GetMapAttr(key string) *MapAttr

func (*Entity) GetMigrateData

func (e *Entity) GetMigrateData() map[string]interface{}

func (*Entity) GetPersistentData

func (e *Entity) GetPersistentData() map[string]interface{}

Get the persistent data

Returns persistent attributes by default

func (*Entity) GetPosition

func (e *Entity) GetPosition() Position

func (*Entity) GetStr

func (e *Entity) GetStr(key string) string

func (*Entity) GetYaw

func (e *Entity) GetYaw() Yaw

func (*Entity) GiveClientTo

func (e *Entity) GiveClientTo(other *Entity)

func (*Entity) IsDestroyed

func (e *Entity) IsDestroyed() bool

func (*Entity) IsPersistent

func (e *Entity) IsPersistent() bool

Return if the entity is persistent

Default implementation check entity for persistent attributes

func (*Entity) IsSpaceEntity

func (e *Entity) IsSpaceEntity() bool

func (*Entity) LoadMigrateData

func (e *Entity) LoadMigrateData(data map[string]interface{})

func (*Entity) LoadPersistentData

func (e *Entity) LoadPersistentData(data map[string]interface{})

Load persistent data

Load persistent data to attributes

func (*Entity) Neighbors

func (e *Entity) Neighbors() EntitySet

func (*Entity) OnBecomePlayer

func (e *Entity) OnBecomePlayer()

func (*Entity) OnClientConnected

func (e *Entity) OnClientConnected()

func (*Entity) OnClientDisconnected

func (e *Entity) OnClientDisconnected()

func (*Entity) OnCreated

func (e *Entity) OnCreated()

func (*Entity) OnDestroy

func (e *Entity) OnDestroy()

func (*Entity) OnEnterSpace

func (e *Entity) OnEnterSpace()

Space Utilities

func (*Entity) OnInit

func (e *Entity) OnInit()

Default Handlers

func (*Entity) OnLeaveSpace

func (e *Entity) OnLeaveSpace(space *Space)

func (*Entity) OnMigrateIn

func (e *Entity) OnMigrateIn()

func (*Entity) OnMigrateOut

func (e *Entity) OnMigrateOut()

func (*Entity) OnRestored

func (e *Entity) OnRestored()

func (*Entity) PanicOnError

func (e *Entity) PanicOnError(err error)

Some Other Useful Utilities

func (*Entity) Post

func (e *Entity) Post(cb func())

Post a function which will be executed immediately but not in the current stack frames

func (*Entity) Save

func (e *Entity) Save()

func (*Entity) SetClient

func (e *Entity) SetClient(client *GameClient)

func (*Entity) SetFilterProp

func (e *Entity) SetFilterProp(key string, val string)

func (*Entity) SetPosition

func (e *Entity) SetPosition(pos Position)

func (*Entity) SetYaw

func (e *Entity) SetYaw(yaw Yaw)

func (*Entity) String

func (e *Entity) String() string

func (*Entity) ToSpace

func (e *Entity) ToSpace() *Space

Convert entity to space (only works for space entity)

type EntityIDSet

type EntityIDSet map[EntityID]struct{}

func GetServiceProviders

func GetServiceProviders(serviceName string) EntityIDSet

func (EntityIDSet) Add

func (es EntityIDSet) Add(id EntityID)

func (EntityIDSet) Contains

func (es EntityIDSet) Contains(id EntityID) bool

func (EntityIDSet) Del

func (es EntityIDSet) Del(id EntityID)

func (EntityIDSet) ToList

func (es EntityIDSet) ToList() []EntityID

type EntityManager

type EntityManager struct {
	// contains filtered or unexported fields
}

type EntityMap

type EntityMap map[EntityID]*Entity

func (EntityMap) Add

func (em EntityMap) Add(entity *Entity)

func (EntityMap) Del

func (em EntityMap) Del(id EntityID)

func (EntityMap) Get

func (em EntityMap) Get(id EntityID) *Entity

type EntitySet

type EntitySet map[*Entity]struct{}

func (EntitySet) Add

func (es EntitySet) Add(entity *Entity)

func (EntitySet) Contains

func (es EntitySet) Contains(entity *Entity) bool

func (EntitySet) Del

func (es EntitySet) Del(entity *Entity)

func (EntitySet) String

func (es EntitySet) String() string

type EntityTimerID

type EntityTimerID int

Timer & Callback Management

func (EntityTimerID) IsValid

func (tid EntityTimerID) IsValid() bool

type EntityTypeDesc

type EntityTypeDesc struct {
	// contains filtered or unexported fields
}

func RegisterEntity

func RegisterEntity(typeName string, entityPtr IEntity) *EntityTypeDesc

func (*EntityTypeDesc) DefineAttrs

func (desc *EntityTypeDesc) DefineAttrs(attrDefs map[string][]string)

type FreezeData

type FreezeData struct {
	Entities map[EntityID]*entityFreezeData
	Services map[string][]EntityID
}

func Freeze

func Freeze(gameid uint16) (*FreezeData, error)

type GameClient

type GameClient struct {
	// contains filtered or unexported fields
}

func MakeGameClient

func MakeGameClient(clientid common.ClientID, gid uint16) *GameClient

func (*GameClient) SendCreateEntity

func (client *GameClient) SendCreateEntity(entity *Entity, isPlayer bool)

func (*GameClient) SendDestroyEntity

func (client *GameClient) SendDestroyEntity(entity *Entity)

func (*GameClient) SendNotifyListAttrAppend

func (client *GameClient) SendNotifyListAttrAppend(entityID common.EntityID, path []interface{}, val interface{})

func (*GameClient) SendNotifyListAttrChange

func (client *GameClient) SendNotifyListAttrChange(entityID common.EntityID, path []interface{}, index uint32, val interface{})

func (*GameClient) SendNotifyListAttrPop

func (client *GameClient) SendNotifyListAttrPop(entityID common.EntityID, path []interface{})

func (*GameClient) SendNotifyMapAttrChange

func (client *GameClient) SendNotifyMapAttrChange(entityID common.EntityID, path []interface{}, key string, val interface{})

func (*GameClient) SendNotifyMapAttrDel

func (client *GameClient) SendNotifyMapAttrDel(entityID common.EntityID, path []interface{}, key string)

func (*GameClient) String

func (client *GameClient) String() string

func (*GameClient) UpdatePositionOnClient

func (client *GameClient) UpdatePositionOnClient(entityID common.EntityID, position Position)

func (*GameClient) UpdateYawOnClient

func (client *GameClient) UpdateYawOnClient(entityID common.EntityID, yaw Yaw)

type IEntity

type IEntity interface {
	// Entity Lifetime
	OnInit()    // Called when initializing entity struct, override to initialize entity custom fields
	OnCreated() // Called when entity is just created
	OnDestroy() // Called when entity is destroying (just before destroy)
	// Migration
	OnMigrateOut() // Called just before entity is migrating out
	OnMigrateIn()  // Called just after entity is migrating in
	// Freeze && Restore
	OnRestored() // Called when entity is restored
	// Space Operations
	OnEnterSpace()             // Called when entity leaves space
	OnLeaveSpace(space *Space) // Called when entity enters space
	// Storage: Save & Load
	IsPersistent() bool                             // Return whether entity is persistent, override to return true for persistent entity
	GetPersistentData() map[string]interface{}      // Convert persistent entity attributes to persistent data for storage, can override to customize entity saving
	LoadPersistentData(data map[string]interface{}) // Initialize entity attributes with persistetn data, can override to customize entity loading
	GetMigrateData() map[string]interface{}         // Convert entity attributes for migrating to other servers, can override to customize data migrating
	LoadMigrateData(data map[string]interface{})    // Initialize attributes with migrating data, can override to customize data migrating
	// Client Notifications
	OnClientConnected()    // Called when client is connected to entity (become player)
	OnClientDisconnected() // Called when client disconnected
}

Functions declared by IEntity can be override in Entity subclasses

type ISpace

type ISpace interface {
	OnSpaceInit()    // Called when initializing space struct, override to initialize custom space fields
	OnSpaceCreated() // Called when space is created
	OnSpaceDestroy() // Called just before space is destroyed
	// Space Operations
	OnEntityEnterSpace(entity *Entity) // Called when any entity enters space
	OnEntityLeaveSpace(entity *Entity) // Called when any entity leaves space
}

type ListAttr

type ListAttr struct {
	// contains filtered or unexported fields
}

func NewListAttr

func NewListAttr() *ListAttr

func (*ListAttr) Append

func (a *ListAttr) Append(val interface{})

func (*ListAttr) AssignList

func (a *ListAttr) AssignList(l []interface{})

func (*ListAttr) Get

func (a *ListAttr) Get(index int) interface{}

func (*ListAttr) GetBool

func (a *ListAttr) GetBool(index int) bool

func (*ListAttr) GetFloat

func (a *ListAttr) GetFloat(index int) float64

func (*ListAttr) GetInt

func (a *ListAttr) GetInt(index int) int

func (*ListAttr) GetInt64

func (a *ListAttr) GetInt64(index int) int64

func (*ListAttr) GetListAttr

func (a *ListAttr) GetListAttr(index int) *ListAttr

func (*ListAttr) GetStr

func (a *ListAttr) GetStr(index int) string

func (*ListAttr) GetUint64

func (a *ListAttr) GetUint64(index int) uint64

func (*ListAttr) Pop

func (a *ListAttr) Pop() interface{}

Delete a key in attrs

func (*ListAttr) PopListAttr

func (a *ListAttr) PopListAttr() *ListAttr

func (*ListAttr) Set

func (a *ListAttr) Set(index int, val interface{})

func (*ListAttr) Size

func (a *ListAttr) Size() int

func (*ListAttr) ToList

func (a *ListAttr) ToList() []interface{}

type MapAttr

type MapAttr struct {
	// contains filtered or unexported fields
}

func NewMapAttr

func NewMapAttr() *MapAttr

func (*MapAttr) AssignMap

func (a *MapAttr) AssignMap(doc map[string]interface{})

func (*MapAttr) AssignMapWithFilter

func (a *MapAttr) AssignMapWithFilter(doc map[string]interface{}, filter func(string) bool)

func (*MapAttr) Del

func (a *MapAttr) Del(key string)

func (*MapAttr) Get

func (a *MapAttr) Get(key string) interface{}

func (*MapAttr) GetBool

func (a *MapAttr) GetBool(key string) bool

func (*MapAttr) GetFloat

func (a *MapAttr) GetFloat(key string) float64

func (*MapAttr) GetInt

func (a *MapAttr) GetInt(key string) int

func (*MapAttr) GetInt64

func (a *MapAttr) GetInt64(key string) int64

func (*MapAttr) GetKeys

func (a *MapAttr) GetKeys() []string

func (*MapAttr) GetListAttr

func (a *MapAttr) GetListAttr(key string) *ListAttr

func (*MapAttr) GetMapAttr

func (a *MapAttr) GetMapAttr(key string) *MapAttr

func (*MapAttr) GetStr

func (a *MapAttr) GetStr(key string) string

func (*MapAttr) GetUint64

func (a *MapAttr) GetUint64(key string) uint64

func (*MapAttr) GetValues

func (a *MapAttr) GetValues() []interface{}

func (*MapAttr) HasKey

func (a *MapAttr) HasKey(key string) bool

func (*MapAttr) Pop

func (a *MapAttr) Pop(key string) interface{}

Delete a key in attrs

func (*MapAttr) PopMapAttr

func (a *MapAttr) PopMapAttr(key string) *MapAttr

func (*MapAttr) Set

func (a *MapAttr) Set(key string, val interface{})

func (*MapAttr) SetDefault

func (a *MapAttr) SetDefault(key string, val interface{})

func (*MapAttr) Size

func (a *MapAttr) Size() int

func (*MapAttr) ToMap

func (a *MapAttr) ToMap() map[string]interface{}

func (*MapAttr) ToMapWithFilter

func (a *MapAttr) ToMapWithFilter(filter func(string) bool) map[string]interface{}

type Position

type Position struct {
	X Coord
	Y Coord
	Z Coord
}

func (Position) DistanceTo

func (p Position) DistanceTo(o Position) Coord

func (Position) String

func (p Position) String() string

type RpcDesc

type RpcDesc struct {
	Func       reflect.Value
	Flags      uint
	MethodType reflect.Type
	NumArgs    int
}

type RpcDescMap

type RpcDescMap map[string]*RpcDesc

type Space

type Space struct {
	Entity

	Kind int
	I    ISpace
	// contains filtered or unexported fields
}

func (*Space) CountEntities

func (space *Space) CountEntities(typeName string) int

func (*Space) CreateEntity

func (space *Space) CreateEntity(typeName string, pos Position)

func (*Space) GetEntityCount

func (space *Space) GetEntityCount() int

func (*Space) IsNil

func (space *Space) IsNil() bool

func (*Space) LoadEntity

func (space *Space) LoadEntity(typeName string, entityID common.EntityID, pos Position)

func (*Space) OnCreated

func (space *Space) OnCreated()

func (*Space) OnDestroy

func (space *Space) OnDestroy()

func (*Space) OnEntityEnterSpace

func (space *Space) OnEntityEnterSpace(entity *Entity)

func (*Space) OnEntityLeaveSpace

func (space *Space) OnEntityLeaveSpace(entity *Entity)

func (*Space) OnInit

func (space *Space) OnInit()

func (*Space) OnRestored

func (space *Space) OnRestored()

func (*Space) OnSpaceCreated

func (space *Space) OnSpaceCreated()

func (*Space) OnSpaceDestroy

func (space *Space) OnSpaceDestroy()

func (*Space) OnSpaceInit

func (space *Space) OnSpaceInit()

func (*Space) String

func (space *Space) String() string

type SpaceManager

type SpaceManager struct {
	// contains filtered or unexported fields
}

type XZListAOICalculator

type XZListAOICalculator struct {
	// contains filtered or unexported fields
}

func (*XZListAOICalculator) Enter

func (cal *XZListAOICalculator) Enter(aoi *AOI, pos Position)

func (*XZListAOICalculator) Interested

func (cal *XZListAOICalculator) Interested(aoi *AOI) AOISet

func (*XZListAOICalculator) Leave

func (cal *XZListAOICalculator) Leave(aoi *AOI)

func (*XZListAOICalculator) Move

func (cal *XZListAOICalculator) Move(aoi *AOI, pos Position)

type Yaw

type Yaw float32

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL