diff --git a/game/builtin/world.go b/game/builtin/world.go index 7335e37..a699480 100644 --- a/game/builtin/world.go +++ b/game/builtin/world.go @@ -8,6 +8,7 @@ import ( "sync/atomic" ) +// NewWorld 创建一个内置的游戏世界 func NewWorld[PlayerID comparable, Player game.Player[PlayerID]](guid int64, options ...WorldOption[PlayerID, Player]) *World[PlayerID, Player] { world := &World[PlayerID, Player]{ guid: guid, @@ -23,6 +24,7 @@ func NewWorld[PlayerID comparable, Player game.Player[PlayerID]](guid int64, opt return world } +// World 游戏世界的内置实现,实现了基本的游戏世界接口 type World[PlayerID comparable, Player game.Player[PlayerID]] struct { guid int64 actorGuid atomic.Int64 diff --git a/game/builtin/world_errors.go b/game/builtin/world_errors.go index 15c1487..3f7889c 100644 --- a/game/builtin/world_errors.go +++ b/game/builtin/world_errors.go @@ -3,6 +3,6 @@ package builtin import "errors" var ( - ErrWorldPlayerLimit = errors.New("the number of players in the world has reached the upper limit") - ErrWorldReleased = errors.New("the world has been released") + ErrWorldPlayerLimit = errors.New("the number of players in the world has reached the upper limit") // 玩家数量达到上限 + ErrWorldReleased = errors.New("the world has been released") // 世界已被释放 ) diff --git a/game/builtin/world_options.go b/game/builtin/world_options.go index 739bdd1..096fc7c 100644 --- a/game/builtin/world_options.go +++ b/game/builtin/world_options.go @@ -2,8 +2,10 @@ package builtin import "minotaur/game" +// WorldOption 世界构建可选项 type WorldOption[PlayerID comparable, Player game.Player[PlayerID]] func(world *World[PlayerID, Player]) +// WithWorldPlayerLimit 限制世界的玩家数量上限 func WithWorldPlayerLimit[PlayerID comparable, Player game.Player[PlayerID]](playerLimit int) WorldOption[PlayerID, Player] { return func(world *World[PlayerID, Player]) { world.playerLimit = playerLimit