计轴rssp 集成

This commit is contained in:
xzb 2023-11-09 15:50:34 +08:00
parent 7b44437fb1
commit 8cb019147f
2 changed files with 58 additions and 0 deletions

View File

@ -36,5 +36,6 @@ func BindSystem(w ecs.World) {
device_sys.NewAlarmSys(),
//物理区段
device_sys.NewFaDcAxleDeviceSystem(),
device_sys.NewTrainSectionSystem(),
)
}

57
sys/device_sys/train.go Normal file
View File

@ -0,0 +1,57 @@
package device_sys
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// TrainSectionSystem 列车所在区段更新系统
type TrainSectionSystem struct {
trainQuery *ecs.Query
axleSectionQuery *ecs.Query
}
func NewTrainSectionSystem() *TrainSectionSystem {
return &TrainSectionSystem{trainQuery: ecs.NewQuery(filter.Contains(component.UidType, component.TrainPositionInfoType)),
axleSectionQuery: ecs.NewQuery(filter.Contains(component.UidType, component.AxlePhysicalSectionType))}
}
func (s *TrainSectionSystem) Update(w ecs.World) {
//key-sectionId,统计区段上有车的情况
sectionTrainMap := make(map[string]*trainCount)
//所有列车
s.trainQuery.Each(w, func(entry *donburi.Entry) {
tp := component.TrainPositionInfoType.Get(entry)
for _, sectionId := range tp.SectionIds { //车所在区段
tc, find := sectionTrainMap[sectionId]
if !find {
tc = newTrainCount()
sectionTrainMap[sectionId] = tc
}
tc.add()
}
})
//计轴区段
s.axleSectionQuery.Each(w, func(entry *donburi.Entry) {
axleSectionId := component.UidType.Get(entry).Id
axleSection := component.AxlePhysicalSectionType.Get(entry)
tc, find := sectionTrainMap[axleSectionId]
if find {
axleSection.UpdateCount(int(tc.count))
} else {
axleSection.UpdateCount(0)
}
})
}
type trainCount struct {
count int8
}
func newTrainCount() *trainCount {
return &trainCount{count: 0}
}
func (c *trainCount) add() {
c.count++
}