From 0aa3290e734f963ff7eef5fee4200c4ce973519b Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 19 Oct 2023 16:38:46 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=94=9F=E4=BA=A7=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E5=85=AC=E9=87=8C=E6=A0=87=E4=BF=A1=E6=81=AF=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/ibp.go | 4 ++-- repository/coordinate.go | 8 +++++++ repository/repository.go | 37 ++++++++++++++++++++++++++++++++ repository/repository_manager.go | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 repository/coordinate.go diff --git a/entity/ibp.go b/entity/ibp.go index 88c068b..36ffe6f 100644 --- a/entity/ibp.go +++ b/entity/ibp.go @@ -33,7 +33,7 @@ func NewButtonEntity(w ecs.World, data *repository.Button, entityMap map[string] component.UidType.SetValue(entry, component.Uid{Id: uid}) // 带灯按钮 if data.HasLight() { - entry.AddComponent(component.SingleLightType, unsafe.Pointer(NewLightHEntity(w))) + entry.AddComponent(component.SingleLightType, unsafe.Pointer(NewLightEntity(w))) } entityMap[uid] = entry } @@ -56,7 +56,7 @@ func NewAlarmEntity(w ecs.World, alarm *repository.Alarm, entityMap map[string]* func NewIBPLightEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry { entry, ok := entityMap[uid] if !ok { - entry = w.Entry(w.Create(component.LightTag, component.HdTag, component.UidType, component.LightDriveType, component.BitStateType)) + entry = w.Entry(w.Create(component.LightTag, component.UidType, component.LightDriveType, component.BitStateType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) entityMap[uid] = entry } diff --git a/repository/coordinate.go b/repository/coordinate.go new file mode 100644 index 0000000..150b5f2 --- /dev/null +++ b/repository/coordinate.go @@ -0,0 +1,8 @@ +package repository + +// 检测点 +type MapCoordinate struct { + Coordinate string // 坐标系 + MinCoordinate int64 // 坐标系最小值 + MaxCoordinate int64 // 坐标系最大值 +} diff --git a/repository/repository.go b/repository/repository.go index 395bb06..ed456d6 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -2,6 +2,7 @@ package repository import ( "fmt" + "math" "joylink.club/rtsssimulation/repository/model/proto" ) @@ -9,6 +10,7 @@ import ( type Repository struct { id string version string + coordinate *MapCoordinate // 基准坐标系类型,在列车画图时统一坐标系 physicalSectionMap map[string]*PhysicalSection checkPointMap map[string]*CheckPoint turnoutMap map[string]*Turnout @@ -244,6 +246,41 @@ func (repo *Repository) getKilometerConvert(cs1, cs2 string) (*proto.KilometerCo return convert, nil } +// 获取地图坐标信息 +func (repo Repository) generateCoordinateInfo() *MapCoordinate { + if repo.coordinate != nil { + return repo.coordinate + } + coordinate := &MapCoordinate{ + MinCoordinate: int64(math.MaxInt64), + MaxCoordinate: int64(math.MinInt64), + } + for _, data := range repo.checkPointMap { + if data.km == nil || data.km.CoordinateSystem == "" { + continue + } + if coordinate.Coordinate == "" { + coordinate.Coordinate = data.km.CoordinateSystem + } + km := repo.ConvertKilometer(data.km, coordinate.Coordinate) + if km.Value < coordinate.MinCoordinate { + coordinate.MinCoordinate = km.Value + } + if km.Value > coordinate.MaxCoordinate { + coordinate.MaxCoordinate = km.Value + } + } + if coordinate.Coordinate == "" { + panic("无计轴公里标信息") + } + repo.coordinate = coordinate + return repo.coordinate +} + +func (repo Repository) GetCoordinateInfo() *MapCoordinate { + return repo.coordinate +} + func buildKilometerConvertKey(cs1 string, cs2 string) string { return cs1 + cs2 } diff --git a/repository/repository_manager.go b/repository/repository_manager.go index 33c29d8..fe0cbaa 100644 --- a/repository/repository_manager.go +++ b/repository/repository_manager.go @@ -114,8 +114,8 @@ func buildModels(source *proto.Repository, repository *Repository) { for _, protoData := range source.Mkxs { m := NewMkx(protoData.Id) repository.mkxMap[m.Id()] = m - } + repository.generateCoordinateInfo() } func buildModelRelationship(source *proto.Repository, repository *Repository) error {