Cache unit information

This commit is contained in:
SilentSpike 2015-07-24 17:13:03 +01:00
parent 8ef6364b59
commit e413cb3d91
5 changed files with 48 additions and 9 deletions

View File

@ -2,6 +2,7 @@
ADDON = false;
PREP(cacheUnitInfo);
PREP(cycleCamera);
PREP(handleCamera);
PREP(handleCompass);

View File

@ -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 <OBJECT>
*
* Return Value:
* None <NIL>
*
* 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);

View File

@ -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);

View File

@ -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);

View File

@ -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;