Cache Nametags onDraw3D flags. (#4847)

* Cache Nametag flags

* Remove unused privates

* Fix fading, cursorOnly mode, improve cache reset

* Fix header
This commit is contained in:
Dedmen Miller 2017-02-10 19:19:14 +01:00 committed by PabstMirror
parent 231346a199
commit 5351b43ff3
4 changed files with 82 additions and 50 deletions

View File

@ -2,6 +2,7 @@
PREP(canShow);
PREP(doShow);
PREP(drawNameTagIcon);
PREP(getCachedFlags);
PREP(getVehicleData);
PREP(initIsSpeaking);
PREP(moduleNameTags);

View File

@ -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
},
@ -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

View File

@ -0,0 +1,56 @@
/*
* Author: <N/A>
* 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]

View File

@ -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 _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] 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", "_maxDistance"];
private _onKeyPressAlphaMax = 1;
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 _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 {
@ -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:
@ -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;
@ -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;