74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/consts"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"log/slog"
|
|
)
|
|
|
|
type CkmSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewCkmSys() *CkmSys {
|
|
return &CkmSys{
|
|
query: ecs.NewQuery(filter.Contains(entity.CkmBaseComponentTypes...)),
|
|
}
|
|
}
|
|
|
|
func (p *CkmSys) Update(world ecs.World) {
|
|
worldData := entity.GetWorldData(world)
|
|
p.query.Each(world, func(entry *ecs.Entry) {
|
|
//车库门故障(状态丢失)
|
|
if entry.HasComponent(component.CkmStateLossTag) {
|
|
return
|
|
}
|
|
posCom := component.FixedPositionTransformType.Get(entry)
|
|
circuit := component.CkmCircuitType.Get(entry) //目前不考虑没有车库门电路的情况
|
|
//车库门PSL
|
|
if entry.HasComponent(component.CkmPslType) {
|
|
ckmPsl := component.CkmPslType.Get(entry)
|
|
component.RelayDriveType.Get(circuit.MPLJ).Td = component.BitStateType.Get(ckmPsl.MPLA).Val //门旁路
|
|
component.RelayDriveType.Get(circuit.MMSJ).Td = component.BitStateType.Get(ckmPsl.MMSA).Val //门模式
|
|
}
|
|
//门开/关继电器及状态
|
|
if posCom.Pos == consts.TwoPosMin {
|
|
component.RelayDriveType.Get(circuit.MGJ).Td = true
|
|
component.RelayDriveType.Get(circuit.MKJ).Td = false
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.MGJ).Td = false
|
|
component.RelayDriveType.Get(circuit.MKJ).Td = true
|
|
}
|
|
//门故障继电器及状态
|
|
component.RelayDriveType.Get(circuit.MGZJ).Td = entry.HasComponent(component.CkmStateLossTag)
|
|
//开/关门继电器驱动状态
|
|
if component.BitStateType.Get(circuit.MMSJ).Val {
|
|
ckmPsl := component.CkmPslType.Get(entry)
|
|
component.RelayDriveType.Get(circuit.KMJ).Td = component.BitStateType.Get(ckmPsl.KMA).Val
|
|
component.RelayDriveType.Get(circuit.GMJ).Td = component.BitStateType.Get(ckmPsl.GMA).Val
|
|
} else {
|
|
kmBit, err := worldData.QueryQdBit(component.UidType.Get(circuit.KMJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.KMJ).Td = kmBit
|
|
} else {
|
|
slog.Error(err.Error())
|
|
}
|
|
gmBit, err := worldData.QueryQdBit(component.UidType.Get(circuit.GMJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.GMJ).Td = gmBit
|
|
} else {
|
|
slog.Error(err.Error())
|
|
}
|
|
}
|
|
//驱动
|
|
if component.BitStateType.Get(circuit.GMJ).Val {
|
|
posCom.Speed = -component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
|
|
} else if component.BitStateType.Get(circuit.KMJ).Val {
|
|
posCom.Speed = component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
|
|
}
|
|
})
|
|
}
|