PFHs only as needed

This commit is contained in:
SilentSpike 2015-07-24 19:02:27 +01:00
parent e2e6091c1f
commit c9750919a4
6 changed files with 57 additions and 39 deletions

View File

@ -19,11 +19,8 @@
params ["_display"]; params ["_display"];
// Kill PFH when display is closed // Kill PFH when compass hidden (or display is closed)
if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; if (isNil QGVAR(compHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Reduce overhead when compass is hidden
if !(ctrlShown (_display displayCtrl IDC_COMP)) exitWith {};
private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"]; private ["_compass","_NE","_ES","_SW","_WN","_compassW","_degree","_heading","_offset","_positions","_sequence"];

View File

@ -99,15 +99,9 @@ switch (toLower _mode) do {
// Always show interface and hide map upon opening // Always show interface and hide map upon opening
[_display,nil,nil,!GVAR(showInterface),GVAR(showMap)] call FUNC(toggleInterface); [_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; [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 // Populate the help splash
private "_help"; private "_help";
_help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST; _help = (_display displayCtrl IDC_HELP) controlsGroupCtrl IDC_HELP_LIST;
@ -159,6 +153,8 @@ switch (toLower _mode) do {
}; };
GVAR(camHandler) = nil; GVAR(camHandler) = nil;
GVAR(compHandler) = nil;
GVAR(toolHandler) = nil;
}; };
// Mouse events // Mouse events
case "onmousebuttondown": { case "onmousebuttondown": {
@ -183,9 +179,9 @@ switch (toLower _mode) do {
// Scroll to change speed, modifier for zoom // Scroll to change speed, modifier for zoom
if (GVAR(ctrlKey)) then { 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 { } 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": { case "onmousemoving": {

View File

@ -19,14 +19,8 @@
params ["_display"]; params ["_display"];
// Kill PFH when display is closed // Kill PFH when toolbar hidden (or display is closed)
if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; if (isNil QGVAR(toolHandler)) 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 {};
private ["_name","_vision","_fov","_speed","_mode","_time","_toolbar"]; private ["_name","_vision","_fov","_speed","_mode","_time","_toolbar"];
_toolbar = _display displayCtrl IDC_TOOL; _toolbar = _display displayCtrl IDC_TOOL;

View File

@ -16,8 +16,8 @@
* 3: Camera position (ATL) <ARRAY> <OPTIONAL> * 3: Camera position (ATL) <ARRAY> <OPTIONAL>
* 4: Camera pan (0 - 360) <NUMBER> <OPTIONAL> * 4: Camera pan (0 - 360) <NUMBER> <OPTIONAL>
* 5: Camera tilt (-90 - 90) <NUMBER> <OPTIONAL> * 5: Camera tilt (-90 - 90) <NUMBER> <OPTIONAL>
* 6: Camera zoom (0.1 - 2) <NUMBER> <OPTIONAL> * 6: Camera zoom (0.01 - 2) <NUMBER> <OPTIONAL>
* 7: Camera speed (m/s) <NUMBER> <OPTIONAL> * 7: Camera speed in m/s (0.05 - 10) <NUMBER> <OPTIONAL>
* *
* Return Value: * Return Value:
* None <NIL> * None <NIL>
@ -52,11 +52,11 @@ if !(_vision in GVAR(availableVisions)) then {
GVAR(camPan) = ((_heading % 360) max 0); GVAR(camPan) = ((_heading % 360) max 0);
GVAR(camPosition) = (ATLtoASL _position); GVAR(camPosition) = (ATLtoASL _position);
GVAR(camSpeed) = (_speed min 0.05) max 10; GVAR(camSpeed) = (_speed max 0.05) min 10;
GVAR(camTilt) = (_heading min -89) max 89; GVAR(camTilt) = (_heading max -89) min 89;
GVAR(camUnit) = _unit; GVAR(camUnit) = _unit;
GVAR(camVision) = _vision; GVAR(camVision) = _vision;
GVAR(camZoom) = (_zoom min 2) max 0; GVAR(camZoom) = (_zoom min 2) max 0.01;
// Apply if camera exists // Apply if camera exists
if !(isNil QGVAR(camera)) then { if !(isNil QGVAR(camera)) then {

View File

@ -24,6 +24,13 @@
params ["_display", ["_toggleComp",false], ["_toggleHelp",false], ["_toggleInterface",false], ["_toggleMap",false], ["_toggleTool",false], ["_toggleUnit",false]]; 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 // Map and help operate outside of interface
GVAR(showHelp) = [GVAR(showHelp), !GVAR(showHelp)] select _toggleHelp; GVAR(showHelp) = [GVAR(showHelp), !GVAR(showHelp)] select _toggleHelp;
GVAR(showMap) = [GVAR(showMap), !GVAR(showMap)] select _toggleMap; GVAR(showMap) = [GVAR(showMap), !GVAR(showMap)] select _toggleMap;
@ -34,18 +41,20 @@ if (GVAR(showMap) && _toggleHelp) then {
GVAR(showMap) = false; GVAR(showMap) = false;
}; };
(_display displayCtrl IDC_HELP) ctrlShow GVAR(showHelp); _help ctrlShow GVAR(showHelp);
(_display displayCtrl IDC_MAP) ctrlShow GVAR(showMap); _map ctrlShow GVAR(showMap);
if (GVAR(showMap)) then { if (GVAR(showMap)) then {
// When map is shown, temporarily hide interface to stop overlapping // When map is shown, temporarily hide interface to stop overlapping
{ {
(_display displayCtrl _x) ctrlShow false; _x ctrlShow false;
} forEach [IDC_COMP,IDC_HELP,IDC_TOOL,IDC_UNIT]; } forEach [_comp,_help,_tool,_unit];
// Centre map on camera/unit // Centre map on camera/unit upon opening
(_display displayCtrl IDC_MAP) ctrlMapAnimAdd [0, 0.5, [GVAR(camUnit),GVAR(camera)] select (GVAR(camMode) == 0)]; if (_toggleMap) then {
ctrlMapAnimCommit (_display displayCtrl IDC_MAP); _map ctrlMapAnimAdd [0, 0.5, [GVAR(camUnit),GVAR(camera)] select (GVAR(camMode) == 0)];
ctrlMapAnimCommit _map;
};
} else { } else {
// Can only toggle interface with map minimised // Can only toggle interface with map minimised
GVAR(showInterface) = [GVAR(showInterface), !GVAR(showInterface)] select _toggleInterface; 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(showTool) = [GVAR(showTool), !GVAR(showTool)] select _toggleTool;
GVAR(showUnit) = [GVAR(showUnit), !GVAR(showUnit)] select _toggleUnit; GVAR(showUnit) = [GVAR(showUnit), !GVAR(showUnit)] select _toggleUnit;
(_display displayCtrl IDC_COMP) ctrlShow GVAR(showComp); _comp ctrlShow GVAR(showComp);
(_display displayCtrl IDC_TOOL) ctrlShow GVAR(showTool); _tool ctrlShow GVAR(showTool);
(_display displayCtrl IDC_UNIT) ctrlShow GVAR(showUnit); _unit ctrlShow GVAR(showUnit);
} else { } else {
{ {
(_display displayCtrl _x) ctrlShow false; _x ctrlShow false;
} forEach [IDC_COMP,IDC_TOOL,IDC_UNIT]; } 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;
};

View File

@ -47,6 +47,10 @@ if (_newMode == 0) then { // Free
// Preserve camUnit value for consistency when manually changing view // Preserve camUnit value for consistency when manually changing view
GVAR(camera) cameraEffect ["internal", "back"]; 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 // Switch to camera to stop AI group chat
GVAR(camera) switchCamera "internal"; GVAR(camera) switchCamera "internal";
clearRadio; clearRadio;
@ -88,6 +92,11 @@ if (_newMode == 0) then { // Free
_newUnit switchCamera "external"; _newUnit switchCamera "external";
}; };
// Clear radio if group changed
if (group _newUnit != group GVAR(camUnit)) then {
clearRadio;
};
GVAR(camUnit) = _newUnit; GVAR(camUnit) = _newUnit;
// Terminate camera view // Terminate camera view