Skip to content

Commit

Permalink
Merge pull request #2 from toolness/bevy-0.11
Browse files Browse the repository at this point in the history
As per the instructions in https://bevyengine.org/learn/migration-guides/0.10-0.11/.

## Notes

* `bevy_rapier`'s new Gizmo-based debug renderer seems buggy, as lines seem to disappear when parts of them are off-camera.  I mentioned this in dimforge/bevy_rapier#345 (comment).

* It seems that all of my Blender scene's wall colliders going along the Y axis in Blender had a non-uniform scale applied to them.  Previously this seemed to pose no problem (or perhaps it was a problem of a different kind that I never noticed) but the new versions of the dependencies appear to ignore the non-uniform scale, which caused problems, so I applied the scale in the scene to make it all uniform (afe2a78).

* Spawning the player at the origin made them get stuck in the floor on respawn.  Not sure exactly why this was happening (perhaps weird system ordering) but nudging the start position to be slightly above the ground fixed this (238e8d1).
  • Loading branch information
toolness authored Jul 15, 2023
2 parents 478f223 + 238e8d1 commit b7cd260
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 266 deletions.
606 changes: 377 additions & 229 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.10.1"
bevy-inspector-egui = { version = "0.18.3", optional = true }
bevy_common_assets = { version = "0.6.0", features = ["json"] }
bevy = "0.11.0"
bevy-inspector-egui = { version = "0.19.0", optional = true }
bevy_common_assets = { version = "0.7.0", features = ["json"] }
# We can't use 0.21.0 due to https://github.com/dimforge/bevy_rapier/issues/345. Once 0.22 is
# released, we can switch to that.
bevy_rapier3d = {git = "https://github.com/dimforge/bevy_rapier.git"}
serde = { version = "1.0.164", features = ["serde_derive"] }
bevy_rapier3d = { version = "0.22.0" }
serde = { version = "1.0.171", features = ["serde_derive"] }

# Enable a small amount of optimization in debug mode
[profile.dev]
Expand Down
2 changes: 1 addition & 1 deletion assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"gravity": 9.8,
"jump_velocity": 5.0,
"fall_off_level_y": -50.0,
"spawn_position": [0, 0, 0],
"spawn_position": [0, 0.1, 0],
"ambient_color": {
"Rgba": {
"red": 0.052,
Expand Down
Binary file modified assets/dungeon.blend
Binary file not shown.
10 changes: 6 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use bevy_common_assets::json::JsonAssetPlugin;

use crate::app_state::{AppState, AssetsLoading};

#[derive(serde::Deserialize, bevy::reflect::TypeUuid, Resource, Default, Clone)]
#[derive(
serde::Deserialize, bevy::reflect::TypeUuid, bevy::reflect::TypePath, Resource, Default, Clone,
)]
#[uuid = "83187ffe-c216-4626-803f-e2a96e016323"]
pub struct Config {
/// Player speed in meters per second.
Expand Down Expand Up @@ -59,9 +61,9 @@ pub struct ConfigPlugin;

impl Plugin for ConfigPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(JsonAssetPlugin::<Config>::new(&["json"]))
app.add_plugins(JsonAssetPlugin::<Config>::new(&["json"]))
.init_resource::<Config>()
.add_startup_system(load_config)
.add_system(apply_config.in_schedule(OnExit(AppState::LoadingAssets)));
.add_systems(Startup, load_config)
.add_systems(OnExit(AppState::LoadingAssets), apply_config);
}
}
4 changes: 2 additions & 2 deletions src/debug_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl Plugin for DebugModePlugin {
{
#[cfg(feature = "debug_mode")]
{
app.add_system(toggle_grab_cursor);
app.add_systems(Update, toggle_grab_cursor);
let inspector = bevy_inspector_egui::quick::WorldInspectorPlugin::new();
app.add_plugin(inspector.run_if(is_in_debug_mode));
app.add_plugins(inspector.run_if(is_in_debug_mode));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/dungeon_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ pub struct DungeonScenePlugin;

impl Plugin for DungeonScenePlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(load_scene)
app.add_systems(Startup, load_scene)
.init_resource::<AssetsLoading>()
.add_system(wait_for_scene_to_load.in_set(OnUpdate(AppState::LoadingAssets)))
.add_systems(
Update,
wait_for_scene_to_load.run_if(in_state(AppState::LoadingAssets)),
)
.add_systems(
OnEnter(AppState::SettingUpScene),
(
set_global_rendering_resources,
fix_scene_emissive_materials,
Expand All @@ -37,8 +41,7 @@ impl Plugin for DungeonScenePlugin {
fix_scene_physics,
start_game,
)
.chain()
.in_schedule(OnEnter(AppState::SettingUpScene)),
.chain(),
);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ fn show_instructions(mut commands: Commands, fonts: Res<Fonts>, config: Res<Conf
.with_text_alignment(TextAlignment::Left)
.with_style(Style {
position_type: PositionType::Absolute,
position: UiRect {
left: Val::Px(10.0),
top: Val::Px(10.0),
..Default::default()
},
left: Val::Px(10.0),
top: Val::Px(10.0),
..Default::default()
}),
InstructionText,
Expand All @@ -66,8 +63,8 @@ pub struct InstructionsPlugin;

impl Plugin for InstructionsPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(load_fonts)
.add_system(show_instructions.in_schedule(OnEnter(AppState::InGame)))
.add_system(hide_instructions.in_set(OnUpdate(AppState::InGame)));
app.add_systems(Startup, load_fonts)
.add_systems(OnEnter(AppState::InGame), show_instructions)
.add_systems(Update, hide_instructions.run_if(in_state(AppState::InGame)));
}
}
24 changes: 14 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ fn main() {
}),
..Default::default()
}))
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugin(RapierDebugRenderPlugin {
always_on_top: true,
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugins(RapierDebugRenderPlugin {
enabled: false,
..default()
})
.add_system(bevy::window::close_on_esc.run_if(is_not_wasm))
.add_plugin(ConfigPlugin)
.add_plugin(PlayerPlugin)
.add_plugin(DungeonScenePlugin)
.add_plugin(InstructionsPlugin)
.add_plugin(DebugModePlugin)
.add_system(toggle_rapier_debug_render_mode)
.insert_resource(GizmoConfig {
enabled: true,
depth_bias: -1.0,
..Default::default()
})
.add_systems(Update, bevy::window::close_on_esc.run_if(is_not_wasm))
.add_plugins(ConfigPlugin)
.add_plugins(PlayerPlugin)
.add_plugins(DungeonScenePlugin)
.add_plugins(InstructionsPlugin)
.add_plugins(DebugModePlugin)
.add_systems(Update, toggle_rapier_debug_render_mode)
.run();
}

Expand Down
8 changes: 5 additions & 3 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Player {
grounded: bool,
}

#[derive(Event)]
pub struct PlayerMovement;

fn player_spawn_transform(config: &Config) -> Transform {
Expand Down Expand Up @@ -245,17 +246,18 @@ pub struct PlayerPlugin;

impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.add_system(setup_player.in_schedule(OnEnter(AppState::SettingUpScene)))
.add_startup_system(grab_cursor)
app.add_systems(OnEnter(AppState::SettingUpScene), setup_player)
.add_systems(Startup, grab_cursor)
.add_systems(
Update,
(
maybe_respawn_player,
player_movement.run_if(not(is_in_debug_mode)),
player_look.run_if(not(is_in_debug_mode)),
player_force_push.run_if(not(is_in_debug_mode)),
update_player_after_physics,
)
.in_set(OnUpdate(AppState::InGame)),
.run_if(in_state(AppState::InGame)),
)
.add_event::<PlayerMovement>();
}
Expand Down

0 comments on commit b7cd260

Please sign in to comment.