From 972bac0561d75dec406b03a87283d81411cd668a Mon Sep 17 00:00:00 2001 From: walker Date: Wed, 10 Jan 2024 11:12:19 +0800 Subject: [PATCH] =?UTF-8?q?merge=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/common.go | 2 +- component/component_data/common.pb.go | 89 ++++++++++++++++++++++++--- entity/balise.go | 6 +- repository/repository.go | 20 +++--- repository/repository_manager.go | 4 +- 5 files changed, 98 insertions(+), 23 deletions(-) diff --git a/component/common.go b/component/common.go index b627284..fd38a41 100644 --- a/component/common.go +++ b/component/common.go @@ -63,4 +63,4 @@ type Counter struct { var CounterType = ecs.NewComponentType[Counter]() -var LinkPositionType = ecs.NewComponentType[component_proto.LinkPosition]() +var LinkPositionType = ecs.NewComponentType[component_data.LinkPosition]() diff --git a/component/component_data/common.pb.go b/component/component_data/common.pb.go index 049c190..af3e632 100644 --- a/component/component_data/common.pb.go +++ b/component/component_data/common.pb.go @@ -360,6 +360,64 @@ func (x *Counter) GetStep() int32 { return 0 } +// Link位置 +type LinkPosition struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Link的ID + LinkId string `protobuf:"bytes,1,opt,name=linkId,proto3" json:"linkId,omitempty"` + // Link的偏移量 + Offset int64 `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"` +} + +func (x *LinkPosition) Reset() { + *x = LinkPosition{} + if protoimpl.UnsafeEnabled { + mi := &file_component_common_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LinkPosition) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LinkPosition) ProtoMessage() {} + +func (x *LinkPosition) ProtoReflect() protoreflect.Message { + mi := &file_component_common_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LinkPosition.ProtoReflect.Descriptor instead. +func (*LinkPosition) Descriptor() ([]byte, []int) { + return file_component_common_proto_rawDescGZIP(), []int{6} +} + +func (x *LinkPosition) GetLinkId() string { + if x != nil { + return x.LinkId + } + return "" +} + +func (x *LinkPosition) GetOffset() int64 { + if x != nil { + return x.Offset + } + return 0 +} + // 倒数/倒计时组件 type CounterDown struct { state protoimpl.MessageState @@ -373,7 +431,7 @@ type CounterDown struct { func (x *CounterDown) Reset() { *x = CounterDown{} if protoimpl.UnsafeEnabled { - mi := &file_component_common_proto_msgTypes[6] + mi := &file_component_common_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -386,7 +444,7 @@ func (x *CounterDown) String() string { func (*CounterDown) ProtoMessage() {} func (x *CounterDown) ProtoReflect() protoreflect.Message { - mi := &file_component_common_proto_msgTypes[6] + mi := &file_component_common_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -399,7 +457,7 @@ func (x *CounterDown) ProtoReflect() protoreflect.Message { // Deprecated: Use CounterDown.ProtoReflect.Descriptor instead. func (*CounterDown) Descriptor() ([]byte, []int) { - return file_component_common_proto_rawDescGZIP(), []int{6} + return file_component_common_proto_rawDescGZIP(), []int{7} } func (x *CounterDown) GetVal() int32 { @@ -441,7 +499,11 @@ var file_component_common_proto_rawDesc = []byte{ 0x03, 0x76, 0x61, 0x6c, 0x22, 0x2f, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x74, 0x65, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x04, 0x73, 0x74, 0x65, 0x70, 0x22, 0x33, 0x0a, 0x0b, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, + 0x04, 0x73, 0x74, 0x65, 0x70, 0x22, 0x3e, 0x0a, 0x0c, 0x4c, 0x69, 0x6e, 0x6b, 0x50, 0x6f, 0x73, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, + 0x66, 0x66, 0x73, 0x65, 0x74, 0x22, 0x33, 0x0a, 0x0b, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x74, 0x65, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x74, 0x65, 0x70, 0x42, 0x1c, 0x5a, 0x1a, 0x2e, 0x2f, @@ -461,7 +523,7 @@ func file_component_common_proto_rawDescGZIP() []byte { return file_component_common_proto_rawDescData } -var file_component_common_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_component_common_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_component_common_proto_goTypes = []interface{}{ (*MotorState)(nil), // 0: component.MotorState (*RelayState)(nil), // 1: component.RelayState @@ -469,7 +531,8 @@ var file_component_common_proto_goTypes = []interface{}{ (*FixedPositionTransform)(nil), // 3: component.FixedPositionTransform (*BitState)(nil), // 4: component.BitState (*Counter)(nil), // 5: component.Counter - (*CounterDown)(nil), // 6: component.CounterDown + (*LinkPosition)(nil), // 6: component.LinkPosition + (*CounterDown)(nil), // 7: component.CounterDown } var file_component_common_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type @@ -558,6 +621,18 @@ func file_component_common_proto_init() { } } file_component_common_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LinkPosition); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_component_common_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CounterDown); i { case 0: return &v.state @@ -576,7 +651,7 @@ func file_component_common_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_component_common_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/entity/balise.go b/entity/balise.go index 6cc61dc..89344ef 100644 --- a/entity/balise.go +++ b/entity/balise.go @@ -3,7 +3,7 @@ package entity import ( "joylink.club/ecs" "joylink.club/rtsssimulation/component" - "joylink.club/rtsssimulation/component/component_proto" + "joylink.club/rtsssimulation/component/component_data" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" ) @@ -11,12 +11,12 @@ import ( // LoadBalises 加载应答器实体 func LoadBalises(w ecs.World) error { data := GetWorldData(w) - balises := data.Repo.TransponderList() + balises := data.Repo.ResponderList() for _, b := range balises { be := newBaliseEntity(w, b, data) //应答器位置 be.AddComponent(component.LinkPositionType) - component.LinkPositionType.SetValue(be, component_proto.LinkPosition{ + component.LinkPositionType.SetValue(be, component_data.LinkPosition{ LinkId: b.LinkPosition().Link().Id(), Offset: b.LinkPosition().Offset(), }) diff --git a/repository/repository.go b/repository/repository.go index e65cac0..eddf03a 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -15,7 +15,7 @@ type Repository struct { checkPointMap map[string]*CheckPoint turnoutMap map[string]*Turnout signalMap map[string]*Signal - transponderMap map[string]*Transponder + responderMap map[string]*Transponder slopeMap map[string]*Slope sectionalCurvatureMap map[string]*SectionalCurvature kilometerConvertMap map[string]*proto.KilometerConvert @@ -62,7 +62,7 @@ func newRepository(id string, version string) *Repository { checkPointMap: make(map[string]*CheckPoint), turnoutMap: make(map[string]*Turnout), signalMap: make(map[string]*Signal), - transponderMap: make(map[string]*Transponder), + responderMap: make(map[string]*Transponder), slopeMap: make(map[string]*Slope), sectionalCurvatureMap: make(map[string]*SectionalCurvature), kilometerConvertMap: make(map[string]*proto.KilometerConvert), @@ -119,7 +119,7 @@ func (repo *Repository) FindById(id string) Identity { if md, ok := repo.checkPointMap[id]; ok { return md } - if md, ok := repo.transponderMap[id]; ok { + if md, ok := repo.responderMap[id]; ok { return md } if md, ok := repo.stationMap[id]; ok { @@ -225,16 +225,16 @@ func (repo *Repository) SignalList() []*Signal { } return list } -func (repo *Repository) TransponderList() []*Transponder { +func (repo *Repository) ResponderList() []*Transponder { var list []*Transponder - for _, model := range repo.transponderMap { + for _, model := range repo.responderMap { list = append(list, model) } return list } func (repo *Repository) ResponderListByLink(linkId string) []*Transponder { var list []*Transponder - for _, model := range repo.transponderMap { + for _, model := range repo.responderMap { if model.linkPosition.link.Id() == linkId { list = append(list, model) } @@ -336,7 +336,7 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType) case proto.DeviceType_DeviceType_Signal: return repo.signalMap[deviceId], nil case proto.DeviceType_DeviceType_Transponder: - return repo.transponderMap[deviceId], nil + return repo.responderMap[deviceId], nil case proto.DeviceType_DeviceType_Slope: return repo.slopeMap[deviceId], nil case proto.DeviceType_DeviceType_SectionalCurvature: @@ -396,7 +396,7 @@ func (repo *Repository) FindLink(id string) *Link { return repo.linkMap[id] } func (repo *Repository) FindTransponder(id string) *Transponder { - return repo.transponderMap[id] + return repo.responderMap[id] } func (repo *Repository) FindTurnout(id string) *Turnout { return repo.turnoutMap[id] @@ -419,7 +419,7 @@ func (repo *Repository) FindPsd(id string) *Psd { return repo.psdMap[id] } -func (repo *Repository) FindPlatform(id string) *Platform { +func (repo *Repository) FindPlatfrom(id string) *Platform { return repo.platformMap[id] } @@ -499,7 +499,7 @@ func (repo *Repository) generateCoordinateInfo(coordinateSystem string) error { return nil } -func (repo *Repository) GetCoordinateInfo() *MapCoordinate { +func (repo Repository) GetCoordinateInfo() *MapCoordinate { return repo.coordinate } diff --git a/repository/repository_manager.go b/repository/repository_manager.go index dabd686..e006d8e 100644 --- a/repository/repository_manager.go +++ b/repository/repository_manager.go @@ -85,7 +85,7 @@ func buildModels(source *proto.Repository, repository *Repository) error { } for _, protoData := range source.Transponders { m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.Type) - repository.transponderMap[m.Id()] = m + repository.responderMap[m.Id()] = m } for _, protoData := range source.Slopes { m := NewSlope(protoData.Id, protoData.Kms, protoData.Degree) @@ -346,7 +346,7 @@ func buildCheckPointRelationShip(source *proto.Repository, repo *Repository) err func buildResponderRelationShip(source *proto.Repository, repository *Repository) error { for _, protoData := range source.Transponders { - responder := repository.transponderMap[protoData.Id] + responder := repository.responderMap[protoData.Id] //应答器和区段相互关联 if protoData.SectionId != "" { interrelateResponderAndPhysicalSection(responder, repository.physicalSectionMap[protoData.SectionId])