Skip to content

Commit

Permalink
Merge pull request #23 from jameshiew/bevy-0.15
Browse files Browse the repository at this point in the history
Update to Bevy 0.15
  • Loading branch information
jameshiew authored Nov 30, 2024
2 parents 7a6457a + 323978a commit 472f3a0
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 428 deletions.
1,098 changes: 732 additions & 366 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 @@ -3,13 +3,13 @@ name = "infinigen"
version = "0.0.0"
edition = "2021"
publish = false
rust-version = "1.80.1"
rust-version = "1.82.0" # msrv should be at least the msrv of the bevy version used

[dependencies]
bevy = { version = "0.14.2" }
bevy_common_assets = { version = "0.11.0", features = ["ron"] }
bevy_egui = { version = "0.30.1" }
bevy-inspector-egui = { version = "0.27.0" }
bevy = { version = "0.15.0" }
bevy_common_assets = { version = "0.12.0", features = ["ron"] }
bevy_egui = { version = "0.31.1" }
bevy-inspector-egui = "0.28.0"

# config
config = { version = "0.14.1", default-features = false, features = ["ron"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cargo run --features dynamic_linking
- <kbd>Space</kbd> - ascend
- <kbd>Shift</kbd> - descend
- <kbd>F3</kbd> - toggle wireframes
- <kbd>F7</kbd> - toggle debug panels
- <kbd>F9</kbd> - toggle chunk borders (only works near the origin)

### Configuration
Expand Down
10 changes: 5 additions & 5 deletions src/camera/input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! adapted from bevy_flycam
use bevy::ecs::event::ManualEventReader;
use bevy::ecs::event::EventCursor;
use bevy::input::mouse::MouseMotion;
use bevy::prelude::*;
use bevy::window::{CursorGrabMode, PrimaryWindow};
Expand Down Expand Up @@ -30,7 +30,7 @@ impl Default for KeyBindings {

#[derive(Resource, Default)]
pub struct InputState {
mouse_motion: ManualEventReader<MouseMotion>,
mouse_motion: EventCursor<MouseMotion>,
}

pub fn keyboard(
Expand All @@ -49,7 +49,7 @@ pub fn keyboard(
let right = Vec3::new(local_z.z, 0., -local_z.x);

for key in keys.get_pressed() {
match window.cursor.grab_mode {
match window.cursor_options.grab_mode {
CursorGrabMode::None => (),
_ => {
let key = *key;
Expand All @@ -70,7 +70,7 @@ pub fn keyboard(
}

velocity = velocity.normalize_or_zero();
transform.translation += velocity * time.delta_seconds() * camera.speed;
transform.translation += velocity * time.delta_secs() * camera.speed;
}
}
}
Expand All @@ -87,7 +87,7 @@ pub fn mouse(
for mut transform in query.iter_mut() {
for ev in state.mouse_motion.read(&motion) {
let (mut yaw, mut pitch, _) = transform.rotation.to_euler(EulerRot::YXZ);
match window.cursor.grab_mode {
match window.cursor_options.grab_mode {
CursorGrabMode::None => (),
_ => {
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
Expand Down
27 changes: 13 additions & 14 deletions src/camera/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{
core_pipeline::experimental::taa::TemporalAntiAliasBundle,
pbr::ScreenSpaceAmbientOcclusionBundle, prelude::*, utils::default,
core_pipeline::experimental::taa::TemporalAntiAliasing, pbr::ScreenSpaceAmbientOcclusion,
prelude::*, utils::default,
};

use crate::{scene::FAR, settings::Config};
Expand Down Expand Up @@ -31,20 +31,19 @@ pub fn setup(mut commands: Commands, config: Res<Config>) {
dbg!(transform.rotation);
commands
.spawn((
Camera3dBundle {
transform,
camera: Camera {
hdr: true,
..default()
},
projection: Projection::Perspective(PerspectiveProjection {
far: FAR,
..Default::default()
}),
Projection::Perspective(PerspectiveProjection {
far: FAR,
..Default::default()
}),
transform,
Camera {
hdr: true,
..default()
},
Camera3d::default(),
Settings::default(),
))
.insert(ScreenSpaceAmbientOcclusionBundle::default())
.insert(TemporalAntiAliasBundle::default());
.insert(ScreenSpaceAmbientOcclusion::default())
.insert(TemporalAntiAliasing::default())
.insert(Msaa::Off);
}
10 changes: 5 additions & 5 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use bevy::prelude::*;
use bevy::window::{CursorGrabMode, PrimaryWindow, Window};

pub fn grab(window: &mut Window) {
window.cursor.grab_mode = CursorGrabMode::Confined;
window.cursor.visible = false;
window.cursor_options.grab_mode = CursorGrabMode::Confined;
window.cursor_options.visible = false;
}

pub fn release(window: &mut Window) {
window.cursor.grab_mode = CursorGrabMode::None;
window.cursor.visible = true;
window.cursor_options.grab_mode = CursorGrabMode::None;
window.cursor_options.visible = true;
}

pub fn toggle_grab(window: &mut Window) {
match window.cursor.grab_mode {
match window.cursor_options.grab_mode {
CursorGrabMode::None => grab(window),
_ => release(window),
}
Expand Down
13 changes: 5 additions & 8 deletions src/debug/chunk_borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,11 @@ pub fn toggle(
lines: chunk_cube_lines.clone(),
});
commands.spawn((
MaterialMeshBundle {
mesh: meshes.add(mesh),
transform,
material: materials.add(LineMaterial {
color: LinearRgba::WHITE,
}),
..default()
},
Mesh3d(meshes.add(mesh)),
MeshMaterial3d(materials.add(LineMaterial {
color: LinearRgba::WHITE,
})),
transform,
ChunkBorder,
));
}
Expand Down
19 changes: 8 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::prelude::Msaa;
use bevy::prelude::Plugin;

pub mod camera;
Expand Down Expand Up @@ -26,15 +25,13 @@ impl ClientPlugin {
impl Plugin for ClientPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
tracing::info!("Initializing client plugin with config: {:#?}", self.config);
app.insert_resource(self.config.clone())
.insert_resource(Msaa::Off)
.add_plugins((
scene::Plugin,
chunks::ChunksPlugin,
camera::CameraPlugin,
cursor::CursorPlugin,
fake_client::FakeClientPlugin,
debug::UiPlugin,
));
app.insert_resource(self.config.clone()).add_plugins((
scene::Plugin,
chunks::ChunksPlugin,
camera::CameraPlugin,
cursor::CursorPlugin,
fake_client::FakeClientPlugin,
debug::UiPlugin,
));
}
}
4 changes: 2 additions & 2 deletions src/scene/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn setup(
panic!();
};
}
let (atlas_layout, texture_atlas) = block_tatlas_builder.build().unwrap();
let (atlas_layout, atlas_sources, texture_atlas) = block_tatlas_builder.build().unwrap();
tracing::info!(?atlas_layout.size, ?atlas_layout.textures, "Stitched texture atlas");
let texture_atlas = textures.add(texture_atlas);

Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn setup(
.get(texture_file_names.get(&face).unwrap())
.unwrap();
tracing::info!(?face, ?block_definition.id, "Found specific texture");
let tidx = atlas_layout.get_texture_index(texture_handle).unwrap();
let tidx = atlas_sources.texture_index(texture_handle).unwrap();
let tidx = FaceAppearance::Texture {
coords: [
atlas_layout.textures[tidx].min[0] as usize,
Expand Down
9 changes: 4 additions & 5 deletions src/scene/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ pub fn process_ops(
let mut eids = FxHashSet::default();
for (mesh, material) in loads {
let eid = commands
.spawn((PbrBundle {
mesh: meshes.add(mesh),
material,
.spawn((
Mesh3d(meshes.add(mesh)),
MeshMaterial3d(material),
transform,
..default()
},))
))
.id();

eids.insert(eid);
Expand Down
13 changes: 6 additions & 7 deletions src/scene/lights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ pub fn setup(mut commands: Commands) {
brightness: 0.5,
});

commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
commands.spawn((
DirectionalLight {
shadows_enabled: true,
..default()
},
transform: Transform {
Transform {
translation: Vec3::new(0.0, FAR / 8., 0.0),
rotation: Quat::from_rotation_x(-PI / 4.),
..default()
},
cascade_shadow_config: CascadeShadowConfigBuilder {
CascadeShadowConfigBuilder {
num_cascades: 4,
first_cascade_far_bound: CHUNK_SIZE_F32 * 8.,
maximum_distance: FAR,
..default()
}
.into(),
..default()
});
.build(),
));
}

0 comments on commit 472f3a0

Please sign in to comment.