From 6b33879525f76e6f23f781c2446083129469eebf Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 23 Nov 2023 13:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=AD=94=E5=99=A8=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/balise.go | 16 ++++++++++++++ entity/balise.go | 37 +++++++++++++++++++++++++++++--- entity/init.go | 6 ++++++ repository/repository_manager.go | 2 +- repository/transponder.go | 13 ++++++++--- 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 component/balise.go diff --git a/component/balise.go b/component/balise.go new file mode 100644 index 0000000..044c5d7 --- /dev/null +++ b/component/balise.go @@ -0,0 +1,16 @@ +package component + +import "joylink.club/ecs" + +type BaliseState struct { + ValidTelegram []byte //当前一条有效报文 +} + +var ( + BaliseFB = ecs.NewTag() // 固定应答器 + BaliseWB = ecs.NewTag() // 轮径校正应答器 + BaliseDB = ecs.NewTag() // 休眠唤醒应答器 + BaliseVB = ecs.NewTag() // 主信号应答器 + BaliseIB = ecs.NewTag() // 预告应答器 + BaliseStateType = ecs.NewComponentType[BaliseState]() +) diff --git a/entity/balise.go b/entity/balise.go index 65cd603..96d8627 100644 --- a/entity/balise.go +++ b/entity/balise.go @@ -1,10 +1,41 @@ package entity -import "joylink.club/ecs" +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/repository" + "joylink.club/rtsssimulation/repository/model/proto" +) // LoadBalises 加载应答器实体 func LoadBalises(w ecs.World) error { - //data := GetWorldData(w) - //signals := data.Repo.ResponderList() + data := GetWorldData(w) + balises := data.Repo.ResponderList() + for _, b := range balises { + be := newBaliseEntity(w, b, data) + switch b.TransponderType() { + case proto.Transponder_FB: + be.AddComponent(component.BaliseFB) + case proto.Transponder_WB: + be.AddComponent(component.BaliseWB) + case proto.Transponder_DB: + be.AddComponent(component.BaliseDB) + case proto.Transponder_VB: + be.AddComponent(component.BaliseVB) + case proto.Transponder_IB: + be.AddComponent(component.BaliseIB) + } + } return nil } +func newBaliseEntity(w ecs.World, td *repository.Transponder, worldData *component.WorldData) *ecs.Entry { + uid := td.Id() + entry, ok := worldData.EntityMap[uid] + if !ok { + entry = w.Entry(w.Create(component.UidType, component.BaliseStateType)) + component.UidType.SetValue(entry, component.Uid{Id: uid}) + component.BaliseStateType.Set(entry, &component.BaliseState{}) + worldData.EntityMap[uid] = entry + } + return entry +} diff --git a/entity/init.go b/entity/init.go index 6be3570..a6fba5c 100644 --- a/entity/init.go +++ b/entity/init.go @@ -39,5 +39,11 @@ func Load(w ecs.World, repo *repository.Repository) error { if err != nil { return err } + // 加载应答器 + err = LoadBalises(w) + if err != nil { + return err + } + // return err } diff --git a/repository/repository_manager.go b/repository/repository_manager.go index edec024..4e28a08 100644 --- a/repository/repository_manager.go +++ b/repository/repository_manager.go @@ -78,7 +78,7 @@ func buildModels(source *proto.Repository, repository *Repository) error { repository.signalMap[m.Id()] = m } for _, protoData := range source.Transponders { - m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram) + m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.Type) repository.responderMap[m.Id()] = m } for _, protoData := range source.Slopes { diff --git a/repository/transponder.go b/repository/transponder.go index 762b231..c0d9952 100644 --- a/repository/transponder.go +++ b/repository/transponder.go @@ -9,17 +9,24 @@ type Transponder struct { //section *PhysicalSection //turnoutPort TurnoutPort linkPosition *LinkPosition - fixedTelegram []byte //无源应答器固定报文 + fixedTelegram []byte //无源应答器固定报文 + baliseType proto.Transponder_Type //应答器类型 } -func NewTransponder(id string, km *proto.Kilometer, fixedTelegram []byte) *Transponder { +func NewTransponder(id string, km *proto.Kilometer, fixedTelegram []byte, baliseType proto.Transponder_Type) *Transponder { return &Transponder{ Identity: identity{id, proto.DeviceType_DeviceType_Transponder}, km: km, fixedTelegram: fixedTelegram, + baliseType: baliseType, } } - +func (t *Transponder) TransponderType() proto.Transponder_Type { + return t.baliseType +} +func (t *Transponder) FixedTelegram() []byte { + return t.fixedTelegram +} func (t *Transponder) bindLinkPosition(position *LinkPosition) { t.linkPosition = position }