From 17b63f2883cf00064b935123970b3a5814d9070a Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Sat, 9 Feb 2019 15:43:52 +0100 Subject: [PATCH 1/3] Cache refuel classes --- addons/refuel/XEH_postInit.sqf | 45 +++++++++++++--------------------- addons/refuel/XEH_preStart.sqf | 26 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/addons/refuel/XEH_postInit.sqf b/addons/refuel/XEH_postInit.sqf index 43933f2cf53..6805cb3ab16 100644 --- a/addons/refuel/XEH_postInit.sqf +++ b/addons/refuel/XEH_postInit.sqf @@ -62,36 +62,25 @@ GVAR(actions) = [ ]; // init menu for config refuel vehicles -private _sourceClasses = []; +private _cacheRefuelClasses = call (uiNamespace getVariable [QGVAR(cacheRefuelClasses), {[[],[]]}]); + +_cacheRefuelClasses params [["_staticClasses", [], [[]]], ["_dynamicClasses", [], [[]]]]; + { - private _fuelCargo = getNumber (_x >> QGVAR(fuelCargo)); - if (_fuelCargo > 0 || {_fuelCargo == REFUEL_INFINITE_FUEL}) then { - private _sourceClass = configName _x; - // check if we can use actions with inheritance - if ( - !isText (_x >> "EventHandlers" >> "CBA_Extended_EventHandlers" >> "init") // addActionToClass relies on XEH init - || {configName _x isKindOf "Static"} // CBA_fnc_addClassEventHandler doesn't support "Static" class - ) then { - if (2 == getNumber (_x >> "scope")) then { - [_sourceClass, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass); - { - [_sourceClass, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass); - } forEach GVAR(actions); - TRACE_1("add menu to static",_sourceClass); - }; - } else { - if (0 == {_sourceClass isKindOf _x} count _sourceClasses) then { - _sourceClasses pushBack _sourceClass; - [_sourceClass, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass); - { - [_sourceClass, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass); - } forEach GVAR(actions); - TRACE_1("add menu to dynamic",_sourceClass); - }; - }; - }; -} forEach ('true' configClasses (configFile >> "CfgVehicles")); + [_x, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass); + { + [_x, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass); + } forEach GVAR(actions); + TRACE_1("add menu to static",_x); +} forEach _staticClasses; +{ + [_x, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass); + { + [_x, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass); + } forEach GVAR(actions); + TRACE_1("add menu to dynamic",_x); +} forEach _dynamicClasses; #ifdef DRAW_HOOKS_POS addMissionEventHandler ["Draw3D", { diff --git a/addons/refuel/XEH_preStart.sqf b/addons/refuel/XEH_preStart.sqf index 022888575ed..7966321182b 100644 --- a/addons/refuel/XEH_preStart.sqf +++ b/addons/refuel/XEH_preStart.sqf @@ -1,3 +1,29 @@ #include "script_component.hpp" #include "XEH_PREP.hpp" + +// cache refuel vehicles, see XEH_postInit.sqf +private _staticClasses = []; +private _dynamicClasses = []; + +{ + private _fuelCargo = getNumber (_x >> QGVAR(fuelCargo)); + if (_fuelCargo > 0 || {_fuelCargo == REFUEL_INFINITE_FUEL}) then { + private _sourceClass = configName _x; + // check if we can use actions with inheritance + if ( + !isText (_x >> "EventHandlers" >> "CBA_Extended_EventHandlers" >> "init") // addActionToClass relies on XEH init + || {configName _x isKindOf "Static"} // CBA_fnc_addClassEventHandler doesn't support "Static" class + ) then { + if (2 == getNumber (_x >> "scope")) then { + _staticClasses pushBackUnique _sourceClass; + }; + } else { + if (0 == {_sourceClass isKindOf _x} count _dynamicClasses) then { + _dynamicClasses pushBackUnique _sourceClass; + }; + }; + }; +} forEach ('true' configClasses (configFile >> "CfgVehicles")); + +uiNamespace setVariable [QGVAR(cacheRefuelClasses), compileFinal str [_staticClasses, _dynamicClasses]]; \ No newline at end of file From 1349ba9db8c166afc87899bfacf54887c93c9c0c Mon Sep 17 00:00:00 2001 From: Dystopian Date: Tue, 12 Feb 2019 13:04:15 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-Authored-By: dedmen --- addons/refuel/XEH_preStart.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/refuel/XEH_preStart.sqf b/addons/refuel/XEH_preStart.sqf index 7966321182b..72c3823c8d9 100644 --- a/addons/refuel/XEH_preStart.sqf +++ b/addons/refuel/XEH_preStart.sqf @@ -19,11 +19,11 @@ private _dynamicClasses = []; _staticClasses pushBackUnique _sourceClass; }; } else { - if (0 == {_sourceClass isKindOf _x} count _dynamicClasses) then { + if (-1 == _dynamicClasses findIf {_sourceClass isKindOf _x}) then { _dynamicClasses pushBackUnique _sourceClass; }; }; }; } forEach ('true' configClasses (configFile >> "CfgVehicles")); -uiNamespace setVariable [QGVAR(cacheRefuelClasses), compileFinal str [_staticClasses, _dynamicClasses]]; \ No newline at end of file +uiNamespace setVariable [QGVAR(cacheRefuelClasses), compileFinal str [_staticClasses, _dynamicClasses]]; From a842d9a68b473120930ad4d98fad8b2ef236b289 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 14 Feb 2019 14:57:30 -0600 Subject: [PATCH 3/3] Fix script errors from inner _x --- addons/refuel/XEH_postInit.sqf | 11 ++++++----- addons/refuel/XEH_preStart.sqf | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/refuel/XEH_postInit.sqf b/addons/refuel/XEH_postInit.sqf index 6805cb3ab16..e6c0ad5b932 100644 --- a/addons/refuel/XEH_postInit.sqf +++ b/addons/refuel/XEH_postInit.sqf @@ -63,21 +63,22 @@ GVAR(actions) = [ // init menu for config refuel vehicles private _cacheRefuelClasses = call (uiNamespace getVariable [QGVAR(cacheRefuelClasses), {[[],[]]}]); - _cacheRefuelClasses params [["_staticClasses", [], [[]]], ["_dynamicClasses", [], [[]]]]; { - [_x, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass); + private _className = _x; + [_className, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass); { - [_x, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass); + [_className, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass); } forEach GVAR(actions); TRACE_1("add menu to static",_x); } forEach _staticClasses; { - [_x, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass); + private _className = _x; + [_className, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass); { - [_x, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass); + [_className, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass); } forEach GVAR(actions); TRACE_1("add menu to dynamic",_x); } forEach _dynamicClasses; diff --git a/addons/refuel/XEH_preStart.sqf b/addons/refuel/XEH_preStart.sqf index 72c3823c8d9..fa5fe4acda1 100644 --- a/addons/refuel/XEH_preStart.sqf +++ b/addons/refuel/XEH_preStart.sqf @@ -26,4 +26,5 @@ private _dynamicClasses = []; }; } forEach ('true' configClasses (configFile >> "CfgVehicles")); +TRACE_2("compiled",count _staticClasses,count _dynamicClasses); uiNamespace setVariable [QGVAR(cacheRefuelClasses), compileFinal str [_staticClasses, _dynamicClasses]];