From 919c8469de59cd72391953417cf7df2eeb0fe1a0 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 5 Aug 2016 12:05:15 -0500 Subject: [PATCH] Add interaction action on demand (#4079) * Only use addActionEventHandler when needed -Only install addActionEventHandler when the interaction menu is actually open -Less SQF running each frame, -it should help with issue #4066 * Cleanup debug --- addons/interact_menu/XEH_PREP.hpp | 1 - addons/interact_menu/XEH_clientInit.sqf | 5 ++-- .../functions/fnc_handlePlayerChanged.sqf | 30 ------------------- .../interact_menu/functions/fnc_keyDown.sqf | 18 +++++++++++ addons/interact_menu/functions/fnc_keyUp.sqf | 8 +++++ 5 files changed, 28 insertions(+), 34 deletions(-) delete mode 100644 addons/interact_menu/functions/fnc_handlePlayerChanged.sqf diff --git a/addons/interact_menu/XEH_PREP.hpp b/addons/interact_menu/XEH_PREP.hpp index b571b19162..0c1a6842fc 100644 --- a/addons/interact_menu/XEH_PREP.hpp +++ b/addons/interact_menu/XEH_PREP.hpp @@ -9,7 +9,6 @@ PREP(collectActiveActionTree); PREP(createAction); PREP(ctrlSetParsedTextCached); PREP(findActionNode); -PREP(handlePlayerChanged); PREP(isSubPath); PREP(keyDown); PREP(keyUp); diff --git a/addons/interact_menu/XEH_clientInit.sqf b/addons/interact_menu/XEH_clientInit.sqf index e4b7655efc..0d280506b3 100644 --- a/addons/interact_menu/XEH_clientInit.sqf +++ b/addons/interact_menu/XEH_clientInit.sqf @@ -3,6 +3,8 @@ if (!hasInterface) exitWith {}; +GVAR(blockDefaultActions) = []; + GVAR(cachedBuildingTypes) = []; GVAR(cachedBuildingActionPairs) = []; @@ -53,9 +55,6 @@ GVAR(ParsedTextCached) = []; [GVAR(openedMenuType), false] call FUNC(keyUp); }] call CBA_fnc_addEventHandler; -// disable firing while the interact menu is is is opened -["unit", FUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler; - // background options ["ace_interactMenuOpened", { if (GVAR(menuBackground)==1) then {[QGVAR(menuBackground), true] call EFUNC(common,blurScreen);}; diff --git a/addons/interact_menu/functions/fnc_handlePlayerChanged.sqf b/addons/interact_menu/functions/fnc_handlePlayerChanged.sqf deleted file mode 100644 index f995ffa454..0000000000 --- a/addons/interact_menu/functions/fnc_handlePlayerChanged.sqf +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Author: commy2 - * Disables firing while the menu is opened. Called from playerChanged eh. - * - * Arguments: - * 0: New unit to add the addAction eh - * 1: Old unit to remove the addAction eh - * - * Return Value: - * None - */ -#include "script_component.hpp" - -params ["_newUnit", "_oldUnit"]; - -// add to new unit -private _ehid = [_newUnit, "DefaultAction", {GVAR(openedMenuType) >= 0}, { - if (!GVAR(actionOnKeyRelease) && GVAR(actionSelected)) then { - [GVAR(openedMenuType),true] call FUNC(keyUp); - }; -}] call EFUNC(common,addActionEventHandler); - -_newUnit setVariable [QGVAR(AAEHID), _ehid]; - -// remove from old unit -_ehid = _oldUnit getVariable [QGVAR(AAEHID), -1]; - -[_oldUnit, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler); - -_oldUnit setVariable [QGVAR(AAEHID), -1]; diff --git a/addons/interact_menu/functions/fnc_keyDown.sqf b/addons/interact_menu/functions/fnc_keyDown.sqf index 1aa9b4c653..58286a65bb 100644 --- a/addons/interact_menu/functions/fnc_keyDown.sqf +++ b/addons/interact_menu/functions/fnc_keyDown.sqf @@ -104,4 +104,22 @@ if (GVAR(openedMenuType) == 0) then { ["ace_interactMenuOpened", [_menuType]] call CBA_fnc_localEvent; +//Remove the old "DefaultAction" action event handler if it already exists +GVAR(blockDefaultActions) params [["_player", objNull], ["_ehid", -1]]; +TRACE_2("blockDefaultActions",_player,_ehid); +if (!isNull _player) then { + [_player, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler); + GVAR(blockDefaultActions) = []; +}; +//Add the "DefaultAction" action event handler +if (alive ACE_player) then { + private _ehid = [ACE_player, "DefaultAction", {GVAR(openedMenuType) >= 0}, { + if (!GVAR(actionOnKeyRelease) && GVAR(actionSelected)) then { + [GVAR(openedMenuType),true] call FUNC(keyUp); + }; + }] call EFUNC(common,addActionEventHandler); + TRACE_2("Added",ACE_player,_ehid); + GVAR(blockDefaultActions) = [ACE_player, _ehid]; +}; + true diff --git a/addons/interact_menu/functions/fnc_keyUp.sqf b/addons/interact_menu/functions/fnc_keyUp.sqf index ce96250552..aae9a370c1 100644 --- a/addons/interact_menu/functions/fnc_keyUp.sqf +++ b/addons/interact_menu/functions/fnc_keyUp.sqf @@ -46,6 +46,14 @@ if(GVAR(actionSelected)) then { ["ace_interactMenuClosed", [GVAR(openedMenuType)]] call CBA_fnc_localEvent; +//Remove the "DefaultAction" action event handler +GVAR(blockDefaultActions) params [["_player", objNull], ["_ehid", -1]]; +TRACE_2("blockDefaultActions",_player,_ehid); +if (!isNull _player) then { + [_player, "DefaultAction", _ehid] call EFUNC(common,removeActionEventHandler); + GVAR(blockDefaultActions) = []; +}; + GVAR(keyDown) = false; GVAR(keyDownSelfAction) = false; GVAR(openedMenuType) = -1;