Skip to content

Commit

Permalink
Bevy 0.15 (#34)
Browse files Browse the repository at this point in the history
Migrate to the Bevy 0.15 RC.

- Migrate examples
- Add `with_child` to `ReferenceFrameCommands` and
`SpatialEntityCommands` to match Bevy's `EntityCommands::with_child`
- Add `Typed` bound to `GridPrecision` (required for `register_type`)

---------

Co-authored-by: Aevyrie <aevyrie@gmail.com>
  • Loading branch information
Jondolf and aevyrie authored Dec 5, 2024
1 parent d9f531e commit 9e77874
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 403 deletions.
31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ repository = "https://github.com/aevyrie/big_space"
documentation = "https://docs.rs/crate/big_space/latest"

[dependencies]
bevy_app = { version = "0.14.0", default-features = false }
bevy_ecs = { version = "0.14.0", default-features = false }
bevy_hierarchy = { version = "0.14.0", default-features = false }
bevy_log = { version = "0.14.0", default-features = false }
bevy_math = { version = "0.14.0", default-features = false }
bevy_reflect = { version = "0.14.0", default-features = false }
bevy_transform = { version = "0.14.0", default-features = false }
bevy_utils = { version = "0.14.0", default-features = false }
bevy_app = { version = "0.15.0", default-features = false }
bevy_ecs = { version = "0.15.0", default-features = false }
bevy_hierarchy = { version = "0.15.0", default-features = false }
bevy_log = { version = "0.15.0", default-features = false }
bevy_math = { version = "0.15.0", default-features = false }
bevy_reflect = { version = "0.15.0", default-features = false }
bevy_transform = { version = "0.15.0", default-features = false }
bevy_utils = { version = "0.15.0", default-features = false }
# Optional
bevy_color = { version = "0.14.0", default-features = false, optional = true }
bevy_gizmos = { version = "0.14.0", default-features = false, optional = true }
bevy_render = { version = "0.14.0", default-features = false, optional = true }
bevy_input = { version = "0.14.0", default-features = false, optional = true }
bevy_time = { version = "0.14.0", default-features = false, optional = true }
bevy_color = { version = "0.15.0", default-features = false, optional = true }
bevy_gizmos = { version = "0.15.0", default-features = false, optional = true }
bevy_render = { version = "0.15.0", default-features = false, optional = true }
bevy_input = { version = "0.15.0", default-features = false, optional = true }
bevy_time = { version = "0.15.0", default-features = false, optional = true }

[dev-dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_scene",
"bevy_gltf",
"bevy_winit",
"default_font",
"bevy_ui",
"bevy_pbr",
"bevy_gizmos",
"animation",
"bevy_window",
"x11",
"tonemapping_luts",
"multi_threaded",
] }
# bevy-inspector-egui = "0.24"
rand = "0.8.5"

[features]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ From the docs: https://docs.rs/big_space/latest/big_space/precision/trait.GridPr

| bevy | big_space |
| ---- | --------- |
| 0.15 | 0.8 |
| 0.14 | 0.7 |
| 0.13 | 0.5, 0.6 |
| 0.12 | 0.4 |
Expand Down
54 changes: 18 additions & 36 deletions examples/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fn movement(
)>,
) {
let delta_translation = |offset: f32, scale: f32| -> Vec3 {
let t_1 = time.elapsed_seconds() * 0.1 + offset;
let dt = time.delta_seconds() * 0.1;
let t_1 = time.elapsed_secs() * 0.1 + offset;
let dt = time.delta_secs() * 0.1;
let t_0 = t_1 - dt;
let pos =
|t: f32| -> Vec3 { Vec3::new(t.cos() * 2.0, t.sin() * 2.0, (t * 1.3).sin() * 2.0) };
Expand All @@ -51,7 +51,7 @@ struct Rotator;

fn rotation(time: Res<Time>, mut query: Query<&mut Transform, With<Rotator>>) {
for mut transform in &mut query {
transform.rotate_z(3.0 * time.delta_seconds() * 0.2);
transform.rotate_z(3.0 * time.delta_secs() * 0.2);
}
}

Expand All @@ -68,60 +68,42 @@ fn setup(

commands.spawn_big_space(ReferenceFrame::<i64>::new(1.0, 0.01), |root| {
root.spawn_spatial((
PbrBundle {
mesh: mesh_handle.clone(),
material: matl_handle.clone(),
transform: Transform::from_xyz(0.0, 0.0, 1.0),
..default()
},
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(matl_handle.clone()),
Transform::from_xyz(0.0, 0.0, 1.0),
Mover::<1>,
));

root.spawn_spatial((
PbrBundle {
mesh: mesh_handle.clone(),
material: matl_handle.clone(),
transform: Transform::from_xyz(1.0, 0.0, 0.0),
..default()
},
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(matl_handle.clone()),
Transform::from_xyz(1.0, 0.0, 0.0),
Mover::<2>,
));

root.with_frame(ReferenceFrame::new(0.2, 0.01), |new_frame| {
new_frame.insert((
PbrBundle {
mesh: mesh_handle.clone(),
material: matl_handle.clone(),
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
},
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(matl_handle.clone()),
Transform::from_xyz(0.0, 1.0, 0.0),
Rotator,
Mover::<3>,
));
new_frame.spawn_spatial((
PbrBundle {
mesh: mesh_handle,
material: matl_handle,
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
Mesh3d(mesh_handle),
MeshMaterial3d(matl_handle),
Transform::from_xyz(0.0, 0.5, 0.0),
Mover::<4>,
));
});

// light
root.spawn_spatial((PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
},));
root.spawn_spatial((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0)));

// camera
root.spawn_spatial((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 8.0)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
FloatingOrigin,
));
});
Expand Down
88 changes: 38 additions & 50 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ fn setup(
) {
commands.spawn_big_space(ReferenceFrame::<i128>::default(), |root| {
root.spawn_spatial((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 8.0)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
projection: Projection::Perspective(PerspectiveProjection {
near: 1e-18,
..default()
}),
Camera3d::default(),
Projection::Perspective(PerspectiveProjection {
near: 1e-18,
..default()
},
}),
Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
FloatingOrigin, // Important: marks the floating origin entity for rendering.
CameraController::default() // Built-in camera controller
.with_speed_bounds([10e-18, 10e35])
Expand All @@ -68,20 +65,16 @@ fn setup(
translation.x += j / 2.0 + k;
translation.y = j / 2.0;

root.spawn_spatial(PbrBundle {
mesh: mesh_handle.clone(),
material: matl_handle.clone(),
transform: Transform::from_scale(Vec3::splat(j)).with_translation(translation),
..default()
});
root.spawn_spatial((
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(matl_handle.clone()),
Transform::from_scale(Vec3::splat(j)).with_translation(translation),
));
}

// light
root.spawn_spatial(DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 10_000.0,
..default()
},
root.spawn_spatial(DirectionalLight {
illuminance: 10_000.0,
..default()
});
});
Expand All @@ -95,41 +88,37 @@ pub struct FunFactText;

fn ui_setup(mut commands: Commands) {
commands.spawn((
TextBundle::from_section(
"",
TextStyle {
font_size: 18.0,
color: Color::WHITE,
..default()
},
)
.with_text_justify(JustifyText::Left)
.with_style(Style {
Text::default(),
TextFont {
font_size: 18.0,
..default()
},
TextColor(Color::WHITE),
TextLayout::new_with_justify(JustifyText::Left),
Node {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
},
BigSpaceDebugText,
));

commands.spawn((
TextBundle::from_section(
"",
TextStyle {
font_size: 52.0,
color: Color::WHITE,
..default()
},
)
.with_style(Style {
Text::default(),
TextFont {
font_size: 52.0,
..default()
},
TextColor(Color::WHITE),
TextLayout::new_with_justify(JustifyText::Center),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
right: Val::Px(10.0),
left: Val::Px(10.0),
..default()
})
.with_text_justify(JustifyText::Center),
},
FunFactText,
));
}
Expand All @@ -150,7 +139,6 @@ fn highlight_nearest_sphere(
gizmos
.sphere(
translation,
Quat::IDENTITY, // Bevy likes to explode on non-normalized quats in gizmos,
scale.x * 0.505,
Color::Srgba(palettes::basic::RED),
)
Expand All @@ -168,7 +156,7 @@ fn ui_text_system(
time: Res<Time>,
origin: Query<(Entity, GridTransformReadOnly<i128>), With<FloatingOrigin>>,
camera: Query<&CameraController>,
objects: Query<&Transform, With<Handle<Mesh>>>,
objects: Query<&Transform, With<Mesh3d>>,
) {
let (origin_entity, origin_pos) = origin.single();
let translation = origin_pos.transform.translation;
Expand Down Expand Up @@ -198,7 +186,7 @@ fn ui_text_system(
);

let velocity = camera.single().velocity();
let speed = velocity.0.length() / time.delta_seconds_f64();
let speed = velocity.0.length() / time.delta_secs_f64();
let camera_text = if speed > 3.0e8 {
format!("Speed: {:.0e} * speed of light", speed / 3.0e8)
} else {
Expand All @@ -222,11 +210,11 @@ fn ui_text_system(

let mut debug_text = debug_text.single_mut();

debug_text.0.sections[0].value = format!(
debug_text.0.0 = format!(
"{grid_text}\n{translation_text}\n\n{real_position_f64_text}\n{real_position_f32_text}\n\n{camera_text}\n{nearest_text}"
);

fun_text.single_mut().sections[0].value = fact_text
fun_text.single_mut().0 = fact_text
}

fn closest<'a>(diameter: f32) -> (f32, &'a str) {
Expand Down Expand Up @@ -282,15 +270,15 @@ fn cursor_grab_system(
};

if btn.just_pressed(MouseButton::Left) {
window.cursor.grab_mode = CursorGrabMode::Locked;
window.cursor.visible = false;
window.cursor_options.grab_mode = CursorGrabMode::Locked;
window.cursor_options.visible = false;
// window.mode = WindowMode::BorderlessFullscreen;
cam.defaults_disabled = false;
}

if key.just_pressed(KeyCode::Escape) {
window.cursor.grab_mode = CursorGrabMode::None;
window.cursor.visible = true;
window.cursor_options.grab_mode = CursorGrabMode::None;
window.cursor_options.visible = true;
// window.mode = WindowMode::Windowed;
cam.defaults_disabled = true;
}
Expand Down
Loading

0 comments on commit 9e77874

Please sign in to comment.