继电器
This commit is contained in:
parent
5af2b04ef6
commit
38769c954c
@ -55,3 +55,9 @@ var RelayStateComponent = ecs.NewComponentType[cstate.RelayState]()
|
||||
|
||||
// 紧急停车按钮状态组件
|
||||
var EmpStateComponent = ecs.NewComponentType[cstate.EmpState]()
|
||||
|
||||
// 生成标签组件
|
||||
// 用于标记实体便于查找
|
||||
func NewComponentTag() *ecs.ComponentType[struct{}] {
|
||||
return ecs.NewComponentType[struct{}]()
|
||||
}
|
||||
|
@ -84,8 +84,6 @@ func foreachModels(modelManager umi.IModelManager, deviceType umi.DeviceType, ea
|
||||
}
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// 设备继电器标签,即标记继电器属于哪个设备的
|
||||
type DeviceRelayTag struct{}
|
||||
|
||||
// 创建模型仓库引用实体
|
||||
func CreateModelStorageRefEntity(w ecs.World) *ecs.Entry {
|
||||
@ -100,14 +98,14 @@ func CreateWorldTimeEntity(w ecs.World) *ecs.Entry {
|
||||
// 创建道岔实体
|
||||
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent, components.RelayTagHandlerComponent)
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[DeviceRelayTag]()})
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: components.NewComponentTag()})
|
||||
return e
|
||||
}
|
||||
|
||||
// 创建信号机实体
|
||||
func CreateSignalEntity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(components.DeviceIdentityComponent, components.SignalStateComponent, components.RelayTagHandlerComponent)
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[DeviceRelayTag]()})
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: components.NewComponentTag()})
|
||||
return e
|
||||
}
|
||||
|
||||
@ -116,14 +114,11 @@ func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(components.DeviceIdentityComponent, components.PhysicalSectionStateComponent)
|
||||
}
|
||||
|
||||
// 屏蔽门与其cell关系tag定义
|
||||
type PsdCellTag struct{}
|
||||
|
||||
// 创建站台单侧屏蔽门实体
|
||||
func CreatePsdEntity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(components.DeviceIdentityComponent, components.PsdStateComponent, components.PsdTagHandlerComponent, components.RelayTagHandlerComponent)
|
||||
components.PsdTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[PsdCellTag]()})
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[DeviceRelayTag]()})
|
||||
components.PsdTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: components.NewComponentTag()})
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: components.NewComponentTag()})
|
||||
return e
|
||||
}
|
||||
|
||||
@ -156,6 +151,6 @@ func CreateRelayEntity(w ecs.World, deviceEntry *ecs.Entry) *ecs.Entry {
|
||||
// 创建紧急停车按钮实体
|
||||
func CreateEmpEntity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(components.DeviceIdentityComponent, components.EmpStateComponent, components.RelayTagHandlerComponent)
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: ecs.NewComponentType[DeviceRelayTag]()})
|
||||
components.RelayTagHandlerComponent.Set(e, &cstate.EntityTagHandler{Tag: components.NewComponentTag()})
|
||||
return e
|
||||
}
|
||||
|
37
system/emp_relay_system.go
Normal file
37
system/emp_relay_system.go
Normal file
@ -0,0 +1,37 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/components"
|
||||
"joylink.club/rtsssimulation/umi"
|
||||
)
|
||||
|
||||
// 紧急停车按钮继电器系统
|
||||
type EmpRelaySystem struct {
|
||||
relaySystem
|
||||
// 紧急停车按钮查询
|
||||
query *ecs.Query
|
||||
}
|
||||
|
||||
func NewEmpRelaySystem() *EmpRelaySystem {
|
||||
return &EmpRelaySystem{
|
||||
relaySystem: relaySystem{relayQuery: make(map[string]*ecs.Query)},
|
||||
query: ecs.NewQuery(filter.Contains(components.EmpStateComponent)),
|
||||
}
|
||||
}
|
||||
|
||||
// world 执行
|
||||
func (me *EmpRelaySystem) Update(world ecs.World) {
|
||||
me.query.Each(world, func(empEntry *ecs.Entry) {
|
||||
//key-继电器作用名,value-继电器实体
|
||||
usageRelayMapper := make(map[string]*ecs.Entry)
|
||||
//迭代关联的所有继电器
|
||||
me.getDeviceRelayQuery(empEntry).Each(world, func(empRelayEntry *ecs.Entry) {
|
||||
relayId := components.DeviceIdentityComponent.Get(empRelayEntry).Id
|
||||
relayModel := (WorldModelStorage(world).FindById(relayId)).(umi.IRelayModel)
|
||||
usageRelayMapper[relayModel.UsageName()] = empRelayEntry
|
||||
})
|
||||
//根据具体业务逻辑处理继电器
|
||||
})
|
||||
}
|
@ -7,7 +7,7 @@ import (
|
||||
"joylink.club/rtsssimulation/components/cstate"
|
||||
)
|
||||
|
||||
var PsdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.PsdTagHandlerComponent))
|
||||
var PsdQuery = ecs.NewQuery(filter.Contains(components.PsdStateComponent, components.PsdTagHandlerComponent))
|
||||
|
||||
const (
|
||||
//屏蔽门完全关闭
|
||||
|
@ -18,7 +18,7 @@ type SignalRelaySystem struct {
|
||||
func NewSignalReplaySystem() *SignalRelaySystem {
|
||||
return &SignalRelaySystem{
|
||||
relaySystem: relaySystem{relayQuery: make(map[string]*ecs.Query)},
|
||||
query: ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent)),
|
||||
query: ecs.NewQuery(filter.Contains(components.SignalStateComponent)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"joylink.club/rtsssimulation/umi"
|
||||
)
|
||||
|
||||
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent))
|
||||
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent))
|
||||
|
||||
const (
|
||||
//道岔定位
|
||||
|
Loading…
Reference in New Issue
Block a user