From 9364ae60dfd05d53a08d8d46df2c846a8bcd3d4b Mon Sep 17 00:00:00 2001 From: SilentSpike <silentspike100+Github@gmail.com> Date: Wed, 11 May 2016 13:30:17 +0100 Subject: [PATCH 1/2] Fix spectator unit tree refreshing - Account for decrement in node index when culling the tree of sides/groups/units - Fix non-zero-based index `to` value when navigating the units in the tree --- .../functions/fnc_handleInterface.sqf | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index a8a607d537..ea20d0fcdd 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -331,31 +331,40 @@ switch (toLower _mode) do { }; case "onunitsupdate": { _args params ["_tree"]; - private ["_cachedUnits","_cachedGrps","_cachedSides","_s","_g","_grp","_u","_unit","_side"]; + private ["_cachedUnits","_cachedGrps","_cachedSides","_sT","_gT","_uT","_s","_g","_u","_grp","_unit","_side"]; // Cache existing group and side nodes and cull removed data _cachedUnits = []; _cachedGrps = []; _cachedSides = []; - for "_s" from 0 to ((_tree tvCount []) - 1) do { - for "_g" from 0 to ((_tree tvCount [_s]) - 1) do { + // Track deleted nodes to account for decrease in index + _sT = _tree tvCount []; + for [{_s = 0;}, {_s < _sT}, {_s = _s + 1}] do { + _gT = _tree tvCount [_s]; + + for [{_g = 0;}, {_g < _gT}, {_g = _g + 1}] do { _grp = groupFromNetID (_tree tvData [_s,_g]); if (_grp in GVAR(groupList)) then { _cachedGrps pushBack _grp; _cachedGrps pushBack _g; - for "_u" from 0 to ((_tree tvCount [_s,_g])) do { + _uT = _tree tvCount [_s,_g]; + for [{_u = 0;}, {_u < _uT}, {_u = _u + 1}] do { _unit = objectFromNetId (_tree tvData [_s,_g,_u]); if (_unit in GVAR(unitList)) then { _cachedUnits pushBack _unit; } else { _tree tvDelete [_s,_g,_u]; + _u = _u - 1; + _uT = _uT - 1; }; }; } else { _tree tvDelete [_s,_g]; + _g = _g - 1; + _gT = _gT - 1; }; }; @@ -364,6 +373,8 @@ switch (toLower _mode) do { _cachedSides pushBack _s; } else { _tree tvDelete [_s]; + _s = _s - 1; + _sT = _sT - 1; }; }; From 1b1329b3507a8be5e52b7326985def6d624ebd50 Mon Sep 17 00:00:00 2001 From: SilentSpike <silentspike100+Github@gmail.com> Date: Wed, 11 May 2016 16:01:07 +0100 Subject: [PATCH 2/2] Increase spectator unit tree refresh rate Reduce the time between automated refreshing of the unit tree. Also makes an initial call to the tree populating code upon first opening to remove the initial delay. --- addons/spectator/functions/fnc_handleInterface.sqf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index ea20d0fcdd..381f64505c 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -27,8 +27,11 @@ switch (toLower _mode) do { // Always show interface and hide map upon opening [_display,nil,nil,!GVAR(showInterface),GVAR(showMap)] call FUNC(toggleInterface); + // Initalize the unit tree + ["onUnitsUpdate",[(_display displayCtrl IDC_UNIT) controlsGroupCtrl IDC_UNIT_TREE]] call FUNC(handleInterface); + // Keep unit list and tree up to date - [FUNC(handleUnits), 21, _display] call CBA_fnc_addPerFrameHandler; + [FUNC(handleUnits), 9, _display] call CBA_fnc_addPerFrameHandler; // Handle 3D unit icons GVAR(iconHandler) = addMissionEventHandler ["Draw3D",FUNC(handleIcons)];