iscs bas 大系统

This commit is contained in:
xzb 2024-01-09 09:39:03 +08:00
parent 9b16941d2f
commit d443ee3c41
8 changed files with 86 additions and 63 deletions

View File

@ -9,8 +9,4 @@ type AirConditioning struct {
var (
AirConditioningType = ecs.NewComponentType[AirConditioning]() //空调
CombinationAirConditionerTag = ecs.NewTag() //组合式空调(变频空调)
AirConditioningGroupTag = ecs.NewTag() //空调群控系统
AirConditionerTag = ecs.NewTag() //空调器
)

View File

@ -9,6 +9,4 @@ type AirPavilion struct {
var (
AirPavilionType = ecs.NewComponentType[AirPavilion]() //风亭
ExhaustPavilionTag = ecs.NewTag() //排风亭
AirSupplyPavilionTag = ecs.NewTag() //送风亭
)

View File

@ -118,7 +118,6 @@ var (
PipeType = ecs.NewComponentType[Pipe]() //电线
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
)

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}
})
}

View File

@ -13,16 +13,16 @@ import (
// FluidDriverSystem 流体驱动系统
// 实现流体在设备、管线中流动
// 流体驱动源(风机、送风亭、泵)
// 流体驱动源(风机、泵、组合式空调)
type FluidDriverSystem struct {
query *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)),
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,13 +151,14 @@ 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 {
} else {
if lenNextPipes == 1 {
if !searchContext.viaPipe(nextViaPipes[0].Device().Id()) && !s.exclude(nextViaPipes[0].Device().Id()) {
searchContext.addPipe(nextViaPipes[0])
s.doSearch(searchContext)
@ -174,25 +177,41 @@ func (s *fluidDriverPathSearcher) doSearch(searchContext *fluidPath) {
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 //排除(舍弃)该路径搜索
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -242,6 +261,7 @@ func (p *fluidPath) nextGasMixingChamberViaPipes(nextDevice *repository.GasMixin
type fluidPath struct {
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 {