From 5ca1a2826fc86601032d54d00c06829f3adb9d0a Mon Sep 17 00:00:00 2001 From: jonpas Date: Fri, 14 Sep 2018 17:34:29 +0200 Subject: [PATCH 1/6] Add Feature Camera Player EH --- addons/common/CfgFunctions.hpp | 2 + addons/common/XEH_preInit.sqf | 9 +++++ addons/common/fnc_getActiveFeatureCamera.sqf | 40 +++++++++++++++++++ addons/common/fnc_registerFeatureCamera.sqf | 28 +++++++++++++ addons/events/fnc_addPlayerEventHandler.sqf | 38 ++++++++++++------ .../events/fnc_removePlayerEventHandler.sqf | 3 ++ 6 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 addons/common/fnc_getActiveFeatureCamera.sqf create mode 100644 addons/common/fnc_registerFeatureCamera.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 724832a77..b8724d694 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -27,6 +27,8 @@ class CfgFunctions { PATHTO_FNC(getMagazineIndex); PATHTO_FNC(currentMagazineIndex); PATHTO_FNC(setCallsign); + PATHTO_FNC(getActiveFeatureCamera); + PATHTO_FNC(registerFeatureCamera); }; class Soldiers { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 714379e19..911412a62 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -23,6 +23,15 @@ GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); // Initialize Components GVAR(groups) = [grpNull, grpNull, grpNull, grpNull, grpNull]; +GVAR(featureCameras) = [ + ["curator", {!isNull curatorCamera}], // Curator + ["nexus", {!isNull (missionNamespace getVariable ["BIS_EGSpectatorCamera_camera", objNull])}], // BIS Nexus Spectator + ["arsenal", {!isNull (uiNamespace getVariable ["BIS_fnc_arsenal_cam", objNull])}], // Arsenal camera + ["establishing", {!isNull (missionNamespace getVariable ["BIS_fnc_establishingShot_fakeUAV", objNull])}], // Establishing shot camera + ["splendid", {!isNull (missionNamespace getVariable ["BIS_fnc_camera_cam", objNull])}], // Splendid camera + ["animViewer", {!isNull (uiNamespace getVariable ["BIS_fnc_animViewer_cam", objNull])}], // Animation viewer camera + ["classic", {!isNull (missionNamespace getVariable ["BIS_DEBUG_CAM", objNull])}] // Classic camera +]; call COMPILE_FILE(init_gauss); call COMPILE_FILE(init_perFrameHandler); diff --git a/addons/common/fnc_getActiveFeatureCamera.sqf b/addons/common/fnc_getActiveFeatureCamera.sqf new file mode 100644 index 000000000..d2e580669 --- /dev/null +++ b/addons/common/fnc_getActiveFeatureCamera.sqf @@ -0,0 +1,40 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getActiveFeatureCamera + +Description: + Returns active feature camera. + + Checks for the following feature cameras: + - Curator + - Arsenal camera (BIS_fnc_arsenal) + - Nexus Spectator (BIS_fnc_EGSpectator) + - Establishing shot (BIS_fnc_establishingShot) + - Splendid camera (BIS_fnc_camera) + - Animation viewer (BIS_fnc_animViewer) + - Classic camera (BIS_fnc_cameraOld) + + And cameras registered via CBA_fnc_registerFeatureCamera. + +Parameters: + None + +Returns: + Active feature camera ("" if none) + +Examples: + (begin example) + _result = [] call CBA_fnc_getActiveFeatureCamera + (end) + +Author: + Sniperwolf572, Jonpas +---------------------------------------------------------------------------- */ +SCRIPT(getActiveFeatureCamera); + +{ + _x params ["_name", "_callback"]; + + if (call _callback) exitWith {_name}; + "" +} forEach GVAR(featureCameras); diff --git a/addons/common/fnc_registerFeatureCamera.sqf b/addons/common/fnc_registerFeatureCamera.sqf new file mode 100644 index 000000000..17e68d7f0 --- /dev/null +++ b/addons/common/fnc_registerFeatureCamera.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_registerFeatureCamera + +Description: + Registers a feature camera for use with CBA_fnc_getActiveFeatureCamera. + +Parameters: + _name - Name (unique/tagged) + _callback - Activity check (should return true if active, false otherwise) + +Returns: + None + +Examples: + (begin example) + _result = [ + "ace_spectator", + {!isNull (missionNamespace getVariable ["ace_spectator_isSet", objNull])} + ] call CBA_fnc_registerFeatureCamera + (end) + +Author: + Sniperwolf572, Jonpas +---------------------------------------------------------------------------- */ +SCRIPT(registerFeatureCamera); + +GVAR(featureCameras) pushBackUnique _this; diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 7543c9fa0..9a2fd4a99 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -6,20 +6,21 @@ Description: Adds a player event handler. Possible events: - "unit" - player controlled unit changed - "weapon" - currently selected weapon change - "loadout" - players loadout changed - "vehicle" - players current vehicle changed - "turret" - position in vehicle changed - "visionMode" - player changed to normal/night/thermal view - "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) - "visibleMap" - opened or closed map - "group" - player group changes - "leader" - leader of player changes + "unit" - player controlled unit changed + "weapon" - currently selected weapon change + "loadout" - players loadout changed + "vehicle" - players current vehicle changed + "turret" - position in vehicle changed + "visionMode" - player changed to normal/night/thermal view + "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) + "featureCamera" - camera changed (Curator, Arsenal, Spectator etc.) + "visibleMap" - opened or closed map + "group" - player group changes + "leader" - leader of player changes Parameters: - _type - Event handler type. - _function - Function to add to event. + _type - Event handler type. + _function - Function to add to event. _applyRetroactively - Call function immediately if player is defined already (optional, default: false) Returns: @@ -84,6 +85,12 @@ private _id = switch (_type) do { }; [QGVAR(cameraViewEvent), _function] call CBA_fnc_addEventHandler // return id }; + case "featurecamera": { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), call CBA_fnc_getActiveFeatureCamera] call _function; + }; + [QGVAR(featureCameraEvent), _function] call CBA_fnc_addEventHandler // return id + }; case "visiblemap": { if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), visibleMap] call _function; @@ -120,6 +127,7 @@ if (_id != -1) then { GVAR(oldTurret) = []; GVAR(oldVisionMode) = -1; GVAR(oldCameraView) = ""; + GVAR(oldFeatureCamera) = ""; GVAR(oldVisibleMap) = false; GVAR(playerEHInfo) pushBack addMissionEventHandler ["EachFrame", {call FUNC(playerEH_EachFrame)}]; @@ -192,6 +200,12 @@ if (_id != -1) then { GVAR(oldCameraView) = _data; [QGVAR(cameraViewEvent), [_player, _data]] call CBA_fnc_localEvent; }; + + _data = call CBA_fnc_getActiveFeatureCamera; + if !(_data isEqualTo GVAR(oldFeatureCamera)) then { + GVAR(oldFeatureCamera) = _data; + [QGVAR(featureCameraEvent), [_player, _data]] call CBA_fnc_localEvent; + }; }] call CBA_fnc_compileFinal; GVAR(playerEHInfo) pushBack addMissionEventHandler ["Map", {call FUNC(playerEH_Map)}]; diff --git a/addons/events/fnc_removePlayerEventHandler.sqf b/addons/events/fnc_removePlayerEventHandler.sqf index 35e98f96a..9bd7c3410 100644 --- a/addons/events/fnc_removePlayerEventHandler.sqf +++ b/addons/events/fnc_removePlayerEventHandler.sqf @@ -48,6 +48,9 @@ switch (_type) do { case "cameraview": { [QGVAR(cameraViewEvent), _id] call CBA_fnc_removeEventHandler; }; + case "featurecamera": { + [QGVAR(featureCameraEvent), _id] call CBA_fnc_removeEventHandler; + }; case "visiblemap": { [QGVAR(visibleMapEvent), _id] call CBA_fnc_removeEventHandler; }; From 99f32e7bbf067cac5b1b07d4384e76f6224c86f4 Mon Sep 17 00:00:00 2001 From: jonpas Date: Fri, 14 Sep 2018 18:25:21 +0200 Subject: [PATCH 2/6] Add argument verification to registerFeatureCamera --- addons/common/fnc_registerFeatureCamera.sqf | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/common/fnc_registerFeatureCamera.sqf b/addons/common/fnc_registerFeatureCamera.sqf index 17e68d7f0..4c67ecff1 100644 --- a/addons/common/fnc_registerFeatureCamera.sqf +++ b/addons/common/fnc_registerFeatureCamera.sqf @@ -10,7 +10,7 @@ Parameters: _callback - Activity check (should return true if active, false otherwise) Returns: - None + Successfully registered Examples: (begin example) @@ -25,4 +25,16 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(registerFeatureCamera); -GVAR(featureCameras) pushBackUnique _this; +params [["_name", "", [""]], ["_callback", false, [{}]]]; + +if (_name isEqualTo "") exitWith { + TRACE_1("Name empty",_name); + false +}; + +if (_callback isEqualTo false) exitWith { + TRACE_1("Callback not code",_name); + false +}; + +(GVAR(featureCameras) pushBackUnique _this) != -1 // return From 9e07b1c82db036602ea0923ad0ca425ef912f4c1 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 14 Sep 2018 12:00:56 -0500 Subject: [PATCH 3/6] Optimize CBA_fnc_getActiveFeatureCamera --- addons/common/XEH_preInit.sqf | 25 +++++++++++++------- addons/common/fnc_getActiveFeatureCamera.sqf | 7 +----- addons/common/fnc_registerFeatureCamera.sqf | 5 +++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 911412a62..d927fc36a 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -23,14 +23,23 @@ GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); // Initialize Components GVAR(groups) = [grpNull, grpNull, grpNull, grpNull, grpNull]; -GVAR(featureCameras) = [ - ["curator", {!isNull curatorCamera}], // Curator - ["nexus", {!isNull (missionNamespace getVariable ["BIS_EGSpectatorCamera_camera", objNull])}], // BIS Nexus Spectator - ["arsenal", {!isNull (uiNamespace getVariable ["BIS_fnc_arsenal_cam", objNull])}], // Arsenal camera - ["establishing", {!isNull (missionNamespace getVariable ["BIS_fnc_establishingShot_fakeUAV", objNull])}], // Establishing shot camera - ["splendid", {!isNull (missionNamespace getVariable ["BIS_fnc_camera_cam", objNull])}], // Splendid camera - ["animViewer", {!isNull (uiNamespace getVariable ["BIS_fnc_animViewer_cam", objNull])}], // Animation viewer camera - ["classic", {!isNull (missionNamespace getVariable ["BIS_DEBUG_CAM", objNull])}] // Classic camera +GVAR(featureCamerasCode) = [ + {!isNull curatorCamera}, // Curator + {!isNull (missionNamespace getVariable ["BIS_EGSpectatorCamera_camera", objNull])}, // BIS Nexus Spectator + {!isNull (uiNamespace getVariable ["BIS_fnc_arsenal_cam", objNull])}, // Arsenal camera + {!isNull (missionNamespace getVariable ["BIS_fnc_establishingShot_fakeUAV", objNull])}, // Establishing shot camera + {!isNull (missionNamespace getVariable ["BIS_fnc_camera_cam", objNull])}, // Splendid camera + {!isNull (uiNamespace getVariable ["BIS_fnc_animViewer_cam", objNull])}, // Animation viewer camera + {!isNull (missionNamespace getVariable ["BIS_DEBUG_CAM", objNull])} // Classic camera +]; +GVAR(featureCamerasNames) = [ + "curator", // Curator + "nexus", // BIS Nexus Spectator + "arsenal", // Arsenal camera + "establishing", // Establishing shot camera + "splendid", // Splendid camera + "animViewer", // Animation viewer camera + "classic" // Classic camera ]; call COMPILE_FILE(init_gauss); diff --git a/addons/common/fnc_getActiveFeatureCamera.sqf b/addons/common/fnc_getActiveFeatureCamera.sqf index d2e580669..a35c35156 100644 --- a/addons/common/fnc_getActiveFeatureCamera.sqf +++ b/addons/common/fnc_getActiveFeatureCamera.sqf @@ -32,9 +32,4 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(getActiveFeatureCamera); -{ - _x params ["_name", "_callback"]; - - if (call _callback) exitWith {_name}; - "" -} forEach GVAR(featureCameras); +GVAR(featureCamerasNames) param [GVAR(featureCamerasCode) findIf {call _x}, "none"] diff --git a/addons/common/fnc_registerFeatureCamera.sqf b/addons/common/fnc_registerFeatureCamera.sqf index 4c67ecff1..3aa2c0da5 100644 --- a/addons/common/fnc_registerFeatureCamera.sqf +++ b/addons/common/fnc_registerFeatureCamera.sqf @@ -37,4 +37,7 @@ if (_callback isEqualTo false) exitWith { false }; -(GVAR(featureCameras) pushBackUnique _this) != -1 // return +GVAR(featureCamerasNames) pushBack _name; +GVAR(featureCamerasCode) pushBack _callback; + +true From 2289585587881a7627e4409b9f144400d4c21f8b Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 14 Sep 2018 12:09:53 -0500 Subject: [PATCH 4/6] fixes --- addons/common/fnc_getActiveFeatureCamera.sqf | 2 +- addons/common/fnc_registerFeatureCamera.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/fnc_getActiveFeatureCamera.sqf b/addons/common/fnc_getActiveFeatureCamera.sqf index a35c35156..965b22801 100644 --- a/addons/common/fnc_getActiveFeatureCamera.sqf +++ b/addons/common/fnc_getActiveFeatureCamera.sqf @@ -32,4 +32,4 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(getActiveFeatureCamera); -GVAR(featureCamerasNames) param [GVAR(featureCamerasCode) findIf {call _x}, "none"] +GVAR(featureCamerasNames) param [GVAR(featureCamerasCode) findIf {call _x}, ""] diff --git a/addons/common/fnc_registerFeatureCamera.sqf b/addons/common/fnc_registerFeatureCamera.sqf index 3aa2c0da5..06746579c 100644 --- a/addons/common/fnc_registerFeatureCamera.sqf +++ b/addons/common/fnc_registerFeatureCamera.sqf @@ -37,7 +37,7 @@ if (_callback isEqualTo false) exitWith { false }; -GVAR(featureCamerasNames) pushBack _name; +if ((GVAR(featureCamerasNames) pushBackUnique _name) == -1) exitWith {false}; GVAR(featureCamerasCode) pushBack _callback; true From 86966872be441885e7cd2f2b3476b6b2b89f4c32 Mon Sep 17 00:00:00 2001 From: jonpas Date: Mon, 17 Sep 2018 14:49:06 +0200 Subject: [PATCH 5/6] Run feature camera player EH only every 0.5s --- addons/events/fnc_addPlayerEventHandler.sqf | 15 +++++++++------ addons/events/fnc_removePlayerEventHandler.sqf | 9 +++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 9a2fd4a99..772b464c4 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -200,12 +200,6 @@ if (_id != -1) then { GVAR(oldCameraView) = _data; [QGVAR(cameraViewEvent), [_player, _data]] call CBA_fnc_localEvent; }; - - _data = call CBA_fnc_getActiveFeatureCamera; - if !(_data isEqualTo GVAR(oldFeatureCamera)) then { - GVAR(oldFeatureCamera) = _data; - [QGVAR(featureCameraEvent), [_player, _data]] call CBA_fnc_localEvent; - }; }] call CBA_fnc_compileFinal; GVAR(playerEHInfo) pushBack addMissionEventHandler ["Map", {call FUNC(playerEH_Map)}]; @@ -228,6 +222,15 @@ if (_id != -1) then { }; } call CBA_fnc_directCall; }; + + GVAR(playerEHInfo) pushBack ([{call FUNC(playerEH_HalfSecond)}, 0.5] call CBA_fnc_addPerFrameHandler); + [QFUNC(playerEH_HalfSecond), { + private _data = call CBA_fnc_getActiveFeatureCamera; + if !(_data isEqualTo GVAR(oldFeatureCamera)) then { + GVAR(oldFeatureCamera) = _data; + [QGVAR(featureCameraEvent), [call CBA_fnc_currentUnit, _data]] call CBA_fnc_localEvent; + }; + }] call CBA_fnc_compileFinal; }; GVAR(playerEHInfo) pushBack [_type, _id]; diff --git a/addons/events/fnc_removePlayerEventHandler.sqf b/addons/events/fnc_removePlayerEventHandler.sqf index 9bd7c3410..a24e18502 100644 --- a/addons/events/fnc_removePlayerEventHandler.sqf +++ b/addons/events/fnc_removePlayerEventHandler.sqf @@ -66,12 +66,13 @@ switch (_type) do { if (!isNil QGVAR(playerEHInfo)) then { GVAR(playerEHInfo) deleteAt (GVAR(playerEHInfo) find [_type, _id]); - // First two entries are mission eventhandler ids. Rest are framework - // specific ids in array form. If all playerChanged eventhandlers were - // removed, then also clean up the mission eventhandlers. - if (count GVAR(playerEHInfo) == 2) then { + // First two entries are Mission EH IDs, third is PFH ID. Rest are framework + // specific IDs in array form. If all playerChanged eventhandlers were + // removed, then also clean up the Mission EHs and PFHs. + if (count GVAR(playerEHInfo) == 3) then { removeMissionEventHandler ["EachFrame", GVAR(playerEHInfo) select 0]; removeMissionEventHandler ["Map", GVAR(playerEHInfo) select 1]; + [GVAR(playerEHInfo) select 2] call CBA_fnc_removePerFrameHandler; GVAR(playerEHInfo) = nil; }; }; From 55f5e2eb174632230cc62cee70bd3316b552fbb8 Mon Sep 17 00:00:00 2001 From: jonpas Date: Mon, 17 Sep 2018 15:55:56 +0200 Subject: [PATCH 6/6] Don't compile final a PFH function --- addons/events/fnc_addPlayerEventHandler.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 772b464c4..c3e22fbae 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -223,14 +223,14 @@ if (_id != -1) then { } call CBA_fnc_directCall; }; - GVAR(playerEHInfo) pushBack ([{call FUNC(playerEH_HalfSecond)}, 0.5] call CBA_fnc_addPerFrameHandler); - [QFUNC(playerEH_HalfSecond), { + GVAR(playerEHInfo) pushBack ([{ private _data = call CBA_fnc_getActiveFeatureCamera; if !(_data isEqualTo GVAR(oldFeatureCamera)) then { GVAR(oldFeatureCamera) = _data; [QGVAR(featureCameraEvent), [call CBA_fnc_currentUnit, _data]] call CBA_fnc_localEvent; }; - }] call CBA_fnc_compileFinal; + }, 0.5] call CBA_fnc_addPerFrameHandler); + }; GVAR(playerEHInfo) pushBack [_type, _id];