Upgrade to Bevy 0.16.0

main
copygirl 1 week ago
parent b2e17f5d8b
commit 877f72a1e0
  1. 1499
      Cargo.lock
  2. 4
      Cargo.toml
  3. 2
      src/bloxel/chunk.rs
  4. 3
      src/bloxel/generic_math/pos.rs
  5. 3
      src/bloxel/generic_math/region.rs
  6. 2
      src/bloxel/mesh/mod.rs
  7. 22
      src/bloxel/mod.rs
  8. 2
      src/bloxel/storage/chunked_octree.rs
  9. 8
      src/bloxel/worldgen/mod.rs
  10. 4
      src/camera_controller.rs

1499
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -12,9 +12,9 @@ opt-level = 1
opt-level = 3 opt-level = 3
[dependencies] [dependencies]
bevy = { version = "0.15.3", features = [ "file_watcher", "embedded_watcher" ] } bevy = { version = "0.16.0", features = [ "file_watcher", "embedded_watcher" ] }
bitvec = "1.0.1" bitvec = "1.0.1"
noise-functions = "0.8.1" noise-functions = "0.8.1"
overload = "0.1.1" overload = "0.1.1"
rand = "0.9.0" rand = "0.9.1"
zorder = "0.2.2" zorder = "0.2.2"

@ -1,4 +1,4 @@
use bevy::{prelude::*, utils::HashMap}; use bevy::{platform::collections::HashMap, prelude::*};
use super::{ use super::{
math::{ChunkPos, CHUNK_LENGTH}, math::{ChunkPos, CHUNK_LENGTH},

@ -4,7 +4,7 @@ use std::{
}; };
use bevy::{ use bevy::{
ecs::component::Component, ecs::component::{Component, Immutable},
math::{Dir3, IVec3, InvalidDirectionError}, math::{Dir3, IVec3, InvalidDirectionError},
}; };
@ -75,6 +75,7 @@ impl<T> std::fmt::Debug for Pos<T> {
use bevy::ecs::component::StorageType; use bevy::ecs::component::StorageType;
impl<T: Send + Sync + 'static> Component for Pos<T> { impl<T: Send + Sync + 'static> Component for Pos<T> {
const STORAGE_TYPE: StorageType = StorageType::Table; const STORAGE_TYPE: StorageType = StorageType::Table;
type Mutability = Immutable;
} }
impl<T> Default for Pos<T> { impl<T> Default for Pos<T> {

@ -4,7 +4,7 @@ use std::{
}; };
use bevy::{ use bevy::{
ecs::component::Component, ecs::component::{Component, Immutable},
math::{IVec3, UVec3}, math::{IVec3, UVec3},
}; };
@ -98,6 +98,7 @@ impl<T> std::fmt::Debug for Region<T> {
use bevy::ecs::component::StorageType; use bevy::ecs::component::StorageType;
impl<T: Send + Sync + 'static> Component for Region<T> { impl<T: Send + Sync + 'static> Component for Region<T> {
const STORAGE_TYPE: StorageType = StorageType::Table; const STORAGE_TYPE: StorageType = StorageType::Table;
type Mutability = Immutable;
} }
impl<T> Default for Region<T> { impl<T> Default for Region<T> {

@ -23,9 +23,11 @@ pub fn generate_chunk_mesh(
) { ) {
// This system will run before `TerrainMaterial` is available, so to avoid // This system will run before `TerrainMaterial` is available, so to avoid
// the system failing, we'll make the material and atlas an `Option`. // the system failing, we'll make the material and atlas an `Option`.
// TODO: Should be able to be replaced with `When<>` once available in Bevy.
let Some(terrain_material) = terrain_material else { let Some(terrain_material) = terrain_material else {
return; return;
}; };
// Atlas and layout should exist at this point, if material does. // Atlas and layout should exist at this point, if material does.
let terrain_atlas = terrain_atlas.unwrap(); let terrain_atlas = terrain_atlas.unwrap();
let terrain_atlas_layout = atlas_layouts.get(&terrain_atlas.layout).unwrap(); let terrain_atlas_layout = atlas_layouts.get(&terrain_atlas.layout).unwrap();

@ -47,31 +47,31 @@ fn set_transform_on_chunkpos_changed(
} }
fn add_chunks_to_chunkmap( fn add_chunks_to_chunkmap(
trigger: Trigger<OnAdd, (Parent, ChunkPos)>, trigger: Trigger<OnAdd, (ChildOf, ChunkPos)>,
chunk_query: Query<(&Parent, &ChunkPos)>, chunk_query: Query<(&ChildOf, &ChunkPos)>,
mut map_query: Query<&mut ChunkMap>, mut map_query: Query<&mut ChunkMap>,
) { ) {
let chunk = trigger.entity(); let chunk = trigger.target();
let Ok((parent, pos)) = chunk_query.get(chunk) else { let Ok((child_of, pos)) = chunk_query.get(chunk) else {
// Trigger with a bundle doesn't work as expected. It triggers // Trigger with a bundle doesn't work as expected. It triggers
// when ANY component is added, rather than when ALL are present. // when ANY component is added, rather than when ALL are present.
return; return;
}; };
let mut map = map_query.get_mut(parent.get()).unwrap(); let mut map = map_query.get_mut(child_of.parent()).unwrap();
map.try_insert(*pos, chunk).expect("chunk already present"); map.try_insert(*pos, chunk).expect("chunk already present");
} }
fn remove_chunks_from_chunkmap( fn remove_chunks_from_chunkmap(
trigger: Trigger<OnRemove, (Parent, ChunkPos)>, trigger: Trigger<OnRemove, (ChildOf, ChunkPos)>,
chunk_query: Query<(&Parent, &ChunkPos)>, chunk_query: Query<(&ChildOf, &ChunkPos)>,
mut map_query: Query<&mut ChunkMap>, mut map_query: Query<&mut ChunkMap>,
) { ) {
let chunk = trigger.entity(); let chunk = trigger.target();
let Ok((parent, pos)) = chunk_query.get(chunk) else { let Ok((child_of, pos)) = chunk_query.get(chunk) else {
// See above. // See above.
return; return;
}; };
let mut map = map_query.get_mut(parent.get()).unwrap(); let mut map = map_query.get_mut(child_of.parent()).unwrap();
map.remove(pos).expect("chunk not found"); map.remove(pos).expect("chunk not found");
println!("Chunk {chunk} @ {pos:?} removed from {}", parent.get()); println!("Chunk {chunk} @ {pos:?} removed from {}", child_of.parent());
} }

@ -2,7 +2,7 @@ use std::{array::from_fn, collections::BinaryHeap};
use bevy::{ use bevy::{
math::IVec3, math::IVec3,
utils::{HashMap, HashSet}, platform::collections::{HashMap, HashSet},
}; };
use crate::bloxel::math::{zorder, ChunkPos, ChunkRegion, ZOrderIndex}; use crate::bloxel::math::{zorder, ChunkPos, ChunkRegion, ZOrderIndex};

@ -34,9 +34,9 @@ fn create_chunks_around_camera(
let block_pos = camera.translation.as_ivec3().into(); let block_pos = camera.translation.as_ivec3().into();
let (chunk_pos, _) = ChunkPos::from_block_pos(block_pos); let (chunk_pos, _) = ChunkPos::from_block_pos(block_pos);
let mut create_chunk = |octree: &mut ExistingChunks, chunk_pos: ChunkPos| { let mut create_chunk = |octree: &mut ExistingChunks, pos: ChunkPos| {
commands.entity(*chunk_map).with_child((Chunk, chunk_pos)); commands.entity(*chunk_map).with_child((Chunk, pos));
octree.update(chunk_pos, |_, children, parent| { octree.update(pos, |_, children, parent| {
let children = children.map(|a| a.as_slice()).unwrap_or_default(); let children = children.map(|a| a.as_slice()).unwrap_or_default();
*parent = if children.iter().all(|c| *c == Existing::All) { *parent = if children.iter().all(|c| *c == Existing::All) {
Existing::All Existing::All
@ -90,7 +90,7 @@ fn destroy_chunks_away_from_camera(
for chunk_pos in to_destroy { for chunk_pos in to_destroy {
let chunk = *chunk_map.get(&chunk_pos).unwrap(); let chunk = *chunk_map.get(&chunk_pos).unwrap();
commands.entity(chunk).despawn_recursive(); commands.entity(chunk).despawn();
octree.update(chunk_pos, |_, children, parent| { octree.update(chunk_pos, |_, children, parent| {
let children = children.map(|a| a.as_slice()).unwrap_or_default(); let children = children.map(|a| a.as_slice()).unwrap_or_default();
*parent = if children.iter().all(|c| *c == Existing::None) { *parent = if children.iter().all(|c| *c == Existing::None) {

@ -52,7 +52,7 @@ fn camera_mouse_rotation(
} }
// We also need to have exactly one camera with the `ControlledCamera` component. // We also need to have exactly one camera with the `ControlledCamera` component.
let Ok(mut transform) = camera.get_single_mut() else { let Ok(mut transform) = camera.single_mut() else {
return; return;
}; };
@ -78,7 +78,7 @@ fn camera_keyboard_translation(
} }
// We also need to have exactly one camera with the `ControlledCamera` component. // We also need to have exactly one camera with the `ControlledCamera` component.
let Ok(mut transform) = camera.get_single_mut() else { let Ok(mut transform) = camera.single_mut() else {
return; return;
}; };

Loading…
Cancel
Save