Skip to content

Commit

Permalink
Add doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
msvbg committed May 28, 2024
1 parent 54278d1 commit ff9e1de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lightyear/src/connection/steam/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ impl Default for SteamConfig {
}
}

/// Steam socket configuration for clients
#[derive(Debug, Clone)]
pub enum SocketConfig {
/// Connect to a server by IP address. Suitable for dedicated servers.
Ip { server_addr: SocketAddr },
/// Connect to another Steam user hosting a server. Suitable for
/// peer-to-peer games.
P2P { virtual_port: i32, steam_id: u64 },
}

Expand Down
7 changes: 4 additions & 3 deletions lightyear/src/connection/steam/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ impl Default for SteamConfig {
}
}

/// Steam socket configuration for servers
#[derive(Debug, Clone)]
pub enum SocketConfig {
/// This server accepts connections via IP address. Suitable for dedicated servers.
Ip {
server_ip: Ipv4Addr,
game_port: u16,
query_port: u16,
},
P2P {
virtual_port: i32,
},
/// This server accepts Steam P2P connections. Suitable for peer-to-peer games.
P2P { virtual_port: i32 },
}

impl Default for SocketConfig {
Expand Down
11 changes: 10 additions & 1 deletion lightyear/src/connection/steam/steamworks_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use bevy::utils::synccell::SyncCell;
use steamworks::{ClientManager, SingleClient};
use tracing::info;

/// This wraps the Steamworks client. It must only be created once per
/// application run. For convenience, Lightyear can automatically create the
/// client for you, but for more control, you can create it yourself and pass it in to Lightyear.
pub struct SteamworksClient {
app_id: u32,
client: steamworks::Client<ClientManager>,
single: SyncCell<SingleClient>,
single: SyncCell<SingleClient>, // https://github.com/Noxime/steamworks-rs/issues/159
}

impl std::fmt::Debug for SteamworksClient {
Expand All @@ -19,6 +22,8 @@ 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 {
let (client, single) = steamworks::Client::<ClientManager>::init_app(app_id).unwrap();

Expand All @@ -29,10 +34,14 @@ impl SteamworksClient {
}
}

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

/// Gets the non-thread-safe Steamworks client. This is only used to run
/// Steamworks callbacks.
pub fn get_single(&mut self) -> &mut SingleClient<ClientManager> {
self.single.get()
}
Expand Down

0 comments on commit ff9e1de

Please sign in to comment.