54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package system
|
||
|
||
import (
|
||
"fmt"
|
||
"time"
|
||
|
||
"joylink.club/ecs"
|
||
"joylink.club/ecs/examples/rtss-cg/mwayside"
|
||
"joylink.club/ecs/examples/rtss-cg/simulation"
|
||
"joylink.club/ecs/filter"
|
||
)
|
||
|
||
type SwitchSystem struct {
|
||
ComQuery *ecs.Query
|
||
}
|
||
|
||
func (me *SwitchSystem) Update(w ecs.World) {
|
||
me.ComQuery.Each(w, func(e *ecs.Entry) {
|
||
switchId := simulation.ComId.Get(e).Id
|
||
state := simulation.ComSwitchState.Get(e)
|
||
fmt.Printf("==>>当前状态:道岔id=%s 定位=%t 反位=%t ", switchId, state.Normal, state.Reverse)
|
||
opt := simulation.ComSwitchOperating.Get(e)
|
||
if nil != opt && opt.EnableStart {
|
||
if time.Duration(time.Now().Second()-opt.StartTime.Second()) <= 4 {
|
||
fmt.Println(" ... 扳道中 ....")
|
||
} else {
|
||
opt.EnableStart = false
|
||
fmt.Println(" ... 完成扳道...")
|
||
state.Normal = !state.Normal
|
||
state.Reverse = !state.Reverse
|
||
}
|
||
} else {
|
||
fmt.Println()
|
||
}
|
||
})
|
||
|
||
}
|
||
func NewSwitchSystem() *SwitchSystem {
|
||
return &SwitchSystem{ComQuery: ecs.NewQuery(filter.Contains(simulation.ComId, simulation.ComSwitchOperating))}
|
||
}
|
||
|
||
// 判断点是否在该物理区段内
|
||
func ContainsPoint(me *mwayside.PhysicalSectionModel, linkId string, kilometerSign int64) bool {
|
||
if me.AxlePointPortA.(*mwayside.AxlePointModel).Link.GetId() != linkId || me.AxlePointPortB.(*mwayside.AxlePointModel).Link.GetId() != linkId {
|
||
return false
|
||
}
|
||
if me.Line {
|
||
return me.AxlePointPortA.(*mwayside.AxlePointModel).KilometerSign < kilometerSign && me.AxlePointPortB.(*mwayside.AxlePointModel).KilometerSign > kilometerSign
|
||
} else {
|
||
|
||
}
|
||
return true
|
||
}
|