This commit is contained in:
xzb 2023-10-20 16:02:49 +08:00
commit 61ff2efbc0
7 changed files with 34 additions and 24 deletions

View File

@ -209,10 +209,10 @@ func LoadEMPEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap,
for _, light := range spkData.Lights() {
e := NewIBPLightEntity(w, light.Id(), entityMap)
switch light.Code() {
case "XEMPD":
emp.XEMPJ = e
case "SEMPD":
emp.SEMPJ = e
case "X紧急关闭":
emp.XEMPD = e
case "S紧急关闭":
emp.SEMPD = e
}
}
// 蜂鸣器

View File

@ -30,7 +30,7 @@ func GetWorldData(w ecs.World) *component.WorldData {
if ok {
return component.WorldDataType.Get(entry)
}
panic("不存在世界数据")
panic("不存在世界数据组件")
}
// 根据uid获取对象实体

View File

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

View File

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

View File

@ -218,13 +218,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
@ -239,7 +240,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) {
@ -256,7 +257,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),
@ -269,7 +270,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
}
@ -278,9 +282,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 {

View File

@ -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)
}
@ -119,7 +122,8 @@ func buildModels(source *proto.Repository, repository *Repository) {
m := NewKey(protoData.Id, protoData.Code, protoData.Gear)
repository.keyMap[m.Id()] = m
}
repository.generateCoordinateInfo(source.MainCoordinateSystem)
err := repository.generateCoordinateInfo(source.MainCoordinateSystem)
return err
}
func buildModelRelationship(source *proto.Repository, repository *Repository) error {