Skip to content

Commit

Permalink
Merge pull request #15 from Bendzae/replicon-0.29
Browse files Browse the repository at this point in the history
Upgrade to replicon 0.29
  • Loading branch information
Bendzae authored Dec 22, 2024
2 parents 657792c + 94f4f22 commit 0722c0a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 111 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
tags:
- '*'
- "*"

name: Publish

Expand All @@ -13,9 +13,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt install libudev-dev
sudo apt install libasound2-dev
- uses: taiki-e/install-action@nextest
- name: 'Build and test'
- name: "Build and test"
run: cargo nextest run --workspace --all-targets --all-features

crates_io_publish:
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ name: CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt install libudev-dev
sudo apt install libasound2-dev
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
20 changes: 5 additions & 15 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.5"
version = "0.2.6"
edition = "2021"
authors = ["Ben Dzaebel <[email protected]>"]
hompage = "bendz.dev"
Expand All @@ -13,26 +13,16 @@ 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.14", default_features = false }
bevy_replicon = "0.28.3"
bevy = { version = "0.15", default_features = false }
bevy_replicon = "0.29.1"
serde = "1.0"

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

[dev-dependencies]
clap = { version = "4.1", features = ["derive"] }
bevy = { version = "0.14", default-features = false, features = [
"bevy_asset",
"bevy_core_pipeline",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"bevy_gizmos",
"x11",
"default_font",
] }
bevy_replicon_renet = "0.5.0"
bevy = { version = "0.15", default-features = true }
bevy_replicon_renet = { git = "https://github.com/matoous/bevy_replicon_renet.git", branch = "md/bevy-0.15" }

[package.metadata.commands]
example_interpolation = "cargo run --example interpolated -- server & cargo run --example interpolated -- client && fg"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ commands.spawn((
));
```

## Compatitbiliy

| bevy | bevy_replicon | bevy_replicon_snap |
| ------ | ------------- | ------------------ |
| 0.15.0 | 0.29 | 0.26 |
| 0.14.0 | 0.27 | 0.25 |

## Alternatives

- [bevy_timewarp](https://github.com/RJ/bevy_timewarp) An awesome
Expand Down
46 changes: 22 additions & 24 deletions examples/interpolated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use std::{
time::SystemTime,
};

use bevy::{prelude::*, winit::UpdateMode::Continuous, winit::WinitSettings};
use bevy::{
color::palettes::css::{GREEN, WHITE},
prelude::*,
winit::{UpdateMode::Continuous, WinitSettings},
};
use bevy_replicon::prelude::*;
use bevy_replicon_renet::{
renet::{
transport::{
ClientAuthentication, NetcodeClientTransport, NetcodeServerTransport,
ServerAuthentication, ServerConfig,
},
netcode::{ClientAuthentication, NetcodeClientTransport, NetcodeServerTransport, ServerAuthentication, ServerConfig}, renet::{
ConnectionConfig, RenetClient, RenetServer,
},
RenetChannelsExt, RepliconRenetPlugins,
}, RenetChannelsExt, RepliconRenetPlugins
};
use bevy_replicon_snap::{
interpolation::{AppInterpolationExt, Interpolated},
Expand Down Expand Up @@ -67,7 +66,7 @@ impl Plugin for SimpleBoxPlugin {
.add_systems(
Update,
(
Self::movement_system.run_if(has_authority), // Runs only on the server or a single player.
Self::movement_system.run_if(server_or_singleplayer), // Runs only on the server or a single player.
Self::server_event_system.run_if(server_running), // Runs only on the server.
(Self::draw_boxes_system, Self::input_system),
),
Expand All @@ -86,7 +85,7 @@ impl SimpleBoxPlugin {
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
bevy::color::palettes::css::GREEN.into(),
GREEN.into(),
));
}
Cli::Server { port } => {
Expand Down Expand Up @@ -114,18 +113,18 @@ 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()
},
TextColor(WHITE.into()),
));
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Vec2::ZERO,
bevy::color::palettes::css::GREEN.into(),
GREEN.into(),
));
}
Cli::Client { port, ip } => {
Expand Down Expand Up @@ -153,13 +152,13 @@ impl SimpleBoxPlugin {
commands.insert_resource(client);
commands.insert_resource(transport);

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

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

/// Logs server events and spawns a new player whenever a client connects.
Expand Down Expand Up @@ -196,9 +195,8 @@ impl SimpleBoxPlugin {

fn draw_boxes_system(mut gizmos: Gizmos, players: Query<(&PlayerPosition, &PlayerColor)>) {
for (position, color) in &players {
gizmos.rect(
Vec3::new(position.x, position.y, 0.0),
Quat::IDENTITY,
gizmos.rect_2d(
Isometry2d::from_xy(position.x, position.y),
Vec2::ONE * 50.0,
color.0,
);
Expand Down Expand Up @@ -238,7 +236,7 @@ impl SimpleBoxPlugin {
for FromClient { client_id, event } in move_events.read() {
for (player, mut position) in &mut players {
if client_id.get() == player.0 {
**position += event.0 * time.delta_seconds() * MOVE_SPEED;
**position += event.0 * time.delta_secs() * MOVE_SPEED;
}
}
}
Expand Down
37 changes: 17 additions & 20 deletions examples/no_interpolation_or_prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ use serde::{Deserialize, Serialize};

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,
};

Expand Down Expand Up @@ -60,7 +58,7 @@ impl Plugin for SimpleBoxPlugin {
.add_systems(
Update,
(
Self::movement_system.run_if(has_authority), // Runs only on the server or a single player.
Self::movement_system.run_if(server_or_singleplayer), // Runs only on the server or a single player.
Self::server_event_system.run_if(resource_exists::<RenetServer>), // Runs only on the server.
(Self::draw_boxes_system, Self::input_system),
),
Expand Down Expand Up @@ -107,13 +105,13 @@ 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()
},
TextColor::WHITE,
));
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Expand Down Expand Up @@ -146,13 +144,13 @@ impl SimpleBoxPlugin {
commands.insert_resource(client);
commands.insert_resource(transport);

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

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

/// Logs server events and spawns a new player whenever a client connects.
Expand Down Expand Up @@ -189,9 +187,8 @@ impl SimpleBoxPlugin {

fn draw_boxes_system(mut gizmos: Gizmos, players: Query<(&PlayerPosition, &PlayerColor)>) {
for (position, color) in &players {
gizmos.rect(
Vec3::new(position.x, position.y, 0.0),
Quat::IDENTITY,
gizmos.rect_2d(
Isometry2d::from_xy(position.x, position.y),
Vec2::ONE * 50.0,
color.0,
);
Expand Down Expand Up @@ -232,7 +229,7 @@ impl SimpleBoxPlugin {
info!("received event {event:?} from client {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
34 changes: 15 additions & 19 deletions examples/owner_predicted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ use std::{
use bevy::{prelude::*, winit::UpdateMode::Continuous, winit::WinitSettings};
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 bevy_replicon_snap::{
Expand Down Expand Up @@ -118,13 +116,13 @@ 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()
},
TextColor::WHITE,
));
commands.spawn(PlayerBundle::new(
ClientId::SERVER,
Expand Down Expand Up @@ -156,14 +154,13 @@ impl SimpleBoxPlugin {

commands.insert_resource(client);
commands.insert_resource(transport);

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

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

/// Logs server events and spawns a new player whenever a client connects.
Expand Down Expand Up @@ -200,9 +197,8 @@ impl SimpleBoxPlugin {

fn draw_boxes_system(mut gizmos: Gizmos, players: Query<(&PlayerPosition, &PlayerColor)>) {
for (position, color) in &players {
gizmos.rect(
Vec3::new(position.x, position.y, 0.0),
Quat::IDENTITY,
gizmos.rect_2d(
Isometry2d::from_xy(position.x, position.y),
Vec2::ONE * 50.0,
color.0,
);
Expand Down
Loading

0 comments on commit 0722c0a

Please sign in to comment.