From 62349f685c37bdfdb29e8cf5c2af678b079b91f0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 29 Sep 2015 22:01:40 +0200 Subject: [PATCH] more goggles code cleanup --- addons/goggles/XEH_postInit.sqf | 123 ++++++++---------- .../goggles/functions/fnc_applyDirtEffect.sqf | 2 +- .../goggles/functions/fnc_applyDustEffect.sqf | 2 +- .../functions/fnc_applyGlassesEffect.sqf | 2 +- addons/goggles/functions/fnc_checkGoggles.sqf | 2 +- .../goggles/functions/fnc_handleExplosion.sqf | 19 +++ addons/goggles/functions/fnc_handleFired.sqf | 2 + addons/goggles/functions/fnc_handleKilled.sqf | 13 ++ addons/goggles/functions/fnc_onEachFrame.sqf | 2 +- 9 files changed, 94 insertions(+), 73 deletions(-) diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 2d78e6f372..5a3c2c875b 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -12,22 +12,25 @@ if (!hasInterface) exitWith {}; {false}, [20, [true, true, false]], false] call CBA_fnc_addKeybind; +// make sure to stack effect layers in correct order +QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer; +QGVAR(GogglesLayer) call BIS_fnc_RSCLayer; - - - - -if isNil(QGVAR(UsePP)) then { +if (isNil QGVAR(UsePP)) then { GVAR(UsePP) = true; }; -GVAR(PostProcess) = ppEffectCreate ["ColorCorrections", 1995]; +// init pp effects +GVAR(PostProcess) = ppEffectCreate ["ColorCorrections", 1995]; GVAR(PostProcessEyes) = ppEffectCreate ["ColorCorrections", 1992]; -GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; +GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 0; GVAR(PostProcessEyes) ppEffectEnable false; + GVAR(EffectsActive) = false; + SETGLASSES(ace_player,GLASSESDEFAULT); + GVAR(Current) = "None"; GVAR(EyesDamageScript) = -1; GVAR(FrameEvent) = [false, [false,20]]; @@ -39,82 +42,66 @@ GVAR(RainLastLevel) = 0; GVAR(surfaceCache) = ""; GVAR(surfaceCacheIsDust) = false; -FUNC(CheckGlasses) = { - if (GVAR(Current) != (goggles ace_player)) then { - GVAR(Current) = (goggles ace_player); - ["GlassesChanged",[GVAR(Current)]] call EFUNC(common,localEvent); - }; -}; -player addEventHandler ["Explosion", { - private "_effects"; - if (alive ace_player) then { - call FUNC(applyDirtEffect); - if (GETBROKEN) exitWith {}; - if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; - if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; - _effects = GETGLASSES(ace_player); - _effects set [BROKEN, true]; - SETGLASSES(ace_player,_effects); - if (getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked") != "" && {cameraOn == ace_player}) then { - if (call FUNC(ExternalCamera)) exitWith {}; - if (isNull(GLASSDISPLAY)) then { - 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; - }; - (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked"); - }; - ["GlassesCracked",[ace_player]] call EFUNC(common,localEvent); - }; -}]; -player addEventHandler ["Killed",{ - GVAR(PostProcessEyes) ppEffectEnable false; - SETGLASSES(ace_player,GLASSESDEFAULT); - call FUNC(removeGlassesEffect); - GVAR(EffectsActive)=false; - ace_player setVariable ["ACE_EyesDamaged", false]; - if (GVAR(EyesDamageScript) != -1) then { - [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); - }; - if (GVAR(DustHandler) != -1) then { - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; - }; -}]; -player addEventHandler ["Fired",{[_this select 0, _this select 1] call FUNC(dustHandler);}]; -player AddEventHandler ["Take",{call FUNC(checkGlasses);}]; -player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; +// init GlassesChanged eventhandler +GVAR(OldGlasses) = "#NULLSTRING"; -["GlassesChanged",{ - SETGLASSES(ace_player,GLASSESDEFAULT); +["playerInventoryChanged", { + (_this select 1) params ["", "_currentGlasses"]; + + if (GVAR(OldGlasses) != _currentGlasses) then { + ["GlassesChanged", [ACE_player, _currentGlasses]] call EFUNC(common,localEvent); + GVAR(OldGlasses) = _currentGlasses; + }; +}] call EFUNC(common,addEventHandler); + +// add glasses eventhandlers +["GlassesChanged", { + params ["_unit", "_glasses"]; + + SETGLASSES(_unit,GLASSESDEFAULT); if (call FUNC(ExternalCamera)) exitWith {call FUNC(RemoveGlassesEffect)}; - if ([ace_player] call FUNC(isGogglesVisible)) then { - [_this select 0] call FUNC(applyGlassesEffect); + if ([_unit] call FUNC(isGogglesVisible)) then { + _glasses call FUNC(applyGlassesEffect); } else { call FUNC(removeGlassesEffect); }; }] call EFUNC(common,addEventHandler); -["GlassesCracked",{ - if (_this select 0 != ace_player) exitWith {}; - ace_player setVariable ["ACE_EyesDamaged", true]; - if (GVAR(EyesDamageScript) != -1) then { - [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); - }; - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [0.5,0.5,0.5,0.5],[1,1,1,0]]; + +["GlassesCracked", { + params ["_unit"]; + + _unit setVariable ["ACE_EyesDamaged", true]; + + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [0.5, 0.5, 0.5, 0.5], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 0; GVAR(PostProcessEyes) ppEffectEnable true; - GVAR(EyesDamageScript) = [{ - GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [1,1,1,1],[1,1,1,0]]; + + [{ + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 0]]; GVAR(PostProcessEyes) ppEffectCommit 5; + GVAR(EyesDamageScript) = [{ + params ["_unit"]; + GVAR(PostProcessEyes) ppEffectEnable false; - ace_player setVariable ["ACE_EyesDamaged", false]; - GVAR(EyesDamageScript) = -1; - }, [], 5, 1] call EFUNC(common,waitAndExecute); - }, [], 25, 5] call EFUNC(common,waitAndExecute); + + _unit setVariable ["ACE_EyesDamaged", false]; + + }, _this, 5] call EFUNC(common,waitAndExecute); + + }, _unit, 25] call EFUNC(common,waitAndExecute); + }] call EFUNC(common,addEventHandler); -call FUNC(checkGlasses); + + + + + + + [FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; [FUNC(applyRainEffect), 0.5, []] call CBA_fnc_addPerFrameHandler; [FUNC(onEachFrame), 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/functions/fnc_applyDirtEffect.sqf b/addons/goggles/functions/fnc_applyDirtEffect.sqf index b8aedd5e64..655fec2f59 100644 --- a/addons/goggles/functions/fnc_applyDirtEffect.sqf +++ b/addons/goggles/functions/fnc_applyDirtEffect.sqf @@ -31,7 +31,7 @@ if ([_unit] call FUNC(isGogglesVisible)) then { local _dirtImage = getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_OverlayDirt"); if (_dirtImage != "") then { - (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; // @todo init as 100 + (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 0.1, false]; (GETUVAR(GVAR(DisplayEffects),displayNull) displayCtrl 10660) ctrlSetText _dirtImage; }; }; diff --git a/addons/goggles/functions/fnc_applyDustEffect.sqf b/addons/goggles/functions/fnc_applyDustEffect.sqf index 6e89a8df6b..f281af8c3e 100644 --- a/addons/goggles/functions/fnc_applyDustEffect.sqf +++ b/addons/goggles/functions/fnc_applyDustEffect.sqf @@ -25,7 +25,7 @@ _unit = ACE_player; if ([_unit] call FUNC(isGogglesVisible)) exitWith { (QGVAR(GogglesEffectsLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_GogglesEffects", "PLAIN", 2, false]; - ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; + ((GETUVAR(GVAR(DisplayEffects),displayNull)) displayCtrl 10662) ctrlSetText format [getText (configFile >> "CfgGlasses" >> goggles _unit >> "ACE_DustPath"), GETDUSTT(DAMOUNT) + 1]; SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT) + 1,0,1)); SETDUST(DBULLETS,0); diff --git a/addons/goggles/functions/fnc_applyGlassesEffect.sqf b/addons/goggles/functions/fnc_applyGlassesEffect.sqf index a8ccf23633..aa0ecea6af 100644 --- a/addons/goggles/functions/fnc_applyGlassesEffect.sqf +++ b/addons/goggles/functions/fnc_applyGlassesEffect.sqf @@ -42,7 +42,7 @@ if (_postProcessTintAmount != 0 && {GVAR(UsePP)}) then { _imagePath = getText (_config >> ["ACE_Overlay", "ACE_OverlayCracked"] select GETBROKEN); if (_imagePath != "") then { - (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; // @todo init as 150 + (QGVAR(GogglesLayer) call BIS_fnc_RSCLayer) cutRsc ["RscACE_Goggles", "PLAIN", 1, false]; (GLASSDISPLAY displayCtrl 10650) ctrlSetText _imagePath; }; diff --git a/addons/goggles/functions/fnc_checkGoggles.sqf b/addons/goggles/functions/fnc_checkGoggles.sqf index 84b86c3da4..2d10515fc6 100644 --- a/addons/goggles/functions/fnc_checkGoggles.sqf +++ b/addons/goggles/functions/fnc_checkGoggles.sqf @@ -23,7 +23,7 @@ if (true) then { call FUNC(removeGlassesEffect); }; }; - call FUNC(checkGlasses); + //call FUNC(checkGlasses); if !([ace_player] call FUNC(isGogglesVisible)) exitWith { if (GVAR(EffectsActive)) then { call FUNC(removeGlassesEffect); diff --git a/addons/goggles/functions/fnc_handleExplosion.sqf b/addons/goggles/functions/fnc_handleExplosion.sqf index e69de29bb2..a47b2f14ba 100644 --- a/addons/goggles/functions/fnc_handleExplosion.sqf +++ b/addons/goggles/functions/fnc_handleExplosion.sqf @@ -0,0 +1,19 @@ +#include "script_component.hpp" + private "_effects"; + if (alive ace_player) then { + call FUNC(applyDirtEffect); + if (GETBROKEN) exitWith {}; + if (((_this select 1) call FUNC(GetExplosionIndex)) < getNumber(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Resistance")) exitWith {}; + if !([ace_player] call FUNC(isGogglesVisible)) exitWith {["GlassesCracked",[ace_player]] call EFUNC(common,localEvent);}; + _effects = GETGLASSES(ace_player); + _effects set [BROKEN, true]; + SETGLASSES(ace_player,_effects); + if (getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked") != "" && {cameraOn == ace_player}) then { + if (call FUNC(ExternalCamera)) exitWith {}; + if (isNull(GLASSDISPLAY)) then { + 150 cutRsc["RscACE_Goggles", "PLAIN",1, false]; + }; + (GLASSDISPLAY displayCtrl 10650) ctrlSetText getText(ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_OverlayCracked"); + }; + ["GlassesCracked",[ace_player]] call EFUNC(common,localEvent); + }; \ No newline at end of file diff --git a/addons/goggles/functions/fnc_handleFired.sqf b/addons/goggles/functions/fnc_handleFired.sqf index e69de29bb2..521418bea4 100644 --- a/addons/goggles/functions/fnc_handleFired.sqf +++ b/addons/goggles/functions/fnc_handleFired.sqf @@ -0,0 +1,2 @@ +#include "script_component.hpp" +[_this select 0, _this select 1] call FUNC(dustHandler); \ No newline at end of file diff --git a/addons/goggles/functions/fnc_handleKilled.sqf b/addons/goggles/functions/fnc_handleKilled.sqf index e69de29bb2..55dd926387 100644 --- a/addons/goggles/functions/fnc_handleKilled.sqf +++ b/addons/goggles/functions/fnc_handleKilled.sqf @@ -0,0 +1,13 @@ +#include "script_component.hpp" + GVAR(PostProcessEyes) ppEffectEnable false; + SETGLASSES(ace_player,GLASSESDEFAULT); + call FUNC(removeGlassesEffect); + GVAR(EffectsActive)=false; + ace_player setVariable ["ACE_EyesDamaged", false]; + if (GVAR(EyesDamageScript) != -1) then { + [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); + }; + if (GVAR(DustHandler) != -1) then { + [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; + }; \ No newline at end of file diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf index b3494d1290..d9181373a1 100644 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ b/addons/goggles/functions/fnc_onEachFrame.sqf @@ -53,7 +53,7 @@ if !(_safe) then { }; }; }; - _safe = (getNumber (ConfigFile >> "CfgGlasses" >> GVAR(Current) >> "ACE_Protection") == 1); + _safe = (getNumber (ConfigFile >> "CfgGlasses" >> goggles ace_player >> "ACE_Protection") == 1); }; if (_safe) exitWith {}; if ((_rotorWash select 1) <= 15) then {