Skip to content

Commit

Permalink
Separate new() and new_with_app_id() (#841)
Browse files Browse the repository at this point in the history
* Add new() and new_with_app_id()

* fix calls

* ugh

* Add comment to new()

Copied from the steamworks rs docs.
  • Loading branch information
NathanTaylorHunt authored Jan 26, 2025
1 parent 41c3fc3 commit 1d1a3e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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

0 comments on commit 1d1a3e9

Please sign in to comment.