46 lines
900 B
Go
46 lines
900 B
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"github.com/yohamta/donburi/filter"
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/components"
|
||
|
)
|
||
|
|
||
|
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComSystemTimer))
|
||
|
|
||
|
// 系统时钟操作
|
||
|
type TimerSystem struct {
|
||
|
}
|
||
|
|
||
|
func NewTimerSystem() *TimerSystem {
|
||
|
return &TimerSystem{}
|
||
|
}
|
||
|
|
||
|
// world 执行
|
||
|
func (me *TimerSystem) Update(w ecs.World) {
|
||
|
if e, ok := timerQuery.First(w); ok {
|
||
|
timer := components.ComSystemTimer.Get(e)
|
||
|
timer.Tick(w.Tick())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 重置world时间
|
||
|
func ResetWorldTimer(w ecs.World, time time.Time) {
|
||
|
if e, ok := timerQuery.First(w); ok {
|
||
|
timer := components.ComSystemTimer.Get(e)
|
||
|
timer.ResetTime(time)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 获取world当前时间
|
||
|
func GetWorldNow(w ecs.World) *time.Time {
|
||
|
if e, ok := timerQuery.First(w); ok {
|
||
|
timer := components.ComSystemTimer.Get(e)
|
||
|
now := timer.Now()
|
||
|
return &now
|
||
|
}
|
||
|
return nil
|
||
|
}
|