entity

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call added in v0.1.3

func Call(id common.EntityID, method string, args []interface{})

func CallNilSpaces added in v0.1.3

func CallNilSpaces(method string, args []interface{}, gameid uint16)

func CollectEntitySyncInfos

func CollectEntitySyncInfos()

CollectEntitySyncInfos is called by game service to collect and broadcast entity sync infos to all clients

func CreateEntitySomewhere added in v0.1.6

func CreateEntitySomewhere(gameid uint16, typeName string) common.EntityID

CreateEntitySomewhere creates new entity in any game

func CreateSpaceSomewhere added in v0.1.6

func CreateSpaceSomewhere(gameid uint16, kind int) common.EntityID

CreateSpaceSomewhere creates a space in any game server

func GetNilSpaceID added in v0.1.4

func GetNilSpaceID(gameid uint16) common.EntityID

GetNilSpaceEntityID returns the EntityID for Nil Space on the specified game GoWorld uses fixed EntityID for nil spaces on each game

func LoadEntityAnywhere

func LoadEntityAnywhere(typeName string, entityID common.EntityID)

LoadEntityAnywhere loads entity in the any game

LoadEntityAnywhere has no effect if entity already exists on any game

func LoadEntityOnGame added in v0.1.4

func LoadEntityOnGame(typeName string, entityID common.EntityID, gameid uint16)

func OnAllGamesConnected added in v0.1.3

func OnAllGamesConnected()

OnAllGamesConnected is called when all games are connected to dispatcher cluster

func OnCall

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

OnCall is called by engine when method call reaches in the game

func OnCallNilSpaces added in v0.1.3

func OnCallNilSpaces(method string, args [][]byte)

func OnClientDisconnected

func OnClientDisconnected(ownerID common.EntityID, clientid common.ClientID)

OnClientDisconnected is called by engine when Client is disconnected

func OnCreateEntitySomewhere added in v0.1.6

func OnCreateEntitySomewhere(entityid common.EntityID, typeName string, data map[string]interface{})

OnCreateEntitySomewhere is called when CreateEntitySomewhere chooses this game

func OnGameTerminating

func OnGameTerminating()

OnGameTerminating is called when game is terminating

func OnGateDisconnected

func OnGateDisconnected(gateid uint16)

OnGateDisconnected is called when gate is down

func OnLoadEntitySomewhere added in v0.1.4

func OnLoadEntitySomewhere(typeName string, entityID common.EntityID)

OnLoadEntitySomewhere loads entity in the local game.

func OnMigrateRequestAck

func OnMigrateRequestAck(entityid common.EntityID, spaceid common.EntityID, spaceGameID uint16)

OnMigrateRequestAck is called by engine when mgirate request Ack is received

func OnQuerySpaceGameIDForMigrateAck added in v0.1.2

func OnQuerySpaceGameIDForMigrateAck(entityid common.EntityID, spaceid common.EntityID, spaceGameID uint16)

OnQuerySpaceGameIDForMigrateAck is called by engine when query entity gameid ACK is received

func OnRealMigrate

func OnRealMigrate(entityid common.EntityID, data []byte)

OnRealMigrate is used by entity migration

func OnSyncPositionYawFromClient

func OnSyncPositionYawFromClient(eid common.EntityID, x, y, z Coord, yaw Yaw)

OnSyncPositionYawFromClient is called by engine to sync entity infos from Client

func RegisterSpace

func RegisterSpace(spacePtr ISpace)

RegisterSpace registers the user custom space type

func RestoreFreezedEntities

func RestoreFreezedEntities(freeze *FreezeData) (err error)

RestoreFreezedEntities restore entity system from freeze data

func SaveAllEntities

func SaveAllEntities()

SaveAllEntities saves all entities

func SetSaveInterval

func SetSaveInterval(duration time.Duration)

SetSaveInterval sets the save interval for entity system

func TraverseEntityByType added in v0.1.4

func TraverseEntityByType(etype string, cb func(e *Entity))

TraverseEntityByType traverses entities of the specified type

Types

type Coord

type Coord float32

Coord is the of coordinations entity position (x, y, z)

type Entity

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

	Space     *Space
	Position  Vector3
	Neighbors EntitySet

	Attrs *MapAttr
	// contains filtered or unexported fields
}

Entity is the basic execution unit in GoWorld server. Entities can be used to represent players, NPCs, monsters. Entities can migrate among spaces.

func CreateEntityLocally

func CreateEntityLocally(typeName string, data map[string]interface{}) *Entity

CreateEntityLocally creates new entity in the local game

func CreateEntityLocallyWithID added in v0.1.6

func CreateEntityLocallyWithID(typeName string, data map[string]interface{}, id common.EntityID) *Entity

CreateEntityLocallyWithEntityID creates new entity in the local game with specified entity ID

func GetEntity

func GetEntity(id common.EntityID) *Entity

GetEntity returns the entity with specified ID

func (*Entity) AddCallback

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

AddCallback adds a one-time callback for the entity

The callback will be cancelled if entity is destroyed

func (*Entity) AddTimer

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

AddTimer adds a repeat timer for the entity

The callback will be cancelled if entity is destroyed

func (*Entity) AsSpace added in v0.1.4

func (e *Entity) AsSpace() *Space

AsSpace converts entity to space (only works for space entity)

func (*Entity) Call

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

Call other entities

func (*Entity) CallAllClients

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

CallAllClients calls the entity method on all clients

func (*Entity) CallClient

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

CallClient calls the Client entity

func (*Entity) CallFilteredClients added in v0.1.3

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

CallFilteredClients calls the filtered clients with prop key == value supported op includes "=", "!=", "<", "<=", ">", ">=" if key = "", all clients are called despite the value of op and val

The message is broadcast to filtered clientproxies directly without going through entities, and therefore more efficient

func (*Entity) CancelTimer

func (e *Entity) CancelTimer(tid EntityTimerID)

CancelTimer cancels the Callback / Timer

func (*Entity) Destroy

func (e *Entity) Destroy()

Destroy destroys the entity

func (*Entity) DistanceTo

func (e *Entity) DistanceTo(other *Entity) Coord

DistanceTo calculates the distance between two entities

func (*Entity) EnterSpace

func (e *Entity) EnterSpace(spaceid common.EntityID, pos Vector3)

EnterSpace let the entity enters space

func (*Entity) FaceTo

func (e *Entity) FaceTo(other *Entity)

FaceTo let entity face to another entity by setting Yaw accordingly

func (*Entity) FaceToPos

func (e *Entity) FaceToPos(pos Vector3)

func (*Entity) ForAllClients

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

ForAllClients visits all clients (own Client and clients of neighbors)

func (*Entity) GetBool added in v0.1.4

func (e *Entity) GetBool(key string) bool

GetBool gets an outtermost attribute as int

func (*Entity) GetClient

func (e *Entity) GetClient() *GameClient

GetClient returns the Client of entity

func (*Entity) GetFloat

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

GetFloat gets an outtermost attribute as float64

func (*Entity) GetInt

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

GetInt gets an outtermost attribute as int

func (*Entity) GetListAttr

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

GetListAttr gets an outtermost attribute as ListAttr

func (*Entity) GetMapAttr

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

GetMapAttr gets an outtermost attribute as MapAttr

func (*Entity) GetMigrateData

func (e *Entity) GetMigrateData(spaceid common.EntityID) *entityMigrateData

GetMigrateData gets the migration data

func (*Entity) GetPosition

func (e *Entity) GetPosition() Vector3

GetPosition returns the entity position

func (*Entity) GetStr

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

GetStr gets an outtermost attribute as string

func (*Entity) GetYaw

func (e *Entity) GetYaw() Yaw

GetYaw gets entity Yaw

func (*Entity) GiveClientTo

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

GiveClientTo gives Client to other entity

func (*Entity) IsDestroyed

func (e *Entity) IsDestroyed() bool

IsDestroyed returns if the entity is destroyed

func (*Entity) IsNeighbor

func (e *Entity) IsNeighbor(other *Entity) bool

IsNeighbor checks if other entity is a neighbor

func (*Entity) IsPersistent

func (e *Entity) IsPersistent() bool

IsPersistent returns if the entity is persistent

Default implementation check entity for persistent attributes

func (*Entity) IsSpaceEntity

func (e *Entity) IsSpaceEntity() bool

IsSpaceEntity returns if the entity is actually a space

func (*Entity) IsUseAOI

func (e *Entity) IsUseAOI() bool

IsUseAOI returns if entity type is using aoi

Entities like Account, Service entities should not be using aoi

func (*Entity) OnAttrsReady added in v0.1.3

func (e *Entity) OnAttrsReady()

OnAttrsReady is called when entity's attribute is ready

Can override this function in custom entity type

func (*Entity) OnClientConnected

func (e *Entity) OnClientConnected()

OnClientConnected is called when Client is connected

Can override this function in custom entity type

func (*Entity) OnClientDisconnected

func (e *Entity) OnClientDisconnected()

OnClientDisconnected is called when Client is disconnected

Can override this function in custom entity type

func (*Entity) OnCreated

func (e *Entity) OnCreated()

OnCreated is called when entity is created

Can override this function in custom entity type

func (*Entity) OnDestroy

func (e *Entity) OnDestroy()

OnDestroy is called when entity is destroying

Can override this function in custom entity type

func (*Entity) OnEnterAOI added in v0.1.1

func (e *Entity) OnEnterAOI(otherAoi *aoi.AOI)

func (*Entity) OnEnterSpace

func (e *Entity) OnEnterSpace()

OnEnterSpace is called when entity enters space

Can override this function in custom entity type

func (*Entity) OnFreeze

func (e *Entity) OnFreeze()

OnFreeze is called when entity is freezed

Can override this function in custom entity type

func (*Entity) OnInit

func (e *Entity) OnInit()

OnInit is called when entity is initializing

Can override this function in custom entity type

func (*Entity) OnLeaveAOI added in v0.1.1

func (e *Entity) OnLeaveAOI(otherAoi *aoi.AOI)

func (*Entity) OnLeaveSpace

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

OnLeaveSpace is called when entity leaves space

Can override this function in custom entity type

func (*Entity) OnMigrateIn

func (e *Entity) OnMigrateIn()

OnMigrateIn is called when entity is migrating in

Can override this function in custom entity type

func (*Entity) OnMigrateOut

func (e *Entity) OnMigrateOut()

OnMigrateOut is called when entity is migrating out

Can override this function in custom entity type

func (*Entity) OnRestored

func (e *Entity) OnRestored()

OnRestored is called when entity is restored

Can override this function in custom entity type

func (*Entity) PanicOnError

func (e *Entity) PanicOnError(err error)

PanicOnError panics if err != nil

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()

Save the entity

func (*Entity) SetClient

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

SetClient sets the Client of entity

func (*Entity) SetClientFilterProp added in v0.1.4

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

SetClientFilterProp sets a filter property key-value

func (*Entity) SetClientSyncing

func (e *Entity) SetClientSyncing(syncing bool)

SetClientSyncing set if entity infos (position, Yaw) is syncing with Client

func (*Entity) SetPosition

func (e *Entity) SetPosition(pos Vector3)

SetPosition sets the entity position

func (*Entity) SetYaw

func (e *Entity) SetYaw(yaw Yaw)

SetYaw sets entity Yaw

func (*Entity) String

func (e *Entity) String() string

type EntityMap

type EntityMap map[common.EntityID]*Entity

EntityMap is the data structure for maintaining entity IDs to entities

func Entities

func Entities() EntityMap

Entities gets all entities

Never modify the return value !

func GetEntitiesByType added in v0.1.4

func GetEntitiesByType(etype string) EntityMap

func (EntityMap) Add

func (em EntityMap) Add(entity *Entity)

Add adds a new entity to EntityMap

func (EntityMap) Del

func (em EntityMap) Del(id common.EntityID)

Del deletes an entity from EntityMap

func (EntityMap) Get

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

Get returns the Entity of specified entity ID in EntityMap

func (EntityMap) Keys added in v0.1.4

func (em EntityMap) Keys() (keys []common.EntityID)

Keys return keys of the EntityMap in a slice

func (EntityMap) Values added in v0.1.4

func (em EntityMap) Values() (vals []*Entity)

Values return values of the EntityMap in a slice

type EntitySet

type EntitySet map[*Entity]struct{}

EntitySet is the data structure for a set of entities

func (EntitySet) Add

func (es EntitySet) Add(entity *Entity)

Add adds an entity to the EntitySet

func (EntitySet) Contains

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

Contains returns if the entity is in the EntitySet

func (EntitySet) Del

func (es EntitySet) Del(entity *Entity)

Del deletes an entity from the EntitySet

func (EntitySet) String

func (es EntitySet) String() string

type EntityTimerID

type EntityTimerID int

EntityTimerID is the type of entity timer ID

func (EntityTimerID) IsValid

func (tid EntityTimerID) IsValid() bool

IsValid returns if the EntityTimerID is still valid (not fired and not cancelled)

type EntityTypeDesc

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

EntityTypeDesc is the entity type description for registering entity types

func GetEntityTypeDesc added in v0.1.4

func GetEntityTypeDesc(typeName string) *EntityTypeDesc

func RegisterEntity

func RegisterEntity(typeName string, entity IEntity, isService bool) *EntityTypeDesc

RegisterEntity registers custom entity type and define entity behaviors

func (*EntityTypeDesc) DefineAttr added in v0.1.1

func (desc *EntityTypeDesc) DefineAttr(attr string, defs ...string) *EntityTypeDesc

func (*EntityTypeDesc) SetPersistent added in v0.1.3

func (desc *EntityTypeDesc) SetPersistent(persistent bool) *EntityTypeDesc

func (*EntityTypeDesc) SetUseAOI added in v0.1.3

func (desc *EntityTypeDesc) SetUseAOI(useAOI bool) *EntityTypeDesc

type FreezeData

type FreezeData struct {
	Entities map[common.EntityID]*entityMigrateData
}

FreezeData is the data structure for storing entity freeze data

func Freeze

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

Freeze freezes the entity system and returns all freeze data

type GameClient

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

GameClient represents the game Client of entity

Each entity can have at most one GameClient, and GameClient can be given to other entities

func MakeGameClient

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

MakeGameClient creates a GameClient object using Client ID and Game ID

func (*GameClient) String

func (client *GameClient) String() string

type IEntity added in v0.1.1

type IEntity interface {
	// Entity Lifetime
	OnInit()       // Called when initializing entity struct, override to initialize entity custom fields
	OnAttrsReady() // Called when entity attributes are ready.
	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
	OnFreeze()   // Called when entity is freezing
	OnRestored() // Called when entity is restored
	// Space Operations
	OnEnterSpace()             // Called when entity leaves space
	OnLeaveSpace(space *Space) // Called when entity enters space
	// Client Notifications
	OnClientConnected()    // Called when Client is connected to entity (become player)
	OnClientDisconnected() // Called when Client disconnected

	DescribeEntityType(desc *EntityTypeDesc) // Define entity attributes in this function
}

IEntity declares functions that is defined in Entity These functions are mostly component functions

type ISpace added in v0.1.1

type ISpace interface {
	IEntity

	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
	// Game releated callbacks on nil space only
	OnGameReady()
}

ISpace is the space delegate interface

User custom space class can override these functions for their own game logic

type ListAttr

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

ListAttr is a attribute for a list of attributes

func NewListAttr

func NewListAttr() *ListAttr

NewListAttr creates a new ListAttr

func (*ListAttr) AppendBool

func (a *ListAttr) AppendBool(v bool)

AppendBool puts bool value to the end of list

func (*ListAttr) AppendFloat

func (a *ListAttr) AppendFloat(v float64)

AppendFloat puts float value to the end of list

func (*ListAttr) AppendInt

func (a *ListAttr) AppendInt(v int64)

AppendInt puts int value to the end of list

func (*ListAttr) AppendListAttr

func (a *ListAttr) AppendListAttr(attr *ListAttr)

AppendListAttr puts ListAttr value to the end of list

func (*ListAttr) AppendMapAttr

func (a *ListAttr) AppendMapAttr(attr *MapAttr)

AppendMapAttr puts MapAttr value to the end of list

func (*ListAttr) AppendStr

func (a *ListAttr) AppendStr(v string)

AppendStr puts string value to the end of list

func (*ListAttr) AssignList

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

AssignList assigns slice to ListAttr, recursively

func (*ListAttr) GetBool

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

GetBool gets item value as bool

func (*ListAttr) GetFloat

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

GetFloat gets item value as float64

func (*ListAttr) GetInt

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

GetInt gets item value as int

func (*ListAttr) GetListAttr

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

GetListAttr gets item value as ListAttr

func (*ListAttr) GetMapAttr

func (a *ListAttr) GetMapAttr(index int) *MapAttr

GetMapAttr gets item value as MapAttr

func (*ListAttr) GetStr

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

GetStr gets item value as string

func (*ListAttr) PopBool

func (a *ListAttr) PopBool() bool

func (*ListAttr) PopFloat

func (a *ListAttr) PopFloat() float64

func (*ListAttr) PopInt

func (a *ListAttr) PopInt() int64

func (*ListAttr) PopListAttr

func (a *ListAttr) PopListAttr() *ListAttr

PopListAttr removes the last item and returns as ListAttr

func (*ListAttr) PopMapAttr

func (a *ListAttr) PopMapAttr() *MapAttr

PopMapAttr removes the last item and returns as MapAttr

func (*ListAttr) PopStr

func (a *ListAttr) PopStr() string

func (*ListAttr) SetBool

func (a *ListAttr) SetBool(index int, v bool)

SetBool sets bool value at the index

func (*ListAttr) SetFloat

func (a *ListAttr) SetFloat(index int, v float64)

SetFloat sets float value at the index

func (*ListAttr) SetInt

func (a *ListAttr) SetInt(index int, v int64)

SetInt sets int value at the index

func (*ListAttr) SetListAttr

func (a *ListAttr) SetListAttr(index int, attr *ListAttr)

SetListAttr sets ListAttr value at the index

func (*ListAttr) SetMapAttr

func (a *ListAttr) SetMapAttr(index int, attr *MapAttr)

SetMapAttr sets MapAttr value at the index

func (*ListAttr) SetStr

func (a *ListAttr) SetStr(index int, v string)

SetStr sets string value at the index

func (*ListAttr) Size

func (a *ListAttr) Size() int

Size returns size of ListAttr

func (*ListAttr) String added in v0.1.4

func (a *ListAttr) String() string

func (*ListAttr) ToList

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

ToList converts ListAttr to slice, recursively

type MapAttr

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

MapAttr is a map attribute containing muiltiple attributes indexed by string keys

func NewMapAttr

func NewMapAttr() *MapAttr

NewMapAttr creates a new MapAttr

func (*MapAttr) AssignMap

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

AssignMap assigns native map to MapAttr recursively

func (*MapAttr) AssignMapWithFilter

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

AssignMapWithFilter assigns filtered fields of native map to MapAttr recursively

func (*MapAttr) Clear added in v0.1.4

func (a *MapAttr) Clear()

Clear removes all key-values from the MapAttr

func (*MapAttr) Del

func (a *MapAttr) Del(key string)

Del deletes a key in MapAttr

func (*MapAttr) ForEach

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

ForEach calls f on all items Be careful about the type of val

func (*MapAttr) ForEachKey

func (a *MapAttr) ForEachKey(f func(key string))

ForEachKey calls f on all keys

func (*MapAttr) GetBool

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

GetBool returns the attribute of specified key in MapAttr as bool

func (*MapAttr) GetFloat

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

GetFloat returns the attribute of specified key in MapAttr as float64

func (*MapAttr) GetInt

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

GetInt returns the attribute of specified key in MapAttr as int64

func (*MapAttr) GetListAttr

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

GetListAttr returns the attribute of specified key in MapAttr as ListAttr

func (*MapAttr) GetMapAttr

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

GetMapAttr returns the attribute of specified key in MapAttr as MapAttr

func (*MapAttr) GetStr

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

GetStr returns the attribute of specified key in MapAttr as string

func (*MapAttr) HasKey

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

HasKey returns if the key exists in MapAttr

func (*MapAttr) Keys

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

Keys returns all keys of Attrs

func (*MapAttr) PopBool added in v0.1.4

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

PopBool deletes a key in MapAttr and returns the attribute as bool

func (*MapAttr) PopFloat added in v0.1.4

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

PopFloat deletes a key in MapAttr and returns the attribute as float64

func (*MapAttr) PopInt added in v0.1.4

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

PopInt deletes a key in MapAttr and returns the attribute as int64

func (*MapAttr) PopListAttr added in v0.1.4

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

PopListAttr deletes a key in MapAttr and returns the attribute as MapAttr

func (*MapAttr) PopMapAttr

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

PopMapAttr deletes a key in MapAttr and returns the attribute as MapAttr

func (*MapAttr) PopStr added in v0.1.4

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

PopStr deletes a key in MapAttr and returns the attribute as str

func (*MapAttr) SetBool

func (a *MapAttr) SetBool(key string, v bool)

SetBool sets bool value at the key

func (*MapAttr) SetDefaultBool

func (a *MapAttr) SetDefaultBool(key string, v bool)

SetDefaultBool sets default bool value at the key

func (*MapAttr) SetDefaultFloat

func (a *MapAttr) SetDefaultFloat(key string, v float64)

SetDefaultFloat sets default float value at the key

func (*MapAttr) SetDefaultInt

func (a *MapAttr) SetDefaultInt(key string, v int64)

SetDefaultInt sets default int value at the key

func (*MapAttr) SetDefaultListAttr

func (a *MapAttr) SetDefaultListAttr(key string, attr *ListAttr)

SetDefaultListAttr sets default ListAttr value at the key

func (*MapAttr) SetDefaultMapAttr

func (a *MapAttr) SetDefaultMapAttr(key string, attr *MapAttr)

SetDefaultMapAttr sets default MapAttr value at the key

func (*MapAttr) SetDefaultStr

func (a *MapAttr) SetDefaultStr(key string, v string)

SetDefaultStr sets default string value at the key

func (*MapAttr) SetFloat

func (a *MapAttr) SetFloat(key string, v float64)

SetFloat sets float value at the key

func (*MapAttr) SetInt

func (a *MapAttr) SetInt(key string, v int64)

SetInt sets int value at the key

func (*MapAttr) SetListAttr

func (a *MapAttr) SetListAttr(key string, attr *ListAttr)

SetListAttr sets ListAttr value at the key

func (*MapAttr) SetMapAttr

func (a *MapAttr) SetMapAttr(key string, attr *MapAttr)

SetMapAttr sets MapAttr value at the key

func (*MapAttr) SetStr

func (a *MapAttr) SetStr(key string, v string)

SetStr sets string value at the key

func (*MapAttr) Size

func (a *MapAttr) Size() int

Size returns the size of MapAttr

func (*MapAttr) String added in v0.1.4

func (a *MapAttr) String() string

String convert MapAttr to readable string

func (*MapAttr) ToMap

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

ToMap converts MapAttr to native map, recursively

func (*MapAttr) ToMapWithFilter

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

ToMapWithFilter converts filtered fields of MapAttr to to native map, recursively

type Space

type Space struct {
	Entity

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

Space is the entity type of spaces

Spaces are also entities but with space management logics

func CreateNilSpace added in v0.1.3

func CreateNilSpace(gameid uint16) *Space

CreateNilSpace creates the nil space

func CreateSpaceLocally

func CreateSpaceLocally(kind int) *Space

CreateSpaceLocally creates a space in the local game server

func GetNilSpace added in v0.1.4

func GetNilSpace() *Space

func GetSpace added in v0.1.4

func GetSpace(id common.EntityID) *Space

func (*Space) CountEntities

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

CountEntities returns the number of entities of specified type in space

func (*Space) CreateEntity

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

CreateEntity creates a new local entity in this space

func (*Space) DescribeEntityType added in v0.1.3

func (space *Space) DescribeEntityType(desc *EntityTypeDesc)

func (*Space) EnableAOI added in v0.1.4

func (space *Space) EnableAOI()

func (*Space) ForEachEntity

func (space *Space) ForEachEntity(f func(e *Entity))

ForEachEntity visits all entities in space and call function f with each entity

func (*Space) GetEntity

func (space *Space) GetEntity(entityID common.EntityID) *Entity

GetEntity returns the entity in space with specified ID, nil otherwise

func (*Space) GetEntityCount

func (space *Space) GetEntityCount() int

GetEntityCount returns the total count of entities in space

func (*Space) GetSpaceRange added in v0.1.1

func (space *Space) GetSpaceRange() (minX, minY, maxX, maxY Coord)

func (*Space) GetTowerRange added in v0.1.1

func (space *Space) GetTowerRange() (minX, minY, maxX, maxY Coord)

func (*Space) IsNil

func (space *Space) IsNil() bool

IsNil checks if the space is the nil space

func (*Space) LoadEntity

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

LoadEntity loads a entity of specified entityID to the space

If the entity already exists on server, this call has no effect

func (*Space) OnCreated

func (space *Space) OnCreated()

OnCreated is called when Space entity is created

func (*Space) OnDestroy

func (space *Space) OnDestroy()

OnDestroy is called when Space entity is destroyed

func (*Space) OnEntityEnterSpace

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

OnEntityEnterSpace is called when entity enters space

Custom space type can override this function

func (*Space) OnEntityLeaveSpace

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

OnEntityLeaveSpace is called when entity leaves space

Custom space type can override this function

func (*Space) OnGameReady added in v0.1.3

func (space *Space) OnGameReady()

OnGameReady is called when the game server is ready on NilSpace only

func (*Space) OnInit

func (space *Space) OnInit()

OnInit initialize Space entity

func (*Space) OnRestored

func (space *Space) OnRestored()

OnRestored is called when space entity is restored

func (*Space) OnSpaceCreated

func (space *Space) OnSpaceCreated()

OnSpaceCreated is called when space is created

Custom space type can override to provide custom logic

func (*Space) OnSpaceDestroy

func (space *Space) OnSpaceDestroy()

OnSpaceDestroy is called when space is destroying

Custom space type can override to provide custom logic

func (*Space) OnSpaceInit added in v0.1.1

func (space *Space) OnSpaceInit()

OnSpaceInit is a compositive method for initializing space fields

func (*Space) String

func (space *Space) String() string

type Vector3

type Vector3 struct {
	X Coord
	Y Coord
	Z Coord
}

Vector3 is type of entity position

func (Vector3) Add

func (p Vector3) Add(o Vector3) Vector3

func (Vector3) DirToYaw

func (dir Vector3) DirToYaw() Yaw

DirToYaw convert direction represented by Vector3 to Yaw

func (Vector3) DistanceTo

func (p Vector3) DistanceTo(o Vector3) Coord

DistanceTo calculates distance between two positions

func (Vector3) Mul

func (p Vector3) Mul(m Coord) Vector3

Mul calculates Vector3 p * m

func (*Vector3) Normalize

func (p *Vector3) Normalize()

func (Vector3) Normalized

func (p Vector3) Normalized() Vector3

func (Vector3) String

func (p Vector3) String() string

func (Vector3) Sub

func (p Vector3) Sub(o Vector3) Vector3

Sub calculates Vector3 p - Vector3 o

type Yaw

type Yaw float32

Yaw is the type of entity Yaw

Jump to

Keyboard shortcuts

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