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 all 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
9 changes: 8 additions & 1 deletion addons/nametags/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GVAR(showNamesTime) = -10;

// Statement
GVAR(showNamesTime) = CBA_missionTime;
if (call FUNC(canShow)) then{ call FUNC(doShow); };
// if (call FUNC(canShow)) then{ call FUNC(doShow); }; // This code doesn't work (canShow has a nil / has never worked??)
// Return false so it doesn't block other actions
false
},
Expand All @@ -34,6 +34,13 @@ GVAR(showNamesTime) = -10;
if (_name == QGVAR(showPlayerNames)) then {
call FUNC(updateSettings);
};
// Reset nametag flag cache on setting change:
ACE_player setVariable [QGVAR(flagsCache), nil];
}] call CBA_fnc_addEventHandler;

["cba_events_visionModeEvent", {
// Reset nametag flag cache on vision mode change:
ACE_player setVariable [QGVAR(flagsCache), nil];
}] call CBA_fnc_addEventHandler;

// civilians don't use military ranks
Expand Down
56 changes: 56 additions & 0 deletions addons/nametags/functions/fnc_getCachedFlags.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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,_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;

switch (GVAR(showPlayerNames)) do {
case 0: {
// Player names Disabled [Note: this should be unreachable as the drawEH will be removed]
_drawName = false;
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
};
case 1: {
// Player names Enabled
_enabledTagsNearby = true;
};
case 2: {
// Player names Only cursor
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = true;
};
case 3: {
// Player names Only Keypress
_enabledTagsNearby = GVAR(showSoundWaves) == 2; // non-cached: || _onKeyPressAlphaMax) > 0
};
case 4: {
// Player names Only Cursor and Keypress
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
// non-cached: _enabledTagsCursor = _onKeyPressAlphaMax > 0;
};
case 5: {
// Fade on border
_enabledTagsNearby = true;
};
};

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,_maxDistance]
64 changes: 16 additions & 48 deletions addons/nametags/functions/fnc_onDraw3d.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,33 @@
*/
#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 _flags = [[], DFUNC(getCachedFlags), ACE_player, QGVAR(flagsCache), 2] call EFUNC(common,cachedCall);

_flags params ["_drawName", "_drawRank", "_enabledTagsNearby", "_enabledTagsCursor", "_maxDistance"];

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;
};
if (GVAR(showPlayerNames) == 3) then {
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsNearby = _enabledTagsNearby || {_onKeyPressAlphaMax > 0}
};
if (GVAR(showPlayerNames) == 4) then {
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - CBA_missionTime);
_enabledTagsCursor = _onKeyPressAlphaMax > 0;
};

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

private _camPosAGL = positionCameraToWorld [0, 0, 0];
if !((_camPosAGL select 0) isEqualType 0) exitWith {}; // handle RHS / bugged vehicle slots

private _camPosASL = AGLtoASL _camPosAGL;
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 +58,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 Expand Up @@ -137,6 +103,9 @@ if (_enabledTagsNearby) then {
private _target = _x;

if !(isNull _target) then {
private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)};
if (_enabledTagsCursor && {!_drawSoundwave}) exitWith {}; // (Cursor Only && showSoundWaves==2) - quick exit

private _relPos = (visiblePositionASL _target) vectorDiff _camPosASL;
private _distance = vectorMagnitude _relPos;

Expand All @@ -152,7 +121,6 @@ if (_enabledTagsNearby) then {
};
};

private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)};
private _alphaMax = _onKeyPressAlphaMax;
if ((GVAR(showSoundWaves) == 2) && _drawSoundwave) then {
_drawName = _drawSoundwave;
Expand Down