修改断相保护器系统逻辑bug

修改道岔挤岔故障bug
修改计数器系统逻辑bug
This commit is contained in:
walker 2023-10-16 15:40:03 +08:00
parent 93725ce934
commit 97b2880c7b
4 changed files with 44 additions and 39 deletions

View File

@ -13,31 +13,40 @@ import (
// 设置道岔故障 // 设置道岔故障
func SetTurnoutFault(w ecs.World, id string, fault component_proto.Turnout_Fault) error { func SetTurnoutFault(w ecs.World, id string, fault component_proto.Turnout_Fault) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { return updateTrunoutFault(w, id, fault, true)
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
ct := component.GetTurnoutFaultType(fault)
if !entry.HasComponent(ct) {
entry.AddComponent(ct)
}
} else {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的道岔", id))
}
return ecs.NewOkEmptyResult()
})
return result.Err
} }
// 取消道岔故障 // 取消道岔故障
func CancelTurnoutFault(w ecs.World, id string, fault component_proto.Turnout_Fault) error { func CancelTurnoutFault(w ecs.World, id string, fault component_proto.Turnout_Fault) error {
return updateTrunoutFault(w, id, fault, false)
}
func updateTrunoutFault(w ecs.World, id string, fault component_proto.Turnout_Fault, set bool) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id] entry, ok := wd.EntityMap[id]
if ok { if ok {
ct := component.GetTurnoutFaultType(fault) ct := component.GetTurnoutFaultType(fault)
if entry.HasComponent(ct) { switch fault {
entry.RemoveComponent(ct) case component_proto.Turnout_JC: // 挤岔故障
zzjs := component.TurnoutZzjType.Get(entry)
for _, e := range zzjs.ZzjList {
if set {
if !e.HasComponent(ct) {
e.AddComponent(ct)
}
} else {
e.RemoveComponent(ct)
}
}
default:
if set {
if !entry.HasComponent(ct) {
entry.AddComponent(ct)
}
} else {
entry.RemoveComponent(ct)
}
} }
} else { } else {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的道岔", id)) return ecs.NewErrResult(fmt.Errorf("未找到id=%s的道岔", id))

View File

@ -10,6 +10,7 @@ import (
// 添加系统到World // 添加系统到World
func BindSystem(w ecs.World) { func BindSystem(w ecs.World) {
w.AddSystem(NewWorldTimeSys(), w.AddSystem(NewWorldTimeSys(),
common_sys.NewCounterSys(),
common_sys.NewCounterDownSys(), common_sys.NewCounterDownSys(),
common_sys.NewTwoPositionMovementSys(), common_sys.NewTwoPositionMovementSys(),
device_sys.NewRelaySys(), device_sys.NewRelaySys(),

View File

@ -10,8 +10,8 @@ type CounterSys struct {
query *ecs.Query query *ecs.Query
} }
func NewCounterSys() *CounterDownSys { func NewCounterSys() *CounterSys {
return &CounterDownSys{ return &CounterSys{
query: ecs.NewQuery(filter.Contains(component.CounterType)), query: ecs.NewQuery(filter.Contains(component.CounterType)),
} }
} }

View File

@ -22,29 +22,24 @@ func (q *DBQSys) Update(w ecs.World) {
q.query.Each(w, func(entry *ecs.Entry) { q.query.Each(w, func(entry *ecs.Entry) {
// 电路是否通电 // 电路是否通电
dbq := component.DBQStateType.Get(entry) dbq := component.DBQStateType.Get(entry)
if dbq.Td && !dbq.Dzkg { // 通电但开关未开,启动 // 定时器处理
counter := component.CounterType.Get(entry)
if dbq.Td && counter.Val < consts.DBQTimeout && counter.Step == 0 { // 通电但开关未开,启动
// 定时器启动
counter.Step = w.Tick()
} else if dbq.Td && counter.Val >= consts.DBQTimeout && counter.Step != 0 { // 已经启动,判定延时切断
// 判断定时器是否超时,如果超时,断开电子开关
counter.Step = 0
} else if !dbq.Td && counter.Val > 0 { // 断电,数字计时器
counter.Val = 0
counter.Step = 0
}
// 电子开关状态变化
if !dbq.Dzkg && dbq.Td && counter.Val < consts.DBQTimeout {
dbq.Dzkg = true dbq.Dzkg = true
if entry.HasComponent(component.CounterType) { } else if dbq.Dzkg && !(dbq.Td && counter.Val < consts.DBQTimeout) {
// 定时器启动
counter := component.CounterType.Get(entry)
counter.Val = 0
counter.Step = w.Tick()
}
} else if dbq.Td && dbq.Dzkg { // 已经启动,判定延时切断
if entry.HasComponent(component.CounterType) {
// 判断定时器是否超时,如果超时,断开电子开关
counter := component.CounterType.Get(entry)
if counter.Val >= consts.DBQTimeout {
counter.Step = 0
dbq.Dzkg = false
}
}
} else if !dbq.Td && dbq.Dzkg { // 断电,断开电子开关
dbq.Dzkg = false dbq.Dzkg = false
if entry.HasComponent(component.CounterType) { // 断电,停止计时
counter := component.CounterType.Get(entry)
counter.Step = 0
}
} }
}) })
} }