From 6a9b48b4d36d56941e1853221bfafaed8c9e3755 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 12 Oct 2023 15:13:13 +0800 Subject: [PATCH] =?UTF-8?q?signal=203xh3=20=E9=A9=B1=E9=87=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/light.go | 1 + component/signal.go | 30 +++++++++++++-- entity/light.go | 9 +++++ entity/signal_3xh3.go | 8 ++++ fi/signal_3xh3.go | 37 ++++++------------ jl-ecs-go | 2 +- sys/circuit_sys/signal_3xh3.go | 70 ++++++++++++++++++++++++++-------- 7 files changed, 111 insertions(+), 46 deletions(-) diff --git a/component/light.go b/component/light.go index 8cfb011..4d62299 100644 --- a/component/light.go +++ b/component/light.go @@ -17,6 +17,7 @@ var ( UdTag = ecs.NewTag() //黄 BdTag = ecs.NewTag() //白 AdTag = ecs.NewTag() //蓝 + FdTag = ecs.NewTag() //封,封灯显示 ) // 组件 diff --git a/component/signal.go b/component/signal.go index a40f84d..d784b18 100644 --- a/component/signal.go +++ b/component/signal.go @@ -170,12 +170,34 @@ type Signal3XH3Electronic struct { Z3XH3_LXJ *ecs.Entry //引导信号继电器,true-吸合 Z3XH3_YXJ *ecs.Entry - // 物理黄灯,true-亮 - Z3XH3_U *ecs.Entry - // 物理红灯,true-亮 - Z3XH3_H *ecs.Entry +} + +// Signal3XH3Lsq 联锁驱 +type Signal3XH3Lsq struct { + //true-联锁施加励磁电流驱动继电器DDJ + Z3XH3_DDJ_Q bool + ////true-联锁施加励磁电流驱动继电器LXJ + Z3XH3_LXJ_Q bool + ////true-联锁施加励磁电流驱动继电器LXJ + Z3XH3_YXJ_Q bool +} + +// Signal3XH3Lsc 联锁采 +type Signal3XH3Lsc struct { + //true-继电器DJ吸起 + Z3XH3_DJ_Xq bool + //true-继电器2DJ吸起 + Z3XH3_2DJ_Xq bool + //true-继电器DDJ落下 + Z3XH3_DDJ_Lx bool + //true-继电器LXJ吸起 + Z3XH3_LXJ_Xq bool + //true-继电器YXJ吸起 + Z3XH3_YXJ_Xq bool } var ( Signal3XH3ElectronicType = ecs.NewComponentType[Signal3XH3Electronic]() + Signal3XH3LsqType = ecs.NewComponentType[Signal3XH3Lsq]() + Signal3XH3LscType = ecs.NewComponentType[Signal3XH3Lsc]() ) diff --git a/entity/light.go b/entity/light.go index d24f85c..2220245 100644 --- a/entity/light.go +++ b/entity/light.go @@ -55,3 +55,12 @@ func NewLights(w ecs.World, lightTags ...component.DsTag) []*ecs.Entry { } return ls } + +// IsLightFd 灯是否被封(如Signal 3xh3 红绿黄三显示封绿灯) +func IsLightFd(lightEntry *ecs.Entry) bool { + if lightEntry.HasComponent(component.LightDriveType) && lightEntry.HasComponent(component.BitStateType) { + return lightEntry.HasComponent(component.FdTag) + } else { + panic("IsLightFd 参数lightEntry的值非灯实体") + } +} diff --git a/entity/signal_3xh3.go b/entity/signal_3xh3.go index 3d3d92c..cc9a611 100644 --- a/entity/signal_3xh3.go +++ b/entity/signal_3xh3.go @@ -12,6 +12,9 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent if len(elecs) == 5 { //3xh3组合类型包含5个继电器 signalEntry.AddComponent(component.Signal3XH3ElectronicType) + signalEntry.AddComponent(component.Signal3XH3LsqType) + signalEntry.AddComponent(component.Signal3XH3LscType) + signalEntry.AddComponent(component.SignalLightsType) // elecState := &component.Signal3XH3Electronic{} for _, elec := range elecs { @@ -32,6 +35,11 @@ func loadSignal3xh3(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent } // component.Signal3XH3ElectronicType.Set(signalEntry, elecState) + component.Signal3XH3LsqType.Set(signalEntry, &component.Signal3XH3Lsq{}) + component.Signal3XH3LscType.Set(signalEntry, &component.Signal3XH3Lsc{}) + component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag)) + //封绿灯,即有绿灯但绿被封 + component.SignalLightsType.Get(signalEntry).GetLightByTag(component.LdTag).AddComponent(component.FdTag) } else { return fmt.Errorf("id=[%s]的信号机3xh3,电子元器件数量须为5", signal.Id()) } diff --git a/fi/signal_3xh3.go b/fi/signal_3xh3.go index a3d321c..2586e7e 100644 --- a/fi/signal_3xh3.go +++ b/fi/signal_3xh3.go @@ -15,11 +15,8 @@ func DriveSignal3XH3Dd(w ecs.World, signalId string, dd bool) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH3ElectronicType.Get(signalEntry) - driveDd := component.RelayDriveType.Get(state.Z3XH3_DDJ) - //点灯继电器落下时才点灯 - driveDd.Td = !dd - driveDd.Xq = !dd + lsq := component.Signal3XH3LsqType.Get(signalEntry) + lsq.Z3XH3_DDJ_Q = !dd } }) } @@ -30,13 +27,9 @@ func DriveSignal3XH3Lx(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH3ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) - driveLx.Td = true - driveLx.Xq = true - driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ) - driveYx.Td = false - driveYx.Xq = false + lsq := component.Signal3XH3LsqType.Get(signalEntry) + lsq.Z3XH3_LXJ_Q = true + lsq.Z3XH3_YXJ_Q = false } }) } @@ -47,13 +40,9 @@ func DriveSignal3XH3Yx(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH3ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) - driveLx.Td = false - driveLx.Xq = false - driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ) - driveYx.Td = true - driveYx.Xq = true + lsq := component.Signal3XH3LsqType.Get(signalEntry) + lsq.Z3XH3_LXJ_Q = false + lsq.Z3XH3_YXJ_Q = true } }) } @@ -64,13 +53,9 @@ func DriveSignal3XH3Non(w ecs.World, signalId string) { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { - state := component.Signal3XH3ElectronicType.Get(signalEntry) - driveLx := component.RelayDriveType.Get(state.Z3XH3_LXJ) - driveLx.Td = false - driveLx.Xq = false - driveYx := component.RelayDriveType.Get(state.Z3XH3_YXJ) - driveYx.Td = false - driveYx.Xq = false + lsq := component.Signal3XH3LsqType.Get(signalEntry) + lsq.Z3XH3_LXJ_Q = false + lsq.Z3XH3_YXJ_Q = false } }) } diff --git a/jl-ecs-go b/jl-ecs-go index af60502..1c6eed6 160000 --- a/jl-ecs-go +++ b/jl-ecs-go @@ -1 +1 @@ -Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c +Subproject commit 1c6eed67ea95b41e7b3cae7375f0f740202fd22b diff --git a/sys/circuit_sys/signal_3xh3.go b/sys/circuit_sys/signal_3xh3.go index 7fff239..7485fcf 100644 --- a/sys/circuit_sys/signal_3xh3.go +++ b/sys/circuit_sys/signal_3xh3.go @@ -16,49 +16,89 @@ func NewSignal3XH3System() *Signal3XH3System { // Update world 执行 func (s *Signal3XH3System) Update(w ecs.World) { - s.query.Each(w, func(e *ecs.Entry) { - state := component.Signal3XH3ElectronicType.Get(e) + s.query.Each(w, func(entry *ecs.Entry) { + state := component.Signal3XH3ElectronicType.Get(entry) + lsq := component.Signal3XH3LsqType.Get(entry) + lsc := component.Signal3XH3LscType.Get(entry) + lights := component.SignalLightsType.Get(entry) + Z3XH3_H := lights.GetLightByTag(component.HdTag) + Z3XH3_U := lights.GetLightByTag(component.UdTag) // - s.calculateU(state) - s.calculateH(state) - s.calculateDJ(state) - s.calculate2DJ(state) + s.calculateLsq(state, lsq) + s.calculateU(state, Z3XH3_U) + s.calculateH(state, Z3XH3_H) + s.calculateDJ(state, Z3XH3_U, Z3XH3_H) + s.calculate2DJ(state, Z3XH3_U) + s.calculateLsc(state, lsc) }) } -func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic) { +// 联锁驱 +func (s *Signal3XH3System) calculateLsq(state *component.Signal3XH3Electronic, lsq *component.Signal3XH3Lsq) { + ddj := component.RelayDriveType.Get(state.Z3XH3_DDJ) + lxj := component.RelayDriveType.Get(state.Z3XH3_LXJ) + yxj := component.RelayDriveType.Get(state.Z3XH3_YXJ) + // + ddjQ := lsq.Z3XH3_DDJ_Q + ddj.Td = ddjQ + ddj.Xq = ddjQ + // + lxjQ := lsq.Z3XH3_LXJ_Q + lxj.Td = lxjQ + lxj.Xq = lxjQ + // + yxjQ := lsq.Z3XH3_YXJ_Q + yxj.Td = yxjQ + yxj.Xq = yxjQ +} + +// 联锁采 +func (s *Signal3XH3System) calculateLsc(state *component.Signal3XH3Electronic, lsc *component.Signal3XH3Lsc) { + ddj := component.BitStateType.Get(state.Z3XH3_DDJ) + lxj := component.BitStateType.Get(state.Z3XH3_LXJ) + dj := component.BitStateType.Get(state.Z3XH3_DJ) + edj := component.BitStateType.Get(state.Z3XH3_2DJ) + yxj := component.BitStateType.Get(state.Z3XH3_YXJ) + // + lsc.Z3XH3_2DJ_Xq = edj.Val + lsc.Z3XH3_DJ_Xq = dj.Val + lsc.Z3XH3_DDJ_Lx = !ddj.Val + lsc.Z3XH3_LXJ_Xq = lxj.Val + lsc.Z3XH3_YXJ_Xq = yxj.Val +} +func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH3_DDJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ) dj := component.BitStateType.Get(state.Z3XH3_DJ) yxj := component.BitStateType.Get(state.Z3XH3_YXJ) isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val - driveU := component.LightDriveType.Get(state.Z3XH3_U) + driveU := component.LightDriveType.Get(Z3XH3_U) driveU.Td = isU } -func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic) { +func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic, Z3XH3_H *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH3_DDJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ) isH := !ddj.Val && !lxj.Val - driveH := component.LightDriveType.Get(state.Z3XH3_H) + driveH := component.LightDriveType.Get(Z3XH3_H) driveH.Td = isH } -func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic) { +func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry, Z3XH3_H *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH3_DDJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ) - ud := component.BitStateType.Get(state.Z3XH3_U) - hd := component.BitStateType.Get(state.Z3XH3_H) + ud := component.BitStateType.Get(Z3XH3_U) + hd := component.BitStateType.Get(Z3XH3_H) isDJ := ud.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val drive := component.RelayDriveType.Get(state.Z3XH3_DJ) drive.Td = isDJ drive.Xq = isDJ } -func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic) { +func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic, Z3XH3_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH3_DDJ) lxj := component.BitStateType.Get(state.Z3XH3_LXJ) dj := component.BitStateType.Get(state.Z3XH3_DJ) yxj := component.BitStateType.Get(state.Z3XH3_YXJ) - ud := component.BitStateType.Get(state.Z3XH3_U) + ud := component.BitStateType.Get(Z3XH3_U) is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val drive := component.RelayDriveType.Get(state.Z3XH3_2DJ) drive.Td = is2DJ