56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package memory
|
||
|
||
import (
|
||
"fmt"
|
||
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/component"
|
||
"joylink.club/rtsssimulation/entity"
|
||
"log/slog"
|
||
)
|
||
|
||
var ( //保存状态丢失的继电器的最后一次状态
|
||
xqStateMap = make(map[string]*bool)
|
||
lxStateMap = make(map[string]*bool)
|
||
)
|
||
|
||
// 采集继电器吸起电路状态
|
||
func CollectXQCircuitState(w ecs.World, id string) bool {
|
||
wd := entity.GetWorldData(w)
|
||
entry, ok := wd.EntityMap[id]
|
||
if ok {
|
||
state := component.BitStateType.Get(entry).Val
|
||
if entry.HasComponent(appcomponent.RelayStateLossTag) {
|
||
if xqStateMap[id] == nil {
|
||
xqStateMap[id] = &state
|
||
} else {
|
||
state = *xqStateMap[id]
|
||
}
|
||
}
|
||
return state
|
||
} else {
|
||
slog.Error(fmt.Sprintf("采集继电器状态时,未找到id=%s的继电器\n", id))
|
||
}
|
||
return false
|
||
}
|
||
|
||
// 采集继电器落下电路状态
|
||
func CollectLXCircuitState(w ecs.World, id string) bool {
|
||
wd := entity.GetWorldData(w)
|
||
entry, ok := wd.EntityMap[id]
|
||
if ok {
|
||
state := !component.BitStateType.Get(entry).Val
|
||
if entry.HasComponent(appcomponent.RelayStateLossTag) {
|
||
if lxStateMap[id] == nil {
|
||
lxStateMap[id] = &state
|
||
} else {
|
||
state = *lxStateMap[id]
|
||
}
|
||
}
|
||
return state
|
||
} else {
|
||
slog.Error(fmt.Sprintf("采集继电器状态时,未找到id=%s的继电器\n", id))
|
||
}
|
||
return false
|
||
}
|