Single PFEH for wind deflection

This commit is contained in:
PabstMirror 2015-07-22 03:04:54 -05:00
parent 3e420b6bf6
commit 8f18fd7eaa
4 changed files with 57 additions and 31 deletions

View File

@ -3,7 +3,11 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit)); init = QUOTE(call COMPILE_FILE(XEH_preInit));
}; };
}; };
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_FiredBIS_EventHandlers { class Extended_FiredBIS_EventHandlers {
class AllVehicles { class AllVehicles {
class ADDON { class ADDON {

View File

@ -0,0 +1,13 @@
#include "script_component.hpp"
if !(hasInterface) exitWith {};
GVAR(trackedBullets) = [];
["SettingsInitialized", {
//If not enabled, dont't add PFEH
if (!GVAR(enabled)) exitWith {};
[] call FUNC(updateTrajectoryPFH);
}] call EFUNC(common,addEventHandler);

View File

@ -34,6 +34,6 @@ if (!((_bullet isKindOf "BulletBase") || (_bullet isKindOf "GrenadeBase"))) exit
if (_unit distance ACE_player > GVAR(simulationRadius)) exitWith {false}; if (_unit distance ACE_player > GVAR(simulationRadius)) exitWith {false};
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {false}; if (!([_unit] call EFUNC(common,isPlayer))) exitWith {false};
[_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction")] call FUNC(updateTrajectoryPFH); GVAR(trackedBullets) pushBack [_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction")];
true; true;

View File

@ -13,27 +13,31 @@
* *
* Public: No * Public: No
*/ */
#define ENABLE_PERFORMANCE_COUNTERS
#include "script_component.hpp" #include "script_component.hpp"
[{ [{
private ["_args", "_bullet", "_airFriction", "_time", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueSpeed", "_dragRef", "_drag", "_accelRef", "_accel"]; BEGIN_COUNTER(pfeh);
_args = _this select 0; private["_accel", "_accelRef", "_bulletSpeed", "_bulletVelocity", "_deleted", "_deltaT", "_drag", "_dragRef", "_isWind", "_lastTime", "_trueSpeed", "_trueVelocity"];
_bullet = _args select 0;
_airFriction = _args select 1; _lastTime = (_this select 0) select 0;
_time = _args select 2; _deltaT = ACE_time - _lastTime;
(_this select 0) set [0, ACE_time];
_deleted = 0;
_isWind = (vectorMagnitude ACE_wind > 0);
{
_x params ["_bullet", "_airFriction"];
_bulletVelocity = velocity _bullet; _bulletVelocity = velocity _bullet;
_bulletSpeed = vectorMagnitude _bulletVelocity; _bulletSpeed = vectorMagnitude _bulletVelocity;
if (!alive _bullet || ((_bullet isKindOf "BulletBase") && _bulletSpeed < 100)) exitwith { if ((!alive _bullet) || {(_bullet isKindOf "BulletBase") && {_bulletSpeed < 100}}) then {
[_this select 1] call cba_fnc_removePerFrameHandler; GVAR(trackedBullets) deleteAt (_forEachIndex - _deleted);
}; _deleted = _deleted + 1;
} else {
_deltaT = ACE_time - _time; if (_isWind) then {
_args set[2, ACE_time];
if (vectorMagnitude ACE_wind > 0) then {
_trueVelocity = _bulletVelocity vectorDiff ACE_wind; _trueVelocity = _bulletVelocity vectorDiff ACE_wind;
_trueSpeed = vectorMagnitude _trueVelocity; _trueSpeed = vectorMagnitude _trueVelocity;
@ -46,5 +50,10 @@
_bulletVelocity = _bulletVelocity vectorAdd _accel; _bulletVelocity = _bulletVelocity vectorAdd _accel;
}; };
_bullet setVelocity _bulletVelocity; _bullet setVelocity _bulletVelocity;
};
}, GVAR(simulationInterval), [_this select 0, _this select 1, ACE_time]] call CBA_fnc_addPerFrameHandler; } forEach GVAR(trackedBullets);
END_COUNTER(pfeh);
}, GVAR(simulationInterval), [ACE_time]] call CBA_fnc_addPerFrameHandler;