道岔系统
This commit is contained in:
parent
8d8791cdd6
commit
a4745d7a67
@ -18,14 +18,8 @@ var EntityTagHandlerComponent = ecs.NewComponentType[state.EntityTagHandler]()
|
||||
var PercentageDeviceComponent = ecs.NewComponentType[state.PercentageDeviceState]()
|
||||
var PercentageDeviceOperatingComponent = ecs.NewComponentType[state.PercentageDeviceOperating]()
|
||||
|
||||
// 道岔状态组件
|
||||
var SwitchStateComponent = ecs.NewComponentType[state.SwitchState]()
|
||||
|
||||
// 道岔定反操继电器动作组件
|
||||
var SwitchNRRelayOperatingComponent = ecs.NewComponentType[state.SwitchNRRelayOperating]()
|
||||
|
||||
// 道岔正常转动组件
|
||||
var SwitchTurnOperatingComponent = ecs.NewComponentType[state.SwitchTurnOperating]()
|
||||
// 道岔继电器状态组件
|
||||
var SwitchRelayStateComponent = ecs.NewComponentType[state.SwitchRelayState]()
|
||||
|
||||
// 物理区段状态组件
|
||||
var PhysicalSectionStateComponent = ecs.NewComponentType[state.PhysicalSectionState]()
|
||||
|
@ -26,7 +26,7 @@ func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
|
||||
|
||||
// 创建道岔实体
|
||||
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(components.DeviceIdentityComponent, components.SwitchStateComponent)
|
||||
return w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent)
|
||||
}
|
||||
|
||||
// 创建信号机实体
|
||||
|
@ -10,41 +10,21 @@ message DeviceIdentity{
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
//道岔状态
|
||||
message SwitchState{
|
||||
//道岔继电器状态
|
||||
message SwitchRelayState{
|
||||
//定操继电器
|
||||
//true-继电器吸合触发道岔转动到定位操作,当定操完成该继电器断开
|
||||
bool normalRelay = 1;
|
||||
//true-继电器吸合
|
||||
bool dcJ = 1;
|
||||
//反操继电器
|
||||
//true-继电器吸合触发道岔转动到反位操作,当反操完成该继电器断开
|
||||
bool reverseRelay = 2;
|
||||
//true-继电器吸合
|
||||
bool fcJ = 2;
|
||||
//定表继电器
|
||||
//true-继电器吸合表示道岔转动到定位
|
||||
bool normalTable = 3;
|
||||
bool dbJ = 3;
|
||||
//反表继电器
|
||||
//true-继电器吸合表示道岔转动到反位
|
||||
bool reverseTable = 4;
|
||||
}
|
||||
//道岔定反操继电器动作过程操作
|
||||
message SwitchNRRelayOperating{
|
||||
//true-定操继电器,false-反操继电器
|
||||
bool normal = 1;
|
||||
//启动定反操继电器
|
||||
bool start = 2;
|
||||
//该继电器动作剩余时间,单位ms
|
||||
int64 operateTime = 3;
|
||||
//true-吸合,false-断开
|
||||
bool close = 4;
|
||||
}
|
||||
//道岔转动操作
|
||||
message SwitchTurnOperating{
|
||||
//是否执行转动操作,true-开始执行或正在执行转动操作
|
||||
bool start = 1;
|
||||
//执行转动操作需要的剩余时长,单位ms
|
||||
int64 operateTime = 2;
|
||||
//执行转动操作的目标,true-道岔转向定位,false-道岔转向反位
|
||||
bool turnNormal = 3;
|
||||
}
|
||||
bool fbJ = 4;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -62,23 +62,6 @@ func debugSignal(w ecs.World) {
|
||||
|
||||
// 显示道岔状态
|
||||
func debugSwitch(w ecs.World) {
|
||||
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent))
|
||||
switchesQuery.Each(w, func(e *ecs.Entry) {
|
||||
id := components.DeviceIdentityComponent.Get(e).Id
|
||||
state := components.SwitchStateComponent.Get(e)
|
||||
fmt.Printf("==>>道岔[%s] ,定操Relay=%t ,反操Relay=%t ,定表Relay=%t ,反表Relay=%t ,", id, state.NormalRelay, state.ReverseRelay, state.NormalTable, state.ReverseTable)
|
||||
if e.HasComponent(components.SwitchNRRelayOperatingComponent) {
|
||||
nrOperation := components.SwitchNRRelayOperatingComponent.Get(e)
|
||||
if nrOperation.Normal {
|
||||
fmt.Printf("定操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close)
|
||||
} else {
|
||||
fmt.Printf("反操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close)
|
||||
}
|
||||
}
|
||||
if e.HasComponent(components.SwitchTurnOperatingComponent) {
|
||||
turnOperation := components.SwitchTurnOperatingComponent.Get(e)
|
||||
fmt.Printf("转动操作Start=%t ,转动到定位=%t ,剩余时间=%d", turnOperation.Start, turnOperation.TurnNormal, turnOperation.OperateTime)
|
||||
}
|
||||
fmt.Println()
|
||||
})
|
||||
//switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent))
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,9 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/components"
|
||||
"joylink.club/rtsssimulation/state"
|
||||
)
|
||||
|
||||
// 定反操继电器查询
|
||||
var nrRelayQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SwitchNRRelayOperatingComponent))
|
||||
|
||||
// 道岔转动查询
|
||||
var turningQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SwitchTurnOperatingComponent))
|
||||
|
||||
// 道岔状态查询
|
||||
var switchStateQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent))
|
||||
|
||||
// 道岔系统操作
|
||||
type SwitchSystem struct {
|
||||
}
|
||||
@ -29,96 +17,13 @@ func NewSwitchSystem() *SwitchSystem {
|
||||
// switchId: 道岔id
|
||||
// turnNormal: true-道岔转动到定位,false-道岔转动到反位
|
||||
func FireSwitchTurn(w ecs.World, switchId string, turnNormal bool) bool {
|
||||
var switchEntry *ecs.Entry = nil
|
||||
switchStateQuery.Each(w, func(e *ecs.Entry) {
|
||||
if id := components.DeviceIdentityComponent.Get(e).Id; id == switchId {
|
||||
switchEntry = e
|
||||
}
|
||||
})
|
||||
//
|
||||
if nil == switchEntry {
|
||||
return false
|
||||
}
|
||||
//
|
||||
switchState := components.SwitchStateComponent.Get(switchEntry)
|
||||
if turnNormal == switchState.NormalTable && !turnNormal == switchState.ReverseTable {
|
||||
return true
|
||||
}
|
||||
//
|
||||
nrRelayTime := getSwitchNRDelayTime(switchId)
|
||||
if !switchEntry.HasComponent(components.SwitchNRRelayOperatingComponent) {
|
||||
switchEntry.AddComponent(components.SwitchNRRelayOperatingComponent)
|
||||
}
|
||||
*(components.SwitchNRRelayOperatingComponent.Get(switchEntry)) = state.SwitchNRRelayOperating{Start: true, OperateTime: nrRelayTime, Close: true, Normal: turnNormal}
|
||||
//
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// world 执行
|
||||
func (me *SwitchSystem) Update(w ecs.World) {
|
||||
updateNormalReverseRelay(w)
|
||||
updateTurnOperating(w)
|
||||
}
|
||||
|
||||
// 道岔转动动作
|
||||
func updateTurnOperating(w ecs.World) {
|
||||
turningQuery.Each(w, func(e *ecs.Entry) {
|
||||
if !e.HasComponent(components.SwitchNRRelayOperatingComponent) {
|
||||
operation := components.SwitchTurnOperatingComponent.Get(e)
|
||||
switchState := components.SwitchStateComponent.Get(e)
|
||||
if operation.Start {
|
||||
if operation.OperateTime <= 0 {
|
||||
operation.Start = false
|
||||
switchState.NormalTable = operation.TurnNormal
|
||||
switchState.ReverseTable = !operation.TurnNormal
|
||||
switchState.NormalRelay = false
|
||||
switchState.ReverseRelay = false
|
||||
} else { //此时道岔失表
|
||||
operation.OperateTime -= int64(w.Tick())
|
||||
switchState.NormalTable = false
|
||||
switchState.ReverseTable = false
|
||||
}
|
||||
}
|
||||
if !operation.Start {
|
||||
e.RemoveComponent(components.SwitchTurnOperatingComponent)
|
||||
}
|
||||
} else {
|
||||
e.RemoveComponent(components.SwitchTurnOperatingComponent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 定反操继电器操作
|
||||
func updateNormalReverseRelay(w ecs.World) {
|
||||
nrRelayQuery.Each(w, func(e *ecs.Entry) {
|
||||
operation := components.SwitchNRRelayOperatingComponent.Get(e)
|
||||
if operation.Start {
|
||||
if operation.OperateTime <= 0 {
|
||||
operation.Start = false
|
||||
//
|
||||
switchState := components.SwitchStateComponent.Get(e)
|
||||
if operation.Normal {
|
||||
switchState.NormalRelay = operation.Close
|
||||
} else {
|
||||
switchState.ReverseRelay = operation.Close
|
||||
}
|
||||
//
|
||||
if operation.Close { //触发道岔转动操作
|
||||
if !e.HasComponent(components.SwitchTurnOperatingComponent) {
|
||||
e.AddComponent(components.SwitchTurnOperatingComponent)
|
||||
}
|
||||
switchId := components.DeviceIdentityComponent.Get(e).Id
|
||||
turnTime := getSwitchTurnTime(switchId)
|
||||
*(components.SwitchTurnOperatingComponent.Get(e)) = state.SwitchTurnOperating{Start: true, OperateTime: turnTime, TurnNormal: operation.Normal}
|
||||
}
|
||||
} else {
|
||||
operation.OperateTime -= int64(w.Tick())
|
||||
}
|
||||
}
|
||||
if !operation.Start {
|
||||
e.RemoveComponent(components.SwitchNRRelayOperatingComponent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取道岔转动耗时ms
|
||||
|
Loading…
Reference in New Issue
Block a user