This commit is contained in:
walker 2024-01-02 18:24:38 +08:00
commit 4dc5c17a89
20 changed files with 1522 additions and 1030 deletions

View File

@ -42,7 +42,7 @@ const (
// 占用状态
type OccupiedStatus struct {
Type OccupiedType
Types []OccupiedType // 占用状态
}
var OccupiedStatusType = ecs.NewComponentType[OccupiedStatus]() // 占用状态组件
@ -71,7 +71,6 @@ var BlockadeStatusType = ecs.NewComponentType[BlockadeStatus]() // 封锁状态
type UnLockStatus struct {
Delay bool // 延迟状态
DelayTime time.Duration // 延迟解锁时间
TriggerDevice *ecs.Entry // 触发解锁设备
}
var UnLockStatusType = ecs.NewComponentType[UnLockStatus]() // 解锁状态组件
@ -118,6 +117,7 @@ type RouteStatus struct {
AtsControl bool // ats自动控制
Setting bool // 进路是否排列中
Lock bool // 已锁闭
Setable bool // 是否可排列
}
var RouteStatusType = ecs.NewComponentType[RouteStatus]() // 进路状态组件
@ -145,24 +145,7 @@ const (
type DevicePosition struct {
Device *ecs.Entry // 设备
Offset int64 // 在设备上的相对a位置偏移
Direction bool // 从a到b为true;从b到a为false
Direction bool // 上下行
}
var DevicePositionType = ecs.NewComponentType[DevicePosition]()
// 列车运行状态
type TrainRunStatus struct {
RunLevel TrainRunLevel // 列车运行级别
DriveMode DriveMode // 驾驶模式
Speed float32 // 运行速度
SpeedMax float32 // 最大速度
HeadPosition *DevicePosition // 车头位置
TailPosition *DevicePosition // 车尾位置
Hold bool // 扣车
}
var TrainRunStatusType = ecs.NewComponentType[TrainRunStatus]() // 列车位置状态组件
var (
TrainSpeedMax float32 = 80 / 3.6
)

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/ci.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/common.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/points.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/ci.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/common.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/psd.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/signal.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: component/turnout.proto

View File

@ -4,7 +4,15 @@ import "joylink.club/ecs"
// FluidPipe 流体管线
type FluidPipe struct {
Direction PipeFlowDirection //流动方向
Direction PipeFlowDirection //管线内综合流动方向
FlowSpeed float32 //管线内综合流量m3/h
Sources []*SourceFlow //该管线内所有流体源投射的分量
}
// SourceFlow 流体源进入管线的流体描述
type SourceFlow struct {
Direction PipeFlowDirection
FlowSpeed float32
}
// PipeFlowDirection 管线内流体流动方向定义
@ -16,6 +24,16 @@ const (
PipeFlowBa //流体从管线的B->A
)
func (d *PipeFlowDirection) IsFlowAb() bool {
return *d == PipeFlowAb
}
func (d *PipeFlowDirection) IsFlowBa() bool {
return *d == PipeFlowBa
}
func (d *PipeFlowDirection) IsFlowNon() bool {
return *d == PipeFlowNon
}
// FluidDriver 流体驱动器
type FluidDriver struct {
On bool //true-输出流体驱动力false-未输出流体驱动力

@ -1 +1 @@
Subproject commit 2757e2c4e06b03afab94727cee9d948dae6d1754
Subproject commit e83feb89dd84e3456aafebb7d6dbe179675344e8

View File

@ -216,6 +216,8 @@ enum DeviceType {
DeviceType_Breakers = 21;
//
DeviceType_PowerScreen = 22;
//
DeviceType_Route = 23;
//--------ISCS [300,500]------
//ISCS门磁
@ -574,18 +576,24 @@ message Route {
PASS = 3;
LONG_SHUNTING = 4;
}
message TurnoutPosition {
string id = 1; // ID
bool normal = 2; //
}
string id = 1;
string name = 2;
//
string startId = 3;
//
string destinationId = 4;
// ID
// ID
repeated string deviceIds = 5;
// ID
repeated string conflictingRouteIds = 6;
//
RouteType routeType = 7;
//
repeated TurnoutPosition turnouts = 8;
}
//////////////////////////ISCS///////////////////////////////////

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc-gen-go v1.28.1
// protoc v4.23.1
// source: cg_repo.proto

View File

@ -9,7 +9,7 @@ type AirPavilion struct {
Identity
Code string
PavilionType proto.AirPavilion_Type //风亭子类型
PortA DevicePort //风亭A端口连接的设备
PortA *PipePort //风亭A端口连接的设备
}
func NewAirPavilion(id string, code string, pavilionType proto.AirPavilion_Type) *AirPavilion {

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,9 @@ type PhysicalSection struct {
//物理区段所属集中站
centralizedStation string
// 所属站台
platform *Platform
}
func NewPhysicalSection(id string) *PhysicalSection {
@ -188,6 +191,10 @@ func (s *PhysicalSection) LinkRanges() []*LinkRange {
return s.linkRanges
}
func (p *PhysicalSection) Platform() *Platform {
return p.platform
}
type PhysicalSectionPort struct {
section *PhysicalSection
port proto.Port

View File

@ -6,6 +6,7 @@ type Platform struct {
Identity
code string
station *Station
section *PhysicalSection
}
func NewPlatform(id string, code string) *Platform {
@ -25,3 +26,7 @@ func (p *Platform) Code() string {
func (p *Platform) Station() *Station {
return p.station
}
func (p *Platform) Section() *PhysicalSection {
return p.section
}

55
repository/route.go Normal file
View File

@ -0,0 +1,55 @@
package repository
import "joylink.club/rtsssimulation/repository/model/proto"
type Route struct {
Identity
name string
routeType proto.Route_RouteType
start *Signal
destination *Signal
sections []*PhysicalSection
conflictingRoutes []*Route
turnoutPositions []*TurnoutPosition
}
func NewRoute(id string, name string, routeType proto.Route_RouteType) *Route {
return &Route{
Identity: identity{id, proto.DeviceType_DeviceType_Route},
name: name,
routeType: routeType,
}
}
func (s *Route) StartSignal() *Signal {
return s.start
}
func (s *Route) DestinationSignal() *Signal {
return s.destination
}
func (s *Route) Sections() []*PhysicalSection {
return s.sections
}
func (s *Route) ConflictingRoutes() []*Route {
return s.conflictingRoutes
}
func (s *Route) TurnoutPositions() []*TurnoutPosition {
return s.turnoutPositions
}
type TurnoutPosition struct {
turnout *Turnout
normal bool
}
func (s *TurnoutPosition) Turnout() *Turnout {
return s.turnout
}
func (s *TurnoutPosition) Position() bool {
return s.normal
}

View File

@ -1,33 +0,0 @@
package cbtc_sys
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// 列车运行控制组件,给列车增加限制组件
type TrainRunControlSys struct {
trainQuery *ecs.Query
}
func NewTrainRunControlSys() *TrainRunControlSys {
return &TrainRunControlSys{
trainQuery: ecs.NewQuery(filter.Contains(component.TrainRunStatusType)),
}
}
func (sls *TrainRunControlSys) Update(w ecs.World) {
sls.trainQuery.Each(w, func(e *donburi.Entry) {
runStatus := component.TrainRunStatusType.Get(e)
headDevice := runStatus.HeadPosition.Device
// 限速赋值
if headDevice.HasComponent(component.SpeedLimitType) { // 车头所在设备有限速组件
speedLimit := component.SpeedLimitType.Get(headDevice)
runStatus.SpeedMax = speedLimit.Val
} else {
runStatus.SpeedMax = component.TrainSpeedMax
}
})
}

View File

@ -17,11 +17,13 @@ import (
type FluidDriverSystem struct {
query *ecs.Query //流体驱动源
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
queryFluidPipe *ecs.Query
}
func NewFluidDriverSystem() *FluidDriverSystem {
return &FluidDriverSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.FluidPipeType)),
}
}
@ -54,20 +56,107 @@ func (s *FluidDriverSystem) Update(w ecs.World) {
fanOutPath := s.findFluidPath(fanModel, fanOutPort, true)
fanInPath := s.findFluidPath(fanModel, fanInPort, false)
//
_ = fanOutPath
_ = fanInPath
_ = fluidDriverOn
s.calculateFluid(w, fluidDriverOn, fanOutPath, fanInPath)
}
case proto.DeviceType_DeviceType_AirPavilion: //风亭,其中送风亭为动力源
{
apModel := fdModel.(*repository.AirPavilion)
if apModel.PavilionType == proto.AirPavilion_AirSupplyPavilion {
apOutPort := *apModel.PortA
apOutPath := s.findFluidPath(apModel, apOutPort, true)
s.calculateFluid(w, fluidDriverOn, apOutPath, nil)
}
}
}
}
})
//
s.queryFluidPipe.Each(w, func(entry *ecs.Entry) {
pipe := component.FluidPipeType.Get(entry)
if len(pipe.Sources) > 0 {
directionAb := int8(0)
for _, ps := range pipe.Sources {
if ps.Direction.IsFlowAb() {
directionAb++
}
if ps.Direction.IsFlowBa() {
directionAb--
}
}
if directionAb > 0 {
pipe.Direction = component.PipeFlowAb
} else if directionAb < 0 {
pipe.Direction = component.PipeFlowBa
} else {
pipe.Direction = component.PipeFlowNon
}
} else {
pipe.Direction = component.PipeFlowNon
pipe.FlowSpeed = 0
}
})
}
// 计算流体在管线中的流动参数
func (s *FluidDriverSystem) calculateFluid(fluidDriverOn bool, outPath []*SearchedPath, inPath []*SearchedPath) {
func (s *FluidDriverSystem) calculateFluid(w ecs.World, fluidDriverOn bool, outPath []*SearchedPath, inPath []*SearchedPath) {
for _, out := range outPath {
s.clearFluidPathSources(w, out)
}
for _, in := range inPath {
s.clearFluidPathSources(w, in)
}
//
if fluidDriverOn {
var validOutPath, validInPath []*SearchedPath
for _, out := range outPath {
if s.isFluidPathUnblocked(out, w) {
validOutPath = append(validOutPath, out)
}
}
for _, in := range inPath {
if s.isFluidPathUnblocked(in, w) {
validInPath = append(validInPath, in)
}
}
isValid := len(outPath) > 0 && len(inPath) > 0 && len(validInPath) > 0 && len(validOutPath) > 0 || len(outPath) > 0 && len(inPath) == 0 && len(inPath) > 0
if isValid {
wd := entity.GetWorldData(w)
for _, outSp := range validOutPath {
for _, outPipe := range outSp.ViaPipes {
pipeEntry := wd.EntityMap[outPipe.Device().Id()]
fluidPipe := component.FluidPipeType.Get(pipeEntry)
fluidPipe.Sources = append(fluidPipe.Sources, &component.SourceFlow{Direction: convertFlowDirection(outPipe)})
}
}
for _, inSp := range validInPath {
for _, inPipe := range inSp.ViaPipes {
pipeEntry := wd.EntityMap[inPipe.Device().Id()]
fluidPipe := component.FluidPipeType.Get(pipeEntry)
fluidPipe.Sources = append(fluidPipe.Sources, &component.SourceFlow{Direction: convertFlowDirection(inPipe)})
}
}
}
}
}
func convertFlowDirection(sp repository.PipePort) component.PipeFlowDirection {
switch sp.Port() {
case proto.Port_A:
return component.PipeFlowAb
case proto.Port_B:
return component.PipeFlowBa
default:
return component.PipeFlowNon
}
}
// 清空管线流体源
func (s *FluidDriverSystem) clearFluidPathSources(w ecs.World, path *SearchedPath) {
wd := entity.GetWorldData(w)
for _, pipe := range path.ViaPipes {
pipeEntry := wd.EntityMap[pipe.Device().Id()]
fluidPipe := component.FluidPipeType.Get(pipeEntry)
fluidPipe.Sources = fluidPipe.Sources[0:0]
}
}
// 判断路径是否畅通