From 0b3d38a72f6cccb9880acb03cc446b725f51ba5d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 23 Sep 2016 16:40:52 -0500 Subject: [PATCH] Use waitAndExecute for fatigue loop (#4453) * Use waitAndExecute for fatigue loop Close #4379 - Will use CBA_missionTime so it repsects pause and time accl - Possible performance improvment over using a PFEH * Rename main loop function --- addons/advanced_fatigue/XEH_PREP.hpp | 2 +- addons/advanced_fatigue/XEH_postInit.sqf | 4 ++-- .../functions/{fnc_pfhMain.sqf => fnc_mainLoop.sqf} | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) rename addons/advanced_fatigue/functions/{fnc_pfhMain.sqf => fnc_mainLoop.sqf} (91%) diff --git a/addons/advanced_fatigue/XEH_PREP.hpp b/addons/advanced_fatigue/XEH_PREP.hpp index 1ec7705695..c6250516f5 100644 --- a/addons/advanced_fatigue/XEH_PREP.hpp +++ b/addons/advanced_fatigue/XEH_PREP.hpp @@ -5,6 +5,6 @@ PREP(getMetabolicCosts); PREP(handleEffects); PREP(handlePlayerChanged); PREP(handleStaminaBar); +PREP(mainLoop); PREP(moduleSettings); -PREP(pfhMain); PREP(removeDutyFactor); diff --git a/addons/advanced_fatigue/XEH_postInit.sqf b/addons/advanced_fatigue/XEH_postInit.sqf index ba733b33e1..d566e3b042 100644 --- a/addons/advanced_fatigue/XEH_postInit.sqf +++ b/addons/advanced_fatigue/XEH_postInit.sqf @@ -37,8 +37,8 @@ if (!hasInterface) exitWith {}; }] call FUNC(addDutyFactor); }; - // - Add main PFH ------------------------------------------------------------- - [FUNC(pfhMain), 1, []] call CBA_fnc_addPerFrameHandler; + // - Add main loop at 1 second interval ------------------------------------------------------------- + [FUNC(mainLoop), [], 1] call CBA_fnc_waitAndExecute; }] call CBA_fnc_addEventHandler; ["ace_settingChanged", { diff --git a/addons/advanced_fatigue/functions/fnc_pfhMain.sqf b/addons/advanced_fatigue/functions/fnc_mainLoop.sqf similarity index 91% rename from addons/advanced_fatigue/functions/fnc_pfhMain.sqf rename to addons/advanced_fatigue/functions/fnc_mainLoop.sqf index 9e7ad381d6..6430643cac 100644 --- a/addons/advanced_fatigue/functions/fnc_pfhMain.sqf +++ b/addons/advanced_fatigue/functions/fnc_mainLoop.sqf @@ -1,6 +1,6 @@ /* * Author: BaerMitUmlaut - * Main perFrameHandler that updates fatigue values. + * Main looping function that updates fatigue values. * * Arguments: * None @@ -9,7 +9,9 @@ * None */ #include "script_component.hpp" -if (!alive ACE_player) exitWith {}; // Dead people don't breath, Will also handle null (Map intros) +if (!alive ACE_player) exitWith { // Dead people don't breath, Will also handle null (Map intros) + [FUNC(mainLoop), [], 1] call CBA_fnc_waitAndExecute; +}; private _currentWork = REE; private _currentSpeed = (vectorMagnitude (velocity ACE_player)) min 6; @@ -61,3 +63,5 @@ private _perceivedFatigue = 1 - (_anReservePercentage min _aeReservePercentage); if (GVAR(enableStaminaBar)) then { [GVAR(anReserve) / AN_MAXRESERVE] call FUNC(handleStaminaBar); }; + +[FUNC(mainLoop), [], 1] call CBA_fnc_waitAndExecute;