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

chore(deps): update to Bevy 0.15 #17

Merged
merged 7 commits into from
Dec 25, 2024
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
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_replicon_renet"
version = "0.5.1"
version = "0.6.0"
authors = [
"Hennadii Chernyshchyk <genaloner@gmail.com>",
"koe <ukoe@protonmail.com>",
Expand All @@ -25,39 +25,40 @@ rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true

[dependencies]
bevy_replicon = { version = "0.28", default-features = false }
bevy_renet = { version = "0.0.12", default-features = false }
bevy = { version = "0.14", default-features = false }
bevy_replicon = { version = "0.29", default-features = false }
bevy_renet = { version = "1.0", default-features = false }
bevy = { version = "0.15", default-features = false }

[dev-dependencies]
serde = "1.0"
clap = { version = "4.1", features = ["derive"] }
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_text",
"bevy_ui",
"bevy_gizmos",
"bevy_state",
"bevy_window",
"x11",
"default_font",
] }

[features]
default = ["client", "server", "renet_serde", "renet_transport"]
default = ["client", "server", "renet_netcode"]
server = ["bevy_replicon/server"]
client = ["bevy_replicon/client"]

# Re-exports of renet features
renet_serde = ["bevy_renet/serde"]
renet_transport = ["bevy_renet/transport"]
renet_netcode = ["bevy_renet/netcode"]
renet_steam = ["bevy_renet/steam"]

[[test]]
name = "transport"
required-features = ["server", "client", "renet_transport"]
name = "netcode"
required-features = ["server", "client", "renet_netcode"]

[[example]]
name = "simple_box"
required-features = ["server", "client", "renet_transport"]
required-features = ["server", "client", "renet_netcode"]

[[example]]
name = "tic_tac_toe"
required-features = ["server", "client", "renet_transport"]
required-features = ["server", "client", "renet_netcode"]
77 changes: 22 additions & 55 deletions examples/simple_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ use bevy::{
};
use bevy_replicon::prelude::*;
use bevy_replicon_renet::{
renet::{
transport::{
ClientAuthentication, NetcodeClientTransport, NetcodeServerTransport,
ServerAuthentication, ServerConfig,
},
ConnectionConfig, RenetClient, RenetServer,
netcode::{
ClientAuthentication, NetcodeClientTransport, NetcodeServerTransport, ServerAuthentication,
ServerConfig,
},
renet::{ConnectionConfig, RenetClient, RenetServer},
RenetChannelsExt, RepliconRenetPlugins,
};
use clap::Parser;
Expand Down Expand Up @@ -73,11 +71,7 @@ impl SimpleBoxPlugin {
) -> Result<(), Box<dyn Error>> {
match *cli {
Cli::SinglePlayer => {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
GREEN.into(),
));
commands.spawn((Player(ClientId::SERVER), PlayerColor(GREEN.into())));
}
Cli::Server { port } => {
let server_channels_config = channels.get_server_configs();
Expand All @@ -103,19 +97,15 @@ impl SimpleBoxPlugin {
commands.insert_resource(server);
commands.insert_resource(transport);

commands.spawn(TextBundle::from_section(
"Server",
TextStyle {
commands.spawn((
Text::new("Server"),
TextFont {
font_size: 30.0,
color: Color::WHITE,
..default()
..Default::default()
},
TextColor::WHITE,
));
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
GREEN.into(),
));
commands.spawn((Player(ClientId::SERVER), PlayerColor(GREEN.into())));
}
Cli::Client { port, ip } => {
let server_channels_config = channels.get_server_configs();
Expand All @@ -142,13 +132,13 @@ impl SimpleBoxPlugin {
commands.insert_resource(client);
commands.insert_resource(transport);

commands.spawn(TextBundle::from_section(
format!("Client: {client_id:?}"),
TextStyle {
commands.spawn((
Text(format!("Client: {client_id:?}")),
TextFont {
font_size: 30.0,
color: Color::WHITE,
..default()
},
TextColor::WHITE,
));
}
}
Expand All @@ -157,7 +147,7 @@ impl SimpleBoxPlugin {
}

fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

/// Logs server events and spawns a new player whenever a client connects.
Expand All @@ -170,11 +160,7 @@ impl SimpleBoxPlugin {
let r = ((client_id.get() % 23) as f32) / 23.0;
let g = ((client_id.get() % 27) as f32) / 27.0;
let b = ((client_id.get() % 39) as f32) / 39.0;
commands.spawn(PlayerBundle::new(
*client_id,
Vec2::ZERO,
Color::srgb(r, g, b),
));
commands.spawn((Player(*client_id), PlayerColor(Color::srgb(r, g, b))));
}
ServerEvent::ClientDisconnected { client_id, reason } => {
info!("{client_id:?} disconnected: {reason}");
Expand All @@ -187,7 +173,6 @@ impl SimpleBoxPlugin {
for (position, color) in &players {
gizmos.rect(
Vec3::new(position.x, position.y, 0.0),
Quat::IDENTITY,
Vec2::ONE * 50.0,
color.0,
);
Expand Down Expand Up @@ -228,7 +213,7 @@ impl SimpleBoxPlugin {
info!("received event {event:?} from {client_id:?}");
for (player, mut position) in &mut players {
if *client_id == player.0 {
**position += event.0 * time.delta_seconds() * MOVE_SPEED;
**position += event.0 * time.delta_secs() * MOVE_SPEED;
}
}
}
Expand Down Expand Up @@ -260,33 +245,15 @@ impl Default for Cli {
}
}

#[derive(Bundle)]
struct PlayerBundle {
player: Player,
position: PlayerPosition,
color: PlayerColor,
replicated: Replicated,
}

impl PlayerBundle {
fn new(client_id: ClientId, position: Vec2, color: Color) -> Self {
Self {
player: Player(client_id),
position: PlayerPosition(position),
color: PlayerColor(color),
replicated: Replicated,
}
}
}

/// Contains the client ID of a player.
/// Contains player ID.
#[derive(Component, Serialize, Deserialize)]
#[require(PlayerPosition, PlayerColor, Replicated)]
struct Player(ClientId);

#[derive(Component, Deserialize, Serialize, Deref, DerefMut)]
#[derive(Component, Deserialize, Serialize, Deref, DerefMut, Default)]
struct PlayerPosition(Vec2);

#[derive(Component, Deserialize, Serialize)]
#[derive(Component, Deserialize, Serialize, Default)]
struct PlayerColor(Color);

/// A movement event for the controlled box.
Expand Down
Loading
Loading