ATragMX - Utilize 'linearConversion' (#5743)

* Improved muzzle velocity table lookup speed
* Improved drag coefficient table lookup speed
This commit is contained in:
ulteq 2017-11-11 20:44:23 +01:00 committed by GitHub
parent 662089a61b
commit 9e11e39eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 26 deletions

View File

@ -28,24 +28,16 @@ private _lookupTableSize = count _lookupTable;
if (_lookupTableSize < 2) exitWith { (GVAR(workingMemory) select 15) };
_lookupTable sort true;
private _lowerIndex = -1;
private _upperIndex = -1;
private _lowerIndex = 0;
private _upperIndex = 1;
for "_index" from 1 to (_lookupTableSize - 1) do {
_upperIndex = _index;
_lowerIndex = _upperIndex - 1;
if (((_lookupTable select _index) select 0) >= _targetRange) exitWith { (GVAR(workingMemory) select 15) };
if (((_lookupTable select _index) select 0) >= _targetRange) exitWith {};
};
private _lowerDistance = (_lookupTable select _lowerIndex) select 0;
private _upperDistance = (_lookupTable select _upperIndex) select 0;
private _lowerC1 = (_lookupTable select _lowerIndex) select 1;
private _upperC1 = (_lookupTable select _upperIndex) select 1;
private _c1 = _lowerC1;
if (_lowerDistance != _upperDistance) then {
private _slope = (_upperC1 - _lowerC1) / (_upperDistance - _lowerDistance);
_c1 = _lowerC1 + (_targetRange - _lowerDistance) * _slope;
};
_c1 = 0.1 max _c1 min 2.0;
(_lookupTable select _lowerIndex) params ["_lowerDistance", "_lowerC1"];
(_lookupTable select _upperIndex) params ["_upperDistance", "_upperC1"];
_c1
(0.1 max (linearConversion [_lowerDistance, _upperDistance, _targetRange, _lowerC1, _upperC1]) min 2.0)

View File

@ -33,24 +33,19 @@ private _lookupTableSize = count _lookupTable;
if (_lookupTableSize < 2) exitWith {};
_lookupTable sort true;
private _lowerIndex = -1;
private _upperIndex = -1;
private _lowerIndex = 0;
private _upperIndex = 1;
for "_index" from 1 to (_lookupTableSize - 1) do {
_upperIndex = _index;
_lowerIndex = _upperIndex - 1;
if (((_lookupTable select _index) select 0) >= GVAR(temperature)) exitWith {};
};
private _lowerTemperature = (_lookupTable select _lowerIndex) select 0;
private _upperTemperature = (_lookupTable select _upperIndex) select 0;
private _lowerMuzzleVelocity = (_lookupTable select _lowerIndex) select 1;
private _upperMuzzleVelocity = (_lookupTable select _upperIndex) select 1;
private _muzzleVelocity = _lowerMuzzleVelocity;
if (_lowerTemperature != _upperTemperature) then {
private _slope = (_upperMuzzleVelocity - _lowerMuzzleVelocity) / (_upperTemperature - _lowerTemperature);
_muzzleVelocity = _lowerMuzzleVelocity + (GVAR(temperature) - _lowerTemperature) * _slope;
};
_muzzleVelocity = 100 max _muzzleVelocity min 1400;
(_lookupTable select _lowerIndex) params ["_lowerDistance", "_lowerMuzzleVelocity"];
(_lookupTable select _upperIndex) params ["_upperDistance", "_upperMuzzleVelocity"];
_muzzleVelocity = 100 max (linearConversion [_lowerDistance, _upperDistance, GVAR(temperature), _lowerMuzzleVelocity, _upperMuzzleVelocity]) min 1400;
if (_muzzleVelocity != GVAR(workingMemory) select 1) then {
GVAR(workingMemory) set [1, _muzzleVelocity];