33 lines
611 B
Go
33 lines
611 B
Go
package state
|
|
|
|
import "time"
|
|
|
|
// 此文件中为与设备无关的仿真系统自身的状态定义
|
|
|
|
// 系统时钟,单例
|
|
type SystemTimer struct {
|
|
timer *time.Time
|
|
}
|
|
|
|
// 以指定时间构建
|
|
func NewSystemTimer(time *time.Time) *SystemTimer {
|
|
return &SystemTimer{
|
|
timer: time,
|
|
}
|
|
}
|
|
|
|
// 重置时间
|
|
func (me *SystemTimer) ResetTime(time time.Time) {
|
|
*me.timer = time
|
|
}
|
|
|
|
// 获取当前时间的副本
|
|
func (me *SystemTimer) Now() time.Time {
|
|
return *me.timer
|
|
}
|
|
|
|
// tick系统时钟,单位ms
|
|
func (me *SystemTimer) Tick(tick int) {
|
|
*me.timer = me.timer.Add(time.Duration(tick) * time.Millisecond)
|
|
}
|