Skip to content

Commit

Permalink
Update to Bevy 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Jul 10, 2024
1 parent 3e46e51 commit ef47c3f
Show file tree
Hide file tree
Showing 10 changed files with 1,142 additions and 620 deletions.
1,660 changes: 1,084 additions & 576 deletions Cargo.lock

Large diffs are not rendered by default.

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

[dependencies]
bevy = "0.12"
bevy = "0.13"
ndshape = "0.3.0"
block-mesh = "0.2.0"
ndcopy = "0.3.0"
thread_local = "1.1.7"
bevy_egui = "0.23"
bevy_egui = "0.27"
float-ord = "0.3.2"
futures-lite = "1.12.0"
once_cell = "1.17.1"
bevy_atmosphere = "0.8"
bevy_atmosphere = "0.9"
bitflags = "2.0.2"
ilattice = { version = "0.3.0", features = ["glam", "morton-encoding"] }
noise = "0.8.2"
Expand Down
4 changes: 2 additions & 2 deletions assets/shaders/terrain_uniforms.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ struct VoxelMat {
reflectance: f32,
};

@group(1) @binding(0)
@group(2) @binding(0)
var<uniform> render_distance: u32;

// A GPU-suited representation of voxel materials.
@group(1) @binding(1)
@group(2) @binding(1)
var<uniform> voxel_materials: array<VoxelMat, 256>;
12 changes: 6 additions & 6 deletions src/debug/debug_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ fn display_debug_stats(mut egui: EguiContexts, diagnostics: Res<DiagnosticsStore
ui.label(format!(
"Avg. FPS: {:.02}",
diagnostics
.get(FrameTimeDiagnosticsPlugin::FPS)
.get(&FrameTimeDiagnosticsPlugin::FPS)
.unwrap()
.average()
.unwrap_or_default()
));
ui.label(format!(
"Total Entity count: {}",
diagnostics
.get(EntityCountDiagnosticsPlugin::ENTITY_COUNT)
.get(&EntityCountDiagnosticsPlugin::ENTITY_COUNT)
.unwrap()
.average()
.unwrap_or_default()
Expand Down Expand Up @@ -85,10 +85,10 @@ fn toggle_debug_ui_displays(
) {
for input in inputs.read() {
match input.key_code {
Some(key_code) if key_code == KeyCode::F3 && input.state == ButtonState::Pressed => {
KeyCode::F3 if input.state == ButtonState::Pressed => {
ui_state.display_debug_info = !ui_state.display_debug_info;
}
Some(key_code) if key_code == KeyCode::F7 && input.state == ButtonState::Pressed => {
KeyCode::F7 if input.state == ButtonState::Pressed => {
ui_state.display_mat_debug = !ui_state.display_mat_debug;
}
_ => {}
Expand Down Expand Up @@ -142,7 +142,7 @@ fn display_material_editor(
&mut editable_color,
egui::color_picker::Alpha::Opaque,
);
selected_mat.base_color = Color::from(editable_color.to_array());
selected_mat.base_color = Color::rgba_from_array(editable_color.to_array());
ui.label("Perceptual Roughness");
ui.add(Slider::new(
&mut selected_mat.perceptual_roughness,
Expand All @@ -165,7 +165,7 @@ fn display_material_editor(
&mut editable_emissive,
egui::color_picker::Alpha::Opaque,
);
selected_mat.emissive = Color::from(editable_emissive.to_array());
selected_mat.emissive = Color::rgba_from_array(editable_emissive.to_array());
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/voxel/render/chunk_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Plugin for ChunkMaterialPlugin {
.add_systems(
Update,
update_chunk_material_singleton
.run_if(resource_changed::<VoxelMaterialRegistry>())
.run_if(resource_changed::<VoxelMaterialRegistry>)
.in_set(ChunkMaterialSet),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/voxel/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ pub fn mesh_buffer<T, S>(
VertexAttributeValues::Uint32(data),
);

render_mesh.set_indices(Some(Indices::U32(indices.clone())));
render_mesh.insert_indices(Indices::U32(indices.clone()));
}
20 changes: 11 additions & 9 deletions src/voxel/world/chunks_anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ fn step_chunk_animation(
time: Res<Time>,
mut commands: Commands,
) {
chunks.for_each_mut(|(entity, mut transform, _chunk, animation)| {
let delta = (time.elapsed_seconds() - animation.start_time).min(ANIMATION_DURATION);
chunks
.iter_mut()
.for_each(|(entity, mut transform, _chunk, animation)| {
let delta = (time.elapsed_seconds() - animation.start_time).min(ANIMATION_DURATION);

let ytransform = (1. - (1. - (delta / ANIMATION_DURATION)).powi(5))
.mul_add(ANIMATION_HEIGHT, _chunk.0.y as f32 - ANIMATION_HEIGHT);
let ytransform = (1. - (1. - (delta / ANIMATION_DURATION)).powi(5))
.mul_add(ANIMATION_HEIGHT, _chunk.0.y as f32 - ANIMATION_HEIGHT);

transform.translation.y = ytransform;
transform.translation.y = ytransform;

if delta == ANIMATION_DURATION {
commands.entity(entity).remove::<ChunkSpawnAnimation>();
}
});
if delta == ANIMATION_DURATION {
commands.entity(entity).remove::<ChunkSpawnAnimation>();
}
});
}

/// Animates the spawning of chunk entities that come into sight.
Expand Down
28 changes: 19 additions & 9 deletions src/voxel/world/meshing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::voxel::{
use bevy::{
pbr::NotShadowCaster,
prelude::*,
render::{primitives::Aabb, render_resource::PrimitiveTopology},
render::{
primitives::Aabb, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology,
},
tasks::{AsyncComputeTaskPool, Task},
};
use futures_lite::future;
Expand All @@ -31,7 +33,10 @@ pub fn prepare_chunks(
entity_commands.insert((
MaterialMeshBundle {
material: (**material).clone(),
mesh: meshes.add(Mesh::new(PrimitiveTopology::TriangleList)),
mesh: meshes.add(Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
)),
transform: Transform::from_translation(chunk_key.0.as_vec3()),
visibility: Visibility::Hidden,
..Default::default()
Expand Down Expand Up @@ -76,7 +81,10 @@ fn queue_mesh_tasks(
})
.borrow_mut();

let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
let mut mesh = Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
);
mesh_buffer(&buffer, &mut mesh_buffers, &mut mesh, 1.0);

mesh
Expand All @@ -94,12 +102,14 @@ fn process_mesh_tasks(
mut chunk_query: Query<(Entity, &Handle<Mesh>, &mut ChunkMeshingTask), With<Chunk>>,
mut commands: Commands,
) {
chunk_query.for_each_mut(|(entity, handle, mut mesh_task)| {
if let Some(mesh) = future::block_on(future::poll_once(&mut mesh_task.0)) {
*meshes.get_mut(handle).unwrap() = mesh;
commands.entity(entity).remove::<ChunkMeshingTask>();
}
});
chunk_query
.iter_mut()
.for_each(|(entity, handle, mut mesh_task)| {
if let Some(mesh) = future::block_on(future::poll_once(&mut mesh_task.0)) {
*meshes.get_mut(handle).unwrap() = mesh;
commands.entity(entity).remove::<ChunkMeshingTask>();
}
});
}

/// The set of systems which asynchronusly mesh the chunks.
Expand Down
12 changes: 6 additions & 6 deletions src/voxel/world/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub fn handle_player_mouse_move(
pub fn handle_player_input(
mut egui: EguiContexts,
mut query: Query<(&mut PlayerController, &mut Transform)>,
keys: Res<Input<KeyCode>>,
btns: Res<Input<MouseButton>>,
keys: Res<ButtonInput<KeyCode>>,
btns: Res<ButtonInput<MouseButton>>,
) {
let (mut controller, mut transform) = query.single_mut();

Expand All @@ -78,19 +78,19 @@ pub fn handle_player_input(

let mut acceleration = 1.0f32;

if keys.pressed(KeyCode::W) {
if keys.pressed(KeyCode::KeyW) {
direction.z -= 1.0;
}

if keys.pressed(KeyCode::S) {
if keys.pressed(KeyCode::KeyS) {
direction.z += 1.0;
}

if keys.pressed(KeyCode::D) {
if keys.pressed(KeyCode::KeyD) {
direction.x += 1.0;
}

if keys.pressed(KeyCode::A) {
if keys.pressed(KeyCode::KeyA) {
direction.x -= 1.0;
}

Expand Down
16 changes: 9 additions & 7 deletions src/voxel/world/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ pub fn process_terrain_gen(
mut dirty_chunks: ResMut<DirtyChunks>,
mut gen_chunks: Query<(Entity, &Chunk, &mut TerrainGenTask)>,
) {
gen_chunks.for_each_mut(|(entity, chunk, mut gen_task)| {
if let Some(data) = future::block_on(future::poll_once(&mut gen_task.0)) {
chunk_data.insert(chunk.0, data);
dirty_chunks.mark_dirty(chunk.0);
commands.entity(entity).remove::<TerrainGenTask>();
}
});
gen_chunks
.iter_mut()
.for_each(|(entity, chunk, mut gen_task)| {
if let Some(data) = future::block_on(future::poll_once(&mut gen_task.0)) {
chunk_data.insert(chunk.0, data);
dirty_chunks.mark_dirty(chunk.0);
commands.entity(entity).remove::<TerrainGenTask>();
}
});
}

/// Handles terrain generation.
Expand Down

0 comments on commit ef47c3f

Please sign in to comment.