Skip to content

Commit

Permalink
Replace CBA Namespaces with Hash Maps (#618)
Browse files Browse the repository at this point in the history
* replaced CBA namespaces with hashmaps

* spectate funcitons

* respawn

* ai vehicle bail functions
  • Loading branch information
lambdatiger authored Dec 26, 2024
1 parent cff8057 commit 9770ab2
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 55 deletions.
4 changes: 2 additions & 2 deletions addons/aiVehicleBail/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "script_component.hpp"

GVAR(hitpointTypes) = [false] call CBA_fnc_createNamespace;
GVAR(hitpointTypes) = createHashMap;
{
_x params ["_hitpoints", "_type"];
{
GVAR(hitpointTypes) setVariable [_x, _type];
GVAR(hitpointTypes) set [_x, _type];
} forEach _hitpoints;
} forEach [ENGINE_HITPOINTS, HULL_HITPOINTS, TURRET_HITPOINTS, TRACK_HITPOINTS, WHEEL_HITPOINTS];

Expand Down
2 changes: 1 addition & 1 deletion addons/aiVehicleBail/functions/fnc_handleVehicleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if !(alive _vehicle) exitWith {
};

_hitPoint = toLower _hitPoint;
private _type = GVAR(hitpointTypes) getVariable [_hitPoint, "exit"];
private _type = GVAR(hitpointTypes) getOrDefault [_hitPoint, "exit"];
if (_type == "exit") exitWith {};

private _canMove = _vehicle getVariable[QGVAR(can_move), true];
Expand Down
6 changes: 3 additions & 3 deletions addons/assignGear/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ PREP_RECOMPILE_END;
GVAR(usePotato) = [missionConfigFile >> "CfgLoadouts" >> "usePotato"] call CFUNC(getBool);

if (GVAR(usePotato)) then {
GVAR(loadoutCache) = call CBA_fnc_createNamespace;
GVAR(classnameCache) = call CBA_fnc_createNamespace;
GVAR(magnifiedOpticCache) = call CBA_fnc_createNamespace;
GVAR(loadoutCache) = createHashMap;
GVAR(classnameCache) = createHashMap;
GVAR(magnifiedOpticCache) = createHashMap;

GVAR(allowMagnifiedOptics) = [missionConfigFile >> "CfgLoadouts" >> "allowMagnifiedOptics"] call CFUNC(getBool);
GVAR(allowChangeableOptics) = [missionConfigFile >> "CfgLoadouts" >> "allowChangeableOptics"] call CFUNC(getBool);
Expand Down
8 changes: 3 additions & 5 deletions addons/assignGear/functions/fnc_assignGearMan.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,14 @@ if (!isClass(_path)) exitWith {
private _randomIndex = floor (random GVAR(maxRandomization));
private _loadoutKey = format ["%1:%2", _path, _randomIndex];

private _loadoutArray = GVAR(loadoutCache) getVariable _loadoutKey;

if (isNil "_loadoutArray") then {
private _loadoutArray = GVAR(loadoutCache) getOrDefaultCall [_loadoutKey, {
TRACE_1("compiling new",_loadoutKey);
BEGIN_COUNTER(getLoadoutFromConfig);
_loadoutArray = [_path, _unit] call FUNC(getLoadoutFromConfig);
END_COUNTER(getLoadoutFromConfig);
TRACE_1("",_loadoutArray);
GVAR(loadoutCache) setVariable [_loadoutKey, _loadoutArray];
};
_loadoutArray
}, true];

// set unit loadout overrides our sick shades :(
_loadoutArray set [LA_FACEWARE_INDEX, goggles _unit];
Expand Down
7 changes: 3 additions & 4 deletions addons/assignGear/functions/fnc_cleanPrefix.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ TRACE_1("cleanPrefix",_unitClassname);

if (_unitClassname == "") exitWith {ERROR("_unitClassname is empty string"); _unitClassname };

private _cleanedClassname = GVAR(classnameCache) getVariable _unitClassname;
if (isNil "_cleanedClassname") then { // cache classname lookups
private _cleanedClassname = GVAR(classnameCache) getOrDefaultCall [_unitClassname, {
_cleanedClassname = _unitClassname;
{
private _prefixLength = count _x;
Expand All @@ -32,7 +31,7 @@ if (isNil "_cleanedClassname") then { // cache classname lookups
nil
} count GVAR(prefixes); // count used here for speed, make sure nil is above this line

GVAR(classnameCache) setVariable [_unitClassname, _cleanedClassname];
};
_cleanedClassname;
}, true];

_cleanedClassname
7 changes: 3 additions & 4 deletions addons/assignGear/functions/fnc_isOpticMagnified.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ params [["_opticClassname", "", [""]]];

if (_opticClassname == "") exitWith { ERROR("No optic classname provided"); false };

private _isMagnified = GVAR(magnifiedOpticCache) getVariable _opticClassname;
if (isNil "_isMagnified") then { // cache magnification check
private _isMagnified = GVAR(magnifiedOpticCache) getOrDefaultCall [_opticClassname, {
TRACE_1("Looking up key: ",_opticClassname);
private _minZoom = 999; //FOV, so smaller is more zoomed in

Expand All @@ -33,7 +32,7 @@ if (isNil "_isMagnified") then { // cache magnification check
} count configProperties [configFile >> "CfgWeapons" >> _opticClassname >> "ItemInfo" >> "OpticsModes"]; // count used here for speed, make sure nil is above this line

_isMagnified = _minZoom < MAG_OPTIC_ZOOM_THRESHOLD;
GVAR(magnifiedOpticCache) setVariable [_opticClassname, _isMagnified];
};
_isMagnified;
}, true];

_isMagnified
4 changes: 2 additions & 2 deletions addons/respawn/functions/fnc_addGroup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ if (!isNil QGVAR(currentFaction) && {GVAR(currentFaction) != _factionData}) then
};
GVAR(currentFaction) = _factionData;

(GVAR(factionsToInfo) getVariable _factionData) params [
(GVAR(factionsToInfo) get _factionData) params [
"_factionDisplayName",
"",
"",
"_factionPrefix"
];

(GVAR(groupsToInfo) getVariable _groupData) params [
(GVAR(groupsToInfo) get _groupData) params [
"_groupDisplayName",
"_unitsArray"
];
Expand Down
8 changes: 4 additions & 4 deletions addons/respawn/functions/fnc_readConfigToVariables.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TRACE_1("params",_this);

// parse faction info
GVAR(factionsToInfo) = [] call CBA_fnc_createNamespace;
GVAR(factionsToInfo) = createHashMap;
{
private _infoArray = [];

Expand All @@ -30,14 +30,14 @@ GVAR(factionsToInfo) = [] call CBA_fnc_createNamespace;
_infoArray pushBack ([_x >> "groups"] call CFUNC(getArray));

TRACE_2("Faction info",configName _x,_infoArray);
GVAR(factionsToInfo) setVariable [configName _x, _infoArray]; // possible to override mission side
GVAR(factionsToInfo) set [configName _x, _infoArray]; // possible to override mission side
} forEach (
("true" configClasses (configFile >> "CfgRespawnFactions")) +
("true" configClasses (missionConfigFile >> "CfgRespawnFactions"))
);

// parse group info
GVAR(groupsToInfo) = [] call CBA_fnc_createNamespace;
GVAR(groupsToInfo) = createHashMap;
{
private _infoArray = [];

Expand Down Expand Up @@ -104,7 +104,7 @@ GVAR(groupsToInfo) = [] call CBA_fnc_createNamespace;


TRACE_2("Group info",configName _x,_infoArray);
GVAR(groupsToInfo) setVariable [configName _x, _infoArray]; // possible to override mission side
GVAR(groupsToInfo) set [configName _x, _infoArray]; // possible to override mission side
} forEach (
("isClass (_x >> 'Units') && isClass (_x >> 'Configurations')" configClasses (configFile >> "CfgRespawnGroups")) +
("isClass (_x >> 'Units') && isClass (_x >> 'Configurations')" configClasses (missionConfigFile >> "CfgRespawnGroups"))
Expand Down
4 changes: 2 additions & 2 deletions addons/respawn/functions/fnc_triggerRespawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private _delay = 0;
private _unitCount = { !isNull (_x select 3) } count _newUnits;

if (_unitCount > 0) then {
(GVAR(factionsToInfo) getVariable _factionData) params [
(GVAR(factionsToInfo) get _factionData) params [
"",
"_callsignPrefix",
"_factionClassname",
Expand All @@ -58,7 +58,7 @@ private _delay = 0;

private _factionSide = [getNumber (configFile >> "CfgFactionClasses" >> _factionClassname >> "side")] call EFUNC(core,toSide);

(GVAR(groupsToInfo) getVariable _groupData) params [
(GVAR(groupsToInfo) get _groupData) params [
"_groupDisplayName",
"_unitsArray",
"_configsArray"
Expand Down
16 changes: 8 additions & 8 deletions addons/respawn/functions/fnc_ui_handleAdminLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ ctrlShow [ADMIN_MAP_IDC, false];
[] call FUNC(updateOpenButton);

// get count of players on each faction so we don't respawn on the wrong side
private _allFactions = createHashMap;
{
if (isPlayer _x) then {
private _faction = faction _x;
_allFactions set [_faction, 1 + (_allFactions getOrDefault [_faction, 0])];
};
private _allFactions = createHashMap;
{
if (isPlayer _x) then {
private _faction = faction _x;
_allFactions set [_faction, 1 + (_allFactions getOrDefault [_faction, 0])];
};
} forEach allUnits;

{
(GVAR(factionsToInfo) getVariable _x) params ["_displayName", "", "_factionClassname"];
(GVAR(factionsToInfo) get _x) params ["_displayName", "", "_factionClassname"];
private _count = _allFactions getOrDefault [_factionClassname, 0];
if (_count > 0) then { _displayName = _displayName + format [" [%1]", _count]; };

Expand All @@ -86,7 +86,7 @@ private _allFactions = createHashMap;
lbSetPicture [ADMIN_FACTION_COMBO_IDC, _index, getText (configFile >> "CfgFactionClasses" >> _factionClassname >> "icon")];
};
lbSetData [ADMIN_FACTION_COMBO_IDC, _index, _x];
} forEach (allVariables GVAR(factionsToInfo));
} forEach (keys GVAR(factionsToInfo));

private _factionIndex = if (isNil QGVAR(lastFactionIndex)) then {
0
Expand Down
4 changes: 2 additions & 2 deletions addons/respawn/functions/fnc_ui_handleFactionChange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ GVAR(setupFaction) = _lookUp;
lbClear ADMIN_GROUP_COMBO_IDC;

{
private _index = lbAdd [ADMIN_GROUP_COMBO_IDC, (GVAR(groupsToInfo) getVariable _x) select 0];
private _index = lbAdd [ADMIN_GROUP_COMBO_IDC, (GVAR(groupsToInfo) get _x) select 0];
lbSetData [ADMIN_GROUP_COMBO_IDC, _index, _x];
} forEach ((GVAR(factionsToInfo) getVariable _lookUp) select 4);
} forEach ((GVAR(factionsToInfo) get _lookUp) select 4);

lbSetCurSel [ADMIN_GROUP_COMBO_IDC, 0];
[ADMIN_GROUP_COMBO, 0] call FUNC(ui_handleGroupChange);
2 changes: 1 addition & 1 deletion addons/respawn/functions/fnc_ui_handleGroupChange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TRACE_1("params",_this);
params ["", "_index"];

private _lookUp = lbData [ADMIN_GROUP_COMBO_IDC, _index];
(GVAR(groupsToInfo) getVariable _lookUp) params ["", "_units", "_configurations"];
(GVAR(groupsToInfo) get _lookUp) params ["", "_units", "_configurations"];

// agressively look ahead into the units for a leader marker/color
private _unitMarkerColor = [0,0,0,0];
Expand Down
10 changes: 2 additions & 8 deletions addons/spectate/XEH_postClientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ if (GVAR(enabled) && hasInterface) then {
GVAR(availableLanguages) = (missionNamespace getVariable [QEGVAR(radios,availableLanguages), []]) apply {_x select 0};
GVAR(classEHInstalled) = false;

GVAR(boundingBoxCache) = call CBA_fnc_createNamespace;
GVAR(groupIconCache) = call CBA_fnc_createNamespace;

// populate group icon cache
{
_x params ["_key", "_value"];
GVAR(groupIconCache) setVariable [_key, _value];
} forEach [
GVAR(boundingBoxCache) = createHashMap;
GVAR(groupIconCache) = createHashMapFromArray [
[QPATHTOEF(markers,data\armor.paa), QPATHTOF(data\armor.paa)],
[QPATHTOEF(markers,data\artillery.paa), QPATHTOF(data\artillery.paa)],
[QPATHTOEF(markers,data\attack_fixed_wing.paa), QPATHTOF(data\attack_fixed_wing.paa)],
Expand Down
8 changes: 3 additions & 5 deletions addons/spectate/functions/fnc_getBoundingBox.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ params [["_object", objNull, [objNull]]];
if (isNull _object) exitWith { [1,1,1] };

private _objectType = typeOf _object;
private _cachedValue = GVAR(boundingBoxCache) getVariable _objectType;

if (isNil "_cachedValue") then {
private _cachedValue = GVAR(boundingBoxCache) getOrDefaultCall [_objectType, {
(boundingBoxReal _object) params ["_p1", "_p2"];
_cachedValue = [
abs ((_p2 select 0) - (_p1 select 0)), // max width
abs ((_p2 select 1) - (_p1 select 1)), // max length
abs ((_p2 select 2) - (_p1 select 2)) // max height
];

GVAR(boundingBoxCache) setVariable [_objectType, _cachedValue];
};
_cachedValue;
}, true];

_cachedValue
5 changes: 1 addition & 4 deletions addons/spectate/functions/fnc_getGroupIcon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ if (isNil "_cachedValue") then {
}
};

_cachedValue = GVAR(groupIconCache) getVariable _lookup;
if (isNil "_cachedValue") then {
_cachedValue = DEFAULT_TEXTURE;
};
_cachedValue = GVAR(groupIconCache) getOrDefault [_lookup, DEFAULT_TEXTURE, true];

_group setVariable [QGVAR(markerTexture), _cachedValue];
};
Expand Down

0 comments on commit 9770ab2

Please sign in to comment.