forked from lucaspoffo/renet
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split renet2 crate into renet2 and renet2_netcode; move steam bevy in…
…tegration to bevy_renet2; ClientId is now a type alias for u64
- Loading branch information
Showing
71 changed files
with
477 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
[workspace] | ||
members = [ | ||
"examples/echo_client_native", | ||
#"examples/echo_client_wt", # requires wasm32-unknown-unknown target | ||
#"examples/echo_client_wasm", # requires wasm32-unknown-unknown target | ||
"examples/echo_server_cross", | ||
"demo_chat", | ||
"demo_bevy", | ||
"bevy_renet2", | ||
"bevy_replicon_renet2", | ||
"renet2", | ||
"renet2_netcode", | ||
"renet2_visualizer", | ||
"renet2_steam", | ||
"renetcode2", | ||
] | ||
exclude = [ | ||
"examples/echo_client_wt", | ||
"examples/echo_client_wasm", | ||
] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,15 @@ | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
pub use renet2; | ||
|
||
use bevy_app::prelude::*; | ||
use bevy_ecs::prelude::*; | ||
use bevy_time::prelude::*; | ||
#[cfg(feature = "netcode")] | ||
pub mod netcode; | ||
|
||
use renet2::{RenetClient, RenetServer, ServerEvent}; | ||
#[cfg(feature = "steam")] | ||
pub mod steam; | ||
|
||
#[cfg(feature = "transport")] | ||
pub mod transport; | ||
mod renet2; | ||
mod run_conditions; | ||
|
||
/// This system set is where all transports receive messages | ||
/// | ||
/// If you want to ensure data has arrived in the [`RenetClient`] or [`RenetServer`], then schedule your | ||
/// system after this set. | ||
/// | ||
/// This system set runs in PreUpdate. | ||
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct RenetReceive; | ||
|
||
/// This system set is where all transports send messages | ||
/// | ||
/// If you want to ensure your packets have been registered by the [`RenetClient`] or [`RenetServer`], then | ||
/// schedule your system before this set. | ||
/// | ||
/// This system set runs in PostUpdate. | ||
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct RenetSend; | ||
|
||
pub struct RenetServerPlugin; | ||
|
||
pub struct RenetClientPlugin; | ||
|
||
impl Plugin for RenetServerPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_resource::<Events<ServerEvent>>(); | ||
app.add_systems(PreUpdate, Self::update_system.run_if(resource_exists::<RenetServer>)); | ||
app.add_systems( | ||
PreUpdate, | ||
Self::emit_server_events_system | ||
.in_set(RenetReceive) | ||
.run_if(resource_exists::<RenetServer>) | ||
.after(Self::update_system), | ||
); | ||
} | ||
} | ||
|
||
impl RenetServerPlugin { | ||
pub fn update_system(mut server: ResMut<RenetServer>, time: Res<Time>) { | ||
server.update(time.delta()); | ||
} | ||
|
||
pub fn emit_server_events_system(mut server: ResMut<RenetServer>, mut server_events: EventWriter<ServerEvent>) { | ||
while let Some(event) = server.get_event() { | ||
server_events.send(event); | ||
} | ||
} | ||
} | ||
|
||
impl Plugin for RenetClientPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(PreUpdate, Self::update_system.run_if(client_should_update())); | ||
} | ||
} | ||
|
||
impl RenetClientPlugin { | ||
pub fn update_system(mut client: ResMut<RenetClient>, time: Res<Time>) { | ||
client.update(time.delta()); | ||
} | ||
} | ||
|
||
pub fn client_connected(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_connected(), | ||
None => false, | ||
} | ||
} | ||
|
||
pub fn client_disconnected(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_disconnected(), | ||
None => true, | ||
} | ||
} | ||
|
||
pub fn client_connecting(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_connecting(), | ||
None => false, | ||
} | ||
} | ||
|
||
pub fn client_just_connected(mut last_connected: Local<bool>, client: Option<Res<RenetClient>>) -> bool { | ||
let connected = client.map(|client| client.is_connected()).unwrap_or(false); | ||
|
||
let just_connected = !*last_connected && connected; | ||
*last_connected = connected; | ||
just_connected | ||
} | ||
|
||
pub fn client_just_disconnected(mut last_connected: Local<bool>, client: Option<Res<RenetClient>>) -> bool { | ||
let disconnected = client.map(|client| client.is_disconnected()).unwrap_or(true); | ||
|
||
let just_disconnected = *last_connected && disconnected; | ||
*last_connected = !disconnected; | ||
just_disconnected | ||
} | ||
|
||
pub fn client_should_update() -> impl Condition<()> { | ||
// (just_disconnected || !disconnected) && exists<RenetClient> | ||
IntoSystem::into_system( | ||
client_just_disconnected | ||
.or(not(client_disconnected)) | ||
.and(resource_exists::<RenetClient>), | ||
) | ||
pub mod prelude { | ||
pub use crate::renet2::*; | ||
pub use crate::run_conditions::*; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
pub use renet2::*; | ||
|
||
use bevy_app::prelude::*; | ||
use bevy_ecs::prelude::*; | ||
use bevy_time::prelude::*; | ||
|
||
use crate::prelude::client_should_update; | ||
|
||
/// This system set is where all transports receive messages | ||
/// | ||
/// If you want to ensure data has arrived in the [`RenetClient`] or [`RenetServer`], then schedule your | ||
/// system after this set. | ||
/// | ||
/// This system set runs in PreUpdate. | ||
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct RenetReceive; | ||
|
||
/// This system set is where all transports send messages | ||
/// | ||
/// If you want to ensure your packets have been registered by the [`RenetClient`] or [`RenetServer`], then | ||
/// schedule your system before this set. | ||
/// | ||
/// This system set runs in PostUpdate. | ||
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct RenetSend; | ||
|
||
pub struct RenetServerPlugin; | ||
|
||
pub struct RenetClientPlugin; | ||
|
||
impl Plugin for RenetServerPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_resource::<Events<ServerEvent>>(); | ||
app.add_systems(PreUpdate, Self::update_system.run_if(resource_exists::<RenetServer>)); | ||
app.add_systems( | ||
PreUpdate, | ||
Self::emit_server_events_system | ||
.in_set(RenetReceive) | ||
.run_if(resource_exists::<RenetServer>) | ||
.after(Self::update_system), | ||
); | ||
} | ||
} | ||
|
||
impl RenetServerPlugin { | ||
pub fn update_system(mut server: ResMut<RenetServer>, time: Res<Time>) { | ||
server.update(time.delta()); | ||
} | ||
|
||
pub fn emit_server_events_system(mut server: ResMut<RenetServer>, mut server_events: EventWriter<ServerEvent>) { | ||
while let Some(event) = server.get_event() { | ||
server_events.send(event); | ||
} | ||
} | ||
} | ||
|
||
impl Plugin for RenetClientPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(PreUpdate, Self::update_system.run_if(client_should_update())); | ||
} | ||
} | ||
|
||
impl RenetClientPlugin { | ||
pub fn update_system(mut client: ResMut<RenetClient>, time: Res<Time>) { | ||
client.update(time.delta()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
use renet2::RenetClient; | ||
|
||
pub fn client_connected(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_connected(), | ||
None => false, | ||
} | ||
} | ||
|
||
pub fn client_disconnected(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_disconnected(), | ||
None => true, | ||
} | ||
} | ||
|
||
pub fn client_connecting(client: Option<Res<RenetClient>>) -> bool { | ||
match client { | ||
Some(client) => client.is_connecting(), | ||
None => false, | ||
} | ||
} | ||
|
||
pub fn client_just_connected(mut last_connected: Local<bool>, client: Option<Res<RenetClient>>) -> bool { | ||
let connected = client.map(|client| client.is_connected()).unwrap_or(false); | ||
|
||
let just_connected = !*last_connected && connected; | ||
*last_connected = connected; | ||
just_connected | ||
} | ||
|
||
pub fn client_just_disconnected(mut last_connected: Local<bool>, client: Option<Res<RenetClient>>) -> bool { | ||
let disconnected = client.map(|client| client.is_disconnected()).unwrap_or(true); | ||
|
||
let just_disconnected = *last_connected && disconnected; | ||
*last_connected = !disconnected; | ||
just_disconnected | ||
} | ||
|
||
pub fn client_should_update() -> impl Condition<()> { | ||
// (just_disconnected || !disconnected) && exists<RenetClient> | ||
IntoSystem::into_system( | ||
client_just_disconnected | ||
.or(not(client_disconnected)) | ||
.and(resource_exists::<RenetClient>), | ||
) | ||
} |
Oops, something went wrong.