Headless - Code optimisation (#9873)

* Headless optimisations

* Swapped blacklist for unitIsUAV check

* Moved UAV check

* Update addons/headless/functions/fnc_transferGroups.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update addons/headless/functions/fnc_transferGroups.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update fnc_transferGroups.sqf

---------

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
This commit is contained in:
johnb432 2024-04-04 13:01:12 +02:00 committed by GitHub
parent e6cc5fca89
commit 0d401b2664
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 28 additions and 40 deletions

View File

@ -1,12 +1,12 @@
#include "script_component.hpp"
["ace_settingsInitialized", {
["CBA_settingsInitialized", {
// Register and remove HCs if not client that is not server and distribution or end mission enabled
if ((!hasInterface || isServer) && {XGVAR(enabled) || XGVAR(endMission) != 0}) then {
if (isServer) then {
// Request rebalance on any unit spawn (only if distribution enabled)
if (XGVAR(enabled)) then {
["AllVehicles", "initPost", LINKFUNC(handleSpawn), nil, nil, true] call CBA_fnc_addClassEventHandler;
["CAManBase", "initPost", LINKFUNC(handleSpawn), nil, nil, true] call CBA_fnc_addClassEventHandler;
};
// Add disconnect EH
addMissionEventHandler ["HandleDisconnect", {call FUNC(handleDisconnect)}];

View File

@ -12,7 +12,6 @@ if (isServer) then {
GVAR(headlessClients) = [];
GVAR(inRebalance) = false;
GVAR(endMissionCheckDelayed) = false;
GVAR(blacklistType) = [BLACKLIST_UAV];
[QXGVAR(headlessClientJoined), LINKFUNC(handleConnectHC)] call CBA_fnc_addEventHandler;
};

View File

@ -19,17 +19,14 @@ params ["_headlessClient"];
// Exit if HC already registered
// No need to check if distribution or end mission enabled, as if disabled this will never run
if (_headlessClient in GVAR(headlessClients)) exitWith {};
// Register for use
GVAR(headlessClients) pushBack _headlessClient;
if (GVAR(headlessClients) pushBackUnique _headlessClient == -1) exitWith {};
if (XGVAR(log)) then {
INFO_1("Registered HC: %1",_headlessClient);
};
// Exit if AI distribution is disabled
if (!XGVAR(enabled)) exitWith {true};
if (!XGVAR(enabled)) exitWith {};
// Rebalance
[true] call FUNC(rebalance);

View File

@ -17,7 +17,7 @@
*/
params ["_object"];
TRACE_1("HandleDisconnect",_this);
TRACE_1("HandleDisconnect",_object);
// Exit if not HC
if !(_object in GVAR(headlessClients)) exitWith {
@ -28,9 +28,7 @@ if !(_object in GVAR(headlessClients)) exitWith {
if (CBA_missionTime < 150) then {
TRACE_1("Mission start delay",CBA_missionTime);
GVAR(endMissionCheckDelayed) = true;
[{
call FUNC(endMissionNoPlayers);
}, [], 150 - CBA_missionTime] call CBA_fnc_waitAndExecute;
[LINKFUNC(endMissionNoPlayers), [], 150 - CBA_missionTime] call CBA_fnc_waitAndExecute;
} else {
// End instantly or after delay
if (XGVAR(endMission) == 1) then {
@ -39,7 +37,7 @@ if !(_object in GVAR(headlessClients)) exitWith {
} else {
TRACE_2("Delayed 60s end",GVAR(endMission),CBA_missionTime);
GVAR(endMissionCheckDelayed) = true;
[FUNC(endMissionNoPlayers), [], 60] call CBA_fnc_waitAndExecute;
[LINKFUNC(endMissionNoPlayers), [], 60] call CBA_fnc_waitAndExecute;
};
};
};

View File

@ -4,27 +4,22 @@
* Handles AI spawn and requests a rebalance if applicable.
*
* Arguments:
* 0: Object <OBJECT>
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [object] call ace_headless_fnc_handleSpawn
* [cursorObject] call ace_headless_fnc_handleSpawn
*
* Public: No
*/
params ["_object"];
TRACE_1("Spawn",_object);
params ["_unit"];
TRACE_1("Spawn",_unit);
// Exit if HC transferring disabled or object not a unit (including unit inside vehicle) or is player
if (!(_object in allUnits) || {isPlayer _object}) exitWith {};
// Exit and blacklist if of blacklist type
if ({_object isKindOf _x} count GVAR(blacklistType) > 0) exitWith {
_object setVariable [QXGVAR(blacklist), true];
};
// Exit if unit is player or UAV crew
if (isPlayer _unit || {unitIsUAV _unit}) exitWith {};
// Rebalance
[false] call FUNC(rebalance);

View File

@ -23,7 +23,7 @@ TRACE_3("Rebalance",GVAR(inRebalance),GVAR(headlessClients),_force);
if (GVAR(inRebalance) || {GVAR(headlessClients) isEqualTo []}) exitWith {};
// Transfer after rebalance delay
[FUNC(transferGroups), [_force], XGVAR(Delay)] call CBA_fnc_waitAndExecute;
[LINKFUNC(transferGroups), _force, XGVAR(delay)] call CBA_fnc_waitAndExecute;
// Currently in rebalance flag
GVAR(inRebalance) = true;

View File

@ -79,8 +79,8 @@ private _numTransferredHC3 = 0;
_transfer = false;
};
// No transfer if player in this group
if (isPlayer _x) exitWith {
// No transfer if player or UAV in this group
if (isPlayer _x || {unitIsUAV _x}) exitWith {
_transfer = false;
};
@ -89,14 +89,16 @@ private _numTransferredHC3 = 0;
_transfer = false;
};
// No transfer if vehicle unit is in or crew in that vehicle is blacklisted
if (vehicle _x != _x && {(vehicle _x) getVariable [QXGVAR(blacklist), false]}) exitWith {
private _vehicle = objectParent _x;
// No transfer if the vehicle the unit is in or if the crew in that vehicle is blacklisted
if ((_vehicle getVariable [QXGVAR(blacklist), false]) || {unitIsUAV _vehicle}) exitWith {
_transfer = false;
};
// Save gear if unit about to be transferred with current loadout (naked unit work-around)
if (XGVAR(transferLoadout) == 1) then {
_x setVariable [QGVAR(loadout), [_x] call CBA_fnc_getLoadout, true];
_x setVariable [QGVAR(loadout), _x call CBA_fnc_getLoadout, true];
};
} forEach (units _x);
};

View File

@ -4,7 +4,7 @@
[ELSTRING(common,Enabled), LSTRING(EnabledDesc)],
format ["ACE %1", LLSTRING(Module)],
false,
true,
1,
{[QGVAR(enabled), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
] call CBA_fnc_addSetting;
@ -15,9 +15,8 @@
[LSTRING(Delay), LSTRING(DelayDesc)],
format ["ACE %1", LLSTRING(Module)],
[0, 60, 15, -1],
true,
{[QGVAR(delay), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
1,
{[QGVAR(delay), _this] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;
[
@ -26,7 +25,7 @@
[LSTRING(EndMission), LSTRING(EndMissionDesc)],
format ["ACE %1", LLSTRING(Module)],
[[0, 1, 2], [ELSTRING(Common,Disabled), LSTRING(Instant), LSTRING(Delayed)], 0],
true,
1,
{[QGVAR(delay), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
] call CBA_fnc_addSetting;
@ -37,9 +36,8 @@
[LSTRING(Log), LSTRING(LogDesc)],
format ["ACE %1", LLSTRING(Module)],
false,
true,
{[QGVAR(enabled), _this] call EFUNC(common,cbaSettings_settingChanged)},
true
1,
{[QGVAR(enabled), _this] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;
[
@ -48,7 +46,7 @@
[LSTRING(TransferLoadout), LSTRING(TransferLoadoutDesc)],
format ["ACE %1", LLSTRING(Module)],
[[0, 1, 2], [ELSTRING(Common,Disabled), LSTRING(TransferLoadoutCurrent), LSTRING(TransferLoadoutConfig)], 0],
true,
1,
{},
true // needs mission restart
] call CBA_fnc_addSetting;

View File

@ -17,4 +17,3 @@
#include "\z\ace\addons\main\script_macros.hpp"
#define DELAY_DEFAULT 15
#define BLACKLIST_UAV "UAV", "UAV_AI_base_F", "B_UAV_AI", "O_UAV_AI", "I_UAV_AI"