rts-sim-module/sys/circuit_sys/signal_3xh4.go

67 lines
2.3 KiB
Go
Raw Normal View History

2023-10-08 18:03:07 +08:00
package circuit_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type Signal3XH4System struct {
query *ecs.Query
}
func NewSignal3XH4System() *Signal3XH4System {
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(component.Signal3XH4ElectronicType, component.Signal3XH4FilamentType))}
}
// Update world 执行
func (s *Signal3XH4System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH4ElectronicType.Get(e)
filament := component.Signal3XH4FilamentType.Get(e)
//
s.calculateU(state, filament)
s.calculateL(state, filament)
s.calculateH(w, state, filament)
s.calculateDJ(w, e, state, filament)
})
}
func (s *Signal3XH4System) calculateU(state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isU := filament.Uf && !ddj.Val && lxj.Val && !zxj.Val
filament.U = isU
}
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isL := filament.Lf && !ddj.Val && lxj.Val && zxj.Val
filament.L = isL
}
func (s *Signal3XH4System) calculateH(w ecs.World, state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
isH := filament.Hf && !ddj.Val && !lxj.Val
filament.H = isH
}
func (s *Signal3XH4System) calculateDJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH4Electronic, filament *component.Signal3XH4Filament) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
dj := component.BitStateType.Get(state.Z3XH4_DJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isDJ := filament.Uf && !ddj.Val && lxj.Val && !zxj.Val ||
filament.Lf && !ddj.Val && lxj.Val && zxj.Val ||
filament.Hf && !ddj.Val && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.Z3XH4_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}