Skip to content

Commit

Permalink
why do we need CR in 2016?
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Jul 13, 2016
1 parent 082ce3b commit 0f7a6ac
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 249 deletions.
398 changes: 199 additions & 199 deletions addons/xeh/fnc_compileEventHandlers.sqf
Original file line number Diff line number Diff line change
@@ -1,199 +1,199 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compileEventHandlers
Description:
Compiles all Extended EventHandlers in given config.
Parameters:
0: _baseConfig - What config file should be used. <CONFIG>
Returns:
Compiled code of all Extended EventHandlers <ARRAY>
format: [event1, event2, ..., eventN] <ARRAY>
eventX format: [_className <STRING>, _eventName <STRING>, _eventFunc <CODE>, _allowInheritance <BOOLEAN>, _excludedClasses <ARRAY>]
Examples:
(begin example)
configFile call CBA_fnc_compileEventHandlers;
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"

params [["_baseConfig", configNull, [configNull]]];

private _result = [];
private _resultNames = [];

// note: format is never used for config parsing here, because of it's 8192 character limitation.

{
private _eventName = _x;

{
private _eventFunc = "";
private _customName = configName _x;

if (isClass _x) then {
// events on clients and server
private _entry = _x >> "init";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};

// client only events
if (!isDedicated) then {
_entry = _x >> "clientInit";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// server only events
if (isServer) then {
_entry = _x >> "serverInit";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};
} else {
// global events
if (isText _x) then {
_eventFunc = getText _x + ";";
};
};

if !(_eventFunc isEqualTo "") then {
_eventFunc = compile _eventFunc;
TRACE_2("does something",_customName,_eventName);
} else {
_eventFunc = {};
TRACE_2("does NOT do something",_customName,_eventName);
};

_result pushBack ["", _eventName, _eventFunc];
_resultNames pushBack _customName;
} forEach configProperties [_baseConfig >> XEH_FORMAT_CONFIG_NAME(_eventName)];
} forEach ["preInit", "postInit"];

// object events
{
private _eventName = _x;

{
private _entryName = _eventName; // how the entries are labeled, e.g. init, serverInit

private _className = configName _x;
private _eventFuncBase = "";

if (_eventName == "initPost") then {
_entryName = "init";
};

// backwards compatibility
if (_eventName == "fired") then {
// generate backwards compatible format of _this
_eventFuncBase = "private _this = [_this select 0, _this select 1, _this select 2, _this select 3, _this select 4, _this select 6, _this select 5];";
diag_log text format ["[XEH]: Usage of deprecated Extended Event Handler ""fired"". Use ""firedBIS"" instead. Path: %1\%2\%3\%4.", configSourceMod _x, _baseConfig, XEH_FORMAT_CONFIG_NAME(_eventName), _className];
};

{
private _eventFunc = _eventFuncBase;
private _customName = configName _x;
private _allowInheritance = true;
private _excludedClasses = [];

if (isClass _x) then {
// allow inheritance of this event?
private _scope = _x >> "scope";

if (isNumber _scope) then {
_allowInheritance = getNumber _scope != 0;
};

// classes excluded from this event
private _exclude = _x >> "exclude";

if (isArray _exclude) then {
_excludedClasses append getArray _exclude;
};

if (isText _exclude) then {
_excludedClasses pushBack getText _exclude;
};

// events on clients and server
private _entry = _x >> _entryName;

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};

// client only events
if (!isDedicated) then {
_entry = _x >> format ["client%1", _entryName];

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// server only events
if (isServer) then {
_entry = _x >> format ["server%1", _entryName];

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// init event handlers that should run on respawn again, onRespawn = 1
if (toLower _eventName in ["init", "initpost"] && {getNumber (_x >> "onRespawn") == 1}) then {
_eventFunc = _eventFunc + "(_this select 0) addEventHandler ['Respawn', " + str _eventFunc + "];";
};
} else {
// global events
if (isText _x) then {
_eventFunc = _eventFunc + getText _x + ";";
};
};

// emulate oo-like inheritance by adding classnames that would redefine an event by using the same custom event name to the excluded classes
{
(_result select _forEachIndex) params ["_classNameX", "_eventNameX"];

// same custom name and same event type
if (_customName == _x && {_eventName == _eventNameX}) then {
// has parent already set, update parent to exclude this class
if (_className isKindOf _classNameX) then {
(_result select _forEachIndex select 4) pushBack _className;
};

// has child already set, add child to excluded classes
if (_classNameX isKindOf _className) then {
_excludedClasses pushBack _classNameX;
};
};
} forEach _resultNames;

// only add event on machines where it exists
if !(_eventFunc isEqualTo _eventFuncBase) then {
_eventFunc = compile _eventFunc;
TRACE_3("does something",_customName,_className,_eventName);
} else {
_eventFunc = {};
TRACE_3("does NOT do something",_customName,_className,_eventName);
};

_result pushBack [_className, _eventName, _eventFunc, _allowInheritance, _excludedClasses];
_resultNames pushBack _customName;
} forEach configProperties [_x];
} forEach configProperties [_baseConfig >> XEH_FORMAT_CONFIG_NAME(_eventName), "isClass _x"];
} forEach [XEH_EVENTS];

_result select {!((_x select 2) isEqualTo {})}
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compileEventHandlers
Description:
Compiles all Extended EventHandlers in given config.
Parameters:
0: _baseConfig - What config file should be used. <CONFIG>
Returns:
Compiled code of all Extended EventHandlers <ARRAY>
format: [event1, event2, ..., eventN] <ARRAY>
eventX format: [_className <STRING>, _eventName <STRING>, _eventFunc <CODE>, _allowInheritance <BOOLEAN>, _excludedClasses <ARRAY>]
Examples:
(begin example)
configFile call CBA_fnc_compileEventHandlers;
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"

params [["_baseConfig", configNull, [configNull]]];

private _result = [];
private _resultNames = [];

// note: format is never used for config parsing here, because of it's 8192 character limitation.

{
private _eventName = _x;

{
private _eventFunc = "";
private _customName = configName _x;

if (isClass _x) then {
// events on clients and server
private _entry = _x >> "init";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};

// client only events
if (!isDedicated) then {
_entry = _x >> "clientInit";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// server only events
if (isServer) then {
_entry = _x >> "serverInit";

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};
} else {
// global events
if (isText _x) then {
_eventFunc = getText _x + ";";
};
};

if !(_eventFunc isEqualTo "") then {
_eventFunc = compile _eventFunc;
TRACE_2("does something",_customName,_eventName);
} else {
_eventFunc = {};
TRACE_2("does NOT do something",_customName,_eventName);
};

_result pushBack ["", _eventName, _eventFunc];
_resultNames pushBack _customName;
} forEach configProperties [_baseConfig >> XEH_FORMAT_CONFIG_NAME(_eventName)];
} forEach ["preInit", "postInit"];

// object events
{
private _eventName = _x;

{
private _entryName = _eventName; // how the entries are labeled, e.g. init, serverInit

private _className = configName _x;
private _eventFuncBase = "";

if (_eventName == "initPost") then {
_entryName = "init";
};

// backwards compatibility
if (_eventName == "fired") then {
// generate backwards compatible format of _this
_eventFuncBase = "private _this = [_this select 0, _this select 1, _this select 2, _this select 3, _this select 4, _this select 6, _this select 5];";
diag_log text format ["[XEH]: Usage of deprecated Extended Event Handler ""fired"". Use ""firedBIS"" instead. Path: %1\%2\%3\%4.", configSourceMod _x, _baseConfig, XEH_FORMAT_CONFIG_NAME(_eventName), _className];
};

{
private _eventFunc = _eventFuncBase;
private _customName = configName _x;
private _allowInheritance = true;
private _excludedClasses = [];

if (isClass _x) then {
// allow inheritance of this event?
private _scope = _x >> "scope";

if (isNumber _scope) then {
_allowInheritance = getNumber _scope != 0;
};

// classes excluded from this event
private _exclude = _x >> "exclude";

if (isArray _exclude) then {
_excludedClasses append getArray _exclude;
};

if (isText _exclude) then {
_excludedClasses pushBack getText _exclude;
};

// events on clients and server
private _entry = _x >> _entryName;

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};

// client only events
if (!isDedicated) then {
_entry = _x >> format ["client%1", _entryName];

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// server only events
if (isServer) then {
_entry = _x >> format ["server%1", _entryName];

if (isText _entry) then {
_eventFunc = _eventFunc + getText _entry + ";";
};
};

// init event handlers that should run on respawn again, onRespawn = 1
if (toLower _eventName in ["init", "initpost"] && {getNumber (_x >> "onRespawn") == 1}) then {
_eventFunc = _eventFunc + "(_this select 0) addEventHandler ['Respawn', " + str _eventFunc + "];";
};
} else {
// global events
if (isText _x) then {
_eventFunc = _eventFunc + getText _x + ";";
};
};

// emulate oo-like inheritance by adding classnames that would redefine an event by using the same custom event name to the excluded classes
{
(_result select _forEachIndex) params ["_classNameX", "_eventNameX"];

// same custom name and same event type
if (_customName == _x && {_eventName == _eventNameX}) then {
// has parent already set, update parent to exclude this class
if (_className isKindOf _classNameX) then {
(_result select _forEachIndex select 4) pushBack _className;
};

// has child already set, add child to excluded classes
if (_classNameX isKindOf _className) then {
_excludedClasses pushBack _classNameX;
};
};
} forEach _resultNames;

// only add event on machines where it exists
if !(_eventFunc isEqualTo _eventFuncBase) then {
_eventFunc = compile _eventFunc;
TRACE_3("does something",_customName,_className,_eventName);
} else {
_eventFunc = {};
TRACE_3("does NOT do something",_customName,_className,_eventName);
};

_result pushBack [_className, _eventName, _eventFunc, _allowInheritance, _excludedClasses];
_resultNames pushBack _customName;
} forEach configProperties [_x];
} forEach configProperties [_baseConfig >> XEH_FORMAT_CONFIG_NAME(_eventName), "isClass _x"];
} forEach [XEH_EVENTS];

_result select {!((_x select 2) isEqualTo {})}
Loading

0 comments on commit 0f7a6ac

Please sign in to comment.