mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Added helper function to cache generic function calls for a given time
This commit is contained in:
parent
cad5456010
commit
fab81c8701
@ -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);
|
||||
|
30
addons/common/functions/fnc_cachedCall.sqf
Normal file
30
addons/common/functions/fnc_cachedCall.sqf
Normal 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
|
18
addons/common/functions/fnc_eraseCache.sqf
Normal file
18
addons/common/functions/fnc_eraseCache.sqf
Normal 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];
|
Loading…
Reference in New Issue
Block a user