From c9750919a4ed67bed14ef424ff0aa44ea909c72a Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 24 Jul 2015 19:02:27 +0100 Subject: [PATCH] PFHs only as needed --- .../spectator/functions/fnc_handleCompass.sqf | 7 +-- .../functions/fnc_handleInterface.sqf | 14 ++---- .../spectator/functions/fnc_handleToolbar.sqf | 10 +--- .../functions/fnc_setCameraAttributes.sqf | 10 ++-- .../functions/fnc_toggleInterface.sqf | 46 ++++++++++++++----- .../functions/fnc_transitionCamera.sqf | 9 ++++ 6 files changed, 57 insertions(+), 39 deletions(-) diff --git a/addons/spectator/functions/fnc_handleCompass.sqf b/addons/spectator/functions/fnc_handleCompass.sqf index caa29b06d7..a65cc9ddce 100644 --- a/addons/spectator/functions/fnc_handleCompass.sqf +++ b/addons/spectator/functions/fnc_handleCompass.sqf @@ -19,11 +19,8 @@ params ["_display"]; -// Kill PFH when display is closed -if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; - -// Reduce overhead when compass is hidden -if !(ctrlShown (_display displayCtrl IDC_COMP)) exitWith {}; +// Kill PFH when compass hidden (or display is closed) +if (isNil QGVAR(compHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"]; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index cb0c396393..10773d61fa 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -99,15 +99,9 @@ switch (toLower _mode) do { // Always show interface and hide map upon opening [_display,nil,nil,!GVAR(showInterface),GVAR(showMap)] call FUNC(toggleInterface); - // Keep unit tree up to date + // Keep unit list and tree up to date [FUNC(handleUnits), 21, _display] call CBA_fnc_addPerFrameHandler; - // Handle the compass heading - [FUNC(handleCompass), 0, _display] call CBA_fnc_addPerFrameHandler; - - // Handle the toolbar values - [FUNC(handleToolbar), 0, _display] call CBA_fnc_addPerFrameHandler; - // Populate the help splash private "_help"; _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST; @@ -159,6 +153,8 @@ switch (toLower _mode) do { }; GVAR(camHandler) = nil; + GVAR(compHandler) = nil; + GVAR(toolHandler) = nil; }; // Mouse events case "onmousebuttondown": { @@ -183,9 +179,9 @@ switch (toLower _mode) do { // Scroll to change speed, modifier for zoom if (GVAR(ctrlKey)) then { - GVAR(camZoom) = ((GVAR(camZoom) + _zChange * 0.1) max 0.01) min 2; + [nil,nil,nil,nil,nil,nil, GVAR(camZoom) + _zChange * 0.1] call FUNC(setCameraAttributes); } else { - GVAR(camSpeed) = ((GVAR(camSpeed) + _zChange * 0.2) max 0.05) min 10; + [nil,nil,nil,nil,nil,nil,nil, GVAR(camSpeed) + _zChange * 0.2] call FUNC(setCameraAttributes); }; }; case "onmousemoving": { diff --git a/addons/spectator/functions/fnc_handleToolbar.sqf b/addons/spectator/functions/fnc_handleToolbar.sqf index 3528edbb03..58ed926f10 100644 --- a/addons/spectator/functions/fnc_handleToolbar.sqf +++ b/addons/spectator/functions/fnc_handleToolbar.sqf @@ -19,14 +19,8 @@ params ["_display"]; -// Kill PFH when display is closed -if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; - -GVAR(camera) camSetFov -(linearConversion [0.1,2,GVAR(camZoom),-2,-0.1,true]); -GVAR(camera) camCommit 0; - -// Reduce overhead when toolbar is hidden -if !(ctrlShown (_display displayCtrl IDC_TOOL)) exitWith {}; +// Kill PFH when toolbar hidden (or display is closed) +if (isNil QGVAR(toolHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; private ["_name","_vision","_fov","_speed","_mode","_time","_toolbar"]; _toolbar = _display displayCtrl IDC_TOOL; diff --git a/addons/spectator/functions/fnc_setCameraAttributes.sqf b/addons/spectator/functions/fnc_setCameraAttributes.sqf index c447c81047..73ae55111b 100644 --- a/addons/spectator/functions/fnc_setCameraAttributes.sqf +++ b/addons/spectator/functions/fnc_setCameraAttributes.sqf @@ -16,8 +16,8 @@ * 3: Camera position (ATL) * 4: Camera pan (0 - 360) * 5: Camera tilt (-90 - 90) - * 6: Camera zoom (0.1 - 2) - * 7: Camera speed (m/s) + * 6: Camera zoom (0.01 - 2) + * 7: Camera speed in m/s (0.05 - 10) * * Return Value: * None @@ -52,11 +52,11 @@ if !(_vision in GVAR(availableVisions)) then { GVAR(camPan) = ((_heading % 360) max 0); GVAR(camPosition) = (ATLtoASL _position); -GVAR(camSpeed) = (_speed min 0.05) max 10; -GVAR(camTilt) = (_heading min -89) max 89; +GVAR(camSpeed) = (_speed max 0.05) min 10; +GVAR(camTilt) = (_heading max -89) min 89; GVAR(camUnit) = _unit; GVAR(camVision) = _vision; -GVAR(camZoom) = (_zoom min 2) max 0; +GVAR(camZoom) = (_zoom min 2) max 0.01; // Apply if camera exists if !(isNil QGVAR(camera)) then { diff --git a/addons/spectator/functions/fnc_toggleInterface.sqf b/addons/spectator/functions/fnc_toggleInterface.sqf index cd4563f7f0..4230040762 100644 --- a/addons/spectator/functions/fnc_toggleInterface.sqf +++ b/addons/spectator/functions/fnc_toggleInterface.sqf @@ -24,6 +24,13 @@ params ["_display", ["_toggleComp",false], ["_toggleHelp",false], ["_toggleInterface",false], ["_toggleMap",false], ["_toggleTool",false], ["_toggleUnit",false]]; +private ["_comp","_display","_help","_map","_tool","_unit"]; +_comp = _display displayCtrl IDC_COMP; +_help = _display displayCtrl IDC_HELP; +_map = _display displayCtrl IDC_MAP; +_tool = _display displayCtrl IDC_TOOL; +_unit = _display displayCtrl IDC_UNIT; + // Map and help operate outside of interface GVAR(showHelp) = [GVAR(showHelp), !GVAR(showHelp)] select _toggleHelp; GVAR(showMap) = [GVAR(showMap), !GVAR(showMap)] select _toggleMap; @@ -34,18 +41,20 @@ if (GVAR(showMap) && _toggleHelp) then { GVAR(showMap) = false; }; -(_display displayCtrl IDC_HELP) ctrlShow GVAR(showHelp); -(_display displayCtrl IDC_MAP) ctrlShow GVAR(showMap); +_help ctrlShow GVAR(showHelp); +_map ctrlShow GVAR(showMap); if (GVAR(showMap)) then { // When map is shown, temporarily hide interface to stop overlapping { - (_display displayCtrl _x) ctrlShow false; - } forEach [IDC_COMP,IDC_HELP,IDC_TOOL,IDC_UNIT]; + _x ctrlShow false; + } forEach [_comp,_help,_tool,_unit]; - // Centre map on camera/unit - (_display displayCtrl IDC_MAP) ctrlMapAnimAdd [0, 0.5, [GVAR(camUnit),GVAR(camera)] select (GVAR(camMode) == 0)]; - ctrlMapAnimCommit (_display displayCtrl IDC_MAP); + // Centre map on camera/unit upon opening + if (_toggleMap) then { + _map ctrlMapAnimAdd [0, 0.5, [GVAR(camUnit),GVAR(camera)] select (GVAR(camMode) == 0)]; + ctrlMapAnimCommit _map; + }; } else { // Can only toggle interface with map minimised GVAR(showInterface) = [GVAR(showInterface), !GVAR(showInterface)] select _toggleInterface; @@ -56,12 +65,25 @@ if (GVAR(showMap)) then { GVAR(showTool) = [GVAR(showTool), !GVAR(showTool)] select _toggleTool; GVAR(showUnit) = [GVAR(showUnit), !GVAR(showUnit)] select _toggleUnit; - (_display displayCtrl IDC_COMP) ctrlShow GVAR(showComp); - (_display displayCtrl IDC_TOOL) ctrlShow GVAR(showTool); - (_display displayCtrl IDC_UNIT) ctrlShow GVAR(showUnit); + _comp ctrlShow GVAR(showComp); + _tool ctrlShow GVAR(showTool); + _unit ctrlShow GVAR(showUnit); } else { { - (_display displayCtrl _x) ctrlShow false; - } forEach [IDC_COMP,IDC_TOOL,IDC_UNIT]; + _x ctrlShow false; + } forEach [_comp,_tool,_unit]; }; }; + +// Only run PFHs for toolbar and compass when respective control is shown, otherwise kill +if (ctrlShown _comp) then { + if (isNil QGVAR(compHandler)) then { GVAR(compHandler) = [FUNC(handleCompass), 0] call CBA_fnc_addPerFrameHandler; }; +} else { + GVAR(compHandler) = nil; +}; + +if (ctrlShown _tool) then { + if (isNil QGVAR(toolHandler)) then { GVAR(toolHandler) = [FUNC(handleToolbar), 0] call CBA_fnc_addPerFrameHandler; }; +} else { + GVAR(toolHandler) = nil; +}; diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index f65341c241..a6a5d710ca 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -47,6 +47,10 @@ if (_newMode == 0) then { // Free // Preserve camUnit value for consistency when manually changing view GVAR(camera) cameraEffect ["internal", "back"]; + // Apply the camera zoom + GVAR(camera) camSetFov -(linearConversion [0.01,2,GVAR(camZoom),-2,-0.01,true]); + GVAR(camera) camCommit 0; + // Switch to camera to stop AI group chat GVAR(camera) switchCamera "internal"; clearRadio; @@ -88,6 +92,11 @@ if (_newMode == 0) then { // Free _newUnit switchCamera "external"; }; + // Clear radio if group changed + if (group _newUnit != group GVAR(camUnit)) then { + clearRadio; + }; + GVAR(camUnit) = _newUnit; // Terminate camera view