Nametags optimization

This commit is contained in:
esteldunedain 2016-02-08 15:36:56 -03:00
parent 94977ffe5c
commit 62fb26200f
2 changed files with 113 additions and 96 deletions

View File

@ -7,44 +7,43 @@
* 1: Target <OBJECT>
* 2: Alpha <NUMBER>
* 4: Height offset <NUMBER>
* 5: Draw Type <NUMBER>
* 5: Draw name <BOOL>
* 5: Draw rank <BOOL>
* 6: Draw soundwave <BOOL>
*
* Return value:
* None
*
* Example:
* [ACE_player, bob, 0.5, height, ICON_NAME_SPEAK] call ace_nametags_fnc_drawNameTagIcon
* [ACE_player, bob, 0.5, height, true, true, true] call ace_nametags_fnc_drawNameTagIcon
*
* Public: No
*/
#include "script_component.hpp"
params ["", "_target", "", "_heightOffset", ""];
TRACE_1("drawName:", _this);
params ["", "_target", "", "_heightOffset"];
_fnc_parameters = {
params ["_player", "_target", "_alpha", "_heightOffset", "_iconType"];
if ((_iconType == ICON_NONE) || {isObjectHidden _target}) exitWith {}; //Don't waste time if not visable
params ["_player", "_target", "_alpha", "_heightOffset", "_drawName", "_drawRank", "_drawSoundwave"];
//Set Icon:
private _icon = "";
private _size = 0;
if (_iconType == ICON_NAME_SPEAK || _iconType == ICON_SPEAK) then {
_icon = format [QUOTE(PATHTOF(UI\soundwave%1.paa)), floor (random 10)];
if (_drawSoundwave) then {
_icon = format [QUOTE(PATHTOF(UI\soundwave%1.paa)), floor random 10];
_size = 1;
_alpha = (_alpha max 0.2) + 0.2;//Boost alpha when speaking
} else {
if (_iconType == ICON_NAME_RANK) then {
_icon = format["\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa", toLower(rank _target)];
if (_drawRank) then {
_icon = format["\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa", toLower rank _target];
_size = 1;
};
};
if (_alpha < 0) exitWith {}; //Don't waste time if not visable
//Set Text:
private _name = if (_iconType in [ICON_NAME, ICON_NAME_RANK, ICON_NAME_SPEAK]) then {
private _name = if (_drawName) then {
[_target, true, true] call EFUNC(common,getName)
} else {
""
@ -75,10 +74,8 @@ _fnc_parameters = {
]
};
private _parameters = [_this, _fnc_parameters, _target, QGVAR(drawParameters), 0.3] call EFUNC(common,cachedCall);
private _parameters = [_this, _fnc_parameters, _target, QGVAR(drawParameters), 0.1] call EFUNC(common,cachedCall);
// Convert position to ASLW (expected by drawIcon3D) and add height offsets
_parameters set [2, _target modelToWorldVisual ((_target selectionPosition "pilot") vectorAdd [0,0,_heightOffset + .3])];
_parameters set [2, (ASLtoAGL eyePos _target) vectorAdd [0,0,_heightOffset + .3]];
TRACE_1("Params:",_parameters);
drawIcon3D _parameters;

View File

@ -15,105 +15,125 @@
*/
#include "script_component.hpp"
private ["_onKeyPressAlphaMax", "_defaultIcon", "_distance", "_alpha", "_icon", "_targets", "_relPos", "_projDist", "_target"];
private ["_defaultIcon", "_distance", "_alpha", "_icon", "_targets", "_relPos", "_projDist", "_target"];
BEGIN_COUNTER(GVAR(onDraw3d));
//don't show nametags in spectator or if RscDisplayMPInterrupt is open
// 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;
if (GVAR(showPlayerNames) == 0) then {
// Player names Disabled
_drawName = false;
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
} else {
if (GVAR(showPlayerNames) == 1) then {
// Player names Enabled
_enabledTagsNearby = true;
_enabledTagsCursor = false;
} else {
// Player names Only cursor
if (GVAR(showPlayerNames) == 2) then {
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = true;
} else {
if (GVAR(showPlayerNames) == 3) then {
// Player names Only Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - ACE_time);
_enabledTagsNearby = (_onKeyPressAlphaMax) > 0 || (GVAR(showSoundWaves) == 2);
_enabledTagsCursor = false;
} else {
if (GVAR(showPlayerNames) == 4) then {
// Player names Only Cursor and Keypress
_onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - ACE_time);
_enabledTagsNearby = (GVAR(showSoundWaves) == 2);
_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);
_onKeyPressAlphaMax = if ((GVAR(showPlayerNames) in [3,4])) then {
2 + (GVAR(showNamesTime) - ACE_time); //after release 1 second of full opacity, 1 second of fading to 0
} else {
1
};
_defaultIcon = if (GVAR(showPlayerRanks)) then {
ICON_NAME_RANK;
} else {
ICON_NAME;
};
//When cursorTarget is on a vehicle show the nametag for the commander.
//If set to "Only On Keypress" settings, fade just like main tags
if (GVAR(showCursorTagForVehicles) && {_onKeyPressAlphaMax > 0}) then {
// Show nametag for the unit behind the cursor or its commander
if (_enabledTagsCursor) then {
_target = cursorTarget;
if ((!(_target isKindOf "CAManBase")) && {!(_target in allUnitsUAV)}) then {
_target = effectiveCommander _target;
if ((!isNull _target) &&
{(side (group _target)) == (side (group ACE_player))} &&
{_target != ACE_player} &&
{GVAR(showNamesForAI) || {[_target] call EFUNC(common,isPlayer)}} &&
{!(_target getVariable ["ACE_hideName", false])}) then {
_distance = ACE_player distance _target;
_alpha = (((1 - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _onKeyPressAlphaMax;
[ACE_player, _target, _alpha, _distance * 0.026, _defaultIcon] call FUNC(drawNameTagIcon);
};
};
};
//"Only Cursor" mode, only show nametags for humans on cursorTarget
if ((GVAR(showPlayerNames) in [2,4]) && {_onKeyPressAlphaMax > 0}) then {
_target = cursorTarget;
if ((!isNull _target) &&
{_target isKindOf "CAManBase"} &&
{(side (group _target)) == (side (group ACE_player))} &&
{_target != ACE_player} &&
{GVAR(showNamesForAI) || {[_target] call EFUNC(common,isPlayer)}} &&
{!(_target getVariable ["ACE_hideName", false])}) then {
_distance = ACE_player distance _target;
if (_distance > (_maxDistance + 5)) exitWith {};
_alpha = (((1 - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _onKeyPressAlphaMax;
_icon = ICON_NONE;
if (GVAR(showSoundWaves) == 2) then { //icon will be drawn below, so only show name here
_icon = if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target}) then {ICON_NAME} else {_defaultIcon};
if !(_target isKindOf "CAManBase") then {
// When cursorTarget is on a vehicle show the nametag for the commander.
if !(_target in allUnitsUAV) then {
_target = effectiveCommander _target;
} else {
_icon = if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {ICON_NAME_SPEAK} else {_defaultIcon};
_target = objNull;
};
};
if (isNull _target) exitWith {};
[ACE_player, _target, _alpha, _distance * 0.026, _icon] call FUNC(drawNameTagIcon);
if (_target != ACE_player &&
{(side group _target) == (side group ACE_player)} &&
{GVAR(showNamesForAI) || {[_target] call EFUNC(common,isPlayer)}} &&
{lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, _x] isEqualTo []} &&
{!isObjectHidden _x}) then {
_distance = ACE_player distance _target;
private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)};
// Alpha:
// - base value determined by GVAR(playerNamesMaxAlpha)
// - decreases when _distance > _maxDistance
// - increases when the unit is speaking
// - it's clamped by the value of _onKeyPressAlphaMax
private _alpha = (((1 + ([0, 0.2] select _drawSoundwave) - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _onKeyPressAlphaMax;
if (_alpha > 0) then {
[ACE_player, _target, _alpha, _distance * 0.026, _drawName, _drawRank, _drawSoundwave] call FUNC(drawNameTagIcon);
};
};
};
if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(showSoundWaves) == 2}) then {
private _pos = positionCameraToWorld [0, 0, 0];
private _targets = [_pos, {
private _nearMen = _this nearObjects ["CAManBase", _maxDistance + 7];
[_nearMen, {
!(lineIntersects [AGLtoASL _pos, eyePos _x, ACE_player, _x])
}] call EFUNC(common,filter);
// Show nametags for nearby units
if (_enabledTagsNearby) then {
private _camPosAGL = positionCameraToWorld [0, 0, 0];
private _camPosASL = AGLtoASL _camPosAGL;
private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _camPosAGL;
// Find valid targets and cache them
private _targets = [[], {
private _nearMen = _camPosAGL nearObjects ["CAManBase", _maxDistance + 7];
_nearMen select {
_x != ACE_player &&
{(side group _x) == (side group ACE_player)} &&
{GVAR(showNamesForAI) || {[_x] call EFUNC(common,isPlayer)}} &&
{lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, _x] isEqualTo []} &&
{!isObjectHidden _x}
}
}, missionNamespace, QGVAR(nearMen), 0.5] call EFUNC(common,cachedCall);
_pos = AGLtoASL _pos;
private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _pos;
{
_target = _x;
private _target = _x;
_icon = ICON_NONE;
if ((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) then {
if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {_icon = ICON_NAME_SPEAK;} else {_icon = _defaultIcon};
} else {
//showSoundWaves must be 2, only draw speak icon
if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target}) then {_icon = ICON_SPEAK;};
};
private _relPos = (visiblePositionASL _target) vectorDiff _camPosASL;
private _distance = vectorMagnitude _relPos;
private _projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy));
if ((_icon != ICON_NONE) &&
{(side (group _target)) == (side (group ACE_player))} &&
{_target != ACE_player} &&
{GVAR(showNamesForAI) || {[_target] call EFUNC(common,isPlayer)}} &&
{!(_target getVariable ["ACE_hideName", false])}) then {
private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)};
// Alpha:
// - base value determined by GVAR(playerNamesMaxAlpha)
// - decreases when _distance > _maxDistance
// - increases when the unit is speaking
// - it's clamped by the value of _onKeyPressAlphaMax
private _alpha = (((1 + ([0, 0.2] select _drawSoundwave) - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _onKeyPressAlphaMax;
_relPos = (visiblePositionASL _target) vectorDiff _pos;
_distance = vectorMagnitude _relPos;
_projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy));
_alpha = (((1 - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _onKeyPressAlphaMax;
[ACE_player, _target, _alpha, _distance * 0.026, _icon] call FUNC(drawNameTagIcon);
if (_alpha > 0) then {
[ACE_player, _target, _alpha, _distance * 0.026, _drawName, _drawRank, _drawSoundwave] call FUNC(drawNameTagIcon);
};
nil
} count _targets;