iscs bas 大系统
This commit is contained in:
parent
2803f32329
commit
3c0fc2293b
@ -4,7 +4,15 @@ import "joylink.club/ecs"
|
|||||||
|
|
||||||
// FluidPipe 流体管线
|
// FluidPipe 流体管线
|
||||||
type FluidPipe struct {
|
type FluidPipe struct {
|
||||||
Direction PipeFlowDirection //流动方向
|
Direction PipeFlowDirection //管线内综合流动方向
|
||||||
|
FlowSpeed float32 //管线内综合流量,m3/h
|
||||||
|
Sources []*SourceFlow //该管线内所有流体源投射的分量
|
||||||
|
}
|
||||||
|
|
||||||
|
// SourceFlow 流体源进入管线的流体描述
|
||||||
|
type SourceFlow struct {
|
||||||
|
Direction PipeFlowDirection
|
||||||
|
FlowSpeed float32
|
||||||
}
|
}
|
||||||
|
|
||||||
// PipeFlowDirection 管线内流体流动方向定义
|
// PipeFlowDirection 管线内流体流动方向定义
|
||||||
@ -16,6 +24,16 @@ const (
|
|||||||
PipeFlowBa //流体从管线的B->A
|
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 流体驱动器
|
// FluidDriver 流体驱动器
|
||||||
type FluidDriver struct {
|
type FluidDriver struct {
|
||||||
On bool //true-输出流体驱动力;false-未输出流体驱动力
|
On bool //true-输出流体驱动力;false-未输出流体驱动力
|
||||||
|
@ -9,7 +9,7 @@ type AirPavilion struct {
|
|||||||
Identity
|
Identity
|
||||||
Code string
|
Code string
|
||||||
PavilionType proto.AirPavilion_Type //风亭子类型
|
PavilionType proto.AirPavilion_Type //风亭子类型
|
||||||
PortA DevicePort //风亭A端口连接的设备
|
PortA *PipePort //风亭A端口连接的设备
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAirPavilion(id string, code string, pavilionType proto.AirPavilion_Type) *AirPavilion {
|
func NewAirPavilion(id string, code string, pavilionType proto.AirPavilion_Type) *AirPavilion {
|
||||||
|
@ -15,13 +15,15 @@ import (
|
|||||||
// 实现流体在设备、管线中流动
|
// 实现流体在设备、管线中流动
|
||||||
// 流体驱动源(风机、送风亭、泵)
|
// 流体驱动源(风机、送风亭、泵)
|
||||||
type FluidDriverSystem struct {
|
type FluidDriverSystem struct {
|
||||||
query *ecs.Query //流体驱动源
|
query *ecs.Query //流体驱动源
|
||||||
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
||||||
|
queryFluidPipe *ecs.Query
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFluidDriverSystem() *FluidDriverSystem {
|
func NewFluidDriverSystem() *FluidDriverSystem {
|
||||||
return &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)
|
fanOutPath := s.findFluidPath(fanModel, fanOutPort, true)
|
||||||
fanInPath := s.findFluidPath(fanModel, fanInPort, false)
|
fanInPath := s.findFluidPath(fanModel, fanInPort, false)
|
||||||
//
|
//
|
||||||
_ = fanOutPath
|
s.calculateFluid(w, fluidDriverOn, fanOutPath, fanInPath)
|
||||||
_ = fanInPath
|
|
||||||
_ = fluidDriverOn
|
|
||||||
}
|
}
|
||||||
case proto.DeviceType_DeviceType_AirPavilion: //风亭,其中送风亭为动力源
|
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]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断路径是否畅通
|
// 判断路径是否畅通
|
||||||
|
Loading…
Reference in New Issue
Block a user