From a2e9b4771da730a20a348487ddcd1553a2af8f43 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 27 Sep 2023 15:27:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=97=A8=E6=8E=A7=E7=AE=B1=E7=94=B5?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/dcb_system.go | 246 +++++++++++++++++++++++++++++++++++ system/event/button_event.go | 3 + 2 files changed, 249 insertions(+) create mode 100644 system/dcb_system.go create mode 100644 system/event/button_event.go diff --git a/system/dcb_system.go b/system/dcb_system.go new file mode 100644 index 0000000..9974f64 --- /dev/null +++ b/system/dcb_system.go @@ -0,0 +1,246 @@ +package system + +import ( + "github.com/yohamta/donburi/filter" + "joylink.club/ecs" +) + +// DcbCircuitState 门控箱电路 A---按钮 J---继电器 +type DcbCircuitState struct { + //下行站台门关闭继电器,true-继电器吸起 + XPCBJ bool + //ture-按钮开关接通常开点 + MKX5_PCB5A bool + //ture-按钮开关接通常开点 + MKX5_PCB5_MKXPL5A bool + //ture-按钮开关接通常开点 + MKX3_PCB3A bool + //ture-按钮开关接通常开点 + MKX3_PCB3_MKXPL3A bool + //ture-按钮开关接通常开点 + MKX1_PCB1A bool + //ture-按钮开关接通常开点 + MKX1_PCB1_MKXPL1A bool + + //下行站台门打开继电器,true-继电器吸起 + XPOBJ bool + //ture-按钮开关接通常开点 + MKX5_POB5A bool + //ture-按钮开关接通常开点 + MKX5_POB5_MKXPL5A bool + //ture-按钮开关接通常开点 + MKX3_POB3A bool + //ture-按钮开关接通常开点 + MKX3_POB3_MKXPL3A bool + //ture-按钮开关接通常开点 + MKX1_POB1A bool + //ture-按钮开关接通常开点 + MKX1_POB1_MKXPL1A bool + + //下行站台确认继电器,true-继电器吸起 + XPABJ bool + //ture-按钮开关接通常开点 + MKX5_PAB5A bool + //ture-按钮开关接通常开点 + MKX5_PAB5_MKXPL5A bool + //ture-按钮开关接通常开点 + MKX3_PAB3A bool + //ture-按钮开关接通常开点 + MKX3_PAB3_MKXPL3A bool + //ture-按钮开关接通常开点 + MKX1_PAB1A bool + //ture-按钮开关接通常开点 + MKX1_PAB1_MKXPL1A bool + + //上行站台门关闭继电器,true-继电器吸起 + SPCBJ bool + //ture-按钮开关接通常开点 + MKX6_PCB6A bool + //ture-按钮开关接通常开点 + MKX6_PCB6_MKXPL6A bool + //ture-按钮开关接通常开点 + MKX4_PCB4A bool + //ture-按钮开关接通常开点 + MKX4_PCB4_MKXPL4A bool + //ture-按钮开关接通常开点 + MKX2_PCB2A bool + //ture-按钮开关接通常开点 + MKX2_PCB2_MKXPL2A bool + + //上行站台门开门继电器,true-继电器吸起 + SPOBJ bool + //ture-按钮开关接通常开点 + MKX6_POB6A bool + //ture-按钮开关接通常开点 + MKX6_POB6_MKXPL6A bool + //ture-按钮开关接通常开点 + MKX4_POB4A bool + //ture-按钮开关接通常开点 + MKX4_POB4_MKXPL4A bool + //ture-按钮开关接通常开点 + MKX2_POB2A bool + //ture-按钮开关接通常开点 + MKX2_POB2_MKXPL2A bool + + //上行站台门开门继电器,true-继电器吸起 + SPABJ bool + //ture-按钮开关接通常开点 + MKX6_PAB6A bool + //ture-按钮开关接通常开点 + MKX6_PAB6_MKXPL6A bool + //ture-按钮开关接通常开点 + MKX4_PAB4A bool + //ture-按钮开关接通常开点 + MKX4_PAB4_MKXPL4A bool + //ture-按钮开关接通常开点 + MKX2_PAB2A bool + //ture-按钮开关接通常开点 + MKX2_PAB2_MKXPL2A bool +} + +var DcbCircuitStateComponent = ecs.NewComponentType[DcbCircuitState]() + +type DcbCircuitSystem struct { + query *ecs.Query +} + +func NewDcbCircuitState() *DcbCircuitState { + return &DcbCircuitState{ + //下行站台门关闭继电器,true-继电器吸起 + XPCBJ: false, + //ture-按钮开关接通常开点 + MKX5_PCB5A: false, + //ture-按钮开关接通常开点 + MKX5_PCB5_MKXPL5A: true, + //ture-按钮开关接通常开点 + MKX3_PCB3A: false, + //ture-按钮开关接通常开点 + MKX3_PCB3_MKXPL3A: true, + //ture-按钮开关接通常开点 + MKX1_PCB1A: false, + //ture-按钮开关接通常开点 + MKX1_PCB1_MKXPL1A: true, + + //下行站台门打开继电器,true-继电器吸起 + XPOBJ: false, + //ture-按钮开关接通常开点 + MKX5_POB5A: false, + //ture-按钮开关接通常开点 + MKX5_POB5_MKXPL5A: true, + //ture-按钮开关接通常开点 + MKX3_POB3A: false, + //ture-按钮开关接通常开点 + MKX3_POB3_MKXPL3A: true, + //ture-按钮开关接通常开点 + MKX1_POB1A: false, + //ture-按钮开关接通常开点 + MKX1_POB1_MKXPL1A: true, + + //下行站台确认继电器,true-继电器吸起 + XPABJ: false, + //ture-按钮开关接通常开点 + MKX5_PAB5A: false, + //ture-按钮开关接通常开点 + MKX5_PAB5_MKXPL5A: true, + //ture-按钮开关接通常开点 + MKX3_PAB3A: false, + //ture-按钮开关接通常开点 + MKX3_PAB3_MKXPL3A: true, + //ture-按钮开关接通常开点 + MKX1_PAB1A: false, + //ture-按钮开关接通常开点 + MKX1_PAB1_MKXPL1A: true, + + //上行站台门关闭继电器,true-继电器吸起 + SPCBJ: false, + //ture-按钮开关接通常开点 + MKX6_PCB6A: false, + //ture-按钮开关接通常开点 + MKX6_PCB6_MKXPL6A: true, + //ture-按钮开关接通常开点 + MKX4_PCB4A: false, + //ture-按钮开关接通常开点 + MKX4_PCB4_MKXPL4A: true, + //ture-按钮开关接通常开点 + MKX2_PCB2A: false, + //ture-按钮开关接通常开点 + MKX2_PCB2_MKXPL2A: true, + + //上行站台门开门继电器,true-继电器吸起 + SPOBJ: false, + //ture-按钮开关接通常开点 + MKX6_POB6A: false, + //ture-按钮开关接通常开点 + MKX6_POB6_MKXPL6A: true, + //ture-按钮开关接通常开点 + MKX4_POB4A: false, + //ture-按钮开关接通常开点 + MKX4_POB4_MKXPL4A: true, + //ture-按钮开关接通常开点 + MKX2_POB2A: false, + //ture-按钮开关接通常开点 + MKX2_POB2_MKXPL2A: true, + + //上行站台门开门继电器,true-继电器吸起 + SPABJ: false, + //ture-按钮开关接通常开点 + MKX6_PAB6A: false, + //ture-按钮开关接通常开点 + MKX6_PAB6_MKXPL6A: true, + //ture-按钮开关接通常开点 + MKX4_PAB4A: false, + //ture-按钮开关接通常开点 + MKX4_PAB4_MKXPL4A: true, + //ture-按钮开关接通常开点 + MKX2_PAB2A: false, + //ture-按钮开关接通常开点 + MKX2_PAB2_MKXPL2A: true, + } +} +func NewDcbCircuitSystem() *DcbCircuitSystem { + return &DcbCircuitSystem{query: ecs.NewQuery(filter.Contains(DcbCircuitStateComponent))} +} + +// Update world 执行 +func (me *DcbCircuitSystem) Update(w ecs.World) { + me.query.Each(w, func(e *ecs.Entry) { + state := DcbCircuitStateComponent.Get(e) + // + me.calculateXPCBJ(state) + me.calculateXPOBJ(state) + me.calculateXPABJ(state) + me.calculateSPCBJ(state) + me.calculateSPOBJ(state) + me.calculateSPABJ(state) + }) +} +func (me *DcbCircuitSystem) calculateXPCBJ(state *DcbCircuitState) { + state.XPCBJ = state.MKX5_PCB5A && state.MKX5_PCB5_MKXPL5A || + state.MKX3_PCB3A && state.MKX3_PCB3_MKXPL3A || + state.MKX1_PCB1A && state.MKX1_PCB1_MKXPL1A +} +func (me *DcbCircuitSystem) calculateXPOBJ(state *DcbCircuitState) { + state.XPOBJ = state.MKX5_POB5A && state.MKX5_POB5_MKXPL5A || + state.MKX3_POB3A && state.MKX3_POB3_MKXPL3A || + state.MKX1_POB1A && state.MKX1_POB1_MKXPL1A +} +func (me *DcbCircuitSystem) calculateXPABJ(state *DcbCircuitState) { + state.XPABJ = state.MKX5_PAB5A && state.MKX5_PAB5_MKXPL5A || + state.MKX3_PAB3A && state.MKX3_PAB3_MKXPL3A || + state.MKX1_PAB1A && state.MKX1_PAB1_MKXPL1A +} +func (me *DcbCircuitSystem) calculateSPCBJ(state *DcbCircuitState) { + state.SPCBJ = state.MKX6_PCB6A && state.MKX6_PCB6_MKXPL6A || + state.MKX4_PCB4A && state.MKX4_PCB4_MKXPL4A || + state.MKX2_PCB2A && state.MKX2_PCB2_MKXPL2A +} +func (me *DcbCircuitSystem) calculateSPOBJ(state *DcbCircuitState) { + state.SPOBJ = state.MKX6_POB6A && state.MKX6_POB6_MKXPL6A || + state.MKX4_POB4A && state.MKX4_POB4_MKXPL4A || + state.MKX2_POB2A && state.MKX2_POB2_MKXPL2A +} +func (me *DcbCircuitSystem) calculateSPABJ(state *DcbCircuitState) { + state.SPABJ = state.MKX6_PAB6A && state.MKX6_PAB6_MKXPL6A || + state.MKX4_PAB4A && state.MKX4_PAB4_MKXPL4A || + state.MKX2_PAB2A && state.MKX2_PAB2_MKXPL2A +} diff --git a/system/event/button_event.go b/system/event/button_event.go new file mode 100644 index 0000000..2ccf600 --- /dev/null +++ b/system/event/button_event.go @@ -0,0 +1,3 @@ +package sysEvent + +//广义按钮相关事件 From 7bc8d247a49e45bb6ad47c0a3b1163386fdedf5b Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 27 Sep 2023 15:34:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=97=A8=E6=8E=A7?= =?UTF-8?q?=E7=AE=B1=E7=94=B5=E8=B7=AF=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/dcb_entity.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 entities/dcb_entity.go diff --git a/entities/dcb_entity.go b/entities/dcb_entity.go new file mode 100644 index 0000000..57d24a4 --- /dev/null +++ b/entities/dcb_entity.go @@ -0,0 +1,14 @@ +package entities + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/system" +) + +// CreateDcbCircuitEntity 创建门控箱电路实体 +func CreateDcbCircuitEntity(w ecs.World, dcbCircuitId string) *ecs.Entry { + e := w.Create(system.EntityIdentityComponent, system.DcbCircuitStateComponent) + system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: dcbCircuitId}) + system.DcbCircuitStateComponent.Set(e, system.NewDcbCircuitState()) + return e +} From 899deff8b06763661bd3a26375c45874972a5710 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 27 Sep 2023 16:16:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/button_entity.go | 23 ++++++++++++++++++ system/button_system.go | 50 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 entities/button_entity.go diff --git a/entities/button_entity.go b/entities/button_entity.go new file mode 100644 index 0000000..4a20b16 --- /dev/null +++ b/entities/button_entity.go @@ -0,0 +1,23 @@ +package entities + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/system" +) + +// CreateSelfResetButtonEntity 创建自复位按钮实体 +func CreateSelfResetButtonEntity(w ecs.World, buttonId string) *ecs.Entry { + e := w.Create(system.EntityIdentityComponent, system.ButtonStateComponent, system.ButtonSelfRestTag) + system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: buttonId}) + system.ButtonStateComponent.Set(e, system.NewButtonState()) + system.ButtonSelfRestTag.Set(e, &system.ButtonSelfRestState{KeepAxTime: 0}) + return e +} + +// CreateNonResetButtonEntity 创建非自复位按钮实体 +func CreateNonResetButtonEntity(w ecs.World, buttonId string) *ecs.Entry { + e := w.Create(system.EntityIdentityComponent, system.ButtonStateComponent, system.ButtonNonRestTag) + system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: buttonId}) + system.ButtonStateComponent.Set(e, system.NewButtonState()) + return e +} diff --git a/system/button_system.go b/system/button_system.go index 65e78be..5fa86b5 100644 --- a/system/button_system.go +++ b/system/button_system.go @@ -1,6 +1,9 @@ package system -import "joylink.club/ecs" +import ( + "github.com/yohamta/donburi/filter" + "joylink.club/ecs" +) // ButtonState 广义按钮开关状态,开关有三个接点,分别为公共接点、常开点和常闭点 type ButtonState struct { @@ -8,6 +11,51 @@ type ButtonState struct { Ckd bool } +// ButtonSelfRestState 广义自复位按钮,复位状态 +type ButtonSelfRestState struct { + //自复位按钮保持按下剩余时间,ms + KeepAxTime int64 +} + var ( ButtonStateComponent = ecs.NewComponentType[ButtonState]() + ButtonSelfRestTag = ecs.NewComponentType[ButtonSelfRestState]() //自复位按钮标签 + ButtonNonRestTag = ecs.NewTag() //非自复位按钮标签 ) + +type ButtonSystem struct { + query *ecs.Query +} + +func NewButtonSystem() *ButtonSystem { + return &ButtonSystem{query: ecs.NewQuery(filter.Contains(ButtonStateComponent))} +} +func NewButtonState() *ButtonState { + return &ButtonState{Ckd: false} +} + +// Update world 执行 +func (me *ButtonSystem) Update(w ecs.World) { + me.query.Each(w, func(e *ecs.Entry) { + if e.HasComponent(ButtonSelfRestTag) { + state := ButtonStateComponent.Get(e) + me.calculateSelfRest(w, e, state) + } + }) +} + +// 自复位按钮运算 +func (me *ButtonSystem) calculateSelfRest(w ecs.World, e *ecs.Entry, state *ButtonState) { + if state.Ckd { + reset := ButtonSelfRestTag.Get(e) + if reset.KeepAxTime > 0 { + reset.KeepAxTime -= int64(w.Tick()) + if reset.KeepAxTime < 0 { + reset.KeepAxTime = 0 + } + } + if reset.KeepAxTime <= 0 { + state.Ckd = false + } + } +} From 7891fe2ded994e852b9a82658c84035eda5a8b37 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 27 Sep 2023 17:08:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/button_system.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/system/button_system.go b/system/button_system.go index 5fa86b5..112714a 100644 --- a/system/button_system.go +++ b/system/button_system.go @@ -24,11 +24,11 @@ var ( ) type ButtonSystem struct { - query *ecs.Query + selfRestQuery *ecs.Query } func NewButtonSystem() *ButtonSystem { - return &ButtonSystem{query: ecs.NewQuery(filter.Contains(ButtonStateComponent))} + return &ButtonSystem{selfRestQuery: ecs.NewQuery(filter.Contains(ButtonStateComponent, ButtonSelfRestTag))} } func NewButtonState() *ButtonState { return &ButtonState{Ckd: false} @@ -36,11 +36,9 @@ func NewButtonState() *ButtonState { // Update world 执行 func (me *ButtonSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - if e.HasComponent(ButtonSelfRestTag) { - state := ButtonStateComponent.Get(e) - me.calculateSelfRest(w, e, state) - } + me.selfRestQuery.Each(w, func(e *ecs.Entry) { + state := ButtonStateComponent.Get(e) + me.calculateSelfRest(w, e, state) }) }