diff --git a/addons/xeh/CfgEventHandlers.hpp b/addons/xeh/CfgEventHandlers.hpp index 2fde2c0e5..2a9fedd8f 100644 --- a/addons/xeh/CfgEventHandlers.hpp +++ b/addons/xeh/CfgEventHandlers.hpp @@ -1,10 +1,10 @@ -class CBA_Extended_EventHandlers { +class XEH_CLASS { EXTENDED_EVENTHANDLERS }; class DefaultEventhandlers { - class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {}; + class XEH_CLASS: XEH_CLASS {}; }; // The PreStart handlers run once when the game is started diff --git a/addons/xeh/CfgFunctions.hpp b/addons/xeh/CfgFunctions.hpp index 67fad6114..612cef5bc 100644 --- a/addons/xeh/CfgFunctions.hpp +++ b/addons/xeh/CfgFunctions.hpp @@ -14,14 +14,15 @@ class CfgFunctions { description = "Add an eventhandler to a class and all children."; file = PATHTOF(fnc_addClassEventHandler.sqf); }; - class initObject { + class init { headerType = -1; - description = "Runs Init and adds other event handlers on this object."; - file = PATHTOF(fnc_initObject.sqf); + description = "Runs Init and InitPost event handlers on this object."; + file = PATHTOF(fnc_init.sqf); }; - class initPostObject { - description = "Runs InitPost event handlers on this object."; - file = PATHTOF(fnc_initPostObject.sqf); + class initEvents { + headerType = -1; + description = "Adds all event handlers to this object."; + file = PATHTOF(fnc_initEvents.sqf); }; class supportMonitor { description = "Iterate through all vehicle classes and find those who don't support extended event handlers."; diff --git a/addons/xeh/fnc_init.sqf b/addons/xeh/fnc_init.sqf new file mode 100644 index 000000000..51ef473a4 --- /dev/null +++ b/addons/xeh/fnc_init.sqf @@ -0,0 +1,46 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_init + +Description: + Runs Init and InitPost event handlers on this object. + Internal use only. + +Parameters: + 0: Any CfgVehicles object + +Returns: + None + +Examples: + (begin example) + [_unit] call CBA_fnc_init; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_this"]; + +if !(ISINITIALIZED(_this)) then { + SETINITIALIZED(_this); + + // run Init + { + [_this] call _x; + } forEach (_this getVariable QGVAR(init)); + + // run InitPost or put on stack + if (SLX_XEH_MACHINE select 8) then { + { + [_this] call _x; + } forEach (_this getVariable QGVAR(initPost)); + } else { + GVAR(initPostStack) pushBack _this; + }; + + #ifdef DEBUG_MODE_FULL + diag_log ["Init", _unit, local _unit, typeOf _unit]; + #endif +}; diff --git a/addons/xeh/fnc_initObject.sqf b/addons/xeh/fnc_initEvents.sqf similarity index 65% rename from addons/xeh/fnc_initObject.sqf rename to addons/xeh/fnc_initEvents.sqf index 085bbce56..09e39bbc2 100644 --- a/addons/xeh/fnc_initObject.sqf +++ b/addons/xeh/fnc_initEvents.sqf @@ -1,8 +1,8 @@ /* ---------------------------------------------------------------------------- -Function: CBA_fnc_initObject +Function: CBA_fnc_initEvents Description: - Runs Init and adds other event handlers on this object. + Adds all event handlers to this object. Internal use only. Parameters: @@ -13,7 +13,7 @@ Returns: Examples: (begin example) - _unit call CBA_fnc_initObject; + _unit call CBA_fnc_initEvents; (end) Author: @@ -31,7 +31,7 @@ if !(ISPROCESSED(_unit)) then { if (getNumber (_class >> "SLX_XEH_DISABLED") == 1) exitWith {}; // add events to XEH incompatible units - if (ISINCOMP(typeOf _unit)) then { + if (!isClass (_class >> "EventHandlers" >> QUOTE(XEH_CLASS))) then { { if (_x isEqualTo "hitpart") then { _unit addEventHandler ["hitpart", "{_this call _x} forEach ((_this select 0 select 0) getVariable ""cba_xeh_hitpart"")"]; @@ -46,18 +46,6 @@ if !(ISPROCESSED(_unit)) then { while {isClass _class} do { private _className = configName _class; - // call Init event handlers - if !(ISINITIALIZED(_unit)) then { - { - if (ISKINDOF(_unit,_className,_x select 1,_x select 2)) then { - // prevent variable from being overwritten and causing issues without proper use of private - private ["_class", "_className"]; - - [_unit] call (_x select 0); - }; - } forEach EVENTHANDLERS("init",_className); - }; - // add other event handlers { private _eventName = _x; @@ -76,21 +64,4 @@ if !(ISPROCESSED(_unit)) then { _class = inheritsFrom _class; }; - - // run InitPost or put on stack - if !(ISINITIALIZED(_unit)) then { - if (SLX_XEH_MACHINE select 8) then { - _unit call CBA_fnc_initPostObject; - } else { - GVAR(InitPostStack) pushBack _unit; - }; - }; - - SETINITIALIZED(_unit); }; - -#ifdef DEBUG_MODE_FULL - diag_log ["Init", _unit, local _unit, typeOf _unit]; -#endif - -nil diff --git a/addons/xeh/fnc_initPostObject.sqf b/addons/xeh/fnc_initPostObject.sqf deleted file mode 100644 index 5cb2f60c3..000000000 --- a/addons/xeh/fnc_initPostObject.sqf +++ /dev/null @@ -1,44 +0,0 @@ -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_initPostObject - -Description: - Runs InitPost event handlers on this object. - Internal use only. - -Parameters: - 0: Any CfgVehicles object - -Returns: - None - -Examples: - (begin example) - _unit call CBA_fnc_initPostObject; - (end) - -Author: - commy2 ----------------------------------------------------------------------------- */ -#include "script_component.hpp" - -params ["_unit"]; - -private _class = configFile >> "CfgVehicles" >> typeOf _unit; - -while {isClass _class} do { - // call InitPost event handlers - { - if (ISKINDOF(_unit,configName _class,_x select 1,_x select 2)) then { - // prevent variable from being overwritten and causing issues without proper use of private - private _class = nil; - - [_unit] call (_x select 0); - }; - } forEach EVENTHANDLERS("initPost",configName _class); - - _class = inheritsFrom _class; -}; - -#ifdef DEBUG_MODE_FULL - diag_log ["InitPost", _unit, local _unit, typeOf _unit]; -#endif diff --git a/addons/xeh/fnc_postInit_unsheduled.sqf b/addons/xeh/fnc_postInit_unsheduled.sqf index 38d17cf39..148523090 100644 --- a/addons/xeh/fnc_postInit_unsheduled.sqf +++ b/addons/xeh/fnc_postInit_unsheduled.sqf @@ -27,9 +27,14 @@ XEH_LOG("XEH: PostInit started."); // do InitPost { - _x call CBA_fnc_initPostObject; -} forEach GVAR(InitPostStack); -GVAR(InitPostStack) = nil; + _x params ["_this"]; + + { + [_this] call _x; + } forEach (_this getVariable QGVAR(initPost)); +} forEach GVAR(initPostStack); + +GVAR(initPostStack) = nil; #ifdef DEBUG_MODE_FULL diag_log text format ["isSheduled = %1", call CBA_fnc_isSheduled]; diff --git a/addons/xeh/fnc_preInit.sqf b/addons/xeh/fnc_preInit.sqf index ded7a635c..df0b5564c 100644 --- a/addons/xeh/fnc_preInit.sqf +++ b/addons/xeh/fnc_preInit.sqf @@ -96,7 +96,7 @@ GVAR(fallbackRunning) = false; }; } forEach GVAR(allEventHandlers); -GVAR(InitPostStack) = []; +GVAR(initPostStack) = []; #ifdef DEBUG_MODE_FULL diag_log text format ["isSheduled = %1", call CBA_fnc_isSheduled]; diff --git a/addons/xeh/fnc_startFallbackLoop.sqf b/addons/xeh/fnc_startFallbackLoop.sqf index 371466919..48739cd9a 100644 --- a/addons/xeh/fnc_startFallbackLoop.sqf +++ b/addons/xeh/fnc_startFallbackLoop.sqf @@ -22,19 +22,15 @@ Author: #include "script_component.hpp" if (GVAR(fallbackRunning)) exitWith {}; -GVAR(fallbackRunning) = true; -GVAR(entities) = entities "" + allUnits; +GVAR(fallbackRunning) = true; { // don't run init and initPost event handlers on objects that already exist SETINITIALIZED(_x); +} forEach (entities "" + allUnits); - // add other events now. prevents addClassEventHandler from adding duplicates on incompatible units for the first time - if !(ISPROCESSED(_x)) then { - _x call CBA_fnc_initObject; - }; -} forEach GVAR(entities); +GVAR(entities) = []; [{ private _entities = entities "" + allUnits; @@ -44,8 +40,13 @@ GVAR(entities) = entities "" + allUnits; { if !(ISPROCESSED(_x)) then { - _x call CBA_fnc_initObject; + _x call CBA_fnc_initEvents; + + if (!ISINITIALIZED(_x) && {getNumber (configFile >> "CfgVehicles" >> typeOf _x >> "SLX_XEH_DISABLED") != 1}) then { + _x call CBA_fnc_init; + }; }; + nil } count _entities; }; }, 0.1, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/xeh/script_component.hpp b/addons/xeh/script_component.hpp index 721ea3205..e7fd54d3a 100644 --- a/addons/xeh/script_component.hpp +++ b/addons/xeh/script_component.hpp @@ -20,13 +20,16 @@ #define EVENTHANDLERS(type,class) (missionNamespace getVariable [SYS_EVENTHANDLERS(type,class), []]) #define SETEVENTHANDLERS(type,class,events) (missionNamespace setVariable [SYS_EVENTHANDLERS(type,class), events]) +// For any class that does not comply with XEH or has at least one incompatible descendant. #define SYS_INCOMP(class) format [QGVAR(\%1), class] #define SETINCOMP(class) missionNamespace setVariable [SYS_INCOMP(class), true] #define ISINCOMP(class) !isNil SYS_INCOMP(class) +// Event handler variables set. #define ISPROCESSED(obj) (obj getVariable [QGVAR(isProcessed), false]) #define SETPROCESSED(obj) obj setVariable [QGVAR(isProcessed), true] +// Init and InitPost events done. #define ISINITIALIZED(obj) (obj getVariable [QGVAR(isInitialized), false]) #define SETINITIALIZED(obj) obj setVariable [QGVAR(isInitialized), true] diff --git a/addons/xeh/script_xeh.hpp b/addons/xeh/script_xeh.hpp index 1c6741376..e1ab5ba94 100644 --- a/addons/xeh/script_xeh.hpp +++ b/addons/xeh/script_xeh.hpp @@ -9,7 +9,7 @@ // Add all XEH event handlers ///////////////////////////////////////////////////////////////////////////////// -#define EXTENDED_EVENTHANDLERS init = "_this call CBA_fnc_initObject"; \ +#define EXTENDED_EVENTHANDLERS init = "(_this select 0) call CBA_fnc_initEvents; (_this select 0) call CBA_fnc_init"; \ fired = "{_this call _x} forEach ((_this select 0) getVariable ""cba_xeh_fired"")"; \ animChanged = "{_this call _x} forEach ((_this select 0) getVariable ""cba_xeh_animChanged"")"; \ animDone = "{_this call _x} forEach ((_this select 0) getVariable ""cba_xeh_animDone"")"; \