Config lookup optimization mentioned by johnb432 here: https://github.com/acemod/ACE3/pull/9728#discussion_r1452726505

This commit is contained in:
lambdatiger 2024-01-15 18:47:06 -06:00
parent c4a93c775d
commit b2666fceec
7 changed files with 56 additions and 31 deletions

View File

@ -39,9 +39,10 @@ if (_onlyShotAmmoTypes) then {
]; ];
if (_ammo isEqualTo "" || {_ammo in _allAmmoConfigs}) exitWith {}; if (_ammo isEqualTo "" || {_ammo in _allAmmoConfigs}) exitWith {};
_allAmmoConfigs pushBack _ammo; _allAmmoConfigs pushBack _ammo;
private _subMunit = toLowerANSI getText (configFile >> "cfgAmmo" >> _ammo >> "submunitionAmmo"); private _ammoConfig = configFile >> "cfgAmmo" >> _ammo;
private _subMunit = toLowerANSI getText (_ammoConfig >> "submunitionAmmo");
if (_subMunit isNotEqualTo "") then { if (_subMunit isNotEqualTo "") then {
_subMunit = getArray (configFile >> "cfgAmmo" >> _ammo >> "submunitionAmmo"); _subMunit = getArray (_ammoConfig >> "submunitionAmmo");
for "_i" from 0 to count _subMunit - 1 do { for "_i" from 0 to count _subMunit - 1 do {
if (_i mod 2 == 0) then { if (_i mod 2 == 0) then {
[toLowerANSI (_subMunit#_i)] call _configSearchFunc; [toLowerANSI (_subMunit#_i)] call _configSearchFunc;
@ -57,7 +58,7 @@ if (_onlyShotAmmoTypes) then {
[toLowerANSI getText (_x >> "ammo")] call _configSearchFunc; [toLowerANSI getText (_x >> "ammo")] call _configSearchFunc;
} forEach _allMagazineConfigs; } forEach _allMagazineConfigs;
} else { } else {
_allAmmoConfigs = configProperties [configFile >> "cfgAmmo", "isClass _x && !('ace_frag' in configName _x)", true] apply {configName _x}; _allAmmoConfigs = configProperties [configFile >> "CfgAmmo", "isClass _x && !('ace_frag' in configName _x)", true] apply {configName _x};
}; };
private _processedCfgAmmos = []; private _processedCfgAmmos = [];
@ -67,7 +68,7 @@ private _printCount = 0;
if (_ammo != "" && {!(_ammo in _processedCfgAmmos)}) then { if (_ammo != "" && {!(_ammo in _processedCfgAmmos)}) then {
_processedCfgAmmos pushBack _ammo; _processedCfgAmmos pushBack _ammo;
private _ammoConfig = (configFile >> "cfgAmmo" >> _ammo); private _ammoConfig = (configFile >> "CfgAmmo" >> _ammo);
private _shoulFrag = [_ammo] call FUNC(shouldFrag); private _shoulFrag = [_ammo] call FUNC(shouldFrag);
if (_shoulFrag || _logAll) then { if (_shoulFrag || _logAll) then {

View File

@ -27,10 +27,11 @@ private _ammoInfo = GVAR(fragInfoCache) get _ammo;
if (!isNil "_ammoInfo") exitWith {_ammoInfo}; if (!isNil "_ammoInfo") exitWith {_ammoInfo};
private _ammoConfig = configFile >> "CfgAmmo" >> _ammo;
private _fragTypes = []; private _fragTypes = [];
private _warn = false; private _warn = false;
if (isArray (configFile >> "cfgAmmo" >> _ammo >> QGVAR(CLASSES))) then { if (isArray (_ammoConfig >> QGVAR(CLASSES))) then {
_fragTypes = getArray (configFile >> "cfgAmmo" >> _ammo >> QGVAR(CLASSES)); _fragTypes = getArray (_ammoConfig >> QGVAR(CLASSES));
} else { } else {
_warn = true; _warn = true;
}; };
@ -55,16 +56,35 @@ if (isArray (configFile >> "cfgAmmo" >> _ammo >> QGVAR(CLASSES))) then {
* or 0.8 * _gurneyConstant * sqrt (_chargeMass /(_metalMass + _chargeMass * _geometryCoefficient)); (slightly faster to compute) * or 0.8 * _gurneyConstant * sqrt (_chargeMass /(_metalMass + _chargeMass * _geometryCoefficient)); (slightly faster to compute)
*/ */
private _chargeMass = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(CHARGE)); private _chargeMass = getNumber (_ammoConfig >> QGVAR(CHARGE));
if (_chargeMass == 0) then {_chargeMass = 1; _warn = true;}; if (_chargeMass == 0) then {
private _metalMass = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(METAL)); _chargeMass = 1;
if (_metalMass == 0) then {_metalMass = 2; _warn = true;}; _warn = true;
private _geometryCoefficient = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(GURNEY_K)); };
if (_geometryCoefficient == 0) then {_geometryCoefficient = 0.8; _warn = true;};
private _gurneyConstant = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(GURNEY_C)); private _metalMass = getNumber (_ammoConfig >> QGVAR(METAL));
if (_gurneyConstant == 0) then {_gurneyConstant = 2440; _warn = true;}; if (_metalMass == 0) then {
private _fragCount = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(fragCount)); _metalMass = 2;
if (_fragCount == 0) then {_fragCount = 400; _warn = true;}; _warn = true;
};
private _geometryCoefficient = getNumber (_ammoConfig >> QGVAR(GURNEY_K));
if (_geometryCoefficient == 0) then {
_geometryCoefficient = 0.8;
_warn = true;
};
private _gurneyConstant = getNumber (_ammoConfig >> QGVAR(GURNEY_C));
if (_gurneyConstant == 0) then {
_gurneyConstant = 2440;
_warn = true;
};
private _fragCount = getNumber (_ammoConfig >> QGVAR(fragCount));
if (_fragCount == 0) then {
_fragCount = 400;
_warn = true;
};
if (_warn) then { if (_warn) then {
INFO_1("Ammo class %1 lacks proper explosive properties definitions for frag!",_ammo); INFO_1("Ammo class %1 lacks proper explosive properties definitions for frag!",_ammo);

View File

@ -28,10 +28,11 @@ if (!isNil "_material") exitWith {
_material _material
}; };
// Use 'soundEnviron' or 'soundHit' to extract approx material // Use 'soundEnviron' or 'soundHit' to extract approx material
if (isClass (configFile >> "CfgSurfaces" >> _surfType)) then { private _surfaceConfig = configFile >> "CfgSurfaces" >> _surfType;
_material = getText (configFile >> "CfgSurfaces" >> _surfType >> "soundEnviron"); if (isClass _surfaceConfig) then {
_material = getText (_surfaceConfig >> "soundEnviron");
if (_material isEqualTo "" || {_material isEqualTo "empty"}) then { if (_material isEqualTo "" || {_material isEqualTo "empty"}) then {
_material = getText (configFile >> "CfgSurfaces" >> _surfType >> "soundhit"); _material = getText (_surfaceConfig >> "soundhit");
}; };
} else { // Messy way when a surface isn't added to cfgSurfaces } else { // Messy way when a surface isn't added to cfgSurfaces
private _surfFileText = toLowerANSI preprocessFile _surfType; private _surfFileText = toLowerANSI preprocessFile _surfType;

View File

@ -25,9 +25,10 @@ private _ammoInfo = GVAR(spallInfoCache) get _ammo;
if (!isNil "_ammoInfo") exitWith {_ammoInfo}; if (!isNil "_ammoInfo") exitWith {_ammoInfo};
private _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber"); private _ammoConfig = (configFile >> "CfgAmmo" >> _ammo);
private _explosive = 1 min getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive"); private _caliber = getNumber (_ammoConfig >> "caliber");
private _indirectHit = getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"); private _explosive = 1 min getNumber (_ammoConfig >> "explosive");
private _indirectHit = getNumber (_ammoConfig >> "indirectHitRange");
private _ammoInfo = [_caliber, _explosive, _indirectHit]; private _ammoInfo = [_caliber, _explosive, _indirectHit];
GVAR(spallInfoCache) set [_ammo, _ammoInfo]; GVAR(spallInfoCache) set [_ammo, _ammoInfo];

View File

@ -24,7 +24,7 @@ if (!ADDON) then {
// could improve text parsing of CBA setting string // could improve text parsing of CBA setting string
private _convArray = parseSimpleArray GVAR(blackList); private _convArray = parseSimpleArray GVAR(blackList);
if (count _convArray == 0 ) exitWith { if (_convArray isEqualTo []) exitWith {
TRACE_1("Empty blacklist", _convArray); TRACE_1("Empty blacklist", _convArray);
}; };

View File

@ -24,11 +24,12 @@ if (!isNil "_shouldFrag") exitWith {_shouldFrag};
_shouldFrag = true; _shouldFrag = true;
private _skip = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(skip)); private _ammoConfig = configFile >> "CfgAmmo" >> _ammo;
private _force = getNumber (configFile >> "cfgAmmo" >> _ammo >> QGVAR(force)); private _skip = getNumber (_ammoConfig >> QGVAR(skip));
private _explosive = getNumber (configFile >> "cfgAmmo" >> _ammo >> "explosive"); private _force = getNumber (_ammoConfig >> QGVAR(force));
private _indirectHit = getNumber (configFile >> "cfgAmmo" >> _ammo >> "indirectHit"); private _explosive = getNumber (_ammoConfig >> "explosive");
private _indirectRange = getNumber (configFile >> "cfgAmmo" >> _ammo >> "indirectHitRange"); private _indirectHit = getNumber (_ammoConfig >> "indirectHit");
private _indirectRange = getNumber (_ammoConfig >> "indirectHitRange");
if (_skip == 1 || (_force == 0 && {_explosive < 0.5 || {_indirectHit < 3 if (_skip == 1 || (_force == 0 && {_explosive < 0.5 || {_indirectHit < 3
|| {_indirectRange < 5 && _indirectHit < _indirectRange}}})) then { || {_indirectRange < 5 && _indirectHit < _indirectRange}}})) then {

View File

@ -22,9 +22,10 @@ private _shouldSpall = GVAR(shouldSpallCache) get _ammo;
if (!isNil "_shouldSpall") exitWith {_shouldSpall}; if (!isNil "_shouldSpall") exitWith {_shouldSpall};
private _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber"); private _ammoConfig = configFile >> "CfgAmmo" >> _ammo;
private _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive"); private _caliber = getNumber (_ammoConfig >> "caliber");
private _indirectHit = getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"); private _explosive = getNumber (_ammoConfig >> "explosive");
private _indirectHit = getNumber (_ammoConfig >> "indirectHitRange");
_shouldSpall = _caliber * GVAR(spallIntensity) >= 2.5 || (_explosive >= 0.5 && _explosive * _indirectHit * GVAR(spallIntensity) >= 4); _shouldSpall = _caliber * GVAR(spallIntensity) >= 2.5 || (_explosive >= 0.5 && _explosive * _indirectHit * GVAR(spallIntensity) >= 4);