Minimising PFH overhead

This commit is contained in:
SilentSpike 2015-07-19 13:40:08 +01:00
parent 3b1afe930e
commit d8cd1eeb1a
3 changed files with 59 additions and 48 deletions

View File

@ -10,7 +10,7 @@
* None <NIL> * None <NIL>
* *
* Example: * Example:
* [ace_spectator_fnc_handleCompass, 0] call CBA_fnc_addPerFrameHandler; * [ace_spectator_fnc_handleCompass, 0, _display] call CBA_fnc_addPerFrameHandler;
* *
* Public: No * Public: No
*/ */
@ -22,6 +22,9 @@ params ["_display"];
// Kill PFH when display is closed // Kill PFH when display is closed
if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; 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"]; private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"];
_compass = _display displayCtrl IDC_COMP; _compass = _display displayCtrl IDC_COMP;

View File

@ -117,7 +117,7 @@ switch (toLower _mode) do {
(_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode)); (_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode));
// Keep unit tree up to date // 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 // Handle the compass heading
[FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler;
@ -289,4 +289,52 @@ switch (toLower _mode) do {
[_newMode,_newUnit] call FUNC(updateCamera); [_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];
};
}; };

View File

@ -11,7 +11,7 @@
* None <NIL> * None <NIL>
* *
* Example: * Example:
* [ace_spectator_fnc_handleUnits, 10] call CBA_fnc_addPerFrameHandler; * [ace_spectator_fnc_handleUnits, 10, _display] call CBA_fnc_addPerFrameHandler;
* *
* Public: No * Public: No
*/ */
@ -31,48 +31,8 @@ if !(GVAR(camUnit) in GVAR(unitList)) then {
[0,objNull] call FUNC(updateCamera); [0,objNull] call FUNC(updateCamera);
}; };
private ["_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"]; // Reduce overhead when unit tree is hidden
if (GVAR(showUnit) && GVAR(showInterface)) then {
// Fetch tree // Reduce overhead by spreading across frames
_ctrl = _display displayCtrl IDC_UNIT; [FUNC(handleInterface),["onUnitsUpdate",[_display]],1] call EFUNC(common,waitAndExecute);
// 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];