rts-sim-module/system/timer_system.go

46 lines
924 B
Go
Raw Normal View History

2023-08-15 16:50:24 +08:00
package system
import (
"time"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
2023-08-18 10:06:17 +08:00
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SystemTimerComponent))
2023-08-15 16:50:24 +08:00
// 系统时钟操作
type TimerSystem struct {
}
func NewTimerSystem() *TimerSystem {
return &TimerSystem{}
}
// world 执行
func (me *TimerSystem) Update(w ecs.World) {
if e, ok := timerQuery.First(w); ok {
2023-08-18 10:06:17 +08:00
timer := components.SystemTimerComponent.Get(e)
2023-08-15 16:50:24 +08:00
timer.Tick(w.Tick())
}
}
// 重置world时间
func ResetWorldTimer(w ecs.World, time time.Time) {
if e, ok := timerQuery.First(w); ok {
2023-08-18 10:06:17 +08:00
timer := components.SystemTimerComponent.Get(e)
2023-08-15 16:50:24 +08:00
timer.ResetTime(time)
}
}
// 获取world当前时间
func GetWorldNow(w ecs.World) *time.Time {
if e, ok := timerQuery.First(w); ok {
2023-08-18 10:06:17 +08:00
timer := components.SystemTimerComponent.Get(e)
2023-08-15 16:50:24 +08:00
now := timer.Now()
return &now
}
return nil
}