ACE3/addons/common/functions/fnc_cachedCall.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

69 lines
2.3 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: esteldunedain, Jaynus
* Returns the result of the function and caches it up to a given time or event
*
* 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>
* 5: Event that clears the cache (default: nil) <STRING>
*
* Return Value:
* Result of the function <ANY>
*
* Example:
* [[array]], {dothings}, NAMESPACE, "UID", 5, "clear"] call ace_common_fnc_cachedCall
*
* Public: No
*/
params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"];
if ((_namespace getVariable [_uid, [-99999]]) select 0 < diag_tickTime) then {
_namespace setVariable [_uid, [diag_tickTime + _duration, _params call _function]];
// Does the cache need to be cleared on an event?
if (!isNil "_event") then {
private _varName = format [QGVAR(clearCache_%1), _event];
private _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, {
#ifdef DEBUG_MODE_FULL
INFO_1("Clear cached variables on event: %1",_eventName);
#endif
// Get the list of caches to clear
//IGNORE_PRIVATE_WARNING ["_eventName"];
// _eventName is defined on the function that calls the event
private _varName = format [QGVAR(clearCache_%1), _eventName];
private _cacheList = missionNamespace getVariable [_varName, []];
// Erase all the cached results
{
_x call FUNC(eraseCache);
} forEach _cacheList;
// Empty the list
missionNamespace setVariable [_varName, []];
}] call CBA_fnc_addEventHandler;
};
// Add this cache to the list of the event
_cacheList pushBack [_namespace, _uid];
};
#ifdef DEBUG_MODE_FULL
INFO_2("Calculated result: %1 %2",_namespace,_uid);
} else {
INFO_2("Cached result: %1 %2",_namespace,_uid);
#endif
};
(_namespace getVariable _uid) select 1