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,76 +20,68 @@ 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];
TRACE_2("Unit fired with temp:",_unit,_temperature); 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"]; ([_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);
// Dispersion and bullet slow down if (_scaledTemperature > 0.1) then {
if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then { // Dispersion and bullet slow down
// Exit if GVAR(pseudoRandomList) isn't synced yet if (GVAR(overheatingDispersion)) then {
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
_dispersion = _dispersion * 0.28125 * (_scaledTemperature^2); _dispersion = _dispersion * 0.28125 * (_scaledTemperature^2);
_slowdownFactor = _slowdownFactor * linearConversion [0.666, 1, _scaledTemperature, 0, -0.1, true]; _slowdownFactor = _slowdownFactor * linearConversion [0.666, 1, _scaledTemperature, 0, -0.1, true];
// Get the pseudo random values for dispersion from the remaining ammo count // Get the pseudo random values for dispersion from the remaining ammo count
(GVAR(pseudoRandomList) select ((_unit ammo _weapon) mod (count GVAR(pseudoRandomList)))) params ["_dispersionX", "_dispersionY"]; (GVAR(pseudoRandomList) select ((_unit ammo _weapon) mod (count GVAR(pseudoRandomList)))) params ["_dispersionX", "_dispersionY"];
TRACE_4("change",_dispersion,_slowdownFactor,_dispersionX,_dispersionY); TRACE_4("change",_dispersion,_slowdownFactor,_dispersionX,_dispersionY);
TRACE_PROJECTILE_INFO(_projectile); TRACE_PROJECTILE_INFO(_projectile);
[_projectile, _dispersionX * _dispersion, _dispersionY * _dispersion, _slowdownFactor * vectorMagnitude (velocity _projectile)] call EFUNC(common,changeProjectileDirection); [_projectile, _dispersionX * _dispersion, _dispersionY * _dispersion, _slowdownFactor * vectorMagnitude (velocity _projectile)] call EFUNC(common,changeProjectileDirection);
TRACE_PROJECTILE_INFO(_projectile); TRACE_PROJECTILE_INFO(_projectile);
};
// ------ 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;
private _position = (position _projectile) vectorAdd (_direction vectorMultiply (4*(random 0.30)));
// Refract SFX, beginning at temp 100°C and maxs out at 500°C
private _intensity = linearConversion [0.1, 0.5, _scaledTemperature, 0, 1, true];
TRACE_3("refract",_direction,_position,_intensity);
if (_intensity > 0) then {
drop [
"\A3\data_f\ParticleEffects\Universal\Refract", "", "Billboard", 10, 2, _position, _direction, 0, 1.2, 1.0,
0.1, [0.10,0.25], [[0.6,0.6,0.6,0.3 * _intensity],[0.2,0.2,0.2,0.05 * _intensity]], [0,1], 0.1, 0.05, "", "", ""];
}; };
// Smoke SFX, beginning at temp 150°C
private _intensity = linearConversion [0.15, 1, _scaledTemperature, 0, 1, true]; // Particle Effects
TRACE_3("smoke",_direction,_position,_intensity); if (GVAR(showParticleEffects)
if (_intensity > 0) then { && {GVAR(showParticleEffectsForEveryone) || {_unit == ACE_player} || {_unit distance ACE_player <= 20}}
drop [ && {CBA_missionTime > (_unit getVariable [QGVAR(lastDrop), -1000]) + 0.40}) then {
["\A3\data_f\ParticleEffects\Universal\Universal", 16, 12, 1, 16], "", "Billboard", 10, 1.2, _position,
[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]], _unit setVariable [QGVAR(lastDrop), CBA_missionTime];
[0,1], 1, 0.04, "", "", ""];
private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25;
private _position = (position _projectile) vectorAdd (_direction vectorMultiply (4*(random 0.30)));
// Refract SFX, beginning at temp 100°C and maxs out at 500°C
private _intensity = linearConversion [0.1, 0.5, _scaledTemperature, 0, 1, true];
TRACE_3("refract",_direction,_position,_intensity);
if (_intensity > 0) then {
drop [
"\A3\data_f\ParticleEffects\Universal\Refract", "", "Billboard", 10, 2, _position, _direction, 0, 1.2, 1.0,
0.1, [0.10,0.25], [[0.6,0.6,0.6,0.3 * _intensity],[0.2,0.2,0.2,0.05 * _intensity]], [0,1], 0.1, 0.05, "", "", ""];
};
// Smoke SFX, beginning at temp 150°C
private _intensity = linearConversion [0.15, 1, _scaledTemperature, 0, 1, true];
TRACE_3("smoke",_direction,_position,_intensity);
if (_intensity > 0) then {
drop [
["\A3\data_f\ParticleEffects\Universal\Universal", 16, 12, 1, 16], "", "Billboard", 10, 1.2, _position,
[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, "", "", ""];
};
}; };
}; };
@ -97,20 +89,34 @@ if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime >
// 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;
if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then { private _array = [0.5, 1, 2, 8, 20, 150];
private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]); _jamChance = _jamChance * linearConversion [0, 1, _value % 1, _array select floor _value, _array select ceil _value];
if (isClass _surface) then {
TRACE_1("dust",getNumber (_surface >> "dust")); TRACE_3("check for random jam",_unit,_weapon,_jamChance);
_jamChance = _jamChance + (getNumber (_surface >> "dust")) * _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;
};
};
};
if (_randomNumber < _jamChance) then {
[_unit, _weapon] call FUNC(jamWeapon);
}; };
}; };
TRACE_3("check for random jam",_unit,_weapon,_jamChance);
if ((random 1) < _jamChance) then {
[_unit, _weapon] call FUNC(jamWeapon);
};
END_COUNTER(firedEH); END_COUNTER(firedEH);

View File

@ -23,27 +23,25 @@
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
// 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 GVAR(cacheAmmoData) setVariable [_ammo, _energyIncrement];
// 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);
// 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,
@ -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);