Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Feature Camera Player EH #982

Merged
merged 6 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CfgFunctions {
PATHTO_FNC(getMagazineIndex);
PATHTO_FNC(currentMagazineIndex);
PATHTO_FNC(setCallsign);
PATHTO_FNC(getActiveFeatureCamera);
PATHTO_FNC(registerFeatureCamera);
};

class Soldiers {
Expand Down
18 changes: 18 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm));

// Initialize Components
GVAR(groups) = [grpNull, grpNull, grpNull, grpNull, grpNull];
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);
call COMPILE_FILE(init_perFrameHandler);
Expand Down
35 changes: 35 additions & 0 deletions addons/common/fnc_getActiveFeatureCamera.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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) <STRING>

Examples:
(begin example)
_result = [] call CBA_fnc_getActiveFeatureCamera
(end)

Author:
Sniperwolf572, Jonpas
---------------------------------------------------------------------------- */
SCRIPT(getActiveFeatureCamera);

GVAR(featureCamerasNames) param [GVAR(featureCamerasCode) findIf {call _x}, ""]
43 changes: 43 additions & 0 deletions addons/common/fnc_registerFeatureCamera.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_registerFeatureCamera

Description:
Registers a feature camera for use with CBA_fnc_getActiveFeatureCamera.

Parameters:
_name - Name (unique/tagged) <STRING>
_callback - Activity check (should return true if active, false otherwise) <CODE>

Returns:
Successfully registered <BOOL>

Examples:
(begin example)
_result = [
"ace_spectator",
{!isNull (missionNamespace getVariable ["ace_spectator_isSet", objNull])}
] call CBA_fnc_registerFeatureCamera
(end)

Author:
Sniperwolf572, Jonpas
---------------------------------------------------------------------------- */
SCRIPT(registerFeatureCamera);

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
};

if ((GVAR(featureCamerasNames) pushBackUnique _name) == -1) exitWith {false};
GVAR(featureCamerasCode) pushBack _callback;

true
41 changes: 29 additions & 12 deletions addons/events/fnc_addPlayerEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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. <STRING>
_function - Function to add to event. <CODE>
_type - Event handler type. <STRING>
_function - Function to add to event. <CODE>
_applyRetroactively - Call function immediately if player is defined already (optional, default: false) <BOOL>

Returns:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)}];
Expand Down Expand Up @@ -214,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to compileFinal this. It is only done for Map, because it is a mission event handler and therefore affected by the recompiled-every-execution-bug. That however does not apply to CBA PFH.

};

GVAR(playerEHInfo) pushBack [_type, _id];
Expand Down
12 changes: 8 additions & 4 deletions addons/events/fnc_removePlayerEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -63,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;
};
};
Expand Down