iscs bas 大系统
This commit is contained in:
parent
411a5e0157
commit
2dfe213742
@ -5,7 +5,6 @@ import "joylink.club/ecs"
|
||||
// AirConditioning 空调
|
||||
type AirConditioning struct {
|
||||
Running bool //true-运行正常;false-停止
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
|
21
component/iscs_bas_pipe.go
Normal file
21
component/iscs_bas_pipe.go
Normal file
@ -0,0 +1,21 @@
|
||||
package component
|
||||
|
||||
import "joylink.club/ecs"
|
||||
|
||||
// FluidPipe 流体管线
|
||||
//
|
||||
// 管线内流体流动条件:1、管线内有流体;2、管线两端有压差;3、管线畅通
|
||||
type FluidPipe struct {
|
||||
FlowVelocity int32 //流速,大于零从管线A端向B端流动,小于零从管线B端向A端流动,等于零没有流动
|
||||
}
|
||||
|
||||
// FluidDriver 流体驱动器
|
||||
type FluidDriver struct {
|
||||
On bool //true-输出流体驱动力;false-未输出流体驱动力
|
||||
Forward bool //true-正转;false-反转
|
||||
}
|
||||
|
||||
var (
|
||||
FluidPipeType = ecs.NewComponentType[FluidPipe]() //流体管线
|
||||
FluidDriverType = ecs.NewComponentType[FluidDriver]() //流体驱动器
|
||||
)
|
@ -101,7 +101,7 @@ func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[str
|
||||
wd := GetWorldData(w)
|
||||
e, ok := wd.EntityMap[id]
|
||||
if !ok {
|
||||
e = w.Entry(w.Create(component.UidType, component.AirConditioningType, component.DeviceExceptionType, tag))
|
||||
e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.FluidDriverType, component.DeviceExceptionType, tag))
|
||||
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||
wd.EntityMap[id] = e
|
||||
}
|
||||
@ -149,7 +149,7 @@ func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *ecs.Entry {
|
||||
wd := GetWorldData(w)
|
||||
e, ok := wd.EntityMap[id]
|
||||
if !ok {
|
||||
e = w.Entry(w.Create(component.UidType, component.MotorType, component.DeviceExceptionType))
|
||||
e = w.Entry(w.Create(component.UidType, component.MotorType, component.FluidDriverType, component.DeviceExceptionType))
|
||||
component.UidType.SetValue(e, component.Uid{Id: id})
|
||||
component.MotorType.Set(e, &component.Motor{Speed: 0, Forward: true, Ms: component.MsOff})
|
||||
//
|
||||
|
@ -136,6 +136,26 @@ func NewCombinationAirConditioner(id string, code string) *CombinationAirConditi
|
||||
func (p *CombinationAirConditioner) PortNum() int {
|
||||
return 4
|
||||
}
|
||||
func (p *CombinationAirConditioner) Outputs() []DevicePort {
|
||||
var out []DevicePort
|
||||
if p.PortB != nil {
|
||||
out = append(out, p.PortB)
|
||||
}
|
||||
if p.PortC != nil {
|
||||
out = append(out, p.PortC)
|
||||
}
|
||||
return out
|
||||
}
|
||||
func (p *CombinationAirConditioner) Inputs() []DevicePort {
|
||||
var in []DevicePort
|
||||
if p.PortA != nil {
|
||||
in = append(in, p.PortA)
|
||||
}
|
||||
if p.PortD != nil {
|
||||
in = append(in, p.PortD)
|
||||
}
|
||||
return in
|
||||
}
|
||||
|
||||
// CombinationAirConditionerPort 组合式空调端口
|
||||
//
|
||||
@ -211,8 +231,8 @@ type Fan struct {
|
||||
Code string
|
||||
FanType proto.Fan_Type
|
||||
*fanRunningModel
|
||||
PortA DevicePort //A端口连接的设备,风机出风口即排风口
|
||||
PortB DevicePort //B端口连接的设备,风机进风口
|
||||
PortA DevicePort //A端口连接的设备,风机出风口即排风口,输出端口
|
||||
PortB DevicePort //B端口连接的设备,风机进风口,输入端口
|
||||
}
|
||||
|
||||
func NewFan(id string, code string, fanType proto.Fan_Type) *Fan {
|
||||
@ -226,6 +246,18 @@ func NewFan(id string, code string, fanType proto.Fan_Type) *Fan {
|
||||
func (p *Fan) PortNum() int {
|
||||
return 2
|
||||
}
|
||||
func (p *Fan) Outputs() []DevicePort {
|
||||
if p.PortA == nil {
|
||||
return nil
|
||||
}
|
||||
return []DevicePort{p.PortA}
|
||||
}
|
||||
func (p *Fan) Inputs() []DevicePort {
|
||||
if p.PortB == nil {
|
||||
return nil
|
||||
}
|
||||
return []DevicePort{p.PortB}
|
||||
}
|
||||
|
||||
// FanPort 风机端口
|
||||
//
|
||||
|
29
sys/iscs_sys/iscs_bas_air_conditioner.go
Normal file
29
sys/iscs_sys/iscs_bas_air_conditioner.go
Normal file
@ -0,0 +1,29 @@
|
||||
package iscs_sys
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/ecs/filter"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
)
|
||||
|
||||
// AirConditionerSystem 空调
|
||||
type AirConditionerSystem struct {
|
||||
query *ecs.Query
|
||||
}
|
||||
|
||||
func NewAirConditionerSystem() *AirConditionerSystem {
|
||||
return &AirConditionerSystem{
|
||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.MotorType, component.AirConditioningType, component.FluidDriverType)),
|
||||
}
|
||||
}
|
||||
func (s *AirConditionerSystem) Update(w ecs.World) {
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
motor := component.MotorType.Get(entry)
|
||||
fluidDriver := component.FluidDriverType.Get(entry)
|
||||
air := component.AirConditioningType.Get(entry)
|
||||
//
|
||||
air.Running = motor.Speed > 0
|
||||
fluidDriver.On = air.Running
|
||||
fluidDriver.Forward = motor.Forward
|
||||
})
|
||||
}
|
@ -14,13 +14,14 @@ type FanSystem struct {
|
||||
// NewFanSystem 风机系统
|
||||
func NewFanSystem() *FanSystem {
|
||||
return &FanSystem{
|
||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.MotorType, component.DeviceExceptionType)),
|
||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.MotorType, component.FluidDriverType, component.DeviceExceptionType)),
|
||||
}
|
||||
}
|
||||
func (s *FanSystem) Update(w ecs.World) {
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
//fanId := component.UidType.Get(entry).Id
|
||||
fan := component.MotorType.Get(entry)
|
||||
fluidDriver := component.FluidDriverType.Get(entry)
|
||||
//fmt.Printf("====>>>fanId = %s , forward = %t , speed = %f , ms = %d\n", fanId, fan.Forward, fan.Speed, fan.Ms)
|
||||
//一般风机(3000 r/min)
|
||||
if entry.HasComponent(component.CommonFanTag) {
|
||||
@ -47,5 +48,8 @@ func (s *FanSystem) Update(w ecs.World) {
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
fluidDriver.On = fan.Speed > 0
|
||||
fluidDriver.Forward = fan.Forward
|
||||
})
|
||||
}
|
||||
|
51
sys/iscs_sys/iscs_bas_fluid.go
Normal file
51
sys/iscs_sys/iscs_bas_fluid.go
Normal file
@ -0,0 +1,51 @@
|
||||
package iscs_sys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/ecs/filter"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
)
|
||||
|
||||
// FluidDriverSystem 流体驱动系统
|
||||
// 实现流体在设备、管线中流动
|
||||
type FluidDriverSystem struct {
|
||||
query *ecs.Query
|
||||
}
|
||||
|
||||
func NewFluidDriverSystem() *FluidDriverSystem {
|
||||
return &FluidDriverSystem{
|
||||
query: ecs.NewQuery(filter.Contains(component.UidType, component.FluidDriverType)),
|
||||
}
|
||||
}
|
||||
|
||||
// 流体驱动系统依赖的数据
|
||||
type fluidDriverModel interface {
|
||||
Outputs() []repository.DevicePort
|
||||
Inputs() []repository.DevicePort
|
||||
}
|
||||
|
||||
func (s *FluidDriverSystem) Update(w ecs.World) {
|
||||
wd := entity.GetWorldData(w)
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
fdId := component.UidType.Get(entry).Id
|
||||
fd := component.FluidDriverType.Get(entry)
|
||||
fdModel, fdModelOk := wd.Repo.FindById(fdId).(fluidDriverModel)
|
||||
if !fdModelOk {
|
||||
fmt.Printf("==>>FluidDriverSystem.Update FluidDriver[%s]未实现接口fluidDriverModel\n", fdId)
|
||||
} else {
|
||||
s.fluidDrive(entry, fd, fdModel)
|
||||
}
|
||||
})
|
||||
}
|
||||
func (s *FluidDriverSystem) fluidDrive(entry *ecs.Entry, fd *component.FluidDriver, fdModel fluidDriverModel) {
|
||||
for _, out := range fdModel.Outputs() {
|
||||
switch out.Device().Type() {
|
||||
case proto.DeviceType_DeviceType_Pipe:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -16,12 +16,13 @@ type WaterPumpSystem struct {
|
||||
|
||||
func NewWaterPumpSystem() *WaterPumpSystem {
|
||||
return &WaterPumpSystem{
|
||||
query: ecs.NewQuery(filter.Contains(component.WaterPumpType, component.DeviceExceptionType)),
|
||||
query: ecs.NewQuery(filter.Contains(component.WaterPumpType, component.FluidDriverType, component.DeviceExceptionType)),
|
||||
}
|
||||
}
|
||||
func (s *WaterPumpSystem) Update(w ecs.World) {
|
||||
s.query.Each(w, func(entry *ecs.Entry) {
|
||||
pump := component.WaterPumpType.Get(entry)
|
||||
fluidDriver := component.FluidDriverType.Get(entry)
|
||||
//浮球型水泵,水箱水位控制浮球开关从而控制水泵开关
|
||||
if entry.HasComponent(component.FloatBallSwitchType) {
|
||||
fbs := component.FloatBallSwitchType.Get(entry)
|
||||
@ -33,5 +34,7 @@ func (s *WaterPumpSystem) Update(w ecs.World) {
|
||||
if de.Exception != consts.DeviceExceptionNon {
|
||||
pump.Running = false
|
||||
}
|
||||
//
|
||||
fluidDriver.On = pump.Running
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user