Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass functions by "reference" to bis event handlers #4898

Merged
merged 3 commits into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/concertina_wire/XEH_init.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "script_component.hpp"
params ["_wire"];
_wire addEventHandler ["HandleDamage", FUNC(handleDamage)];
_wire addEventHandler ["HandleDamage", {call FUNC(handleDamage)}];
6 changes: 3 additions & 3 deletions addons/hearing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 (firedNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

_vehicle setVariable [QGVAR(firedEH), _firedEH];
GVAR(lastPlayerVehicle) = _vehicle;
TRACE_2("added veh eh",_firedEH,GVAR(lastPlayerVehicle));
Expand All @@ -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 (firedNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

_player setVariable [QGVAR(firedEH), _firedEH];
private _explosionEH = _player addEventHandler ["Explosion", LINKFUNC(explosionNear)];
private _explosionEH = _player addEventHandler ["Explosion", {call (explosionNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

_player setVariable [QGVAR(explosionEH), _explosionEH];
TRACE_3("added unit eh",_player,_firedEH,_explosionEH);
};
Expand Down
2 changes: 1 addition & 1 deletion addons/interact_menu/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion addons/laserpointer/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion addons/spectator/functions/fnc_handleInterface.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions docs/wiki/development/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<div class="panel info">
<h5>Warning about BIS event handlers:</h5>
<p>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.</p>
```js
player addEventHandler ["Fired", FUNC(handleFired)]; // bad
player addEventHandler ["Fired", {call FUNC(handleFired)}]; // good
```
</div>

### 7.4 Hashes

When a key value pair is required, make use of the hash implementation from ACE3.
Expand Down