rts-sim-module/component/singleton/world_time.go

38 lines
615 B
Go
Raw Normal View History

package singleton
import (
"time"
"joylink.club/ecs"
)
var WorldTimeType = ecs.NewComponentType[WorldTime]()
type WorldTime struct {
time int64
}
func (w *WorldTime) SetTime(t time.Time) {
w.time = t.UnixMilli()
}
// 增加时间
func (w *WorldTime) Run(ms int) {
w.time += int64(ms)
}
// 获取时间
func (w *WorldTime) GetTime() time.Time {
return time.UnixMilli(w.time)
}
2023-12-29 17:48:57 +08:00
// 获取时间戳ms
func (w *WorldTime) GetMilli() int64 {
return w.time
}
func LoadWorldTime(w ecs.World) {
entry := w.Entry(w.Create(WorldTimeType))
WorldTimeType.Set(entry, &WorldTime{time: time.Now().UnixMilli()})
}