mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Pass functions by "reference" to bis event handlers (#4898)
* Pass functions by "reference" to bis event handlers * Add Doc * Fix
This commit is contained in:
parent
036bb0ecd4
commit
dfca4fdcf8
@ -1,3 +1,3 @@
|
|||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
params ["_wire"];
|
params ["_wire"];
|
||||||
_wire addEventHandler ["HandleDamage", FUNC(handleDamage)];
|
_wire addEventHandler ["HandleDamage", {call FUNC(handleDamage)}];
|
||||||
|
@ -35,7 +35,7 @@ GVAR(lastPlayerVehicle) = objNull;
|
|||||||
TRACE_2("removed veh eh",_firedEH,GVAR(lastPlayerVehicle));
|
TRACE_2("removed veh eh",_firedEH,GVAR(lastPlayerVehicle));
|
||||||
};
|
};
|
||||||
if ((!isNull _vehicle) && {_player != _vehicle}) then {
|
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];
|
_vehicle setVariable [QGVAR(firedEH), _firedEH];
|
||||||
GVAR(lastPlayerVehicle) = _vehicle;
|
GVAR(lastPlayerVehicle) = _vehicle;
|
||||||
TRACE_2("added veh eh",_firedEH,GVAR(lastPlayerVehicle));
|
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
|
// Don't add a new EH if the unit respawned
|
||||||
if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then {
|
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];
|
_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];
|
_player setVariable [QGVAR(explosionEH), _explosionEH];
|
||||||
TRACE_3("added unit eh",_player,_firedEH,_explosionEH);
|
TRACE_3("added unit eh",_player,_firedEH,_explosionEH);
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ GVAR(ParsedTextCached) = [];
|
|||||||
//Setup text/shadow/size/color settings matrix
|
//Setup text/shadow/size/color settings matrix
|
||||||
[] call FUNC(setupTextColors);
|
[] call FUNC(setupTextColors);
|
||||||
// Install the render EH on the main display
|
// Install the render EH on the main display
|
||||||
addMissionEventHandler ["Draw3D", DFUNC(render)];
|
addMissionEventHandler ["Draw3D", {call FUNC(render)}];
|
||||||
}] call CBA_fnc_addEventHandler;
|
}] call CBA_fnc_addEventHandler;
|
||||||
|
|
||||||
//Add Actions to Houses:
|
//Add Actions to Houses:
|
||||||
|
@ -77,5 +77,5 @@ GVAR(greenLaserUnits) = [];
|
|||||||
_unit call _fnc_processUnit;
|
_unit call _fnc_processUnit;
|
||||||
}, 0.1, _fnc_processUnit] call CBA_fnc_addPerFrameHandler;
|
}, 0.1, _fnc_processUnit] call CBA_fnc_addPerFrameHandler;
|
||||||
|
|
||||||
addMissionEventHandler ["Draw3D", FUNC(onDraw)];
|
addMissionEventHandler ["Draw3D", {call FUNC(onDraw)}];
|
||||||
}] call CBA_fnc_addEventHandler;
|
}] call CBA_fnc_addEventHandler;
|
||||||
|
@ -34,7 +34,7 @@ switch (toLower _mode) do {
|
|||||||
[FUNC(handleUnits), 9, _display] call CBA_fnc_addPerFrameHandler;
|
[FUNC(handleUnits), 9, _display] call CBA_fnc_addPerFrameHandler;
|
||||||
|
|
||||||
// Handle 3D unit icons
|
// Handle 3D unit icons
|
||||||
GVAR(iconHandler) = addMissionEventHandler ["Draw3D",FUNC(handleIcons)];
|
GVAR(iconHandler) = addMissionEventHandler ["Draw3D", {call FUNC(handleIcons)}];
|
||||||
|
|
||||||
// Populate the help window
|
// Populate the help window
|
||||||
private _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST;
|
private _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST;
|
||||||
|
@ -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.
|
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
|
### 7.4 Hashes
|
||||||
|
|
||||||
When a key value pair is required, make use of the hash implementation from ACE3.
|
When a key value pair is required, make use of the hash implementation from ACE3.
|
||||||
|
Loading…
Reference in New Issue
Block a user