diff --git a/addons/optics/XEH_postInit.sqf b/addons/optics/XEH_postInit.sqf index 44e59a4074..a4f118619b 100644 --- a/addons/optics/XEH_postInit.sqf +++ b/addons/optics/XEH_postInit.sqf @@ -5,30 +5,9 @@ if (!hasInterface) exitWith {}; GVAR(camera) = objNull; -0 = 0 spawn { - // Workarround for the ThreeDen Editor Camera - if ((!isNil {is3DEN}) && {is3DEN}) exitWith { - ACE_LOGINFO("Eden detected: disabling Optics PIP Camera"); - }; - - waitUntil {!isNull ACE_player}; - waitUntil {sleep 1; {_x != GVAR(camera)} count allMissionObjects "camera" == 0 && {isNull curatorCamera}}; - - GVAR(camera) cameraEffect ["TERMINATE", "BACK"]; - camDestroy GVAR(camera); - - // PiP technique by BadBenson - GVAR(camera) = "camera" camCreate positionCameraToWorld [0,0,0]; - GVAR(camera) camSetFov 0.7; - GVAR(camera) camSetTarget ACE_player; - GVAR(camera) camCommit 1; - - "ace_optics_rendertarget0" setPiPEffect [0]; - GVAR(camera) cameraEffect ["INTERNAL", "BACK", "ace_optics_rendertarget0"]; -}; - // save control for fired EH ["ace_infoDisplayChanged", { + TRACE_1("ace_infoDisplayChanged",_this); if (!isNull ((_this select 0) displayCtrl 1713001)) then { uiNamespace setVariable [QGVAR(RscWeaponInfo2D), _this select 0]; }; @@ -36,18 +15,15 @@ GVAR(camera) = objNull; // camera has to be re-created every time another camera is created. Otherwise r2t is either black or transparent. @todo Add popular custom cameras to the event in ACE_common. ["ace_activeCameraChanged", { - if !(_this select 1) then { - GVAR(camera) cameraEffect ["TERMINATE", "BACK"]; - camDestroy GVAR(camera); - - // PiP technique by BadBenson - GVAR(camera) = "camera" camCreate positionCameraToWorld [0,0,0]; - GVAR(camera) camSetFov 0.7; - GVAR(camera) camSetTarget ACE_player; - GVAR(camera) camCommit 1; - - "ace_optics_rendertarget0" setPiPEffect [0]; - GVAR(camera) cameraEffect ["INTERNAL", "BACK", "ace_optics_rendertarget0"]; + params ["", "_isfeatureCameraActive"]; + TRACE_1("ace_activeCameraChanged",_isfeatureCameraActive); + if (!_isfeatureCameraActive) then { + //Destroy the camera, and it will be re-created in the onDrawScope2d helper + if (!isNull GVAR(camera)) then { + GVAR(camera) cameraEffect ["TERMINATE", "BACK"]; + camDestroy GVAR(camera); + TRACE_1("destroying pip camera for restart",GVAR(camera)); + }; }; }] call CBA_fnc_addEventHandler; diff --git a/addons/optics/functions/fnc_handleFired.sqf b/addons/optics/functions/fnc_handleFired.sqf index 299b2c30f4..2a740ac54d 100644 --- a/addons/optics/functions/fnc_handleFired.sqf +++ b/addons/optics/functions/fnc_handleFired.sqf @@ -16,8 +16,7 @@ TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret); // check if compatible scope is used -private "_display"; -_display = uiNamespace getVariable [QGVAR(RscWeaponInfo2D), displayNull]; +private _display = uiNamespace getVariable [QGVAR(RscWeaponInfo2D), displayNull]; if (isNull _display) exitWith {}; diff --git a/addons/optics/functions/fnc_onDrawScope2D.sqf b/addons/optics/functions/fnc_onDrawScope2D.sqf index 82602842ca..6e8ba739d8 100644 --- a/addons/optics/functions/fnc_onDrawScope2D.sqf +++ b/addons/optics/functions/fnc_onDrawScope2D.sqf @@ -1,12 +1,59 @@ -// by commy2 +/* + * Author: commy2 + * Helper function for updating the 2d and 3d scope controls + * Called from a dummy map controls onDraw. + * + * Arguments: + * 0: Display (RscInGameUI for a weapon) + * + * Return Value: + * Nothing + * + * Example: + * [ACE_RscWeapon_Arco's Display] call ace_optics_fnc_onDrawScope2D + * + * Public: No + */ #include "script_component.hpp" disableSerialization; -private "_display"; +private _display = _this select 0; -_display = _this select 0; +// @todo, all weapon types +private _optic = (primaryWeaponItems ACE_player) select 2; +private _isPIP = (getText (configFile >> "CfgWeapons" >> _optic >> "ItemInfo" >> "modelOptics")) == QPATHTOF(models\ace_optics_pip.p3d); +if (_isPIP) then { + GVAR(pipLastFrame) = diag_frameno; + if (isNull GVAR(camera)) then { + if ((({_x != GVAR(camera)} count allMissionObjects "camera") > 0) || {!isNull curatorCamera}) exitWith { + TRACE_1("waiting for feature camera to end",GVAR(camera)); + }; + + // PiP technique by BadBenson + GVAR(camera) = "camera" camCreate positionCameraToWorld [0,0,0]; + GVAR(camera) camSetFov 0.7; + GVAR(camera) camSetTarget ACE_player; + GVAR(camera) camCommit 1; + + "ace_optics_rendertarget0" setPiPEffect [0]; + GVAR(camera) cameraEffect ["INTERNAL", "BACK", "ace_optics_rendertarget0"]; + + TRACE_2("created new pip camera",GVAR(camera),isNull GVAR(camera)); + + //Start a waitUntil to handle destruction after GVAR(pipLastFrame) is no longer updated + [{ + (abs (diag_frameno - GVAR(pipLastFrame))) > 1 + }, { + GVAR(camera) cameraEffect ["TERMINATE", "BACK"]; + camDestroy GVAR(camera); + TRACE_2("destroyed pip camera",GVAR(camera),isNull GVAR(camera)); + }, []] call CBA_fnc_waitUntilAndExecute; + }; +}; + +//If we are not zoomed into the actual scope (not collimator) if (!ctrlShown (_display displayCtrl 154)) exitWith { (_display displayCtrl 1713001) ctrlShow false; (_display displayCtrl 1713002) ctrlShow false; @@ -16,11 +63,6 @@ if (!ctrlShown (_display displayCtrl 154)) exitWith { (_display displayCtrl 1713011) ctrlShow false; }; -// @todo, all weapon types -private ["_optic", "_isPIP"]; -_optic = (primaryWeaponItems ACE_player) select 2; -_isPIP = (getText (configFile >> "CfgWeapons" >> _optic >> "ItemInfo" >> "modelOptics")) == QPATHTOF(models\ace_optics_pip.p3d); - if (_isPIP) then { GVAR(camera) setPosATL positionCameraToWorld [0,0,0.4]; GVAR(camera) camPrepareTarget positionCameraToWorld [0,0,50]; @@ -37,10 +79,8 @@ if (_isPIP) then { }; // calculate lighting -private ["_dayOpacity", "_nightOpacity"]; - -_dayOpacity = call EFUNC(common,ambientBrightness); -_nightOpacity = [1,0] select (_dayOpacity == 1); +private _dayOpacity = call EFUNC(common,ambientBrightness); +private _nightOpacity = [1,0] select (_dayOpacity == 1); // Apply lighting and make layers visible (_display displayCtrl 1713001) ctrlSetTextColor [1,1,1,1];