From 351d20ec324e562844da5fcd7a03d8a817d494cc Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sun, 24 Jan 2016 17:12:06 -0300 Subject: [PATCH 01/13] Cache near object CAManBase that are on LOS instead of recomputing each frame --- addons/nametags/functions/fnc_onDraw3d.sqf | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index bbf608b75a..3fca2b36d2 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -15,13 +15,15 @@ */ #include "script_component.hpp" -private ["_onKeyPressAlphaMax", "_defaultIcon", "_distance", "_alpha", "_icon", "_targets", "_pos2", "_vecy", "_relPos", "_projDist", "_pos", "_target", "_targetEyePosASL", "_ambientBrightness", "_maxDistance"]; +private ["_onKeyPressAlphaMax", "_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 {}; -_ambientBrightness = ((([] call EFUNC(common,ambientBrightness)) + ([0, 0.4] select ((currentVisionMode ace_player) != 0))) min 1) max 0; -_maxDistance = _ambientBrightness * GVAR(PlayerNamesViewDistance); +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 @@ -77,17 +79,16 @@ if ((GVAR(showPlayerNames) in [2,4]) && {_onKeyPressAlphaMax > 0}) then { }; if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(showSoundWaves) == 2}) then { - _pos = positionCameraToWorld [0, 0, 0]; - _targets = _pos nearObjects ["CAManBase", _maxDistance + 5]; + 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); + }, missionNamespace, QGVAR(nearMen), 0.5] call EFUNC(common,cachedCall); - if (!surfaceIsWater _pos) then { - _pos = ATLtoASL _pos; - }; - _pos2 = positionCameraToWorld [0, 0, 1]; - if (!surfaceIsWater _pos2) then { - _pos2 = ATLtoASL _pos2; - }; - _vecy = _pos2 vectorDiff _pos; + _pos = AGLtoASL _pos; + private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _pos; { _target = _x; @@ -106,9 +107,6 @@ if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(sho {GVAR(showNamesForAI) || {[_target] call EFUNC(common,isPlayer)}} && {!(_target getVariable ["ACE_hideName", false])}) then { - _targetEyePosASL = eyePos _target; - if (lineIntersects [_pos, _targetEyePosASL, ACE_player, _target]) exitWith {}; // Check if there is line of sight - _relPos = (visiblePositionASL _target) vectorDiff _pos; _distance = vectorMagnitude _relPos; _projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy)); @@ -120,3 +118,5 @@ if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(sho nil } count _targets; }; + +END_COUNTER(GVAR(onDraw3d)); From 3e25f9c5f0f581a431113b7fc37623af3d6a4fe1 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sun, 24 Jan 2016 17:12:25 -0300 Subject: [PATCH 02/13] Cache drawIcon3D parameters --- .../functions/fnc_drawNameTagIcon.sqf | 100 +++++++++--------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/addons/nametags/functions/fnc_drawNameTagIcon.sqf b/addons/nametags/functions/fnc_drawNameTagIcon.sqf index ac28a427d5..0619bb8e2f 100644 --- a/addons/nametags/functions/fnc_drawNameTagIcon.sqf +++ b/addons/nametags/functions/fnc_drawNameTagIcon.sqf @@ -20,61 +20,65 @@ #include "script_component.hpp" -params ["_player", "_target", "_alpha", "_heightOffset", "_iconType"]; +params ["", "_target", "", "_heightOffset", ""]; -if ((_iconType == ICON_NONE) || {isObjectHidden _target}) exitWith {}; //Don't waste time if not visable +_fnc_parameters = { + params ["_player", "_target", "_alpha", "_heightOffset", "_iconType"]; -private ["_position", "_color", "_name", "_size", "_icon", "_scale"]; + if ((_iconType == ICON_NONE) || {isObjectHidden _target}) exitWith {}; //Don't waste time if not visable -//Set Icon: -_icon = ""; -_size = 0; -if (_iconType in [ICON_NAME_SPEAK, ICON_SPEAK]) then { - _icon = format ["%1%2%3",QUOTE(PATHTOF(UI\soundwave)), floor (random 10), ".paa"]; - _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))]; + //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)]; _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)]; + _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 { + [_target, true, true] call EFUNC(common,getName) + } else { + "" + }; + + //Set Color: + private _color = [1, 1, 1, _alpha]; + if ((group _target) != (group _player)) then { + _color = +GVAR(defaultNametagColor); //Make a copy, then multiply both alpha values (allows client to decrease alpha in settings) + _color set [3, (_color select 3) * _alpha]; + } else { + _color = [[1, 1, 1, _alpha], [1, 0, 0, _alpha], [0, 1, 0, _alpha], [0, 0, 1, _alpha], [1, 1, 0, _alpha]] select ((["MAIN", "RED", "GREEN", "BLUE", "YELLOW"] find (assignedTeam _target)) max 0); + }; + + private _scale = [0.333, 0.5, 0.666, 0.83333, 1] select GVAR(tagSize); + + [ + _icon, + _color, + [], + (_size * _scale), + (_size * _scale), + 0, + _name, + 2, + (0.05 * _scale), + "PuristaMedium" + ] }; -if (_alpha < 0) exitWith {}; //Don't waste time if not visable - -//Set Text: -_name = if (_iconType in [ICON_NAME, ICON_NAME_RANK, ICON_NAME_SPEAK]) then { - [_target, true, true] call EFUNC(common,getName) -} else { - "" -}; - -//Set Color: -if ((group _target) != (group _player)) then { - _color = +GVAR(defaultNametagColor); //Make a copy, then multiply both alpha values (allows client to decrease alpha in settings) - _color set [3, (_color select 3) * _alpha]; -} else { - _color = [[1, 1, 1, _alpha], [1, 0, 0, _alpha], [0, 1, 0, _alpha], [0, 0, 1, _alpha], [1, 1, 0, _alpha]] select ((["MAIN", "RED", "GREEN", "BLUE", "YELLOW"] find (assignedTeam _target)) max 0); -}; - -if (isNil "_color") then { - _color = [1, 1, 1, _alpha]; -}; +private _parameters = [_this, _fnc_parameters, _target, QGVAR(drawParameters), 0.3] call EFUNC(common,cachedCall); // Convert position to ASLW (expected by drawIcon3D) and add height offsets -_position = _target modelToWorldVisual ((_target selectionPosition "pilot") vectorAdd [0,0,(_heightOffset + .3)]); +_parameters set [2, _target modelToWorldVisual ((_target selectionPosition "pilot") vectorAdd [0,0,_heightOffset + .3])]; -_scale = [0.333, 0.5, 0.666, 0.83333, 1] select GVAR(tagSize); - -drawIcon3D [ - _icon, - _color, - _position, - (_size * _scale), - (_size * _scale), - 0, - _name, - 2, - (0.05 * _scale), - "PuristaMedium" -]; +TRACE_1("Params:",_parameters); +drawIcon3D _parameters; From 62fb26200f5b679e36ffa7099f8bf2d23fee9361 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 15:36:56 -0300 Subject: [PATCH 03/13] Nametags optimization --- .../functions/fnc_drawNameTagIcon.sqf | 33 ++-- addons/nametags/functions/fnc_onDraw3d.sqf | 176 ++++++++++-------- 2 files changed, 113 insertions(+), 96 deletions(-) diff --git a/addons/nametags/functions/fnc_drawNameTagIcon.sqf b/addons/nametags/functions/fnc_drawNameTagIcon.sqf index 0619bb8e2f..08a7dcd77f 100644 --- a/addons/nametags/functions/fnc_drawNameTagIcon.sqf +++ b/addons/nametags/functions/fnc_drawNameTagIcon.sqf @@ -7,44 +7,43 @@ * 1: Target * 2: Alpha * 4: Height offset - * 5: Draw Type + * 5: Draw name + * 5: Draw rank + * 6: Draw soundwave * * 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; diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index 3fca2b36d2..156893c71f 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -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; From b358c4a8afcd2e23e65d904e6ccb32137d7b2c73 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 16:09:14 -0300 Subject: [PATCH 04/13] Optimized EFUNC(common,cachedCall) --- addons/common/functions/fnc_cachedCall.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index 2c7cdd4b27..cf60155577 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -17,9 +17,9 @@ */ #include "script_component.hpp" -params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; - if ((_namespace getVariable [_uid, [-99999]]) select 0 < ACE_diagTime) then { + params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; + _namespace setVariable [_uid, [ACE_diagTime + _duration, _params call _function]]; // Does the cache needs to be cleared on an event? From 1b912cdca0636e3e0dbafb887def0f8404b866ce Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 16:38:26 -0300 Subject: [PATCH 05/13] Switch back to modelToWorldVisual. Perf is about the same and it moves smoothly with the model. --- addons/nametags/functions/fnc_drawNameTagIcon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/nametags/functions/fnc_drawNameTagIcon.sqf b/addons/nametags/functions/fnc_drawNameTagIcon.sqf index 08a7dcd77f..3c206c6c57 100644 --- a/addons/nametags/functions/fnc_drawNameTagIcon.sqf +++ b/addons/nametags/functions/fnc_drawNameTagIcon.sqf @@ -75,7 +75,7 @@ _fnc_parameters = { }; private _parameters = [_this, _fnc_parameters, _target, QGVAR(drawParameters), 0.1] call EFUNC(common,cachedCall); +_parameters set [2, _target modelToWorldVisual ((_target selectionPosition "pilot") vectorAdd [0,0,(_heightOffset + .3)])]; -_parameters set [2, (ASLtoAGL eyePos _target) vectorAdd [0,0,_heightOffset + .3]]; drawIcon3D _parameters; From 73499489e0b32e8420fb2f2adfd2f5fec3c73184 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 16:45:16 -0300 Subject: [PATCH 06/13] Revert "Optimized EFUNC(common,cachedCall)" This reverts commit b358c4a8afcd2e23e65d904e6ccb32137d7b2c73. --- addons/common/functions/fnc_cachedCall.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index cf60155577..2c7cdd4b27 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -17,9 +17,9 @@ */ #include "script_component.hpp" -if ((_namespace getVariable [_uid, [-99999]]) select 0 < ACE_diagTime) then { - params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; +params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; +if ((_namespace getVariable [_uid, [-99999]]) select 0 < ACE_diagTime) then { _namespace setVariable [_uid, [ACE_diagTime + _duration, _params call _function]]; // Does the cache needs to be cleared on an event? From b2e9dd0149c51ddf30ec13947f31125000766c7f Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 17:03:18 -0300 Subject: [PATCH 07/13] Fix _vecy --- addons/nametags/functions/fnc_onDraw3d.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index 156893c71f..f8a9768074 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -103,7 +103,7 @@ if (_enabledTagsCursor) then { if (_enabledTagsNearby) then { private _camPosAGL = positionCameraToWorld [0, 0, 0]; private _camPosASL = AGLtoASL _camPosAGL; - private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _camPosAGL; + private _vecy = (AGLtoASL positionCameraToWorld [0, 0, 1]) vectorDiff _camPosASL; // Find valid targets and cache them private _targets = [[], { From c43b3bd5c173519bd9839bd8d042682c552e2f93 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 17:14:18 -0300 Subject: [PATCH 08/13] Switch --- addons/nametags/functions/fnc_onDraw3d.sqf | 50 +++++++++++----------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index f8a9768074..927748be4d 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -28,36 +28,34 @@ 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 { +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; - } else { + }; + case 2: { // 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; - }; - }; - }; + _enabledTagsNearby = (GVAR(showSoundWaves) == 2); + _enabledTagsCursor = true; + }; + case 3: { + // Player names Only Keypress + _onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - ACE_time); + _enabledTagsNearby = (_onKeyPressAlphaMax) > 0 || (GVAR(showSoundWaves) == 2); + _enabledTagsCursor = false; + }; + case 4: { + // Player names Only Cursor and Keypress + _onKeyPressAlphaMax = 2 + (GVAR(showNamesTime) - ACE_time); + _enabledTagsNearby = (GVAR(showSoundWaves) == 2); + _enabledTagsCursor = _onKeyPressAlphaMax > 0; }; }; From a47f7b8162e46886a3bbf82fdbd4b916c53e1783 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 17:18:03 -0300 Subject: [PATCH 09/13] Fix cursor mode --- addons/nametags/functions/fnc_onDraw3d.sqf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index 927748be4d..d14dd1e1a9 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -62,6 +62,10 @@ switch (GVAR(showPlayerNames)) do { 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]; +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; @@ -78,8 +82,8 @@ if (_enabledTagsCursor) then { 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 { + {lineIntersectsSurfaces [_camPosASL, eyePos _target, ACE_player, _target] isEqualTo []} && + {!isObjectHidden _target}) then { _distance = ACE_player distance _target; @@ -99,10 +103,6 @@ if (_enabledTagsCursor) then { // 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 _camPosASL; - // Find valid targets and cache them private _targets = [[], { private _nearMen = _camPosAGL nearObjects ["CAManBase", _maxDistance + 7]; From 4c938a050b6fe742fcf27ea7d1f5165fca00b93a Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 17:57:24 -0300 Subject: [PATCH 10/13] Fix for combination of "Only Cursor + Keypress" and "Always Show Sound Waves" --- addons/nametags/functions/fnc_onDraw3d.sqf | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index d14dd1e1a9..a121b40e34 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -123,12 +123,18 @@ if (_enabledTagsNearby) then { private _projDist = _relPos vectorDistance (_vecy vectorMultiply (_relPos vectorDotProduct _vecy)); private _drawSoundwave = (GVAR(showSoundWaves) > 0) && {[_target] call FUNC(isSpeaking)}; + private _alphaMax = _onKeyPressAlphaMax; + if ((GVAR(showSoundWaves) == 2) && _drawSoundwave) then { + _drawName = _drawSoundwave; + _drawRank = false; + _alphaMax = 1; + }; // 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; + // - it's clamped by the value of _onKeyPressAlphaMax unless soundwaves are forced on and the unit is talking + private _alpha = (((1 + ([0, 0.2] select _drawSoundwave) - 0.2 * (_distance - _maxDistance)) min 1) * GVAR(playerNamesMaxAlpha)) min _alphaMax; if (_alpha > 0) then { [ACE_player, _target, _alpha, _distance * 0.026, _drawName, _drawRank, _drawSoundwave] call FUNC(drawNameTagIcon); From d4eda6d4ec38babcc9145664be076e04c94c2d42 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 8 Feb 2016 22:54:24 -0300 Subject: [PATCH 11/13] Show tags for units inside the player vehicle. Close #538. --- addons/nametags/functions/fnc_onDraw3d.sqf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index a121b40e34..cf3484a885 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -106,11 +106,14 @@ if (_enabledTagsNearby) then { // Find valid targets and cache them private _targets = [[], { private _nearMen = _camPosAGL nearObjects ["CAManBase", _maxDistance + 7]; + if (vehicle ACE_player != ACE_player) then { + _nearMen = _nearMen + crew vehicle ACE_player; + }; _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 []} && + {lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, vehicle _x] isEqualTo []} && {!isObjectHidden _x} } }, missionNamespace, QGVAR(nearMen), 0.5] call EFUNC(common,cachedCall); From 0f41c5bf135adac021affcbb55711d58ffce433a Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 9 Feb 2016 00:01:51 -0300 Subject: [PATCH 12/13] Only test the GEOM LOD for visibility --- addons/nametags/functions/fnc_onDraw3d.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index cf3484a885..bcbf44c36b 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -113,7 +113,7 @@ if (_enabledTagsNearby) then { _x != ACE_player && {(side group _x) == (side group ACE_player)} && {GVAR(showNamesForAI) || {[_x] call EFUNC(common,isPlayer)}} && - {lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, vehicle _x] isEqualTo []} && + {lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, _x, true, 1, "GEOM", "NONE"] isEqualTo []} && {!isObjectHidden _x} } }, missionNamespace, QGVAR(nearMen), 0.5] call EFUNC(common,cachedCall); From b02a67605c835f15bd152e8e72387a988837b414 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 9 Feb 2016 00:19:18 -0300 Subject: [PATCH 13/13] Revert to normal testing for units on foot --- addons/nametags/functions/fnc_onDraw3d.sqf | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index bcbf44c36b..3bb97dba8c 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -106,16 +106,24 @@ if (_enabledTagsNearby) then { // Find valid targets and cache them private _targets = [[], { private _nearMen = _camPosAGL nearObjects ["CAManBase", _maxDistance + 7]; - if (vehicle ACE_player != ACE_player) then { - _nearMen = _nearMen + crew vehicle ACE_player; - }; - _nearMen select { + _nearMen = _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, true, 1, "GEOM", "NONE"] isEqualTo []} && + {lineIntersectsSurfaces [_camPosASL, eyePos _x, ACE_player, _x] isEqualTo []} && {!isObjectHidden _x} - } + }; + private _crewMen = []; + if (vehicle ACE_player != ACE_player) then { + _crewMen = (crew vehicle ACE_player) 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, true, 1, "GEOM", "NONE"] isEqualTo []} && + {!isObjectHidden _x} + }; + }; + (_nearMen + _crewMen) }, missionNamespace, QGVAR(nearMen), 0.5] call EFUNC(common,cachedCall); {