Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gforces - Add ace_setting to only run in aircraft #3705

Merged
merged 2 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions addons/gforces/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ACE_Settings {
class GVAR(enabledFor) {
displayName = CSTRING(enabledFor_displayName);
typeName = "SCALAR";
value = 1;
values[] = {ECSTRING(Common,Disabled), CSTRING(enabledFor_onlyAircraft), ECSTRING(Common,Enabled)};
};
};
2 changes: 1 addition & 1 deletion addons/gforces/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

PREP(addPFEH);
PREP(pfhUpdateGForces);
42 changes: 33 additions & 9 deletions addons/gforces/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@

if (!hasInterface) exitWith {};

// Setup ppEffect
GVAR(GForces_CC) = ppEffectCreate ["ColorCorrections", 4215];
GVAR(GForces_CC) ppEffectEnable true;
GVAR(GForces_CC) ppEffectForceInNVG true;
GVAR(GForces_CC) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[10,10,0,0,0,0.1,0.5]];
GVAR(GForces_CC) ppEffectCommit 0.4;
GVAR(pfID) = -1;

GVAR(lastUpdateTime) = 0;
GVAR(oldVel) = [0,0,0];
["SettingsInitialized", {
TRACE_1("SettingsInitialized eh",GVAR(enabledFor));

[DFUNC(pfhUpdateGForces), 0, []] call CBA_fnc_addPerFrameHandler;
if (GVAR(enabledFor) == 0) exitWith {}; //Module has no effect if enabledFor is "None"
if (GVAR(enabledFor) == 2) exitWith { //PFEH is always on when enabledFor is "All"
[] call FUNC(addPFEH);
TRACE_1("adding perm PFEH",GVAR(pfID));
};

//PFEH only runs when player is in a type "Air" vehicle when enabledFor is "Aircraft"

if ((!isNull (vehicle ACE_player)) && {(vehicle ACE_player) isKindOf "Air"}) then { //"playerVehicleChanged" can happen before "settingInit"
[] call FUNC(addPFEH);
TRACE_1("adding temp PFEH [start in]",GVAR(pfID));
};
["playerVehicleChanged", {
params ["", "_vehicle"];
TRACE_2("playerVehicleChanged",_vehicle,typeOf _vehicle);
if (_vehicle isKindOf "Air") then {
if (GVAR(pfID) == -1) then {
[] call FUNC(addPFEH);
TRACE_1("adding temp PFEH",GVAR(pfID));
};
} else {
if (GVAR(pfID) != -1) then {
TRACE_1("removing temp PFEH",GVAR(pfID));
ppEffectDestroy GVAR(GForces_CC);
[GVAR(pfID)] call CBA_fnc_removePerFrameHandler;
GVAR(pfID) = -1;
};
};
}] call EFUNC(common,addEventHandler);
}] call EFUNC(common,addEventHandler);
29 changes: 29 additions & 0 deletions addons/gforces/functions/fnc_addPFEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Author: KoffeinFlummi and esteldunedain
* Adds the PFEH
*
* Argument:
* None
*
* Return value:
* None
*
* Public: No
*/
#include "script_component.hpp"

//Reset forces array
GVAR(GForces) = [];
GVAR(GForces_Index) = 0;

// Setup ppEffect
GVAR(GForces_CC) = ppEffectCreate ["ColorCorrections", 4215];
GVAR(GForces_CC) ppEffectEnable true;
GVAR(GForces_CC) ppEffectForceInNVG true;
GVAR(GForces_CC) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[10,10,0,0,0,0.1,0.5]];
GVAR(GForces_CC) ppEffectCommit 0.4;

GVAR(lastUpdateTime) = 0;
GVAR(oldVel) = [0,0,0];

GVAR(pfID) = [DFUNC(pfhUpdateGForces), 0, []] call CBA_fnc_addPerFrameHandler;
6 changes: 4 additions & 2 deletions addons/gforces/functions/fnc_pfhUpdateGForces.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*/
#include "script_component.hpp"

EXPLODE_2_PVT(_this,_params,_pfhId);

// Update the g-forces at constant mission time intervals (taking accTime into account)
if ((ACE_time - GVAR(lastUpdateTime)) < INTERVAL) exitWith {};
GVAR(lastUpdateTime) = ACE_time;

if (isNull ACE_player || !(alive ACE_player)) exitWith {};

BEGIN_COUNTER(everyInterval);

private _newVel = velocity (vehicle ACE_player);
private _accel = ((_newVel vectorDiff GVAR(oldVel)) vectorMultiply (1 / INTERVAL)) vectorAdd [0, 0, 9.8];
// Cap maximum G's to +- 10 to avoid g-effects when the update is low fps.
Expand Down Expand Up @@ -91,3 +91,5 @@ if !(ACE_player getVariable ["ACE_isUnconscious", false]) then {
};

GVAR(GForces_CC) ppEffectCommit INTERVAL;

END_COUNTER(everyInterval);
15 changes: 15 additions & 0 deletions addons/gforces/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="gforces">
<Key ID="STR_ACE_gforces_enabledFor_displayName">
<English>Gforces Effects</English>
<German>Gforces Effekte</German>
<Spanish>Efectos Gforces</Spanish>
</Key>
<Key ID="STR_ACE_gforces_enabledFor_onlyAircraft">
<English>Only Aircraft</English>
<German>Nur Luftfahrzeug</German>
<Spanish>Sólo Aeronave</Spanish>
</Key>
</Package>
</Project>