rts-sim-module/component/singleton/world_time.go
walker c4bc8c640f 重构singleton组件及相关方法接口
调整repo目录结构和命名
初步开始重构仿真实体加载
2023-12-28 16:49:28 +08:00

38 lines
613 B
Go

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()})
}