mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-11 13:58:30 +00:00
Update to Bevy 0.16.1
This commit is contained in:
parent
cdef1618ce
commit
1152799b4e
@ -9,7 +9,7 @@ build = "build.rs"
|
|||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.15.1", features = ["jpeg", "trace_tracy", "trace_tracy_memory", "serialize"] }
|
bevy = { version = "0.16.1", features = ["jpeg", "trace_tracy", "trace_tracy_memory", "serialize"] }
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
use bevy::math::DVec3;
|
use bevy::math::DVec3;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy::ecs::prelude::ChildOf;
|
||||||
|
|
||||||
use big_space::prelude::*;
|
use big_space::prelude::*;
|
||||||
|
|
||||||
/// Plugin enabling high precision coordinates using `big_space`.
|
/// Plugin enabling high precision coordinates using `big_space`.
|
||||||
@ -31,7 +33,7 @@ fn spawn_root(mut commands: Commands) {
|
|||||||
// 2) cache the root entity for later use
|
// 2) cache the root entity for later use
|
||||||
fn cache_root(
|
fn cache_root(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
roots: Query<Entity, (With<BigSpace>, Without<Parent>)>, // top-level grid
|
roots: Query<Entity, (With<BigSpace>, Without<ChildOf>)>, // top-level grid
|
||||||
) {
|
) {
|
||||||
if let Ok(entity) = roots.get_single() {
|
if let Ok(entity) = roots.get_single() {
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ fn cache_root(
|
|||||||
|
|
||||||
fn fix_invalid_children(
|
fn fix_invalid_children(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
bad: Query<Entity, (With<FloatingOrigin>, Without<GridCell<i64>>, With<Parent>)>,
|
bad: Query<Entity, (With<FloatingOrigin>, Without<GridCell<i64>>, With<ChildOf>)>,
|
||||||
) {
|
) {
|
||||||
for e in &bad {
|
for e in &bad {
|
||||||
commands.entity(e).insert(GridCell::<i64>::ZERO);
|
commands.entity(e).insert(GridCell::<i64>::ZERO);
|
||||||
@ -65,10 +67,10 @@ pub fn teleport_to<P: GridPrecision>(
|
|||||||
e: Entity,
|
e: Entity,
|
||||||
target: DVec3,
|
target: DVec3,
|
||||||
grids: Grids<'_, '_, P>,
|
grids: Grids<'_, '_, P>,
|
||||||
mut q: Query<(&Parent, &mut GridCell<P>, &mut Transform)>,
|
mut q: Query<(&ChildOf, &mut GridCell<P>, &mut Transform)>,
|
||||||
) {
|
) {
|
||||||
let (parent, mut cell, mut tf) = q.get_mut(e).unwrap();
|
let (child_of, mut cell, mut tf) = q.get_mut(e).unwrap();
|
||||||
let grid = grids.parent_grid(parent.get()).unwrap();
|
let grid = grids.parent_grid(child_of.parent()).unwrap();
|
||||||
|
|
||||||
let (new_cell, local) = grid.translation_to_grid(target);
|
let (new_cell, local) = grid.translation_to_grid(target);
|
||||||
|
|
||||||
|
|||||||
@ -64,10 +64,12 @@ fn log_mesh_count(meshes: Res<Assets<Mesh>>, time: Res<Time>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_visualize_octree(octree_query: Query<&SparseVoxelOctree>,) -> bool {
|
fn should_visualize_octree(octree_query: Query<&SparseVoxelOctree>) -> bool {
|
||||||
octree_query.single().show_wireframe
|
let Ok(octree) = octree_query.get_single() else { return false };
|
||||||
|
octree.show_wireframe
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_draw_grid(octree_query: Query<&SparseVoxelOctree>,) -> bool {
|
fn should_draw_grid(octree_query: Query<&SparseVoxelOctree>) -> bool {
|
||||||
octree_query.single().show_world_grid
|
let Ok(octree) = octree_query.get_single() else { return false };
|
||||||
|
octree.show_world_grid
|
||||||
}
|
}
|
||||||
@ -20,8 +20,9 @@ pub fn despawn_distant_chunks(
|
|||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
cfg : Res<ChunkCullingCfg>,
|
cfg : Res<ChunkCullingCfg>,
|
||||||
) {
|
) {
|
||||||
let tree = tree_q.single();
|
let Ok(tree) = tree_q.get_single() else { return };
|
||||||
let cam = cam_q.single().translation();
|
let Ok(cam_tf) = cam_q.get_single() else { return };
|
||||||
|
let cam = cam_tf.translation();
|
||||||
let centre = world_to_chunk(tree, cam);
|
let centre = world_to_chunk(tree, cam);
|
||||||
|
|
||||||
for (ent, chunk, mesh3d, mat3d) in chunk_q.iter() {
|
for (ent, chunk, mesh3d, mat3d) in chunk_q.iter() {
|
||||||
|
|||||||
@ -100,7 +100,7 @@ pub fn draw_grid(
|
|||||||
camera_query: Query<&Transform, With<Camera>>,
|
camera_query: Query<&Transform, With<Camera>>,
|
||||||
octree_query: Query<(&SparseVoxelOctree, &Transform)>,
|
octree_query: Query<(&SparseVoxelOctree, &Transform)>,
|
||||||
) {
|
) {
|
||||||
let camera_tf = camera_query.single();
|
let Ok(camera_tf) = camera_query.get_single() else { return };
|
||||||
let camera_pos = camera_tf.translation;
|
let camera_pos = camera_tf.translation;
|
||||||
|
|
||||||
for (octree, octree_tf) in octree_query.iter() {
|
for (octree, octree_tf) in octree_query.iter() {
|
||||||
|
|||||||
@ -10,10 +10,11 @@ pub fn update_chunk_lods(
|
|||||||
mut tree_q: Query<&mut SparseVoxelOctree>,
|
mut tree_q: Query<&mut SparseVoxelOctree>,
|
||||||
cfg: Res<ChunkCullingCfg>,
|
cfg: Res<ChunkCullingCfg>,
|
||||||
) {
|
) {
|
||||||
let cam_pos = cam_q.single().translation();
|
let Ok(cam_tf) = cam_q.get_single() else { return };
|
||||||
|
let cam_pos = cam_tf.translation();
|
||||||
|
|
||||||
// Borrow the octree only once to avoid repeated query lookups
|
// Borrow the octree only once to avoid repeated query lookups
|
||||||
let mut tree = tree_q.single_mut();
|
let Ok(mut tree) = tree_q.get_single_mut() else { return };
|
||||||
let max_depth = tree.max_depth - 1;
|
let max_depth = tree.max_depth - 1;
|
||||||
let range_step = cfg.view_distance_chunks as f32 / (max_depth as f32 - 1.0);
|
let range_step = cfg.view_distance_chunks as f32 / (max_depth as f32 - 1.0);
|
||||||
let chunk_size = CHUNK_SIZE as f32 * tree.get_spacing_at_depth(max_depth);
|
let chunk_size = CHUNK_SIZE as f32 * tree.get_spacing_at_depth(max_depth);
|
||||||
|
|||||||
@ -14,8 +14,9 @@ pub fn enqueue_visible_chunks(
|
|||||||
cam_q : Query<&GlobalTransform, With<Camera>>,
|
cam_q : Query<&GlobalTransform, With<Camera>>,
|
||||||
tree_q : Query<&SparseVoxelOctree>,
|
tree_q : Query<&SparseVoxelOctree>,
|
||||||
) {
|
) {
|
||||||
let tree = tree_q.single();
|
let Ok(tree) = tree_q.get_single() else { return };
|
||||||
let cam_pos = cam_q.single().translation();
|
let Ok(cam_tf) = cam_q.get_single() else { return };
|
||||||
|
let cam_pos = cam_tf.translation();
|
||||||
let centre = world_to_chunk(tree, cam_pos);
|
let centre = world_to_chunk(tree, cam_pos);
|
||||||
|
|
||||||
if prev_cam.0 == Some(centre) {
|
if prev_cam.0 == Some(centre) {
|
||||||
@ -54,7 +55,7 @@ pub fn process_chunk_queue(
|
|||||||
budget : Res<ChunkBudget>,
|
budget : Res<ChunkBudget>,
|
||||||
mut tree_q : Query<&mut SparseVoxelOctree>,
|
mut tree_q : Query<&mut SparseVoxelOctree>,
|
||||||
) {
|
) {
|
||||||
let mut tree = tree_q.single_mut();
|
let Ok(mut tree) = tree_q.get_single_mut() else { return };
|
||||||
for _ in 0..budget.per_frame {
|
for _ in 0..budget.per_frame {
|
||||||
if let Some(key) = queue.keys.pop_front() {
|
if let Some(key) = queue.keys.pop_front() {
|
||||||
queue.set.remove(&key);
|
queue.set.remove(&key);
|
||||||
|
|||||||
@ -37,9 +37,9 @@ pub fn flight_systems(
|
|||||||
// 1) Rotation & speed input (borrow transform/controller)
|
// 1) Rotation & speed input (borrow transform/controller)
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
let delta_vec3 = {
|
let delta_vec3 = {
|
||||||
let mut window = windows.single_mut();
|
let Ok(mut window) = windows.get_single_mut() else { return };
|
||||||
let mut transform = xforms.single_mut();
|
let Ok(mut transform) = xforms.get_single_mut() else { return };
|
||||||
let mut controller = ctrls.single_mut();
|
let Ok(mut controller) = ctrls.get_single_mut() else { return };
|
||||||
|
|
||||||
//------------------ mouse look --------------------------
|
//------------------ mouse look --------------------------
|
||||||
if !window.cursor_options.visible {
|
if !window.cursor_options.visible {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ pub fn ui_system(
|
|||||||
mut app_exit_events: EventWriter<AppExit>,
|
mut app_exit_events: EventWriter<AppExit>,
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
) {
|
) {
|
||||||
let mut window = windows.single_mut();
|
let Ok(mut window) = windows.get_single_mut() else { return };
|
||||||
|
|
||||||
if keyboard_input.just_pressed(KeyCode::KeyL) {
|
if keyboard_input.just_pressed(KeyCode::KeyL) {
|
||||||
// Toggle between locked and unlocked
|
// Toggle between locked and unlocked
|
||||||
@ -24,6 +24,6 @@ pub fn ui_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if keyboard_input.pressed(KeyCode::Escape) {
|
if keyboard_input.pressed(KeyCode::Escape) {
|
||||||
app_exit_events.send(Default::default());
|
app_exit_events.write(Default::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14,8 +14,8 @@ pub fn voxel_system(
|
|||||||
mut query: Query<(&mut Transform, &mut CameraController)>,
|
mut query: Query<(&mut Transform, &mut CameraController)>,
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
) {
|
) {
|
||||||
let mut window = windows.single_mut();
|
let Ok(mut window) = windows.get_single_mut() else { return };
|
||||||
let (mut transform, _) = query.single_mut();
|
let Ok((mut transform, _)) = query.get_single_mut() else { return };
|
||||||
|
|
||||||
// =======================
|
// =======================
|
||||||
// 5) Octree Keys
|
// 5) Octree Keys
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user