From c851a14da92dd42c11c7a727ee9b94b1d34a203b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sat, 17 Jan 2015 13:56:24 -0300 Subject: [PATCH] common: added execNextFrame function --- addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_execNextFrame.sqf | 34 +++++++++++++++++++ .../common/functions/fnc_waitAndExecute.sqf | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 addons/common/functions/fnc_execNextFrame.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 366b959251..a4e4f9bd22 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -31,6 +31,7 @@ PREP(displayTextPicture); PREP(displayTextStructured); PREP(doAnimation); PREP(endRadioTransmission); +PREP(execNextFrame); PREP(execPersistentFnc); PREP(execRemoteFnc); PREP(executePersistent); diff --git a/addons/common/functions/fnc_execNextFrame.sqf b/addons/common/functions/fnc_execNextFrame.sqf new file mode 100644 index 0000000000..406b753b6c --- /dev/null +++ b/addons/common/functions/fnc_execNextFrame.sqf @@ -0,0 +1,34 @@ +/* + * Author: CAA-Picard + * + * Executes a code on the next frame + * + * Argument: + * 0: Code to execute (Code) + * 1: Parameters to run the code with (Array) + * + * Return value: + * PFH handler ID + */ +#include "script_component.hpp" + +EXPLODE_4_PVT(_this,_func,_params,_delay,_interval); + +[ + { + EXPLODE_2_PVT(_this,_params,_pfhId); + EXPLODE_2_PVT(_params,_delayedExecParams,_startFrame); + EXPLODE_3_PVT(_delayedExecParams,_func,_funcParams); + + // Exit if we are still on the same frame + if (diag_frameno == _startFrame) exitWith {}; + + // Remove the PFH + [_pfhId] call cba_fnc_removePerFrameHandler; + + // Execute the function + _funcParams call _func; + }, + _interval, + [_this, diag_frameno] +] call CBA_fnc_addPerFrameHandler diff --git a/addons/common/functions/fnc_waitAndExecute.sqf b/addons/common/functions/fnc_waitAndExecute.sqf index 214ea10eb9..7b106cc0c1 100644 --- a/addons/common/functions/fnc_waitAndExecute.sqf +++ b/addons/common/functions/fnc_waitAndExecute.sqf @@ -33,4 +33,4 @@ EXPLODE_4_PVT(_this,_func,_params,_delay,_interval); }, _interval, [_this, time] -] call CBA_fnc_addPerFrameHandler \ No newline at end of file +] call CBA_fnc_addPerFrameHandler