Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless - Code optimisation #9873

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/headless/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -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", FUNC(handleSpawn), nil, nil, true] call CBA_fnc_addClassEventHandler;
["CAManBase", "initPost", LINKFUNC(handleSpawn), nil, nil, true] call CBA_fnc_addClassEventHandler;
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
// Add disconnect EH
addMissionEventHandler ["HandleDisconnect", {call FUNC(handleDisconnect)}];
Expand Down
3 changes: 1 addition & 2 deletions addons/headless/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ if (isServer) then {
GVAR(headlessClients) = [];
GVAR(inRebalance) = false;
GVAR(endMissionCheckDelayed) = false;
GVAR(blacklistType) = [BLACKLIST_UAV];
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
[QXGVAR(headlessClientJoined), FUNC(handleConnectHC)] call CBA_fnc_addEventHandler;
[QXGVAR(headlessClientJoined), LINKFUNC(handleConnectHC)] call CBA_fnc_addEventHandler;
};

ADDON = true;
7 changes: 2 additions & 5 deletions addons/headless/functions/fnc_handleConnectHC.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 3 additions & 5 deletions addons/headless/functions/fnc_handleDisconnect.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

params ["_object"];
TRACE_1("HandleDisconnect",_this);
TRACE_1("HandleDisconnect",_object);

// Exit if not HC
if !(_object in GVAR(headlessClients)) exitWith {
Expand All @@ -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 {
Expand All @@ -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;
};
};
};
Expand Down
17 changes: 6 additions & 11 deletions addons/headless/functions/fnc_handleSpawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion addons/headless/functions/fnc_rebalance.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 5 additions & 3 deletions addons/headless/functions/fnc_transferGroups.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -89,8 +89,10 @@ private _numTransferredHC3 = 0;
_transfer = false;
};

private _vehicle = vehicle _x;
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

// 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 {
if (_vehicle != _x && {_vehicle getVariable [QXGVAR(blacklist), false] || {unitIsUAV _vehicle}}) exitWith {
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
_transfer = false;
};

Expand Down
16 changes: 7 additions & 9 deletions addons/headless/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

[
Expand All @@ -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;
Expand All @@ -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;

[
Expand All @@ -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;
1 change: 0 additions & 1 deletion addons/headless/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"