调整仿真创建接口返回error
调整一些接口返回添加error
This commit is contained in:
parent
41a7f7a585
commit
5c41a01e69
@ -30,7 +30,7 @@ func GetWorldData(w ecs.World) *component.WorldData {
|
||||
if ok {
|
||||
return component.WorldDataType.Get(entry)
|
||||
}
|
||||
panic("不存在世界数据")
|
||||
panic("不存在世界数据组件")
|
||||
}
|
||||
|
||||
// 根据uid获取对象实体
|
||||
|
@ -24,10 +24,10 @@ func LoadTurnouts(w ecs.World) error {
|
||||
case proto.Turnout_ZDJ9_Double:
|
||||
err = LoadTurnoutZdj9Two(w, turnout, entry, data.EntityMap)
|
||||
default:
|
||||
panic(fmt.Sprintf("id=%s的道岔没有转辙机型号数据", turnout.Id()))
|
||||
return fmt.Errorf("id=%s的道岔没有转辙机型号数据", turnout.Id())
|
||||
}
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("加载道岔异常: %s", err.Error()))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -129,7 +129,7 @@ func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent
|
||||
}
|
||||
nils := zdj9TwoElectronic.CheckNilReference()
|
||||
if len(nils) > 0 {
|
||||
return fmt.Errorf("未知的道岔[%s]ZDJ9双机继电器组合数据异常,缺失:[%s]", turnout.Id(), strings.Join(nils, ","))
|
||||
return fmt.Errorf("道岔[%s]ZDJ9双机继电器组合数据异常,缺失:[%s]", turnout.Id(), strings.Join(nils, ","))
|
||||
} else {
|
||||
// 给道岔添加电路组件
|
||||
entry.AddComponent(component.Zdj9TwoElectronicType, unsafe.Pointer(zdj9TwoElectronic))
|
||||
@ -137,7 +137,7 @@ func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent
|
||||
entry.AddComponent(component.Zdj9TwoDriveType)
|
||||
}
|
||||
} else if size > 0 && size < 3 {
|
||||
return fmt.Errorf("id=[%s]的道岔是ZDJ9双机牵引,但继电器组合类型少于3个(应为TDC、TDFJ1、TDFJ2三个组合)", turnout.Id())
|
||||
return fmt.Errorf("id=[%s]的道岔是ZDJ9双机牵引,继电器组合类型应为3个,现有%d个", turnout.Id(), size)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
6
init.go
6
init.go
@ -13,9 +13,9 @@ const (
|
||||
)
|
||||
|
||||
// 初始化仿真
|
||||
func NewSimulation(repo *repository.Repository) ecs.World {
|
||||
func NewSimulation(repo *repository.Repository) (ecs.World, error) {
|
||||
w := ecs.NewWorld(RtssSimulationTick)
|
||||
sys.BindSystem(w)
|
||||
entity.Load(w, repo)
|
||||
return w
|
||||
err := entity.Load(w, repo)
|
||||
return w, err
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 37e06d2aaf64828da677131dfb790bd0de7cef56
|
||||
Subproject commit 8b25469d6ef3e8aeb1a19326d879293a9958bfe8
|
@ -209,13 +209,14 @@ func (repo *Repository) AddPhysicalSection(section *PhysicalSection) {
|
||||
repo.physicalSectionMap[section.Id()] = section
|
||||
}
|
||||
|
||||
func (repo *Repository) ConvertKilometer(km *proto.Kilometer, cs string) *proto.Kilometer {
|
||||
func (repo *Repository) ConvertKilometer(km *proto.Kilometer, cs string) (*proto.Kilometer, error) {
|
||||
if km.CoordinateSystem == cs {
|
||||
return km
|
||||
return km, nil
|
||||
}
|
||||
kc, err := repo.getKilometerConvert(km.CoordinateSystem, cs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
// panic(err)
|
||||
}
|
||||
var sourceCsKm *proto.Kilometer
|
||||
var targetCsKm *proto.Kilometer
|
||||
@ -230,7 +231,7 @@ func (repo *Repository) ConvertKilometer(km *proto.Kilometer, cs string) *proto.
|
||||
if value < 0 {
|
||||
panic(fmt.Sprintf("公里标[%v]转换为坐标系[%s]的公里标的值[%d]小于0", km, cs, value))
|
||||
}
|
||||
return &proto.Kilometer{Value: value, CoordinateSystem: cs}
|
||||
return &proto.Kilometer{Value: value, CoordinateSystem: cs}, nil
|
||||
}
|
||||
|
||||
func (repo *Repository) addKilometerConvert(kc *proto.KilometerConvert) {
|
||||
@ -247,7 +248,7 @@ func (repo *Repository) getKilometerConvert(cs1, cs2 string) (*proto.KilometerCo
|
||||
}
|
||||
|
||||
// 获取地图坐标信息
|
||||
func (repo *Repository) generateCoordinateInfo(coordinateSystem string) {
|
||||
func (repo *Repository) generateCoordinateInfo(coordinateSystem string) error {
|
||||
coordinate := &MapCoordinate{
|
||||
Coordinate: "MAIN_LINE",
|
||||
MinCoordinate: int64(math.MaxInt64),
|
||||
@ -260,7 +261,10 @@ func (repo *Repository) generateCoordinateInfo(coordinateSystem string) {
|
||||
if data.km == nil || data.km.CoordinateSystem == "" {
|
||||
continue
|
||||
}
|
||||
km := repo.ConvertKilometer(data.km, coordinate.Coordinate)
|
||||
km, err := repo.ConvertKilometer(data.km, coordinate.Coordinate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if km.Value < coordinate.MinCoordinate {
|
||||
coordinate.MinCoordinate = km.Value
|
||||
}
|
||||
@ -269,9 +273,11 @@ func (repo *Repository) generateCoordinateInfo(coordinateSystem string) {
|
||||
}
|
||||
}
|
||||
if coordinate.Coordinate == "" {
|
||||
panic("无计轴公里标信息")
|
||||
return fmt.Errorf("无计轴公里标信息")
|
||||
// panic("无计轴公里标信息")
|
||||
}
|
||||
repo.coordinate = coordinate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo Repository) GetCoordinateInfo() *MapCoordinate {
|
||||
|
@ -24,9 +24,12 @@ func BuildRepository(source *proto.Repository) (*Repository, error) {
|
||||
return nil, errors.New("数据校验未通过")
|
||||
}
|
||||
repository := newRepository(source.Id, source.Version)
|
||||
buildModels(source, repository)
|
||||
err := buildModels(source, repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zap.S().Debug("基础模型构建完毕")
|
||||
err := buildModelRelationship(source, repository)
|
||||
err = buildModelRelationship(source, repository)
|
||||
zap.S().Debug("模型关系构建完毕")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -47,7 +50,7 @@ func buildRepositoryKey(id string, version string) string {
|
||||
return id + "_" + version
|
||||
}
|
||||
|
||||
func buildModels(source *proto.Repository, repository *Repository) {
|
||||
func buildModels(source *proto.Repository, repository *Repository) error {
|
||||
for _, protoData := range source.KilometerConverts {
|
||||
repository.addKilometerConvert(protoData)
|
||||
}
|
||||
@ -115,7 +118,8 @@ func buildModels(source *proto.Repository, repository *Repository) {
|
||||
m := NewMkx(protoData.Id)
|
||||
repository.mkxMap[m.Id()] = m
|
||||
}
|
||||
repository.generateCoordinateInfo(source.MainCoordinateSystem)
|
||||
err := repository.generateCoordinateInfo(source.MainCoordinateSystem)
|
||||
return err
|
||||
}
|
||||
|
||||
func buildModelRelationship(source *proto.Repository, repository *Repository) error {
|
||||
|
Loading…
Reference in New Issue
Block a user