From bcb21b782e1ed9d52ca5c7ac61b30d09e90ef795 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Thu, 6 Aug 2015 13:42:31 +0100 Subject: [PATCH] Overhaul spectator icon handling and rendering - Optimize and improve 3D icon drawing - Combine 2D and 3D PFHs into 1 - Render group icons outside of 200m, unit icons within - Store list of groups on units update to cut down on what needs to be done each frame - Change map control type to 100 to remove all default unit icons - Improve colour caching, group colours don't change, unit colours do - Remove icon setting, toggling should be at users discretion --- addons/spectator/ACE_Settings.hpp | 4 -- addons/spectator/UI/interface.hpp | 3 +- addons/spectator/XEH_preInit.sqf | 2 + .../spectator/functions/fnc_cacheUnitInfo.sqf | 11 +++- .../spectator/functions/fnc_handleIcons.sqf | 57 ++++++++----------- .../functions/fnc_handleInterface.sqf | 32 ++--------- addons/spectator/functions/fnc_handleMap.sqf | 46 +++++++++++++++ .../functions/fnc_transitionCamera.sqf | 6 -- .../spectator/functions/fnc_updateUnits.sqf | 7 ++- addons/spectator/stringtable.xml | 8 --- 10 files changed, 90 insertions(+), 86 deletions(-) create mode 100644 addons/spectator/functions/fnc_handleMap.sqf diff --git a/addons/spectator/ACE_Settings.hpp b/addons/spectator/ACE_Settings.hpp index 2889fd2e0f..78402cff23 100644 --- a/addons/spectator/ACE_Settings.hpp +++ b/addons/spectator/ACE_Settings.hpp @@ -19,8 +19,4 @@ class ACE_Settings { value = 0; values[] = {CSTRING(modes_all), CSTRING(visions_nv), CSTRING(visions_ti), "$STR_Special_None"}; }; - class GVAR(unitIcons) { - typeName = "BOOL"; - value = 1; - }; }; diff --git a/addons/spectator/UI/interface.hpp b/addons/spectator/UI/interface.hpp index 182263e7b4..0b4d33ea75 100644 --- a/addons/spectator/UI/interface.hpp +++ b/addons/spectator/UI/interface.hpp @@ -176,12 +176,13 @@ class GVAR(interface) { }; class mapOverlay: RscMapControl { idc = IDC_MAP; + type = 100; x = safeZoneX; y = safeZoneY; w = safeZoneW; h = safeZoneH; onMouseButtonDown = QUOTE([ARR_2('onMapClick',_this)] call FUNC(handleInterface)); - onDraw = QUOTE([ARR_2('onDraw',_this)] call FUNC(handleInterface)); + onDraw = QUOTE(_this call FUNC(handleMap)); }; class helpSplash: RscControlsGroupNoScrollbars { idc = IDC_HELP; diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index 95c18f4a54..2c29598ebc 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -8,6 +8,7 @@ PREP(handleCamera); PREP(handleCompass); PREP(handleIcons); PREP(handleInterface); +PREP(handleMap); PREP(handleMouse); PREP(handleToolbar); PREP(handleUnits); @@ -51,5 +52,6 @@ GVAR(showUnit) = true; GVAR(unitList) = []; GVAR(unitBlacklist) = []; GVAR(unitWhitelist) = []; +GVAR(groupList) = []; ADDON = true; diff --git a/addons/spectator/functions/fnc_cacheUnitInfo.sqf b/addons/spectator/functions/fnc_cacheUnitInfo.sqf index 13977bf398..9f40651748 100644 --- a/addons/spectator/functions/fnc_cacheUnitInfo.sqf +++ b/addons/spectator/functions/fnc_cacheUnitInfo.sqf @@ -19,15 +19,20 @@ params ["_unit"]; private ["_color","_icon","_name"]; -_color = [side group _unit] call BIS_fnc_sideColor; +// Group info only needs to be cached once (groups can't change) +if (isNil { GETVAR((group _unit),GVAR(gColor),nil) }) then { + _color = [side group _unit] call BIS_fnc_sideColor; + SETVAR((group _unit),GVAR(gColor),_color); +}; + +// Unit info should be updated each time _icon = getText (configFile >> "CfgVehicles" >> typeOf _unit >> "Icon"); _name = [_unit,false] call EFUNC(common,getName); // Handle CfgVehicleIcons -if isText (configFile >> "CfgVehicleIcons" >> _icon) then { +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_handleIcons.sqf b/addons/spectator/functions/fnc_handleIcons.sqf index c52943ad10..72c0d7dee6 100644 --- a/addons/spectator/functions/fnc_handleIcons.sqf +++ b/addons/spectator/functions/fnc_handleIcons.sqf @@ -1,5 +1,5 @@ /* - * Author: SilentSpike + * Author: Head, SilentSpike * Handles rendering the spectator 3D unit icons * * Arguments: @@ -17,41 +17,30 @@ #include "script_component.hpp" -// Kill PFH when not in free cam (or display is closed) -if (isNil QGVAR(iconHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; - if !(GVAR(showIcons)) exitWith {}; +private ["_refPoint","_drawVehicles","_leader","_color","_txt","_unit"]; -private ["_cachedVehicles","_unit","_cameraPos","_cameraDir","_lambda","_uPos","_cmd","_txt"]; -_cachedVehicles = []; +// Draw groups unless leader is within distance +_refPoint = [GVAR(camera),GVAR(camUnit)] select (GVAR(camMode) > 0); +_drawVehicles = []; { - _unit = vehicle _x; + _leader = leader _x; + if ((_leader distanceSqr _refPoint) > 40000) then { + _color = GETVAR(_x,GVAR(gColor),[ARR_4(0,0,0,0)]); + _txt = groupID _x; - // Only try each vehicle once - if !(_unit in _cachedVehicles) then { - _cachedVehicles pushBack _unit; - - // Within 200m - if ((GVAR(camera) distanceSqr _unit) < 40000) then { - _cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL); - _cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos; - - // Quick oclussion test (taken from interact_menu) - _lambda = ((getPosASL _x) vectorDiff _cameraPos) vectorDotProduct _cameraDir; - if (_lambda > -1) then { - _uPos = worldToScreen (visiblePosition _unit); - - // Only draw if onscreen - if ((_uPos select 0 > safeZoneXAbs) && (_uPos select 0 < safeZoneXAbs + safeZoneWAbs)) then { - if ((_uPos select 1 > safeZoneY) && (_uPos select 1 < safeZoneY + safeZoneH)) then { - // Use commander's info if available - _cmd = [_x, effectiveCommander _unit] select ((effectiveCommander _unit) in GVAR(unitList)); - _txt = ["", GETVAR(_cmd,GVAR(uName),"")] select (isPlayer _cmd); - - drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", GETVAR(_cmd,GVAR(uColor),[ARR_4(0,0,0,0)]), _unit modelToWorldVisual [0,0,3], 0.7, 0.7, 0, _txt, 1, 0.02]; - }; - }; - }; - }; + drawIcon3D ["\A3\ui_f\data\map\markers\nato\b_inf.paa", _color, _leader modelToWorldVisual [0,0,30], 1, 1, 0, _txt, 2, 0.02]; + } else { + _drawVehicles append (units _x); }; -} forEach GVAR(unitList); + false +} count GVAR(groupList); + +// Draw units for groups within distance +{ + _color = GETVAR((group _x),GVAR(gColor),[ARR_4(0,0,0,0)]); + _txt = ["", GETVAR(_x,GVAR(uName),"")] select (isPlayer _x); + + drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", _color, _x modelToWorldVisual [0,0,3], 0.7, 0.7, 0, _txt, 1, 0.02]; + false +} count (_drawVehicles arrayIntersect GVAR(unitList)); diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 502ce65fd4..d58566968c 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -114,6 +114,9 @@ switch (toLower _mode) do { // Keep unit list and tree up to date [FUNC(handleUnits), 21, _display] call CBA_fnc_addPerFrameHandler; + // Handle unit icons on map and 3D + GVAR(iconHandler) = addMissionEventHandler ["Draw3D",FUNC(handleIcons)]; + // Populate the help splash private "_help"; _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST; @@ -187,6 +190,7 @@ switch (toLower _mode) do { // Kill GUI PFHs GVAR(camHandler) = nil; GVAR(compHandler) = nil; + removeMissionEventHandler ["Draw3D",GVAR(iconHandler)]; GVAR(iconHandler) = nil; GVAR(toolHandler) = nil; }; @@ -435,34 +439,6 @@ switch (toLower _mode) do { [nil,nil,nil, _newPos] call FUNC(setCameraAttributes); }; }; - case "ondraw": { - _args params ["_map"]; - - if (GVAR(camMode) == 0) then { - _map drawIcon ["\A3\UI_F\Data\GUI\Rsc\RscDisplayMissionEditor\iconcamera_ca.paa",[0,0,0,1],GVAR(camera),24,24,GVAR(camPan)]; - }; - - if !(GVAR(showIcons)) exitWith {}; - - private ["_cachedVehicles","_unit","_color","_icon"]; - _cachedVehicles = []; - { - _unit = vehicle _x; - - if !(_unit in _cachedVehicles) then { - _cachedVehicles pushBack _unit; - - // Use previously cached info where possible - if (isNil { GETVAR(_unit,GVAR(uIcon),nil) }) then { - [_unit] call FUNC(cacheUnitInfo); - }; - - _color = GETVAR(_unit,GVAR(uColor),[ARR_4(0,0,0,0)]); - _icon = GETVAR(_unit,GVAR(uIcon),""); - _map drawIcon [_icon, _color, _unit, 24, 24, getDir _unit]; - }; - } forEach GVAR(unitList); - }; // Break from interface for eexternal events case "escape": { _args params ["_display"]; diff --git a/addons/spectator/functions/fnc_handleMap.sqf b/addons/spectator/functions/fnc_handleMap.sqf new file mode 100644 index 0000000000..a0000718bd --- /dev/null +++ b/addons/spectator/functions/fnc_handleMap.sqf @@ -0,0 +1,46 @@ +/* + * Author: Head, SilentSpike + * Handles rendering the spectator map icons + * + * Arguments: + * 0: Parameters + * 1: PFH handle + * + * Return Value: + * None + * + * Example: + * [ace_spectator_fnc_handleIcons, 0] call CBA_fnc_addPerFrameHandler; + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_map"]; +private ["_cachedVehicles","_unit","_color","_icon"]; + +if (GVAR(camMode) == 0) then { + _map drawIcon ["\A3\UI_F\Data\GUI\Rsc\RscDisplayMissionEditor\iconcamera_ca.paa",[0,0,0,1],GVAR(camera),20,20,GVAR(camPan)]; +}; + +_cachedVehicles = []; +{ + _unit = vehicle _x; + + if !(_unit in _cachedVehicles) then { + _cachedVehicles pushBack _unit; + + // Use previously cached info where possible + if (GETVAR(_unit,GVAR(uIcon),"") == "") then { + [_unit] call FUNC(cacheUnitInfo); + }; + + // Function has caching built in + _color = [side effectiveCommander _unit] call BIS_fnc_sideColor; + _icon = GETVAR(_unit,GVAR(uIcon),""); + + _map drawIcon [_icon, _color, _unit, 19, 19, getDir _unit]; + }; + false +} count GVAR(unitList); diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index 90a2dc776b..b35b61b311 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -79,11 +79,6 @@ if (_newMode == 0) then { // Free // Handle camera movement if (isNil QGVAR(camHandler)) then { GVAR(camHandler) = [FUNC(handleCamera), 0] call CBA_fnc_addPerFrameHandler; }; - - // Handle unit icons - if (GVAR(unitIcons)) then { - if (isNil QGVAR(iconHandler)) then { GVAR(iconHandler) = [FUNC(handleIcons), 0] call CBA_fnc_addPerFrameHandler; }; - }; } else { // When null unit is given choose random if (isNull _newUnit) then { @@ -111,7 +106,6 @@ if (_newMode == 0) then { // Free // Terminate camera view GVAR(camera) cameraEffect ["terminate", "back"]; GVAR(camHandler) = nil; - GVAR(iconHandler) = nil; cameraEffectEnableHUD true; }; diff --git a/addons/spectator/functions/fnc_updateUnits.sqf b/addons/spectator/functions/fnc_updateUnits.sqf index 75f1402179..50494cf499 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","_color","_icon"]; +private ["_sides","_cond","_filteredUnits","_filteredGroups"]; // Unit setting filter _newUnits = [[],allPlayers,playableUnits,allUnits] select GVAR(filterUnits); @@ -63,10 +63,13 @@ _filteredUnits = []; _filteredUnits append GVAR(unitWhitelist); // Cache icons and colour for drawing +_filteredGroups = []; { // Intentionally re-applied to units in case their status changes [_x] call FUNC(cacheUnitInfo); + _filteredGroups pushBack (group _x); } forEach _filteredUnits; -// Replace previous list entirely (removes any no longer valid) +// Replace previous lists entirely (removes any no longer valid) GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits; +GVAR(groupList) = _filteredGroups arrayIntersect _filteredGroups; diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index 5219ba7e2d..4d615d4e1e 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -100,14 +100,6 @@ Thermal imaging Termowizja - - Unit icons - Ikony jednostek - - - Render icons above spectatable units. - Renderuj ikony nad głowami jednostek, które można obserwować. - Spectator Controls