ACE3/addons/spectator/functions/fnc_updateUnits.sqf
SilentSpike bcb21b782e 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
2015-08-06 16:03:32 +01:00

76 lines
2.2 KiB
Plaintext

/*
* Author: SilentSpike
* Adds units to spectator whitelist/blacklist and refreshes the filter units
*
* Arguments:
* 0: Units to add to the whitelist <ARRAY>
* 1: Use blacklist <BOOL> <OPTIONAL>
*
* Return Value:
* None <NIL>
*
* Example:
* [allUnits,true] call ace_spectator_fnc_updateUnits
*
* Public: Yes
*/
#include "script_component.hpp"
params [["_newUnits",[],[[]]],["_blacklist",false,[false]]];
// Function only matters on player clients
if !(hasInterface) exitWith {};
// If adding to a list we can exit here, since it won't show up until the UI refreshes anyway
if !(_newUnits isEqualTo []) exitWith {
if (_blacklist) then {
GVAR(unitWhitelist) = GVAR(unitWhitelist) - _newUnits;
GVAR(unitBlacklist) append _newUnits;
} else {
GVAR(unitBlacklist) = GVAR(unitBlacklist) - _newUnits;
GVAR(unitWhitelist) append _newUnits;
};
};
private ["_sides","_cond","_filteredUnits","_filteredGroups"];
// Unit setting filter
_newUnits = [[],allPlayers,playableUnits,allUnits] select GVAR(filterUnits);
// Side setting filter
_sides = [];
_cond = [{_this == (side group player)},{(_this getFriend (side group player)) >= 0.6},{(_this getFriend (side group player)) < 0.6},{true}] select GVAR(filterSides);
{
if (_x call _cond) then {
_sides pushBack _x;
};
} forEach GVAR(availableSides);
// Filter units and append to list
_filteredUnits = [];
{
if (
(alive _x) &&
{(_x isKindOf "CAManBase")} &&
{(side group _x) in _sides} && // Side filter
{simulationEnabled _x} &&
{!(_x getVariable [QGVAR(isStaged), false])} // Who watches the watchmen?
) then {
_filteredUnits pushBack _x;
};
} forEach (_newUnits - GVAR(unitBlacklist));
_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 lists entirely (removes any no longer valid)
GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits;
GVAR(groupList) = _filteredGroups arrayIntersect _filteredGroups;