diff --git a/addons/spectator/functions/fnc_handleCompass.sqf b/addons/spectator/functions/fnc_handleCompass.sqf index c339507f53..00c7f9a0ce 100644 --- a/addons/spectator/functions/fnc_handleCompass.sqf +++ b/addons/spectator/functions/fnc_handleCompass.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [ace_spectator_fnc_handleCompass, 0] call CBA_fnc_addPerFrameHandler; + * [ace_spectator_fnc_handleCompass, 0, _display] call CBA_fnc_addPerFrameHandler; * * Public: No */ @@ -22,6 +22,9 @@ params ["_display"]; // Kill PFH when display is closed if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; +// Reduce overhead when compass is hidden +if !(GVAR(showComp) && GVAR(showInterface)) exitWith {}; + private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"]; _compass = _display displayCtrl IDC_COMP; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 735c96dbf3..76141f411f 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -117,7 +117,7 @@ switch (toLower _mode) do { (_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode)); // Keep unit tree up to date - [FUNC(handleUnits), 20, _display] call CBA_fnc_addPerFrameHandler; + [FUNC(handleUnits), 21, _display] call CBA_fnc_addPerFrameHandler; // Handle the compass heading [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; @@ -289,4 +289,52 @@ switch (toLower _mode) do { [_newMode,_newUnit] call FUNC(updateCamera); }; }; + case "onunitsupdate": { + _args params ["_display"]; + private ["_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; + + // Fetch tree + _ctrl = _display displayCtrl IDC_UNIT; + + // Cache current selection + _curSelData = _ctrl tvData (tvCurSel _ctrl); + + // Clear the tree + tvClear _ctrl; + + // Update the tree from the unit list + _cachedGrps = []; + { + _grp = group _x; + _node = 0; + // If group already exists, find existing node + if !(_grp in _cachedGrps) then { + _side = [west,east,resistance,civilian,sideLogic] find (side _grp); + _node = _ctrl tvCount []; + + _ctrl tvAdd [[], groupID _grp]; + _ctrl tvSetValue [[_node], _side]; + + _cachedGrps pushBack _grp; + } else { + _node = _cachedGrps find _grp; + }; + + _index = _ctrl tvCount [_node]; + + _ctrl tvAdd [[_node], name _x]; + _ctrl tvSetData [[_node,_index], netID _x]; + + // Preserve the previous selection + if (_curSelData == (_ctrl tvData [_node,_index])) then { + _ctrl tvSetCurSel [_node,_index]; + }; + + _ctrl tvSort [[_node],false]; + _ctrl tvExpand [_node]; + } forEach GVAR(unitList); + + // Sort group nodes by side + _ctrl tvSortByValue [[],false]; + }; }; diff --git a/addons/spectator/functions/fnc_handleUnits.sqf b/addons/spectator/functions/fnc_handleUnits.sqf index da28bc4147..79a3807ba4 100644 --- a/addons/spectator/functions/fnc_handleUnits.sqf +++ b/addons/spectator/functions/fnc_handleUnits.sqf @@ -11,7 +11,7 @@ * None * * Example: - * [ace_spectator_fnc_handleUnits, 10] call CBA_fnc_addPerFrameHandler; + * [ace_spectator_fnc_handleUnits, 10, _display] call CBA_fnc_addPerFrameHandler; * * Public: No */ @@ -31,48 +31,8 @@ if !(GVAR(camUnit) in GVAR(unitList)) then { [0,objNull] call FUNC(updateCamera); }; -private ["_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; - -// Fetch tree -_ctrl = _display displayCtrl IDC_UNIT; - -// Cache current selection -_curSelData = _ctrl tvData (tvCurSel _ctrl); - -// Clear the tree -tvClear _ctrl; - -// Update the tree from the unit list -_cachedGrps = []; -{ - _grp = group _x; - _node = 0; - // If group already exists, find existing node - if !(_grp in _cachedGrps) then { - _side = [west,east,resistance,civilian,sideLogic] find (side _grp); - _node = _ctrl tvCount []; - - _ctrl tvAdd [[], groupID _grp]; - _ctrl tvSetValue [[_node], _side]; - - _cachedGrps pushBack _grp; - } else { - _node = _cachedGrps find _grp; - }; - - _index = _ctrl tvCount [_node]; - - _ctrl tvAdd [[_node], name _x]; - _ctrl tvSetData [[_node,_index], netID _x]; - - // Preserve the previous selection - if (_curSelData == (_ctrl tvData [_node,_index])) then { - _ctrl tvSetCurSel [_node,_index]; - }; - - _ctrl tvSort [[_node],false]; - _ctrl tvExpand [_node]; -} forEach GVAR(unitList); - -// Sort group nodes by side -_ctrl tvSortByValue [[],false]; +// Reduce overhead when unit tree is hidden +if (GVAR(showUnit) && GVAR(showInterface)) then { + // Reduce overhead by spreading across frames + [FUNC(handleInterface),["onUnitsUpdate",[_display]],1] call EFUNC(common,waitAndExecute); +};