multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.41k stars 438 forks source link

Add (get)setPlayerNametagDistance() and (get)setPlayerNametagDistanceFixed() #2330

Open PlatinMTA opened 3 years ago

PlatinMTA commented 3 years ago

Is your feature request related to a problem? Please describe. Right now there is not a way to change the default distance of a nametag. If you want your nametags to be seen from closer (or further) you need to create your own resource for managing nametags.

This is not a big issue on it's own, until you start considering that rendering nametags on lua, specially fancy ones, can be quite performance heavy. dxDraw calls are kinda slow, and when you have +15 players on the screen it can start to go bad if you need a lot of information or if you didn't optimize your script enough.

It could come in handy for people that only want to change the distance of a nametag, to have a function in where they can change it without needing to create a nametag manager themselves.

setPlayerNametagDistance( player thePlayer, float distance )
-- returns true if valid, false otherwise

getPlayerNametagDistance( player thePlayer )
-- returns value, false otherwise, default value is 45.0 afaik

The default nametags do also change they minimum requiered distance for rendering depending on a few factors. For example, if you are using an scope, they would render from further away. setPlayerNametagDistanceFixed() could negate this effect and only render nametags if they are closer than the distance defined.

setPlayerNametagDistanceFixed( player thePlayer, bool isFixed )
-- returns true if valid, false otherwise

setPlayerNametagDistanceFixed( player thePlayer )
-- returns boolean (true if fixed, false otherwise, default false)

Describe the solution you'd like Add a function that can change the distance for seeing the nametag. By default it is 45.0f.

Describe alternatives you've considered There are none, unless you consider scripting a nametag resource as an alternative.

Dutchman101 commented 3 years ago

It could come in handy for people that only want to change the distance of a nametag, to have a function in where they can change it without needing to create a nametag manager themselves.

Maybe we should try to get rid of the most common reasons for someone to consider using a custom nametags system (because as you said, it'll always be taxing on client peformance) and the first other thing i can think of in this context is: colorcode support.

If you want, create another issue about native support for colorcode in nicks, because next to rendering distance it's the Top 2 of reasons to sacrifise performance (as you can see, a close reproduction of nametags in Lua that only adds colorcode support, already takes a significant toll) or else i will do that soon

patrikjuvonen commented 3 years ago

I wonder why fundamentally color coded text eats so much processing power. Can this be patched? Seems like a trivial task for a computer in 2021.

Pirulax commented 3 years ago

Look at how it's implemented. A color-coded text is broken down into multiple smaller texts. Also, because of sub-par implementation, theres lot of allocations as well (while there shouldn't be any, obviously). A way to solve this would be to break up the string as necessary, and put it into a hash table, with a limited number of entries.

Zangomangu commented 3 years ago

A side note but could be included in the fix for this

Nametags should use IsLineOfSightClear (and CWorldSA::IgnoreEntity on the player vehicle) instead of ProcessLineOfSight, should be faster