From bb3495468e1a7369deffb6f0cc0931d6559c0224 Mon Sep 17 00:00:00 2001 From: jonpas Date: Mon, 29 Jun 2015 22:13:28 +0200 Subject: [PATCH] Replaced PFH for waitAndExecute with PFH-like handling --- addons/slideshow/XEH_preInit.sqf | 1 + .../functions/fnc_autoTransition.sqf | 45 +++++++++++++++++++ .../functions/fnc_createSlideshow.sqf | 33 +++++--------- 3 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 addons/slideshow/functions/fnc_autoTransition.sqf diff --git a/addons/slideshow/XEH_preInit.sqf b/addons/slideshow/XEH_preInit.sqf index 3e98e90d27..532bb906d8 100644 --- a/addons/slideshow/XEH_preInit.sqf +++ b/addons/slideshow/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(addSlideActions); +PREP(autoTransition); PREP(canChangeSlides); PREP(createSlideshow); PREP(makeList); diff --git a/addons/slideshow/functions/fnc_autoTransition.sqf b/addons/slideshow/functions/fnc_autoTransition.sqf new file mode 100644 index 0000000000..4c6df6e52a --- /dev/null +++ b/addons/slideshow/functions/fnc_autoTransition.sqf @@ -0,0 +1,45 @@ +/* + * Author: Jonpas + * Handles automatic slide transitions using waitAndExecute in a PFH-like manner resulting in no performance loss + * + * Arguments: + * 0: Objects + * 1: Controller Objects + * 2: Image Paths + * 3: Action Names + * 4: Duration (0 disables automatic transitions) + * + * Return Value: + * Parsed List + * + * Example: + * [objects, controllers, images, actionNames, duration] call ace_slideshow_fnc_autoTransition; + * + * Public: No + */ +#define DEBUG_MODE_FULL +#include "script_component.hpp" + +PARAMS_4(_objects,_images,_varString,_duration); + +private ["_currentSlide"]; + +// Get current slide number of this slideshow +_currentSlide = missionNamespace getVariable [_varString, 0]; + +// Increment slide or return to first slide if reached end +_currentSlide = (_currentSlide + 1) mod (count _images); + +// Save slide back into global variable (PFH's local variables do not persist through PFH run) +missionNamespace setVariable [_varString, _currentSlide]; + +// Set slide +{ + _x setObjectTextureGlobal [0, _images select _currentSlide]; +} forEach _objects; + +TRACE_4("Auto-transition",_images select _currentSlide,_currentSlide,count _images,_duration); + + +// Next slide +[FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call EFUNC(common,waitAndExecute); diff --git a/addons/slideshow/functions/fnc_createSlideshow.sqf b/addons/slideshow/functions/fnc_createSlideshow.sqf index 3d2f2041a2..2f8b6bdf09 100644 --- a/addons/slideshow/functions/fnc_createSlideshow.sqf +++ b/addons/slideshow/functions/fnc_createSlideshow.sqf @@ -7,7 +7,7 @@ * 1: Controller Objects * 2: Image Paths * 3: Action Names - * 4: Duration (0 disables automatic transitions) + * 4: Slide Duration (0 disables automatic transitions) * * Return Value: * Parsed List @@ -58,31 +58,18 @@ TRACE_4("Information",_objects,_controllers,_images,_names); } forEach _controllers; -// Exit if automatic transitions are not allowed +// Exit if automatic transitions are disabled if (_duration == 0) exitWith {}; - -// Number of slideshows and formatted global variable (multiple modules support) -private ["_varString"]; +// Number of slideshows (multiple modules support) GVAR(slideshows) = GVAR(slideshows) + 1; + +// Formatted GVAR string (multiple modules support) +private ["_varString"]; _varString = str format [QGVAR(currentSlide%1), GVAR(slideshows)]; -missionNamespace setVariable [_varString, 0]; // First slide -// Automatic transitions PFH -[{ - EXPLODE_3_PVT(_this select 0,_objects,_images,_varString); +// Set formatted GVAR to first slide +missionNamespace setVariable [_varString, 0]; - // Get current slide number of this slideshow - _currentSlide = missionNamespace getVariable [_varString, 0]; - // Increment slide or return to first slide if reached end - _currentSlide = (_currentSlide + 1) mod (count _images); - // Save slide back into global variable (PFH's local variables do not persist through PFH run) - missionNamespace setVariable [_varString, _currentSlide]; - - // Set slide - { - _x setObjectTextureGlobal [0, _images select _currentSlide]; - } forEach _objects; - - TRACE_3("Auto-transition",_images select _currentSlide,_currentSlide,count _images); -}, _duration, [_objects, _images, _varString]] call cba_fnc_addPerFrameHandler; +// Automatic transitions handler +[FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call EFUNC(common,waitAndExecute);