Skip to content

Commit

Permalink
use Native Hashmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jokoho48 committed Apr 19, 2024
1 parent 3d22e8c commit 3a6a2ca
Show file tree
Hide file tree
Showing 35 changed files with 97 additions and 102 deletions.
2 changes: 1 addition & 1 deletion addons/CLib/3dGraphics/fn_add3dGraphics.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ private _completeGraphicsData = [];
};
} forEach _graphicsData;

[GVAR(3dGraphicsNamespace), _id, _completeGraphicsData] call CFUNC(setVariable);
GVAR(3dGraphicsNamespace) set [toLower _id, _completeGraphicsData];
GVAR(3dGraphicsCacheBuildFlag) = GVAR(3dGraphicsCacheBuildFlag) + 1;
5 changes: 2 additions & 3 deletions addons/CLib/3dGraphics/fn_build3dGraphicsCache.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
private _cache = [];

{
_cache append (GVAR(3dGraphicsNamespace) getVariable _x);
nil;
} count ([GVAR(3dGraphicsNamespace)] call CFUNC(allVariables));
_cache append _y;
} forEach (values GVAR(3dGraphicsNamespace));

GVAR(3dGraphicsCache) = +_cache;
2 changes: 1 addition & 1 deletion addons/CLib/3dGraphics/fn_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

//Namespace for Layer
GVAR(3dGraphicsNamespace) = call CFUNC(createNamespace);
GVAR(3dGraphicsNamespace) = createHashMap;

GVAR(3dGraphicsCache) = [];
GVAR(3dGraphicsCacheBuildFlag) = 0; // Should be incremented for each rebuild
Expand Down
2 changes: 1 addition & 1 deletion addons/CLib/3dGraphics/fn_remove3dGraphics.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ params [
["_id", "", [""]]
];

[GVAR(3dGraphicsNamespace), _id, nil] call CFUNC(setVariable);
GVAR(3dGraphicsNamespace) deleteAt (toLower _id);
GVAR(3dGraphicsCacheBuildFlag) = GVAR(3dGraphicsCacheBuildFlag) + 1;
4 changes: 2 additions & 2 deletions addons/CLib/AnimFramework/fn_getDeathAnimation.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ params [
private _animState = animationState _unit;
private _isInVehicle = isNull (objectParent _unit);
private _varName = format ["%1_%2", _animState, _isInVehicle];
private _return = GVAR(animDeathNamespace) getVariable [_varName, ""];
private _return = GVAR(animDeathNamespace) getOrDefault [toLower _varName, ""];

if (_return != "") exitWith {_return};
private _animConfig = configFile >> "CfgMovesMaleSdr" >> "States";
Expand All @@ -48,5 +48,5 @@ if (getNumber (_unitAnimCfg >> "terminal") isEqualTo 1) then {
if (_return == "") then {
_return = "Unconscious";
};
GVAR(animDeathNamespace) setVariable [_varName, _return];
GVAR(animDeathNamespace) set [toLower _varName, _return];
_return
2 changes: 1 addition & 1 deletion addons/CLib/AnimFramework/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
None
*/

GVAR(animDeathNamespace) = false call CFUNC(createNamespace);
GVAR(animDeathNamespace) = createHashMap;
2 changes: 1 addition & 1 deletion addons/CLib/CLib_Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define MOD CLib

#define MAJOR 0
#define MINOR 13
#define MINOR 14
#define PATCHLVL 0
#define BUILD 1086

Expand Down
9 changes: 3 additions & 6 deletions addons/CLib/ConfigCaching/fn_configProperties.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
https://community.bistudio.com/wiki/configProperties
*/

private _ret = GVAR(configCache) getVariable format [QGVAR(configProperties_%1), _this];
if (isNil "_ret") then {
_ret = configProperties _this;
GVAR(configCache) setVariable [format [QGVAR(configProperties_%1), _this], _ret];
};
_ret
GVAR(configCache) getOrDefaultCall [toLower (format [QGVAR(configProperties_%1), _this]), {
configProperties _this
}];
10 changes: 3 additions & 7 deletions addons/CLib/ConfigCaching/fn_getConfigDataCached.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ params [
["_forceDefaultType", false, [true]]
];

private _ret = GVAR(configCache) getVariable format [QGVAR(getCachedData_%1), _path];
if (isNil "_ret") then {
_ret = [_path, _default, _forceDefaultType] call CFUNC(getConfigData);

GVAR(configCache) setVariable [format [QGVAR(getCachedData_%1), _path], _ret];
};
_ret
GVAR(configCache) getOrDefaultCall [toLower (format [QGVAR(getCachedData_%1), _path]), {
[_path, _default, _forceDefaultType] call CFUNC(getConfigData);
}];
2 changes: 1 addition & 1 deletion addons/CLib/ConfigCaching/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
None
*/

GVAR(configCache) = call CFUNC(createNamespace);
GVAR(configCache) = createHashMap;
9 changes: 3 additions & 6 deletions addons/CLib/ConfigCaching/fn_returnParents.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
https://community.bistudio.com/wiki/BIS_fnc_returnParents
*/

private _ret = GVAR(configCache) getVariable format [QGVAR(returnParents_%1), _this];
if (isNil "_ret") then {
_ret = _this call BIS_fnc_returnParents;
GVAR(configCache) setVariable [format [QGVAR(returnParents_%1), _this], _ret];
};
_ret
GVAR(configCache) getOrDefaultCall [toLower (format [QGVAR(returnParents_%1), _this]), {
_this call BIS_fnc_returnParents
}];
17 changes: 9 additions & 8 deletions addons/CLib/Core/Misc/fn_cachedCall.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ params [
["_event", nil, [""]]
];

private _timestamp = (GVAR(cachedCall) getVariable [_uid, [-999999999]]) select 0;
_uid = toLower _uid;
private _timestamp = (GVAR(cachedCall) getOrDefault [_uid, [-999999999]]) select 0;
if (_timestamp < time) then {
GVAR(cachedCall) setVariable [_uid, [time + _duration, _args call _fnc]];
GVAR(cachedCall) set [_uid, [time + _duration, _args call _fnc]];

// Does the cache need to be cleared on an event?
if (!isNil "_event") then {
private _varName = format [QGVAR(clearCache_%1), _event];
private _cacheList = GVAR(cachedCall) getVariable _varName;
private _cacheList = GVAR(cachedCall) get _varName;

// If there was no EH to clear these caches, add one
if (isNil "_cacheList") then {
_cacheList = [];
GVAR(cachedCall) setVariable [_varName, _cacheList];
GVAR(cachedCall) set [_varName, _cacheList];

[_event, {
// _eventName is defined on the function that calls the event
// Get the list of caches to clear
private _varName = format [QGVAR(clearCache_%1), _eventName];
private _cacheList = GVAR(cachedCall) getVariable [_varName, []];
private _cacheList = GVAR(cachedCall) getOrDefault [_varName, []];
// Erase all the cached results
{
GVAR(cachedCall) setVariable [_x, nil];
GVAR(cachedCall) deleteAt _x;
} forEach _cacheList;
// Empty the list
GVAR(cachedCall) setVariable [_varName, []];
GVAR(cachedCall) set [_varName, []];
}] call CFUNC(addEventhandler);
};

Expand All @@ -62,4 +63,4 @@ if (_timestamp < time) then {
};
};

(GVAR(cachedCall) getVariable _uid) select 1
(GVAR(cachedCall) get _uid) select 1
19 changes: 8 additions & 11 deletions addons/CLib/Core/Misc/fn_compatibleMagazines.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ _if then {
_varName = format ["%1_%2_%3_%4", QGVAR(mags), _weapon, _muzzle];
};

_varName = toLower _varName;
if (isNil QGVAR(compatibleMagazinesNamespace)) then {
GVAR(compatibleMagazinesNamespace) = false call CFUNC(createNamespace);
GVAR(compatibleMagazinesNamespace) = createHashMap;
};

private _mags = GVAR(compatibleMagazinesNamespace) getVariable _varName;
private _mags = GVAR(compatibleMagazinesNamespace) get _varName;
if !(isNil "_mags") exitWith {_mags};
private _cfgWeapons = configFile >> "CfgWeapons" >> _weapon;
_if then {
Expand All @@ -44,10 +45,8 @@ private _cfgMagazineWells = configFile >> "CfgMagazineWells";
{
{
_mags append (getArray _x);
nil
} count configProperties [_cfgMagazineWells >> _x, "isArray _x", true];
nil
} count (getArray (_cfgWeapons >> "magazineWell"));
} forEach configProperties [_cfgMagazineWells >> _x, "isArray _x", true];
} forEach (getArray (_cfgWeapons >> "magazineWell"));

{
scopeName "loop";
Expand All @@ -59,16 +58,14 @@ private _cfgMagazineWells = configFile >> "CfgMagazineWells";
_inGroup = true;
breakTo "loop";
};
nil
} count (getArray (_cfgWeapons >> "magazines"));
} forEach (getArray (_cfgWeapons >> "magazines"));

if (_inGroup) then {
_mags pushBackUnique _class;
};
nil
} count configProperties [configFile >> "CfgMagazines", "isClass _x", true];
} forEach configProperties [configFile >> "CfgMagazines", "isClass _x", true];

_mags = _mags arrayIntersect _mags;
_mags = _mags - ["this"];
GVAR(compatibleMagazinesNamespace) setVariable [_varName, _mags];
GVAR(compatibleMagazinesNamespace) set [_varName, _mags];
_mags
2 changes: 1 addition & 1 deletion addons/CLib/Core/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

GVAR(allCustomNamespaces) = [];

GVAR(cachedCall) = call CFUNC(createNamespace);
GVAR(cachedCall) = createHashMap;

if (hasInterface) then {
CLib_Player setVariable [QGVAR(playerName), profileName, true];
Expand Down
6 changes: 3 additions & 3 deletions addons/CLib/Events/fn_addEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ params [
["_callback", {}, [{}, ""]],
["_args", [], []]
];

_event = toLower _event;
// Add this so we get can get sure some events that only gets triggered once get right
["eventAdded", [_event, _callback, _args]] call CFUNC(localEvent);

private _eventArray = GVAR(EventNamespace) getVariable [_event, []];
private _eventArray = GVAR(EventNamespace) getOrDefault [_event, []];
private _id = _eventArray pushBack [_callback, _args];
GVAR(EventNamespace) setVariable [_event, _eventArray];
GVAR(EventNamespace) set [_event, _eventArray];

_id
4 changes: 2 additions & 2 deletions addons/CLib/Events/fn_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private _codeStr = "private ['_oldValue', '_currentValue'];";

// Build a name for the variable where we store the data. Fill it with the initial value.
private _varName = format [QGVAR(EventData_%1), _name];
GVAR(EventNamespace) setVariable [_varName, call _code];
_codeStr = _codeStr + format ["_oldValue = %4 getVariable '%2'; _currentValue = call %1; if (_oldValue isNotEqualTo _currentValue) then { ['%5Changed', [_currentValue, _oldValue]] call %3; _oldValue = %4 setVariable ['%2', _currentValue]; };", _code, _varName, QCFUNC(localEvent), QGVAR(EventNamespace), _name];
GVAR(EventNamespace) set [_varName, call _code];
_codeStr = _codeStr + format ["_oldValue = %4 get '%2'; _currentValue = call %1; if (_oldValue isNotEqualTo _currentValue) then { ['%5Changed', [_currentValue, _oldValue]] call %3; _oldValue = %4 set ['%2', _currentValue]; };", _code, _varName, QCFUNC(localEvent), QGVAR(EventNamespace), _name];
} forEach [
["player", {missionNamespace getVariable ["bis_fnc_moduleRemoteControl_unit", player]}],
["currentThrowable", {currentThrowable CLib_Player}],
Expand Down
4 changes: 2 additions & 2 deletions addons/CLib/Events/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

GVAR(sideEnum) = [west, east, independent, civilian, sideEmpty, sideFriendly, sideEnemy, sideUnknown, sideLogic, sideAmbientLife];
GVAR(sideEnumStr) = GVAR(sideEnum) apply {toLower str _x};
GVAR(EventNamespace) = false call CFUNC(createNamespace);
GVAR(EventNamespace) = createHashMap;

GVAR(ignoredLogEventNames_0) = [];
GVAR(ignoredLogEventNames_1) = [];
Expand Down Expand Up @@ -259,7 +259,7 @@ GVAR(ignoredLogEventNames_1) = [];
}] call CFUNC(addEventhandler);
["setDynamicSimulationDistance", {
(_this select 0) params ["_category", "_distance"];
_category setDynamicSimulationDistance _distance
call compile "_category setDynamicSimulationDistance _distance"
}] call CFUNC(addEventhandler);
["setDynamicSimulationDistanceCoef", {
(_this select 0) params ["_class", "_multiplier"];
Expand Down
2 changes: 1 addition & 1 deletion addons/CLib/Events/fn_invokePlayerChanged.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ params [
];

["playerChanged", [_newPlayer, CLib_Player]] call CFUNC(localEvent);
GVAR(EventNamespace) setVariable [QGVAR(EventData_player), _newPlayer];
GVAR(EventNamespace) set [QGVAR(EventData_player), _newPlayer];
8 changes: 5 additions & 3 deletions addons/CLib/Events/fn_localEvent.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ params [
private _Clib_EventTime = diag_tickTime;
#endif

private _eventArray = GVAR(EventNamespace) getVariable _eventName;
_eventName = toLower _eventName;

private _eventArray = GVAR(EventNamespace) get _eventName;
private _CLib_EventReturn = nil;
if !(isNil "_eventArray") then {
{
Expand All @@ -42,9 +44,9 @@ if !(isNil "_eventArray") then {
};

#ifdef ISDEV
if (!(toLower _eventName in GVAR(ignoredLogEventNames_0))) then {
if !(_eventName in GVAR(ignoredLogEventNames_0)) then {
_Clib_EventTime = ((diag_tickTime - _Clib_EventTime) * 1000) call CFUNC(toFixedNumber);
private _text = format ["Local Event: %1 (%2ms) sent from %3: %4", _eventName, _Clib_EventTime, _CLib_sender, [_args, ""] select ((toLower _eventName) in GVAR(ignoredLogEventNames_1))];
private _text = format ["Local Event: %1 (%2ms) sent from %3: %4", _eventName, _Clib_EventTime, _CLib_sender, [_args, ""] select (_eventName in GVAR(ignoredLogEventNames_1))];
DUMP(_text);
};
#endif
Expand Down
5 changes: 3 additions & 2 deletions addons/CLib/Events/fn_removeEventhandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ params [
];

DUMP("Eventhandler Removed: "+ _event);
private _eventArray = GVAR(EventNamespace) getVariable [_event, []];
_event = toLower _event;
private _eventArray = GVAR(EventNamespace) getOrDefault [_event, []];
if (count _eventArray >= _id) then {
_eventArray set [_id, nil];
GVAR(EventNamespace) setVariable [_event, _eventArray];
GVAR(EventNamespace) set [_event, _eventArray];
true
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions addons/CLib/Interaction/fn_clientInitInteraction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GVAR(PlayerInteraction_Actions) = [];
_newUnit setVariable [QGVAR(ActionIDs), []];
}] call CFUNC(addEventhandler);

GVAR(InGameUIEventHandler) = call CFUNC(createNamespace);
GVAR(InGameUIEventHandler) = createHashMap;
GVAR(DisablePrevAction) = false;
GVAR(DisableNextAction) = false;
GVAR(DisableAction) = false;
Expand All @@ -52,7 +52,7 @@ private _inGameUiEventHandler = {
if (GVAR(DisablePrevAction) && {_eventName == "PrevAction"} || (GVAR(DisableNextAction) && {_eventName == "NextAction"}) || (GVAR(DisableAction) && {_eventName == "Action"})) then {
true
} else {
private _ehData = GVAR(InGameUIEventHandler) getVariable [format ["%1_%2", _eventName, _id], []];
private _ehData = GVAR(InGameUIEventHandler) getOrDefault [toLower (format ["%1_%2", _eventName, _id]), []];
_ehData params [["_code", {}], ["_args", []]];
[_target, _caller, _id, _args] call _code;
};
Expand Down
2 changes: 1 addition & 1 deletion addons/CLib/Interaction/fn_overrideAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ params [
["_arguments", [], []]
];

[GVAR(InGameUIEventHandler), format ["Action_%1", _actionName], [_code, _arguments]] call CFUNC(setVariable);
GVAR(InGameUIEventHandler) set [toLower (format ["Action_%1", _actionName]), [_code, _arguments]]
8 changes: 5 additions & 3 deletions addons/CLib/MapGraphics/fn_addMapGraphicsEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ private _namespace = missionNamespace getVariable _eventNameSpace;

// Check if namespace exist and if not create and save it
if (isNil "_namespace") then {
_namespace = call CFUNC(createNamespace);
_namespace = createHashMap;
missionNamespace setVariable [_eventNameSpace, _namespace];
};

private _eventArray = _namespace getVariable [_uid, []];
_uid = toLower _uid;

private _eventArray = _namespace getOrDefault [_uid, []];

private _id = _eventArray pushBack [_code, _args];

_namespace setVariable [_uid, _eventArray];
_namespace set [_uid, _eventArray];

_id
5 changes: 3 additions & 2 deletions addons/CLib/MapGraphics/fn_addMapGraphicsGroup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ private _completeGroupData = [];
// select the correct state
private _stateNum = 0 max (["normal", "hover", "selected"] find _state);

_groupName = toLower _groupName;
// save the data
private _currentIcon = GVAR(MapGraphicsGroup) getVariable [_groupName, [_layer, 0, 0, [], [], []]];
private _currentIcon = GVAR(MapGraphicsGroup) getOrDefault [_groupName, [_layer, 0, 0, [], [], []]];
_currentIcon set [_stateNum + 3, _completeGroupData];
_currentIcon set [1, time];
[GVAR(MapGraphicsGroup), _groupName, _currentIcon] call CFUNC(setVariable);
GVAR(MapGraphicsGroup) set [_groupName, _currentIcon];
// increment map graphics cache
GVAR(MapGraphicsCacheBuildFlag) = GVAR(MapGraphicsCacheBuildFlag) + 1;
nil
2 changes: 1 addition & 1 deletion addons/CLib/MapGraphics/fn_buildMapGraphicsCache.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private _cache = [];

{
private _graphicsGroupId = _x;
private _graphicsGroup = GVAR(MapGraphicsGroup) getVariable _graphicsGroupId;
private _graphicsGroup = _y;
if (!isNil "_graphicsGroup") then {
_graphicsGroup params ["_layer", "_timestamp", "_state"];
private _graphicsData = _graphicsGroup select (3 + _state);
Expand Down
2 changes: 1 addition & 1 deletion addons/CLib/MapGraphics/fn_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ with uiNamespace do {
};

//Namespace for Layer
GVAR(MapGraphicsGroup) = call CFUNC(createNamespace);
GVAR(MapGraphicsGroup) = createHashMap;

//Render Cache
GVAR(MapGraphicsCacheBuildFlag) = 0; // Should be incremented for each rebuild
Expand Down
Loading

0 comments on commit 3a6a2ca

Please sign in to comment.