-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Caching to CBA_fnc_compatibleItems (Cleanup) #268
Changes from 4 commits
971f9bc
bdb3d17
d69a097
94b0c2d
eaf5c7c
0af30e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
/* | ||
Author: Karel Moricky | ||
Enhanced by Robalo | ||
adding Caching by joko // Jonas | ||
|
||
Description: | ||
Return all compatible weapon attachments | ||
|
||
Parameter(s): | ||
0: STRING - weapon class | ||
1: STRING - optional, accessory type: number (101 - muzzle, 201 - optic, 301 - pointer, 302 - bipod) | ||
|
@@ -15,32 +16,46 @@ | |
Examples: | ||
_acclist = ["LMG_Mk200_F"] call CBA_fnc_compatibleItems; | ||
_muzzleacclist = ["LMG_Mk200_F", 101] call CBA_fnc_compatibleItems; | ||
*/ | ||
|
||
*/ | ||
#include "script_component.hpp" | ||
params [["_weapon", "", [""]], ["_typefilter", 0]]; | ||
if (_weapon == "") exitWith {[]}; | ||
|
||
private _cfgWeapon = configfile >> "cfgweapons" >> _weapon; | ||
|
||
if (isClass _cfgWeapon) then { | ||
private _compatibleItems = []; | ||
{ | ||
private _cfgCompatibleItems = _x >> "compatibleItems"; | ||
if (isarray _cfgCompatibleItems) then { | ||
{ | ||
if !(_x in _compatibleItems) then {_compatibleItems pushBack _x;}; | ||
} forEach getArray _cfgCompatibleItems; | ||
} else { | ||
if (isclass _cfgCompatibleItems) then { | ||
if (isNil QGVAR(namespace)) then { | ||
GVAR(namespace) = call CBA_fnc_createNamespace; | ||
}; | ||
private _compatibleItems = GVAR(namespace) getVariable _weapon; | ||
|
||
if (isNil "_compatibleItems") then { | ||
_compatibleItems = []; | ||
private _cfgWeapon = configfile >> "cfgweapons" >> _weapon; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (isClass _cfgWeapon) then { | ||
{ | ||
private _cfgCompatibleItems = _x >> "compatibleItems"; | ||
if (isArray _cfgCompatibleItems) then { | ||
{ | ||
if (getnumber _x > 0 && {!((configname _x) in _compatibleItems)}) then {_compatibleItems pushBack configname _x}; | ||
} foreach configproperties [_cfgCompatibleItems, "isNumber _x"]; | ||
_compatibleItems pushBackUnique _x; | ||
nil | ||
} count (getArray _cfgCompatibleItems); | ||
} else { | ||
if (isClass _cfgCompatibleItems) then { | ||
{ | ||
if ((getnumber _x > 0)) then {_compatibleItems pushBackUnique (configName _x)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nil | ||
} count configproperties [_cfgCompatibleItems, "isNumber _x"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
}; | ||
}; | ||
} foreach configproperties [_cfgWeapon >> "WeaponSlotsInfo","isclass _x"]; | ||
if (_typefilter == 0) then {_compatibleItems} else {[_compatibleItems, {_typefilter == getnumber(configfile>>"cfgweapons">>_x>>"itemInfo">>"type")}] call BIS_fnc_conditionalSelect}; | ||
nil | ||
} count configproperties [_cfgWeapon >> "WeaponSlotsInfo","isclass _x"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
GVAR(namespace) setVariable [_weapon, _compatibleItems]; //save entry in cache | ||
} else { | ||
["'%1' not found in CfgWeapons",_weapon] call bis_fnc_error; | ||
}; | ||
}; | ||
|
||
if (_typefilter == 0) then { //return | ||
_compatibleItems | ||
} else { | ||
["'%1' not found in CfgWeapons",_weapon] call bis_fnc_error; | ||
[] | ||
_compatibleItems select {_typefilter == getNumber(configfile>>"cfgweapons">>_x>>"itemInfo">>"type")}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ----------------------------------------------------------------------------- | ||
// Automatically generated by 'functions_config.rb' | ||
// DO NOT MANUALLY EDIT THIS FILE! | ||
// ----------------------------------------------------------------------------- | ||
|
||
#include "script_component.hpp" | ||
|
||
#define TESTS ["compatibleItems"] | ||
|
||
SCRIPT(test-jr); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
LOG("=== Testing JR ==="); | ||
|
||
{ | ||
call compile preprocessFileLineNumbers format ["\x\cba\addons\jr\test_%1.sqf", _x]; | ||
} forEach TESTS; | ||
|
||
nil; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_compatibleItems); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
LOG('Testing JR Compatible Items'); | ||
|
||
// UNIT TESTS (polar2vect) | ||
private _fn = "CBA_fnc_compatibleItems"; | ||
TEST_DEFINED("CBA_fnc_compatibleItems",""); | ||
|
||
private _result = [] call CBA_fnc_compatibleItems; | ||
private _expected = []; | ||
TEST_DEFINED_AND_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
_result = ["aGunThatDoesNotExist"] call CBA_fnc_compatibleItems; | ||
_expected = []; | ||
TEST_DEFINED_AND_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
_result = [-1] call CBA_fnc_compatibleItems; | ||
_expected = []; | ||
TEST_DEFINED_AND_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
_result = [-1] call CBA_fnc_compatibleItems; | ||
_expected = []; | ||
TEST_DEFINED_AND_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
private _firstResult = ["LMG_Mk200_F"] call CBA_fnc_compatibleItems; | ||
private _cachedResult = ["LMG_Mk200_F"] call CBA_fnc_compatibleItems; | ||
TEST_DEFINED_AND_OP(_firstResult,isEqualTo,_cachedResult,_fn); | ||
|
||
_result = ["LMG_Mk200_F", 99999] call CBA_fnc_compatibleItems; //invalid accesory type | ||
_expected = []; | ||
TEST_DEFINED_AND_OP(_result,isEqualTo,_expected,_fn); | ||
|
||
_result = ["LMG_Mk200_F", 201] call CBA_fnc_compatibleItems; //201 should filter optics | ||
TEST_TRUE("optic_tws_mg" in _result,_fn); | ||
TEST_FALSE("muzzle_snds_h" in _result,_fn); | ||
|
||
nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Caching added by..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:D ok will fix it