信号机2XH-1
This commit is contained in:
parent
30ae982650
commit
b5bc049e34
@ -12,3 +12,18 @@ func CreateSignal3XH1Entity(w ecs.World, signalId string) *ecs.Entry {
|
||||
system.Signal3XH1FilamentStateComponent.Set(e, system.NewSignal3XH1FilamentState())
|
||||
return e
|
||||
}
|
||||
|
||||
func CreateSignal2XH1CdcEntity(w ecs.World, signalId string) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.Signal2XH1StateComponent, system.Signal2XH1FilamentStateComponent)
|
||||
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId})
|
||||
system.Signal2XH1StateComponent.Set(e, system.NewSignal2XH1CdcState())
|
||||
system.Signal2XH1FilamentStateComponent.Set(e, system.NewSignal2XH1FilamentState())
|
||||
return e
|
||||
}
|
||||
func CreateSignal2XH1CzqzEntity(w ecs.World, signalId string) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.Signal2XH1StateComponent, system.Signal2XH1FilamentStateComponent)
|
||||
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId})
|
||||
system.Signal2XH1StateComponent.Set(e, system.NewSignal2XH1CzqzState())
|
||||
system.Signal2XH1FilamentStateComponent.Set(e, system.NewSignal2XH1FilamentState())
|
||||
return e
|
||||
}
|
||||
|
77
system/signal_2xh1_system.go
Normal file
77
system/signal_2xh1_system.go
Normal file
@ -0,0 +1,77 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
sysEvent "joylink.club/rtsssimulation/system/event"
|
||||
"joylink.club/rtsssimulation/umi"
|
||||
)
|
||||
|
||||
// Signal2XH1State 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机
|
||||
type Signal2XH1State struct {
|
||||
// 物理绿灯,true-亮
|
||||
L bool
|
||||
// 物理红灯,true-亮
|
||||
H bool
|
||||
// 点灯继电器,true-吸合,常态落下表示逻辑点灯
|
||||
DDJ bool
|
||||
//灯丝继电器,true-吸合
|
||||
DJ bool
|
||||
//列车信号继电器,true-吸合
|
||||
LXJ bool
|
||||
}
|
||||
|
||||
// Signal2XH1FilamentState 信号机2XH-1 灯丝状态
|
||||
type Signal2XH1FilamentState struct {
|
||||
// 物理绿灯,true-灯丝正常
|
||||
Lf bool
|
||||
// 物理红灯,true-灯丝正常
|
||||
Hf bool
|
||||
}
|
||||
|
||||
func NewSignal2XH1FilamentState() *Signal2XH1FilamentState {
|
||||
return &Signal2XH1FilamentState{Lf: true, Hf: true}
|
||||
}
|
||||
|
||||
// NewSignal2XH1CdcState 出段(场)信号机
|
||||
func NewSignal2XH1CdcState() *Signal2XH1State {
|
||||
return &Signal2XH1State{DDJ: false, LXJ: false, DJ: true, L: false, H: true}
|
||||
}
|
||||
|
||||
// NewSignal2XH1CzqzState 出站区间阻挡信号机
|
||||
func NewSignal2XH1CzqzState() *Signal2XH1State {
|
||||
return &Signal2XH1State{DDJ: true, LXJ: false, DJ: false, L: false, H: false}
|
||||
}
|
||||
|
||||
var Signal2XH1StateComponent = ecs.NewComponentType[Signal2XH1State]()
|
||||
var Signal2XH1FilamentStateComponent = ecs.NewComponentType[Signal2XH1FilamentState]()
|
||||
var signal2XH1Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Signal2XH1StateComponent))
|
||||
|
||||
// Update world 执行
|
||||
func (me *Signal2XH1State) Update(w ecs.World) {
|
||||
signal2XH1Query.Each(w, func(entry *ecs.Entry) {
|
||||
state := Signal2XH1StateComponent.Get(entry)
|
||||
filament := Signal2XH1FilamentStateComponent.Get(entry)
|
||||
me.calculateL(state, filament)
|
||||
me.calculateH(state, filament)
|
||||
me.calculateDJ(w, entry, state, filament)
|
||||
})
|
||||
}
|
||||
func (me *Signal2XH1State) calculateL(state *Signal2XH1State, filament *Signal2XH1FilamentState) {
|
||||
isL := !state.DDJ && state.LXJ && filament.Lf
|
||||
state.L = isL
|
||||
}
|
||||
func (me *Signal2XH1State) calculateH(state *Signal2XH1State, filament *Signal2XH1FilamentState) {
|
||||
isH := !state.DDJ && !state.LXJ && filament.Hf
|
||||
state.H = isH
|
||||
}
|
||||
func (me *Signal2XH1State) calculateDJ(w ecs.World, e *ecs.Entry, state *Signal2XH1State, filament *Signal2XH1FilamentState) {
|
||||
isDJ := !state.DDJ && state.LXJ && filament.Lf || !state.DDJ && !state.LXJ && filament.Hf
|
||||
//通知继电器进行动作
|
||||
if state.DJ != isDJ {
|
||||
signalModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
|
||||
relayRole, _ := signalModel.(umi.IRelayCRole)
|
||||
relayModel := relayRole.FindRelayModelByCRole(SIGNAL_2XH1, SIGNAL_DJ)
|
||||
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(umi.IDeviceModel).GetId(), Xh: isDJ})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user