From 8cb019147fc9bb17b0ae053d7d98cc074599f9d8 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Thu, 9 Nov 2023 15:50:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E8=BD=B4rssp=20=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys/bind.go | 1 + sys/device_sys/train.go | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 sys/device_sys/train.go diff --git a/sys/bind.go b/sys/bind.go index 9985c31..6574b46 100644 --- a/sys/bind.go +++ b/sys/bind.go @@ -36,5 +36,6 @@ func BindSystem(w ecs.World) { device_sys.NewAlarmSys(), //物理区段 device_sys.NewFaDcAxleDeviceSystem(), + device_sys.NewTrainSectionSystem(), ) } diff --git a/sys/device_sys/train.go b/sys/device_sys/train.go new file mode 100644 index 0000000..f72c488 --- /dev/null +++ b/sys/device_sys/train.go @@ -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++ +}