From dfca4fdcf8234e8a634e736fc8bf3da7774be17c Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 14 Feb 2017 10:54:37 -0600 Subject: [PATCH] Pass functions by "reference" to bis event handlers (#4898) * Pass functions by "reference" to bis event handlers * Add Doc * Fix --- addons/concertina_wire/XEH_init.sqf | 2 +- addons/hearing/XEH_postInit.sqf | 6 +++--- addons/interact_menu/XEH_clientInit.sqf | 2 +- addons/laserpointer/XEH_postInit.sqf | 2 +- addons/spectator/functions/fnc_handleInterface.sqf | 2 +- docs/wiki/development/coding-guidelines.md | 9 +++++++++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/addons/concertina_wire/XEH_init.sqf b/addons/concertina_wire/XEH_init.sqf index dc6424f172..b24353b4df 100644 --- a/addons/concertina_wire/XEH_init.sqf +++ b/addons/concertina_wire/XEH_init.sqf @@ -1,3 +1,3 @@ #include "script_component.hpp" params ["_wire"]; -_wire addEventHandler ["HandleDamage", FUNC(handleDamage)]; +_wire addEventHandler ["HandleDamage", {call FUNC(handleDamage)}]; diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 19be45f3c3..cd2a5aec16 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -35,7 +35,7 @@ GVAR(lastPlayerVehicle) = objNull; TRACE_2("removed veh eh",_firedEH,GVAR(lastPlayerVehicle)); }; if ((!isNull _vehicle) && {_player != _vehicle}) then { - private _firedEH = _vehicle addEventHandler ["FiredNear", LINKFUNC(firedNear)]; + private _firedEH = _vehicle addEventHandler ["FiredNear", {call FUNC(firedNear)}]; _vehicle setVariable [QGVAR(firedEH), _firedEH]; GVAR(lastPlayerVehicle) = _vehicle; TRACE_2("added veh eh",_firedEH,GVAR(lastPlayerVehicle)); @@ -60,9 +60,9 @@ GVAR(lastPlayerVehicle) = objNull; }; // Don't add a new EH if the unit respawned if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then { - private _firedEH = _player addEventHandler ["FiredNear", LINKFUNC(firedNear)]; + private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}]; _player setVariable [QGVAR(firedEH), _firedEH]; - private _explosionEH = _player addEventHandler ["Explosion", LINKFUNC(explosionNear)]; + private _explosionEH = _player addEventHandler ["Explosion", {call FUNC(explosionNear)}]; _player setVariable [QGVAR(explosionEH), _explosionEH]; TRACE_3("added unit eh",_player,_firedEH,_explosionEH); }; diff --git a/addons/interact_menu/XEH_clientInit.sqf b/addons/interact_menu/XEH_clientInit.sqf index 0d280506b3..7e82e2c160 100644 --- a/addons/interact_menu/XEH_clientInit.sqf +++ b/addons/interact_menu/XEH_clientInit.sqf @@ -21,7 +21,7 @@ GVAR(ParsedTextCached) = []; //Setup text/shadow/size/color settings matrix [] call FUNC(setupTextColors); // Install the render EH on the main display - addMissionEventHandler ["Draw3D", DFUNC(render)]; + addMissionEventHandler ["Draw3D", {call FUNC(render)}]; }] call CBA_fnc_addEventHandler; //Add Actions to Houses: diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf index f80a4494e0..1a5a2df597 100644 --- a/addons/laserpointer/XEH_postInit.sqf +++ b/addons/laserpointer/XEH_postInit.sqf @@ -77,5 +77,5 @@ GVAR(greenLaserUnits) = []; _unit call _fnc_processUnit; }, 0.1, _fnc_processUnit] call CBA_fnc_addPerFrameHandler; - addMissionEventHandler ["Draw3D", FUNC(onDraw)]; + addMissionEventHandler ["Draw3D", {call FUNC(onDraw)}]; }] call CBA_fnc_addEventHandler; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index e5bb7498e0..9ba64ec0f0 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -34,7 +34,7 @@ switch (toLower _mode) do { [FUNC(handleUnits), 9, _display] call CBA_fnc_addPerFrameHandler; // Handle 3D unit icons - GVAR(iconHandler) = addMissionEventHandler ["Draw3D",FUNC(handleIcons)]; + GVAR(iconHandler) = addMissionEventHandler ["Draw3D", {call FUNC(handleIcons)}]; // Populate the help window private _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST; diff --git a/docs/wiki/development/coding-guidelines.md b/docs/wiki/development/coding-guidelines.md index b4f844a8e4..81cf20eff4 100644 --- a/docs/wiki/development/coding-guidelines.md +++ b/docs/wiki/development/coding-guidelines.md @@ -590,6 +590,15 @@ Event handlers in ACE3 are implemented through the CBA event system (ACE3's own More information on the [CBA Events System](https://github.com/CBATeam/CBA_A3/wiki/Custom-Events-System){:target="_blank"} and [CBA Player Events](https://github.com/CBATeam/CBA_A3/wiki/Player-Events){:target="_blank"} pages. +
+
Warning about BIS event handlers:
+

BIS's event handlers (`addEventHandler`, `addMissionEventHandler`) are slow when passing a large code variable. Use a short code block that calls the function you want.

+ ```js + player addEventHandler ["Fired", FUNC(handleFired)]; // bad + player addEventHandler ["Fired", {call FUNC(handleFired)}]; // good + ``` +
+ ### 7.4 Hashes When a key value pair is required, make use of the hash implementation from ACE3.