From 9a21c4bfd289fa143b0d2db3de2ffb7020926044 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 12 Oct 2023 16:59:08 +0800 Subject: [PATCH] =?UTF-8?q?signal=20dcxh=20=E9=A9=B1=E9=87=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/signal.go | 30 ++++++++++++++ component/signal_dcxh.go | 28 ------------- entity/signal_dcxh.go | 8 +++- fi/signal_dcxh.go | 12 ++---- sys/circuit_sys/signal_dcxh.go | 76 +++++++++++++++++++++++----------- 5 files changed, 92 insertions(+), 62 deletions(-) delete mode 100644 component/signal_dcxh.go diff --git a/component/signal.go b/component/signal.go index 7dde9c5..edff33b 100644 --- a/component/signal.go +++ b/component/signal.go @@ -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]() +) diff --git a/component/signal_dcxh.go b/component/signal_dcxh.go deleted file mode 100644 index 1a3da24..0000000 --- a/component/signal_dcxh.go +++ /dev/null @@ -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]() -) diff --git a/entity/signal_dcxh.go b/entity/signal_dcxh.go index 1f458de..8273770 100644 --- a/entity/signal_dcxh.go +++ b/entity/signal_dcxh.go @@ -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()) } diff --git a/fi/signal_dcxh.go b/fi/signal_dcxh.go index 901af8a..736b60a 100644 --- a/fi/signal_dcxh.go +++ b/fi/signal_dcxh.go @@ -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 } }) } diff --git a/sys/circuit_sys/signal_dcxh.go b/sys/circuit_sys/signal_dcxh.go index e3ff753..99d075e 100644 --- a/sys/circuit_sys/signal_dcxh.go +++ b/sys/circuit_sys/signal_dcxh.go @@ -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 }