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

Move player finders to a proper place & optimize them #2161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noaccessl
Copy link
Contributor

I thought it would be better to move these functions to a specialized place.
There was even a comment about it there.

-- These are totally in the wrong place.

Also, optimized them by using bidirectional mapping between IDs and players for easier fetching and cleanup.

@bloodycop7
Copy link
Contributor

bloodycop7 commented Nov 24, 2024

Are you sure this cannot have a client side side effect just like ents.Iterator, invalid entities that even IsValid check doesn't fix

@noaccessl
Copy link
Contributor Author

noaccessl commented Nov 24, 2024

Are you sure this cannot have a client side side effect just like ents.Iterator, invalid entities that even IsValid check doesn't fix

Most likely it should never happen as this just clears the certain player from stored data. ents.Iterator invalidates cache entirely, setting recaching up for the next call.

As far as I know, these two hooks shouldn't provide invalid players and only called once (regarding players).

@Cheatoid
Copy link

Cheatoid commented Jan 1, 2025

Let's have another one of those again, yay! #2124
I can't think of why would you do this, like this is not optimizing anything, it is just introducing bugs and reliability issues.
Are you also not aware that UniqueID has hash collisions because it is CRC32? Also SteamID == BOT for all bots while their SteamID64 is different, you see where I am going here(no?), add 1 bot, player.GetBySteamID("BOT") would return it, add 1 more bot, it returns the different (latest bot), kick the second bot, and do player.GetBySteamID("BOT"), what do you think is the result? nil... whereas in the original code, it would always return the first bot it would find under the entity list. On top of that, the lengths of your lookup/map tables would forever differ from that point onwards.
This could cause some spectacular headache when a player's entity is briefly removed (e.g. after being killed), or some ID being empty or nil during OnEntityCreated due to its nature... when this happens, player object might become NULL entity, at which point something is going to mess up the lookup table... Why would you not invalidate whole cache on full update?

...

..


You want to optimize "player finders"? My advice is to stop doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants