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

Cache Nametags onDraw3D flags. #4847

Merged
merged 5 commits into from
Feb 10, 2017
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
1 change: 1 addition & 0 deletions addons/nametags/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PREP(canShow);
PREP(doShow);
PREP(drawNameTagIcon);
PREP(getCachedFlags);
PREP(getVehicleData);
PREP(initIsSpeaking);
PREP(moduleNameTags);
Expand Down
64 changes: 64 additions & 0 deletions addons/nametags/functions/fnc_getCachedFlags.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Author: <N/A>
Copy link
Member

Choose a reason for hiding this comment

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

who's that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* Get's flags used for onDraw3D that can be cached
*
* Arguments:
* None
*
* Return Value:
* [_drawName,_drawRank,_enabledTagsNearby,_enabledTagsCursor,_onKeyPressAlphaMax,_maxDistance]
*
* Example:
* call ace_nametags_fnc_getCachedFlags
*
* Public: No
*/
#include "script_component.hpp"


// Determine flags from current settings
private _drawName = true;
private _enabledTagsNearby = false;
private _enabledTagsCursor = false;
private _onKeyPressAlphaMax = 1;

switch (GVAR(showPlayerNames)) do {
case 0: {
// Player names Disabled
_drawName = false;
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
};
case 1: {
// Player names Enabled
_enabledTagsNearby = true;
_enabledTagsCursor = false;
};
case 2: {
// Player names Only cursor
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = true;
};
case 3: {
// Player names Only Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsNearby = (_onKeyPressAlphaMax) > 0 || (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
};
case 4: {
// Player names Only Cursor and Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = _onKeyPressAlphaMax > 0;
};
case 5: {
// Fade on border
_enabledTagsNearby = true;
_enabledTagsCursor = false;
};
};

private _ambientBrightness = ((([] call EFUNC(common,ambientBrightness)) + ([0, 0.4] select ((currentVisionMode ace_player) != 0))) min 1) max 0;
private _maxDistance = _ambientBrightness * GVAR(PlayerNamesViewDistance);

[_drawName, GVAR(showPlayerRanks),_enabledTagsNearby,_enabledTagsCursor,_onKeyPressAlphaMax,_maxDistance]
51 changes: 4 additions & 47 deletions addons/nametags/functions/fnc_onDraw3d.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,14 @@
*/
#include "script_component.hpp"

private ["_defaultIcon", "_distance", "_alpha", "_icon", "_targets", "_relPos", "_projDist", "_target"];

BEGIN_COUNTER(GVAR(onDraw3d));

// Don't show nametags in spectator or if RscDisplayMPInterrupt is open
if ((isNull ACE_player) || {!alive ACE_player} || {!isNull (findDisplay 49)}) exitWith {};

// Determine flags from current settings
private _drawName = true;
private _drawRank = GVAR(showPlayerRanks);
private _enabledTagsNearby = false;
private _enabledTagsCursor = false;
private _onKeyPressAlphaMax = 1;
switch (GVAR(showPlayerNames)) do {
case 0: {
// Player names Disabled
_drawName = false;
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
};
case 1: {
// Player names Enabled
_enabledTagsNearby = true;
_enabledTagsCursor = false;
};
case 2: {
// Player names Only cursor
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = true;
};
case 3: {
// Player names Only Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsNearby = (_onKeyPressAlphaMax) > 0 || (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
};
case 4: {
// Player names Only Cursor and Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = _onKeyPressAlphaMax > 0;
};
case 5: {
// Fade on border
_enabledTagsNearby = true;
_enabledTagsCursor = false;
};
};
private _flags = [[], DFUNC(getCachedFlags), ACE_player, QGVAR(flagsCache), 2, "cba_events_visionModeEvent"] call EFUNC(common,cachedCall);

private _ambientBrightness = ((([] call EFUNC(common,ambientBrightness)) + ([0, 0.4] select ((currentVisionMode ace_player) != 0))) min 1) max 0;
private _maxDistance = _ambientBrightness * GVAR(PlayerNamesViewDistance);
_flags params ["_drawName", "_drawRank", "_enabledTagsNearby", "_enabledTagsCursor", "_onKeyPressAlphaMax","_maxDistance"];

private _camPosAGL = positionCameraToWorld [0, 0, 0];
if !((_camPosAGL select 0) isEqualType 0) exitWith {}; // handle RHS / bugged vehicle slots
Expand All @@ -75,7 +32,7 @@ private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _camPosASL

// Show nametag for the unit behind the cursor or its commander
if (_enabledTagsCursor) then {
_target = cursorTarget;
private _target = cursorTarget;
if !(_target isKindOf "CAManBase") then {
// When cursorTarget is on a vehicle show the nametag for the commander.
if !(_target in allUnitsUAV) then {
Expand All @@ -92,7 +49,7 @@ if (_enabledTagsCursor) then {
{lineIntersectsSurfaces [_camPosASL, eyePos _target, ACE_player, _target] isEqualTo []} &&
{!isObjectHidden _target}) then {

_distance = ACE_player distance _target;
private _distance = ACE_player distance _target;

private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)};
// Alpha:
Expand Down