signal dcxh 驱采

This commit is contained in:
xzb 2023-10-12 16:59:08 +08:00
parent a1beb531a6
commit 9a21c4bfd2
5 changed files with 92 additions and 62 deletions

View File

@ -243,3 +243,33 @@ var (
Signal3XH4LsqType = ecs.NewComponentType[Signal3XH4Lsq]() Signal3XH4LsqType = ecs.NewComponentType[Signal3XH4Lsq]()
Signal3XH4LscType = ecs.NewComponentType[Signal3XH4Lsc]() 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]()
)

View File

@ -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]()
)

View File

@ -12,7 +12,9 @@ func loadSignalDcxh(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 2 { //dcxh组合类型包含2个继电器 if len(elecs) == 2 { //dcxh组合类型包含2个继电器
signalEntry.AddComponent(component.SignalDCXHElectronicType) signalEntry.AddComponent(component.SignalDCXHElectronicType)
signalEntry.AddComponent(component.SignalDCXHFilamentType) signalEntry.AddComponent(component.SignalDCXHLsqType)
signalEntry.AddComponent(component.SignalDCXHLscType)
signalEntry.AddComponent(component.SignalLightsType)
// //
elecState := &component.SignalDCXHElectronic{} elecState := &component.SignalDCXHElectronic{}
for _, elec := range elecs { 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.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 { } else {
return fmt.Errorf("id=[%s]的信号机dcxh电子元器件数量须为2", signal.Id()) return fmt.Errorf("id=[%s]的信号机dcxh电子元器件数量须为2", signal.Id())
} }

View File

@ -14,10 +14,8 @@ func DriveSignalDCXHDx(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.SignalDCXHElectronicType.Get(signalEntry) lsq := component.SignalDCXHLsqType.Get(signalEntry)
driveDx := component.RelayDriveType.Get(state.DCXH_DXJ) lsq.DCXH_DXJ_Q = true
driveDx.Td = true
driveDx.Xq = true
} }
}) })
} }
@ -28,10 +26,8 @@ func DriveSignalDCXHNon(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.SignalDCXHElectronicType.Get(signalEntry) lsq := component.SignalDCXHLsqType.Get(signalEntry)
driveDx := component.RelayDriveType.Get(state.DCXH_DXJ) lsq.DCXH_DXJ_Q = false
driveDx.Td = false
driveDx.Xq = false
} }
}) })
} }

View File

@ -11,41 +11,69 @@ type SignalDCXHSystem struct {
} }
func NewSignalDCXHSystem() *SignalDCXHSystem { 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 执行 // Update world 执行
func (s *SignalDCXHSystem) Update(w ecs.World) { func (s *SignalDCXHSystem) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
state := component.SignalDCXHElectronicType.Get(e) state := component.SignalDCXHElectronicType.Get(entry)
filament := component.SignalDCXHFilamentType.Get(e) 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.calculateLsq(state, lsq)
s.calculateB(state, filament) s.calculateA(state, DCXH_A)
s.calculateDJ(state, filament) 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) func (s *SignalDCXHSystem) calculateLsq(state *component.SignalDCXHElectronic, lsq *component.SignalDCXHLsq) {
isB := filament.Bf && dxj.Val dxj := component.RelayDriveType.Get(state.DCXH_DXJ)
filament.B = isB //
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) func (s *SignalDCXHSystem) calculateLsc(state *component.SignalDCXHElectronic, lsc *component.SignalDCXHLsc) {
isA := filament.Af && !dxj.Val
filament.A = isA
}
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
dxj := component.BitStateType.Get(state.DCXH_DXJ) dxj := component.BitStateType.Get(state.DCXH_DXJ)
dj := component.BitStateType.Get(state.DCXH_DJ) dj := component.BitStateType.Get(state.DCXH_DJ)
isDJ := filament.Bf && dxj.Val || filament.Af && !dxj.Val //
if isDJ != dj.Val { lsc.DCXH_DJ_Xq = dj.Val
drive := component.RelayDriveType.Get(state.DCXH_DJ) lsc.DCXH_DXJ_Xq = dxj.Val
drive.Td = isDJ }
drive.Xq = isDJ 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
} }