Skip to content

Commit

Permalink
Merge pull request #23 from Henauxg/bevy-0.14
Browse files Browse the repository at this point in the history
Update to Bevy 0.14
  • Loading branch information
Henauxg authored Jul 5, 2024
2 parents b4808e4 + f827299 commit 271d262
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 126 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.9.0 (2024-06-05)

- Update to use Bevy 0.14

## Version 0.8.0 (2024-05-12)

- Added a new crate `bevy_replicon_quinnet` with tests and examples, providing an integration of bevy_quinnet as a replicon back-end.
Expand Down
16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_quinnet"
version = "0.8.0"
version = "0.9.0"
description = "Bevy plugin for Client/Server multiplayer games using QUIC"
repository = "https://github.com/Henauxg/bevy_quinnet"
documentation = "https://docs.rs/bevy_quinnet"
Expand All @@ -15,7 +15,7 @@ exclude = ["assets/"]
members = ["bevy_replicon_quinnet"]

[dependencies]
bevy = { version = "0.13.0", default-features = false, features = [] }
bevy = { version = "0.14", default-features = false, features = [] }
rustls = { version = "0.21.0", default-features = false, features = [
"quic",
"dangerous_configuration",
Expand All @@ -30,7 +30,7 @@ quinn-proto = "0.10.1"
futures-util = "0.3.24"
futures = "0.3.24"
bincode = "1.3.3"
serde = "1.0.145"
serde = { version = "1.0.145", features = ["derive"] }
bytes = "1.5.0"
base64 = "0.13.1"
thiserror = "1.0.37"
Expand All @@ -41,7 +41,7 @@ default = ["shared-client-id"]
shared-client-id = []

[dev-dependencies]
bevy = { version = "0.13.0", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_asset", # Provides asset functionality
"bevy_audio", # Provides audio functionality
"vorbis", # OGG/VORBIS audio format support
Expand All @@ -52,6 +52,14 @@ bevy = { version = "0.13.0", default-features = false, features = [
"bevy_text", # Provides text functionality
"bevy_core_pipeline", # Provides cameras and other basic render pipeline features
"x11", # X11 display server support

# Can be removed later, temporary fixes for a bug in "0.14.0-rc.2"
"bevy_state",
"serialize",
"bevy_scene",
"bevy_pbr",
"ktx2",
"zstd",
] }
rand = "0.8.5"

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ A Client/Server game networking plugin using [QUIC](https://www.chromium.org/qui
- [Server](#server)
- [Channels](#channels)
- [Certificates and server authentication](#certificates-and-server-authentication)
- [Replicon integration](#replicon-integration)
- [Examples](#examples)
- [Replicon integration](#replicon-integration)
- [Compatible Bevy versions](#compatible-bevy-versions)
- [Misc](#misc)
- [Cargo features](#cargo-features)
Expand Down Expand Up @@ -331,6 +331,7 @@ Bevy Quinnet can be used as a transport in [`bevy_replicon`](https://github.com/

| bevy_quinnet | bevy |
| :----------- | :--- |
| 0.9 | 0.14 |
| 0.7-0.8 | 0.13 |
| 0.6 | 0.12 |
| 0.5 | 0.11 |
Expand Down
4 changes: 4 additions & 0 deletions bevy_replicon_quinnet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.4.0 (2024-07-05)

- Update `bevy_replicon` dependency from 0.26 to 0.27

## Version 0.3.0 (2024-05-27)

- Update `bevy_replicon` dependency from 0.25 to 0.26
Expand Down
18 changes: 13 additions & 5 deletions bevy_replicon_quinnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_replicon_quinnet"
version = "0.3.0"
version = "0.4.0"
description = "Integration with bevy_quinnet for bevy_replicon"
repository = "https://github.com/Henauxg/bevy_quinnet"
documentation = "https://docs.rs/bevy_replicon_quinnet"
Expand All @@ -12,19 +12,27 @@ readme = "README.md"
exclude = ["assets/"]

[dependencies]
bevy_replicon = { version = "0.26" }
bevy_quinnet = { version = "0.8.0", path = ".." }
bevy = { version = "0.13", default-features = false }
bevy_replicon = { version = "0.27" }
bevy_quinnet = { version = "0.9.0", path = ".." }
bevy = { version = "0.14", default-features = false }

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


# Can be removed later, temporary fixes for a bug in "0.14.0-rc.2"
"bevy_scene",
"bevy_pbr",
"ktx2",
"zstd",
] }

[[example]]
Expand Down
1 change: 1 addition & 0 deletions bevy_replicon_quinnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Sources for the examples can be found in the [examples](examples) directory.

| bevy | bevy_quinnet | bevy_replicon_quinnet | bevy_replicon |
| :--- | :----------- | :-------------------- | :------------ |
| 0.14 | 0.9 | 0.4 | 0.27 |
| 0.13 | 0.8 | 0.3 | 0.26 |
| 0.13 | 0.8 | 0.2 | 0.25 |
| 0.13 | 0.8 | 0.1 | 0.24 |
Expand Down
8 changes: 5 additions & 3 deletions bevy_replicon_quinnet/examples/simple_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use bevy_replicon_quinnet::{ChannelsConfigurationExt, RepliconQuinnetPlugins};
use clap::Parser;
use serde::{Deserialize, Serialize};

use bevy::color::palettes::css::GREEN;

const PORT: u16 = 5000;

fn main() {
Expand Down Expand Up @@ -76,7 +78,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
GREEN.into(),
));
}
Cli::Server { port } => {
Expand All @@ -101,7 +103,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
Color::GREEN,
GREEN.into(),
));
}
Cli::Client { port, ip } => {
Expand Down Expand Up @@ -149,7 +151,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
12 changes: 6 additions & 6 deletions bevy_replicon_quinnet/examples/tic_tac_toe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Plugin for TicTacToePlugin {

const GRID_SIZE: usize = 3;

const BACKGROUND_COLOR: Color = Color::rgb(0.9, 0.9, 0.9);
const BACKGROUND_COLOR: Color = Color::srgb(0.9, 0.9, 0.9);

// Bottom text defined in two sections, first for text and second for symbols with different font.
const TEXT_SECTION: usize = 0;
Expand All @@ -105,7 +105,7 @@ impl TicTacToePlugin {
const LINE_THICKNESS: f32 = 10.0;
const BOARD_SIZE: f32 = CELL_SIZE * GRID_SIZE as f32 + LINES_COUNT as f32 * LINE_THICKNESS;

const BOARD_COLOR: Color = Color::rgb(0.8, 0.8, 0.8);
const BOARD_COLOR: Color = Color::srgb(0.8, 0.8, 0.8);

for line in 0..LINES_COUNT {
let position = -BOARD_SIZE / 2.0
Expand Down Expand Up @@ -144,7 +144,7 @@ impl TicTacToePlugin {
const BUTTON_SIZE: f32 = CELL_SIZE / 1.2;
const BUTTON_MARGIN: f32 = (CELL_SIZE + LINE_THICKNESS - BUTTON_SIZE) / 2.0;

const TEXT_COLOR: Color = Color::rgb(0.5, 0.5, 1.0);
const TEXT_COLOR: Color = Color::srgb(0.5, 0.5, 1.0);
const FONT_SIZE: f32 = 40.0;

commands
Expand Down Expand Up @@ -351,7 +351,7 @@ impl TicTacToePlugin {
children: Query<&Children>,
mut pick_events: EventWriter<CellPick>,
) {
const HOVER_COLOR: Color = Color::rgb(0.85, 0.85, 0.85);
const HOVER_COLOR: Color = Color::srgb(0.85, 0.85, 0.85);

for (button_entity, button_parent, interaction, mut background) in &mut buttons {
match interaction {
Expand Down Expand Up @@ -572,8 +572,8 @@ impl Symbol {

fn color(self) -> Color {
match self {
Symbol::Cross => Color::rgb(1.0, 0.5, 0.5),
Symbol::Nought => Color::rgb(0.5, 0.5, 1.0),
Symbol::Cross => Color::srgb(1.0, 0.5, 0.5),
Symbol::Nought => Color::srgb(0.5, 0.5, 1.0),
}
}

Expand Down
40 changes: 22 additions & 18 deletions bevy_replicon_quinnet/tests/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ fn connect_disconnect() {

setup(&mut server_app, &mut client_app, port);

let mut quinnet_client = client_app.world.resource_mut::<QuinnetClient>();
let mut quinnet_client = client_app.world_mut().resource_mut::<QuinnetClient>();
assert!(quinnet_client.is_connected());
let default_connection = quinnet_client.get_default_connection().unwrap();
quinnet_client.close_connection(default_connection).unwrap();

client_app.update();

let replicon_client = client_app.world.resource_mut::<RepliconClient>();
let replicon_client = client_app.world_mut().resource_mut::<RepliconClient>();
assert!(replicon_client.is_disconnected());

server_wait_for_disconnect(&mut server_app);

let quinnet_server = server_app.world.resource::<QuinnetServer>();
let quinnet_server = server_app.world().resource::<QuinnetServer>();
assert_eq!(quinnet_server.endpoint().clients().len(), 0);

let connected_clients = server_app.world.resource::<ConnectedClients>();
let connected_clients = server_app.world().resource::<ConnectedClients>();
assert_eq!(connected_clients.len(), 0);
}

Expand All @@ -71,12 +71,12 @@ fn replication() {

setup(&mut server_app, &mut client_app, port);

server_app.world.spawn(Replicated);
server_app.world_mut().spawn(Replicated);

server_app.update();
client_wait_for_message(&mut client_app);

assert_eq!(client_app.world.entities().len(), 1);
assert_eq!(client_app.world().entities().len(), 1);
}

#[test]
Expand All @@ -98,15 +98,15 @@ fn server_event() {

setup(&mut server_app, &mut client_app, port);

server_app.world.send_event(ToClients {
server_app.world_mut().send_event(ToClients {
mode: SendMode::Broadcast,
event: DummyEvent,
});

server_app.update();
client_wait_for_message(&mut client_app);

let dummy_events = client_app.world.resource::<Events<DummyEvent>>();
let dummy_events = client_app.world().resource::<Events<DummyEvent>>();
assert_eq!(dummy_events.len(), 1);
}

Expand All @@ -129,12 +129,12 @@ fn client_event() {

setup(&mut server_app, &mut client_app, port);

client_app.world.send_event(DummyEvent);
client_app.world_mut().send_event(DummyEvent);
client_app.update();
server_wait_for_message(&mut server_app);

let client_events = server_app
.world
.world()
.resource::<Events<FromClient<DummyEvent>>>();
assert_eq!(client_events.len(), 1);
}
Expand All @@ -147,11 +147,11 @@ fn setup(server_app: &mut App, client_app: &mut App, server_port: u16) {

fn setup_client(app: &mut App, server_port: u16) {
let channels_config = app
.world
.world()
.resource::<RepliconChannels>()
.get_client_configs();

let mut client = app.world.resource_mut::<QuinnetClient>();
let mut client = app.world_mut().resource_mut::<QuinnetClient>();
client
.open_connection(
ClientEndpointConfiguration::from_ips(
Expand All @@ -168,11 +168,11 @@ fn setup_client(app: &mut App, server_port: u16) {

fn setup_server(app: &mut App, server_port: u16) {
let channels_config = app
.world
.world()
.resource::<RepliconChannels>()
.get_server_configs();

let mut server = app.world.resource_mut::<QuinnetServer>();
let mut server = app.world_mut().resource_mut::<QuinnetServer>();
server
.start_endpoint(
ServerEndpointConfiguration::from_ip(IpAddr::V4(Ipv4Addr::LOCALHOST), server_port),
Expand All @@ -188,7 +188,11 @@ fn wait_for_connection(server_app: &mut App, client_app: &mut App) {
loop {
client_app.update();
server_app.update();
if client_app.world.resource::<QuinnetClient>().is_connected() {
if client_app
.world()
.resource::<QuinnetClient>()
.is_connected()
{
break;
}
}
Expand All @@ -199,7 +203,7 @@ fn client_wait_for_message(client_app: &mut App) {
sleep(Duration::from_secs_f32(0.05));
client_app.update();
if client_app
.world
.world()
.resource::<QuinnetClient>()
.connection()
.received_messages_count()
Expand All @@ -215,7 +219,7 @@ fn server_wait_for_message(server_app: &mut App) {
sleep(Duration::from_secs_f32(0.05));
server_app.update();
if server_app
.world
.world()
.resource::<QuinnetServer>()
.endpoint()
.endpoint_stats()
Expand All @@ -232,7 +236,7 @@ fn server_wait_for_disconnect(server_app: &mut App) {
sleep(Duration::from_secs_f32(0.05));
server_app.update();
if server_app
.world
.world()
.resource::<QuinnetServer>()
.endpoint()
.endpoint_stats()
Expand Down
20 changes: 18 additions & 2 deletions examples/breakout/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::net::{IpAddr, Ipv4Addr};
use bevy::prelude::*;
use bevy_quinnet::{
client::QuinnetClientPlugin,
server::{QuinnetServerPlugin, QuinnetServer},
server::{QuinnetServer, QuinnetServerPlugin},
};
use client::BACKGROUND_COLOR;

Expand Down Expand Up @@ -134,7 +134,7 @@ fn main() {
.insert_resource(client::BricksMapping::default());

// ------ Main menu
app.add_systems(Update, bevy::window::close_on_esc)
app.add_systems(Update, close_on_esc)
.add_systems(OnEnter(GameState::MainMenu), client::setup_main_menu)
.add_systems(
Update,
Expand Down Expand Up @@ -202,3 +202,19 @@ fn main() {

app.run();
}

pub fn close_on_esc(
mut commands: Commands,
focused_windows: Query<(Entity, &Window)>,
input: Res<ButtonInput<KeyCode>>,
) {
for (window, focus) in focused_windows.iter() {
if !focus.focused {
continue;
}

if input.just_pressed(KeyCode::Escape) {
commands.entity(window).despawn();
}
}
}
Loading

0 comments on commit 271d262

Please sign in to comment.