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

38 lines
613 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)
}
// 获取时间戳
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()})
}