From 74399be1090cbb915fdf8dce99434c202d4656c8 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 31 Jul 2016 11:52:25 +0100 Subject: [PATCH] Optimize spectator unit list function Making good use of the new `select` CODE syntax. --- .../spectator/functions/fnc_updateUnits.sqf | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/addons/spectator/functions/fnc_updateUnits.sqf b/addons/spectator/functions/fnc_updateUnits.sqf index e5b15b6bc1..418643be38 100644 --- a/addons/spectator/functions/fnc_updateUnits.sqf +++ b/addons/spectator/functions/fnc_updateUnits.sqf @@ -33,43 +33,37 @@ if !(_newUnits isEqualTo []) exitWith { }; }; -private ["_sides","_cond","_filteredUnits","_filteredGroups"]; - // Unit setting filter -_newUnits = [[],allPlayers,playableUnits,allUnits] select GVAR(filterUnits); +private _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); +private _sideFilter = [ + {_x == (side group player)}, + {(_x getFriend (side group player)) >= 0.6}, + {(_x getFriend (side group player)) < 0.6}, + {true} +] select GVAR(filterSides); + +private _filteredSides = GVAR(availableSides) select _sideFilter; // 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)); +private _filteredUnits = (_newUnits - GVAR(unitBlacklist)) select { + (alive _x) && + {(_x isKindOf "CAManBase")} && + {(side group _x) in _filteredSides} && // Side filter + {simulationEnabled _x} && + {!(_x getVariable [QGVAR(isStaged), false])} // Who watches the watchmen? +}; _filteredUnits append GVAR(unitWhitelist); // Cache icons and colour for drawing -_filteredGroups = []; +private _filteredGroups = []; { // Intentionally re-applied to units in case their status changes [_x] call FUNC(cacheUnitInfo); - _filteredGroups pushBack (group _x); + _filteredGroups pushBackUnique (group _x); } forEach _filteredUnits; // Replace previous lists entirely (removes any no longer valid) +GVAR(groupList) = _filteredGroups; GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits; -GVAR(groupList) = _filteredGroups arrayIntersect _filteredGroups;