游戏世界事件完善
This commit is contained in:
parent
c685fa163b
commit
8d1ae98671
|
@ -34,6 +34,9 @@ type World[PlayerID comparable] struct {
|
||||||
actorGeneratedEventHandles []game.ActorGeneratedEventHandle
|
actorGeneratedEventHandles []game.ActorGeneratedEventHandle
|
||||||
actorAnnihilationEventHandles []game.ActorAnnihilationEventHandle
|
actorAnnihilationEventHandles []game.ActorAnnihilationEventHandle
|
||||||
actorOwnerChangeEventHandles []game.ActorOwnerChangeEventHandle[PlayerID]
|
actorOwnerChangeEventHandles []game.ActorOwnerChangeEventHandle[PlayerID]
|
||||||
|
worldGeneratedEventHandles []game.WorldGeneratedEventHandle[PlayerID]
|
||||||
|
worldResetEventHandles []game.WorldResetEventHandle[PlayerID]
|
||||||
|
worldReleasedEventHandles []game.WorldReleaseEventHandle[PlayerID]
|
||||||
|
|
||||||
released atomic.Bool
|
released atomic.Bool
|
||||||
}
|
}
|
||||||
|
@ -186,6 +189,36 @@ func (slf *World[PlayerID]) Release() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) RegWorldGeneratedEvent(handle game.WorldGeneratedEventHandle[PlayerID]) {
|
||||||
|
slf.worldGeneratedEventHandles = append(slf.worldGeneratedEventHandles, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) OnWorldGeneratedEvent() {
|
||||||
|
for _, handle := range slf.worldGeneratedEventHandles {
|
||||||
|
handle(slf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) RegWorldResetEvent(handle game.WorldResetEventHandle[PlayerID]) {
|
||||||
|
slf.worldResetEventHandles = append(slf.worldResetEventHandles, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) OnWorldResetEvent() {
|
||||||
|
for _, handle := range slf.worldResetEventHandles {
|
||||||
|
handle(slf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) RegWorldReleaseEvent(handle game.WorldReleaseEventHandle[PlayerID]) {
|
||||||
|
slf.worldReleasedEventHandles = append(slf.worldReleasedEventHandles, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *World[PlayerID]) OnWorldReleaseEvent() {
|
||||||
|
for _, handle := range slf.worldReleasedEventHandles {
|
||||||
|
handle(slf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *World[PlayerID]) RegPlayerJoinWorldEvent(handle game.PlayerJoinWorldEventHandle[PlayerID]) {
|
func (slf *World[PlayerID]) RegPlayerJoinWorldEvent(handle game.PlayerJoinWorldEventHandle[PlayerID]) {
|
||||||
slf.playerJoinWorldEventHandles = append(slf.playerJoinWorldEventHandles, handle)
|
slf.playerJoinWorldEventHandles = append(slf.playerJoinWorldEventHandles, handle)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,15 @@ type World[PlayerID comparable] interface {
|
||||||
// Release 释放世界资源,释放后世界将不可用
|
// Release 释放世界资源,释放后世界将不可用
|
||||||
Release()
|
Release()
|
||||||
|
|
||||||
|
// RegWorldGeneratedEvent 世界创建完成时将立即执行被注册的事件处理函数
|
||||||
|
RegWorldGeneratedEvent(handle WorldGeneratedEventHandle[PlayerID])
|
||||||
|
OnWorldGeneratedEvent()
|
||||||
|
// RegWorldResetEvent 世界被重置后将立即执行被注册的事件处理函数
|
||||||
|
RegWorldResetEvent(handle WorldResetEventHandle[PlayerID])
|
||||||
|
OnWorldResetEvent()
|
||||||
|
// RegWorldReleaseEvent 直接被释放前将立即执行被注册的事件处理函数,此刻世界仍然可用
|
||||||
|
RegWorldReleaseEvent(handle WorldReleaseEventHandle[PlayerID])
|
||||||
|
OnWorldReleaseEvent()
|
||||||
// RegPlayerJoinWorldEvent 玩家进入世界时将立即执行被注册的事件处理函数
|
// RegPlayerJoinWorldEvent 玩家进入世界时将立即执行被注册的事件处理函数
|
||||||
RegPlayerJoinWorldEvent(handle PlayerJoinWorldEventHandle[PlayerID])
|
RegPlayerJoinWorldEvent(handle PlayerJoinWorldEventHandle[PlayerID])
|
||||||
OnPlayerJoinWorldEvent(player Player[PlayerID])
|
OnPlayerJoinWorldEvent(player Player[PlayerID])
|
||||||
|
@ -62,6 +71,9 @@ type World[PlayerID comparable] interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
WorldGeneratedEventHandle[ID comparable] func(world World[ID])
|
||||||
|
WorldResetEventHandle[ID comparable] func(world World[ID])
|
||||||
|
WorldReleaseEventHandle[ID comparable] func(world World[ID])
|
||||||
PlayerJoinWorldEventHandle[ID comparable] func(player Player[ID])
|
PlayerJoinWorldEventHandle[ID comparable] func(player Player[ID])
|
||||||
PlayerLeaveWorldEventHandle[ID comparable] func(player Player[ID])
|
PlayerLeaveWorldEventHandle[ID comparable] func(player Player[ID])
|
||||||
ActorGeneratedEventHandle func(actor Actor)
|
ActorGeneratedEventHandle func(actor Actor)
|
||||||
|
|
Loading…
Reference in New Issue