ecs 测试
This commit is contained in:
parent
b623a7172c
commit
f803324cf4
|
@ -48,7 +48,6 @@ func main() {
|
|||
//
|
||||
simWorld.AddSystem(system.NewSwitchSystem())
|
||||
simWorld.AddSystem(system.NewTrainSystem())
|
||||
//simWorld.AddSystem(system.NewCiSystem())
|
||||
simWorld.AddSystem(system.NewSectionSystem())
|
||||
//
|
||||
simWorld.StartUp()
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/ecs/examples/rtss-cg/simulation"
|
||||
)
|
||||
|
||||
// 把长轨道当成物理区段,列车当成一个点,来计算物理区段的占用空闲状态
|
||||
type CiSystem struct {
|
||||
//轨道查询
|
||||
linkQuery *ecs.Query
|
||||
//列车查询
|
||||
trainQuery *ecs.Query
|
||||
}
|
||||
|
||||
func (me *CiSystem) Update(w ecs.World) {
|
||||
//key linkId,value bool
|
||||
linkOccupyMap := make(map[string]bool)
|
||||
me.trainQuery.Each(w, func(e *ecs.Entry) {
|
||||
train := simulation.ComTrainState.Get(e)
|
||||
|
||||
if len(strings.TrimSpace(train.LinkId)) > 0 {
|
||||
linkOccupyMap[train.LinkId] = true
|
||||
}
|
||||
})
|
||||
//轨道是否被列车占用
|
||||
me.linkQuery.Each(w, func(e *ecs.Entry) {
|
||||
link := simulation.ComLinkState.Get(e)
|
||||
if linkOccupied, ok := linkOccupyMap[link.Id]; ok {
|
||||
link.Occupied = linkOccupied
|
||||
} else {
|
||||
link.Occupied = false
|
||||
}
|
||||
})
|
||||
me.linkQuery.Each(w, func(e *ecs.Entry) {
|
||||
link := simulation.ComLinkState.Get(e)
|
||||
fmt.Println("==>>轨道(", link.Id, ") 上有车(", link.Occupied, ")")
|
||||
})
|
||||
}
|
||||
|
||||
func NewCiSystem() *CiSystem {
|
||||
return &CiSystem{
|
||||
linkQuery: ecs.NewQuery(filter.Contains(simulation.ComLinkState)),
|
||||
trainQuery: ecs.NewQuery(filter.Contains(simulation.ComTrainState)),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue