Skip to content

Commit

Permalink
xeh rewrite simplify init / initPost
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Jan 1, 2016
1 parent 12d5798 commit 5dd6d31
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 98 deletions.
4 changes: 2 additions & 2 deletions addons/xeh/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 7 additions & 6 deletions addons/xeh/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
46 changes: 46 additions & 0 deletions addons/xeh/fnc_init.sqf
Original file line number Diff line number Diff line change
@@ -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 <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
};
37 changes: 4 additions & 33 deletions addons/xeh/fnc_initObject.sqf → addons/xeh/fnc_initEvents.sqf
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -13,7 +13,7 @@ Returns:
Examples:
(begin example)
_unit call CBA_fnc_initObject;
_unit call CBA_fnc_initEvents;
(end)
Author:
Expand All @@ -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"")"];
Expand All @@ -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;
Expand All @@ -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
44 changes: 0 additions & 44 deletions addons/xeh/fnc_initPostObject.sqf

This file was deleted.

11 changes: 8 additions & 3 deletions addons/xeh/fnc_postInit_unsheduled.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion addons/xeh/fnc_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
17 changes: 9 additions & 8 deletions addons/xeh/fnc_startFallbackLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
3 changes: 3 additions & 0 deletions addons/xeh/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion addons/xeh/script_xeh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"")"; \
Expand Down

0 comments on commit 5dd6d31

Please sign in to comment.