signal dcxh 驱采
This commit is contained in:
parent
a1beb531a6
commit
9a21c4bfd2
@ -243,3 +243,33 @@ var (
|
||||
Signal3XH4LsqType = ecs.NewComponentType[Signal3XH4Lsq]()
|
||||
Signal3XH4LscType = ecs.NewComponentType[Signal3XH4Lsc]()
|
||||
)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// SignalDCXHElectronic 电路状态:信号机DCXH(蓝-白) 调车信号机
|
||||
type SignalDCXHElectronic struct {
|
||||
//灯丝继电器,true-吸合
|
||||
DCXH_DJ *ecs.Entry
|
||||
//调车信号继电器,true-吸合
|
||||
DCXH_DXJ *ecs.Entry
|
||||
}
|
||||
|
||||
// SignalDCXHLsq 联锁驱
|
||||
type SignalDCXHLsq struct {
|
||||
////true-联锁施加励磁电流驱动继电器DXJ
|
||||
DCXH_DXJ_Q bool
|
||||
}
|
||||
|
||||
// SignalDCXHLsc 联锁采
|
||||
type SignalDCXHLsc struct {
|
||||
//true-继电器DJ吸起
|
||||
DCXH_DJ_Xq bool
|
||||
//true-继电器DXJ吸起
|
||||
DCXH_DXJ_Xq bool
|
||||
}
|
||||
|
||||
var (
|
||||
SignalDCXHElectronicType = ecs.NewComponentType[SignalDCXHElectronic]()
|
||||
SignalDCXHLsqType = ecs.NewComponentType[SignalDCXHLsq]()
|
||||
SignalDCXHLscType = ecs.NewComponentType[SignalDCXHLsc]()
|
||||
)
|
||||
|
@ -1,28 +0,0 @@
|
||||
package component
|
||||
|
||||
import "joylink.club/ecs"
|
||||
|
||||
// SignalDCXHElectronic 电路状态:信号机DCXH(蓝-白) 调车信号机
|
||||
type SignalDCXHElectronic struct {
|
||||
//灯丝继电器,true-吸合
|
||||
DCXH_DJ *ecs.Entry
|
||||
//调车信号继电器,true-吸合
|
||||
DCXH_DXJ *ecs.Entry
|
||||
}
|
||||
|
||||
// SignalDCXHFilament 信号机DCXH 灯丝状态
|
||||
type SignalDCXHFilament struct {
|
||||
// 物理白灯,true-灯丝正常
|
||||
Bf bool
|
||||
// 物理蓝灯,true-灯丝正常
|
||||
Af bool
|
||||
// 物理白灯,true-亮
|
||||
B bool
|
||||
// 物理蓝灯,true-亮
|
||||
A bool
|
||||
}
|
||||
|
||||
var (
|
||||
SignalDCXHElectronicType = ecs.NewComponentType[SignalDCXHElectronic]()
|
||||
SignalDCXHFilamentType = ecs.NewComponentType[SignalDCXHFilament]()
|
||||
)
|
@ -12,7 +12,9 @@ func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
|
||||
|
||||
if len(elecs) == 2 { //dcxh组合类型包含2个继电器
|
||||
signalEntry.AddComponent(component.SignalDCXHElectronicType)
|
||||
signalEntry.AddComponent(component.SignalDCXHFilamentType)
|
||||
signalEntry.AddComponent(component.SignalDCXHLsqType)
|
||||
signalEntry.AddComponent(component.SignalDCXHLscType)
|
||||
signalEntry.AddComponent(component.SignalLightsType)
|
||||
//
|
||||
elecState := &component.SignalDCXHElectronic{}
|
||||
for _, elec := range elecs {
|
||||
@ -27,7 +29,9 @@ func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
|
||||
}
|
||||
//
|
||||
component.SignalDCXHElectronicType.Set(signalEntry, elecState)
|
||||
component.SignalDCXHFilamentType.Set(signalEntry, &component.SignalDCXHFilament{Bf: true, Af: true, B: false, A: false})
|
||||
component.SignalDCXHLsqType.Set(signalEntry, &component.SignalDCXHLsq{})
|
||||
component.SignalDCXHLscType.Set(signalEntry, &component.SignalDCXHLsc{})
|
||||
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.AdTag, component.BdTag))
|
||||
} else {
|
||||
return fmt.Errorf("id=[%s]的信号机dcxh,电子元器件数量须为2", signal.Id())
|
||||
}
|
||||
|
@ -14,10 +14,8 @@ func DriveSignalDCXHDx(w ecs.World, signalId string) {
|
||||
wd := entity.GetWorldData(w)
|
||||
signalEntry, ok := wd.EntityMap[signalId]
|
||||
if ok {
|
||||
state := component.SignalDCXHElectronicType.Get(signalEntry)
|
||||
driveDx := component.RelayDriveType.Get(state.DCXH_DXJ)
|
||||
driveDx.Td = true
|
||||
driveDx.Xq = true
|
||||
lsq := component.SignalDCXHLsqType.Get(signalEntry)
|
||||
lsq.DCXH_DXJ_Q = true
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -28,10 +26,8 @@ func DriveSignalDCXHNon(w ecs.World, signalId string) {
|
||||
wd := entity.GetWorldData(w)
|
||||
signalEntry, ok := wd.EntityMap[signalId]
|
||||
if ok {
|
||||
state := component.SignalDCXHElectronicType.Get(signalEntry)
|
||||
driveDx := component.RelayDriveType.Get(state.DCXH_DXJ)
|
||||
driveDx.Td = false
|
||||
driveDx.Xq = false
|
||||
lsq := component.SignalDCXHLsqType.Get(signalEntry)
|
||||
lsq.DCXH_DXJ_Q = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -11,41 +11,69 @@ type SignalDCXHSystem struct {
|
||||
}
|
||||
|
||||
func NewSignalDCXHSystem() *SignalDCXHSystem {
|
||||
return &SignalDCXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalDCXHElectronicType, component.SignalDCXHFilamentType))}
|
||||
return &SignalDCXHSystem{query: ecs.NewQuery(filter.Contains(
|
||||
component.SignalDCXHElectronicType,
|
||||
component.SignalDCXHLsqType,
|
||||
component.SignalDCXHLscType,
|
||||
component.SignalLightsType))}
|
||||
}
|
||||
|
||||
// Update world 执行
|
||||
func (s *SignalDCXHSystem) Update(w ecs.World) {
|
||||
s.query.Each(w, func(e *ecs.Entry) {
|
||||
state := component.SignalDCXHElectronicType.Get(e)
|
||||
filament := component.SignalDCXHFilamentType.Get(e)
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
state := component.SignalDCXHElectronicType.Get(entry)
|
||||
lsq := component.SignalDCXHLsqType.Get(entry)
|
||||
lsc := component.SignalDCXHLscType.Get(entry)
|
||||
lights := component.SignalLightsType.Get(entry)
|
||||
DCXH_A := lights.GetLightByTag(component.AdTag)
|
||||
DCXH_B := lights.GetLightByTag(component.BdTag)
|
||||
//
|
||||
s.calculateA(state, filament)
|
||||
s.calculateB(state, filament)
|
||||
s.calculateDJ(state, filament)
|
||||
s.calculateLsq(state, lsq)
|
||||
s.calculateA(state, DCXH_A)
|
||||
s.calculateB(state, DCXH_B)
|
||||
s.calculateDJ(state, DCXH_B, DCXH_A)
|
||||
s.calculateLsc(state, lsc)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (s *SignalDCXHSystem) calculateB(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
isB := filament.Bf && dxj.Val
|
||||
filament.B = isB
|
||||
// 联锁驱
|
||||
func (s *SignalDCXHSystem) calculateLsq(state *component.SignalDCXHElectronic, lsq *component.SignalDCXHLsq) {
|
||||
dxj := component.RelayDriveType.Get(state.DCXH_DXJ)
|
||||
//
|
||||
ddjQ := lsq.DCXH_DXJ_Q
|
||||
dxj.Td = ddjQ
|
||||
dxj.Xq = ddjQ
|
||||
}
|
||||
|
||||
func (s *SignalDCXHSystem) calculateA(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
isA := filament.Af && !dxj.Val
|
||||
filament.A = isA
|
||||
}
|
||||
|
||||
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
|
||||
// 联锁采
|
||||
func (s *SignalDCXHSystem) calculateLsc(state *component.SignalDCXHElectronic, lsc *component.SignalDCXHLsc) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
dj := component.BitStateType.Get(state.DCXH_DJ)
|
||||
isDJ := filament.Bf && dxj.Val || filament.Af && !dxj.Val
|
||||
if isDJ != dj.Val {
|
||||
drive := component.RelayDriveType.Get(state.DCXH_DJ)
|
||||
drive.Td = isDJ
|
||||
drive.Xq = isDJ
|
||||
}
|
||||
//
|
||||
lsc.DCXH_DJ_Xq = dj.Val
|
||||
lsc.DCXH_DXJ_Xq = dxj.Val
|
||||
}
|
||||
func (s *SignalDCXHSystem) calculateB(state *component.SignalDCXHElectronic, DCXH_B *ecs.Entry) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
isB := dxj.Val
|
||||
driveB := component.LightDriveType.Get(DCXH_B)
|
||||
driveB.Td = isB
|
||||
}
|
||||
|
||||
func (s *SignalDCXHSystem) calculateA(state *component.SignalDCXHElectronic, DCXH_A *ecs.Entry) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
isA := !dxj.Val
|
||||
driveA := component.LightDriveType.Get(DCXH_A)
|
||||
driveA.Td = isA
|
||||
}
|
||||
|
||||
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, DCXH_B *ecs.Entry, DCXH_A *ecs.Entry) {
|
||||
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
||||
ad := component.BitStateType.Get(DCXH_A)
|
||||
bd := component.BitStateType.Get(DCXH_B)
|
||||
isDJ := bd.Val && dxj.Val || ad.Val && !dxj.Val
|
||||
drive := component.RelayDriveType.Get(state.DCXH_DJ)
|
||||
drive.Td = isDJ
|
||||
drive.Xq = isDJ
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user