nightvision: use ACE events to replace a PFH

This commit is contained in:
Nicolás Badano 2015-01-16 17:25:30 -03:00
parent 5f1a6c40e3
commit 7c4af1dc17
4 changed files with 82 additions and 116 deletions

View File

@ -3,10 +3,10 @@
if (!hasInterface) exitWith {};
GVAR(ppEffectBlur) = ppEffectCreate ["dynamicBlur", 1234];
GVAR(ppEffectBlur) = ppEffectCreate ["dynamicBlur", 1234];
GVAR(ppEffectBlur) ppEffectForceInNVG true;
GVAR(ppEffectBlur) ppEffectAdjust [0];
GVAR(ppEffectBlur) ppEffectCommit 0;
GVAR(ppEffectBlur) ppEffectAdjust [0];
GVAR(ppEffectBlur) ppEffectCommit 0;
GVAR(ppEffectRadialBlur) = ppEffectCreate ["radialBlur", 1238];
GVAR(ppEffectRadialBlur) ppEffectForceInNVG true;
@ -28,11 +28,10 @@ GVAR(ppEffectMuzzleFlash) ppEffectForceInNVG true;
GVAR(ppEffectMuzzleFlash) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]];
GVAR(ppEffectMuzzleFlash) ppEffectCommit 0;
//Setup global variables for the ppEffectUpdater
GVAR(lastFrameView) = "";
GVAR(lastFrameVehicle) = objNull;
GVAR(lastFrameTurret) = [-1];
GVAR(lastFrameHMD) = "";
GVAR(currentMode) = 0;
[FUNC(updatePPEffectsEachFrame), 0, []] call CBA_fnc_addPerFrameHandler;
// Setup the event handlers
["playerInventoryChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);
["playerVisionModeChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);
["zeusDisplayChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);
["cameraViewChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);
["playerVehicleChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);
["playerTurretChanged", FUNC(updatePPEffects)] call EFUNC(common,addEventHandler);

View File

@ -3,4 +3,4 @@
PREP(blending);
PREP(decreaseNVGBrightness);
PREP(increaseNVGBrightness);
PREP(updatePPEffectsEachFrame);
PREP(updatePPEffects);

View File

@ -0,0 +1,71 @@
//by commy2, PabstMirror and CAA-Picard
#include "script_component.hpp"
private ["_currentVehicle", "_grainSetting", "_blurSetting", "_radBlurSetting", "_config"];
_currentVehicle = vehicle ACE_player;
// If the Zeus display is on or the player has no nightvision
if ((!isNull findDisplay 312) || ((currentVisionMode ACE_player) != 1)) exitWith {
GVAR(ppEffectFilmGrain) ppEffectEnable false;
GVAR(ppEffectBlur) ppEffectEnable false;
GVAR(ppEffectRadialBlur) ppEffectEnable false;
GVAR(ppEffectNVGBrightness) ppEffectEnable false;
};
// The unit has nightvision
_config = configFile >> "CfgVehicles" >> typeOf _currentVehicle;
_hmd = hmd ACE_player;
_cameraView = cameraView;
_turret = [ACE_player] call EFUNC(common,getTurretIndex);
_fnc_isUsingHMD = {
if (_cameraView != "GUNNER") exitWith {true}; // asume hmd usage outside of gunner view
if (ACE_player == (driver _currentVehicle)) exitWith {
!("NVG" in getArray (_config >> "ViewOptics" >> "visionMode"));
};
private ["_result", "_turretConfig", "_turretConfigOpticsIn"];
_result = true;
_turretConfig = [_config, _turret] call EFUNC(common,getTurretConfigPath);
_turretConfigOpticsIn = _turretConfig >> "OpticsIn";
if (isClass _turretConfigOpticsIn) then {
for "_index" from 0 to (count _turretConfig - 1) do {
if ("NVG" in getArray (_turretConfig select _index >> "visionMode")) exitWith {_result = false};
};
} else {
//No OpticsIn usualy means RCWS, still need to test on more vehicles
_result = false;
};
_result
};
if ((_currentVehicle == ACE_player) || _fnc_isUsingHMD) then {
_grainSetting = getNumber (configFile >> "CfgWeapons" >> _hmd >> "ACE_NightVision_grain");
_blurSetting = getNumber (configFile >> "CfgWeapons" >> _hmd >> "ACE_NightVision_blur");
_radBlurSetting = getNumber (configFile >> "CfgWeapons" >> _hmd >> "ACE_NightVision_radBlur");
TRACE_3("New NVG Settings From Player NVG",_grainSetting,_blurSetting,_radBlurSetting)
} else {
_grainSetting = _currentVehicle getVariable ["ACE_NightVision_grain", getNumber (_config >> "ACE_NightVision_grain")];
_blurSetting = _currentVehicle getVariable ["ACE_NightVision_blur", getNumber (_config >> "ACE_NightVision_blur")];
_radBlurSetting = _currentVehicle getVariable ["ACE_NightVision_radBlur", getNumber (_config >> "ACE_NightVision_radBlur")];
TRACE_3("New NVG Settings From Vehicle",_grainSetting,_blurSetting,_radBlurSetting)
};
// Enable the effects
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
// Configure effects parameters
GVAR(ppEffectFilmGrain) ppEffectAdjust [0.25, 2.5, 2.5, _grainSetting, _grainSetting, false];
GVAR(ppEffectFilmGrain) ppEffectCommit 0;
GVAR(ppEffectBlur) ppEffectAdjust [_blurSetting];
GVAR(ppEffectBlur) ppEffectCommit 0;
GVAR(ppEffectRadialBlur) ppEffectAdjust [_radBlurSetting, _radBlurSetting, 0.2, 0.2];
GVAR(ppEffectRadialBlur) ppEffectCommit 0;

View File

@ -1,104 +0,0 @@
//by commy2, PabstMirror
#include "script_component.hpp"
#define MODE_NVG_OFF 0
#define MODE_NVG_ON 1
#define MODE_NVG_ONZEUS 2
_fnc_isUsingHMD = {
if (GVAR(lastFrameView) != "GUNNER") exitWith {true}; // asume hmd usage outside of gunner view
if (ACE_player == (driver _currentVehicle)) exitWith {
!("NVG" in getArray (_config >> "ViewOptics" >> "visionMode"));
};
private ["_result", "_turretConfig", "_turretConfigOpticsIn"];
_result = true;
_turretConfig = [_config, GVAR(lastFrameTurret)] call EFUNC(common,getTurretConfigPath);
_turretConfigOpticsIn = _turretConfig >> "OpticsIn";
if (isClass _turretConfigOpticsIn) then {
for "_index" from 0 to (count _turretConfig - 1) do {
if ("NVG" in getArray (_turretConfig select _index >> "visionMode")) exitWith {_result = false};
};
} else {
//No OpticsIn usualy means RCWS, still need to test on more vehicles
_result = false;
};
_result
};
private ["_currentVehicle", "_grainSetting", "_blurSetting", "_radBlurSetting", "_config"];
_currentVehicle = vehicle ACE_player;
switch (GVAR(currentMode)) do {
case (MODE_NVG_OFF): {
if ((currentVisionMode ACE_player) == 1) then {
GVAR(currentMode) = MODE_NVG_ON;
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
};
};
case (MODE_NVG_ON): {
if ((currentVisionMode ACE_player) == 0) then {
GVAR(currentMode) = MODE_NVG_OFF;
GVAR(ppEffectFilmGrain) ppEffectEnable false;
GVAR(ppEffectBlur) ppEffectEnable false;
GVAR(ppEffectRadialBlur) ppEffectEnable false;
GVAR(ppEffectNVGBrightness) ppEffectEnable false;
};
if (!isNull findDisplay 312) then {
GVAR(currentMode) = MODE_NVG_ONZEUS;
GVAR(ppEffectFilmGrain) ppEffectEnable false;
GVAR(ppEffectBlur) ppEffectEnable false;
GVAR(ppEffectRadialBlur) ppEffectEnable false;
GVAR(ppEffectNVGBrightness) ppEffectEnable false;
} else {
if (((hmd ACE_player) != GVAR(lastFrameHMD)) ||
{cameraView != GVAR(lastFrameView)} ||
{_currentVehicle != GVAR(lastFrameVehicle)} ||
{!(([ACE_player] call EFUNC(common,getTurretIndex)) isEqualTo GVAR(lastFrameTurret))}) then {
GVAR(lastFrameHMD) = hmd ACE_player;
GVAR(lastFrameView) = cameraView;
GVAR(lastFrameVehicle) = _currentVehicle;
GVAR(lastFrameTurret) = [ACE_player] call EFUNC(common,getTurretIndex);
_config = configFile >> "CfgVehicles" >> typeOf _currentVehicle;
if ((_currentVehicle == ACE_player) || _fnc_isUsingHMD) then {
_grainSetting = getNumber (configFile >> "CfgWeapons" >> GVAR(lastFrameHMD) >> "ACE_NightVision_grain");
_blurSetting = getNumber (configFile >> "CfgWeapons" >> GVAR(lastFrameHMD) >> "ACE_NightVision_blur");
_radBlurSetting = getNumber (configFile >> "CfgWeapons" >> GVAR(lastFrameHMD) >> "ACE_NightVision_radBlur");
TRACE_3("New NVG Settings From Player NVG",_grainSetting,_blurSetting,_radBlurSetting)
} else {
_grainSetting = _currentVehicle getVariable ["ACE_NightVision_grain", getNumber (_config >> "ACE_NightVision_grain")];
_blurSetting = _currentVehicle getVariable ["ACE_NightVision_blur", getNumber (_config >> "ACE_NightVision_blur")];
_radBlurSetting = _currentVehicle getVariable ["ACE_NightVision_radBlur", getNumber (_config >> "ACE_NightVision_radBlur")];
TRACE_3("New NVG Settings From Vehicle",_grainSetting,_blurSetting,_radBlurSetting)
};
GVAR(ppEffectFilmGrain) ppEffectAdjust [0.25, 2.5, 2.5, _grainSetting, _grainSetting, false];
GVAR(ppEffectFilmGrain) ppEffectCommit 0;
GVAR(ppEffectBlur) ppEffectAdjust [_blurSetting];
GVAR(ppEffectBlur) ppEffectCommit 0;
GVAR(ppEffectRadialBlur) ppEffectAdjust [_radBlurSetting, _radBlurSetting, 0.2, 0.2];
GVAR(ppEffectRadialBlur) ppEffectCommit 0;
};
};
};
case (MODE_NVG_ONZEUS): {
if (isNull findDisplay 312) then {
if ((currentVisionMode ACE_player) == 0) then {
GVAR(currentMode) = MODE_NVG_OFF;
} else {
GVAR(currentMode) = MODE_NVG_ON;
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
};
};
};
};