重构包

This commit is contained in:
xzb 2023-08-23 16:01:01 +08:00
parent fcdb8c6959
commit c289fd2f6d
12 changed files with 219 additions and 231 deletions

View File

@ -7,6 +7,7 @@ import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/operate"
"joylink.club/rtsssimulation/storages/memory"
"joylink.club/rtsssimulation/storages/memory/wdcreator"
"joylink.club/rtsssimulation/storages/model"
@ -79,9 +80,8 @@ func initSimWorld(sim *Simulation, tick int) {
})
//添加必要的系统
sim.World.AddSystem(system.NewSwitchSystem())
sim.World.AddSystem(system.NewSignalSystem())
sim.World.AddSystem(system.NewPsdSystem())
sim.World.AddSystem(system.NewTowPositionButtonSystem())
sim.World.AddSystem(system.NewPercentageSystem())
}
// 构建模型
@ -128,56 +128,56 @@ func initModels() {
func testPsdOpt(world ecs.World, face *system.FaceSystem) {
face.Call(func(w ecs.World) any {
return system.FirePsdOperation(w, "psd1", true)
return operate.FirePsdOperation(w, "psd1", true)
})
time.Sleep(5 * time.Second)
face.Call(func(w ecs.World) any {
return system.FirePsdOperation(w, "psd1", false)
return operate.FirePsdOperation(w, "psd1", false)
})
}
func testPsdCellOpt(world ecs.World, face *system.FaceSystem) {
face.Call(func(w ecs.World) any {
return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0)
return operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0)
})
face.Call(func(w ecs.World) any {
return system.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0)
return operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0)
})
time.Sleep(10 * time.Second)
face.Call(func(w ecs.World) any {
return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
return operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
})
face.Call(func(w ecs.World) any {
return system.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
return operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
})
}
func testSwitchTurn(world ecs.World, face *system.FaceSystem) {
reslult, _ := face.Call(func(w ecs.World) any {
fmt.Println("==>>1触发转动道岔 ...")
return system.FireSwitchTurn(w, "switch1", system.SwitchReverseRate)
return operate.FireSwitchTurn(w, "switch1", system.SwitchReverseRate)
})
fmt.Println("==>>1触发转动道岔 。。。", reslult)
time.Sleep(8 * time.Second)
reslult2, _ := face.Call(func(w ecs.World) any {
fmt.Println("==>>2触发转动道岔 ...")
return system.FireSwitchTurn(w, "switch1", system.SwitchNormalRate)
return operate.FireSwitchTurn(w, "switch1", system.SwitchNormalRate)
})
fmt.Println("==>>2触发转动道岔 。。。", reslult2)
}
func testSignalOpt(world ecs.World, face *system.FaceSystem) {
face.Call(func(w ecs.World) any {
return system.SetSignalDisplay(w, "siganl1", cstate.SignalAspect_B)
return operate.SetSignalDisplay(w, "siganl1", cstate.SignalAspect_B)
})
}
func testButtonOpt(world ecs.World, face *system.FaceSystem) {
face.Call(func(w ecs.World) any {
return system.FireTowPositionButtonMoving(world, "button1")
return operate.FireTowPositionButtonMoving(world, "button1")
})
time.Sleep(3 * time.Second)
face.Call(func(w ecs.World) any {
return system.FireTowPositionButtonArrivedPos1(world, "button1")
return operate.FireTowPositionButtonArrivedPos1(world, "button1")
})
time.Sleep(3 * time.Second)
face.Call(func(w ecs.World) any {
return system.FireTowPositionButtonArrivedPos2(world, "button1")
return operate.FireTowPositionButtonArrivedPos2(world, "button1")
})
}

View File

@ -1,34 +1,22 @@
package system
package operate
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/system"
)
// 应答器查询
var baliseQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.BaliseStateComponent))
// 应答器模拟系统
// 检测当有列车经过时,把报文发送给该列车
type BaliseSystem struct {
}
func NewTransponderSystem() *BaliseSystem {
return &BaliseSystem{}
}
// world 执行
func (me *BaliseSystem) Update(w ecs.World) {
}
//
// 发送消息到应答器
// 当要清空应答器中报文时,则message=nil
func SendMessageToTransponder(world ecs.World, transponderId string, message *cstate.BaliseContent) bool {
transponderEntry := queryEntityById(world, baliseQuery, transponderId)
transponderEntry := system.QueryEntityById(world, baliseQuery, transponderId)
//
if transponderEntry == nil {
return false

View File

@ -0,0 +1,49 @@
package operate
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
)
// 触发操作百分比设备
// deviceEntry 百分比组件所在的实体
// lhDistance 百分比设备从0-100的距离单位ms
// toRate 本次操作最终目标百分比
func FirePercentageDeviceOperation(w ecs.World, deviceEntry *ecs.Entry, lhDistance int64, toRate int32) error {
if !deviceEntry.HasComponent(components.PercentageDeviceComponent) {
entityId := components.DeviceIdentityComponent.Get(deviceEntry).Id
return fmt.Errorf("实体[%s]中不存在百分比组件", entityId)
}
curRate := components.PercentageDeviceComponent.Get(deviceEntry).Rate
if curRate == toRate {
return nil
}
//
if !deviceEntry.HasComponent(components.PercentageDeviceOperatingComponent) {
deviceEntry.AddComponent(components.PercentageDeviceOperatingComponent)
}
operation := components.PercentageDeviceOperatingComponent.Get(deviceEntry)
//
toHigh := toRate > curRate
var initDistance, sumDistance int64
if toHigh {
initDistance = int64(float64(lhDistance) * (float64(curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(toRate-curRate) / float64(100)))
} else {
initDistance = int64(float64(lhDistance) * (float64(100-curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(curRate-toRate) / float64(100)))
}
//
*operation = cstate.PercentageDeviceOperating{
ToH: toHigh,
LhDistance: lhDistance,
InitDistance: initDistance,
SumDistance: sumDistance,
RemainingDistance: sumDistance,
}
//
return nil
}

87
operate/psd_operation.go Normal file
View File

@ -0,0 +1,87 @@
package operate
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/storages/memory"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// 车站单侧屏蔽门互锁解除操作
func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) error {
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
components.PsdStateComponent.Get(psdEntry).InterlockReleased = lockRelease
//
return nil
}
// 车站单侧屏蔽门操作
// closeOpt true-关门操作false-开门操作
func FirePsdOperation(world ecs.World, psdId string, closeOpt bool) error {
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
//屏蔽门标签
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellQuery.Each(world, func(psdCellEntry *ecs.Entry) {
if closeOpt {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), system.PsdCellWholeCloseRate)
} else {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), system.PsdCellWholeOpenRate)
}
})
//
return nil
}
// 车站单侧屏蔽门单元cell操作
// closeRate cell最终关上的百分比100-完全关上0-完全未关即完全打开,(0,100)内即半关闭
func FirePsdCellOperation(world ecs.World, psdId string, psdCellId string, closeRate int32) error {
if closeRate < 0 || closeRate > 100 {
return fmt.Errorf("屏蔽门单元操作closeRate(%d)不在[0,100]内", closeRate)
}
//
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
//屏蔽门标签
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellEntry := system.QueryEntityById(world, psdCellQuery, psdCellId)
if psdCellEntry == nil {
return fmt.Errorf("屏蔽门[%s]的单元门[%s]的实体不存在", psdId, psdCellId)
}
//
return FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), closeRate)
}
// 获取屏蔽门实体
func findPsdEntry(world ecs.World, psdId string) (*ecs.Entry, error) {
psdEntry := system.QueryEntityById(world, system.PsdQuery, psdId)
if psdEntry == nil {
return nil, fmt.Errorf("屏蔽门[%s]实体不存在", psdId)
} else {
return psdEntry, nil
}
}
// 获取屏蔽门从完全开到完全关所需时间单位ms
func findPsdWholeMoveTime(psdId string) int64 {
psd := memory.DeviceModelStorage.FindModelById(psdId)
if nil != psd {
psdUmi := psd.(umi.IPsdModel)
return psdUmi.MovingTime()
}
//默认值
return 4000
}

View File

@ -1,4 +1,4 @@
package system
package operate
import (
"fmt"
@ -7,22 +7,12 @@ import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/system"
)
type SignalSystem struct {
}
// 信号机显示状态查询
var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
// world 执行
func (me *SignalSystem) Update(world ecs.World) {
}
func NewSignalSystem() *SignalSystem {
return &SignalSystem{}
}
// 设置某个信号机的显示
// 返回值true-设置成功false-设置失败
func SetSignalDisplay(w ecs.World, signalId string, display cstate.SignalAspect) error {
@ -39,7 +29,7 @@ func SetSignalDisplay(w ecs.World, signalId string, display cstate.SignalAspect)
// 获取信号机实体
func findSignalEntry(w ecs.World, signalId string) (*ecs.Entry, error) {
var signalEntry *ecs.Entry = queryEntityById(w, signalQuery, signalId)
var signalEntry *ecs.Entry = system.QueryEntityById(w, signalQuery, signalId)
if signalEntry != nil {
return signalEntry, nil
} else {

View File

@ -0,0 +1,49 @@
package operate
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/storages/memory"
"joylink.club/rtsssimulation/system"
"joylink.club/rtsssimulation/umi"
)
// 触发道岔正常转动
// w: 当前世界
// switchId: 道岔id
// terminalRate: 道岔转动到百分比规定定位百分比为0反位百分比为100
func FireSwitchTurn(w ecs.World, switchId string, terminalRate int32) error {
if terminalRate < 0 || terminalRate > 100 {
return fmt.Errorf("道岔转动终点百分比[%d]不在范围[0,100]内", terminalRate)
}
var switchEntry *ecs.Entry = system.QueryEntityById(w, system.SwitchQuery, switchId)
if switchEntry == nil {
return fmt.Errorf("道岔[%s]的实体不存在", switchId)
}
//
switchRelay := components.SwitchRelayStateComponent.Get(switchEntry)
switchRate := components.PercentageDeviceComponent.Get(switchEntry)
if terminalRate == switchRate.Rate {
return nil
}
switchRelay.DcJ = terminalRate < switchRate.Rate
switchRelay.FcJ = terminalRate > switchRate.Rate
switchRelay.DbJ = false
switchRelay.FbJ = false
//
lhDistance := getSwitchTurnTime(switchId)
return FirePercentageDeviceOperation(w, switchEntry, lhDistance, terminalRate)
}
// 获取道岔转动耗时ms
func getSwitchTurnTime(switchId string) int64 {
dcModel := memory.DeviceModelStorage.FindModelById(switchId)
if nil != dcModel {
var dc umi.ISwitchModel = dcModel.(umi.ISwitchModel)
return dc.TurningTime()
}
//不存在返回默认值
return 5000
}

View File

@ -1,4 +1,4 @@
package system
package operate
import (
"fmt"
@ -6,27 +6,15 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/system"
)
// 两档按钮/旋钮系统
type TowPositionButtonSystem struct {
}
var towPosButtonsQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
func NewTowPositionButtonSystem() *TowPositionButtonSystem {
return &TowPositionButtonSystem{}
}
// world 执行
func (me *TowPositionButtonSystem) Update(w ecs.World) {
}
// 档位变换过程中指令
// 该指令执行后,按钮处于未知状态
func FireTowPositionButtonMoving(w ecs.World, buttonId string) error {
entry := queryEntityById(w, towPosButtonsQuery, buttonId)
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
if nil == entry {
return fmt.Errorf("两档位按钮[%s]实体不存在", buttonId)
}
@ -50,7 +38,7 @@ func FireTowPositionButtonArrivedPos2(w ecs.World, buttonId string) error {
return fireTowPositionButtonArrivedPos(w, buttonId, false)
}
func fireTowPositionButtonArrivedPos(w ecs.World, buttonId string, arrivedPos1 bool) error {
entry := queryEntityById(w, towPosButtonsQuery, buttonId)
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
if nil == entry {
return fmt.Errorf("两档位按钮[%s]实体不存在", buttonId)
}

View File

@ -26,6 +26,7 @@ func (me *DebugSystem) Update(w ecs.World) {
// 两档位按钮旋钮
func debugTowPosButton(w ecs.World) {
towPosButtonsQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
towPosButtonsQuery.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
state := components.TowPositionButtonStateComponent.Get(e)
@ -52,7 +53,7 @@ func debugTowPosButton(w ecs.World) {
// 屏蔽门状态
func debugPsd(w ecs.World) {
psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
psdQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
psdQuery.Each(w, func(e *ecs.Entry) {
psdId := components.DeviceIdentityComponent.Get(e).Id
psdState := components.PsdStateComponent.Get(e)

View File

@ -64,7 +64,7 @@ func (me *FaceSystem) Call(request FaceRequest) (any, bool) {
// 根据id获取实体
func (me *FaceSystem) FindEntity(id string) *ecs.Entry {
return findEntityById(me.world, id)
return FindEntityById(me.world, id)
}
// 获取world当前时间
@ -78,11 +78,11 @@ func (me *FaceSystem) WorldTime() *time.Time {
return nil
}
}
func findEntityById(world ecs.World, id string) *ecs.Entry {
func FindEntityById(world ecs.World, id string) *ecs.Entry {
query := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent))
return queryEntityById(world, query, id)
return QueryEntityById(world, query, id)
}
func queryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
var entry *ecs.Entry = nil
func() {
defer util.Recover()

View File

@ -1,12 +1,9 @@
package system
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
)
// 百分比设备系统
@ -40,43 +37,3 @@ func (me *PercentageSystem) Update(world ecs.World) {
}
})
}
// 触发操作百分比设备
// deviceEntry 百分比组件所在的实体
// lhDistance 百分比设备从0-100的距离单位ms
// toRate 本次操作最终目标百分比
func FirePercentageDeviceOperation(w ecs.World, deviceEntry *ecs.Entry, lhDistance int64, toRate int32) error {
if !deviceEntry.HasComponent(components.PercentageDeviceComponent) {
entityId := components.DeviceIdentityComponent.Get(deviceEntry).Id
return fmt.Errorf("实体[%s]中不存在百分比组件", entityId)
}
curRate := components.PercentageDeviceComponent.Get(deviceEntry).Rate
if curRate == toRate {
return nil
}
//
if !deviceEntry.HasComponent(components.PercentageDeviceOperatingComponent) {
deviceEntry.AddComponent(components.PercentageDeviceOperatingComponent)
}
operation := components.PercentageDeviceOperatingComponent.Get(deviceEntry)
//
toHigh := toRate > curRate
var initDistance, sumDistance int64
if toHigh {
initDistance = int64(float64(lhDistance) * (float64(curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(toRate-curRate) / float64(100)))
} else {
initDistance = int64(float64(lhDistance) * (float64(100-curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(curRate-toRate) / float64(100)))
}
//
*operation = cstate.PercentageDeviceOperating{
ToH: toHigh,
LhDistance: lhDistance,
InitDistance: initDistance,
SumDistance: sumDistance,
RemainingDistance: sumDistance,
}
//
return nil
}

View File

@ -1,17 +1,13 @@
package system
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/storages/memory"
"joylink.club/rtsssimulation/umi"
)
var psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
var PsdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
const (
//屏蔽门完全关闭
@ -30,7 +26,7 @@ func NewPsdSystem() *PsdSystem {
// world 执行
func (me *PsdSystem) Update(world ecs.World) {
psdQuery.Each(world, func(psdEntry *ecs.Entry) {
PsdQuery.Each(world, func(psdEntry *ecs.Entry) {
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery, ok := me.cellsQuery[psdTag]
if !ok {
@ -54,78 +50,3 @@ func (me *PsdSystem) Update(world ecs.World) {
psdState.AllOpened = allCellOpened
})
}
// 车站单侧屏蔽门互锁解除操作
func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) error {
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
components.PsdStateComponent.Get(psdEntry).InterlockReleased = lockRelease
//
return nil
}
// 车站单侧屏蔽门操作
// closeOpt true-关门操作false-开门操作
func FirePsdOperation(world ecs.World, psdId string, closeOpt bool) error {
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
//屏蔽门标签
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellQuery.Each(world, func(psdCellEntry *ecs.Entry) {
if closeOpt {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), PsdCellWholeCloseRate)
} else {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), PsdCellWholeOpenRate)
}
})
//
return nil
}
// 车站单侧屏蔽门单元cell操作
// closeRate cell最终关上的百分比100-完全关上0-完全未关即完全打开,(0,100)内即半关闭
func FirePsdCellOperation(world ecs.World, psdId string, psdCellId string, closeRate int32) error {
if closeRate < 0 || closeRate > 100 {
return fmt.Errorf("屏蔽门单元操作closeRate(%d)不在[0,100]内", closeRate)
}
//
psdEntry, err := findPsdEntry(world, psdId)
if nil != err {
return err
}
//屏蔽门标签
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellEntry := queryEntityById(world, psdCellQuery, psdCellId)
if psdCellEntry == nil {
return fmt.Errorf("屏蔽门[%s]的单元门[%s]的实体不存在", psdId, psdCellId)
}
//
return FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(psdId), closeRate)
}
// 获取屏蔽门实体
func findPsdEntry(world ecs.World, psdId string) (*ecs.Entry, error) {
psdEntry := queryEntityById(world, psdQuery, psdId)
if psdEntry == nil {
return nil, fmt.Errorf("屏蔽门[%s]实体不存在", psdId)
} else {
return psdEntry, nil
}
}
// 获取屏蔽门从完全开到完全关所需时间单位ms
func findPsdWholeMoveTime(psdId string) int64 {
psd := memory.DeviceModelStorage.FindModelById(psdId)
if nil != psd {
psdUmi := psd.(umi.IPsdModel)
return psdUmi.MovingTime()
}
//默认值
return 4000
}

View File

@ -1,16 +1,12 @@
package system
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/storages/memory"
"joylink.club/rtsssimulation/umi"
)
var switchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
const (
//道岔定位
@ -27,36 +23,9 @@ func NewSwitchSystem() *SwitchSystem {
return &SwitchSystem{}
}
// 触发道岔正常转动
// w: 当前世界
// switchId: 道岔id
// terminalRate: 道岔转动到百分比规定定位百分比为0反位百分比为100
func FireSwitchTurn(w ecs.World, switchId string, terminalRate int32) error {
if terminalRate < 0 || terminalRate > 100 {
return fmt.Errorf("道岔转动终点百分比[%d]不在范围[0,100]内", terminalRate)
}
var switchEntry *ecs.Entry = queryEntityById(w, switchQuery, switchId)
if switchEntry == nil {
return fmt.Errorf("道岔[%s]的实体不存在", switchId)
}
//
switchRelay := components.SwitchRelayStateComponent.Get(switchEntry)
switchRate := components.PercentageDeviceComponent.Get(switchEntry)
if terminalRate == switchRate.Rate {
return nil
}
switchRelay.DcJ = terminalRate < switchRate.Rate
switchRelay.FcJ = terminalRate > switchRate.Rate
switchRelay.DbJ = false
switchRelay.FbJ = false
//
lhDistance := getSwitchTurnTime(switchId)
return FirePercentageDeviceOperation(w, switchEntry, lhDistance, terminalRate)
}
// world 执行
func (me *SwitchSystem) Update(w ecs.World) {
switchQuery.Each(w, func(e *ecs.Entry) {
SwitchQuery.Each(w, func(e *ecs.Entry) {
switchRate := components.PercentageDeviceComponent.Get(e)
switchRelay := components.SwitchRelayStateComponent.Get(e)
if switchRate.Rate <= 0 {
@ -77,14 +46,3 @@ func (me *SwitchSystem) Update(w ecs.World) {
}
})
}
// 获取道岔转动耗时ms
func getSwitchTurnTime(switchId string) int64 {
dcModel := memory.DeviceModelStorage.FindModelById(switchId)
if nil != dcModel {
var dc umi.ISwitchModel = dcModel.(umi.ISwitchModel)
return dc.TurningTime()
}
//不存在返回默认值
return 5000
}