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 2 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
9 changes: 9 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions addons/common/fnc_getActiveFeatureCamera.sqf
Original file line number Diff line number Diff line change
@@ -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) <STRING>

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);
40 changes: 40 additions & 0 deletions addons/common/fnc_registerFeatureCamera.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#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
};

(GVAR(featureCameras) pushBackUnique _this) != -1 // return
38 changes: 26 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 @@ -192,6 +200,12 @@ if (_id != -1) then {
GVAR(oldCameraView) = _data;
[QGVAR(cameraViewEvent), [_player, _data]] call CBA_fnc_localEvent;
};

_data = call CBA_fnc_getActiveFeatureCamera;
Copy link
Contributor

Choose a reason for hiding this comment

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

performance?
We might want to only add this when it's actually needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just a bunch of null checks (7 in vanilla). Aren't all Player EHs only added when they are needed already?

Copy link
Member Author

@jonpas jonpas Sep 14, 2018

Choose a reason for hiding this comment

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

0.0301 - 0.031 ms on 10k/10k cycles.

Copy link
Contributor

Choose a reason for hiding this comment

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

0.03 ouhhhh.
How about a check whether either the array of eventhandlers is not empty (by using the CBA internal variable name of the array)
Or check that GVAR(oldFeatureCamera is not nil? and set it to non nil once a Eventhandler is added in line 92?

Copy link
Member Author

Choose a reason for hiding this comment

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

That wouldn't work for cases where we might want to use internal variable (ref ACE PR).

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)}];
Expand Down
3 changes: 3 additions & 0 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 Down