From e3804a086b858658db17de38d21d0c89000733d1 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 5 May 2023 15:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/builtin/world.go | 2 ++ game/builtin/world_errors.go | 4 ++-- game/builtin/world_options.go | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) 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