Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
This commit is contained in:
commit
de70c3da39
@ -1,7 +1,10 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/component"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
@ -23,3 +26,34 @@ func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry {
|
||||
system.PercentageDeviceState2Component.Set(e, j2)
|
||||
return e
|
||||
}
|
||||
|
||||
func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout, systemTypeMap map[system.Type]bool) []*ecs.Entry {
|
||||
var entries []*ecs.Entry
|
||||
for _, turnout := range turnouts {
|
||||
var components []component.IComponentType
|
||||
components = append(components, system.EntityIdentityComponent)
|
||||
components = append(components, system.MovableObject1Component)
|
||||
components = append(components, system.MovableObject2Component)
|
||||
loadZdj9Double := turnout.SwitchMachineType() == proto.Turnout_ZDJ9_Double && systemTypeMap[system.SWITCH_ZDJ9_2]
|
||||
if loadZdj9Double {
|
||||
components = append(components, system.Switch2jZdj9StateComponent)
|
||||
components = append(components, system.Switch2jZdj9CjStateComponent)
|
||||
}
|
||||
entry := world.Create(components...)
|
||||
entries = append(entries, entry)
|
||||
system.EntityIdentityComponent.Set(entry, &system.EntityIdentity{Id: turnout.Id()})
|
||||
//J1
|
||||
j1 := system.NewMovableObject()
|
||||
j1.Value = system.J1Range
|
||||
system.MovableObject1Component.Set(entry, j1)
|
||||
//J2
|
||||
j2 := system.NewMovableObject()
|
||||
j2.Value = system.J2Range
|
||||
system.MovableObject2Component.Set(entry, j2)
|
||||
if loadZdj9Double {
|
||||
system.Switch2jZdj9StateComponent.Set(entry, system.NewSwitch2jZdj9State())
|
||||
system.Switch2jZdj9CjStateComponent.Set(entry, system.NewSwitch2jZdj9CjState())
|
||||
}
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4997760ffb1284a7898ab84164671d5e21ec9248
|
||||
Subproject commit 03669cd1b34f79d2cbc7fa6f07c7dcca9386a8eb
|
57
repository/repository_check.go
Normal file
57
repository/repository_check.go
Normal file
@ -0,0 +1,57 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
)
|
||||
|
||||
// 对数据做基础检查
|
||||
func baseCheck(source *proto.Repository) []string {
|
||||
var errMsg []string
|
||||
//区段
|
||||
sectionMap := make(map[string]*proto.PhysicalSection)
|
||||
for _, section := range source.PhysicalSections {
|
||||
sectionMap[section.Id] = section
|
||||
if len(section.TurnoutIds) == 0 && section.ADevicePort == nil && section.BDevicePort == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("区段[%s]缺少关联的道岔或区段", section.Id))
|
||||
}
|
||||
}
|
||||
//道岔
|
||||
turnoutMap := make(map[string]*proto.Turnout)
|
||||
for _, turnout := range source.Turnouts {
|
||||
turnoutMap[turnout.Id] = turnout
|
||||
if turnout.Km == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少公里标", turnout.Id))
|
||||
}
|
||||
if turnout.ADevicePort == nil || turnout.BDevicePort == nil || turnout.CDevicePort == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少端口关联数据", turnout.Id))
|
||||
}
|
||||
}
|
||||
//检测点
|
||||
checkPointMap := make(map[string]*proto.CheckPoint)
|
||||
for _, point := range source.CheckPoints {
|
||||
checkPointMap[point.Id] = point
|
||||
if point.Km == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少公里标", point.Id))
|
||||
}
|
||||
}
|
||||
//信号机
|
||||
for _, signal := range source.Signals {
|
||||
if signal.Km == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("信号机[%s]缺少公里标", signal.Id))
|
||||
}
|
||||
if signal.SectionId == "" && signal.TurnoutPort == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少关联的区段或道岔", signal.Id))
|
||||
}
|
||||
}
|
||||
//应答器
|
||||
for _, transponder := range source.Transponders {
|
||||
if transponder.Km == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少公里标", transponder.Id))
|
||||
}
|
||||
if transponder.SectionId == "" && transponder.TurnoutPort == nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少关联的区段或道岔", transponder.Id))
|
||||
}
|
||||
}
|
||||
return errMsg
|
||||
}
|
@ -12,6 +12,14 @@ import (
|
||||
var repositoryMap = make(map[string]*Repository)
|
||||
|
||||
func BuildRepository(source *proto.Repository) (*Repository, error) {
|
||||
errMsg := baseCheck(source)
|
||||
if len(errMsg) != 0 {
|
||||
println("-------------------- 数据异常信息 --------------------")
|
||||
for _, s := range errMsg {
|
||||
println(s)
|
||||
}
|
||||
return nil, errors.New("数据校验未通过")
|
||||
}
|
||||
repository := newRepository(source.Id, source.Version)
|
||||
buildModels(source, repository)
|
||||
err := buildModelRelationship(source, repository)
|
||||
@ -47,7 +55,7 @@ func buildModels(source *proto.Repository, repository *Repository) {
|
||||
repository.checkPointMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Turnouts {
|
||||
m := NewTurnout(protoData.Id, protoData.Km)
|
||||
m := NewTurnout(protoData.Id, protoData.Km, protoData.SwitchMachineType)
|
||||
repository.turnoutMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Signals {
|
||||
|
@ -10,7 +10,8 @@ type Turnout struct {
|
||||
Identity
|
||||
|
||||
// 岔心的公里标
|
||||
km *proto.Kilometer
|
||||
km *proto.Kilometer
|
||||
switchMachineType proto.Turnout_SwitchMachineType
|
||||
|
||||
// 道岔关联的道岔物理区段
|
||||
section *PhysicalSection
|
||||
@ -41,10 +42,11 @@ type Turnout struct {
|
||||
cDevices []Identity
|
||||
}
|
||||
|
||||
func NewTurnout(id string, km *proto.Kilometer) *Turnout {
|
||||
func NewTurnout(id string, km *proto.Kilometer, switchMachineType proto.Turnout_SwitchMachineType) *Turnout {
|
||||
return &Turnout{
|
||||
Identity: identity{id, proto.DeviceType_DeviceType_Turnout},
|
||||
km: km,
|
||||
Identity: identity{id, proto.DeviceType_DeviceType_Turnout},
|
||||
km: km,
|
||||
switchMachineType: switchMachineType,
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,6 +197,10 @@ func (t *Turnout) FindLinkPositionByPort(port proto.Port) *LinkPosition {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Turnout) SwitchMachineType() proto.Turnout_SwitchMachineType {
|
||||
return t.switchMachineType
|
||||
}
|
||||
|
||||
type TurnoutPort struct {
|
||||
turnout *Turnout
|
||||
port proto.Port
|
||||
|
@ -2,7 +2,10 @@ package simulation
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/entities"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -22,13 +25,37 @@ func (s *Simulation) GetRepo() *repository.Repository {
|
||||
return s.repo
|
||||
}
|
||||
|
||||
func CreateSimulation(repo *repository.Repository, config *WorldConfig) int {
|
||||
world := InitializeWorld(config)
|
||||
func CreateSimulation(repo *repository.Repository, systemTypes ...system.Type) int {
|
||||
var systems []ecs.ISystem
|
||||
systemTypeMap := make(map[system.Type]bool)
|
||||
for _, systemType := range systemTypes {
|
||||
switch systemType {
|
||||
case system.SWITCH_ZDJ9_2:
|
||||
systems = append(systems, system.NewSwitch2jZdj9System())
|
||||
case system.RELAY:
|
||||
systems = append(systems, system.NewRelaySystem())
|
||||
case system.DEBUG:
|
||||
systems = append(systems, system.NewDebugSystem())
|
||||
}
|
||||
systemTypeMap[systemType] = true
|
||||
}
|
||||
wc := &WorldConfig{
|
||||
Systems: systems,
|
||||
Tick: 200,
|
||||
InitTime: time.Now(),
|
||||
}
|
||||
world := InitializeWorld(wc)
|
||||
sim := &Simulation{
|
||||
world: world,
|
||||
repo: repo,
|
||||
}
|
||||
simulationManager[world.Id()] = sim
|
||||
//添加实体
|
||||
entities.CreateTurnoutEntries(world, repo.TurnoutList(), systemTypeMap)
|
||||
//初始化组件
|
||||
initComponent(world)
|
||||
//启动
|
||||
world.StartUp()
|
||||
return int(world.Id())
|
||||
}
|
||||
|
||||
@ -39,3 +66,7 @@ func DestroySimulation(id ecs.WorldId) {
|
||||
func FindSimulation(id ecs.WorldId) *Simulation {
|
||||
return simulationManager[id]
|
||||
}
|
||||
|
||||
func initComponent(world ecs.World) {
|
||||
|
||||
}
|
||||
|
10
system/type.go
Normal file
10
system/type.go
Normal file
@ -0,0 +1,10 @@
|
||||
package system
|
||||
|
||||
type Type int
|
||||
|
||||
const (
|
||||
SWITCH_ZDJ9_2 Type = iota //ZDJ9双机牵引转辙机
|
||||
//SWITCH_ZDJ9_1 //ZDJ9单机牵引转辙机
|
||||
RELAY //继电器
|
||||
DEBUG
|
||||
)
|
Loading…
Reference in New Issue
Block a user