mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Added to cachedCall an option to clear the cache on an event
This commit is contained in:
parent
ce3ed988a2
commit
213b817947
@ -8,6 +8,7 @@
|
||||
* 2: Namespace to store the cache on <NAMESPACE>
|
||||
* 3: Cache uid <STRING>
|
||||
* 4: Max duration of the cache <NUMBER>
|
||||
* 5: Event that clears the cache <STRING> (Optional)
|
||||
*
|
||||
* Return Value:
|
||||
* Result of the function <ANY>
|
||||
@ -20,6 +21,38 @@ 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]];
|
||||
|
||||
// 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
|
||||
diag_log text format ["ACE: Clear cached variables on event: %1", _eventName];
|
||||
// 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];
|
||||
};
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
diag_log format ["Calculated result: %1 %2", _namespace, _uid];
|
||||
} else {
|
||||
|
@ -63,8 +63,9 @@ _uid = format [QGVAR(ATCache_%1), _actionData select 0];
|
||||
_activeActionTree = [
|
||||
[_object, _baseActionNode, []],
|
||||
DFUNC(collectActiveActionTree),
|
||||
_object, _uid, 0.2
|
||||
_object, _uid, 1.0, "interactMenuClosed"
|
||||
] call EFUNC(common,cachedCall);
|
||||
|
||||
/*
|
||||
diag_log "Printing: _activeActionTree";
|
||||
_fnc_print = {
|
||||
|
Loading…
Reference in New Issue
Block a user