2015-03-11 02:20:05 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: esteldunedain and Jaynus
|
2015-03-21 21:09:42 +00:00
|
|
|
* Returns the result of the function and caches it up to a given time or event
|
2015-03-11 02:20:05 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2015-03-21 20:50:35 +00:00
|
|
|
* 5: Event that clears the cache <STRING> (Optional)
|
2015-03-11 02:20:05 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Result of the function <ANY>
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-05-14 18:02:42 +00:00
|
|
|
PARAMS_5(_params,_function,_namespace,_uid,_duration);
|
2015-03-11 02:20:05 +00:00
|
|
|
|
2015-05-14 22:12:40 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING("_eventName");
|
|
|
|
|
2015-03-11 02:20:05 +00:00
|
|
|
if (((_namespace getVariable [_uid, [-99999]]) select 0) < diag_tickTime) then {
|
|
|
|
_namespace setVariable [_uid, [diag_tickTime + _duration, _params call _function]];
|
2015-03-21 20:50:35 +00:00
|
|
|
|
|
|
|
// Does the cache needs to be cleared on an event?
|
|
|
|
if (count _this > 5) then {
|
|
|
|
private ["_event","_varName","_cacheList"];
|
|
|
|
_event = _this select 5;
|
|
|
|
_varName = format [QGVAR(clearCache_%1),_event];
|
|
|
|
_cacheList = missionNamespace getVariable _varName;
|
|
|
|
|
|
|
|
// If there was no EH to clear these caches, add one
|
|
|
|
if (isNil {_cacheList}) then {
|
|
|
|
_cacheList = [];
|
|
|
|
missionNamespace setVariable [_varName, _cacheList];
|
|
|
|
|
|
|
|
[_event, {
|
|
|
|
private ["_varName","_cacheList"];
|
|
|
|
// _eventName is defined on the function that calls the event
|
2015-03-21 21:09:42 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
|
|
|
diag_log text format ["ACE: Clear cached variables on event: %1", _eventName];
|
|
|
|
#endif
|
2015-03-21 20:50:35 +00:00
|
|
|
// Get the list of caches to clear
|
|
|
|
_varName = format [QGVAR(clearCache_%1),_eventName];
|
|
|
|
_cacheList = missionNamespace getVariable [_varName, []];
|
|
|
|
// Erase all the cached results
|
|
|
|
{
|
|
|
|
_x call FUNC(eraseCache);
|
|
|
|
} forEach _cacheList;
|
|
|
|
// Empty the list
|
|
|
|
missionNamespace setVariable [_varName, []];
|
|
|
|
}] call FUNC(addEventhandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add this cache to the list of the event
|
|
|
|
_cacheList pushBack [_namespace, _uid];
|
|
|
|
};
|
2015-03-11 02:20:05 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
|
|
|
diag_log format ["Calculated result: %1 %2", _namespace, _uid];
|
|
|
|
} else {
|
2015-03-11 03:21:05 +00:00
|
|
|
diag_log format ["Cached result : %1 %2", _namespace, _uid];
|
2015-03-11 02:20:05 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
(_namespace getVariable _uid) select 1
|