Skip to content

Commit

Permalink
bevy 0.14 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
cscorley authored Aug 27, 2024
1 parent 479966c commit f6aa1f8
Show file tree
Hide file tree
Showing 10 changed files with 2,137 additions and 1,396 deletions.
3,361 changes: 2,066 additions & 1,295 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ web = ["bevy_ggrs/wasm-bindgen", "ggrs/wasm-bindgen"]

[dependencies]
# Prefer listing the exact bevy and bevy-adjacent versions here for clarity of what worked
bevy = "0.12.0"
bevy-inspector-egui = "0.21.0"
bevy_framepace = "0.14.1"
bevy_ggrs = "0.14.0"
bevy_matchbox = { version = "0.8.0", features = ["ggrs"] }
bevy = "0.14.1"
bevy-inspector-egui = "0.25.2"
bevy_framepace = "0.17.1"
bevy_ggrs = "0.16.0"
bevy_matchbox = { version = "0.10.0", features = ["ggrs"] }
bincode = "1.3"
bytemuck = { version = "1.13", features = ["derive"] }
ggrs = { version = "0.10.0", features = ["sync-send"] }
bytemuck = { version = "1.17", features = ["derive"] }
ggrs = { version = "0.10.2", features = ["sync-send"] }
log = "0.4"
rand = "0.8.5"
serde = { version = "1.0.192", features = ["serde_derive"] }
serde = { version = "1.0.209", features = ["serde_derive"] }
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-log = "0.1"

# This branch must be used until dimforge/bevy_rapier PRs #233 is merged
# bevy_rapier2d = { version = "0.22.0", features = [
# bevy_rapier2d = { path = "../bevy_rapier/bevy_rapier2d", features = [
bevy_rapier2d = { git = "https://github.com/cscorley/bevy_rapier", branch = "more-deterministic-context-0.12", features = [
bevy_rapier2d = { git = "https://github.com/cscorley/bevy_rapier", branch = "more-deterministic-context-0.14", features = [
"enhanced-determinism",
"serde-serialize",
] }
Expand All @@ -62,7 +62,7 @@ bevy_rapier2d = { git = "https://github.com/cscorley/bevy_rapier", branch = "mor
# use glam ourselves, because we want to force on the libm feature.
# Unfortunately, we cannot enable the feature via bevy yet, which would be
# optimal.
glam = { version = "0.24.1", features = ["libm"] }
glam = { version = "0.28.0", features = ["libm"] }

# Add our web-only dependencies
[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
66 changes: 16 additions & 50 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "Bevy GGRS Rapier Example";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
Expand All @@ -15,7 +15,7 @@
pkgs = import nixpkgs { inherit system overlays; };
pkgsUnstable = import nixpkgs-unstable { inherit system overlays; };

rusts = pkgs.rust-bin.stable.latest.complete.override {
rusts = pkgs.rust-bin.stable."1.80.1".complete.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
};
Expand Down
2 changes: 1 addition & 1 deletion src/log_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Default for LogSettings {
impl Plugin for LogPlugin {
fn build(&self, app: &mut App) {
let default_filter = {
let settings = app.world.get_resource_or_insert_with(LogSettings::default);
let settings = app.world_mut().get_resource_or_insert_with(LogSettings::default);
format!("{},{}", settings.level, settings.filter)
};
LogTracer::init().unwrap();
Expand Down
54 changes: 34 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
// Having 100+ entities ready to spawn will cause bevy_rapier to receive
// components out-of-order. This is good for testing desync on frame 1!
let _ = app
.world
.world_mut()
.spawn_batch((0..101).map(DeterministicSpawnBundle::new))
.collect::<Vec<Entity>>();

Expand Down Expand Up @@ -122,7 +122,7 @@ fn main() {
.add_systems(Startup, respawn_all)
.add_systems(Startup, connect)
.add_systems(Update, toggle_random_input)
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Update, close_on_esc)
.add_systems(Update, update_matchbox_socket)
.add_systems(Update, handle_p2p_events);

Expand Down Expand Up @@ -224,33 +224,31 @@ fn main() {
app.add_plugins(
RapierPhysicsPlugin::<NoUserData>::default()
// The physics scale really should not matter for a game of this size
.with_physics_scale(1.)
.with_length_unit(1.)
// This allows us to hook in the systems ourselves above in the GGRS schedule
.with_default_system_setup(false),
);

// Make sure to insert a new configuration with fixed timestep mode after configuring the plugin
app.insert_resource(RapierConfiguration {
// The timestep_mode MUST be fixed
timestep_mode: TimestepMode::Fixed {
dt: 1. / FPS as f32,
substeps: 1,
},

// This should work with gravity, too. It is fun for testing.
// gravity: Vec2::ZERO,
let mut rapier_config = RapierConfiguration::new(1.);
// The timestep_mode MUST be fixed
rapier_config.timestep_mode = TimestepMode::Fixed {
dt: 1. / FPS as f32,
substeps: 1,
};
// This should work with gravity, too. It is fun for testing.
// rapier_config.gravity = Vec2::ZERO;

// Turn off query pipeline since this example does not use it
query_pipeline_active: false,
// Turn off query pipeline since this example does not use it
rapier_config.query_pipeline_active = false;

// We will turn this on after "loading", this helps when looking at init issues
physics_pipeline_active: false,
// Turn off query pipeline since this example does not use it
rapier_config.physics_pipeline_active = false;

// Do not check internal structures for transform changes
force_update_from_transform_changes: true,
// Do not check internal structures for transform changes
rapier_config.force_update_from_transform_changes = true;

..default()
});
app.insert_resource(rapier_config);

// We don't really draw anything ourselves, just show us the raw physics colliders
app.add_plugins(RapierDebugRenderPlugin {
Expand All @@ -272,3 +270,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();
}
}
}
4 changes: 0 additions & 4 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use bevy_matchbox::{

use crate::prelude::*;

/// Not necessary for this demo, but useful debug output sometimes.
#[derive(Resource)]
pub struct NetworkStatsTimer(pub Timer);

pub fn connect(mut commands: Commands) {
// Connect immediately.
// This starts to poll the matchmaking service for our other player to connect.
Expand Down
6 changes: 3 additions & 3 deletions src/random_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub struct RandomInput {
}

/// Non-game input. Just chucking this into the stack carelessly.
pub fn toggle_random_input(mut commands: Commands, keys: Res<Input<KeyCode>>) {
if keys.just_pressed(KeyCode::R) {
pub fn toggle_random_input(mut commands: Commands, keys: Res<ButtonInput<KeyCode>>) {
if keys.just_pressed(KeyCode::KeyR) {
commands.insert_resource(RandomInput { on: true });
}
if keys.just_pressed(KeyCode::T) {
if keys.just_pressed(KeyCode::KeyT) {
commands.insert_resource(RandomInput { on: false });
}
}
10 changes: 5 additions & 5 deletions src/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct GGRSInput {
pub fn input(
mut commands: Commands,
local_players: Res<LocalPlayers>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut random: ResMut<RandomInput>,
physics_enabled: Res<PhysicsEnabled>,
) {
Expand All @@ -42,16 +42,16 @@ pub fn input(
// Do not do anything until physics are live
if physics_enabled.0 {
// Build the input
if keyboard_input.pressed(KeyCode::W) {
if keyboard_input.pressed(KeyCode::KeyW) {
input |= INPUT_UP;
}
if keyboard_input.pressed(KeyCode::A) {
if keyboard_input.pressed(KeyCode::KeyA) {
input |= INPUT_LEFT;
}
if keyboard_input.pressed(KeyCode::S) {
if keyboard_input.pressed(KeyCode::KeyS) {
input |= INPUT_DOWN;
}
if keyboard_input.pressed(KeyCode::D) {
if keyboard_input.pressed(KeyCode::KeyD) {
input |= INPUT_RIGHT;
}

Expand Down
6 changes: 0 additions & 6 deletions src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ pub fn startup(mut commands: Commands) {

// random movement for testing
commands.insert_resource(RandomInput { on: true });

// network timer
commands.insert_resource(NetworkStatsTimer(Timer::from_seconds(
2.0,
TimerMode::Repeating,
)))
}

pub fn reset_rapier(
Expand Down

0 comments on commit f6aa1f8

Please sign in to comment.