应答器实体

This commit is contained in:
xzb 2023-11-23 13:17:09 +08:00
parent 5d5b25c7ef
commit 6b33879525
5 changed files with 67 additions and 7 deletions

16
component/balise.go Normal file
View File

@ -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]()
)

View File

@ -1,10 +1,41 @@
package entity 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 加载应答器实体 // LoadBalises 加载应答器实体
func LoadBalises(w ecs.World) error { func LoadBalises(w ecs.World) error {
//data := GetWorldData(w) data := GetWorldData(w)
//signals := data.Repo.ResponderList() 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 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
}

View File

@ -39,5 +39,11 @@ func Load(w ecs.World, repo *repository.Repository) error {
if err != nil { if err != nil {
return err return err
} }
// 加载应答器
err = LoadBalises(w)
if err != nil {
return err
}
//
return err return err
} }

View File

@ -78,7 +78,7 @@ func buildModels(source *proto.Repository, repository *Repository) error {
repository.signalMap[m.Id()] = m repository.signalMap[m.Id()] = m
} }
for _, protoData := range source.Transponders { 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 repository.responderMap[m.Id()] = m
} }
for _, protoData := range source.Slopes { for _, protoData := range source.Slopes {

View File

@ -9,17 +9,24 @@ type Transponder struct {
//section *PhysicalSection //section *PhysicalSection
//turnoutPort TurnoutPort //turnoutPort TurnoutPort
linkPosition *LinkPosition 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{ return &Transponder{
Identity: identity{id, proto.DeviceType_DeviceType_Transponder}, Identity: identity{id, proto.DeviceType_DeviceType_Transponder},
km: km, km: km,
fixedTelegram: fixedTelegram, 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) { func (t *Transponder) bindLinkPosition(position *LinkPosition) {
t.linkPosition = position t.linkPosition = position
} }