51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package iscs_sys
|
||
|
||
import (
|
||
"joylink.club/ecs"
|
||
"joylink.club/ecs/filter"
|
||
"joylink.club/rtsssimulation/component"
|
||
)
|
||
|
||
// SmokeDetectorSystem 烟感
|
||
type SmokeDetectorSystem struct {
|
||
query *ecs.Query
|
||
}
|
||
|
||
const (
|
||
SmokeDensityFireAlarm uint16 = 15
|
||
SmokeDensityEarlyWarn uint16 = 10
|
||
)
|
||
|
||
func NewSmokeDetectorSystem() *SmokeDetectorSystem {
|
||
return &SmokeDetectorSystem{
|
||
query: ecs.NewQuery(filter.Contains(component.UidType, component.SmokeDetectorType)),
|
||
}
|
||
}
|
||
func (s *SmokeDetectorSystem) Update(w ecs.World) {
|
||
s.query.Each(w, func(entry *ecs.Entry) {
|
||
detector := component.SmokeDetectorType.Get(entry)
|
||
detectorId := component.UidType.Get(entry).Id
|
||
//烟感探测所在环境
|
||
detector.Density = s.detectSmoke(w, detectorId)
|
||
if detector.State != component.StaIsolate {
|
||
state := component.StaNormal
|
||
//产生烟雾预警信号
|
||
if detector.Density >= SmokeDensityEarlyWarn {
|
||
state = component.StaEarlyWarn
|
||
}
|
||
//产生烟雾报警即火警信号
|
||
if detector.Density >= SmokeDensityFireAlarm {
|
||
state = component.StaFireAlarm
|
||
}
|
||
//
|
||
detector.State = state
|
||
}
|
||
})
|
||
}
|
||
|
||
// 烟感探测环境烟雾浓度,1=0.01%
|
||
func (s *SmokeDetectorSystem) detectSmoke(w ecs.World, detectorId string) uint16 {
|
||
//todo
|
||
return 0
|
||
}
|