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

Separate new() and new_with_app_id() #841

Merged
merged 4 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lightyear/src/connection/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl NetConfig {
} => {
let client = super::steam::client::Client::new(
steamworks_client.unwrap_or_else(|| {
Arc::new(RwLock::new(SteamworksClient::new(config.app_id)))
Arc::new(RwLock::new(SteamworksClient::new_with_app_id(config.app_id)))
}),
config,
conditioner,
Expand Down
2 changes: 1 addition & 1 deletion lightyear/src/connection/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl NetConfig {
// TODO: handle errors
let server = super::steam::server::Server::new(
steamworks_client.unwrap_or_else(|| {
Arc::new(RwLock::new(SteamworksClient::new(config.app_id)))
Arc::new(RwLock::new(SteamworksClient::new_with_app_id(config.app_id)))
}),
config,
conditioner,
Expand Down
20 changes: 17 additions & 3 deletions lightyear/src/connection/steam/steamworks_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ impl std::fmt::Debug for SteamworksClient {
}

impl SteamworksClient {
/// Creates and initializes the Steamworks client. This must only be called
/// once per application run.
pub fn new(app_id: u32) -> Self {
/// Creates and initializes the Steamworks client with the specified AppId.
/// This must only be called once per application run.
pub fn new_with_app_id(app_id: u32) -> Self {
let (client, single) = steamworks::Client::<ClientManager>::init_app(app_id).unwrap();

Self {
Expand All @@ -31,6 +31,20 @@ impl SteamworksClient {
}
}

/// Creates and initializes the Steamworks client. If the game isn’t being run through steam
/// this can be provided by placing a steam_appid.txt with the ID inside in the current
/// working directory.
/// This must only be called once per application run.
pub fn new() -> Self {
let (client, single) = steamworks::Client::<ClientManager>::init().unwrap();

Self {
app_id: client.utils().app_id().0,
client,
single: SyncCell::new(single),
}
}

/// Gets the thread-safe Steamworks client. Most Steamworks API calls live
/// under this client.
pub fn get_client(&self) -> steamworks::Client<ClientManager> {
Expand Down