Skip to content

Commit

Permalink
Merge pull request #10 from Bendzae/feat/replicon-0.27
Browse files Browse the repository at this point in the history
Replicon 0.27
  • Loading branch information
Bendzae authored Jul 21, 2024
2 parents ce179fa + f919147 commit 00c9f16
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_replicon_snap"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
authors = ["Ben Dzaebel <[email protected]>"]
hompage = "bendz.dev"
Expand All @@ -13,16 +13,15 @@ description = "High-level networking crate that extends the bevy_replicon crate
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.13", default_features = false }
bevy_replicon = "0.26.3"
bevy_replicon_renet = "0.3.0"
bevy = { version = "0.14", default_features = false }
bevy_replicon = "0.27"
serde = "1.0"

bevy_replicon_snap_macros = { version = "0.2.0", path = "macros" }

[dev-dependencies]
clap = { version = "4.1", features = ["derive"] }
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_asset",
"bevy_core_pipeline",
"bevy_render",
Expand All @@ -33,6 +32,7 @@ bevy = { version = "0.13", default-features = false, features = [
"x11",
"default_font",
] }
bevy_replicon_renet = "0.4.0"

[package.metadata.commands]
example_interpolation = "cargo run --example interpolated -- server & cargo run --example interpolated -- client && fg"
Expand Down
6 changes: 3 additions & 3 deletions examples/interpolated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Server { port } => {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Client { port, ip } => {
Expand Down Expand Up @@ -184,7 +184,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
*client_id,
Vec2::ZERO,
Color::rgb(r, g, b),
Color::srgb(r, g, b),
));
}
ServerEvent::ClientDisconnected { client_id, reason } => {
Expand Down
6 changes: 3 additions & 3 deletions examples/no_interpolation_or_prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Server { port } => {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Client { port, ip } => {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
*client_id,
Vec2::ZERO,
Color::rgb(r, g, b),
Color::srgb(r, g, b),
));
}
ServerEvent::ClientDisconnected { client_id, reason } => {
Expand Down
6 changes: 3 additions & 3 deletions examples/owner_predicted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Server { port } => {
Expand Down Expand Up @@ -129,7 +129,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
bevy::color::palettes::css::GREEN.into(),
));
}
Cli::Client { port, ip } => {
Expand Down Expand Up @@ -188,7 +188,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
*client_id,
Vec2::ZERO,
Color::rgb(r, g, b),
Color::srgb(r, g, b),
));
}
ServerEvent::ClientDisconnected { client_id, reason } => {
Expand Down
6 changes: 3 additions & 3 deletions src/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use bevy_replicon::{
bincode,
core::{
command_markers::{AppMarkerExt, MarkerConfig},
common_conditions::client_connected,
ctx::{RemoveCtx, WriteCtx},
replication_registry::rule_fns::RuleFns,
replication_rules::AppRuleExt,
},
};
use bevy_replicon_renet::renet::RenetClient;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -168,7 +168,7 @@ impl AppInterpolationExt for App {
PreUpdate,
(snapshot_buffer_init_system::<T>.after(owner_prediction_init_system))
.in_set(InterpolationSet::Init)
.run_if(resource_exists::<RenetClient>),
.run_if(client_connected),
);
self.add_systems(
PreUpdate,
Expand All @@ -178,7 +178,7 @@ impl AppInterpolationExt for App {
)
.chain()
.in_set(InterpolationSet::Interpolate)
.run_if(resource_exists::<RenetClient>),
.run_if(client_connected),
)
.replicate::<T>()
.register_marker_with::<RecordSnapshotsMarker>(MarkerConfig {
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::Debug;

use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::renet::transport::NetcodeClientTransport;
use serde::{Deserialize, Serialize};

pub use bevy_replicon_snap_macros;
Expand Down Expand Up @@ -53,7 +52,7 @@ impl Plugin for SnapshotInterpolationPlugin {
.add_systems(
Update,
owner_prediction_init_system
.run_if(resource_exists::<NetcodeClientTransport>)
.run_if(client_connected)
.in_set(InterpolationSet::Init),
)
.insert_resource(SnapshotInterpolationConfig {
Expand Down
22 changes: 11 additions & 11 deletions src/prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use bevy::{
entity::Entity,
event::{Event, EventReader},
query::{Added, With, Without},
schedule::{common_conditions::resource_exists, IntoSystemConfigs},
schedule::IntoSystemConfigs,
system::{Commands, Query, Res, ResMut, Resource},
},
reflect::Reflect,
time::Time,
};
use bevy_replicon::{
client::{
confirm_history::ConfirmHistory,
events::{ClientEventAppExt, FromClient},
},
client::confirm_history::ConfirmHistory,
core::{
channels::RepliconChannel, common_conditions::has_authority, replication_rules::AppRuleExt,
channels::RepliconChannel,
common_conditions::{client_connected, has_authority},
replication_rules::AppRuleExt,
replicon_client::RepliconClient,
},
prelude::{ClientEventAppExt, FromClient},
};
use bevy_replicon_renet::renet::{transport::NetcodeClientTransport, RenetClient};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::vec_deque::Iter;
use std::collections::VecDeque;
Expand Down Expand Up @@ -87,12 +87,12 @@ impl<T: Event> PredictedEventHistory<T> {

pub fn owner_prediction_init_system(
q_owners: Query<(Entity, &NetworkOwner), Added<OwnerPredicted>>,
client: Res<NetcodeClientTransport>,
client: Res<RepliconClient>,
mut commands: Commands,
) {
let client_id = client.client_id();
let client_id = client.id().expect("No client id id found");
for (e, id) in q_owners.iter() {
if id.0 == client_id.raw() {
if id.0 == client_id.get() {
commands.entity(e).insert(Predicted);
} else {
commands.entity(e).insert(Interpolated);
Expand Down Expand Up @@ -203,7 +203,7 @@ impl AppPredictionExt for App {
Update,
(
server_update_system::<E, T, C>.run_if(has_authority), // Runs only on the server or a single player.
predicted_update_system::<E, T, C>.run_if(resource_exists::<RenetClient>), // Runs only on clients.
predicted_update_system::<E, T, C>.run_if(client_connected), // Runs only on clients.
),
)
.replicate::<T>()
Expand Down

0 comments on commit 00c9f16

Please sign in to comment.