rts-sim-module/system/spks_system.go

128 lines
3.2 KiB
Go
Raw Normal View History

2023-09-25 15:39:03 +08:00
package system
2023-09-26 14:02:05 +08:00
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
)
2023-09-26 11:29:50 +08:00
2023-09-25 15:39:03 +08:00
//车站人员防护开关电路
type SpksCircuitState struct {
2023-09-26 11:29:50 +08:00
//ture-按钮开关接通常开点
SPKSX1JA bool
//ture-按钮开关接通常开点
SPKSX3JA bool
//ture-按钮开关接通常开点
SPKSS2JA bool
//ture-按钮开关接通常开点
SPKSS4JA bool
2023-09-26 14:00:40 +08:00
//ture-按钮开关接通常开点
SPKSXPLA bool
//ture-按钮开关接通常开点
SPKSSPLA bool
2023-09-26 11:29:50 +08:00
//true-灯亮
SPKSX1D bool
//true-灯亮
SPKSX3D bool
//true-灯亮
SPKSS2D bool
//true-灯亮
SPKSS4D bool
//true-灯亮
SPKSXPLAD bool
//true-灯亮
SPKSSPLAD bool
//ture-按钮开关接通常开点
SDA bool
//ture-继电器吸起,接通常开点
SPKSX1J bool
//ture-继电器吸起,接通常开点
SPKSX3J bool
//ture-继电器吸起,接通常开点
SPKSS2J bool
//ture-继电器吸起,接通常开点
SPKSS4J bool
//ture-继电器吸起,接通常开点
SPKSXPLAJ bool
//ture-继电器吸起,接通常开点
SPKSSPLAJ bool
}
type SpksCircuitSystem struct {
2023-09-26 14:00:40 +08:00
query *ecs.Query
2023-09-26 11:29:50 +08:00
}
var (
SpksCircuitStateComponent = ecs.NewComponentType[SpksCircuitState]()
)
2023-09-26 14:02:05 +08:00
func NewSpksCircuitSystem() *SpksCircuitSystem {
return &SpksCircuitSystem{query: ecs.NewQuery(filter.Contains(SpksCircuitStateComponent))}
}
2023-09-26 14:00:40 +08:00
func NewSpksCircuitState() *SpksCircuitState {
return &SpksCircuitState{
SPKSX1JA: true,
SPKSX3JA: true,
SPKSS2JA: true,
SPKSS4JA: true,
SPKSXPLA: false,
SPKSSPLA: false,
SPKSX1D: false,
SPKSX3D: false,
SPKSS2D: false,
SPKSS4D: false,
SPKSXPLAD: false,
SPKSSPLAD: false,
SDA: false,
SPKSX1J: true,
SPKSX3J: true,
SPKSS2J: true,
SPKSS4J: true,
SPKSXPLAJ: false,
SPKSSPLAJ: false,
}
}
2023-09-26 11:29:50 +08:00
// Update world 执行
func (me *SpksCircuitSystem) Update(w ecs.World) {
2023-09-26 14:00:40 +08:00
me.query.Each(w, func(e *ecs.Entry) {
state := SpksCircuitStateComponent.Get(e)
_state := &(*state)
//
me.calculateSpksD(state)
me.calculateSPKSXJ(state)
me.calculateSPKSSJ(state)
me.calculateSPKSPLAJ(state)
me.calculateChange(state, _state)
})
}
// 亮灯运算
func (me *SpksCircuitSystem) calculateSpksD(state *SpksCircuitState) {
state.SPKSX1D = state.SDA || !state.SPKSX1J
state.SPKSX3D = state.SDA || !state.SPKSX3J
state.SPKSS2D = state.SDA || !state.SPKSS2J
state.SPKSS4D = state.SDA || !state.SPKSS4J
state.SPKSXPLAD = state.SDA || state.SPKSXPLAJ
state.SPKSSPLAD = state.SDA || state.SPKSSPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSXJ(state *SpksCircuitState) {
state.SPKSX1J = state.SPKSX1JA || state.SPKSXPLAJ
state.SPKSX3J = state.SPKSX3JA || state.SPKSXPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSSJ(state *SpksCircuitState) {
state.SPKSS2J = state.SPKSS2JA || state.SPKSSPLAJ
state.SPKSS4J = state.SPKSS4JA || state.SPKSSPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSPLAJ(state *SpksCircuitState) {
state.SPKSXPLAJ = state.SPKSXPLA
state.SPKSSPLAJ = state.SPKSSPLA
}
2023-09-26 11:29:50 +08:00
2023-09-26 14:00:40 +08:00
// 状态改变运算,通过pre与cur比较如果某个状态改变则发送对应事件
func (me *SpksCircuitSystem) calculateChange(curState *SpksCircuitState, preState *SpksCircuitState) {
if curState.SPKSX1J != preState.SPKSX1J {
//继电器状态需要改变
}
2023-09-25 15:39:03 +08:00
}