rts-sim-module/sys/circuit_sys/signal_3xh3.go
2023-10-08 17:19:50 +08:00

69 lines
2.5 KiB
Go

package circuit_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type Signal3XH3System struct {
query *ecs.Query
}
func NewSignal3XH3System() *Signal3XH3System {
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(component.Signal3XH3ElectronicType, component.Signal3XH3FilamentType))}
}
// Update world 执行
func (s *Signal3XH3System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH3ElectronicType.Get(e)
filament := component.Signal3XH3FilamentType.Get(e)
//
s.calculateU(w, state, filament)
s.calculateH(w, state, filament)
s.calculateDJ(w, e, state, filament)
s.calculate2DJ(w, e, state, filament)
})
}
func (s *Signal3XH3System) calculateU(w ecs.World, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
isU := filament.Uf && (!ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val)
filament.U = isU
}
func (s *Signal3XH3System) calculateH(w ecs.World, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
isH := filament.Hf && !ddj.Val && !lxj.Val
filament.H = isH
}
func (s *Signal3XH3System) calculateDJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
isDJ := filament.Uf && !ddj.Val && lxj.Val || filament.Hf && !ddj.Val && !lxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.Z3XH3_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}
func (s *Signal3XH3System) calculate2DJ(w ecs.World, e *ecs.Entry, state *component.Signal3XH3Electronic, filament *component.Signal3XH3Filament) {
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
dj := component.BitStateType.Get(state.Z3XH3_DJ)
edj := component.BitStateType.Get(state.Z3XH3_2DJ)
yxj := component.BitStateType.Get(state.Z3XH3_YXJ)
is2DJ := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
if is2DJ != edj.Val {
drive := component.RelayDriveType.Get(state.Z3XH3_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}
}