diff --git a/component/iscs_bas_pipe.go b/component/iscs_bas_pipe.go index b087c95..e036cb6 100644 --- a/component/iscs_bas_pipe.go +++ b/component/iscs_bas_pipe.go @@ -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-未输出流体驱动力 diff --git a/repository/iscs_bas_dxt.go b/repository/iscs_bas_dxt.go index 66d3b2c..0614922 100644 --- a/repository/iscs_bas_dxt.go +++ b/repository/iscs_bas_dxt.go @@ -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 { diff --git a/sys/iscs_sys/iscs_bas_fluid.go b/sys/iscs_sys/iscs_bas_fluid.go index e8c0b4f..218d196 100644 --- a/sys/iscs_sys/iscs_bas_fluid.go +++ b/sys/iscs_sys/iscs_bas_fluid.go @@ -15,13 +15,15 @@ import ( // 实现流体在设备、管线中流动 // 流体驱动源(风机、送风亭、泵) type FluidDriverSystem struct { - query *ecs.Query //流体驱动源 - drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径 + 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)), + 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] + } } // 判断路径是否畅通