Added helper function to cache generic function calls for a given time

This commit is contained in:
Nicolás Badano 2015-03-10 23:20:05 -03:00
parent cad5456010
commit fab81c8701
3 changed files with 50 additions and 0 deletions

View File

@ -19,6 +19,7 @@ PREP(ASLToPosition);
PREP(beingCarried);
PREP(binarizeNumber);
PREP(blurScreen);
PREP(cachedCall);
PREP(callCustomEventHandlers);
PREP(callCustomEventHandlersGlobal);
PREP(canGetInPosition);
@ -47,6 +48,7 @@ PREP(displayTextPicture);
PREP(displayTextStructured);
PREP(doAnimation);
PREP(endRadioTransmission);
PREP(eraseCache);
PREP(execNextFrame);
PREP(execPersistentFnc);
PREP(execRemoteFnc);

View File

@ -0,0 +1,30 @@
/*
* Author: CAA-Picard and Jaynus
* Returns the result of the function and caches it up to a given time
*
* Arguments:
* 0: Parameters <ARRAY>
* 1: Function <CODE>
* 2: Namespace to store the cache on <NAMESPACE>
* 3: Cache uid <STRING>
* 4: Max duration of the cache <NUMBER>
*
* Return Value:
* Result of the function <ANY>
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_5_PVT(_this,_params,_function,_namespace,_uid,_duration);
if (((_namespace getVariable [_uid, [-99999]]) select 0) < diag_tickTime) then {
_namespace setVariable [_uid, [diag_tickTime + _duration, _params call _function]];
#ifdef DEBUG_MODE_FULL
diag_log format ["Calculated result: %1 %2", _namespace, _uid];
} else {
diag_log format ["Cached result : %1 %2", _namespace, _uid];
#endif
};
(_namespace getVariable _uid) select 1

View File

@ -0,0 +1,18 @@
/*
* Author: CAA-Picard
* Deletes a cached result
*
* Arguments:
* 0: Namespace to store the cache on <NAMESPACE>
* 1: Cache uid <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_namespace,_uid);
_namespace setVariable [_uid, nil];