Advanced Ballistics - Minor performance tweaks (#5790)

* Advanced Ballistics - Utilize 'linearConversion'

* Advanced Ballistics - Limit config value boundaries
This commit is contained in:
ulteq 2017-11-22 23:16:17 +01:00 committed by GitHub
parent 7e397b4596
commit 8bc77a7b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 39 deletions

View File

@ -19,20 +19,16 @@
params ["_muzzleVelocityShiftTable", "_temperature"];
// Check if muzzleVelocityShiftTable is Less Than 11 Entrys
// Check if muzzleVelocityShiftTable is less than 11 Entrys
if ((count _muzzleVelocityShiftTable) < 11) exitWith {0};
private _muzzleVelocityShiftTableUpperLimit = _muzzleVelocityShiftTable select 10;
if (isNil "_muzzleVelocityShiftTableUpperLimit") exitWith { 0 };
if (isNil "_muzzleVelocityShiftTableUpperLimit") exitWith {0};
// Find exact data index required for given temperature
private _temperatureIndexFunction = (_temperature + 15) / 5;
private _temperatureIndexFunction = 0 max ((_temperature + 15) / 5) min 10;
// lower and upper data index used for interpolation
private _temperatureIndexA = (0 max (floor(_temperatureIndexFunction))) min 10;
private _temperatureIndexB = (0 max (ceil(_temperatureIndexFunction))) min 10;
// Lower and upper data index used for interpolation
private _temperatureIndexA = floor(_temperatureIndexFunction);
private _temperatureIndexB = ceil(_temperatureIndexFunction);
// Interpolation ratio
private _interpolationRatio = _temperatureIndexFunction - floor(_temperatureIndexFunction);
// Interpolation
(_muzzleVelocityShiftTable select _temperatureIndexA) * (1 - _interpolationRatio) + (_muzzleVelocityShiftTable select _temperatureIndexB) * _interpolationRatio // Return
linearConversion [_temperatureIndexA, _temperatureIndexB, _temperatureIndexFunction, _muzzleVelocityShiftTable select _temperatureIndexA, _muzzleVelocityShiftTable select _temperatureIndexB, true] // Return

View File

@ -19,8 +19,6 @@
*/
#include "script_component.hpp"
scopeName "main";
params ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity"];
TRACE_4("params",_barrelLength,_muzzleVelocityTable,_barrelLengthTable,_muzzleVelocity);
@ -31,7 +29,7 @@ private _muzzleVelocityTableCount = count _muzzleVelocityTable;
private _barrelLengthTableCount = count _barrelLengthTable;
// Exit if tables are different sizes, have no elements or have only one element
if (_muzzleVelocityTableCount != _barrelLengthTableCount || _muzzleVelocityTableCount == 0 || _barrelLengthTableCount == 0) exitWith { 0 };
if (_muzzleVelocityTableCount != _barrelLengthTableCount || _muzzleVelocityTableCount == 0) exitWith { 0 };
if (_muzzleVelocityTableCount == 1) exitWith { (_muzzleVelocityTable select 0) - _muzzleVelocity };
// If we have the precise barrel length value, return result immediately
@ -43,28 +41,15 @@ if (_barrelLength in _barrelLengthTable) exitWith {
if (_barrelLength <= (_barrelLengthTable select 0)) exitWith { (_muzzleVelocityTable select 0) - _muzzleVelocity };
if (_barrelLength >= (_barrelLengthTable select _barrelLengthTableCount - 1)) exitWith { (_muzzleVelocityTable select _barrelLengthTableCount - 1) - _muzzleVelocity };
private _upperDataIndex = -1;
private _lowerDataIndex = -1;
private _upperDataIndex = 0;
private _lowerDataIndex = 1;
// Find closest bordering values for barrel length
{
if (_barrelLength <= _x) then {
if (_barrelLength <= _x) exitWith {
_upperDataIndex = _forEachIndex;
_lowerDataIndex = _upperDataIndex - 1;
breakTo "main";
};
} forEach _barrelLengthTable;
// Worst case scenario
if (_upperDataIndex == -1 || _lowerDataIndex == -1) exitWith {0};
private _lowerBarrelLength = _barrelLengthTable select _lowerDataIndex;
private _upperBarrelLength = _barrelLengthTable select _upperDataIndex;
private _lowerMuzzleVelocity = _muzzleVelocityTable select _lowerDataIndex;
private _upperMuzzleVelocity = _muzzleVelocityTable select _upperDataIndex;
// Calculate interpolation ratio
private _interpolationRatio = [0, (_upperBarrelLength - _barrelLength) / (_upperBarrelLength - _lowerBarrelLength)] select (abs (_lowerBarrelLength - _upperBarrelLength) > 0);
// Calculate interpolated muzzle velocity shift
(_lowerMuzzleVelocity + ((_upperMuzzleVelocity - _lowerMuzzleVelocity) * (1 - _interpolationRatio))) - _muzzleVelocity // Return
(linearConversion [_barrelLengthTable select _lowerDataIndex, _barrelLengthTable select _upperDataIndex, _barrelLength, _muzzleVelocityTable select _lowerDataIndex, _muzzleVelocityTable select _upperDataIndex]) - _muzzleVelocity // Return

View File

@ -102,7 +102,7 @@ if (GVAR(bulletTraceEnabled) && cameraView == "GUNNER") then {
};
private _stabilityFactor = 1.5;
if (_caliber > 0 && _bulletLength > 0 && _bulletMass > 0 && _barrelTwist > 0) then {
if (_caliber * _bulletLength * _bulletMass * _barrelTwist > 0) then {
if (isNil "_temperature") then {
_temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight);
};

View File

@ -32,15 +32,15 @@ TRACE_1("Reading Ammo Config",_this);
private _ammoConfig = configFile >> "CfgAmmo" >> _this;
private _airFriction = getNumber(_ammoConfig >> "airFriction");
private _caliber = getNumber(_ammoConfig >> "ACE_caliber");
private _bulletLength = getNumber(_ammoConfig >> "ACE_bulletLength");
private _bulletMass = getNumber(_ammoConfig >> "ACE_bulletMass");
private _transonicStabilityCoef = getNumber(_ammoConfig >> "ACE_transonicStabilityCoef");
private _caliber = 0 max getNumber(_ammoConfig >> "ACE_caliber");
private _bulletLength = 0 max getNumber(_ammoConfig >> "ACE_bulletLength");
private _bulletMass = 0 max getNumber(_ammoConfig >> "ACE_bulletMass");
private _transonicStabilityCoef = 0 max getNumber(_ammoConfig >> "ACE_transonicStabilityCoef") min 1;
if (_transonicStabilityCoef == 0) then {
_transonicStabilityCoef = 0.5;
};
private _dragModel = getNumber(_ammoConfig >> "ACE_dragModel");
if (_dragModel == 0 || !(_dragModel in [1, 2, 5, 6, 7, 8])) then {
if (!(_dragModel in [1, 2, 5, 6, 7, 8])) then {
_dragModel = 1;
};
private _ballisticCoefficients = getArray(_ammoConfig >> "ACE_ballisticCoefficients");

View File

@ -20,7 +20,7 @@
private _weaponConfig = (configFile >> "CfgWeapons" >> _this);
private _barrelTwist = getNumber(_weaponConfig >> "ACE_barrelTwist");
private _barrelTwist = 0 max getNumber(_weaponConfig >> "ACE_barrelTwist");
private _twistDirection = [0, 1] select (_barrelTwist != 0);
if (isNumber (_weaponConfig >> "ACE_twistDirection")) then {
_twistDirection = getNumber (_weaponConfig >> "ACE_twistDirection");
@ -29,7 +29,7 @@ if (isNumber (_weaponConfig >> "ACE_twistDirection")) then {
};
};
private _barrelLength = getNumber(_weaponConfig >> "ACE_barrelLength");
private _barrelLength = 0 max getNumber(_weaponConfig >> "ACE_barrelLength");
private _result = [_barrelTwist, _twistDirection, _barrelLength];