iscs bas 大系统

This commit is contained in:
xzb 2023-12-26 14:45:41 +08:00
parent 7deeabe23e
commit 19a231c95b
6 changed files with 68 additions and 22 deletions

View File

@ -11,7 +11,7 @@ func NewWireCabinetEntity(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.WireCabinetType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.WireCabinetType, 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
} }
@ -23,7 +23,7 @@ func NewNetworkSwitchEntity(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.NetworkSwitchType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.NetworkSwitchType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.NetworkSwitchType.Set(e, &component.NetworkSwitch{Normal: true}) component.NetworkSwitchType.Set(e, &component.NetworkSwitch{Normal: true})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -36,7 +36,7 @@ func NewAirPavilionEntity(w ecs.World, id string, apType proto.AirPavilion_Type)
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 { switch apType {
case proto.AirPavilion_ExhaustPavilion: case proto.AirPavilion_ExhaustPavilion:
@ -57,7 +57,7 @@ func NewValveEntity(w ecs.World, id string, valveType proto.Valve_Type) *ecs.Ent
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.ValveType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.ValveType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.ValveType.Set(e, &component.Valve{OpenRate: 100, Closed: false, Opened: true, Moving: false}) component.ValveType.Set(e, &component.Valve{OpenRate: 100, Closed: false, Opened: true, Moving: false})
// //
@ -82,7 +82,7 @@ func NewGasMixingChamberEntity(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.GasMixingChamberType)) e = w.Entry(w.Create(component.UidType, component.GasMixingChamberType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e wd.EntityMap[id] = e
} }
@ -97,7 +97,7 @@ func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[str
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.AirConditioningType, component.DeviceExceptionType, tag)) e = w.Entry(w.Create(component.UidType, component.AirConditioningType, component.DeviceExceptionType, tag))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e wd.EntityMap[id] = e
} }
@ -109,7 +109,7 @@ func NewPurificationDeviceEntity(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.PurificationDeviceType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.PurificationDeviceType, 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
} }
@ -121,7 +121,7 @@ func NewAirCurtainEntity(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.AirCurtainType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.AirCurtainType, 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
} }
@ -133,7 +133,7 @@ func NewGasEnvironmentEntity(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.GasEnvironmentType)) e = w.Entry(w.Create(component.UidType, component.GasEnvironmentType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e wd.EntityMap[id] = e
} }
@ -145,7 +145,7 @@ func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *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.FanDeviceType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.FanDeviceType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.FanDeviceType.Set(e, &component.FanDevice{Speed: 0, Forward: true, Fs: component.Off}) component.FanDeviceType.Set(e, &component.FanDevice{Speed: 0, Forward: true, Fs: component.Off})
// //

View File

@ -12,7 +12,7 @@ func NewCircuitBreakerEntity(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.CircuitBreakerType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.CircuitBreakerType, 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
} }
@ -24,7 +24,7 @@ func NewThreePositionSwitchEntity(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.ThreePositionSwitchType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.ThreePositionSwitchType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.ThreePositionSwitchType.Set(e, &component.ThreePositionSwitch{Position: component.StpOpened}) component.ThreePositionSwitchType.Set(e, &component.ThreePositionSwitch{Position: component.StpOpened})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -37,7 +37,7 @@ func NewHandcartSwitchEntity(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.HandcartSwitchType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.HandcartSwitchType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.HandcartSwitchType.Set(e, &component.HandcartSwitch{Position: component.HpOpened}) component.HandcartSwitchType.Set(e, &component.HandcartSwitch{Position: component.HpOpened})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -50,7 +50,7 @@ func NewRectifierEntity(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.RectifierType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.RectifierType, 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
} }
@ -62,7 +62,7 @@ func NewDisconnectorEntity(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.DisconnectorType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.DisconnectorType, 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
} }
@ -74,7 +74,7 @@ func NewLightningArresterEntity(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.LightningArresterType)) e = w.Entry(w.Create(component.UidType, component.LightningArresterType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.LightningArresterType.Set(e, &component.LightningArrester{Normal: true}) component.LightningArresterType.Set(e, &component.LightningArrester{Normal: true})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -87,7 +87,7 @@ func NewEarthingDeviceEntity(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.EarthingDeviceType)) e = w.Entry(w.Create(component.UidType, component.EarthingDeviceType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.EarthingDeviceType.Set(e, &component.EarthingDevice{Voltage: 0}) component.EarthingDeviceType.Set(e, &component.EarthingDevice{Voltage: 0})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -100,7 +100,7 @@ func NewVoltageTransformerEntity(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.VoltageTransformerType, component.DeviceExceptionType)) e = w.Entry(w.Create(component.UidType, component.VoltageTransformerType, 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
} }
@ -112,7 +112,7 @@ func NewPowerPipeEntity(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.PowerPipeType)) e = w.Entry(w.Create(component.UidType, component.PowerPipeType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.PowerPipeType.Set(e, &component.PowerPipe{Sources: make(map[string]*component.ElePower)}) component.PowerPipeType.Set(e, &component.PowerPipe{Sources: make(map[string]*component.ElePower)})
wd.EntityMap[id] = e wd.EntityMap[id] = e
@ -125,7 +125,7 @@ func NewPowerSourceEntity(w ecs.World, id string, ac bool, voltage uint32) *ecs.
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.PowerSourceType)) e = w.Entry(w.Create(component.UidType, component.PowerSourceType))
component.UidType.SetValue(e, component.Uid{Id: id}) component.UidType.SetValue(e, component.Uid{Id: id})
component.PowerSourceType.Set(e, &component.PowerSource{Ac: ac, Voltage: voltage}) component.PowerSourceType.Set(e, &component.PowerSource{Ac: ac, Voltage: voltage})
wd.EntityMap[id] = e wd.EntityMap[id] = e

View File

@ -1,6 +1,10 @@
package main package main
import ( import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/sys"
"time" "time"
rtss_simulation "joylink.club/rtsssimulation" rtss_simulation "joylink.club/rtsssimulation"
@ -8,6 +12,35 @@ import (
) )
func main() { func main() {
protoRepo := &proto.Repository{}
protoRepo.Id = "1"
protoRepo.Version = "V1"
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan1", FanType: proto.Fan_CommonFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan2", FanType: proto.Fan_FcBypassFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan3", FanType: proto.Fan_SoftStartFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan4", FanType: proto.Fan_HighLowSpeedFan})
//
repo, _ := repository.BuildRepository(protoRepo)
sim, _ := newIscsSimulation(repo)
sim.StartUp()
sim.SetSpeed(1)
time.Sleep(8 * time.Second)
sim.Close()
time.Sleep(2 * time.Second)
}
func newIscsSimulation(repo *repository.Repository) (ecs.World, error) {
w := ecs.NewWorld(100)
sys.BindIscsSystem(w)
//
// 初始化世界数据单例组件
entity.LoadWorldData(w, repo)
err := entity.LoadIscs(w)
return w, err
}
///////////////////////////////////////////////////////
func main1() {
sim, _ := rtss_simulation.NewSimulation(&repository.Repository{}) sim, _ := rtss_simulation.NewSimulation(&repository.Repository{})
sim.StartUp() sim.StartUp()
sim.SetSpeed(2) sim.SetSpeed(2)

View File

@ -39,6 +39,11 @@ func BuildRepository(source *proto.Repository) (*Repository, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = buildIscsModelRelationship(source, repository)
if err != nil {
return nil, err
}
//
repositoryMap[buildRepositoryKey(source.Id, source.Version)] = repository repositoryMap[buildRepositoryKey(source.Id, source.Version)] = repository
return repository, err return repository, err
} }
@ -134,9 +139,15 @@ func buildModels(source *proto.Repository, repository *Repository) error {
repository.platformMap[m.Id()] = m repository.platformMap[m.Id()] = m
} }
err := repository.generateCoordinateInfo(source.MainCoordinateSystem) err := repository.generateCoordinateInfo(source.MainCoordinateSystem)
if err != nil {
return err
}
for _, protoData := range source.CentralizedStationRefs { for _, protoData := range source.CentralizedStationRefs {
repository.centralizedMap[protoData.StationId] = protoData repository.centralizedMap[protoData.StationId] = protoData
} }
//
err = buildIscsModels(source, repository)
//
return err return err
} }

View File

@ -43,8 +43,8 @@ func BindSystem(w ecs.World) {
) )
} }
// ISCS 系统 // BindIscsSystem ISCS 系统
func bindIscsSystem(w ecs.World) { func BindIscsSystem(w ecs.World) {
w.AddSystem( w.AddSystem(
iscs_sys.NewIscsExceptionSystem(), iscs_sys.NewIscsExceptionSystem(),
iscs_sys.NewDevicePlacingSystem(), iscs_sys.NewDevicePlacingSystem(),

View File

@ -19,8 +19,10 @@ func NewFanSystem() *FanSystem {
} }
func (s *FanSystem) Update(w ecs.World) { func (s *FanSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
//fanId := component.UidType.Get(entry).Id
fan := component.FanDeviceType.Get(entry) fan := component.FanDeviceType.Get(entry)
fan.Forward = fan.Fs.OnForward() fan.Forward = fan.Fs.OnForward()
//fmt.Printf("==>>风机[%s] forward=%t speed=%f fan-switch=%d\n", fanId, fan.Forward, fan.Speed, fan.Fs)
// //
speed := fan.Speed + s.calculateAc(fan, entry)*float32(w.Tick()) speed := fan.Speed + s.calculateAc(fan, entry)*float32(w.Tick())
// //