diff --git a/component/iscs_bas_air_conditioner.go b/component/iscs_bas_air_conditioner.go index 303c415..fc1ec78 100644 --- a/component/iscs_bas_air_conditioner.go +++ b/component/iscs_bas_air_conditioner.go @@ -9,8 +9,4 @@ type AirConditioning struct { var ( AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调 - - CombinationAirConditionerTag = ecs.NewTag() //组合式空调(变频空调) - AirConditioningGroupTag = ecs.NewTag() //空调群控系统 - AirConditionerTag = ecs.NewTag() //空调器 ) diff --git a/component/iscs_bas_air_pavilion.go b/component/iscs_bas_air_pavilion.go index dbd89f7..de9d93c 100644 --- a/component/iscs_bas_air_pavilion.go +++ b/component/iscs_bas_air_pavilion.go @@ -8,7 +8,5 @@ type AirPavilion struct { } var ( - AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭 - ExhaustPavilionTag = ecs.NewTag() //排风亭 - AirSupplyPavilionTag = ecs.NewTag() //送风亭 + AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭 ) diff --git a/component/iscs_bas_gas_environment.go b/component/iscs_bas_environment.go similarity index 100% rename from component/iscs_bas_gas_environment.go rename to component/iscs_bas_environment.go diff --git a/component/iscs_bas_pipe.go b/component/iscs_bas_pipe.go index 8c15ea3..28b0719 100644 --- a/component/iscs_bas_pipe.go +++ b/component/iscs_bas_pipe.go @@ -115,10 +115,9 @@ func NewPipeFluid() *PipeFluid { } var ( - PipeType = ecs.NewComponentType[Pipe]() //电线 - PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力 - PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体 - + PipeType = ecs.NewComponentType[Pipe]() //电线 + PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力 + PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体 ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源 ) diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index 8633648..5890ef7 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -34,19 +34,12 @@ func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry { } // NewAirPavilionEntity 创建风亭实体 -func NewAirPavilionEntity(w ecs.World, id string, apType proto.AirPavilion_Type) *ecs.Entry { +func NewAirPavilionEntity(w ecs.World, id string) *ecs.Entry { wd := GetWorldData(w) e, ok := wd.EntityMap[id] if !ok { e = w.Entry(w.Create(component.UidType, component.AirPavilionType)) // - switch apType { - case proto.AirPavilion_ExhaustPavilion: - e.AddComponent(component.ExhaustPavilionTag) - case proto.AirPavilion_AirSupplyPavilion: - e.AddComponent(component.AirSupplyPavilionTag) - } - // component.UidType.SetValue(e, component.Uid{Id: id}) component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true}) wd.EntityMap[id] = e @@ -93,15 +86,24 @@ func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry { return e } -// NewCombinationAirConditionerEntity 创建组合式空调实体 +// NewCombinationAirConditionerEntity 创建组合式空调(变频)实体 func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry { - return newAirConditioningEntity(w, id, component.CombinationAirConditionerTag) -} -func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[struct{}]) *ecs.Entry { wd := GetWorldData(w) e, ok := wd.EntityMap[id] if !ok { - e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.DeviceExceptionType, tag)) + e = w.Entry(w.Create(component.UidType, component.MotorType, component.MotorFcType, component.FluidDriverType, component.AirConditioningType, component.DeviceExceptionType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} + +// NewAirConditionerEntity 创建空调实体 +func NewAirConditionerEntity(w ecs.World, id string) *ecs.Entry { + wd := GetWorldData(w) + e, ok := wd.EntityMap[id] + if !ok { + e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.DeviceExceptionType)) component.UidType.SetValue(e, component.Uid{Id: id}) wd.EntityMap[id] = e } diff --git a/entity/iscs_load.go b/entity/iscs_load.go index 37e0bf6..fd04738 100644 --- a/entity/iscs_load.go +++ b/entity/iscs_load.go @@ -57,7 +57,7 @@ func LoadIscs(w ecs.World) error { } //风亭(排风亭、送风亭) for _, ap := range data.Repo.AirPavilionMap { - NewAirPavilionEntity(w, ap.Id(), ap.PavilionType) + NewAirPavilionEntity(w, ap.Id()) } //阀门 for _, valve := range data.Repo.ValveMap { diff --git a/sys/iscs_sys/iscs_bas_air_conditioner.go b/sys/iscs_sys/iscs_bas_air_conditioner.go index 1978bfa..da41c2f 100644 --- a/sys/iscs_sys/iscs_bas_air_conditioner.go +++ b/sys/iscs_sys/iscs_bas_air_conditioner.go @@ -22,5 +22,10 @@ func (s *AirConditionerSystem) Update(w ecs.World) { air := component.AirConditioningType.Get(entry) // air.Running = motor.Speed > 0 + // + if entry.HasComponent(component.FluidDriverType) { + fd := component.FluidDriverType.Get(entry) + fd.On = motor.Speed > 0 + } }) } diff --git a/sys/iscs_sys/iscs_bas_fluid.go b/sys/iscs_sys/iscs_bas_fluid.go index 62f0a33..b918e15 100644 --- a/sys/iscs_sys/iscs_bas_fluid.go +++ b/sys/iscs_sys/iscs_bas_fluid.go @@ -13,17 +13,17 @@ import ( // FluidDriverSystem 流体驱动系统 // 实现流体在设备、管线中流动 -// 流体驱动源(风机、送风亭、泵) +// 流体驱动源(风机、泵、组合式空调) type FluidDriverSystem struct { - query *ecs.Query //流体驱动源 - drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径 - queryFluidPipe *ecs.Query + queryFluidDriver *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.PipeFluidType)), + queryFluidDriver: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)), + queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.PipeFluidType)), } } @@ -38,7 +38,9 @@ func (s *FluidDriverSystem) findFluidPath(fromDevice repository.Identity, fromDe return sp } func (s *FluidDriverSystem) Update(w ecs.World) { - + s.queryFluidDriver.Each(w, func(entry *ecs.Entry) { + //fdId := component.UidType.Get(entry).Id + }) } // 判断路径是否畅通 @@ -110,7 +112,7 @@ func newFluidDriverPathSearcher(fromDevice repository.Identity, fromDevicePortPi func (s *fluidDriverPathSearcher) search() []*SearchedPath { var rt []*SearchedPath if !s.exclude(s.fromDevicePortPipe.Device().Id()) { - searchContext := &fluidPath{} + searchContext := &fluidPath{viaPipeFittings: make(map[string]string)} searchContext.addPipe(s.fromDevicePortPipe) s.doSearch(searchContext) } else { @@ -149,50 +151,67 @@ func (s *fluidDriverPathSearcher) addSearchedPath(searchContext *fluidPath) { s.searchedPaths = append(s.searchedPaths, searchContext) } -// 递归搜索 +// 搜索 func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) { - nextViaPipes := searchContext.nextViaPathPipes() + nextViaPipes, end := searchContext.nextViaPathPipes() lenNextPipes := len(nextViaPipes) - if lenNextPipes == 0 { + if end { s.addSearchedPath(searchContext) - } else if lenNextPipes == 1 { - if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) { - searchContext.addPipe(nextViaPipes[0]) - s.doSearch(searchContext) - } } else { - for _, nextViaPipe := range nextViaPipes { - if searchContext.viaPipe(nextViaPipe.Device().Id()) { //舍弃回头路径 - continue + if lenNextPipes == 1 { + if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) { + searchContext.addPipe(nextViaPipes[0]) + s.doSearch(searchContext) } - if s.exclude(nextViaPipe.Device().Id()) { //舍弃排除路径 - continue + } else { + for _, nextViaPipe := range nextViaPipes { + if searchContext.viaPipe(nextViaPipe.Device().Id()) { //舍弃回头路径 + continue + } + if s.exclude(nextViaPipe.Device().Id()) { //舍弃排除路径 + continue + } + // + cp := searchContext.clone() + cp.addPipe(nextViaPipe) + s.doSearch(cp) } - // - cp := searchContext.clone() - cp.addPipe(nextViaPipe) - s.doSearch(cp) } } } -func (p *fluidPath) nextViaPathPipes() []repository.PipePort { +// 从当前管线找下一个管线 +// 泵、风机、空调 提供驱动力,承接进出 +// 返回bool : true-搜索达终点 +func (p *fluidPath) nextViaPathPipes() ([]repository.PipePort, bool) { nextDevice := p.nextDevice() + // switch nextDevice.Type() { case proto.DeviceType_DeviceType_PipeFitting: - return p.nextDeviceViaPipes(nextDevice.(*repository.PipeFitting).Ports(), p.curPipe) + { + if _, has := p.viaPipeFittings[nextDevice.Id()]; has { //排除已经经过的管件的路径 + return nil, false + } else { + p.viaPipeFittings[nextDevice.Id()] = nextDevice.Id() + return p.nextDeviceViaPipes(nextDevice.(*repository.PipeFitting).Ports(), p.curPipe), false + } + } case proto.DeviceType_DeviceType_Valve: - return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe) - case proto.DeviceType_DeviceType_GasMixingChamber: - return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe) - case proto.DeviceType_DeviceType_CombinationAirConditioner: - return p.nextCombinationAirConditionerViaPipes(nextDevice.(*repository.CombinationAirConditioner), p.curPipe) - case proto.DeviceType_DeviceType_AirPurificationDevice: - return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe) + return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe), false + case proto.DeviceType_DeviceType_GasMixingChamber: //静压箱 + return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe), false + case proto.DeviceType_DeviceType_AirPurificationDevice: //净化装置 + return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe), false + case proto.DeviceType_DeviceType_Environment: //环境 + fallthrough + case proto.DeviceType_DeviceType_AirPavilion: //风亭 + fallthrough + case proto.DeviceType_DeviceType_CombinationAirConditioner: //组合式空调 + return nil, true //路径搜索终点 default: slog.Warn("管线路径中的设备[%d]无法处理", nextDevice.Type()) } - return nil + return nil, false //排除(舍弃)该路径搜索 } /////////////////////////////////////////////////////////////////////////////////////////// @@ -240,8 +259,9 @@ func (p *fluidPath) nextGasMixingChamberViaPipes(nextDevice *repository.GasMixin } type fluidPath struct { - curPipe repository.PipePort //路径中当前有向管线 - viaPipes []repository.PipePort //路径所经过的有向管线 + curPipe repository.PipePort //路径中当前有向管线 + viaPipes []repository.PipePort //路径所经过的有向管线 + viaPipeFittings map[string]string //经过的管件,用于排除闭环路径,key和value均为deviceId } func (p *fluidPath) addPipe(viaPipe repository.PipePort) { @@ -257,8 +277,11 @@ func (p *fluidPath) viaPipe(pipeId string) bool { return false } func (p *fluidPath) clone() *fluidPath { - cp := &fluidPath{viaPipes: make([]repository.PipePort, 0, len(p.viaPipes)), curPipe: p.curPipe} + cp := &fluidPath{viaPipes: make([]repository.PipePort, 0, len(p.viaPipes)), curPipe: p.curPipe, viaPipeFittings: make(map[string]string)} copy(cp.viaPipes, p.viaPipes) + for k, v := range p.viaPipeFittings { + cp.viaPipeFittings[k] = v + } return cp } func (p *fluidPath) nextDevice() repository.Identity {