屏蔽门psd

This commit is contained in:
xzb 2023-09-21 09:46:20 +08:00
parent 3e6bd49525
commit 9b949aee30
2 changed files with 39 additions and 3 deletions

@ -1 +1 @@
Subproject commit c3b9d965c607a2f29e0bdc586aba6851d4f29f13 Subproject commit adb9cf9a0005fc74565da8753f4f7577834d27d4

View File

@ -35,6 +35,10 @@ type StationPsdsCircuitState struct {
type PsdState struct { type PsdState struct {
//屏蔽门打开的百分比则0-完全关闭100-完全打开 //屏蔽门打开的百分比则0-完全关闭100-完全打开
Rate int Rate int
//关门操作被激活
actClosing bool
//开门操作被激活
actOpening bool
} }
// PsdTagHandler 屏蔽门标签用于ecs query // PsdTagHandler 屏蔽门标签用于ecs query
@ -67,7 +71,7 @@ func NewStationPsdsCircuitState() *StationPsdsCircuitState {
return &StationPsdsCircuitState{} return &StationPsdsCircuitState{}
} }
func NewPsdState() *PsdState { func NewPsdState() *PsdState {
return &PsdState{} return &PsdState{Rate: PSD_CLOSED_RATE}
} }
var StationPsdsCircuitStateComponent = ecs.NewComponentType[StationPsdsCircuitState]() var StationPsdsCircuitStateComponent = ecs.NewComponentType[StationPsdsCircuitState]()
@ -111,11 +115,32 @@ func (me *StationPsdsCircuitSystem) Update(w ecs.World) {
func (me *StationPsdsCircuitSystem) circuitUpdate(w ecs.World) { func (me *StationPsdsCircuitSystem) circuitUpdate(w ecs.World) {
psdsCircuitQuery.Each(w, func(e *ecs.Entry) { psdsCircuitQuery.Each(w, func(e *ecs.Entry) {
me.calculateMG(w, e) me.calculateMG(w, e)
me.calculateActGM(w, e)
}) })
} }
// 关门动作运算 // 关门动作运算
func (me *StationPsdsCircuitSystem) calculateGM(w ecs.World, circuitEntry *ecs.Entry) { func (me *StationPsdsCircuitSystem) calculateActGM(w ecs.World, circuitEntry *ecs.Entry) {
circuit := StationPsdsCircuitStateComponent.Get(circuitEntry)
tags := PsdTagHandlerComponent.Get(circuitEntry)
//上行
isActSGm := circuit.SGMJ && !circuit.G4SKMJ && !circuit.G8SKMJ
sQuery := ecs.NewQuery(filter.Contains(tags.STag))
sQuery.Each(w, func(sPsd *ecs.Entry) {
sPsdState := PsdStateComponent.Get(sPsd)
sPsdState.actClosing = isActSGm
})
//下行
isActXGm := circuit.XGMJ && !circuit.G4XKMJ && !circuit.G8XKMJ
xQuery := ecs.NewQuery(filter.Contains(tags.XTag))
xQuery.Each(w, func(xPsd *ecs.Entry) {
xPsdState := PsdStateComponent.Get(xPsd)
xPsdState.actClosing = isActXGm
})
}
// 4编组开门动作运算
func (me *StationPsdsCircuitSystem) calculateAct4KM(w ecs.World, circuitEntry *ecs.Entry) {
} }
@ -159,6 +184,8 @@ func (me *StationPsdsCircuitSystem) psdUpdate(w ecs.World) {
me.calculatePsdMove(e) me.calculatePsdMove(e)
}) })
} }
// 单个屏蔽门移动运算
func (me *StationPsdsCircuitSystem) calculatePsdMove(psd *ecs.Entry) { func (me *StationPsdsCircuitSystem) calculatePsdMove(psd *ecs.Entry) {
//move.Value为门当前打开的宽度 //move.Value为门当前打开的宽度
move := MovableObjectComponent.Get(psd) move := MovableObjectComponent.Get(psd)
@ -170,4 +197,13 @@ func (me *StationPsdsCircuitSystem) calculatePsdMove(psd *ecs.Entry) {
move.Value = PSD_OPENED move.Value = PSD_OPENED
} }
state.Rate = int((float64(move.Value) / float64(PSD_OPENED)) * float64(100)) state.Rate = int((float64(move.Value) / float64(PSD_OPENED)) * float64(100))
//
switch {
case state.actClosing && !state.actOpening:
move.Retreat()
case !state.actClosing && state.actOpening:
move.Forward()
case state.actClosing && state.actOpening:
move.Pause()
}
} }