【修改发送动力学道岔信息逻辑,减少循环】

This commit is contained in:
weizhihong 2023-11-03 13:35:58 +08:00
parent 9654bc4bea
commit 9820e4aa05
3 changed files with 26 additions and 75 deletions

View File

@ -86,38 +86,3 @@ func RemoveTrainState(vs *VerifySimulation, id string) {
panic(fmt.Sprintf("列车【%s】不存在", id))
}
}
/*
// 列车占用状态
func GetDeviceOccByTrainState(vs *VerifySimulation, ts *state.TrainState) {
if ts.DevicePort == "" { // 区段
if ts.PointTo { // 如果是运行方向是从A -> B
if ts.HeadOffset >= ts.TrainLength { // 如果车头偏移量大于车身长度,只占用当前区段
fmt.Println(ts.HeadDeviceUId)
} else { // 如果不够,向后找占用设备
s1 := vs.Repo.FindPhysicalSection(ts.HeadDeviceUId)
l := int64(math.Abs(float64(s1.BLinkPosition().Offset() - s1.ALinkPosition().Offset())))
// 剩余长度
sl := ts.TrainLength - l
// 寻找下一段设备
ar := s1.ARelation()
if condition {
}
if ar.Device().Type() == rtproto.DeviceType_DeviceType_PhysicalSection { // 区段
}
}
} else {
}
} else { // 道岔
}
// 车头所在位置、列车长度
// 运行方向
// 占用设备类型、设备长度
// 占用设备ID、设备偏移
}
*/

View File

@ -3,15 +3,11 @@ package memory
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
"joylink.club/bj-rtsts-server/dto/request_proto"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
)
// 处理道岔操作
@ -44,31 +40,3 @@ func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.Tur
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
}
}
// 获取全部的道岔状态,动力学使用
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
var switchArr []*state.SwitchState
turnoutList := sim.Repo.TurnoutList()
for _, o := range turnoutList {
s := handlerTurnoutState(sim.World, o.Id())
if s == nil {
continue
}
s.Id = sim.GetComIdByUid(o.Id())
switchArr = append(switchArr, s)
}
return switchArr
}
func handlerTurnoutState(w ecs.World, uid string) *state.SwitchState {
entry, ok := entity.GetEntityByUid(w, uid)
if !ok {
fmt.Printf("id=%s的道岔不存在", uid)
return nil
}
if !entry.HasComponent(component.TurnoutPositionType) {
return nil
}
pos := component.TurnoutPositionType.Get(entry)
return &state.SwitchState{Normal: pos.Db, Reverse: pos.Fb, Dw: pos.Dw, Fw: pos.Fw}
}

View File

@ -20,6 +20,8 @@ import (
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
@ -148,23 +150,39 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string {
// 采集动力学道岔状态
func (s *VerifySimulation) CollectDynamicsTurnoutInfo() []*message.DynamicsTurnoutInfo {
stateSlice := GetAllTurnoutState(s)
var turnoutStates []*message.DynamicsTurnoutInfo
for _, sta := range stateSlice {
code64, err := strconv.ParseUint(sta.Id, 10, 16)
for _, o := range s.Repo.TurnoutList() {
sta := s.uidMap[o.Id()]
if sta == nil {
continue
}
code64, err := strconv.ParseUint(sta.CommonId, 10, 16)
if err != nil {
slog.Error("id转uint16报错", err)
}
info := message.DynamicsTurnoutInfo{
Code: uint16(code64),
NPosition: sta.Dw,
RPosition: sta.Fw,
s := handlerDynamicsTurnoutState(s.World, o.Id())
if s == nil {
continue
}
turnoutStates = append(turnoutStates, &info)
s.Code = uint16(code64)
turnoutStates = append(turnoutStates, s)
}
return turnoutStates
}
func handlerDynamicsTurnoutState(w ecs.World, uid string) *message.DynamicsTurnoutInfo {
entry, ok := entity.GetEntityByUid(w, uid)
if !ok {
fmt.Printf("id=%s的道岔不存在", uid)
return nil
}
if !entry.HasComponent(component.TurnoutPositionType) {
return nil
}
pos := component.TurnoutPositionType.Get(entry)
return &message.DynamicsTurnoutInfo{NPosition: pos.Dw, RPosition: pos.Fw}
}
// 处理动力学列车速度消息
func (s *VerifySimulation) HandleDynamicsTrainInfo(info *message.DynamicsTrainInfo) {
sta, ok := s.Memory.Status.TrainStateMap.Load(strconv.Itoa(int(info.Number)))