From e413cb3d91ae61d42c1f24de6ef0e687b1cfd447 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 24 Jul 2015 17:13:03 +0100 Subject: [PATCH] Cache unit information --- addons/spectator/XEH_preInit.sqf | 1 + .../spectator/functions/fnc_cacheUnitInfo.sqf | 33 +++++++++++++++++++ .../functions/fnc_handleInterface.sqf | 13 ++++---- .../spectator/functions/fnc_handleToolbar.sqf | 2 +- .../spectator/functions/fnc_updateUnits.sqf | 8 ++++- 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 addons/spectator/functions/fnc_cacheUnitInfo.sqf diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index 65556a12ff..fd8cd74b0a 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(cacheUnitInfo); PREP(cycleCamera); PREP(handleCamera); PREP(handleCompass); diff --git a/addons/spectator/functions/fnc_cacheUnitInfo.sqf b/addons/spectator/functions/fnc_cacheUnitInfo.sqf new file mode 100644 index 0000000000..13977bf398 --- /dev/null +++ b/addons/spectator/functions/fnc_cacheUnitInfo.sqf @@ -0,0 +1,33 @@ +/* + * Author: SilentSpike + * Caches the units information for quick retrevial in spectator interface PFHs + * + * Arguments: + * 0: Unit to have info cached for + * + * Return Value: + * None + * + * Example: + * [vehicle player] call ace_spectator_fnc_cacheUnitInfo + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_unit"]; +private ["_color","_icon","_name"]; + +_color = [side group _unit] call BIS_fnc_sideColor; +_icon = getText (configFile >> "CfgVehicles" >> typeOf _unit >> "Icon"); +_name = [_unit,false] call EFUNC(common,getName); + +// Handle CfgVehicleIcons +if isText (configFile >> "CfgVehicleIcons" >> _icon) then { + _icon = getText (configFile >> "CfgVehicleIcons" >> _icon); +}; + +SETVAR(_unit,GVAR(uColor),_color); +SETVAR(_unit,GVAR(uIcon),_icon); +SETVAR(_unit,GVAR(uName),_name); diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 8480bd09d2..f844eaf89b 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -346,7 +346,7 @@ switch (toLower _mode) do { _gNode = _cachedGrps select ((_cachedGrps find _grp) + 1); }; - _uNode = _tree tvAdd [[_sNode,_gNode], name _x]; + _uNode = _tree tvAdd [[_sNode,_gNode], GETVAR(_x,GVAR(uName),"")]; _tree tvSetData [[_sNode,_gNode,_uNode], netID _x]; // Preserve the previous selection @@ -394,14 +394,13 @@ switch (toLower _mode) do { if !(_unit in _cachedVehicles) then { _cachedVehicles pushBack _unit; - _color = [side group _unit] call BIS_fnc_sideColor; - _icon = getText (configFile >> "CfgVehicles" >> typeOf _unit >> "Icon"); - - // Handle CfgVehicleIcons - if isText (configFile >> "CfgVehicleIcons" >> _icon) then { - _icon = getText (configFile >> "CfgVehicleIcons" >> _icon); + // Use previously cached info where possible + if (isNil { GETVAR(_unit,GVAR(uIcon),nil) }) then { + [_unit] call FUNC(cacheUnitInfo); }; + _color = GETVAR(_unit,GVAR(uColor),[0,0,0,0]); + _icon = GETVAR(_unit,GVAR(uIcon),""); _map drawIcon [_icon, _color, _unit, 24, 24, getDir _unit]; }; } forEach GVAR(unitList); diff --git a/addons/spectator/functions/fnc_handleToolbar.sqf b/addons/spectator/functions/fnc_handleToolbar.sqf index b3463885d4..3528edbb03 100644 --- a/addons/spectator/functions/fnc_handleToolbar.sqf +++ b/addons/spectator/functions/fnc_handleToolbar.sqf @@ -45,7 +45,7 @@ if (GVAR(camMode) == 0) then { if (isNull GVAR(camUnit)) then { _name = localize "STR_VOICE_MASK_NONE"; } else { - _name = name GVAR(camUnit); + _name = GETVAR(GVAR(camUnit),GVAR(uName),""); }; _mode = [localize LSTRING(ViewFree),localize LSTRING(ViewInternal),localize LSTRING(ViewExternal)] select GVAR(camMode); diff --git a/addons/spectator/functions/fnc_updateUnits.sqf b/addons/spectator/functions/fnc_updateUnits.sqf index 866deacdbc..66c91c37a0 100644 --- a/addons/spectator/functions/fnc_updateUnits.sqf +++ b/addons/spectator/functions/fnc_updateUnits.sqf @@ -33,7 +33,7 @@ if !(_newUnits isEqualTo []) exitWith { }; }; -private ["_sides","_cond","_filteredUnits"]; +private ["_sides","_cond","_filteredUnits","_color","_icon"]; // Unit setting filter _newUnits = [[],allPlayers,allUnits] select GVAR(filterUnits); @@ -62,5 +62,11 @@ _filteredUnits = []; } forEach (_newUnits - GVAR(unitBlacklist)); _filteredUnits append GVAR(unitWhitelist); +// Cache icons and colour for drawing +{ + // Intentionally re-applied to units in case their status changes + [_x] call FUNC(cacheUnitInfo); +} forEach _filteredUnits; + // Replace previous list entirely (removes any no longer valid) GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits;