Documentation ¶
Index ¶
- Constants
- Variables
- func AssertErr(err error)
- func AssertNil(v interface{}, errorInfo string)
- func AssertPtr(v interface{}, errInfo string) (err error)
- func FileLogger() *log.Logger
- func MapToList[K int64, V any](m map[K]V) ([]K, []V)
- func StopApplication()
- func SyncMapToList(m *sync.Map) ([]any, []any)
- type Closing
- type DefaultPlayer
- type DefaultRoom
- func (d *DefaultRoom) ClearRoom()
- func (d *DefaultRoom) GetMaxUser() int64
- func (d *DefaultRoom) GetPlayer(userId int64) IPlayer
- func (d *DefaultRoom) GetPlayerList() []IPlayer
- func (d *DefaultRoom) GetRoomId() int64
- func (d *DefaultRoom) GetRoomStatus() RoomStatus
- func (d *DefaultRoom) GetUserIdList() (list []int64)
- func (d *DefaultRoom) HeartbeatTime() int64
- func (d *DefaultRoom) JoinRoom(player IPlayer)
- func (d *DefaultRoom) QuitRoom(player IPlayer)
- type FrameSyncManager
- type IPlayer
- type IRoom
- type MatchQueue
- type Pool
- type RoomManger
- func (m *RoomManger) AddRoom(r IRoom)
- func (m *RoomManger) GetByRoomId(roomId int64) IRoom
- func (m *RoomManger) GetByUserId(userId int64) IRoom
- func (m *RoomManger) GetUniqueRoomId() int64
- func (m *RoomManger) JoinRoom(player IPlayer, roomId int64)
- func (m *RoomManger) ListRoom() (list []IRoom)
- func (m *RoomManger) QuitRoom(player IPlayer, roomId int64)
- func (m *RoomManger) RemoveRoom(roomId int64)
- func (m *RoomManger) RoomClear(max int64)
- type RoomStatus
- type SafeList
- type SafeMap
- type SyncRoom
Constants ¶
View Source
const ( GatewayName = "gateway-game" ServiceName = "service-game" )
Variables ¶
View Source
var CatLog *log.Logger
CatLog 一般日志
View Source
var CmdKit = &cmdKit{}
View Source
var UuidKit = &uuidKit{}
Functions ¶
func StopApplication ¶
func StopApplication()
Types ¶
type DefaultPlayer ¶ added in v0.0.37
type DefaultPlayer struct {
Uid int64
}
DefaultPlayer 默认Player
func (*DefaultPlayer) UserId ¶ added in v0.0.37
func (d *DefaultPlayer) UserId() int64
type DefaultRoom ¶ added in v0.0.31
type DefaultRoom struct { // 房间id RoomId int64 // 房间状态 RoomStatus // 创建时间十位时间戳 CreateTime int64 // 最大人数 MaxUser int64 // 心跳时间 Heartbeat int64 // 锁 sync.Mutex // contains filtered or unexported fields }
DefaultRoom 默认房间实现,请继承此结构体,并重写方法,线程安全
func (*DefaultRoom) ClearRoom ¶ added in v0.0.37
func (d *DefaultRoom) ClearRoom()
func (*DefaultRoom) GetMaxUser ¶ added in v0.0.31
func (d *DefaultRoom) GetMaxUser() int64
func (*DefaultRoom) GetPlayer ¶ added in v0.0.36
func (d *DefaultRoom) GetPlayer(userId int64) IPlayer
func (*DefaultRoom) GetPlayerList ¶ added in v0.0.31
func (d *DefaultRoom) GetPlayerList() []IPlayer
func (*DefaultRoom) GetRoomId ¶ added in v0.0.31
func (d *DefaultRoom) GetRoomId() int64
func (*DefaultRoom) GetRoomStatus ¶ added in v0.0.31
func (d *DefaultRoom) GetRoomStatus() RoomStatus
func (*DefaultRoom) GetUserIdList ¶ added in v0.0.31
func (d *DefaultRoom) GetUserIdList() (list []int64)
func (*DefaultRoom) HeartbeatTime ¶ added in v0.0.31
func (d *DefaultRoom) HeartbeatTime() int64
func (*DefaultRoom) JoinRoom ¶ added in v0.0.31
func (d *DefaultRoom) JoinRoom(player IPlayer)
func (*DefaultRoom) QuitRoom ¶ added in v0.0.31
func (d *DefaultRoom) QuitRoom(player IPlayer)
type FrameSyncManager ¶ added in v0.0.18
type FrameSyncManager struct {
// contains filtered or unexported fields
}
FrameSyncManager 帧同步管理器
func NewFrameSyncManager ¶ added in v0.0.18
func NewFrameSyncManager(frameRate float64, delay time.Duration) *FrameSyncManager
NewFrameSyncManager 创建新的帧同步管理器
func (*FrameSyncManager) GetCurrentFrame ¶ added in v0.0.18
func (f *FrameSyncManager) GetCurrentFrame() int
GetCurrentFrame 获取当前帧
func (*FrameSyncManager) WaitNextFrame ¶ added in v0.0.18
func (f *FrameSyncManager) WaitNextFrame(callback func())
WaitNextFrame 等待下一帧
- 获取当前时间
- 计算预期时间 = 开始时间 + 帧延迟 * 当前帧 + 延迟 -> 示例: 1秒 + 1/60秒 * 0 + 1/60秒 = 1.016秒
- 如果预期时间大于当前时间,就等待; 示例: 1.016秒 > 1秒 就等待16毫秒
- 执行回调函数
type IRoom ¶ added in v0.0.30
type IRoom interface { // GetRoomId 获取房间id GetRoomId() int64 // GetMaxUser 获取房间最大人数 GetMaxUser() int64 // GetRoomStatus 获取房间状态 GetRoomStatus() RoomStatus // GetUserIdList 获取房间内所有玩家Id GetUserIdList() []int64 // GetPlayerList 获取房间内所有玩家 GetPlayerList() []IPlayer // JoinRoom 加入房间,请通过RoomManager使用 JoinRoom(player IPlayer) // QuitRoom 退出房间,请通过RoomManager使用 QuitRoom(player IPlayer) // HeartbeatTime 房间上次心跳时间,如果在一定时间内没有心跳则清理房间,10位时间戳 HeartbeatTime() int64 // GetPlayer 获取某个玩家 GetPlayer(userId int64) IPlayer // ClearRoom 清空所有玩家 ClearRoom() }
IRoom 房间接口, 其默认实现为DefaultRoom, 所以继承DefaultRoom使用即可
type MatchQueue ¶ added in v0.0.27
type MatchQueue struct {
// contains filtered or unexported fields
}
func NewMatchQueue ¶ added in v0.0.27
func NewMatchQueue(maxMatch int64, callback func([]int64)) *MatchQueue
func (*MatchQueue) AddMatch ¶ added in v0.0.27
func (mq *MatchQueue) AddMatch(player IPlayer)
func (*MatchQueue) GetMatches ¶ added in v0.0.27
func (mq *MatchQueue) GetMatches() []int64
func (*MatchQueue) RemoveMatch ¶ added in v0.0.27
func (mq *MatchQueue) RemoveMatch(match int64)
type RoomManger ¶
type RoomManger struct {
// contains filtered or unexported fields
}
RoomManger 线程安全
func NewRoomManger ¶ added in v0.0.30
func NewRoomManger() *RoomManger
func (*RoomManger) GetByRoomId ¶ added in v0.0.30
func (m *RoomManger) GetByRoomId(roomId int64) IRoom
GetByRoomId 根据房间id获取房间, 对象,是否存在
func (*RoomManger) GetByUserId ¶ added in v0.0.30
func (m *RoomManger) GetByUserId(userId int64) IRoom
func (*RoomManger) GetUniqueRoomId ¶ added in v0.0.30
func (m *RoomManger) GetUniqueRoomId() int64
GetUniqueRoomId 创建房间
func (*RoomManger) JoinRoom ¶ added in v0.0.33
func (m *RoomManger) JoinRoom(player IPlayer, roomId int64)
JoinRoom 加入房间
func (*RoomManger) ListRoom ¶ added in v0.0.30
func (m *RoomManger) ListRoom() (list []IRoom)
ListRoom 获取房间列表
func (*RoomManger) QuitRoom ¶ added in v0.0.33
func (m *RoomManger) QuitRoom(player IPlayer, roomId int64)
QuitRoom 退出房间
func (*RoomManger) RemoveRoom ¶ added in v0.0.30
func (m *RoomManger) RemoveRoom(roomId int64)
RemoveRoom 移除房间并清理关联用户id
func (*RoomManger) RoomClear ¶ added in v0.0.30
func (m *RoomManger) RoomClear(max int64)
RoomClear 处理已经打开的房间并且30秒没有同步数据的房间 max 最大房间未动秒数
type RoomStatus ¶
type RoomStatus int
const ( Ready RoomStatus = iota // 准备状态, 未开始 Running // 运行状态, 已经开始 Close // 关闭状态, 已经结束 )
房间状态
type SafeMap ¶ added in v0.0.18
SafeMap 安全的map,支持并发读写,加有序的key
type SyncRoom ¶ added in v0.0.31
type SyncRoom struct { DefaultRoom // 同步数据,索引为帧号 List []*SafeList // 创建时间十位时间戳 CreateTime int64 }
SyncRoom 帧同步房间
func (*SyncRoom) AddSyncData ¶ added in v0.0.31
AddSyncData 添加同步数据
func (*SyncRoom) GetLastSyncData ¶ added in v0.0.31
GetLastSyncData 获取最后帧的同步数据
func (*SyncRoom) GetUserIdList ¶ added in v0.0.31
GetUserIdList 获取所有用户Id
func (*SyncRoom) Start ¶ added in v0.0.31
func (r *SyncRoom) Start(f func())
Start 进行房间的帧同步,以每秒60帧为例,每1/60秒执行一次
func (*SyncRoom) StartCustom ¶ added in v0.0.31
StartCustom 以每秒60帧为例,delay = time.Second/60 为每一帧的执行时间 = 1/60m秒
Click to show internal directories.
Click to hide internal directories.