道岔
This commit is contained in:
parent
502001238b
commit
f35515eb05
@ -49,3 +49,6 @@ var TrainStateComponent = ecs.NewComponentType[cstate.TrainState]()
|
||||
|
||||
// 两档按钮/旋钮状态组件
|
||||
var TowPositionButtonStateComponent = ecs.NewComponentType[cstate.TowPositionButtonState]()
|
||||
|
||||
// 继电器状态组件
|
||||
var RelayStateComponent = ecs.NewComponentType[cstate.RelayState]()
|
||||
|
@ -103,10 +103,13 @@ func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(components.DeviceIdentityComponent, components.PhysicalSectionStateComponent)
|
||||
}
|
||||
|
||||
// 屏蔽门与其cell关系tag定义
|
||||
type PsdCellTag struct{}
|
||||
|
||||
// 创建站台单侧屏蔽门实体
|
||||
func CreatePsdEntity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent)
|
||||
components.EntityTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[struct{}]()})
|
||||
components.EntityTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[PsdCellTag]()})
|
||||
return e
|
||||
}
|
||||
|
||||
@ -129,3 +132,8 @@ func CreateTrainEntity(w ecs.World) *ecs.Entry {
|
||||
func CreateTowPosButtonEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent)
|
||||
}
|
||||
|
||||
// 创建继电器实体
|
||||
func CreateRelayEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(components.DeviceIdentityComponent, components.RelayStateComponent)
|
||||
}
|
||||
|
@ -27,10 +27,9 @@ func main() {
|
||||
Tick: 300,
|
||||
InitTime: time.Now(),
|
||||
Systems: []ecs.ISystem{
|
||||
system.NewSwitchControlSystem(),
|
||||
system.NewMovableDeviceSystem(),
|
||||
system.NewPercentageDeviceSystem(),
|
||||
system.NewSwitchRelaySystem(),
|
||||
system.NewSwitchSystem(),
|
||||
system.NewPsdSystem(),
|
||||
system.NewTimerSystem(),
|
||||
system.NewDebugSystem()},
|
||||
@ -109,6 +108,13 @@ func testPsdCellOpt(w ecs.World) {
|
||||
time.Sleep(10 * time.Second)
|
||||
operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
|
||||
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
|
||||
//
|
||||
time.Sleep(10 * time.Second)
|
||||
operate.FirePsdCellOperation(w, "psd2", "psd2Cell1", 0)
|
||||
operate.FirePsdCellOperation(w, "psd2", "psd2Cell2", 0)
|
||||
time.Sleep(10 * time.Second)
|
||||
operate.FirePsdCellOperation(w, "psd2", "psd2Cell1", 100-20)
|
||||
operate.FirePsdCellOperation(w, "psd2", "psd2Cell2", 100)
|
||||
}
|
||||
func testSwitchTurn(w ecs.World) {
|
||||
operate.FireSwitchFcj(w, "switch1")
|
||||
|
@ -1,49 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/components"
|
||||
)
|
||||
|
||||
// 控制道岔定操反操的执行过程
|
||||
type SwitchControlSystem struct {
|
||||
query *ecs.Query
|
||||
}
|
||||
|
||||
func NewSwitchControlSystem() *SwitchControlSystem {
|
||||
return &SwitchControlSystem{query: ecs.NewQuery(filter.Contains(components.SwitchControlStateComponent))}
|
||||
}
|
||||
|
||||
// world 执行
|
||||
func (me *SwitchControlSystem) Update(w ecs.World) {
|
||||
me.query.Each(w, func(e *ecs.Entry) {
|
||||
control := components.SwitchControlStateComponent.Get(e)
|
||||
if control.FireDcj || control.FireFcj {
|
||||
relay := components.SwitchRelayStateComponent.Get(e)
|
||||
percent := components.PercentageDeviceStateComponent.Get(e)
|
||||
movable := components.MovableDeviceStateComponent.Get(e)
|
||||
//
|
||||
relay.DcJ = false
|
||||
relay.FcJ = false
|
||||
relay.DbJ = false
|
||||
relay.FbJ = false
|
||||
//
|
||||
movable.Speed = CalculateRateSpeed(int32(w.Tick()), control.LhDistance)
|
||||
//
|
||||
if control.FireDcj {
|
||||
relay.DcJ = true
|
||||
movable.ToH = false
|
||||
percent.Target = SwitchNormalVaule
|
||||
}
|
||||
if control.FireFcj {
|
||||
relay.FcJ = true
|
||||
movable.ToH = true
|
||||
percent.Target = SwitchReverseValue
|
||||
}
|
||||
//
|
||||
control.FireDcj = false
|
||||
control.FireFcj = false
|
||||
}
|
||||
})
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/components"
|
||||
)
|
||||
|
||||
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent))
|
||||
|
||||
const (
|
||||
//道岔定位
|
||||
SwitchNormalVaule int64 = PercentageRateValueMin
|
||||
//道岔反位
|
||||
SwitchReverseValue int64 = PercentageRateValueMax
|
||||
)
|
||||
|
||||
// 道岔系统操作
|
||||
type SwitchRelaySystem struct {
|
||||
}
|
||||
|
||||
func NewSwitchRelaySystem() *SwitchRelaySystem {
|
||||
return &SwitchRelaySystem{}
|
||||
}
|
||||
|
||||
// world 执行
|
||||
// 观察道岔百分比组件来更新道岔逻辑继电器状态
|
||||
func (me *SwitchRelaySystem) Update(w ecs.World) {
|
||||
SwitchQuery.Each(w, func(e *ecs.Entry) {
|
||||
switchPercent := components.PercentageDeviceStateComponent.Get(e)
|
||||
switchRelay := components.SwitchRelayStateComponent.Get(e)
|
||||
if switchPercent.Rate == switchPercent.Target {
|
||||
switchRelay.DcJ = false
|
||||
switchRelay.FcJ = false
|
||||
switchRelay.DbJ = switchPercent.Rate <= SwitchNormalVaule
|
||||
switchRelay.FbJ = switchPercent.Rate >= SwitchReverseValue
|
||||
} else {
|
||||
switchRelay.DbJ = false
|
||||
switchRelay.FbJ = false
|
||||
}
|
||||
})
|
||||
}
|
76
system/switch_system.go
Normal file
76
system/switch_system.go
Normal file
@ -0,0 +1,76 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/components"
|
||||
)
|
||||
|
||||
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent))
|
||||
|
||||
const (
|
||||
//道岔定位
|
||||
SwitchNormalVaule int64 = PercentageRateValueMin
|
||||
//道岔反位
|
||||
SwitchReverseValue int64 = PercentageRateValueMax
|
||||
)
|
||||
|
||||
// 道岔系统操作
|
||||
type SwitchSystem struct {
|
||||
//道岔定反操控制查询
|
||||
queryDfc *ecs.Query
|
||||
}
|
||||
|
||||
func NewSwitchSystem() *SwitchSystem {
|
||||
return &SwitchSystem{
|
||||
queryDfc: ecs.NewQuery(filter.Contains(components.SwitchControlStateComponent)),
|
||||
}
|
||||
}
|
||||
|
||||
// world 执行
|
||||
func (me *SwitchSystem) Update(w ecs.World) {
|
||||
//控制道岔定操反操的执行过程
|
||||
me.queryDfc.Each(w, func(e *ecs.Entry) {
|
||||
control := components.SwitchControlStateComponent.Get(e)
|
||||
if control.FireDcj || control.FireFcj {
|
||||
relay := components.SwitchRelayStateComponent.Get(e)
|
||||
percent := components.PercentageDeviceStateComponent.Get(e)
|
||||
movable := components.MovableDeviceStateComponent.Get(e)
|
||||
//
|
||||
relay.DcJ = false
|
||||
relay.FcJ = false
|
||||
relay.DbJ = false
|
||||
relay.FbJ = false
|
||||
//
|
||||
movable.Speed = CalculateRateSpeed(int32(w.Tick()), control.LhDistance)
|
||||
//
|
||||
if control.FireDcj {
|
||||
relay.DcJ = true
|
||||
movable.ToH = false
|
||||
percent.Target = SwitchNormalVaule
|
||||
}
|
||||
if control.FireFcj {
|
||||
relay.FcJ = true
|
||||
movable.ToH = true
|
||||
percent.Target = SwitchReverseValue
|
||||
}
|
||||
//
|
||||
control.FireDcj = false
|
||||
control.FireFcj = false
|
||||
}
|
||||
})
|
||||
//观察道岔百分比组件来更新道岔逻辑继电器状态
|
||||
SwitchQuery.Each(w, func(e *ecs.Entry) {
|
||||
switchPercent := components.PercentageDeviceStateComponent.Get(e)
|
||||
switchRelay := components.SwitchRelayStateComponent.Get(e)
|
||||
if switchPercent.Rate == switchPercent.Target {
|
||||
switchRelay.DcJ = false
|
||||
switchRelay.FcJ = false
|
||||
switchRelay.DbJ = switchPercent.Rate <= SwitchNormalVaule
|
||||
switchRelay.FbJ = switchPercent.Rate >= SwitchReverseValue
|
||||
} else {
|
||||
switchRelay.DbJ = false
|
||||
switchRelay.FbJ = false
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user