From 213b8179471f7d465024761e1d4292d57a3a8087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sat, 21 Mar 2015 17:50:35 -0300 Subject: [PATCH 1/2] Added to cachedCall an option to clear the cache on an event --- addons/common/functions/fnc_cachedCall.sqf | 33 +++++++++++++++++++ .../functions/fnc_renderBaseMenu.sqf | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index 0c9aafcfc8..a61c24c802 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -8,6 +8,7 @@ * 2: Namespace to store the cache on * 3: Cache uid * 4: Max duration of the cache + * 5: Event that clears the cache (Optional) * * Return Value: * Result of the function @@ -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 { diff --git a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf index 277f79c141..b73c3c4979 100644 --- a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf +++ b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf @@ -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 = { From 87b1458dc0cc2bb50d3de809d7864371343b350c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sat, 21 Mar 2015 18:09:42 -0300 Subject: [PATCH 2/2] Fix debug stuff --- addons/common/functions/fnc_cachedCall.sqf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index a61c24c802..03916b8600 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -1,6 +1,6 @@ /* * Author: CAA-Picard and Jaynus - * Returns the result of the function and caches it up to a given time + * Returns the result of the function and caches it up to a given time or event * * Arguments: * 0: Parameters @@ -37,7 +37,9 @@ if (((_namespace getVariable [_uid, [-99999]]) select 0) < diag_tickTime) then { [_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]; + #ifdef DEBUG_MODE_FULL + diag_log text format ["ACE: Clear cached variables on event: %1", _eventName]; + #endif // Get the list of caches to clear _varName = format [QGVAR(clearCache_%1),_eventName]; _cacheList = missionNamespace getVariable [_varName, []];