Доработка. Убран список целей в обработчиках, т.к. не используется. Добавлено событие "изменение размера списка целей".
This commit is contained in:
@@ -36,39 +36,42 @@ class Threat:
|
||||
items.any(func(vn): set(vn, dic_vals[vn]); fflags[vn] = true; return false)
|
||||
|
||||
|
||||
signal threat_new(threats: Dictionary, th: Threat)
|
||||
signal threat_lost(threats: Dictionary, th: Threat)
|
||||
signal threat_update(threats: Dictionary, th: Threat)
|
||||
|
||||
|
||||
var threats = {} ## Список целей. Индекс - <номер цели>
|
||||
signal threat_new(th: Threat)
|
||||
signal threat_lost(th: Threat)
|
||||
signal threat_update(th: Threat)
|
||||
signal threats_resized(th: Dictionary)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Log.info('Модуль обработки целей готов')
|
||||
var threats = {} ## Список целей. Индекс - <номер цели>
|
||||
var unit_key = REPSettings.get_unit_key('уарэп-капсрпб-отп')
|
||||
var unit = REPNetwork.units[unit_key]
|
||||
var timer_check_lost: = Timer.new()
|
||||
add_child(timer_check_lost)
|
||||
unit.connect('data_received', Callable(self, 'on_data_capsrpb_received'))
|
||||
timer_check_lost.connect('timeout', Callable(self, 'on_timer_check_lost').bind(REPSettings.ThreatParams.time_lost))
|
||||
unit.connect('data_received', Callable(self, 'on_data_capsrpb_received').bind(threats))
|
||||
timer_check_lost.connect('timeout', Callable(self, 'on_timer_check_lost').bind(REPSettings.ThreatParams.time_lost, threats))
|
||||
timer_check_lost.start(REPSettings.ThreatParams.time_lost / 1000.0)
|
||||
|
||||
|
||||
## Периодически удаляет устаревшие цели
|
||||
func on_timer_check_lost(time_lost: int):
|
||||
func on_timer_check_lost(time_lost: int, threats: Dictionary):
|
||||
var tick = Time.get_ticks_msec()
|
||||
var sz: = threats.size()
|
||||
for th in threats.values():
|
||||
if (tick - th.tick_rx) >= time_lost:
|
||||
threats.erase(th.id)
|
||||
emit_signal('threat_lost', threats, th)
|
||||
call_deferred('emit_signal', 'threat_lost', th)
|
||||
if sz != threats.size():
|
||||
call_deferred('emit_signal', 'threats_resized', threats)
|
||||
|
||||
|
||||
## Производит приём целей
|
||||
func on_data_capsrpb_received(unit: capsrpb.CapsRpb):
|
||||
func on_data_capsrpb_received(unit: capsrpb.CapsRpb, threats: Dictionary):
|
||||
if not unit.json_dic.has('mis'):
|
||||
return
|
||||
var mis = unit.json_dic['mis']
|
||||
var sz: = threats.size()
|
||||
for dic_th in mis:
|
||||
if dic_th.has('id'):
|
||||
var id = int(dic_th['id'])
|
||||
@@ -77,10 +80,12 @@ func on_data_capsrpb_received(unit: capsrpb.CapsRpb):
|
||||
th.clear_fflags()
|
||||
th.set_from_dic(dic_th)
|
||||
th.tick_rx = unit.tick
|
||||
call_deferred('emit_signal', 'threat_update', threats, th)
|
||||
call_deferred('emit_signal', 'threat_update', th)
|
||||
else:
|
||||
var th = Threat.new()
|
||||
th.set_from_dic(dic_th)
|
||||
threats[id] = th
|
||||
th.tick_rx = unit.tick
|
||||
call_deferred('emit_signal', 'threat_new', threats, th)
|
||||
call_deferred('emit_signal', 'threat_new', th)
|
||||
if sz != threats.size():
|
||||
call_deferred('emit_signal', 'threats_resized', threats)
|
||||
|
||||
Reference in New Issue
Block a user