From dc882a3c6675b4409efd89e6da529025a21385b7 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 30 Sep 2015 01:26:08 +0200 Subject: [PATCH] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 36 ++++-- addons/goggles/XEH_preInit.sqf | 8 +- .../goggles/functions/fnc_applyDustEffect.sqf | 12 +- .../functions/fnc_applyRotorWashEffect.sqf | 108 ++++++++++++++++++ addons/goggles/functions/fnc_checkGoggles.sqf | 46 -------- addons/goggles/functions/fnc_onEachFrame.sqf | 78 ------------- 6 files changed, 146 insertions(+), 142 deletions(-) create mode 100644 addons/goggles/functions/fnc_applyRotorWashEffect.sqf delete mode 100644 addons/goggles/functions/fnc_checkGoggles.sqf delete mode 100644 addons/goggles/functions/fnc_onEachFrame.sqf diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index cc25c259e9..4958c8e02b 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -31,9 +31,8 @@ GVAR(EffectsActive) = false; SETGLASSES(ace_player,GLASSESDEFAULT); -GVAR(Current) = "None"; GVAR(EyesDamageScript) = -1; -GVAR(FrameEvent) = [false, [false,20]]; +GVAR(FrameEvent) = [false, [false, 20]]; GVAR(PostProcessEyes_Enabled) = false; GVAR(DustHandler) = -1; GVAR(RainDrops) = objNull; @@ -42,7 +41,6 @@ GVAR(RainLastLevel) = 0; GVAR(surfaceCache) = ""; GVAR(surfaceCacheIsDust) = false; - // init GlassesChanged eventhandler GVAR(OldGlasses) = "#NULLSTRING"; @@ -96,12 +94,36 @@ GVAR(OldGlasses) = "#NULLSTRING"; }] call EFUNC(common,addEventHandler); +// check goggles +local _fnc_checkGoggles = { + params ["_unit"]; + if (GVAR(EffectsActive)) then { + if (call FUNC(externalCamera) || {!([_unit] call FUNC(isGogglesVisible))}) then { + call FUNC(removeGlassesEffect); + }; + } else { + if (!(call FUNC(externalCamera)) && {[_unit] call FUNC(isGogglesVisible)}) then { + [goggles _unit] call FUNC(applyGlassesEffect); + }; + }; +}; +["cameraViewChanged", _fnc_checkGoggles] call EFUNC(common,addEventHandler); +["activeCameraChanged", _fnc_checkGoggles] call EFUNC(common,addEventHandler); +// goggles effects main PFH +[{ + // rain + call FUNC(applyRainEffect); + // auto remove effects under water + if (GVAR(EffectsActive) && {[goggles ACE_player] call FUNC(isDivingGoggles) && {underwater ACE_player}}) then { + call FUNC(removeRainEffect); + call FUNC(removeDirtEffect); + call FUNC(removeDustEffect); + }; - -[FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; -[FUNC(applyRainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; -[FUNC(onEachFrame), 0, []] call CBA_fnc_addPerFrameHandler; + // rotor wash effect + call FUNC(applyRotorWashEffect) +}, 0.5, _fnc_checkGoggles] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/XEH_preInit.sqf b/addons/goggles/XEH_preInit.sqf index deb2aed0fc..ba5fa2373e 100644 --- a/addons/goggles/XEH_preInit.sqf +++ b/addons/goggles/XEH_preInit.sqf @@ -7,6 +7,7 @@ PREP(applyDirtEffect); PREP(applyDustEffect); PREP(applyGlassesEffect); PREP(applyRainEffect); +PREP(applyRotorWashEffect); PREP(removeDirtEffect); PREP(removeDustEffect); PREP(removeGlassesEffect); @@ -27,11 +28,4 @@ PREP(handleExplosion); PREP(handleFired); PREP(handleKilled); - - -PREP(checkGoggles); -PREP(onEachFrame); - - - ADDON = true; diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf index 558a6c674b..b052f3eae7 100644 --- a/addons/goggles/functions/fnc_applyDustEffect.sqf +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -62,13 +62,17 @@ GVAR(DustHandler) = [{ }; if (GETDUSTT(DAMOUNT) <= 0) then { + SETDUST(DACTIVE,false); + SETDUST(DBULLETS,0); + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 2; - [{GVAR(PostProcessEyes) ppEffectEnable false}, [], 2] call EFUNC(common,waitAndExecute); - - SETDUST(DACTIVE,false); - SETDUST(DBULLETS,0); + [{ + if (GVAR(DustHandler) == -1) then { + GVAR(PostProcessEyes) ppEffectEnable false + }; + }, [], 2] call EFUNC(common,waitAndExecute); [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; GVAR(DustHandler) = -1; diff --git a/addons/goggles/functions/fnc_applyRotorWashEffect.sqf b/addons/goggles/functions/fnc_applyRotorWashEffect.sqf new file mode 100644 index 0000000000..7dc088bc4e --- /dev/null +++ b/addons/goggles/functions/fnc_applyRotorWashEffect.sqf @@ -0,0 +1,108 @@ +/* + * Author: Garth 'L-H' de Wet, commy2 + * Handles the rotor wash effects. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_goggles_fnc_applyRotorWashEffect; + * + * Public: No + */ +#include "script_component.hpp" + +private ["_unit", "_fnc_underCover"]; + +_unit = ACE_player; + +if (!alive _unit) exitWith {}; + +// idk. chaching magic? ends with isInRotorWash check. +GVAR(FrameEvent) set [0, !(GVAR(FrameEvent) select 0)]; + +if (GVAR(FrameEvent) select 0) exitWith { + if (vehicle _unit != _unit && {!isTurnedOut _unit}) exitWith { + (GVAR(FrameEvent) select 1) set [0, false]; + }; + + GVAR(FrameEvent) set [1, ([_unit] call FUNC(isInRotorWash))]; +}; + +// check if the unit is affected by rotor wash +private ["_rotorWash", "_safe"]; + +_rotorWash = GVAR(FrameEvent) select 1; +_safe = false; + +// no rotor wash? remove effects. +if !(_rotorWash select 0) exitWith { + if (GVAR(PostProcessEyes_Enabled)) then { + GVAR(PostProcessEyes_Enabled) = false; + + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 2; + + [{ + if (GVAR(DustHandler) == -1) then { + GVAR(PostProcessEyes) ppEffectEnable false; + } + }, [], 2] call EFUNC(common,waitAndExecute); + + [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(DustHandler) = -1; + }; +}; + +// check protection of helmet +if (headgear _unit != "") then { + _safe = getNumber (configFile >> "CfgWeapons" >> headgear _unit >> "ACE_Protection") == 1; +}; + +// check protection of goggles +if !(_safe) then { + if !([_unit] call FUNC(isGogglesVisible)) exitWith {}; + + if (GETDUSTT(DAMOUNT) < 2) then { + if !(GETDUSTT(DACTIVE)) then { + SETDUST(DACTIVE,true); + + call FUNC(applyDustEffect); + } else { + if (_rotorWash select 1 > 0.5) then { + call FUNC(applyDustEffect); + }; + }; + }; + + _safe = getNumber (ConfigFile >> "CfgGlasses" >> goggles _unit >> "ACE_Protection") == 1; +}; + +// quit if protected by goggles or helmet +if (_safe) exitWith {}; + +// apply rotor wash effect +if (_rotorWash select 1 > 0) then { + local _scale = 0.7; + + if (_rotorWash select 1 > 0) then { + _scale = CLAMP(0.3 * (_rotorWash select 1),0.1,0.3); + } else { + _scale = 0.1; + }; + + _scale = 1 - _scale; + + [GVAR(DustHandler)] call CBA_fnc_removePerFrameHandler; + GVAR(DustHandler) = -1; + + if !(_unit getVariable ["ACE_EyesDamaged", false]) then { + GVAR(PostProcessEyes_Enabled) = true; + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [_scale, _scale, _scale, _scale], [1, 1, 1, 0]]; + GVAR(PostProcessEyes) ppEffectCommit 0.5; + GVAR(PostProcessEyes) ppEffectEnable true; + }; +}; diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf deleted file mode 100644 index 2d10515fc6..0000000000 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Performs rain checks and checks to see whether glasses effects have been applied or not. - * Checks for external camera and removes effects. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * None - * - * Public: No - */ -#include "script_component.hpp" -if (!alive ace_player) exitWith {}; -if (true) then { - // Detect if curator interface is open and disable effects - if !(isNull curatorCamera) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - //call FUNC(checkGlasses); - if !([ace_player] call FUNC(isGogglesVisible)) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - if (call FUNC(externalCamera)) exitWith { - if (GVAR(EffectsActive)) then { - call FUNC(removeGlassesEffect); - }; - }; - if !(GVAR(EffectsActive)) then { - [goggles ace_player] call FUNC(applyGlassesEffect); - } else { - if ([goggles ace_player] call FUNC(isDivingGoggles) && {underwater ace_player}) then { - call FUNC(removeRainEffect); - call FUNC(removeDirtEffect); - call FUNC(removeDustEffect); - }; - }; -}; diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf deleted file mode 100644 index d9181373a1..0000000000 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Author: Garth 'L-H' de Wet - * Checks whether the player is in the downwash of a helicopter and handles applying effects of that. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * ["ACE_Goggles_RotorWash", "OnEachFrame", "call ace_goggles_fnc_OnEachFrame;"] call BIS_fnc_addStackedEventHandler; - * - * Public: No - */ -#include "script_component.hpp" -if (isNull(ace_player)) exitWith {}; -GVAR(FrameEvent) set [0, !(GVAR(FrameEvent) select 0)]; -if (GVAR(FrameEvent) select 0) exitWith { - if (vehicle ace_player != ace_player && {!isTurnedOut ACE_player}) exitWith {(GVAR(FrameEvent) select 1) set [0, false]; }; - GVAR(FrameEvent) set [1, ([ace_player] call FUNC(isInRotorWash))]; -}; -private ["_rotorWash","_safe"]; -_rotorWash = GVAR(FrameEvent) select 1; -_safe = false; -if !(_rotorWash select 0) exitWith { - if (GVAR(PostProcessEyes_Enabled)) then { - GVAR(PostProcessEyes_Enabled) = false; - if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; - GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 2; - GVAR(DustHandler) = [{ - GVAR(PostProcessEyes) ppEffectEnable false; - GVAR(DustHandler) = -1; - }, [], 2, 0.5] call EFUNC(common,waitAndExecute); - }; -}; -if ((headgear ace_player) != "") then { - _safe = (getNumber (ConfigFile >> "CfgWeapons" >> (headgear ace_player) >> "ACE_Protection") == 1); -}; -if !(_safe) then { - if !([ace_player] call FUNC(isGogglesVisible)) exitWith{}; - if (GETDUSTT(DAMOUNT) < 2) then { - if (!GETDUSTT(DACTIVE)) then { - SETDUST(DACTIVE,true); - call FUNC(applyDustEffect); - } else { - if ((_rotorWash select 1) > 0.5) then { - call FUNC(applyDustEffect); - }; - }; - }; - _safe = (getNumber (ConfigFile >> "CfgGlasses" >> goggles ace_player >> "ACE_Protection") == 1); -}; -if (_safe) exitWith {}; -if ((_rotorWash select 1) <= 15) then { - private "_scale"; - _scale = 0.7; - if ((_rotorWash select 1) != 0) then { - _scale = CLAMP(0.3*(_rotorWash select 1),0.1,0.3); - } else { - _scale = 0.1; - }; - _scale = 1 - _scale; - if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; - if !(ace_player getVariable ["ACE_EyesDamaged", false]) then { - GVAR(PostProcessEyes_Enabled) = true; - GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [_scale,_scale,_scale,_scale],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 0.5; - GVAR(PostProcessEyes) ppEffectEnable true; - }; -};