Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
This commit is contained in:
commit
660b6a6797
23
entities/button_entity.go
Normal file
23
entities/button_entity.go
Normal file
@ -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
|
||||||
|
}
|
14
entities/dcb_entity.go
Normal file
14
entities/dcb_entity.go
Normal file
@ -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
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import "joylink.club/ecs"
|
import (
|
||||||
|
"github.com/yohamta/donburi/filter"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
)
|
||||||
|
|
||||||
// ButtonState 广义按钮开关状态,开关有三个接点,分别为公共接点、常开点和常闭点
|
// ButtonState 广义按钮开关状态,开关有三个接点,分别为公共接点、常开点和常闭点
|
||||||
type ButtonState struct {
|
type ButtonState struct {
|
||||||
@ -8,6 +11,49 @@ type ButtonState struct {
|
|||||||
Ckd bool
|
Ckd bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ButtonSelfRestState 广义自复位按钮,复位状态
|
||||||
|
type ButtonSelfRestState struct {
|
||||||
|
//自复位按钮保持按下剩余时间,ms
|
||||||
|
KeepAxTime int64
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ButtonStateComponent = ecs.NewComponentType[ButtonState]()
|
ButtonStateComponent = ecs.NewComponentType[ButtonState]()
|
||||||
|
ButtonSelfRestTag = ecs.NewComponentType[ButtonSelfRestState]() //自复位按钮标签
|
||||||
|
ButtonNonRestTag = ecs.NewTag() //非自复位按钮标签
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ButtonSystem struct {
|
||||||
|
selfRestQuery *ecs.Query
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewButtonSystem() *ButtonSystem {
|
||||||
|
return &ButtonSystem{selfRestQuery: ecs.NewQuery(filter.Contains(ButtonStateComponent, ButtonSelfRestTag))}
|
||||||
|
}
|
||||||
|
func NewButtonState() *ButtonState {
|
||||||
|
return &ButtonState{Ckd: false}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update world 执行
|
||||||
|
func (me *ButtonSystem) Update(w ecs.World) {
|
||||||
|
me.selfRestQuery.Each(w, func(e *ecs.Entry) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
246
system/dcb_system.go
Normal file
246
system/dcb_system.go
Normal file
@ -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
|
||||||
|
}
|
3
system/event/button_event.go
Normal file
3
system/event/button_event.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package sysEvent
|
||||||
|
|
||||||
|
//广义按钮相关事件
|
Loading…
Reference in New Issue
Block a user