应答器实体
This commit is contained in:
parent
5d5b25c7ef
commit
6b33879525
16
component/balise.go
Normal file
16
component/balise.go
Normal 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]()
|
||||
)
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user