From b960ae5d6b1794522acab298cfd7580123016f73 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 12 Jun 2015 00:58:04 -0500 Subject: [PATCH] Optional setting to disable laser pointer system --- addons/laserpointer/ACE_Settings.hpp | 6 +++ addons/laserpointer/XEH_postInit.sqf | 46 ++++++++++--------- addons/laserpointer/config.cpp | 1 + .../functions/fnc_switchLaserLightMode.sqf | 5 ++ 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 addons/laserpointer/ACE_Settings.hpp diff --git a/addons/laserpointer/ACE_Settings.hpp b/addons/laserpointer/ACE_Settings.hpp new file mode 100644 index 0000000000..0536db730d --- /dev/null +++ b/addons/laserpointer/ACE_Settings.hpp @@ -0,0 +1,6 @@ +class ACE_Settings { + class GVAR(enabled) { + typeName = "BOOL"; + value = 1; + }; +}; diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf index 81b2da2473..5e16a06efe 100644 --- a/addons/laserpointer/XEH_postInit.sqf +++ b/addons/laserpointer/XEH_postInit.sqf @@ -14,26 +14,28 @@ if !(hasInterface) exitWith {}; GVAR(nearUnits) = []; -// @todo. Maybe move to common? -[{ - private "_nearUnits"; - _nearUnits = []; - - { - _nearUnits append crew _x; - - if (count _nearUnits > 10) exitWith { - _nearUnits resize 10; - }; - - } forEach nearestObjects [positionCameraToWorld [0,0,0], ["AllVehicles"], 50]; // when moving this, search also for units inside vehicles. currently breaks the laser in FFV - - GVAR(nearUnits) = _nearUnits; - -} , 5, []] call CBA_fnc_addPerFrameHandler; - -addMissionEventHandler ["Draw3D", { - call FUNC(onDraw); -}]; - #include "initKeybinds.sqf" + +["SettingsInitialized", { + //If not enabled, dont't add draw eventhandler or PFEH (for performance) + if (!GVAR(enabled)) exitWith {}; + + // @todo. Maybe move to common? + [{ + private "_nearUnits"; + _nearUnits = []; + { + _nearUnits append crew _x; + if (count _nearUnits > 10) exitWith { + _nearUnits resize 10; + }; + } forEach nearestObjects [positionCameraToWorld [0,0,0], ["AllVehicles"], 50]; // when moving this, search also for units inside vehicles. currently breaks the laser in FFV + + GVAR(nearUnits) = _nearUnits; + + } , 5, []] call CBA_fnc_addPerFrameHandler; + + addMissionEventHandler ["Draw3D", { + call FUNC(onDraw); + }]; +}] call EFUNC(common,addEventHandler); diff --git a/addons/laserpointer/config.cpp b/addons/laserpointer/config.cpp index 5ca5ce3470..d368512257 100644 --- a/addons/laserpointer/config.cpp +++ b/addons/laserpointer/config.cpp @@ -12,6 +12,7 @@ class CfgPatches { }; }; +#include "ACE_Settings.hpp" #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" diff --git a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf index 4927e7db13..99549ec18f 100644 --- a/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf +++ b/addons/laserpointer/functions/fnc_switchLaserLightMode.sqf @@ -37,6 +37,11 @@ _nextPointer = getText (_config >> "ACE_nextModeClass"); if (_nextPointer == "") exitWith {}; +//If system disabled, don't switch to a laser: +private "_nextPointerIsLaser"; +_nextPointerIsLaser = getNumber (configFile >> "CfgWeapons" >> _nextPointer >> "ACE_laserpointer"); +if ((!GVAR(enabled)) && {_nextPointerIsLaser == 1}) exitWith {}; + // disable inheritance for this entry, because addons claim this as a base class for convenience if !((_config >> "ACE_nextModeClass") in configProperties [_config, "true", false]) exitWith {};