diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2b4aac7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 yuanqi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/component/components/doc.go b/component/components/doc.go new file mode 100644 index 0000000..84e7ef6 --- /dev/null +++ b/component/components/doc.go @@ -0,0 +1,4 @@ +// Package components 通用组件的内置实现 +// - lockstep.go 帧同步组件 +// - lockstep_options.go 帧同步组件可选项 +package components diff --git a/component/doc.go b/component/doc.go new file mode 100644 index 0000000..bf58a33 --- /dev/null +++ b/component/doc.go @@ -0,0 +1,4 @@ +// Package component 通用组件的接口定义 +// - lockstep.go 帧同步组件接口定义 +// - lockstep_client.go 帧同步组件客户端接口定义 +package component diff --git a/component/lockstep.go b/component/lockstep.go index d5a55c7..854cc52 100644 --- a/component/lockstep.go +++ b/component/lockstep.go @@ -1,5 +1,6 @@ package component +// Lockstep 帧同步组件接口定义 type Lockstep[ClientID comparable, Command any] interface { // JoinClient 加入客户端 JoinClient(client LockstepClient[ClientID]) @@ -28,5 +29,6 @@ type Lockstep[ClientID comparable, Command any] interface { } type ( + // LockstepStoppedEventHandle 帧同步停止广播事件处理函数 LockstepStoppedEventHandle[ClientID comparable, Command any] func(lockstep Lockstep[ClientID, Command]) ) diff --git a/component/lockstep_client.go b/component/lockstep_client.go index de6c5f2..7dbe702 100644 --- a/component/lockstep_client.go +++ b/component/lockstep_client.go @@ -1,7 +1,11 @@ package component -import "github.com/kercylan98/minotaur/game" - +// LockstepClient 帧同步客户端接口定义 +// - 客户端应该具备ID及写入数据包的实现 type LockstepClient[ID comparable] interface { - game.Player[ID] + // GetID 用户玩家ID + GetID() ID + // Send 发送数据包 + // - messageType: websocket模式中指定消息类型 + Send(packet []byte, messageType ...int) } diff --git a/config/config.go b/config/config.go index d3a52f9..dbb4deb 100644 --- a/config/config.go +++ b/config/config.go @@ -11,7 +11,10 @@ import ( "time" ) +// LoadHandle 配置加载处理函数 type LoadHandle func(handle func(filename string, config any) error) + +// RefreshHandle 配置刷新处理函数 type RefreshHandle func() const ( @@ -28,12 +31,14 @@ var ( mutex sync.Mutex ) +// Init 配置初始化 func Init(loadDir string, loadHandle LoadHandle, refreshHandle RefreshHandle) { cLoadDir = loadDir cLoadHandle = loadHandle cRefreshHandle = refreshHandle } +// Load 加载配置 func Load() { mutex.Lock() if cTicker != nil { @@ -53,6 +58,7 @@ func Load() { mutex.Unlock() } +// WithTickerLoad 通过定时器加载配置 func WithTickerLoad(ticker *timer.Ticker, interval time.Duration) { if ticker != cTicker && cTicker != nil { cTicker.StopTimer(tickerLoadRefresh) @@ -65,12 +71,14 @@ func WithTickerLoad(ticker *timer.Ticker, interval time.Duration) { }) } +// StopTickerLoad 停止通过定时器加载配置 func StopTickerLoad() { if cTicker != nil { cTicker.StopTimer(tickerLoadRefresh) } } +// Refresh 刷新配置 func Refresh() { mutex.Lock() cRefreshHandle() diff --git a/config/doc.go b/config/doc.go new file mode 100644 index 0000000..09bd1ab --- /dev/null +++ b/config/doc.go @@ -0,0 +1,2 @@ +// Package config 基于配置导表功能实现的配置加载及刷新功能 +package config diff --git a/config/event.go b/config/event.go index 042ced6..e4d1776 100644 --- a/config/event.go +++ b/config/event.go @@ -1,11 +1,12 @@ package config -type RefreshEvent func() +// RefreshEventHandle 配置刷新事件处理函数 +type RefreshEventHandle func() var configRefreshEventHandles []func() // RegConfigRefreshEvent 当配置刷新时将立即执行被注册的事件处理函数 -func RegConfigRefreshEvent(handle RefreshEvent) { +func RegConfigRefreshEvent(handle RefreshEventHandle) { configRefreshEventHandles = append(configRefreshEventHandles, handle) } diff --git a/examples/doc.go b/examples/doc.go new file mode 100644 index 0000000..5150013 --- /dev/null +++ b/examples/doc.go @@ -0,0 +1,2 @@ +// Package examples 提供了多种实现案例 +package examples diff --git a/game/player.go b/game/player.go index ff8ffb4..1e11608 100644 --- a/game/player.go +++ b/game/player.go @@ -4,13 +4,8 @@ import "github.com/kercylan98/minotaur/server" // Player 玩家 type Player[ID comparable] interface { - // GetID 用户玩家ID - GetID() ID // UseConn 指定连接 UseConn(conn *server.Conn) - // Send 发送数据包 - // - messageType: websocket模式中指定消息类型 - Send(packet []byte, messageType ...int) // Close 关闭玩家并且释放其资源 Close() } diff --git a/local-doc.bat b/local-doc.bat new file mode 100644 index 0000000..e531ed7 --- /dev/null +++ b/local-doc.bat @@ -0,0 +1,3 @@ +@echo off +echo Open: http://localhost:9998/pkg/github.com/kercylan98/minotaur/ +godoc -http=:9998 -play \ No newline at end of file diff --git a/local-doc.sh b/local-doc.sh new file mode 100644 index 0000000..cf28bbd --- /dev/null +++ b/local-doc.sh @@ -0,0 +1,2 @@ +echo Open: http://localhost:9998/pkg/github.com/kercylan98/minotaur/ +godoc -http=:9998 -play \ No newline at end of file