From 6b3783e8ffc63d04438c160a299c04627220223f Mon Sep 17 00:00:00 2001 From: Jonastex Date: Thu, 3 Oct 2024 13:01:53 +0200 Subject: [PATCH 1/4] Replacing loop with event mission --- addons/xeh/CfgFunctions.hpp | 1 - addons/xeh/fnc_addClassEventHandler.sqf | 6 --- addons/xeh/fnc_postInit.sqf | 11 +++++ addons/xeh/fnc_startFallbackLoop.sqf | 53 ------------------------- 4 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 addons/xeh/fnc_startFallbackLoop.sqf diff --git a/addons/xeh/CfgFunctions.hpp b/addons/xeh/CfgFunctions.hpp index 29837be6e7..b03718f275 100644 --- a/addons/xeh/CfgFunctions.hpp +++ b/addons/xeh/CfgFunctions.hpp @@ -9,7 +9,6 @@ class CfgFunctions { PATHTO_FNC(supportMonitor); PATHTO_FNC(compileEventHandlers); PATHTO_FNC(compileFunction); - PATHTO_FNC(startFallbackLoop); class preStart { preStart = 1; diff --git a/addons/xeh/fnc_addClassEventHandler.sqf b/addons/xeh/fnc_addClassEventHandler.sqf index 726514b6c4..9491769653 100644 --- a/addons/xeh/fnc_addClassEventHandler.sqf +++ b/addons/xeh/fnc_addClassEventHandler.sqf @@ -31,12 +31,6 @@ params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [ private _config = configFile >> "CfgVehicles" >> _className; -// init fallback loop when executing on incompatible class for the first time -if (!GVAR(fallbackRunning) && {ISINCOMP(_className)}) then { - WARNING_1("One or more children of class %1 do not support Extended Event Handlers. Fall back to loop.",configName _config); - call CBA_fnc_startFallbackLoop; -}; - // no such CfgVehicles class if (!isClass _config) exitWith {false}; diff --git a/addons/xeh/fnc_postInit.sqf b/addons/xeh/fnc_postInit.sqf index 09d0417f10..d0548d979e 100644 --- a/addons/xeh/fnc_postInit.sqf +++ b/addons/xeh/fnc_postInit.sqf @@ -19,6 +19,17 @@ Author: isNil { XEH_LOG("PostInit started. " + PFORMAT_9("MISSIONINIT",missionName,missionVersion,worldName,isMultiplayer,isServer,isDedicated,CBA_isHeadlessClient,hasInterface,didJIP)); + addMissionEventHandler ["EntityCreated", { + params ["_entity"]; + if !(ISPROCESSED(_entity)) then { + _entity call CBA_fnc_initEvents; + + if !(ISINITIALIZED(_entity)) then { + _entity call CBA_fnc_init; + }; + }; + }]; + // fix CBA_missionTime being -1 on (non-JIP) clients at mission start. if (CBA_missionTime == -1) then { CBA_missionTime = 0; diff --git a/addons/xeh/fnc_startFallbackLoop.sqf b/addons/xeh/fnc_startFallbackLoop.sqf deleted file mode 100644 index 9528038ab0..0000000000 --- a/addons/xeh/fnc_startFallbackLoop.sqf +++ /dev/null @@ -1,53 +0,0 @@ -#include "script_component.hpp" -/* ---------------------------------------------------------------------------- -Internal Function: CBA_fnc_startFallbackLoop - -Description: - Starts a loop to iterate through all objects to initialize event handlers on XEH incompatible objects. - Internal use only. - -Parameters: - None - -Returns: - None - -Examples: - (begin example) - call CBA_fnc_startFallbackLoop; - (end) - -Author: - commy2 ----------------------------------------------------------------------------- */ - -if (GVAR(fallbackRunning)) exitWith {}; - -GVAR(fallbackRunning) = true; - -{ - // don't run init and initPost event handlers on objects that already exist - SETINITIALIZED(_x); -} count (entities [[], [], true, true]); // count is safe here because SETINITIALIZED is a setVariable, which returns nil - -GVAR(entities) = []; - -[{ - SCRIPT(fallbackLoopPFEH); - private _entities = entities [[], [], true, true]; - - if (_entities isNotEqualTo GVAR(entities)) then { - private _newEntities = _entities - GVAR(entities); - GVAR(entities) = _entities; - - { - if !(ISPROCESSED(_x)) then { - _x call CBA_fnc_initEvents; - - if !(ISINITIALIZED(_x)) then { - _x call CBA_fnc_init; - }; - }; - } forEach _newEntities; - }; -}, 0.1, []] call CBA_fnc_addPerFrameHandler; From 449b06856524af2de8fa7da3b72ae8f5a507ef9d Mon Sep 17 00:00:00 2001 From: Jonastex Date: Wed, 9 Oct 2024 12:07:36 +0200 Subject: [PATCH 2/4] Filter entity created & init object --- addons/xeh/fnc_postInit.sqf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/xeh/fnc_postInit.sqf b/addons/xeh/fnc_postInit.sqf index d0548d979e..4ca769ec4c 100644 --- a/addons/xeh/fnc_postInit.sqf +++ b/addons/xeh/fnc_postInit.sqf @@ -21,7 +21,7 @@ isNil { addMissionEventHandler ["EntityCreated", { params ["_entity"]; - if !(ISPROCESSED(_entity)) then { + if ((!ISPROCESSED(_entity)) && (ISINCOMP(typeof _entity))) then { _entity call CBA_fnc_initEvents; if !(ISINITIALIZED(_entity)) then { @@ -29,6 +29,17 @@ isNil { }; }; }]; + + // init object incomp + { + if !(ISPROCESSED(_x)) then { + _x call CBA_fnc_initEvents; + + if !(ISINITIALIZED(_x)) then { + _x call CBA_fnc_init; + }; + }; + } forEach (entities [(call (uiNamespace getVariable [QGVAR(incompatibleClasses), {[]}])), [], true, true]); // fix CBA_missionTime being -1 on (non-JIP) clients at mission start. if (CBA_missionTime == -1) then { From 13ae8ca49219be52186d163a0ec69a0b48b898e9 Mon Sep 17 00:00:00 2001 From: Jonastex Date: Wed, 9 Oct 2024 12:27:29 +0200 Subject: [PATCH 3/4] comment details --- addons/xeh/fnc_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/xeh/fnc_postInit.sqf b/addons/xeh/fnc_postInit.sqf index 4ca769ec4c..28d7340f71 100644 --- a/addons/xeh/fnc_postInit.sqf +++ b/addons/xeh/fnc_postInit.sqf @@ -30,7 +30,7 @@ isNil { }; }]; - // init object incomp + // init object incompatile XEH { if !(ISPROCESSED(_x)) then { _x call CBA_fnc_initEvents; From 095085c604ad3cea4e6c3d7f81c8a2d027f7e650 Mon Sep 17 00:00:00 2001 From: Jonastex <30275981+Jonastex@users.noreply.github.com> Date: Thu, 10 Oct 2024 08:42:42 +0200 Subject: [PATCH 4/4] Update addons/xeh/fnc_postInit.sqf Co-authored-by: Filip Maciejewski --- addons/xeh/fnc_postInit.sqf | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/addons/xeh/fnc_postInit.sqf b/addons/xeh/fnc_postInit.sqf index 28d7340f71..e3c5b1e499 100644 --- a/addons/xeh/fnc_postInit.sqf +++ b/addons/xeh/fnc_postInit.sqf @@ -19,27 +19,31 @@ Author: isNil { XEH_LOG("PostInit started. " + PFORMAT_9("MISSIONINIT",missionName,missionVersion,worldName,isMultiplayer,isServer,isDedicated,CBA_isHeadlessClient,hasInterface,didJIP)); - addMissionEventHandler ["EntityCreated", { - params ["_entity"]; - if ((!ISPROCESSED(_entity)) && (ISINCOMP(typeof _entity))) then { - _entity call CBA_fnc_initEvents; + private _incompatibleClasses = call (uiNamespace getVariable [QGVAR(incompatibleClasses), {[]}]); + if (count _incompatibleClasses > 0) then { - if !(ISINITIALIZED(_entity)) then { - _entity call CBA_fnc_init; + addMissionEventHandler ["EntityCreated", { + params ["_entity"]; + if ((!ISPROCESSED(_entity)) && (ISINCOMP(typeOf _entity))) then { + _entity call CBA_fnc_initEvents; + + if !(ISINITIALIZED(_entity)) then { + _entity call CBA_fnc_init; + }; }; - }; - }]; - - // init object incompatile XEH - { - if !(ISPROCESSED(_x)) then { - _x call CBA_fnc_initEvents; + }]; + + // init object incompatile XEH + { + if !(ISPROCESSED(_x)) then { + _x call CBA_fnc_initEvents; - if !(ISINITIALIZED(_x)) then { - _x call CBA_fnc_init; + if !(ISINITIALIZED(_x)) then { + _x call CBA_fnc_init; + }; }; - }; - } forEach (entities [(call (uiNamespace getVariable [QGVAR(incompatibleClasses), {[]}])), [], true, true]); + } forEach (entities [_incompatibleClasses, [], true, true]); + }; // fix CBA_missionTime being -1 on (non-JIP) clients at mission start. if (CBA_missionTime == -1) then {