Documentation ¶
Index ¶
- Constants
- Variables
- type AOIManager
- func (m *AOIManager) AddPIDToGrID(pID, gID int)
- func (m *AOIManager) AddToGrIDByPos(pID int, x, y float32)
- func (m *AOIManager) GetGIDByPos(x, y float32) int
- func (m *AOIManager) GetPIDsByGID(gID int) (playerIDs []int)
- func (m *AOIManager) GetPIDsByPos(x, y float32) (playerIDs []int)
- func (m *AOIManager) GetSurroundGrIDsByGID(gID int) (grIDs []*GrID)
- func (m *AOIManager) RemoveFromGrIDByPos(pID int, x, y float32)
- func (m *AOIManager) RemovePIDFromGrID(pID, gID int)
- func (m *AOIManager) String() string
- type GrID
- type Player
- func (p *Player) BroadCastStartPosition()
- func (p *Player) GetSurroundingPlayers() []*Player
- func (p *Player) LostConnection()
- func (p *Player) OnExchangeAoiGrID(oldGID, newGID int) error
- func (p *Player) SendMsg(msgID uint32, data proto.Message)
- func (p *Player) SyncPID()
- func (p *Player) SyncSurrounding()
- func (p *Player) Talk(content string)
- func (p *Player) UpdatePos(x float32, y float32, z float32, v float32)
- type WorldManager
Constants ¶
Variables ¶
var IDLock sync.Mutex // Mutex for protecting PIDGen(保护PIDGen的互斥机制)
var PIDGen int32 = 1 // Counter for generating player IDs(用来生成玩家ID的计数器)
Player ID Generator
Functions ¶
This section is empty.
Types ¶
type AOIManager ¶
type AOIManager struct { MinX int // Left boundary coordinate of the area(区域左边界坐标) MaxX int // Right boundary coordinate of the area(区域右边界坐标) CntsX int // Number of grids in the x direction(x方向格子的数量) MinY int // Upper boundary coordinate of the area(区域上边界坐标) MaxY int // Lower boundary coordinate of the area(区域下边界坐标) CntsY int // Number of grids in the y direction(y方向的格子数量) // contains filtered or unexported fields }
AOIManager AOI management module(AOI管理模块)
func NewAOIManager ¶
func NewAOIManager(minX, maxX, cntsX, minY, maxY, cntsY int) *AOIManager
NewAOIManager Initialize an AOI area(初始化一个AOI区域)
func (*AOIManager) AddPIDToGrID ¶
func (m *AOIManager) AddPIDToGrID(pID, gID int)
AddPIDToGrID Add a PlayerID to a grid 添加一个PlayerID到一个格子中
func (*AOIManager) AddToGrIDByPos ¶
func (m *AOIManager) AddToGrIDByPos(pID int, x, y float32)
AddToGrIDByPos Add a Player to a grid based on horizontal and vertical coordinates 通过横纵坐标添加一个Player到一个格子中
func (*AOIManager) GetGIDByPos ¶
func (m *AOIManager) GetGIDByPos(x, y float32) int
GetGIDByPos Get the corresponding grid ID by horizontal and vertical coordinates 通过横纵坐标获取对应的格子ID
func (*AOIManager) GetPIDsByGID ¶
func (m *AOIManager) GetPIDsByGID(gID int) (playerIDs []int)
GetPIDsByGID Get all PlayerIDs within the surrounding nine grids by horizontal and vertical coordinates 通过GID获取当前格子的全部playerID
func (*AOIManager) GetPIDsByPos ¶
func (m *AOIManager) GetPIDsByPos(x, y float32) (playerIDs []int)
GetPIDsByPos Get all PlayerIDs within the surrounding nine grids by horizontal and vertical coordinates 通过横纵坐标得到周边九宫格内的全部PlayerIDs
func (*AOIManager) GetSurroundGrIDsByGID ¶
func (m *AOIManager) GetSurroundGrIDsByGID(gID int) (grIDs []*GrID)
GetSurroundGrIDsByGID Get the surrounding nine grids information based on the grid's gID 根据格子的gID得到当前周边的九宫格信息
func (*AOIManager) RemoveFromGrIDByPos ¶
func (m *AOIManager) RemoveFromGrIDByPos(pID int, x, y float32)
RemoveFromGrIDByPos Remove a Player from the corresponding grid based on horizontal and vertical coordinates 通过横纵坐标把一个Player从对应的格子中删除
func (*AOIManager) RemovePIDFromGrID ¶
func (m *AOIManager) RemovePIDFromGrID(pID, gID int)
RemovePIDFromGrID Remove a PlayerID from a grid 移除一个格子中的PlayerID
func (*AOIManager) String ¶
func (m *AOIManager) String() string
String Print information method (打印信息方法)
type GrID ¶
type GrID struct { GID int // Grid ID MinX int // Left boundary coordinate of the grid MaxX int // Right boundary coordinate of the grid MinY int // Upper boundary coordinate of the grid MaxY int // Lower boundary coordinate of the grid // contains filtered or unexported fields }
GrID A grid class in a map 一个地图中的格子类
func (*GrID) GetPlyerIDs ¶
GetPlyerIDs Get all players in the current grid
type Player ¶
type Player struct { PID int32 // Player ID Conn ziface.IConnection // Current player's connection X float32 // Planar x coordinate(平面x坐标) Y float32 // Height(高度) Z float32 // Planar y coordinate (Note: not Y)- 平面y坐标 (注意不是Y) V float32 // Rotation 0-360 degrees(旋转0-360度) }
Player object
func (*Player) BroadCastStartPosition ¶
func (p *Player) BroadCastStartPosition()
BroadCastStartPosition Broadcast the player's starting position (广播玩家自己的出生地点)
func (*Player) GetSurroundingPlayers ¶
Get information of surrounding players in the current player's AOI 获得当前玩家的AOI周边玩家信息
func (*Player) OnExchangeAoiGrID ¶
func (*Player) SendMsg ¶
SendMsg Send messages to the client, mainly serializing and sending the protobuf data of the pb Message
(发送消息给客户端,主要是将pb的protobuf数据序列化之后发送)
func (*Player) SyncPID ¶
func (p *Player) SyncPID()
SyncPID Inform the client about pID and synchronize the generated player ID to the client (告知客户端pID,同步已经生成的玩家ID给客户端)
func (*Player) SyncSurrounding ¶
func (p *Player) SyncSurrounding()
SyncSurrounding Broadcast the player's position to the surrounding players in the same grid 给当前玩家周边的(九宫格内)玩家广播自己的位置,让他们显示自己
type WorldManager ¶
type WorldManager struct { AoiMgr *AOIManager // AOI planning manager for the current world map(当前世界地图的AOI规划管理器) Players map[int32]*Player // Collection of currently online players(当前在线的玩家集合) // contains filtered or unexported fields }
WorldManager The overall management module of the current game world 当前游戏世界的总管理模块
var WorldMgrObj *WorldManager
Provide an external handle to the world management module 提供一个对外的世界管理模块句柄
func (*WorldManager) AddPlayer ¶
func (wm *WorldManager) AddPlayer(player *Player)
AddPlayer Provide the ability to add a player, adding the player to the player information table Players (提供添加一个玩家的的功能,将玩家添加进玩家信息表Players)
func (*WorldManager) GetAllPlayers ¶
func (wm *WorldManager) GetAllPlayers() []*Player
GetAllPlayers Get information of all players 获取所有玩家的信息
func (*WorldManager) GetPlayerByPID ¶
func (wm *WorldManager) GetPlayerByPID(pID int32) *Player
GetPlayerByPID Get corresponding player information by player ID 通过玩家ID 获取对应玩家信息
func (*WorldManager) GetPlayersByGID ¶
func (wm *WorldManager) GetPlayersByGID(gID int) []*Player
GetPlayersByGID Get information of all players in a specific gID 获取指定gID中的所有player信息
func (*WorldManager) RemovePlayerByPID ¶
func (wm *WorldManager) RemovePlayerByPID(pID int32)
RemovePlayerByPID Remove a player from the player information table by player ID 从玩家信息表中移除一个玩家