umi 使用repository中model接口

This commit is contained in:
xzb 2023-09-21 17:04:28 +08:00
parent 1986b616ca
commit bbd7368fab
2 changed files with 22 additions and 21 deletions

View File

@ -22,6 +22,12 @@ func NewPercentageDeviceStateL() *PercentageDeviceState {
func NewPercentageDeviceStateM() *PercentageDeviceState {
return &PercentageDeviceState{V: 0, P: PD_M, R: 100}
}
func (me *PercentageDeviceState) isToL() bool {
return me.P <= PD_L
}
func (me *PercentageDeviceState) isToM() bool {
return me.P >= PD_M
}
// 百分比设备位置范围
const (
@ -47,34 +53,29 @@ func NewPercentageMovableSystem() *PercentageMovableSystem {
// Update world 执行
func (me *PercentageMovableSystem) Update(w ecs.World) {
me.query.Each(w, func(e *ecs.Entry) {
var state *PercentageDeviceState
if e.HasComponent(PercentageDeviceStateComponent) {
PercentageDeviceStateComponent.Get(e).move()
state = PercentageDeviceStateComponent.Get(e)
}
if e.HasComponent(PercentageDeviceState1Component) {
PercentageDeviceState1Component.Get(e).move()
state = PercentageDeviceState1Component.Get(e)
}
if e.HasComponent(PercentageDeviceState2Component) {
PercentageDeviceState2Component.Get(e).move()
state = PercentageDeviceState2Component.Get(e)
}
if state != nil {
me.move(w, state)
}
})
}
////////////////////////////////////////////////
func (me *PercentageDeviceState) move() {
me.P += me.V
if me.P < PD_L {
me.P = PD_L
func (me *PercentageMovableSystem) move(w ecs.World, state *PercentageDeviceState) {
state.P += state.V * int64(w.Tick())
if state.P < PD_L {
state.P = PD_L
}
if me.P > PD_M {
me.P = PD_M
if state.P > PD_M {
state.P = PD_M
}
//
me.R = int8((float64(me.P) / float64(PD_M)) * float64(100))
}
func (me *PercentageDeviceState) isToL() bool {
return me.P <= PD_L
}
func (me *PercentageDeviceState) isToM() bool {
return me.P >= PD_M
state.R = int8((float64(state.P) / float64(PD_M)) * float64(100))
}

View File

@ -612,10 +612,10 @@ func (me *Switch2jZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry,
// j.Value 0-反位 jRange-定位
func (me *Switch2jZdj9System) calculateMove(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
j1 := PercentageDeviceState1Component.Get(switchEntry)
j1.V = int64(state.J1_Traction) * 25 * int64(w.Tick())
j1.V = int64(state.J1_Traction) * 25
//
j2 := PercentageDeviceState2Component.Get(switchEntry)
j2.V = int64(state.J2_Traction) * 20 * int64(w.Tick())
j2.V = int64(state.J2_Traction) * 20
}
// 转辙机对外端子9、10运算