iscs bas 大系统
This commit is contained in:
parent
9b16941d2f
commit
d443ee3c41
@ -9,8 +9,4 @@ type AirConditioning struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调
|
AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调
|
||||||
|
|
||||||
CombinationAirConditionerTag = ecs.NewTag() //组合式空调(变频空调)
|
|
||||||
AirConditioningGroupTag = ecs.NewTag() //空调群控系统
|
|
||||||
AirConditionerTag = ecs.NewTag() //空调器
|
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,5 @@ type AirPavilion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭
|
AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭
|
||||||
ExhaustPavilionTag = ecs.NewTag() //排风亭
|
|
||||||
AirSupplyPavilionTag = ecs.NewTag() //送风亭
|
|
||||||
)
|
)
|
||||||
|
@ -115,10 +115,9 @@ func NewPipeFluid() *PipeFluid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
PipeType = ecs.NewComponentType[Pipe]() //电线
|
PipeType = ecs.NewComponentType[Pipe]() //电线
|
||||||
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
|
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
|
||||||
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
|
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
|
||||||
|
|
||||||
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
|
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -34,19 +34,12 @@ func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewAirPavilionEntity 创建风亭实体
|
// 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)
|
wd := GetWorldData(w)
|
||||||
e, ok := wd.EntityMap[id]
|
e, ok := wd.EntityMap[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = w.Entry(w.Create(component.UidType, component.AirPavilionType))
|
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.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
||||||
wd.EntityMap[id] = e
|
wd.EntityMap[id] = e
|
||||||
@ -93,15 +86,24 @@ func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinationAirConditionerEntity 创建组合式空调实体
|
// NewCombinationAirConditionerEntity 创建组合式空调(变频)实体
|
||||||
func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
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)
|
wd := GetWorldData(w)
|
||||||
e, ok := wd.EntityMap[id]
|
e, ok := wd.EntityMap[id]
|
||||||
if !ok {
|
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})
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||||
wd.EntityMap[id] = e
|
wd.EntityMap[id] = e
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func LoadIscs(w ecs.World) error {
|
|||||||
}
|
}
|
||||||
//风亭(排风亭、送风亭)
|
//风亭(排风亭、送风亭)
|
||||||
for _, ap := range data.Repo.AirPavilionMap {
|
for _, ap := range data.Repo.AirPavilionMap {
|
||||||
NewAirPavilionEntity(w, ap.Id(), ap.PavilionType)
|
NewAirPavilionEntity(w, ap.Id())
|
||||||
}
|
}
|
||||||
//阀门
|
//阀门
|
||||||
for _, valve := range data.Repo.ValveMap {
|
for _, valve := range data.Repo.ValveMap {
|
||||||
|
@ -22,5 +22,10 @@ func (s *AirConditionerSystem) Update(w ecs.World) {
|
|||||||
air := component.AirConditioningType.Get(entry)
|
air := component.AirConditioningType.Get(entry)
|
||||||
//
|
//
|
||||||
air.Running = motor.Speed > 0
|
air.Running = motor.Speed > 0
|
||||||
|
//
|
||||||
|
if entry.HasComponent(component.FluidDriverType) {
|
||||||
|
fd := component.FluidDriverType.Get(entry)
|
||||||
|
fd.On = motor.Speed > 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,17 @@ import (
|
|||||||
|
|
||||||
// FluidDriverSystem 流体驱动系统
|
// FluidDriverSystem 流体驱动系统
|
||||||
// 实现流体在设备、管线中流动
|
// 实现流体在设备、管线中流动
|
||||||
// 流体驱动源(风机、送风亭、泵)
|
// 流体驱动源(风机、泵、组合式空调)
|
||||||
type FluidDriverSystem struct {
|
type FluidDriverSystem struct {
|
||||||
query *ecs.Query //流体驱动源
|
queryFluidDriver *ecs.Query //流体驱动源
|
||||||
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
drivePathMap map[string][]*SearchedPath //key pipePortId,value 驱动源驱动流体的路径
|
||||||
queryFluidPipe *ecs.Query
|
queryFluidPipe *ecs.Query
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFluidDriverSystem() *FluidDriverSystem {
|
func NewFluidDriverSystem() *FluidDriverSystem {
|
||||||
return &FluidDriverSystem{
|
return &FluidDriverSystem{
|
||||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
|
queryFluidDriver: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
|
||||||
queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.PipeFluidType)),
|
queryFluidPipe: ecs.NewQuery(filter.Contains(component.UidType, component.PipeFluidType)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,9 @@ func (s *FluidDriverSystem) findFluidPath(fromDevice repository.Identity, fromDe
|
|||||||
return sp
|
return sp
|
||||||
}
|
}
|
||||||
func (s *FluidDriverSystem) Update(w ecs.World) {
|
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 {
|
func (s *fluidDriverPathSearcher) search() []*SearchedPath {
|
||||||
var rt []*SearchedPath
|
var rt []*SearchedPath
|
||||||
if !s.exclude(s.fromDevicePortPipe.Device().Id()) {
|
if !s.exclude(s.fromDevicePortPipe.Device().Id()) {
|
||||||
searchContext := &fluidPath{}
|
searchContext := &fluidPath{viaPipeFittings: make(map[string]string)}
|
||||||
searchContext.addPipe(s.fromDevicePortPipe)
|
searchContext.addPipe(s.fromDevicePortPipe)
|
||||||
s.doSearch(searchContext)
|
s.doSearch(searchContext)
|
||||||
} else {
|
} else {
|
||||||
@ -149,50 +151,67 @@ func (s *fluidDriverPathSearcher) addSearchedPath(searchContext *fluidPath) {
|
|||||||
s.searchedPaths = append(s.searchedPaths, searchContext)
|
s.searchedPaths = append(s.searchedPaths, searchContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 递归搜索
|
// 搜索
|
||||||
func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) {
|
func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) {
|
||||||
nextViaPipes := searchContext.nextViaPathPipes()
|
nextViaPipes, end := searchContext.nextViaPathPipes()
|
||||||
lenNextPipes := len(nextViaPipes)
|
lenNextPipes := len(nextViaPipes)
|
||||||
if lenNextPipes == 0 {
|
if end {
|
||||||
s.addSearchedPath(searchContext)
|
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 {
|
} else {
|
||||||
for _, nextViaPipe := range nextViaPipes {
|
if lenNextPipes == 1 {
|
||||||
if searchContext.viaPipe(nextViaPipe.Device().Id()) { //舍弃回头路径
|
if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) {
|
||||||
continue
|
searchContext.addPipe(nextViaPipes[0])
|
||||||
|
s.doSearch(searchContext)
|
||||||
}
|
}
|
||||||
if s.exclude(nextViaPipe.Device().Id()) { //舍弃排除路径
|
} else {
|
||||||
continue
|
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()
|
nextDevice := p.nextDevice()
|
||||||
|
//
|
||||||
switch nextDevice.Type() {
|
switch nextDevice.Type() {
|
||||||
case proto.DeviceType_DeviceType_PipeFitting:
|
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:
|
case proto.DeviceType_DeviceType_Valve:
|
||||||
return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe)
|
return p.nextDeviceViaPipes(nextDevice.(*repository.Valve).Ports(), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_GasMixingChamber:
|
case proto.DeviceType_DeviceType_GasMixingChamber: //静压箱
|
||||||
return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe)
|
return p.nextGasMixingChamberViaPipes(nextDevice.(*repository.GasMixingChamber), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_CombinationAirConditioner:
|
case proto.DeviceType_DeviceType_AirPurificationDevice: //净化装置
|
||||||
return p.nextCombinationAirConditionerViaPipes(nextDevice.(*repository.CombinationAirConditioner), p.curPipe)
|
return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe), false
|
||||||
case proto.DeviceType_DeviceType_AirPurificationDevice:
|
case proto.DeviceType_DeviceType_Environment: //环境
|
||||||
return p.nextDeviceViaPipes(nextDevice.(*repository.AirPurificationDevice).Ports(), p.curPipe)
|
fallthrough
|
||||||
|
case proto.DeviceType_DeviceType_AirPavilion: //风亭
|
||||||
|
fallthrough
|
||||||
|
case proto.DeviceType_DeviceType_CombinationAirConditioner: //组合式空调
|
||||||
|
return nil, true //路径搜索终点
|
||||||
default:
|
default:
|
||||||
slog.Warn("管线路径中的设备[%d]无法处理", nextDevice.Type())
|
slog.Warn("管线路径中的设备[%d]无法处理", nextDevice.Type())
|
||||||
}
|
}
|
||||||
return nil
|
return nil, false //排除(舍弃)该路径搜索
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -240,8 +259,9 @@ func (p *fluidPath) nextGasMixingChamberViaPipes(nextDevice *repository.GasMixin
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fluidPath struct {
|
type fluidPath struct {
|
||||||
curPipe repository.PipePort //路径中当前有向管线
|
curPipe repository.PipePort //路径中当前有向管线
|
||||||
viaPipes []repository.PipePort //路径所经过的有向管线
|
viaPipes []repository.PipePort //路径所经过的有向管线
|
||||||
|
viaPipeFittings map[string]string //经过的管件,用于排除闭环路径,key和value均为deviceId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *fluidPath) addPipe(viaPipe repository.PipePort) {
|
func (p *fluidPath) addPipe(viaPipe repository.PipePort) {
|
||||||
@ -257,8 +277,11 @@ func (p *fluidPath) viaPipe(pipeId string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (p *fluidPath) clone() *fluidPath {
|
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)
|
copy(cp.viaPipes, p.viaPipes)
|
||||||
|
for k, v := range p.viaPipeFittings {
|
||||||
|
cp.viaPipeFittings[k] = v
|
||||||
|
}
|
||||||
return cp
|
return cp
|
||||||
}
|
}
|
||||||
func (p *fluidPath) nextDevice() repository.Identity {
|
func (p *fluidPath) nextDevice() repository.Identity {
|
||||||
|
Loading…
Reference in New Issue
Block a user