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

67 lines
2.2 KiB
Go
Raw Normal View History

2023-10-08 17:19:50 +08:00
package circuit_sys
import (
"joylink.club/ecs"
2023-10-09 13:23:34 +08:00
"joylink.club/ecs/filter"
2023-10-08 17:19:50 +08:00
"joylink.club/rtsssimulation/component"
)
type Signal3XH3System struct {
query *ecs.Query
}
func NewSignal3XH3System() *Signal3XH3System {
2023-10-11 17:44:44 +08:00
return &Signal3XH3System{query: ecs.NewQuery(filter.Contains(component.Signal3XH3ElectronicType))}
2023-10-08 17:19:50 +08:00
}
// Update world 执行
func (s *Signal3XH3System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.Signal3XH3ElectronicType.Get(e)
//
2023-10-11 17:44:44 +08:00
s.calculateU(state)
s.calculateH(state)
s.calculateDJ(state)
s.calculate2DJ(state)
2023-10-08 17:19:50 +08:00
})
}
2023-10-11 17:44:44 +08:00
func (s *Signal3XH3System) calculateU(state *component.Signal3XH3Electronic) {
2023-10-08 17:19:50 +08:00
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)
2023-10-11 17:44:44 +08:00
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val || !ddj.Val && lxj.Val
driveU := component.LightDriveType.Get(state.Z3XH3_U)
driveU.Td = isU
2023-10-08 17:19:50 +08:00
}
2023-10-11 17:44:44 +08:00
func (s *Signal3XH3System) calculateH(state *component.Signal3XH3Electronic) {
2023-10-08 17:19:50 +08:00
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
2023-10-11 17:44:44 +08:00
isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(state.Z3XH3_H)
driveH.Td = isH
2023-10-08 17:19:50 +08:00
}
2023-10-11 17:44:44 +08:00
func (s *Signal3XH3System) calculateDJ(state *component.Signal3XH3Electronic) {
2023-10-08 17:19:50 +08:00
ddj := component.BitStateType.Get(state.Z3XH3_DDJ)
lxj := component.BitStateType.Get(state.Z3XH3_LXJ)
2023-10-11 17:44:44 +08:00
ud := component.BitStateType.Get(state.Z3XH3_U)
hd := component.BitStateType.Get(state.Z3XH3_H)
isDJ := ud.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_DJ)
drive.Td = isDJ
drive.Xq = isDJ
2023-10-08 17:19:50 +08:00
}
2023-10-11 17:44:44 +08:00
func (s *Signal3XH3System) calculate2DJ(state *component.Signal3XH3Electronic) {
2023-10-08 17:19:50 +08:00
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)
2023-10-11 17:44:44 +08:00
ud := component.BitStateType.Get(state.Z3XH3_U)
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
drive := component.RelayDriveType.Get(state.Z3XH3_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
2023-10-08 17:19:50 +08:00
}