Documentation ¶
Index ¶
- Constants
- func CreateEntityAnywhere(typeName string)
- func CreateEntityLocally(typeName string, data map[string]interface{}, client *GameClient) EntityID
- func CreateSpaceAnywhere(kind int)
- func CreateSpaceLocally(kind int) EntityID
- func LoadEntityAnywhere(typeName string, entityID EntityID)
- func LoadEntityLocally(typeName string, entityID EntityID)
- func OnCall(id EntityID, method string, args [][]byte, clientID ClientID)
- func OnClientDisconnected(clientid ClientID)
- func OnDeclareService(serviceName string, entityid EntityID)
- func OnGameTerminating()
- func OnGateDisconnected(gateid uint16)
- func OnMigrateRequestAck(entityID EntityID, spaceID EntityID, spaceLoc uint16)
- func OnRealMigrate(entityID EntityID, spaceID EntityID, x, y, z float32, typeName string, ...)
- func OnUndeclareService(serviceName string, entityid EntityID)
- func OnUpdatePositionYawFromClient(eid EntityID, x, y, z Coord, yaw Yaw, clientid ClientID)
- func RegisterSpace(spacePtr ISpace)
- func RestoreFreezedEntities(freeze *FreezeData) (err error)
- func SaveAllEntities()
- func SetSaveInterval(duration time.Duration)
- type AOI
- type AOICalculator
- type AOISet
- type Coord
- type Entity
- func (e *Entity) AddCallback(d time.Duration, method string, args ...interface{}) EntityTimerID
- func (e *Entity) AddTimer(d time.Duration, method string, args ...interface{}) EntityTimerID
- func (e *Entity) Call(id EntityID, method string, args ...interface{})
- func (e *Entity) CallClient(method string, args ...interface{})
- func (e *Entity) CallFitleredClients(key string, val string, method string, args ...interface{})
- func (e *Entity) CallService(serviceName string, method string, args ...interface{})
- func (e *Entity) CancelTimer(tid EntityTimerID)
- func (e *Entity) DeclareService(serviceName string)
- func (e *Entity) Destroy()
- func (e *Entity) EnterSpace(spaceID EntityID, pos Position)
- func (e *Entity) ForAllClients(f func(client *GameClient))
- func (e *Entity) GetClient() *GameClient
- func (e *Entity) GetFloat(key string) float64
- func (e *Entity) GetFreezeData() *entityFreezeData
- func (e *Entity) GetInt(key string) int
- func (e *Entity) GetListAttr(key string) *ListAttr
- func (e *Entity) GetMapAttr(key string) *MapAttr
- func (e *Entity) GetMigrateData() map[string]interface{}
- func (e *Entity) GetPersistentData() map[string]interface{}
- func (e *Entity) GetPosition() Position
- func (e *Entity) GetStr(key string) string
- func (e *Entity) GetYaw() Yaw
- func (e *Entity) GiveClientTo(other *Entity)
- func (e *Entity) IsDestroyed() bool
- func (e *Entity) IsPersistent() bool
- func (e *Entity) IsSpaceEntity() bool
- func (e *Entity) LoadMigrateData(data map[string]interface{})
- func (e *Entity) LoadPersistentData(data map[string]interface{})
- func (e *Entity) Neighbors() EntitySet
- func (e *Entity) OnBecomePlayer()
- func (e *Entity) OnClientConnected()
- func (e *Entity) OnClientDisconnected()
- func (e *Entity) OnCreated()
- func (e *Entity) OnDestroy()
- func (e *Entity) OnEnterSpace()
- func (e *Entity) OnInit()
- func (e *Entity) OnLeaveSpace(space *Space)
- func (e *Entity) OnMigrateIn()
- func (e *Entity) OnMigrateOut()
- func (e *Entity) OnRestored()
- func (e *Entity) PanicOnError(err error)
- func (e *Entity) Post(cb func())
- func (e *Entity) Save()
- func (e *Entity) SetClient(client *GameClient)
- func (e *Entity) SetFilterProp(key string, val string)
- func (e *Entity) SetPosition(pos Position)
- func (e *Entity) SetYaw(yaw Yaw)
- func (e *Entity) String() string
- func (e *Entity) ToSpace() *Space
- type EntityIDSet
- type EntityManager
- type EntityMap
- type EntitySet
- type EntityTimerID
- type EntityTypeDesc
- type FreezeData
- type GameClient
- func (client *GameClient) SendCreateEntity(entity *Entity, isPlayer bool)
- func (client *GameClient) SendDestroyEntity(entity *Entity)
- func (client *GameClient) SendNotifyListAttrAppend(entityID common.EntityID, path []interface{}, val interface{})
- func (client *GameClient) SendNotifyListAttrChange(entityID common.EntityID, path []interface{}, index uint32, val interface{})
- func (client *GameClient) SendNotifyListAttrPop(entityID common.EntityID, path []interface{})
- func (client *GameClient) SendNotifyMapAttrChange(entityID common.EntityID, path []interface{}, key string, val interface{})
- func (client *GameClient) SendNotifyMapAttrDel(entityID common.EntityID, path []interface{}, key string)
- func (client *GameClient) String() string
- func (client *GameClient) UpdatePositionOnClient(entityID common.EntityID, position Position)
- func (client *GameClient) UpdateYawOnClient(entityID common.EntityID, yaw Yaw)
- type IEntity
- type ISpace
- type ListAttr
- func (a *ListAttr) Append(val interface{})
- func (a *ListAttr) AssignList(l []interface{})
- func (a *ListAttr) Get(index int) interface{}
- func (a *ListAttr) GetBool(index int) bool
- func (a *ListAttr) GetFloat(index int) float64
- func (a *ListAttr) GetInt(index int) int
- func (a *ListAttr) GetInt64(index int) int64
- func (a *ListAttr) GetListAttr(index int) *ListAttr
- func (a *ListAttr) GetStr(index int) string
- func (a *ListAttr) GetUint64(index int) uint64
- func (a *ListAttr) Pop() interface{}
- func (a *ListAttr) PopListAttr() *ListAttr
- func (a *ListAttr) Set(index int, val interface{})
- func (a *ListAttr) Size() int
- func (a *ListAttr) ToList() []interface{}
- type MapAttr
- func (a *MapAttr) AssignMap(doc map[string]interface{})
- func (a *MapAttr) AssignMapWithFilter(doc map[string]interface{}, filter func(string) bool)
- func (a *MapAttr) Del(key string)
- func (a *MapAttr) Get(key string) interface{}
- func (a *MapAttr) GetBool(key string) bool
- func (a *MapAttr) GetFloat(key string) float64
- func (a *MapAttr) GetInt(key string) int
- func (a *MapAttr) GetInt64(key string) int64
- func (a *MapAttr) GetKeys() []string
- func (a *MapAttr) GetListAttr(key string) *ListAttr
- func (a *MapAttr) GetMapAttr(key string) *MapAttr
- func (a *MapAttr) GetStr(key string) string
- func (a *MapAttr) GetUint64(key string) uint64
- func (a *MapAttr) GetValues() []interface{}
- func (a *MapAttr) HasKey(key string) bool
- func (a *MapAttr) Pop(key string) interface{}
- func (a *MapAttr) PopMapAttr(key string) *MapAttr
- func (a *MapAttr) Set(key string, val interface{})
- func (a *MapAttr) SetDefault(key string, val interface{})
- func (a *MapAttr) Size() int
- func (a *MapAttr) ToMap() map[string]interface{}
- func (a *MapAttr) ToMapWithFilter(filter func(string) bool) map[string]interface{}
- type Position
- type RpcDesc
- type RpcDescMap
- type Space
- func (space *Space) CountEntities(typeName string) int
- func (space *Space) CreateEntity(typeName string, pos Position)
- func (space *Space) GetEntityCount() int
- func (space *Space) IsNil() bool
- func (space *Space) LoadEntity(typeName string, entityID common.EntityID, pos Position)
- func (space *Space) OnCreated()
- func (space *Space) OnDestroy()
- func (space *Space) OnEntityEnterSpace(entity *Entity)
- func (space *Space) OnEntityLeaveSpace(entity *Entity)
- func (space *Space) OnInit()
- func (space *Space) OnRestored()
- func (space *Space) OnSpaceCreated()
- func (space *Space) OnSpaceDestroy()
- func (space *Space) OnSpaceInit()
- func (space *Space) String() string
- type SpaceManager
- type XZListAOICalculator
- type Yaw
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 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 OnUndeclareService ¶
func OnUndeclareService(serviceName string, entityid EntityID)
func RegisterSpace ¶
func RegisterSpace(spacePtr ISpace)
func RestoreFreezedEntities ¶
func RestoreFreezedEntities(freeze *FreezeData) (err error)
func SaveAllEntities ¶
func SaveAllEntities()
func SetSaveInterval ¶
Types ¶
type AOICalculator ¶
type Entity ¶
type Entity struct { ID EntityID TypeName string I IEntity IV reflect.Value Space *Space Attrs *MapAttr // contains filtered or unexported fields }
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) CallClient ¶
func (*Entity) CallFitleredClients ¶
Call the filtered clients with prop key = value The message is broadcast to filtered clientproxies directly without going through entities
func (*Entity) CallService ¶
func (*Entity) CancelTimer ¶
func (e *Entity) CancelTimer(tid EntityTimerID)
func (*Entity) DeclareService ¶
Register for global service
func (*Entity) EnterSpace ¶
Enter target space
func (*Entity) ForAllClients ¶
func (e *Entity) ForAllClients(f func(client *GameClient))
func (*Entity) GetFreezeData ¶
func (e *Entity) GetFreezeData() *entityFreezeData
func (*Entity) GetListAttr ¶
func (*Entity) GetMapAttr ¶
func (*Entity) GetMigrateData ¶
func (*Entity) GetPosition ¶
func (*Entity) GiveClientTo ¶
func (*Entity) IsDestroyed ¶
func (*Entity) IsPersistent ¶
Return if the entity is persistent
Default implementation check entity for persistent attributes
func (*Entity) IsSpaceEntity ¶
func (*Entity) LoadMigrateData ¶
func (*Entity) OnBecomePlayer ¶
func (e *Entity) OnBecomePlayer()
func (*Entity) OnClientConnected ¶
func (e *Entity) OnClientConnected()
func (*Entity) OnClientDisconnected ¶
func (e *Entity) OnClientDisconnected()
func (*Entity) OnLeaveSpace ¶
func (*Entity) OnMigrateIn ¶
func (e *Entity) OnMigrateIn()
func (*Entity) OnMigrateOut ¶
func (e *Entity) OnMigrateOut()
func (*Entity) OnRestored ¶
func (e *Entity) OnRestored()
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) SetClient ¶
func (e *Entity) SetClient(client *GameClient)
func (*Entity) SetFilterProp ¶
func (*Entity) SetPosition ¶
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 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) AssignList ¶
func (a *ListAttr) AssignList(l []interface{})
func (*ListAttr) GetListAttr ¶
func (*ListAttr) PopListAttr ¶
type MapAttr ¶
type MapAttr struct {
// contains filtered or unexported fields
}
func NewMapAttr ¶
func NewMapAttr() *MapAttr
func (*MapAttr) AssignMapWithFilter ¶
func (*MapAttr) GetListAttr ¶
func (*MapAttr) GetMapAttr ¶
func (*MapAttr) PopMapAttr ¶
func (*MapAttr) SetDefault ¶
type Position ¶
func (Position) DistanceTo ¶
type RpcDescMap ¶
type Space ¶
func (*Space) CountEntities ¶
func (*Space) CreateEntity ¶
func (*Space) GetEntityCount ¶
func (*Space) LoadEntity ¶
func (*Space) OnEntityEnterSpace ¶
func (*Space) OnEntityLeaveSpace ¶
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()
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)
Click to show internal directories.
Click to hide internal directories.