组件名称修改

This commit is contained in:
xzb 2023-08-18 10:06:17 +08:00
parent b4830de31c
commit e672fdb99d
11 changed files with 121 additions and 105 deletions

View File

@ -6,43 +6,47 @@ import (
)
// 系统时钟组件
var ComSystemTimer = ecs.NewComponentType[state.SystemTimer]()
var SystemTimerComponent = ecs.NewComponentType[state.SystemTimer]()
// 身份组件
var ComDeviceIdentity = ecs.NewComponentType[state.DeviceIdentity]()
var DeviceIdentityComponent = ecs.NewComponentType[state.DeviceIdentity]()
// 持有实体标签的组件
var ComEntityTagHandler = ecs.NewComponentType[state.EntityTagHandler]()
var EntityTagHandlerComponent = ecs.NewComponentType[state.EntityTagHandler]()
// 百分比设备组件
var PercentageDeviceComponent = ecs.NewComponentType[state.PercentageDeviceState]()
var PercentageDeviceOperatingComponent = ecs.NewComponentType[state.PercentageDeviceOperating]()
// 道岔状态组件
var ComSwitchState = ecs.NewComponentType[state.SwitchState]()
var SwitchStateComponent = ecs.NewComponentType[state.SwitchState]()
// 道岔定反操继电器动作组件
var ComSwitchNRRelayOperating = ecs.NewComponentType[state.SwitchNRRelayOperating]()
var SwitchNRRelayOperatingComponent = ecs.NewComponentType[state.SwitchNRRelayOperating]()
// 道岔正常转动组件
var ComSwitchTurnOperating = ecs.NewComponentType[state.SwitchTurnOperating]()
var SwitchTurnOperatingComponent = ecs.NewComponentType[state.SwitchTurnOperating]()
// 物理区段状态组件
var ComPhysicalSectionState = ecs.NewComponentType[state.PhysicalSectionState]()
var PhysicalSectionStateComponent = ecs.NewComponentType[state.PhysicalSectionState]()
// 信号机状态组件
var ComSignalState = ecs.NewComponentType[state.SignalState]()
var SignalStateComponent = ecs.NewComponentType[state.SignalState]()
// 信号机显示操作组件
var ComSignalDisplayOperating = ecs.NewComponentType[state.SignalDisplayOperating]()
var SignalDisplayOperatingComponent = ecs.NewComponentType[state.SignalDisplayOperating]()
// 单个屏蔽门状态组件
var ComPsdCellState = ecs.NewComponentType[state.PsdCellState]()
var PsdCellStateComponent = ecs.NewComponentType[state.PsdCellState]()
// 单个屏蔽门操作组件
var ComPsdCellOperating = ecs.NewComponentType[state.PsdCellOperating]()
var PsdCellOperatingComponent = ecs.NewComponentType[state.PsdCellOperating]()
// 站台单侧所有单个屏蔽门状态组件
var ComPsdState = ecs.NewComponentType[state.PsdState]()
var PsdStateComponent = ecs.NewComponentType[state.PsdState]()
// 应答器状态组件
var ComBaliseState = ecs.NewComponentType[state.BaliseState]()
var BaliseStateComponent = ecs.NewComponentType[state.BaliseState]()
// 列车状态组件
var ComTrainState = ecs.NewComponentType[state.TrainState]()
var TrainStateComponent = ecs.NewComponentType[state.TrainState]()

View File

@ -83,22 +83,22 @@ func testSignalOpt(world ecs.World, face *system.FaceSystem) {
func initDevicesStatus(world ecs.World) {
//当组件未显式set值时world会初始化组件的零值
switch1Entry := memory.CreateSwitchEntity(world)
components.ComDeviceIdentity.Set(switch1Entry, &state.DeviceIdentity{Id: "switch1"})
components.ComSwitchState.Set(switch1Entry, &state.SwitchState{NormalRelay: false, ReverseRelay: false, NormalTable: true, ReverseTable: false})
components.DeviceIdentityComponent.Set(switch1Entry, &state.DeviceIdentity{Id: "switch1"})
components.SwitchStateComponent.Set(switch1Entry, &state.SwitchState{NormalRelay: false, ReverseRelay: false, NormalTable: true, ReverseTable: false})
//
signal1Entry := memory.CreateSignalEntity(world)
components.ComDeviceIdentity.Set(signal1Entry, &state.DeviceIdentity{Id: "siganl1"})
components.ComSignalState.Set(signal1Entry, &state.SignalState{Display: state.SignalAspect_No})
components.DeviceIdentityComponent.Set(signal1Entry, &state.DeviceIdentity{Id: "siganl1"})
components.SignalStateComponent.Set(signal1Entry, &state.SignalState{Display: state.SignalAspect_No})
//psd1两个cell
psd1Entry := memory.CreatePsdEntity(world)
components.ComDeviceIdentity.Set(psd1Entry, &state.DeviceIdentity{Id: "psd1"})
components.ComPsdState.Set(psd1Entry, &state.PsdState{AllClosed: true, AllOpened: false, InterlockReleased: false})
components.DeviceIdentityComponent.Set(psd1Entry, &state.DeviceIdentity{Id: "psd1"})
components.PsdStateComponent.Set(psd1Entry, &state.PsdState{AllClosed: true, AllOpened: false, InterlockReleased: false})
psd1Cell1Entry := memory.CreatePsdCellEntity(world, psd1Entry)
components.ComDeviceIdentity.Set(psd1Cell1Entry, &state.DeviceIdentity{Id: "psd1Cell1"})
components.ComPsdCellState.Set(psd1Cell1Entry, &state.PsdCellState{CloseRate: 100})
components.DeviceIdentityComponent.Set(psd1Cell1Entry, &state.DeviceIdentity{Id: "psd1Cell1"})
components.PsdCellStateComponent.Set(psd1Cell1Entry, &state.PsdCellState{CloseRate: 100})
psd1Cell2Entry := memory.CreatePsdCellEntity(world, psd1Entry)
components.ComDeviceIdentity.Set(psd1Cell2Entry, &state.DeviceIdentity{Id: "psd1Cell2"})
components.ComPsdCellState.Set(psd1Cell2Entry, &state.PsdCellState{CloseRate: 100})
components.DeviceIdentityComponent.Set(psd1Cell2Entry, &state.DeviceIdentity{Id: "psd1Cell2"})
components.PsdCellStateComponent.Set(psd1Cell2Entry, &state.PsdCellState{CloseRate: 100})
}
func initSystems(world ecs.World) {

View File

@ -12,8 +12,8 @@ import (
// 初始化world添加一些内置的组件和系统
func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
//初始化world时钟
timeEntry := w.Create(components.ComSystemTimer)
components.ComSystemTimer.Set(timeEntry, state.NewSystemTimer(&worldTime))
timeEntry := w.Create(components.SystemTimerComponent)
components.SystemTimerComponent.Set(timeEntry, state.NewSystemTimer(&worldTime))
w.AddSystem(system.NewTimerSystem())
//初始化world与外界交互的门面
faceSystem := system.NewFaceSystem(w)
@ -26,37 +26,37 @@ func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
// 创建道岔实体
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComSwitchState)
return w.Create(components.DeviceIdentityComponent, components.SwitchStateComponent)
}
// 创建信号机实体
func CreateSignalEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComSignalState)
return w.Create(components.DeviceIdentityComponent, components.SignalStateComponent)
}
// 创建物理区段实体
func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComPhysicalSectionState)
return w.Create(components.DeviceIdentityComponent, components.PhysicalSectionStateComponent)
}
// 创建站台单侧屏蔽门实体
func CreatePsdEntity(w ecs.World) *ecs.Entry {
e := w.Create(components.ComDeviceIdentity, components.ComPsdState, components.ComEntityTagHandler)
components.ComEntityTagHandler.Set(e, &state.EntityTagHandler{Tag: ecs.NewComponentType[struct{}]()})
e := w.Create(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent)
components.EntityTagHandlerComponent.Set(e, &state.EntityTagHandler{Tag: ecs.NewComponentType[struct{}]()})
return e
}
// 创建单个屏蔽门实体
func CreatePsdCellEntity(w ecs.World, psdEntry *ecs.Entry) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComPsdCellState, components.ComEntityTagHandler.Get(psdEntry).Tag)
return w.Create(components.DeviceIdentityComponent, components.PsdCellStateComponent, components.EntityTagHandlerComponent.Get(psdEntry).Tag)
}
// 创建应答器实体
func CreateBaliseEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComBaliseState)
return w.Create(components.DeviceIdentityComponent, components.BaliseStateComponent)
}
// 创建列车实体
func CreateTrainEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComTrainState)
return w.Create(components.DeviceIdentityComponent, components.TrainStateComponent)
}

View File

@ -8,10 +8,10 @@ import (
)
// 应答器查询
var baliseQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComBaliseState))
var baliseQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.BaliseStateComponent))
// 列车查询
var trainQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComTrainState))
var trainQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TrainStateComponent))
// 应答器模拟系统
// 检测当有列车经过时,把报文发送给该列车
@ -33,7 +33,7 @@ func (me *BaliseSystem) Update(w ecs.World) {
func SendMessageToTransponder(world ecs.World, transponderId string, message *state.BaliseContent) bool {
var transponderEntry *ecs.Entry = nil
baliseQuery.Each(world, func(e *ecs.Entry) {
if transponderId == components.ComDeviceIdentity.Get(e).Id {
if transponderId == components.DeviceIdentityComponent.Get(e).Id {
transponderEntry = e
}
})
@ -42,7 +42,7 @@ func SendMessageToTransponder(world ecs.World, transponderId string, message *st
return false
}
//
components.ComBaliseState.Get(transponderEntry).Content = message
components.BaliseStateComponent.Get(transponderEntry).Content = message
//
return true
}

View File

@ -11,7 +11,7 @@ type ButtonSystem struct {
}
// 按钮组件
var btnIdCom, btnStaCom, btnPreOperCom, btnConOperCom = components.ComDeviceIdentity,
var btnIdCom, btnStaCom, btnPreOperCom, btnConOperCom = components.DeviceIdentityComponent,
components.ButtonStateComponent, components.ButtonPressOperatingComponent, components.ButtonConfirmOperatingComponent
// 查询

View File

@ -23,21 +23,21 @@ func (me *DebugSystem) Update(w ecs.World) {
// 屏蔽门状态
func debugPsd(w ecs.World) {
psdQuery = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComPsdState, components.ComEntityTagHandler))
psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
psdQuery.Each(w, func(e *ecs.Entry) {
psdId := components.ComDeviceIdentity.Get(e).Id
psdState := components.ComPsdState.Get(e)
psdTag := components.ComEntityTagHandler.Get(e).Tag
psdId := components.DeviceIdentityComponent.Get(e).Id
psdState := components.PsdStateComponent.Get(e)
psdTag := components.EntityTagHandlerComponent.Get(e).Tag
fmt.Printf("屏蔽门[%s] ,全关=%t ,全开=%t ,互锁解除=%t > ", psdId, psdState.AllClosed, psdState.AllOpened, psdState.InterlockReleased)
//
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag, components.ComPsdCellState))
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag, components.PsdCellStateComponent))
psdCellQuery.Each(w, func(e *ecs.Entry) {
psdCellId := components.ComDeviceIdentity.Get(e).Id
psdCellState := components.ComPsdCellState.Get(e)
psdCellId := components.DeviceIdentityComponent.Get(e).Id
psdCellState := components.PsdCellStateComponent.Get(e)
//
fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, psdCellState.CloseRate)
if e.HasComponent(components.ComPsdCellOperating) {
psdCellOpt := components.ComPsdCellOperating.Get(e)
if e.HasComponent(components.PsdCellOperatingComponent) {
psdCellOpt := components.PsdCellOperatingComponent.Get(e)
if psdCellOpt.CloseOperate {
fmt.Printf("== 关门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance)
} else {
@ -52,31 +52,31 @@ func debugPsd(w ecs.World) {
// 显示信号机状态
func debugSignal(w ecs.World) {
siganlQuery := ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSignalState))
siganlQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
siganlQuery.Each(w, func(e *ecs.Entry) {
id := components.ComDeviceIdentity.Get(e).Id
state := components.ComSignalState.Get(e)
id := components.DeviceIdentityComponent.Get(e).Id
state := components.SignalStateComponent.Get(e)
fmt.Printf("==>>信号机[%s],显示=%d\n", id, state.Display)
})
}
// 显示道岔状态
func debugSwitch(w ecs.World) {
switchesQuery := ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSwitchState))
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent))
switchesQuery.Each(w, func(e *ecs.Entry) {
id := components.ComDeviceIdentity.Get(e).Id
state := components.ComSwitchState.Get(e)
id := components.DeviceIdentityComponent.Get(e).Id
state := components.SwitchStateComponent.Get(e)
fmt.Printf("==>>道岔[%s] ,定操Relay=%t ,反操Relay=%t ,定表Relay=%t ,反表Relay=%t ,", id, state.NormalRelay, state.ReverseRelay, state.NormalTable, state.ReverseTable)
if e.HasComponent(components.ComSwitchNRRelayOperating) {
nrOperation := components.ComSwitchNRRelayOperating.Get(e)
if e.HasComponent(components.SwitchNRRelayOperatingComponent) {
nrOperation := components.SwitchNRRelayOperatingComponent.Get(e)
if nrOperation.Normal {
fmt.Printf("定操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close)
} else {
fmt.Printf("反操动作Start=%t ,剩余时间=%d ,吸合动作=%t ,", nrOperation.Start, nrOperation.OperateTime, nrOperation.Close)
}
}
if e.HasComponent(components.ComSwitchTurnOperating) {
turnOperation := components.ComSwitchTurnOperating.Get(e)
if e.HasComponent(components.SwitchTurnOperatingComponent) {
turnOperation := components.SwitchTurnOperatingComponent.Get(e)
fmt.Printf("转动操作Start=%t ,转动到定位=%t ,剩余时间=%d", turnOperation.Start, turnOperation.TurnNormal, turnOperation.OperateTime)
}
fmt.Println()

View File

@ -0,0 +1,12 @@
package system
import "joylink.club/ecs"
//百分比设备系统
type PercentageSystem struct {
}
// world 执行
func (me *PercentageSystem) Update(world ecs.World) {
}

View File

@ -7,7 +7,7 @@ import (
"joylink.club/rtsssimulation/state"
)
var psdQuery = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComPsdState, components.ComEntityTagHandler))
var psdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
type PsdSystem struct {
psdTagMap map[state.EntityTag][]*ecs.Query
@ -28,7 +28,7 @@ func (me *PsdSystem) Update(world ecs.World) {
// 车站单侧屏蔽门
func (me *PsdSystem) updatePsd(world ecs.World) {
psdQuery.Each(world, func(e *ecs.Entry) {
psdTag := components.ComEntityTagHandler.Get(e).Tag
psdTag := components.EntityTagHandlerComponent.Get(e).Tag
_, ok := me.psdTagMap[psdTag]
if !ok {
me.psdTagMap[psdTag] = make([]*ecs.Query, 2)
@ -36,13 +36,13 @@ func (me *PsdSystem) updatePsd(world ecs.World) {
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
me.psdTagMap[psdTag][0] = psdCellQuery
//psd的所有cell中的操作查询
psdCellOperateQuery := ecs.NewQuery(filter.Contains(psdTag, components.ComPsdCellOperating))
psdCellOperateQuery := ecs.NewQuery(filter.Contains(psdTag, components.PsdCellOperatingComponent))
me.psdTagMap[psdTag][1] = psdCellOperateQuery
}
var allClosed bool = true
var allOpened bool = true
me.psdTagMap[psdTag][0].Each(world, func(e *ecs.Entry) {
cellState := components.ComPsdCellState.Get(e)
cellState := components.PsdCellStateComponent.Get(e)
if allClosed {
if cellState.CloseRate < 100 {
allClosed = false
@ -55,7 +55,7 @@ func (me *PsdSystem) updatePsd(world ecs.World) {
}
})
//
psdState := components.ComPsdState.Get(e)
psdState := components.PsdStateComponent.Get(e)
psdState.AllClosed = allClosed
psdState.AllOpened = allOpened
})
@ -75,12 +75,12 @@ func (me *PsdSystem) updatePsdCell(world ecs.World) {
for _, psdTagQueries := range me.psdTagMap {
//遍历某个车站单侧的所有单个门的操作
psdTagQueries[1].Each(world, func(e *ecs.Entry) {
if psdCellOpt := components.ComPsdCellOperating.Get(e); psdCellOpt.Start {
psdCellState := components.ComPsdCellState.Get(e)
if psdCellOpt := components.PsdCellOperatingComponent.Get(e); psdCellOpt.Start {
psdCellState := components.PsdCellStateComponent.Get(e)
if psdCellOpt.RemainingDistance <= 0 {
psdCellOpt.Start = false
psdCellOpt.RemainingDistance = 0
e.RemoveComponent(components.ComPsdCellOperating)
e.RemoveComponent(components.PsdCellOperatingComponent)
} else {
psdCellOpt.RemainingDistance -= int64(pSD_CELL_MOVE_SPEED * world.Tick())
}
@ -99,7 +99,7 @@ func (me *PsdSystem) updatePsdCell(world ecs.World) {
func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) bool {
var psdEntry *ecs.Entry = nil
psdQuery.Each(world, func(e *ecs.Entry) {
if psdId == components.ComDeviceIdentity.Get(e).Id {
if psdId == components.DeviceIdentityComponent.Get(e).Id {
psdEntry = e
}
})
@ -107,7 +107,7 @@ func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) bo
if psdEntry == nil {
return false
}
components.ComPsdState.Get(psdEntry).InterlockReleased = lockRelease
components.PsdStateComponent.Get(psdEntry).InterlockReleased = lockRelease
//
return true
}
@ -117,7 +117,7 @@ func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) bo
func FirePsdMove(world ecs.World, psdId string, closeOpt bool) bool {
var psdEntry *ecs.Entry = nil
psdQuery.Each(world, func(e *ecs.Entry) {
if psdId == components.ComDeviceIdentity.Get(e).Id {
if psdId == components.DeviceIdentityComponent.Get(e).Id {
psdEntry = e
}
})
@ -133,10 +133,10 @@ func FirePsdMove(world ecs.World, psdId string, closeOpt bool) bool {
closeRate = 0
}
//
psdTag := components.ComEntityTagHandler.Get(psdEntry).Tag
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellQuery.Each(world, func(e *ecs.Entry) {
psdCellId := components.ComDeviceIdentity.Get(e).Id
psdCellId := components.DeviceIdentityComponent.Get(e).Id
firePsdCellMove0(world, psdEntry, psdCellId, closeRate)
})
//
@ -150,7 +150,7 @@ func FirePsdMove(world ecs.World, psdId string, closeOpt bool) bool {
func FirePsdCellMove(world ecs.World, psdId string, psdCellId string, closeRate int) bool {
var psdEntry *ecs.Entry = nil
psdQuery.Each(world, func(e *ecs.Entry) {
if psdId == components.ComDeviceIdentity.Get(e).Id {
if psdId == components.DeviceIdentityComponent.Get(e).Id {
psdEntry = e
}
})
@ -162,11 +162,11 @@ func firePsdCellMove0(world ecs.World, psdEntry *ecs.Entry, psdCellId string, cl
return false
}
//
psdTag := components.ComEntityTagHandler.Get(psdEntry).Tag
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
var psdCellEntry *ecs.Entry = nil
psdCellQuery.Each(world, func(e *ecs.Entry) {
if psdCellId == components.ComDeviceIdentity.Get(e).Id {
if psdCellId == components.DeviceIdentityComponent.Get(e).Id {
psdCellEntry = e
}
})
@ -174,15 +174,15 @@ func firePsdCellMove0(world ecs.World, psdEntry *ecs.Entry, psdCellId string, cl
return false
}
//
psdCellState := components.ComPsdCellState.Get(psdCellEntry)
psdCellState := components.PsdCellStateComponent.Get(psdCellEntry)
if closeRate == int(psdCellState.CloseRate) {
return true
}
// 判断是关门还是开门操作
close := closeRate > int(psdCellState.CloseRate)
//
if !psdCellEntry.HasComponent(components.ComPsdCellOperating) {
psdCellEntry.AddComponent(components.ComPsdCellOperating)
if !psdCellEntry.HasComponent(components.PsdCellOperatingComponent) {
psdCellEntry.AddComponent(components.PsdCellOperatingComponent)
}
//
var initDistance int64
@ -195,7 +195,7 @@ func firePsdCellMove0(world ecs.World, psdEntry *ecs.Entry, psdCellId string, cl
sumDistance = int64(float32(pSD_CELL_LEN) * (float32(int(psdCellState.CloseRate)-closeRate) / float32(100)))
}
//
*(components.ComPsdCellOperating.Get(psdCellEntry)) = state.PsdCellOperating{
*(components.PsdCellOperatingComponent.Get(psdCellEntry)) = state.PsdCellOperating{
Start: true,
CloseOperate: close,
InitDistance: initDistance,

View File

@ -11,7 +11,7 @@ type SignalSystem struct {
}
// 信号机显示状态查询
var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSignalState))
var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
// world 执行
func (me *SignalSystem) Update(world ecs.World) {
@ -26,7 +26,7 @@ func NewSignalSystem() *SignalSystem {
func SetSignalDisplay(w ecs.World, signalId string, display state.SignalAspect) bool {
var signalEntry *ecs.Entry
signalQuery.Each(w, func(e *ecs.Entry) {
if signalId == components.ComDeviceIdentity.Get(e).Id {
if signalId == components.DeviceIdentityComponent.Get(e).Id {
signalEntry = e
}
})
@ -35,7 +35,7 @@ func SetSignalDisplay(w ecs.World, signalId string, display state.SignalAspect)
return false
}
//
signalState := components.ComSignalState.Get(signalEntry)
signalState := components.SignalStateComponent.Get(signalEntry)
signalState.Display = display
//
return true

View File

@ -8,13 +8,13 @@ import (
)
// 定反操继电器查询
var nrRelayQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComSwitchNRRelayOperating))
var nrRelayQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SwitchNRRelayOperatingComponent))
// 道岔转动查询
var turningQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComSwitchTurnOperating))
var turningQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SwitchTurnOperatingComponent))
// 道岔状态查询
var switchStateQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSwitchState))
var switchStateQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchStateComponent))
// 道岔系统操作
type SwitchSystem struct {
@ -31,7 +31,7 @@ func NewSwitchSystem() *SwitchSystem {
func FireSwitchTurn(w ecs.World, switchId string, turnNormal bool) bool {
var switchEntry *ecs.Entry = nil
switchStateQuery.Each(w, func(e *ecs.Entry) {
if id := components.ComDeviceIdentity.Get(e).Id; id == switchId {
if id := components.DeviceIdentityComponent.Get(e).Id; id == switchId {
switchEntry = e
}
})
@ -40,16 +40,16 @@ func FireSwitchTurn(w ecs.World, switchId string, turnNormal bool) bool {
return false
}
//
switchState := components.ComSwitchState.Get(switchEntry)
switchState := components.SwitchStateComponent.Get(switchEntry)
if turnNormal == switchState.NormalTable && !turnNormal == switchState.ReverseTable {
return true
}
//
nrRelayTime := getSwitchNRDelayTime(switchId)
if !switchEntry.HasComponent(components.ComSwitchNRRelayOperating) {
switchEntry.AddComponent(components.ComSwitchNRRelayOperating)
if !switchEntry.HasComponent(components.SwitchNRRelayOperatingComponent) {
switchEntry.AddComponent(components.SwitchNRRelayOperatingComponent)
}
*(components.ComSwitchNRRelayOperating.Get(switchEntry)) = state.SwitchNRRelayOperating{Start: true, OperateTime: nrRelayTime, Close: true, Normal: turnNormal}
*(components.SwitchNRRelayOperatingComponent.Get(switchEntry)) = state.SwitchNRRelayOperating{Start: true, OperateTime: nrRelayTime, Close: true, Normal: turnNormal}
//
return true
}
@ -63,9 +63,9 @@ func (me *SwitchSystem) Update(w ecs.World) {
// 道岔转动动作
func updateTurnOperating(w ecs.World) {
turningQuery.Each(w, func(e *ecs.Entry) {
if !e.HasComponent(components.ComSwitchNRRelayOperating) {
operation := components.ComSwitchTurnOperating.Get(e)
switchState := components.ComSwitchState.Get(e)
if !e.HasComponent(components.SwitchNRRelayOperatingComponent) {
operation := components.SwitchTurnOperatingComponent.Get(e)
switchState := components.SwitchStateComponent.Get(e)
if operation.Start {
if operation.OperateTime <= 0 {
operation.Start = false
@ -80,10 +80,10 @@ func updateTurnOperating(w ecs.World) {
}
}
if !operation.Start {
e.RemoveComponent(components.ComSwitchTurnOperating)
e.RemoveComponent(components.SwitchTurnOperatingComponent)
}
} else {
e.RemoveComponent(components.ComSwitchTurnOperating)
e.RemoveComponent(components.SwitchTurnOperatingComponent)
}
})
}
@ -91,12 +91,12 @@ func updateTurnOperating(w ecs.World) {
// 定反操继电器操作
func updateNormalReverseRelay(w ecs.World) {
nrRelayQuery.Each(w, func(e *ecs.Entry) {
operation := components.ComSwitchNRRelayOperating.Get(e)
operation := components.SwitchNRRelayOperatingComponent.Get(e)
if operation.Start {
if operation.OperateTime <= 0 {
operation.Start = false
//
switchState := components.ComSwitchState.Get(e)
switchState := components.SwitchStateComponent.Get(e)
if operation.Normal {
switchState.NormalRelay = operation.Close
} else {
@ -104,19 +104,19 @@ func updateNormalReverseRelay(w ecs.World) {
}
//
if operation.Close { //触发道岔转动操作
if !e.HasComponent(components.ComSwitchTurnOperating) {
e.AddComponent(components.ComSwitchTurnOperating)
if !e.HasComponent(components.SwitchTurnOperatingComponent) {
e.AddComponent(components.SwitchTurnOperatingComponent)
}
switchId := components.ComDeviceIdentity.Get(e).Id
switchId := components.DeviceIdentityComponent.Get(e).Id
turnTime := getSwitchTurnTime(switchId)
*(components.ComSwitchTurnOperating.Get(e)) = state.SwitchTurnOperating{Start: true, OperateTime: turnTime, TurnNormal: operation.Normal}
*(components.SwitchTurnOperatingComponent.Get(e)) = state.SwitchTurnOperating{Start: true, OperateTime: turnTime, TurnNormal: operation.Normal}
}
} else {
operation.OperateTime -= int64(w.Tick())
}
}
if !operation.Start {
e.RemoveComponent(components.ComSwitchNRRelayOperating)
e.RemoveComponent(components.SwitchNRRelayOperatingComponent)
}
})
}

View File

@ -8,7 +8,7 @@ import (
"joylink.club/rtsssimulation/components"
)
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComSystemTimer))
var timerQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.SystemTimerComponent))
// 系统时钟操作
type TimerSystem struct {
@ -21,7 +21,7 @@ func NewTimerSystem() *TimerSystem {
// world 执行
func (me *TimerSystem) Update(w ecs.World) {
if e, ok := timerQuery.First(w); ok {
timer := components.ComSystemTimer.Get(e)
timer := components.SystemTimerComponent.Get(e)
timer.Tick(w.Tick())
}
}
@ -29,7 +29,7 @@ func (me *TimerSystem) Update(w ecs.World) {
// 重置world时间
func ResetWorldTimer(w ecs.World, time time.Time) {
if e, ok := timerQuery.First(w); ok {
timer := components.ComSystemTimer.Get(e)
timer := components.SystemTimerComponent.Get(e)
timer.ResetTime(time)
}
}
@ -37,7 +37,7 @@ func ResetWorldTimer(w ecs.World, time time.Time) {
// 获取world当前时间
func GetWorldNow(w ecs.World) *time.Time {
if e, ok := timerQuery.First(w); ok {
timer := components.ComSystemTimer.Get(e)
timer := components.SystemTimerComponent.Get(e)
now := timer.Now()
return &now
}