Convert while loop to addPerFrameHandler

This commit is contained in:
PabstMirror 2015-01-12 23:12:38 -06:00
parent 72cd691e46
commit c10b12174b
5 changed files with 109 additions and 105 deletions

View File

@ -28,4 +28,11 @@ 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;
0 spawn COMPILE_FILE(nightVision); //ToDo
//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;

View File

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

View File

@ -8,7 +8,6 @@ _weapon = _this select 1;
_ammo = _this select 4;
_magazine = _this select 5;
// if (_this select 0 == vehicle ACE_player && {currentVisionMode (_this select 0) == 1}) then {_this call AGM_NightVision_fnc_blending};
if ((_vehicle != (vehicle ACE_player)) || {(currentVisionMode _vehicle) != 1}) exitWith {};
_player = ACE_player;

View File

@ -0,0 +1,100 @@
//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 {
GVAR(currentMode) = MODE_NVG_ON;
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
};
};
};

View File

@ -1,103 +0,0 @@
//by commy2
#include "script_component.hpp"
private ["_currentVehicle", "_currentTurret", "_currentHMD", "_grainSetting", "_blurSetting"];
_currentView = "";
_currentVehicle = objNull;
_currentTurret = [-1];
_currentHMD = "";
while {true} do {
GVAR(ppEffectFilmGrain) ppEffectEnable false;
GVAR(ppEffectBlur) ppEffectEnable false;
GVAR(ppEffectRadialBlur) ppEffectEnable false;
GVAR(ppEffectNVGBrightness) ppEffectEnable false;
waitUntil {currentVisionMode ACE_player == 1};
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
waitUntil {
// any updates?
if (hmd ACE_player != _currentHMD || {cameraView != _currentView} || {vehicle ACE_player != _currentVehicle} || {!(_currentTurret isEqualTo []) && {ACE_player != _currentVehicle turretUnit _currentTurret}}) then {
_currentHMD = hmd ACE_player;
_currentView = cameraView;
_currentVehicle = vehicle ACE_player;
_currentTurret = [ACE_player] call EFUNC(common,getTurretIndex);
private ["_config", "_fnc_isUsingHMD"];
_config = configFile >> "CfgVehicles" >> typeOf _currentVehicle;
_fnc_isUsingHMD = {
if (_currentView != "GUNNER") exitWith {true}; // asume hmd usage outside of gunner view
if (ACE_player == (driver _currentVehicle)) exitWith {
!("NVG" in getArray (_config >> "ViewOptics" >> "visionMode"));
};
private "_turretConfig";
_turretConfig = [_config, _currentTurret] call EFUNC(core,getTurretConfigPath);
_turretConfig = _turretConfig >> "OpticsIn";
private "_result";
_result = true;
for "_index" from 0 to (count _turretConfig - 1) do {
if ("NVG" in getArray (_turretConfig select _index >> "visionMode")) exitWith {_result = false};
true
};
_result
};
// on foot or in vehicle using hmd
if ((_currentVehicle == ACE_player) || _fnc_isUsingHMD) then {
_grainSetting = getNumber (configFile >> "CfgWeapons" >> _currentHMD >> "ACE_NightVision_grain");
_blurSetting = getNumber (configFile >> "CfgWeapons" >> _currentHMD >> "ACE_NightVision_blur");
_radBlurSetting = getNumber (configFile >> "CfgWeapons" >> _currentHMD >> "ACE_NightVision_radBlur");
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;
// in vehicle and not using hmd
} 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")];
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;
};
};
// Detect if curator interface is open and disable effects
if (!isNull findDisplay 312) then {
GVAR(ppEffectFilmGrain) ppEffectEnable false;
GVAR(ppEffectBlur) ppEffectEnable false;
GVAR(ppEffectRadialBlur) ppEffectEnable false;
GVAR(ppEffectNVGBrightness) ppEffectEnable false;
waitUntil {isNull findDisplay 312};
GVAR(ppEffectFilmGrain) ppEffectEnable true;
GVAR(ppEffectBlur) ppEffectEnable true;
GVAR(ppEffectRadialBlur) ppEffectEnable true;
GVAR(ppEffectNVGBrightness) ppEffectEnable true;
};
currentVisionMode ACE_player != 1
};
};