diff --git a/addons/common/functions/fnc_isFeatureCameraActive.sqf b/addons/common/functions/fnc_isFeatureCameraActive.sqf index b0870408af..2f3cafe35d 100644 --- a/addons/common/functions/fnc_isFeatureCameraActive.sqf +++ b/addons/common/functions/fnc_isFeatureCameraActive.sqf @@ -5,6 +5,7 @@ * - Curator * - ACE Spectator * - Arsenal camera (BIS_fnc_arsenal) + * - Nexus Spectator (BIS_fnc_EGSpectator) * - Establishing shot (BIS_fnc_establishingShot) * - Splendid camera (BIS_fnc_camera) * - Animation viewer (BIS_fnc_animViewer) @@ -26,6 +27,7 @@ !( isNull curatorCamera && // Curator {!(GETMVAR(EGVAR(spectator,isSet),false))} && // ACE Spectator + {isNull (GETMVAR(BIS_EGSpectatorCamera_camera, objNull))} && // BIS Nexus Spectator {isNull (GETUVAR(BIS_fnc_arsenal_cam, objNull))} && // Arsenal camera {isNull (GETMVAR(BIS_fnc_establishingShot_fakeUAV, objNull))} && // Establishing shot camera {isNull (GETMVAR(BIS_fnc_camera_cam, objNull))} && // Splendid camera diff --git a/addons/nightvision/ACE_Settings.hpp b/addons/nightvision/ACE_Settings.hpp index 32dbab7fff..b054bdaaf8 100644 --- a/addons/nightvision/ACE_Settings.hpp +++ b/addons/nightvision/ACE_Settings.hpp @@ -1,8 +1,23 @@ class ACE_Settings { class GVAR(disableNVGsWithSights) { + category = CSTRING(Category); displayName = CSTRING(DisableNVGsWithSights_DisplayName); description = CSTRING(DisableNVGsWithSights_description); typeName = "BOOL"; value = 0; }; + class GVAR(fogScaling) { + category = CSTRING(Category); + displayName = CSTRING(fogScaling_DisplayName); + description = CSTRING(fogScaling_Description); + typeName = "SCALAR"; + value = 1; + }; + class GVAR(effectScaling) { + category = CSTRING(Category); + displayName = CSTRING(effectScaling_DisplayName); + description = CSTRING(effectScaling_Description); + typeName = "SCALAR"; + value = 1; + }; }; diff --git a/addons/nightvision/CfgEventHandlers.hpp b/addons/nightvision/CfgEventHandlers.hpp index 152887a24a..e90bed419e 100644 --- a/addons/nightvision/CfgEventHandlers.hpp +++ b/addons/nightvision/CfgEventHandlers.hpp @@ -1,30 +1,15 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preStart)); }; }; - class Extended_PreInit_EventHandlers { class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preInit) ); + init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; - class Extended_PostInit_EventHandlers { class ADDON { - clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient)); - }; -}; - -class Extended_DisplayLoad_EventHandlers { - class RscDisplayCurator { - ADDON = QUOTE(_this call FUNC(updatePPEffects)); - }; -}; - -class Extended_DisplayUnload_EventHandlers { - class RscDisplayCurator { - ADDON = QUOTE(displayNull call FUNC(updatePPEffects)); // emulate zeus display being deleted + init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; diff --git a/addons/nightvision/CfgVehicles.hpp b/addons/nightvision/CfgVehicles.hpp index cc57d2313a..6b7b04f25d 100644 --- a/addons/nightvision/CfgVehicles.hpp +++ b/addons/nightvision/CfgVehicles.hpp @@ -1,9 +1,4 @@ class CfgVehicles { - class All { - ACE_NightVision_grain = 0.75; - ACE_NightVision_blur = 0.055; - }; - class Box_NATO_Support_F; class ACE_Box_Misc: Box_NATO_Support_F { class TransportItems { diff --git a/addons/nightvision/CfgWeapons.hpp b/addons/nightvision/CfgWeapons.hpp index 72be31d8cf..5d87b0170c 100644 --- a/addons/nightvision/CfgWeapons.hpp +++ b/addons/nightvision/CfgWeapons.hpp @@ -2,55 +2,85 @@ class CfgWeapons { class Binocular; class NVGoggles: Binocular { displayName = CSTRING(NVG_Gen3_brown); - ACE_NightVision_grain = 0.75; - ACE_NightVision_blur = 0.055; - ACE_NightVision_radBlur = 0.001; + modelOptics = ""; + GVAR(border) = QPATHTOF(data\nvg_mask_binos_4096.paa); + GVAR(bluRadius) = 0.15; + }; + class O_NVGoggles_hex_F: NVGoggles { // APEX NVG with multiple lenses (spider eyes) + modelOptics = ""; + GVAR(border) = QPATHTOF(data\nvg_mask_quad_4096.paa); // Use quad tube mask + GVAR(bluRadius) = 0.26; + }; + class NVGogglesB_grn_F: NVGoggles { // APEX NVG/Thermal + modelOptics = "\A3\weapons_f\reticle\optics_night"; // use vanilla modelOptics so it will show in IR mode }; class NVGoggles_OPFOR: NVGoggles { + modelOptics = ""; displayName = CSTRING(NVG_Gen3_black); }; class NVGoggles_INDEP: NVGoggles { + modelOptics = ""; displayName = CSTRING(NVG_Gen3_green); }; - class ACE_NVG_Gen1: NVGoggles_OPFOR { author = ECSTRING(common,ACETeam); - modelOptics = "\A3\weapons_f\reticle\optics_night"; displayName = CSTRING(NVG_Gen1); - ACE_NightVision_grain = 2.25; - ACE_NightVision_blur = 0.22; - ACE_NightVision_radBlur = 0.004; + GVAR(generation) = 1; }; class ACE_NVG_Gen2: NVGoggles_INDEP { author = ECSTRING(common,ACETeam); - modelOptics = "\A3\weapons_f\reticle\optics_night"; displayName = CSTRING(NVG_Gen2); - ACE_NightVision_grain = 1.5; - ACE_NightVision_blur = 0.11; - ACE_NightVision_radBlur = 0.002; + GVAR(generation) = 2; }; - /*class ACE_NVG_Gen3: NVGoggles { - author = ECSTRING(common,ACETeam); - modelOptics = "\A3\weapons_f\reticle\optics_night"; - displayName = CSTRING(NVG_Gen3); - ACE_NightVision_grain = 0.75; - ACE_NightVision_blur = 0.055; - ACE_NightVision_radBlur = 0.001; -};*/ class ACE_NVG_Gen4: NVGoggles { author = ECSTRING(common,ACETeam); - modelOptics = "\A3\weapons_f\reticle\optics_night"; displayName = CSTRING(NVG_Gen4); - ACE_NightVision_grain = 0.0; - ACE_NightVision_blur = 0.0; - ACE_NightVision_radBlur = 0.0; + GVAR(generation) = 4; }; class ACE_NVG_Wide: NVGoggles { author = ECSTRING(common,ACETeam); modelOptics = QPATHTOF(models\ACE_nvg_wide_optics); displayName = CSTRING(NVG_FullScreen); - ACE_NightVision_grain = 0.75; - ACE_NightVision_blur = 0.055; - ACE_NightVision_radBlur = 0.001; + }; + + + // Examples of different goggle effect types (scope=1) + // These all function differently, but we have no models to go with them + class ACE_NVG_Biocular: NVGoggles { + scope = 1; + modelOptics = ""; + author = ECSTRING(common,ACETeam); + descriptionShort = "Biocular nightvision goggles"; + displayName = "NV Goggles (Bio)"; + GVAR(border) = QPATHTOF(data\nvg_mask_4096.paa); + GVAR(bluRadius) = 0.13; + GVAR(eyeCups) = 1; + }; + class ACE_NVG_Monocular: NVGoggles { + scope = 1; + modelOptics = ""; + author = ECSTRING(common,ACETeam); + descriptionShort = "Monocular nightvision goggles"; + displayName = "NV Goggles (Mono)"; + GVAR(border) = QPATHTOF(data\nvg_mask_4096.paa); + GVAR(bluRadius) = 0.13; + }; + class ACE_NVG_Binocular: NVGoggles { + scope = 1; + modelOptics = ""; + author = ECSTRING(common,ACETeam); + descriptionShort = "Binocular nightvision goggles"; + displayName = "NV Goggles (Bino)"; + GVAR(border) = QPATHTOF(data\nvg_mask_binos_4096.paa); + GVAR(bluRadius) = 0.15; + }; + class ACE_NVG_Quadocular: NVGoggles { + scope = 1; + modelOptics = ""; + author = ECSTRING(common,ACETeam); + descriptionShort = "Quadocular nightvision goggles"; + displayName = "NV Goggles (Quad)"; + GVAR(border) = QPATHTOF(data\nvg_mask_quad_4096.paa); + GVAR(bluRadius) = 0.26; }; }; diff --git a/addons/nightvision/RscTitles.hpp b/addons/nightvision/RscTitles.hpp new file mode 100644 index 0000000000..98c2b11cb3 --- /dev/null +++ b/addons/nightvision/RscTitles.hpp @@ -0,0 +1,41 @@ +class RscPicture; +class RscText; + +class RscTitles { + class GVAR(title) { + idd = 10777; + movingEnable = 1; + enableSimulation = 1; + enableDisplay = 1; + + onLoad = QUOTE(with uiNamespace do {GVAR(titleDisplay) = _this select 0};); + onunLoad = ""; + + duration = 999999; + fadein = 0; + fadeout = 0; + + class controls { + class Hexes: RscPicture { + idc = 1000; + }; + class Mask: RscPicture { + idc = 1001; + }; + + // Add blinders for side monitors for tripple monitors (mask won't cover them) + class trippleHeadLeft: RscPicture { + idc = 1002; + text = "#(argb,8,8,3)color(0,0,0,1)"; + x = "safeZoneXAbs"; + Y = "safezoneY"; + W = "(safezoneX - safeZoneXAbs) * ((getResolution select 4)/(16/3))"; + H = "safeZoneH"; + }; + class trippleHeadRight: trippleHeadLeft { + idc = 1003; + x = "safeZoneXAbs + safeZoneWAbs - (safezoneX - safeZoneXABS) * ((getResolution select 4)/(16/3))"; + }; + }; + }; +}; diff --git a/addons/nightvision/XEH_PREP.hpp b/addons/nightvision/XEH_PREP.hpp index 251c8cc5dd..c212d22b18 100644 --- a/addons/nightvision/XEH_PREP.hpp +++ b/addons/nightvision/XEH_PREP.hpp @@ -1,7 +1,12 @@ -PREP(blending); PREP(changeNVGBrightness); PREP(initModule); +PREP(nonDedicatedFix); PREP(onCameraViewChanged); +PREP(onFiredPlayer); +PREP(onLoadoutChanged); PREP(onVisionModeChanged); -PREP(updatePPEffects); +PREP(pfeh); +PREP(refreshGoggleType); +PREP(scaleCtrl); +PREP(setupDisplayEffects); diff --git a/addons/nightvision/XEH_postInit.sqf b/addons/nightvision/XEH_postInit.sqf new file mode 100644 index 0000000000..0911b13a6e --- /dev/null +++ b/addons/nightvision/XEH_postInit.sqf @@ -0,0 +1,94 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +GVAR(PFID) = -1; +GVAR(running) = false; +GVAR(nextEffectsUpdate) = -1; + +GVAR(playerHMD) = "#"; + +GVAR(priorFog) = nil; +GVAR(nvgFog) = [0,0,0]; + +GVAR(nvgBlurRadius) = -1; +GVAR(nvgGeneration) = -1; +GVAR(defaultPositionBorder) = []; +GVAR(defaultPositionHex) = []; + +GVAR(ppeffectGrain) = -1; +GVAR(ppeffectRadialBlur) = -1; +GVAR(ppeffectColorCorrect) = -1; +GVAR(ppeffectBlur) = -1; +GVAR(ppEffectCCMuzzleFlash) = -1; + + +["ace_settingsInitialized", { + TRACE_3("settingsInitialized",GVAR(disableNVGsWithSights),GVAR(fogScaling),GVAR(effectScaling)); + + // Disable ALL effects if ace_nightvision_effectScaling is zero + if (GVAR(effectScaling) == 0) exitWith {}; + + ["loadout", LINKFUNC(onLoadoutChanged), true] call CBA_fnc_addPlayerEventHandler; + ["visionMode", LINKFUNC(onVisionModeChanged), false] call CBA_fnc_addPlayerEventHandler; + ["cameraView", LINKFUNC(onCameraViewChanged), true] call CBA_fnc_addPlayerEventHandler; + ["vehicle", LINKFUNC(refreshGoggleType), false] call CBA_fnc_addPlayerEventHandler; + ["turret", LINKFUNC(refreshGoggleType), true] call CBA_fnc_addPlayerEventHandler; + + ["ace_firedPlayer", LINKFUNC(onFiredPlayer)] call CBA_fnc_addEventHandler; + ["ace_firedPlayerVehicle", LINKFUNC(onFiredPlayer)] call CBA_fnc_addEventHandler; + + + addMissionEventHandler ["Loaded", { // Restart UI vars on mission load + if (GVAR(running)) then { + TRACE_1("restarting effects",CBA_missionTime); + [false] call FUNC(setupDisplayEffects); + [true] call FUNC(setupDisplayEffects); + }; + }]; +}] call CBA_fnc_addEventHandler; + + +// Handle an edge case for non-dedicated servers were the server running the fog effect would sync fog to other clients +[QGVAR(nonDedicatedFix), LINKFUNC(nonDedicatedFix)] call CBA_fnc_addEventHandler; +if (!isNil QGVAR(serverPriorFog)) then {[] call FUNC(nonDedicatedFix);}; // If var is defined, run it now (we must be a jip) + + +// Add keybinds +["ACE3 Equipment", QGVAR(IncreaseNVGBrightness), localize LSTRING(IncreaseNVGBrightness), { + // Conditions: canInteract + if !([ACE_player, objNull, ["isNotEscorting", "isNotInside", "isNotSitting", "isNotRefueling"]] call EFUNC(common,canInteractWith)) exitWith {false}; + // Conditions: specific + if ((currentVisionMode ACE_player != 1)) exitWith {false}; + + // Statement + [ACE_player, 1] call FUNC(changeNVGBrightness); + true +}, {false}, [201, [false, false, true]], false] call CBA_fnc_addKeybind; //PageUp + ALT + +["ACE3 Equipment", QGVAR(DecreaseNVGBrightness), localize LSTRING(DecreaseNVGBrightness), { + // Conditions: canInteract + if !([ACE_player, objNull, ["isNotEscorting", "isNotInside", "isNotSitting", "isNotRefueling"]] call EFUNC(common,canInteractWith)) exitWith {false}; + // Conditions: specific + if ((currentVisionMode ACE_player != 1)) exitWith {false}; + + // Statement + [ACE_player, -1] call FUNC(changeNVGBrightness); + true +}, {false}, [209, [false, false, true]], false] call CBA_fnc_addKeybind; //PageDown + ALT + +#ifdef DEBUG_MODE_FULL +WARNING("Debug mouse wheel action enabled, this should NOT be in a final release"); +["MouseZChanged", { + GVAR(nextEffectsUpdate) = 0; + if (cba_events_shift) then { + GVAR(effectScaling) = ((GVAR(effectScaling) + ((_this select 1) / 20)) max 0) min 1; + systemChat format ["%1: %2", QGVAR(effectScaling), GVAR(effectScaling)]; + }; + if (cba_events_control) then { + GVAR(fogScaling) = ((GVAR(fogScaling) + ((_this select 1) / 20)) max 0) min 1; + systemChat format ["%1: %2", QGVAR(fogScaling), GVAR(fogScaling)]; + }; +}] call CBA_fnc_addDisplayHandler; +#endif + diff --git a/addons/nightvision/XEH_postInitClient.sqf b/addons/nightvision/XEH_postInitClient.sqf deleted file mode 100644 index bbc31d2b74..0000000000 --- a/addons/nightvision/XEH_postInitClient.sqf +++ /dev/null @@ -1,65 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -if (!hasInterface) exitWith {}; - -GVAR(ppEffectBlur) = ppEffectCreate ["dynamicBlur", 1234]; -GVAR(ppEffectBlur) ppEffectForceInNVG true; -GVAR(ppEffectBlur) ppEffectAdjust [0]; -GVAR(ppEffectBlur) ppEffectCommit 0; - -GVAR(ppEffectRadialBlur) = ppEffectCreate ["radialBlur", 1238]; -GVAR(ppEffectRadialBlur) ppEffectForceInNVG true; -GVAR(ppEffectRadialBlur) ppEffectAdjust [0, 0, 0, 0]; -GVAR(ppEffectRadialBlur) ppEffectCommit 0; - -GVAR(ppEffectFilmGrain) = ppEffectCreate ["FilmGrain", 1235]; -GVAR(ppEffectFilmGrain) ppEffectAdjust [0.25, 2.5, 2.5, 2.5*0.3, 2.5*0.3, false]; -GVAR(ppEffectFilmGrain) ppEffectCommit 0; - -GVAR(ppEffectNVGBrightness) = ppEffectCreate ["ColorCorrections", 1236]; -GVAR(ppEffectNVGBrightness) ppEffectForceInNVG true; -GVAR(ppEffectNVGBrightness) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; -GVAR(ppEffectNVGBrightness) ppEffectCommit 0; - -GVAR(ppEffectMuzzleFlash) = ppEffectCreate ["ColorCorrections", 1237]; -GVAR(ppEffectMuzzleFlash) ppEffectEnable true; -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 the event handlers -["loadout", FUNC(updatePPEffects)] call CBA_fnc_addPlayerEventHandler; -["visionMode", FUNC(updatePPEffects)] call CBA_fnc_addPlayerEventHandler; -["visionMode", FUNC(onVisionModeChanged)] call CBA_fnc_addPlayerEventHandler; -["cameraView", FUNC(updatePPEffects)] call CBA_fnc_addPlayerEventHandler; -["cameraView", FUNC(onCameraViewChanged)] call CBA_fnc_addPlayerEventHandler; -["vehicle", FUNC(updatePPEffects)] call CBA_fnc_addPlayerEventHandler; -["turret", FUNC(updatePPEffects)] call CBA_fnc_addPlayerEventHandler; - -// Add keybinds -["ACE3 Equipment", QGVAR(IncreaseNVGBrightness), localize LSTRING(IncreaseNVGBrightness), { - // Conditions: canInteract - if !([ACE_player, objNull, ["isNotEscorting", "isNotInside", "isNotSitting", "isNotRefueling"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if ((currentVisionMode ACE_player != 1)) exitWith {false}; - - // Statement - [ACE_player, 1] call FUNC(changeNVGBrightness); - true -}, {false}, [201, [false, false, true]], false] call CBA_fnc_addKeybind; //PageUp + ALT - -["ACE3 Equipment", QGVAR(DecreaseNVGBrightness), localize LSTRING(DecreaseNVGBrightness), { - // Conditions: canInteract - if !([ACE_player, objNull, ["isNotEscorting", "isNotInside", "isNotSitting", "isNotRefueling"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - if ((currentVisionMode ACE_player != 1)) exitWith {false}; - - // Statement - [ACE_player, -1] call FUNC(changeNVGBrightness); - true -}, {false}, [209, [false, false, true]], false] call CBA_fnc_addKeybind; //PageDown + ALT - -// Register fire event handler -["ace_firedPlayer", DFUNC(blending)] call CBA_fnc_addEventHandler; -["ace_firedPlayerVehicle", DFUNC(blending)] call CBA_fnc_addEventHandler; diff --git a/addons/nightvision/config.cpp b/addons/nightvision/config.cpp index 673a7d31c0..8e33002c31 100644 --- a/addons/nightvision/config.cpp +++ b/addons/nightvision/config.cpp @@ -18,3 +18,4 @@ class CfgPatches { #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" #include "ACE_Settings.hpp" +#include "RscTitles.hpp" diff --git a/addons/nightvision/data/nvg_mask_2048.paa b/addons/nightvision/data/nvg_mask_2048.paa new file mode 100644 index 0000000000..93913fc08c Binary files /dev/null and b/addons/nightvision/data/nvg_mask_2048.paa differ diff --git a/addons/nightvision/data/nvg_mask_4096.paa b/addons/nightvision/data/nvg_mask_4096.paa new file mode 100644 index 0000000000..24d83ef648 Binary files /dev/null and b/addons/nightvision/data/nvg_mask_4096.paa differ diff --git a/addons/nightvision/data/nvg_mask_binos_2048.paa b/addons/nightvision/data/nvg_mask_binos_2048.paa new file mode 100644 index 0000000000..b3f6e2525f Binary files /dev/null and b/addons/nightvision/data/nvg_mask_binos_2048.paa differ diff --git a/addons/nightvision/data/nvg_mask_binos_4096.paa b/addons/nightvision/data/nvg_mask_binos_4096.paa new file mode 100644 index 0000000000..4a208090f4 Binary files /dev/null and b/addons/nightvision/data/nvg_mask_binos_4096.paa differ diff --git a/addons/nightvision/data/nvg_mask_hexes.paa b/addons/nightvision/data/nvg_mask_hexes.paa new file mode 100644 index 0000000000..f81514b074 Binary files /dev/null and b/addons/nightvision/data/nvg_mask_hexes.paa differ diff --git a/addons/nightvision/data/nvg_mask_hexes_thin.paa b/addons/nightvision/data/nvg_mask_hexes_thin.paa new file mode 100644 index 0000000000..57fed1ccb0 Binary files /dev/null and b/addons/nightvision/data/nvg_mask_hexes_thin.paa differ diff --git a/addons/nightvision/data/nvg_mask_quad_2048.paa b/addons/nightvision/data/nvg_mask_quad_2048.paa new file mode 100644 index 0000000000..43df98c333 Binary files /dev/null and b/addons/nightvision/data/nvg_mask_quad_2048.paa differ diff --git a/addons/nightvision/data/nvg_mask_quad_4096.paa b/addons/nightvision/data/nvg_mask_quad_4096.paa new file mode 100644 index 0000000000..3449bc8e7a Binary files /dev/null and b/addons/nightvision/data/nvg_mask_quad_4096.paa differ diff --git a/addons/nightvision/functions/fnc_blending.sqf b/addons/nightvision/functions/fnc_blending.sqf deleted file mode 100644 index 4a858838d3..0000000000 --- a/addons/nightvision/functions/fnc_blending.sqf +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Author: commy2 - * Change the blending when the player fires??. Called from the unified fired EH only for the local player and his vehicle. - * - * Arguments: - * None. Parameters inherited from EFUNC(common,firedEH) - * - * Return Value: - * Noneg - * - * Example: - * [clientFiredBIS-XEH] call ace_nightvision_fnc_blending - * - * Public: No - */ -#include "script_component.hpp" - -//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"]; -TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret); - -private _player = ACE_player; - -//If we're not in NVG mode, or it's a grenade, exit -if (currentVisionMode _player != 1 || {toLower _weapon in ["throw", "put"]}) exitWith {}; - -private _silencer = _player weaponAccessories _weapon select 0; - -private _visibleFireCoef = 1; -private _visibleFireTimeCoef = 1; - -if (_silencer != "") then { - _visibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "visibleFire"); - _visibleFireTimeCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "visibleFireTime"); -}; - -private _visibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFire"); -private _visibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFireTime"); - -private _fnc_isTracer = { - if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "nvgOnly") > 0) exitWith {false}; - - private _indexShot = (_player ammo _weapon) + 1; - - private _lastRoundsTracer = getNumber (configFile >> "CfgMagazines" >> _magazine >> "lastRoundsTracer"); - if (_indexShot <= _lastRoundsTracer) exitWith {true}; - - private _tracersEvery = getNumber (configFile >> "CfgMagazines" >> _magazine >> "tracersEvery"); - if (_tracersEvery == 0) exitWith {false}; - - (_indexShot - _lastRoundsTracer) % _tracersEvery == 0 -}; - -if (call _fnc_isTracer) then { - _visibleFire = _visibleFire + 2; - _visibleFireTime = _visibleFireTime + 2; -}; - -private _darkness = 1 - (call EFUNC(common,ambientBrightness)); -private _nvgBrightnessCoef = 1 + (_player getVariable [QGVAR(NVGBrightness), 0]) / 4; - -_visibleFire = _darkness * _visibleFireCoef * _visibleFire * _nvgBrightnessCoef / 10 min 1; -_visibleFireTime = _darkness * _visibleFireTimeCoef * _visibleFireTime * _nvgBrightnessCoef / 10 min 0.5; - -TRACE_2("Player Shot, Adjusting NVG Effect", _visibleFire, _visibleFireTime); - -GVAR(ppEffectMuzzleFlash) ppEffectAdjust [1, 1, _visibleFire, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; -GVAR(ppEffectMuzzleFlash) ppEffectCommit 0; - -GVAR(ppEffectMuzzleFlash) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; -GVAR(ppEffectMuzzleFlash) ppEffectCommit _visibleFireTime; diff --git a/addons/nightvision/functions/fnc_changeNVGBrightness.sqf b/addons/nightvision/functions/fnc_changeNVGBrightness.sqf index 5bb5d52721..c038a7392b 100644 --- a/addons/nightvision/functions/fnc_changeNVGBrightness.sqf +++ b/addons/nightvision/functions/fnc_changeNVGBrightness.sqf @@ -1,6 +1,6 @@ /* * Author: commy2 - * Change the brightness of the unit's NVG + * Change the brightness of the unit's NVG. * * Arguments: * 0: The Unit @@ -17,18 +17,16 @@ #include "script_component.hpp" params ["_player", "_changeInBrightness"]; -TRACE_2("params",_player,_changeInBrightness); - -if (!hasInterface) exitWith {}; +TRACE_2("changeNVGBrightness",_player,_changeInBrightness); private _brightness = _player getVariable [QGVAR(NVGBrightness), 0]; -_brightness = ((round (10 * _brightness + _changeInBrightness) / 10) min 0.5) max -0.5; +_brightness = ((_brightness + _changeInBrightness) min 0) max -6; _player setVariable [QGVAR(NVGBrightness), _brightness, false]; -GVAR(ppEffectNVGBrightness) ppEffectAdjust [1, (_brightness + 1), 0, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; -GVAR(ppEffectNVGBrightness) ppEffectCommit 0; - -[format [(localize LSTRING(NVGBrightness)), (_brightness * 10)]] call EFUNC(common,displayTextStructured); +[format [(localize LSTRING(NVGBrightness)), _brightness]] call EFUNC(common,displayTextStructured); playSound "ACE_Sound_Click"; + +// Trigger full ppEffects update next time run in the PFEH: +GVAR(nextEffectsUpdate) = -1; diff --git a/addons/nightvision/functions/fnc_initModule.sqf b/addons/nightvision/functions/fnc_initModule.sqf index 6831a29edf..50f8785e91 100644 --- a/addons/nightvision/functions/fnc_initModule.sqf +++ b/addons/nightvision/functions/fnc_initModule.sqf @@ -17,5 +17,6 @@ #include "script_component.hpp" params ["_module"]; +TRACE_1("initModule",_module); [_module, QGVAR(disableNVGsWithSights), "disableNVGsWithSights"] call EFUNC(common,readSettingFromModule); diff --git a/addons/nightvision/functions/fnc_nonDedicatedFix.sqf b/addons/nightvision/functions/fnc_nonDedicatedFix.sqf new file mode 100644 index 0000000000..2a5178a595 --- /dev/null +++ b/addons/nightvision/functions/fnc_nonDedicatedFix.sqf @@ -0,0 +1,30 @@ +/* + * Author: PabstMirror + * Handles the client who is the non-dedicated server turning on the fog effects. + * + * Arguments: + * 0: Module + * + * Return Value: + * None + * + * Example: + * [] call ace_nightvision_fnc_nonDedicatedFix + * + * Public: No + */ +#include "script_component.hpp" + +TRACE_1("Starting PFEH to handling non-dedicated server running effect",GVAR(serverPriorFog)); + +if (isServer) exitWith {}; + +[{ + if (isNil QGVAR(serverPriorFog)) exitWith { + TRACE_1("Ending PFEH to handling non-dedicated server running effect",_this); + [_this select 1] call CBA_fnc_removePerFrameHandler; + }; + if (!GVAR(running)) then { // If we aren't running the effect ourselves, then use the server's old fog value + 0 setFog GVAR(serverPriorFog); + }; +}, 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/nightvision/functions/fnc_onCameraViewChanged.sqf b/addons/nightvision/functions/fnc_onCameraViewChanged.sqf index 5384d6924c..08ec3afcec 100644 --- a/addons/nightvision/functions/fnc_onCameraViewChanged.sqf +++ b/addons/nightvision/functions/fnc_onCameraViewChanged.sqf @@ -14,10 +14,13 @@ * * Public: No */ - #include "script_component.hpp" params ["_unit", "_cameraView"]; +TRACE_2("onCameraViewChanged",_unit,_cameraView); + +// Refresh goggle effect (e.g. switching to vehicle's NVG) +[] call FUNC(refreshGoggleType); if (GVAR(disableNVGsWithSights) && {(hmd _unit) != ""}) then { if ((vehicle _unit == _unit) diff --git a/addons/nightvision/functions/fnc_onFiredPlayer.sqf b/addons/nightvision/functions/fnc_onFiredPlayer.sqf new file mode 100644 index 0000000000..98dc8ab56d --- /dev/null +++ b/addons/nightvision/functions/fnc_onFiredPlayer.sqf @@ -0,0 +1,66 @@ +/* + * Author: commy2, Dslyecxi, PabstMirror + * Change the blending when the player fires. Called from the unified fired EH only for the local player and his vehicle. + * + * Arguments: + * None. Parameters inherited from EFUNC(common,firedEH) + * + * Return Value: + * None + * + * Example: + * [clientFiredBIS-XEH] call ace_nightvision_fnc_onFiredPlayer + * + * Public: No + */ +#include "script_component.hpp" + +//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"]; +TRACE_7("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile); + +if ((!GVAR(running)) || {_weapon == "throw"} || {_weapon == "put"}) exitWith {}; + +private _visibleFireCoef = 1; +if (_unit == ace_player) then { + private _silencer = (_unit weaponAccessories _weapon) select 0; + if (_silencer != "") then { + _visibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "visibleFire"); + TRACE_1("muzzle attachement",_visibleFireCoef); + }; +}; + +private _visibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFire"); + +private _isTracer = call { + if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "nvgOnly") > 0) exitWith {false}; + private _indexShot = (_unit ammo _weapon) + 1; + private _lastRoundsTracer = getNumber (configFile >> "CfgMagazines" >> _magazine >> "lastRoundsTracer"); + if (_indexShot <= _lastRoundsTracer) exitWith {true}; + private _tracersEvery = getNumber (configFile >> "CfgMagazines" >> _magazine >> "tracersEvery"); + if (_tracersEvery == 0) exitWith {false}; + (_indexShot - _lastRoundsTracer) % _tracersEvery == 0 +}; + +TRACE_3("",_ammo,_visibleFire,_isTracer); +if ( _isTracer) then { + _visibleFire = _visibleFire + 2; +}; + +_visibleFire = _visibleFireCoef * _visibleFire; +if (_ammo isKindOf "BulletBase") then { + _visibleFire = _visibleFire min 5; // Prevent every shot from triggering with HMG +}; +TRACE_1("final", _visibleFire); + +if (_visibleFire <= 1.5) exitWith {}; +if ((random (linearConversion [1, 4, GVAR(nvgGeneration), 10, 20])) > _visibleFire) exitWith {}; + +GVAR(ppEffectCCMuzzleFlash) = ppEffectCreate ["ColorCorrections", 1237]; +GVAR(ppEffectCCMuzzleFlash) ppEffectEnable true; +GVAR(ppEffectCCMuzzleFlash) ppEffectForceInNVG true; + +GVAR(ppEffectCCMuzzleFlash) ppEffectAdjust [1, 1, -1, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; +GVAR(ppEffectCCMuzzleFlash) ppEffectCommit 0; + +GVAR(ppEffectCCMuzzleFlash) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; +GVAR(ppEffectCCMuzzleFlash) ppEffectCommit 0.07; diff --git a/addons/nightvision/functions/fnc_onLoadoutChanged.sqf b/addons/nightvision/functions/fnc_onLoadoutChanged.sqf new file mode 100644 index 0000000000..32f1914bfa --- /dev/null +++ b/addons/nightvision/functions/fnc_onLoadoutChanged.sqf @@ -0,0 +1,25 @@ +/* + * Author: Dslyecxi, PabstMirror + * Refreshes nvg effect if switching NVG goggles. + * + * Arguments: + * 0: Player + * + * Return Value: + * None + * + * Example: + * [player] call ace_nightvision_fnc_onLoadoutChange + * + * Public: No + */ +#include "script_component.hpp" + +params ["_player"]; +TRACE_1("onLoadoutChange",_player); + +private _newHMD = hmd _player; +if (_newHMD != GVAR(playerHMD)) then { + GVAR(playerHMD) = _newHMD; + [] call FUNC(refreshGoggleType); +}; diff --git a/addons/nightvision/functions/fnc_onVisionModeChanged.sqf b/addons/nightvision/functions/fnc_onVisionModeChanged.sqf index 64f77a69bc..7df75c67ae 100644 --- a/addons/nightvision/functions/fnc_onVisionModeChanged.sqf +++ b/addons/nightvision/functions/fnc_onVisionModeChanged.sqf @@ -1,5 +1,5 @@ /* - * Author: BaerMitUmlaut + * Author: BaerMitUmlaut, Dslyecxi, PabstMirror * Disables turning on NVGs while the player aims down his sight. * * Arguments: @@ -14,17 +14,31 @@ * * Public: No */ - #include "script_component.hpp" params ["_unit", "_visionMode"]; +TRACE_2("onVisionModeChanged",_unit,_visionMode); +// Start PFEH when entering night vision mode: +if (_visionMode == 1) then { + if (GVAR(PFID) == -1) then { + GVAR(running) = true; + [true] call FUNC(setupDisplayEffects); + [] call FUNC(refreshGoggleType); + GVAR(PFID) = [LINKFUNC(pfeh), 0, []] call CBA_fnc_addPerFrameHandler; + + // Fade in from black when turning nvg on + QGVAR(turnOnEffect) cutText ["", "BLACK IN", 2.5]; + }; +}; + +// Handle disableNVGsWithSights setting: if (GVAR(disableNVGsWithSights) && {(hmd _unit) != ""}) then { if ((vehicle _unit == _unit) - || {isTurnedOut _unit} - || {!([_unit] call EFUNC(common,hasHatch)) - && {[_unit] call EFUNC(common,getTurretIndex) in ([vehicle _unit] call EFUNC(common,getTurretsFFV))} - }) then { + || {isTurnedOut _unit} + || {!([_unit] call EFUNC(common,hasHatch)) + && {[_unit] call EFUNC(common,getTurretIndex) in ([vehicle _unit] call EFUNC(common,getTurretsFFV))} + }) then { if ((cameraView == "GUNNER") && {_visionMode > 0}) then { _unit action ["NVGogglesOff", _unit]; }; diff --git a/addons/nightvision/functions/fnc_pfeh.sqf b/addons/nightvision/functions/fnc_pfeh.sqf new file mode 100644 index 0000000000..43f0fc068e --- /dev/null +++ b/addons/nightvision/functions/fnc_pfeh.sqf @@ -0,0 +1,160 @@ +/* + * Author: Dslyecxi, PabstMirror + * PFEH to handle refreshing effects. + * Updates UI scale on every frame, effects are updated less often. + * + * Arguments: + * 1: PFEH ID + * + * Return Value: + * None + * + * Example: + * [[], 1] call ace_nightvision_fnc_pfeh + * + * Public: No + */ +#include "script_component.hpp" + +if ((currentVisionMode ACE_player) != 1) exitWith { + GVAR(running) = false; + [false] call FUNC(setupDisplayEffects); + [GVAR(PFID)] call CBA_fnc_removePerFrameHandler; + GVAR(PFID) = -1; +}; +if (EGVAR(common,OldIsCamera)) exitWith { + if (GVAR(running)) then { + TRACE_2("pausing NVG for scripted camera",alive ACE_player,EGVAR(common,OldIsCamera)); + GVAR(running) = false; + [false] call FUNC(setupDisplayEffects); + }; +}; +if (!GVAR(running)) then { + TRACE_1("Un-Pausing", GVAR(paused)); + GVAR(running) = true; + [true] call FUNC(setupDisplayEffects); + [] call FUNC(refreshGoggleType); +}; + +// Scale Border / Hex +BEGIN_COUNTER(borderScaling); +private _scale = (call EFUNC(common,getZoom)) * 1.12513; +if (!(GVAR(defaultPositionBorder) isEqualTo [])) then { + // Prevents issues when "zooming out" on ultra wide monitors - The square mask would be narrower than the screen + if (((GVAR(defaultPositionBorder) select 2) * _scale) < safeZoneW) then { + _scale = safeZoneW / (GVAR(defaultPositionBorder) select 2); + }; + [(uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1000, GVAR(defaultPositionHex), _scale] call FUNC(scaleCtrl); + [(uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1001, GVAR(defaultPositionBorder), _scale] call FUNC(scaleCtrl); + // Fade out hexes with high zoom (optics are doing the magnifying, not the player "focusing in") + ((uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1000) ctrlSetFade (linearConversion [4, 6, _scale, 0.2, 1, true]); +}; +END_COUNTER(borderScaling); + +if (CBA_missionTime < GVAR(nextEffectsUpdate)) then { + // Update radial blur as it depends on zoom level, so should be changed each frame like the border/hex + if (GVAR(ppeffectRadialBlur) != -1) then { + GVAR(ppeffectRadialBlur) ppEffectAdjust [.005, .005, _scale * GVAR(nvgBlurRadius), _scale * .16]; + GVAR(ppeffectRadialBlur) ppEffectCommit 0; + }; + // Need to rapidly update fog or it will try to resync from the server + if (GVAR(fogScaling) > 0) then { + 0 setFog GVAR(nvgFog); + }; +} else { + // Redo full effects less often + BEGIN_COUNTER(updateAllEffects); + GVAR(nextEffectsUpdate) = CBA_missionTime + 5; + + // Detecting the efficiency of the nightvision. + private _lightFinal = 0 max (moonIntensity - ((overcast * .8) min .275) - (rain * .5)); + private _effectiveLight = _lightFinal * linearConversion [1, 3, GVAR(nvgGeneration), 0.25, 1]; + private _effectMod = linearConversion [1, 3, GVAR(nvgGeneration), 1.5, 1]; + // This has become a little weird. Basically means that lightfinal is unlikely to reach zero with any moon in the sky + // buuut it just so happens that setting it like this means that the lighting progression from clear -> cloudy -> rainy works particularly well. + + private _grainFinal = linearConversion [1, 0, _effectiveLight, ST_NVG_GRAIN_MIN, ST_NVG_GRAIN_MAX, true]; + private _blurFinal = _effectMod *_effectMod * linearConversion [1, 0, _effectiveLight, ST_NVG_BLUR_MIN, ST_NVG_BLUR_MAX, true]; + private _brightFinal = linearConversion [0, 1, _effectiveLight, ST_NVG_BRIGHT_MIN, ST_NVG_BRIGHT_MAX, true]; + private _contrastFinal = linearConversion [0, 1, _effectiveLight, ST_NVG_CONTRAST_MIN, ST_NVG_CONTRAST_MAX, true]; + private _grainIntensityFinal = _effectMod * linearConversion [1, 0, _effectiveLight, ST_NVG_NOISEINTENSITY_MIN, ST_NVG_NOISEINTENSITY_MAX, true]; + private _noiseSharpnessFinal = linearConversion [1, 0, _effectiveLight, ST_NVG_NOISESHARPNESS_MIN, ST_NVG_NOISESHARPNESS_MAX, true]; + + private _playerBrightSetting = ACE_player getVariable [QGVAR(NVGBrightness), 0]; + _brightFinal = _brightFinal + (_playerBrightSetting / 20); + + private _fogApply = linearConversion [0, 1, _effectiveLight, ST_NVG_MAXFOG, ST_NVG_MINFOG, true]; + + // Modify blur if looking down scope + if ((cameraView == "GUNNER") && {[ACE_player] call CBA_fnc_canUseWeapon}) then { + if (currentWeapon ACE_player == "") exitWith {}; + if (currentWeapon ACE_player == primaryWeapon ACE_player) exitWith {_blurFinal = _blurFinal * ST_NVG_CAMERA_BLUR_SIGHTS_RIFLE}; // Rifles are bad + if (currentWeapon ACE_player == handgunWeapon ACE_player) exitWith {_blurFinal = _blurFinal * ST_NVG_CAMERA_BLUR_SIGHTS_PISTOL}; // Pistols aren't so bad + }; + + // Scale effects based on ace_nightvision_effectScaling setting + _grainIntensityFinal = _grainIntensityFinal * GVAR(effectScaling); + _noiseSharpnessFinal = linearConversion [0, 1, GVAR(effectScaling), 2.5, _noiseSharpnessFinal]; + private _radialBlurPower = 0.0025 * GVAR(effectScaling); + _brightFinal = linearConversion [0, 1, GVAR(effectScaling), 1, _brightFinal]; + _contrastFinal = linearConversion [0, 1, GVAR(effectScaling), 1, _contrastFinal]; + _blurFinal = _blurFinal * GVAR(effectScaling); + + + // Setup all effects + // This is hacky but... works. This prevents the effects from being cancelled by various things - alt-tabbing, resizing, going into AT sights, etc. A nicer method would be welcome but I don't have time to spend on it. TODO. + + // FilmGrain - Electronic Noise + // Params: [intensity(0..1), sharpness(0..20), grainsize(1..8), intensityX0, intensityX1, monochromatic(bool)] + GVAR(ppeffectGrain) = ppEffectCreate ["FilmGrain", 200]; + GVAR(ppeffectGrain) ppEffectAdjust [_grainIntensityFinal, _noiseSharpnessFinal, _grainFinal, 0.3, 0.3]; + // OldNVG: [0.25, 2.5, 2.5, _grainSetting, _grainSetting, false] + GVAR(ppeffectGrain) ppEffectCommit 0; + GVAR(ppeffectGrain) ppEffectForceInNVG true; + GVAR(ppeffectGrain) ppEffectEnable true; + + // RadialBlur - Blurs closer to the edge nvg border (radius based on GVAR(bluRadius) config; e.g. larger for quadtube) + // Note: "Will not do anything if RADIAL BLUR is disabled in Video Options." - So should try to keep this effect to a minimum to prevent balance issues + // Params: [powerX, powerY, offsetX, offsetY] + if (GVAR(nvgBlurRadius) != -1) then { + GVAR(ppeffectRadialBlur) = ppEffectCreate ["RadialBlur", 451]; + GVAR(ppeffectRadialBlur) ppEffectAdjust [_radialBlurPower, _radialBlurPower, _scale * GVAR(nvgBlurRadius), _scale * .16]; + GVAR(ppeffectRadialBlur) ppEffectCommit 0; + GVAR(ppeffectRadialBlur) ppEffectForceInNVG true; + GVAR(ppeffectRadialBlur) ppEffectEnable true; + }; + + // ColorCorrections - Changes brightness, contrast and "green" color of nvg + // Params: [brightness(0..2), contrast(0..inf), offset(-x..+x), blendArray, colorizeArray, weightArray] + GVAR(ppeffectColorCorrect) = ppEffectCreate ["ColorCorrections", 2003]; + GVAR(ppeffectColorCorrect) ppEffectAdjust [_brightFinal, _contrastFinal, 0, [0.0, 0.0, 0.0, 0.0], [1.3, 1.2, 0.0, 0.9], [6, 1, 1, 0.0]]; + GVAR(ppeffectColorCorrect) ppEffectCommit 0; + GVAR(ppeffectColorCorrect) ppEffectForceInNVG true; + GVAR(ppeffectColorCorrect) ppEffectEnable true; + + // DynamicBlur - Increases overall screen blur when aiming down sights (which would be hard/impossible with NVG) + // Params: [value(0..inf)] + GVAR(ppeffectBlur) = ppEffectCreate ["DynamicBlur", 190]; + GVAR(ppeffectBlur) ppEffectAdjust [_blurFinal]; + GVAR(ppeffectBlur) ppEffectCommit 0; + GVAR(ppeffectBlur) ppEffectForceInNVG true; + GVAR(ppeffectBlur) ppEffectEnable true; + + + // Modify local fog: + if (GVAR(fogScaling) > 0) then { + if (((vehicle ACE_player) != ACE_player) && {(vehicle ACE_player) isKindOf "Air"}) then { // For flying in particular, can refine nicer later. + _fogApply = _fogApply * ST_NVG_AIR_FOG_MULTIPLIER; + }; + _fogApply = linearConversion [0, 1, GVAR(priorFog) select 0, (GVAR(fogScaling) * _fogApply), 1]; // mix in old fog if present + GVAR(nvgFog) = [_fogApply, 0, 0]; + 0 setFog GVAR(nvgFog) + }; + + #ifdef DEBUG_MODE_FULL + private _aceAmbient = [] call EFUNC(common,ambientBrightness); + hintSilent format ["EffectiveLight %1\nLight: %2\nACE Ambient: %3\nBrightness: %4\nContrast: %5\nGrain: %6\nBlur: %7\nFog: %8\nScaling %9", _effectiveLight, _lightFinal, _aceAmbient, _brightFinal, _contrastFinal, [_grainIntensityFinal, _noiseSharpnessFinal, _grainFinal], _blurFinal, _fogApply, [GVAR(effectScaling),GVAR(fogScaling)]]; + #endif + + END_COUNTER(updateAllEffects); +}; diff --git a/addons/nightvision/functions/fnc_refreshGoggleType.sqf b/addons/nightvision/functions/fnc_refreshGoggleType.sqf new file mode 100644 index 0000000000..1ebadf56ae --- /dev/null +++ b/addons/nightvision/functions/fnc_refreshGoggleType.sqf @@ -0,0 +1,129 @@ +/* + * Author: Dslyecxi, PabstMirror + * Determines night vision source (player/vehicle) - Updates UI based on type. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_nightvision_fnc_refreshGoggleType + * + * Public: No + */ +#include "script_component.hpp" + +TRACE_1("refreshGoggleType",_this); + +if (!GVAR(running)) exitWith {}; + +// Defaults (good for most vehicles/binoculars) +private _borderImage = ""; +private _eyeCups = false; +private _hideHex = true; +private _nvgGen = 3; +private _blurRadius = -1; + +if (alive ACE_player) then { + if (((vehicle ACE_player) == ACE_player) || { + // Test if we are using player's nvg or if sourced from vehicle: + + private _currentVehicle = vehicle ACE_player; + private _vehConfig = configFile >> "CfgVehicles" >> (typeOf _currentVehicle); + + if (cameraView != "GUNNER") exitWith {true}; // asume hmd usage outside of gunner view + + if (ACE_player == (driver _currentVehicle)) exitWith { + !("NVG" in getArray (_vehConfig >> "ViewOptics" >> "visionMode")); + }; + private _result = true; + private _turret = ACE_player call CBA_fnc_turretPath; + private _turretConfig = [_currentVehicle, _turret] call CBA_fnc_getTurret; + + // Seems to cover things like the offroad technical + if ((isNumber (_turretConfig >> "optics")) && {(getNumber (_turretConfig >> "optics")) == 0}) exitWith {true}; + + private _turretConfigOpticsIn = _turretConfig >> "OpticsIn"; + if (isClass _turretConfigOpticsIn) then { + for "_index" from 0 to (count _turretConfigOpticsIn - 1) do { + if ("NVG" in getArray (_turretConfigOpticsIn select _index >> "visionMode")) exitWith {_result = false}; + }; + } else { + // No OpticsIn usualy means RCWS, still need to test on more vehicles + _result = false; + }; + _result + }) then { + if ((cameraView == "GUNNER") && {currentWeapon ACE_player != ""} && {binocular ACE_player == currentWeapon ACE_player}) exitWith { + TRACE_1("souce: binocular",binocular ACE_player); // Source is from player's binocular (Rangefinder/Vector21bNite) + private _config = configFile >> "CfgWeapons" >> (binocular ACE_player); + if (isNumber (_config >> QGVAR(generation))) then {_nvgGen = getNumber (_config >> QGVAR(generation));}; + }; + + TRACE_1("source: hmd",GVAR(playerHMD)); // Source is player's HMD (or possibly a NVG scope, but no good way to detect that) + private _config = configFile >> "CfgWeapons" >> GVAR(playerHMD); + if (!isClass _config) exitWith {}; + + // Only use border if there is no modelOptics + if ((getText (_config >> "modelOptics")) == "") then { + _borderImage = getText (_config >> QGVAR(border)); + _eyeCups = ((getNumber (_config >> QGVAR(eyeCups))) == 1); + _hideHex = (getNumber (_config >> QGVAR(hideHex))) == 1; + if (isNumber (_config >> QGVAR(bluRadius))) then {_blurRadius = getNumber (_config >> QGVAR(bluRadius));}; + }; + if (isNumber (_config >> QGVAR(generation))) then {_nvgGen = getNumber (_config >> QGVAR(generation));}; + + } else { + TRACE_1("source: vehicle - defaults",typeOf vehicle ACE_player); + }; +}; + +#ifdef DEBUG_MODE_FULL +systemChat format ["NVG Refresh - Border: %1", _borderImage]; +systemChat format ["EyeCups: %1, HideHex %2, NVGen: %3, BluRadius: %4", _eyeCups, _hideHex, _nvgGen, _blurRadius]; +#endif + +GVAR(nvgBlurRadius) = _blurRadius; +GVAR(nvgGeneration) = _nvgGen; + +// Setup border and hex image based on NVG config: +private _scale = (call EFUNC(common,getZoom)) * 1.12513; + +private _borderImageCtrl = (uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1001; +private _trippleHeadLeft = (uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1002; +private _trippleHeadRight = (uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1003; +if (_borderImage == "") then { + _borderImageCtrl ctrlShow false; + _trippleHeadLeft ctrlShow false; + _trippleHeadRight ctrlShow false; + GVAR(defaultPositionBorder) = []; +} else { + _borderImageCtrl ctrlShow true; + _trippleHeadLeft ctrlShow true; + _trippleHeadRight ctrlShow true; + + _borderImageCtrl ctrlSetText _borderImage; + _borderImageCtrl ctrlSetFade ([.15, 0] select _eyeCups); + + #define BORDER_SIZE 3 + GVAR(defaultPositionBorder) = [safezoneX - (((BORDER_SIZE * 0.75) * safezoneH) - safezoneW) / 2, safezoneY - ((BORDER_SIZE - 1) / 2) * safezoneH, (BORDER_SIZE * 0.75) * safezoneH, BORDER_SIZE * safezoneH]; + [_borderImageCtrl, GVAR(defaultPositionBorder), _scale] call FUNC(scaleCtrl); +}; + +private _hexCtrl = (uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1000; +if (_hideHex) then { + _hexCtrl ctrlShow false; +} else { + _hexCtrl ctrlShow true; + // _hexCtrl ctrlSetText QPATHTOF(data\nvg_mask_hexes.paa); + _hexCtrl ctrlSetText QPATHTOF(data\nvg_mask_hexes_thin.paa); + + #define HEX_SIZE 1.5 + GVAR(defaultPositionHex) = [safezoneX - (((HEX_SIZE * 0.75) * safezoneH) - safezoneW) / 2, safezoneY - ((HEX_SIZE - 1) / 2) * safezoneH, (HEX_SIZE * 0.75) * safezoneH, HEX_SIZE * safezoneH]; + [_hexCtrl, GVAR(defaultPositionHex), _scale] call FUNC(scaleCtrl); +}; + +// Trigger full ppEffects update next time run in the PFEH: +GVAR(nextEffectsUpdate) = -1; diff --git a/addons/nightvision/functions/fnc_scaleCtrl.sqf b/addons/nightvision/functions/fnc_scaleCtrl.sqf new file mode 100644 index 0000000000..b5bb80715d --- /dev/null +++ b/addons/nightvision/functions/fnc_scaleCtrl.sqf @@ -0,0 +1,31 @@ +/* + * Author: Dslyecxi, PabstMirror + * Determines night vision source (player/vehicle) - Updates UI based on type. + * + * Arguments: + * 0: Control + * 1: Default position [x,y,w,h] + * 2: Zoom Level + * + * Return Value: + * None + * + * Example: + * [] call ace_nightvision_fnc_scaleCtrl + * + * Public: No + */ +#include "script_component.hpp" + +params ["_ctrl", "_default_pos", "_scale"]; + +if (!ctrlShown _ctrl) exitWith {}; + +_ctrl ctrlSetPosition +[(((_default_pos select 0) - 0.5) * _scale) + 0.5, +(((_default_pos select 1) - 0.5) * _scale) + 0.5, +(_default_pos select 2) * _scale, +(_default_pos select 3) * _scale]; + + +_ctrl ctrlCommit 0; diff --git a/addons/nightvision/functions/fnc_setupDisplayEffects.sqf b/addons/nightvision/functions/fnc_setupDisplayEffects.sqf new file mode 100644 index 0000000000..004d186998 --- /dev/null +++ b/addons/nightvision/functions/fnc_setupDisplayEffects.sqf @@ -0,0 +1,77 @@ +/* + * Author: Dslyecxi, PabstMirror + * Handles setting up the effects: fog, ppEffects and the RscTittle. + * + * Arguments: + * 0: Activated + * + * Return Value: + * None + * + * Example: + * [true] call ace_nightvision_fnc_setupDisplayEffects + * + * Public: No + */ +#include "script_component.hpp" + +params ["_activated"]; +TRACE_1("setupDisplayEffects",_activated); + +// Backup and restore changes to fog: +if (GVAR(fogScaling) > 0) then { + if (_activated) then { + if (isNil QGVAR(priorFog)) then { + TRACE_1("Backing up fog",fogParams); + GVAR(priorFog) = fogParams; + } else { + ERROR("fog already backed up"); + }; + + // Handle non-dedicated: + if (isServer && hasInterface) then { + missionNamespace setVariable [QGVAR(serverPriorFog), fogParams, true]; + [QGVAR(nonDedicatedFix), []] call CBA_fnc_remoteEvent; + }; + } else { + if (!isNil QGVAR(priorFog)) then { + 0 setFog GVAR(priorFog); + GVAR(priorFog) = nil; + } else { + ERROR("no fog backed up"); + }; + + // Handle non-dedicated: + if (isServer && hasInterface) then { + missionNamespace setVariable [QGVAR(serverPriorFog), nil, true]; + }; + }; +}; + +// Note: Using BIS_fnc_rscLayer because of bug with string syntax - https://feedback.bistudio.com/T120768 +(QGVAR(display) call BIS_fnc_rscLayer) cutText ["", "PLAIN"]; // Cleanup Old Display +if (_activated) then { // Create New Display + (QGVAR(display) call BIS_fnc_rscLayer) cutRsc [QGVAR(title), "PLAIN", 0, false]; +}; + +// Cleanup Old PP Effects +if (GVAR(ppeffectGrain) != -1) then { + ppEffectDestroy GVAR(ppeffectGrain); + GVAR(ppeffectGrain) = -1; +}; +if (GVAR(ppeffectBlur) != -1) then { + ppEffectDestroy GVAR(ppeffectBlur); + GVAR(ppeffectBlur) = -1; +}; +if (GVAR(ppeffectRadialBlur) != -1) then { + ppEffectDestroy GVAR(ppeffectRadialBlur); + GVAR(ppeffectRadialBlur) = -1; +}; +if (GVAR(ppeffectColorCorrect) != -1) then { + ppEffectDestroy GVAR(ppeffectColorCorrect); + GVAR(ppeffectColorCorrect) = -1; +}; +if (GVAR(ppEffectCCMuzzleFlash) != -1) then { + ppEffectDestroy GVAR(ppEffectCCMuzzleFlash); + GVAR(ppEffectCCMuzzleFlash) = -1; +}; diff --git a/addons/nightvision/functions/fnc_updatePPEffects.sqf b/addons/nightvision/functions/fnc_updatePPEffects.sqf deleted file mode 100644 index f80b0fa57e..0000000000 --- a/addons/nightvision/functions/fnc_updatePPEffects.sqf +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Author: commy2, PabstMirror and esteldunedain - * Update the ppEffects everytime something changes - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * [someEvent] call ace_nightvision_fnc_updatePPEffects - * - * Public: No - */ -#include "script_component.hpp" - -if (!hasInterface) exitWith {}; - -disableSerialization; - -params [["_display", displayNull]]; - -if !(_display isEqualType displayNull) then { - _display = displayNull; -}; - -private _currentVehicle = vehicle ACE_player; - -// If the Zeus display is on or the player has no nightvision -if (ctrlIDD _display == 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 -private _config = configFile >> "CfgVehicles" >> typeOf _currentVehicle; -private _hmd = hmd ACE_player; -private _cameraView = cameraView; -private _turret = [ACE_player] call EFUNC(common,getTurretIndex); - - -private _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 = true; - private _turretConfig = [_config, _turret] call EFUNC(common,getTurretConfigPath); - private _turretConfigOpticsIn = _turretConfig >> "OpticsIn"; - - if (isClass _turretConfigOpticsIn) then { - for "_index" from 0 to (count _turretConfigOpticsIn - 1) do { - if ("NVG" in getArray (_turretConfigOpticsIn select _index >> "visionMode")) exitWith {_result = false}; - }; - } else { - //No OpticsIn usualy means RCWS, still need to test on more vehicles - _result = false; - }; - _result -}; - -private _grainSetting = 0; -private _blurSetting = 0; -private _radBlurSetting = 0; - -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; diff --git a/addons/nightvision/script_component.hpp b/addons/nightvision/script_component.hpp index 142983ebdc..0fd46d1fa3 100644 --- a/addons/nightvision/script_component.hpp +++ b/addons/nightvision/script_component.hpp @@ -15,3 +15,34 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + + +// Effect Settings / Magic values to tweak: + +// Decreases fog when in air vehicles +#define ST_NVG_AIR_FOG_MULTIPLIER 0.5 + +// Increase blur when looking down sights +#define ST_NVG_CAMERA_BLUR_SIGHTS_RIFLE 6 +#define ST_NVG_CAMERA_BLUR_SIGHTS_PISTOL 2 + +#define ST_NVG_MINFOG 0.2 +#define ST_NVG_MAXFOG 0.3 + +#define ST_NVG_GRAIN_MIN 2.25 +#define ST_NVG_GRAIN_MAX 2.7 + +#define ST_NVG_BLUR_MIN 0.05 +#define ST_NVG_BLUR_MAX 0.11 + +#define ST_NVG_BRIGHT_MIN 0.65 +#define ST_NVG_BRIGHT_MAX 0.75 + +#define ST_NVG_CONTRAST_MIN 0.4 +#define ST_NVG_CONTRAST_MAX 0.8 + +#define ST_NVG_NOISEINTENSITY_MIN 0.4 +#define ST_NVG_NOISEINTENSITY_MAX 0.55 + +#define ST_NVG_NOISESHARPNESS_MIN 1.2 +#define ST_NVG_NOISESHARPNESS_MAX 1 diff --git a/addons/nightvision/stringtable.xml b/addons/nightvision/stringtable.xml index 9970c8187c..30734e1cfa 100644 --- a/addons/nightvision/stringtable.xml +++ b/addons/nightvision/stringtable.xml @@ -1,6 +1,9 @@  + + ACE - Nightvision + NV Goggles (Gen1) Noktovizor (Gen1) @@ -237,5 +240,17 @@ 此功能开启后,当要使用瞄准镜时,为避免夜视镜镜头碰撞到瞄准镜,会先拿开夜视镜后再进行瞄准镜瞄准。 此功能開啟後,當要使用瞄準鏡時,為避免夜視鏡鏡頭碰撞到瞄準鏡,會先拿開夜視鏡後再進行瞄準鏡瞄準。 + + NVG Fog Scale + + + Fog is used to limit visibility. + + + NVG Effect Scale + + + Blur, grain and brightness effects [Setting to 0 will disable ALL nightvision effects] + diff --git a/optionals/compat_rhs_afrf3/CfgWeapons.hpp b/optionals/compat_rhs_afrf3/CfgWeapons.hpp index 9418f96fea..6dea9eb890 100644 --- a/optionals/compat_rhs_afrf3/CfgWeapons.hpp +++ b/optionals/compat_rhs_afrf3/CfgWeapons.hpp @@ -1,5 +1,13 @@ class CfgWeapons { + + class NVGoggles; + class rhs_1PN138: NVGoggles { // Monocular + modelOptics = ""; + EGVAR(nightvision,border) = QPATHTOEF(nightvision,data\nvg_mask_4096.paa); + EGVAR(nightvision,bluRadius) = 0.13; + }; + class hgun_Rook40_F; class rhs_weap_pya: hgun_Rook40_F { ACE_barrelTwist = 254.0; diff --git a/optionals/compat_rhs_usf3/CfgWeapons.hpp b/optionals/compat_rhs_usf3/CfgWeapons.hpp index 74a4b05baa..84299450b2 100644 --- a/optionals/compat_rhs_usf3/CfgWeapons.hpp +++ b/optionals/compat_rhs_usf3/CfgWeapons.hpp @@ -1,5 +1,17 @@ class CfgWeapons { + class NVGoggles; + class rhsusf_ANPVS_14: NVGoggles { // Monocular + modelOptics = ""; + EGVAR(nightvision,border) = QPATHTOEF(nightvision,data\nvg_mask_4096.paa); + EGVAR(nightvision,bluRadius) = 0.13; + }; + class rhsusf_ANPVS_15: rhsusf_ANPVS_14 { // Binocular (same as base) + modelOptics = ""; + EGVAR(nightvision,border) = QPATHTOEF(nightvision,data\nvg_mask_binos_4096.paa); + EGVAR(nightvision,bluRadius) = 0.15; + }; + class Pistol_Base_F; class Rifle_Base_F; class srifle_EBR_F;