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

View File

@ -17,9 +17,4 @@
if !(alive _this) exitWith {false}; if !(alive _this) exitWith {false};
private _bloodLoss = [_this] call EFUNC(medical,getBloodLoss); ((_this getVariable [QEGVAR(medical,pain), 0] > 0.2) || {[_this] call EFUNC(medical,getBloodLoss) > 0 || {_this getVariable ["ACE_isUnconscious", false]}})
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}

View File

@ -20,16 +20,11 @@ TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectil
BEGIN_COUNTER(firedEH); 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) || {(_muzzle != (primaryWeapon _unit)) && {_muzzle != (handgunWeapon _unit)}}) exitWith { // Only rifle or pistol muzzles (ignore grenades / GLs)
END_COUNTER(firedEH); 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 // Get current temperature from the unit variable
private _temperature = _unit getVariable [format [QGVAR(%1_temp), _weapon], 0]; private _temperature = _unit getVariable [format [QGVAR(%1_temp), _weapon], 0];
private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true]; private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true];
@ -40,9 +35,9 @@ TRACE_2("Unit fired with temp:",_unit,_temperature);
([_weapon] call FUNC(getWeaponData)) params ["_dispersion", "_slowdownFactor", "_jamChance"]; ([_weapon] call FUNC(getWeaponData)) params ["_dispersion", "_slowdownFactor", "_jamChance"];
TRACE_4("weapon data from cache",_weapon,_dispersion,_slowdownFactor,_jamChance); TRACE_4("weapon data from cache",_weapon,_dispersion,_slowdownFactor,_jamChance);
if (_scaledTemperature > 0.1) then {
// Dispersion and bullet slow down // Dispersion and bullet slow down
if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then { if (GVAR(overheatingDispersion)) then {
// Exit if GVAR(pseudoRandomList) isn't synced yet
if (isNil QGVAR(pseudoRandomList)) exitWith {ERROR("No pseudoRandomList sync");}; 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 //Dispersion: 0 mils @ 0°C, 0.5 mils @ 333°C, 2.2 mils @ 666°C, 5 mils at 1000°C
@ -60,15 +55,11 @@ if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then {
TRACE_PROJECTILE_INFO(_projectile); 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]; _unit setVariable [QGVAR(lastDrop), CBA_missionTime];
private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25; private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25;
@ -92,14 +83,29 @@ if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime >
[0,1], 1, 0.04, "", "", ""]; [0,1], 1, 0.04, "", "", ""];
}; };
}; };
};
// ------ LOCAL PLAYER ONLY ------------ // ------ LOCAL PLAYER ONLY ------------
// Only compute jamming for the local player // Only compute jamming for the local player
if (_unit != ACE_player) exitWith {END_COUNTER(firedEH);}; 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) 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 { if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then {
private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]); private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]);
if (isClass _surface) then { if (isClass _surface) then {
@ -107,10 +113,10 @@ if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then {
_jamChance = _jamChance + (getNumber (_surface >> "dust")) * _jamChance; _jamChance = _jamChance + (getNumber (_surface >> "dust")) * _jamChance;
}; };
}; };
};
TRACE_3("check for random jam",_unit,_weapon,_jamChance); if (_randomNumber < _jamChance) then {
if ((random 1) < _jamChance) then {
[_unit, _weapon] call FUNC(jamWeapon); [_unit, _weapon] call FUNC(jamWeapon);
}; };
};
END_COUNTER(firedEH); END_COUNTER(firedEH);

View File

@ -23,21 +23,16 @@
params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"]; params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"];
TRACE_4("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); BEGIN_COUNTER(overheat);
// Get bullet parameters // Get bullet parameters
private _bulletMass = GVAR(cacheAmmoData) getVariable _ammo; private _energyIncrement = GVAR(cacheAmmoData) getVariable _ammo;
if (isNil "_bulletMass") then { if (isNil "_energyIncrement") then {
_bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass"); _bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass");
if (_bulletMass == 0) then { if (_bulletMass == 0) then {
// If the bullet mass is not configured, estimate it // If the bullet mass is not configured, estimate it
_bulletMass = 3.4334 + 0.5171 * (getNumber (configFile >> "CfgAmmo" >> _ammo >> "hit") + getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber")); _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 // Projectile motion is roughly equal to Barrel heat
// Ref: https://en.wikipedia.org/wiki/Physics_of_firearms // Ref: https://en.wikipedia.org/wiki/Physics_of_firearms
@ -45,6 +40,9 @@ if (isNil "_bulletMass") then {
// Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015 // 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); private _energyIncrement = 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile);
GVAR(cacheAmmoData) setVariable [_ammo, _energyIncrement];
};
// Increase overheating depending on how obstrusive is the current supressor, // Increase overheating depending on how obstrusive is the current supressor,
// if any. Typical arma supressors have visibleFire=0.5 and audibleFire=0.3, // if any. Typical arma supressors have visibleFire=0.5 and audibleFire=0.3,
// so they produce x2.1 overheating // so they produce x2.1 overheating
@ -64,7 +62,7 @@ if (_silencer != "") then {
_energyIncrement = _energyIncrement * _silencerCoef; _energyIncrement = _energyIncrement * _silencerCoef;
}; };
TRACE_2("heat",_bulletMass,_energyIncrement); TRACE_1("heat",_energyIncrement);
[_unit, _weapon, _energyIncrement] call FUNC(updateTemperature); [_unit, _weapon, _energyIncrement] call FUNC(updateTemperature);