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

SteamClient.SteamId is terribly slow #784

Open
kristianpiacenti opened this issue Sep 15, 2024 · 4 comments
Open

SteamClient.SteamId is terribly slow #784

kristianpiacenti opened this issue Sep 15, 2024 · 4 comments

Comments

@kristianpiacenti
Copy link

It's not cached and do weird things behind the scenes. It should be moved to a Get method not to cause confusion.
Calling this property each frame can destroy your cpu time.

It's used also in Friend.IsMe so be careful for that.

@DK189
Copy link

DK189 commented Sep 16, 2024

Well, that's right!
I think this library is just a C# friendly interface to call to SteamAPI. SteamClient.SteamId or SteamClient.Name,... will always call back SteamAPI_ISteamUser_GetSteam....

Normally SteamClient.SteamId will always be a constant value that exists from session start SteamClient.Init(..) until session end SteamClient.Shutdown(). If so then we should really save it somewhere instead of always calling SteamClient.SteamId when needed.

Ex:

SteamClient.Init(AppId, true);
SteamId = SteamClient.SteamId;
Name = SteamClient.Name;

@DK189
Copy link

DK189 commented Sep 16, 2024

For SteamAPI_ISteamUser_GetSteamID, the delay is probably because SteamAPI actually calls this data response from SteamClient every time it's requested. I don't understand why they would do that either, for security? It's obviously not supposed to change while the game is running.
Account name, level, avatar, and other things need to be refreshed every time it's called. SteamID doesn't need it.

@kristianpiacenti
Copy link
Author

You are right @DK189 , it's not suppose to change unless you log-in with a different account, but you lose authentication if you try something like and the client should shut down automatically.

I propose just cache that in SteamClient, something simple like

private static bool _steamIdIsCached;
private static SteamId _steamIdCache;
public static SteamId SteamId
{
	get
	{
		if (_steamIdIsCached == false)
		{
			_steamIdIsCached = true;
			_steamIdCache = SteamUser.Internal.GetSteamID();
		}
		
		return _steamIdCache;
	}	
}

and keep a RequestSteamId() in case you need to be sure you have the right one.
(and at that point for consistency you have RequestSteamId in SteamId property)

@DK189
Copy link

DK189 commented Sep 16, 2024

Yes! All programmers should see this! 👍👍👍

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

No branches or pull requests

2 participants