双机zdj9道岔测试

This commit is contained in:
xzb 2023-09-15 13:07:31 +08:00
parent aa71c91e3a
commit 3a989ac1b2
8 changed files with 47 additions and 17 deletions

View File

@ -15,14 +15,6 @@ func CreateModelStorageEntity(w ecs.World, modelManager umi.IModelManager) *ecs.
return e
}
// 创建继电器实体
func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: relayId})
system.RelayStateComponent.Set(e, system.NewRelayState())
return e
}
// 创建系统时钟实体
func CreateSystemTimerEntity(w ecs.World, systemTime time.Time) *ecs.Entry {
e := w.Create(system.SystemTimerComponent)

14
entities/relay_entity.go Normal file
View File

@ -0,0 +1,14 @@
package entities
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/system"
)
// 创建继电器实体
func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: relayId})
system.RelayStateComponent.Set(e, system.NewRelayState())
return e
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
sysEvent "joylink.club/rtsssimulation/system/event"
"time"
"github.com/yohamta/donburi/filter"
@ -23,7 +24,7 @@ func main() {
//
worldConfig := simulation.WorldConfig{
ModelManager: worldStorage,
Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewSwitch2jZdj9System(), system.NewDebugSystem()},
Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewMovableSystem(), system.NewDebugSystem()},
Tick: 100,
InitTime: time.Now(),
}
@ -31,9 +32,18 @@ func main() {
addEntities(world, modelStorage)
initComponents(world)
//
world.StartUp()
//ecs.EventsDebugEnable()
//
time.Sleep(5 * time.Second)
system.Switch2jzdj9AddListeners(world)
system.RelayAddListeners(world)
//
world.StartUp()
time.Sleep(1 * time.Second)
//反操
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-ycj", Xh: true})
sysEvent.RelayNeedChangeEventBus.PublishOutWorld(world, &sysEvent.RelayNeedChangeEvent{Id: "sw1-sjzdj9-fcj", Xh: true})
//
time.Sleep(10 * time.Second)
world.Close()
}

@ -1 +1 @@
Subproject commit c3b9d965c607a2f29e0bdc586aba6851d4f29f13
Subproject commit 747a81e44a4318a0390422156de44b7c3afddb06

View File

@ -18,6 +18,8 @@ func (debug *DebugSystem) Update(w ecs.World) {
zdj9Query.Each(w, func(entry *ecs.Entry) {
swId := EntityIdentityComponent.Get(entry).Id
swState := Switch2jZdj9StateComponent.Get(entry)
log.Println(fmt.Sprintf("==>>2JZDJ9=%s j1-2DQJ=%t", swId, swState.J1_2DQJ))
//log.Println(fmt.Sprintf("==>>2JZDJ9=%s QDJ=%t j1-2DQJ=%t j2-2DQJ=%t", swId, swState.J1_QDJ, swState.J1_2DQJ, swState.J2_2DQJ))
//log.Println(fmt.Sprintf("==>>2JZDJ9=%s j1-1DQJ=%t j2-1DQJ=%t", swId, swState.J1_1DQJ, swState.J2_1DQJ))
log.Println(fmt.Sprintf("==>>2JZDJ9=%s YCJ=%t DCJ=%t FCJ=%t ZDBJ=%t ZFBJ=%t", swId, swState.YCJ, swState.DCJ, swState.FCJ, swState.ZDBJ, swState.ZFBJ))
})
}

View File

@ -21,18 +21,18 @@ var MovableObjectComponent = ecs.NewComponentType[MovableObject]()
var MovableObject1Component = ecs.NewComponentType[MovableObject]()
var MovableObject2Component = ecs.NewComponentType[MovableObject]()
type TimeMovableSystem struct {
type MovableSystem struct {
query *ecs.Query
}
func NewTimeMovableSystem() *TimeMovableSystem {
return &TimeMovableSystem{
func NewMovableSystem() *MovableSystem {
return &MovableSystem{
query: ecs.NewQuery(filter.Or(filter.Contains(MovableObjectComponent), filter.Contains(MovableObject1Component), filter.Contains(MovableObject2Component))),
}
}
// world 执行
func (me *TimeMovableSystem) Update(w ecs.World) {
func (me *MovableSystem) Update(w ecs.World) {
me.query.Each(w, func(e *ecs.Entry) {
if e.HasComponent(MovableObjectComponent) {

View File

@ -4,6 +4,7 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
sysEvent "joylink.club/rtsssimulation/system/event"
"log"
)
// 继电器有两个线圈1-2,3-4
@ -51,8 +52,13 @@ func NewRelaySystem() *RelaySystem {
}
}
func RelayAddListeners(w ecs.World) {
sysEvent.RelayNeedChangeEventBus.Subscribe(w, RelayNeedChangeEventProcessor)
}
// 继电器须要改变事件处理
var RelayNeedChangeEventProcessor = func(w ecs.World, event sysEvent.RelayNeedChangeEvent) {
log.Println("==>>收到继电器须改变事件id = ", event.Id, " xh = ", event.Xh)
relayEntry := FindEntityById(w, event.Id)
relayState := RelayStateComponent.Get(relayEntry)
relayState.needXh = event.Xh

View File

@ -2,6 +2,7 @@ package system
import (
"fmt"
"log"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
@ -276,8 +277,13 @@ const (
SJZDJ9_ZFBJ = "ZFBJ"
)
func Switch2jzdj9AddListeners(w ecs.World) {
sysEvent.RelayActionEventBus.Subscribe(w, Switch2jzdj9RelayActionEventProcessor)
}
// 接收继电器动作事件
var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
log.Println("==>>收到继电器动作事件id = ", event.Id, " xh = ", event.Xh)
zdj9Query.Each(w, func(e *ecs.Entry) {
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
roler, ok := switchModel.(umi.IRelayCRole)