Minor performance tweaks (#5796)

* Medical_ai - Optimize 'fnc_isInjured'
* Laserpointer - Optimize 'fnc_onDraw'
* Overheating - Skip ground detection if possible
* Overheating - Replace function call with inline code
* Overheating - Nest 'firedEH' abort conditions
* Overheating - Remove duplicate code / Skip function call if possible
* Overheating - Cache energy increment
This commit is contained in:
ulteq 2017-11-23 11:13:58 +01:00 committed by GitHub
parent f0036847bc
commit 5ee1df424d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 84 deletions

View File

@ -15,8 +15,7 @@
*/
#include "script_component.hpp"
// no lasers in thermal mode
if !(GVAR(isTI)) then {
if (count GVAR(redLaserUnits) + count GVAR(greenLaserUnits) > 0 && {!GVAR(isTI)}) then {
private _brightness = 2 - call EFUNC(common,ambientBrightness);
{

View File

@ -17,9 +17,4 @@
if !(alive _this) exitWith {false};
private _bloodLoss = [_this] call EFUNC(medical,getBloodLoss);
private _pain = _this getVariable [QEGVAR(medical,pain), 0];
private _unconscious = _this getVariable ["ACE_isUnconscious", false];
// private _heartRate = _this getVariable [QEGVAR(medical,heartRate), 70];
(_bloodLoss > 0) || {_pain > 0.2} || _unconscious // || {_heartRate > 100} || {_heartRate < 40}
((_this getVariable [QEGVAR(medical,pain), 0] > 0.2) || {[_this] call EFUNC(medical,getBloodLoss) > 0 || {_this getVariable ["ACE_isUnconscious", false]}})

View File

@ -20,29 +20,24 @@ TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectil
BEGIN_COUNTER(firedEH);
if ((_unit distance ACE_player) > 3000 //Ignore far away shots
if ((_unit distance ACE_player) > 3000
|| {(_muzzle != (primaryWeapon _unit)) && {_muzzle != (handgunWeapon _unit)}}) exitWith { // Only rifle or pistol muzzles (ignore grenades / GLs)
END_COUNTER(firedEH);
};
// Compute new temperature if the unit is the local player
if (_unit == ACE_player) then {
_this call FUNC(overheat);
};
// Get current temperature from the unit variable
private _temperature = _unit getVariable [format [QGVAR(%1_temp), _weapon], 0];
private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true];
TRACE_2("Unit fired with temp:",_unit,_temperature);
//Get weapon data from cache:
// Get weapon data from cache:
([_weapon] call FUNC(getWeaponData)) params ["_dispersion", "_slowdownFactor", "_jamChance"];
TRACE_4("weapon data from cache",_weapon,_dispersion,_slowdownFactor,_jamChance);
// Dispersion and bullet slow down
if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then {
// Exit if GVAR(pseudoRandomList) isn't synced yet
if (_scaledTemperature > 0.1) then {
// Dispersion and bullet slow down
if (GVAR(overheatingDispersion)) then {
if (isNil QGVAR(pseudoRandomList)) exitWith {ERROR("No pseudoRandomList sync");};
//Dispersion: 0 mils @ 0°C, 0.5 mils @ 333°C, 2.2 mils @ 666°C, 5 mils at 1000°C
@ -58,17 +53,13 @@ if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then {
TRACE_PROJECTILE_INFO(_projectile);
[_projectile, _dispersionX * _dispersion, _dispersionY * _dispersion, _slowdownFactor * vectorMagnitude (velocity _projectile)] call EFUNC(common,changeProjectileDirection);
TRACE_PROJECTILE_INFO(_projectile);
};
};
// Particle Effects
if (GVAR(showParticleEffects)
&& {GVAR(showParticleEffectsForEveryone) || {_unit == ACE_player} || {_unit distance ACE_player <= 20}}
&& {CBA_missionTime > (_unit getVariable [QGVAR(lastDrop), -1000]) + 0.40}) then {
// ------ LOCAL AND NEARBY PLAYERS DEPENDING ON SETTINGS ------------
// Particle effects only apply to the local player and, depending on settings, to other nearby players
if (_unit != ACE_player && (!GVAR(showParticleEffectsForEveryone) || {_unit distance ACE_player > 20})) exitWith {
END_COUNTER(firedEH);
};
//Particle Effects:
if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime > (_unit getVariable [QGVAR(lastDrop), -1000]) + 0.40}) then {
_unit setVariable [QGVAR(lastDrop), CBA_missionTime];
private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25;
@ -91,26 +82,41 @@ if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime >
[0,0,0.15], 100 + random 80, 1.275, 1, 0.025, [0.15,0.43], [[0.6,0.6,0.6,0.5 * _intensity],[0.2,0.2,0.2,0.15 * _intensity]],
[0,1], 1, 0.04, "", "", ""];
};
};
};
// ------ LOCAL PLAYER ONLY ------------
// Only compute jamming for the local player
if (_unit != ACE_player) exitWith {END_COUNTER(firedEH);};
_jamChance = _jamChance * ([[0.5, 1, 2, 8, 20, 150], 5 * _scaledTemperature] call EFUNC(common,interpolateFromArray));
// Compute new temperature once every 3 bullets
if ((_unit ammo _weapon) % 3 == 0) then {
_this call FUNC(overheat);
};
// increase jam chance on dusty grounds if prone (and at ground level)
if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then {
private _value = 5 * _scaledTemperature;
private _array = [0.5, 1, 2, 8, 20, 150];
_jamChance = _jamChance * linearConversion [0, 1, _value % 1, _array select floor _value, _array select ceil _value];
TRACE_3("check for random jam",_unit,_weapon,_jamChance);
private _randomNumber = random 1;
// Fail early if we know that we won't have a malfunction regardless of the ground type.
if (_randomNumber < _jamChance * 2) then {
if (_randomNumber > _jamChance) then {
// Increase jam chance on dusty grounds if prone (and at ground level)
if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then {
private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]);
if (isClass _surface) then {
TRACE_1("dust",getNumber (_surface >> "dust"));
_jamChance = _jamChance + (getNumber (_surface >> "dust")) * _jamChance;
};
};
TRACE_3("check for random jam",_unit,_weapon,_jamChance);
if ((random 1) < _jamChance) then {
};
};
if (_randomNumber < _jamChance) then {
[_unit, _weapon] call FUNC(jamWeapon);
};
};
END_COUNTER(firedEH);

View File

@ -23,27 +23,25 @@
params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"];
TRACE_4("params",_unit,_weapon,_ammo,_projectile);
// Only do heat calculations every 3 bullets
if (((_unit ammo _weapon) % 3) != 0) exitWith {};
BEGIN_COUNTER(overheat);
// Get bullet parameters
private _bulletMass = GVAR(cacheAmmoData) getVariable _ammo;
if (isNil "_bulletMass") then {
private _energyIncrement = GVAR(cacheAmmoData) getVariable _ammo;
if (isNil "_energyIncrement") then {
_bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass");
if (_bulletMass == 0) then {
// If the bullet mass is not configured, estimate it
_bulletMass = 3.4334 + 0.5171 * (getNumber (configFile >> "CfgAmmo" >> _ammo >> "hit") + getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber"));
};
GVAR(cacheAmmoData) setVariable [_ammo, _bulletMass];
};
// Projectile motion is roughly equal to Barrel heat
// Ref: https://en.wikipedia.org/wiki/Physics_of_firearms
// Muzzle Engergy = 1/2 * m * v^2 = (1/2 * 0.001 g/kg * bulletMass (grams) * v^2)
// Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015
private _energyIncrement = 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile);
// Projectile motion is roughly equal to Barrel heat
// Ref: https://en.wikipedia.org/wiki/Physics_of_firearms
// Muzzle Engergy = 1/2 * m * v^2 = (1/2 * 0.001 g/kg * bulletMass (grams) * v^2)
// Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015
private _energyIncrement = 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile);
GVAR(cacheAmmoData) setVariable [_ammo, _energyIncrement];
};
// Increase overheating depending on how obstrusive is the current supressor,
// if any. Typical arma supressors have visibleFire=0.5 and audibleFire=0.3,
@ -64,7 +62,7 @@ if (_silencer != "") then {
_energyIncrement = _energyIncrement * _silencerCoef;
};
TRACE_2("heat",_bulletMass,_energyIncrement);
TRACE_1("heat",_energyIncrement);
[_unit, _weapon, _energyIncrement] call FUNC(updateTemperature);