From 27801da98c0232a6b1321fd7d11c0249a5ffec51 Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Sun, 30 Jun 2024 01:31:16 -0700 Subject: [PATCH] Dependency Reduction (#23) --- Cargo.toml | 23 +++++++++++++++------- examples/demo.rs | 1 - src/bundles.rs | 30 +++++++++++++++-------------- src/camera.rs | 20 ++++++++++--------- src/commands.rs | 19 +++++++++--------- src/debug.rs | 9 +++++++-- src/floating_origins.rs | 17 ++++++++++------ src/grid_cell.rs | 3 ++- src/lib.rs | 16 ++++++++------- src/plugin.rs | 13 ++++++++----- src/precision.rs | 2 +- src/reference_frame/local_origin.rs | 30 +++++++++++++---------------- src/reference_frame/mod.rs | 10 ++++------ src/reference_frame/propagation.rs | 5 ++++- src/validation.rs | 7 +++++-- src/world_query.rs | 6 +++--- 16 files changed, 119 insertions(+), 92 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc5732c..dfeafe0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,20 @@ keywords = ["bevy", "floating-origin", "large-scale", "space"] repository = "https://github.com/aevyrie/big_space" documentation = "https://docs.rs/crate/big_space/latest" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -bevy = { version = "0.13", default_features = false } +bevy_app = { version = "0.13", default_features = false } +bevy_ecs = { version = "0.13", default_features = false } +bevy_hierarchy = { version = "0.13", default_features = false } +bevy_log = { version = "0.13", default_features = false } +bevy_math = { version = "0.13", default_features = false } +bevy_reflect = { version = "0.13", default_features = false } +bevy_transform = { version = "0.13", default_features = false } +bevy_utils = { version = "0.13", default_features = false } +# Optional +bevy_gizmos = { version = "0.13", default_features = false, optional = true } +bevy_render = { version = "0.13", default_features = false, optional = true } +bevy_input = { version = "0.13", default_features = false, optional = true } +bevy_time = { version = "0.13", default_features = false, optional = true } [dev-dependencies] bevy = { version = "0.13", default-features = false, features = [ @@ -21,19 +31,18 @@ bevy = { version = "0.13", default-features = false, features = [ "default_font", "bevy_ui", "bevy_pbr", + "bevy_gizmos", "x11", "tonemapping_luts", "multi-threaded", ] } bevy-inspector-egui = "0.24" -bevy_framepace = { version = "0.15", default-features = false } rand = "0.8.5" [features] default = ["debug", "camera", "bevy_render"] -debug = ["bevy/bevy_gizmos"] -bevy_render = ["bevy/bevy_render"] -camera = ["bevy_render"] +debug = ["bevy_gizmos", "bevy_render"] +camera = ["bevy_render", "bevy_time", "bevy_input"] [[example]] name = "demo" diff --git a/examples/demo.rs b/examples/demo.rs index 37a4812..9c4b620 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -18,7 +18,6 @@ fn main() { big_space::BigSpacePlugin::::default(), big_space::debug::FloatingOriginDebugPlugin::::default(), big_space::camera::CameraControllerPlugin::::default(), - bevy_framepace::FramepacePlugin, )) .insert_resource(ClearColor(Color::BLACK)) .add_systems(Startup, (setup, ui_setup)) diff --git a/src/bundles.rs b/src/bundles.rs index 59e5b8f..c979fcb 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -1,22 +1,24 @@ //! Component bundles for big_space. use crate::{precision::GridPrecision, reference_frame::ReferenceFrame, BigSpace, GridCell}; -use bevy::prelude::*; + +use bevy_ecs::prelude::*; +use bevy_transform::prelude::*; /// Minimal bundle needed to position an entity in floating origin space. /// -/// This is the floating origin equivalent of the [`bevy::prelude::SpatialBundle`]. +/// This is the floating origin equivalent of the `bevy` `SpatialBundle`. #[derive(Bundle, Default)] pub struct BigSpatialBundle { /// The visibility of the entity. #[cfg(feature = "bevy_render")] - pub visibility: Visibility, + pub visibility: bevy_render::view::Visibility, /// The inherited visibility of the entity. #[cfg(feature = "bevy_render")] - pub inherited: InheritedVisibility, + pub inherited: bevy_render::view::InheritedVisibility, /// The view visibility of the entity. #[cfg(feature = "bevy_render")] - pub view: ViewVisibility, + pub view: bevy_render::view::ViewVisibility, /// The transform of the entity. pub transform: Transform, /// The global transform of the entity. @@ -25,21 +27,21 @@ pub struct BigSpatialBundle { pub cell: GridCell

, } -/// A [`SpatialBundle`] that also has a reference frame, allowing other high precision spatial -/// bundles to be nested within that reference frame. +/// A `SpatialBundle` that also has a reference frame, allowing other high precision spatial bundles +/// to be nested within that reference frame. /// -/// This is the floating origin equivalent of the [`SpatialBundle`]. +/// This is the floating origin equivalent of the `bevy` `SpatialBundle`. #[derive(Bundle, Default)] pub struct BigReferenceFrameBundle { /// The visibility of the entity. #[cfg(feature = "bevy_render")] - pub visibility: Visibility, + pub visibility: bevy_render::view::Visibility, /// The inherited visibility of the entity. #[cfg(feature = "bevy_render")] - pub inherited: InheritedVisibility, + pub inherited: bevy_render::view::InheritedVisibility, /// The view visibility of the entity. #[cfg(feature = "bevy_render")] - pub view: ViewVisibility, + pub view: bevy_render::view::ViewVisibility, /// The transform of the entity. pub transform: Transform, /// The global transform of the entity for rendering, computed relative to the floating origin. @@ -55,13 +57,13 @@ pub struct BigReferenceFrameBundle { pub struct BigSpaceRootBundle { /// The visibility of the entity. #[cfg(feature = "bevy_render")] - pub visibility: Visibility, + pub visibility: bevy_render::view::Visibility, /// The inherited visibility of the entity. #[cfg(feature = "bevy_render")] - pub inherited: InheritedVisibility, + pub inherited: bevy_render::view::InheritedVisibility, /// The view visibility of the entity. #[cfg(feature = "bevy_render")] - pub view: ViewVisibility, + pub view: bevy_render::view::ViewVisibility, /// The root reference frame pub reference_frame: ReferenceFrame

, /// Tracks the current floating origin diff --git a/src/camera.rs b/src/camera.rs index 10729be..78051e3 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -2,14 +2,16 @@ use std::marker::PhantomData; -use bevy::{ - input::mouse::MouseMotion, - math::{DQuat, DVec3}, - prelude::*, - render::{primitives::Aabb, view::RenderLayers}, - transform::TransformSystem, - utils::hashbrown::HashSet, -}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; +use bevy_hierarchy::prelude::*; +use bevy_input::{mouse::MouseMotion, prelude::*}; +use bevy_math::{prelude::*, DQuat, DVec3}; +use bevy_reflect::prelude::*; +use bevy_render::{primitives::Aabb, view::RenderLayers}; +use bevy_time::prelude::*; +use bevy_transform::{prelude::*, TransformSystem}; +use bevy_utils::HashSet; use crate::{ precision::GridPrecision, reference_frame::local_origin::ReferenceFrames, @@ -130,7 +132,7 @@ impl CameraInput { pub fn reset(&mut self) { *self = CameraInput { defaults_disabled: self.defaults_disabled, - ..default() + ..Default::default() }; } diff --git a/src/commands.rs b/src/commands.rs index 4bfee40..82903e1 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,7 +3,6 @@ use std::marker::PhantomData; use crate::{reference_frame::ReferenceFrame, *}; -use bevy::prelude::*; use self::precision::GridPrecision; @@ -25,11 +24,11 @@ impl BigSpaceCommands

for Commands<'_, '_> { ) { let mut entity_commands = self.spawn(( #[cfg(feature = "bevy_render")] - Visibility::default(), + bevy_render::view::Visibility::default(), #[cfg(feature = "bevy_render")] - InheritedVisibility::default(), + bevy_render::view::InheritedVisibility::default(), #[cfg(feature = "bevy_render")] - ViewVisibility::default(), + bevy_render::view::ViewVisibility::default(), BigSpace::default(), )); let mut cmd = ReferenceFrameCommands { @@ -70,11 +69,11 @@ impl<'a, P: GridPrecision> ReferenceFrameCommands<'a, P> { let entity = commands .spawn(( #[cfg(feature = "bevy_render")] - Visibility::default(), + bevy_render::view::Visibility::default(), #[cfg(feature = "bevy_render")] - InheritedVisibility::default(), + bevy_render::view::InheritedVisibility::default(), #[cfg(feature = "bevy_render")] - ViewVisibility::default(), + bevy_render::view::ViewVisibility::default(), Transform::default(), GlobalTransform::default(), GridCell::

::default(), @@ -136,11 +135,11 @@ impl<'a, P: GridPrecision> ReferenceFrameCommands<'a, P> { let entity = commands .spawn(( #[cfg(feature = "bevy_render")] - Visibility::default(), + bevy_render::view::Visibility::default(), #[cfg(feature = "bevy_render")] - InheritedVisibility::default(), + bevy_render::view::InheritedVisibility::default(), #[cfg(feature = "bevy_render")] - ViewVisibility::default(), + bevy_render::view::ViewVisibility::default(), Transform::default(), GlobalTransform::default(), GridCell::

::default(), diff --git a/src/debug.rs b/src/debug.rs index aae6610..852c8d2 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -2,7 +2,12 @@ use std::marker::PhantomData; -use bevy::prelude::*; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; +use bevy_gizmos::prelude::*; +use bevy_math::prelude::*; +use bevy_render::prelude::*; +use bevy_transform::prelude::*; use crate::{ precision::GridPrecision, @@ -19,7 +24,7 @@ impl Plugin for FloatingOriginDebugPlugin

{ PostUpdate, (update_debug_bounds::

, update_reference_frame_axes::

) .chain() - .after(bevy::transform::TransformSystem::TransformPropagate), + .after(bevy_transform::TransformSystem::TransformPropagate), ); } } diff --git a/src/floating_origins.rs b/src/floating_origins.rs index 8cc3deb..b4ef066 100644 --- a/src/floating_origins.rs +++ b/src/floating_origins.rs @@ -1,12 +1,16 @@ //! A floating origin for camera-relative rendering, to maximize precision when converting to f32. -use bevy::{log::error, prelude::*, reflect::Reflect, utils::hashbrown::HashMap}; +use bevy_ecs::prelude::*; +use bevy_hierarchy::prelude::*; +use bevy_log::prelude::*; +use bevy_reflect::prelude::*; +use bevy_utils::HashMap; /// Marks the entity to use as the floating origin. /// -/// The [`GlobalTransform`] of all entities within this [`BigSpace`] will be computed relative to -/// this floating origin. There should always be exactly one entity marked with this component -/// within a [`BigSpace`]. +/// The [`GlobalTransform`](bevy_transform::components::GlobalTransform) of all entities within this +/// [`BigSpace`] will be computed relative to this floating origin. There should always be exactly +/// one entity marked with this component within a [`BigSpace`]. #[derive(Component, Reflect)] pub struct FloatingOrigin; @@ -19,8 +23,9 @@ pub struct FloatingOrigin; /// `ReferenceFrame`s, but only one `BigSpace`, at the root. /// /// Your world can have multiple [`BigSpace`]s, and they will remain completely independent. Each -/// big space uses the floating origin contained within it to compute the [`GlobalTransform`] of all -/// spatial entities within that `BigSpace`. +/// big space uses the floating origin contained within it to compute the +/// [`GlobalTransform`](bevy_transform::components::GlobalTransform) of all spatial entities within +/// that `BigSpace`. #[derive(Debug, Default, Component, Reflect)] pub struct BigSpace { /// Set the entity to use as the floating origin within this high precision hierarchy. diff --git a/src/grid_cell.rs b/src/grid_cell.rs index a4ddd5e..1adb5cb 100644 --- a/src/grid_cell.rs +++ b/src/grid_cell.rs @@ -1,6 +1,7 @@ //! Contains the grid cell implementation -use bevy::prelude::*; +use bevy_ecs::prelude::*; +use bevy_reflect::prelude::*; use crate::*; diff --git a/src/lib.rs b/src/lib.rs index cfd3f6d..72f4ba5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ -//! This [`bevy`] plugin makes it possible to build high-precision worlds that exceed the size of -//! the observable universe, with no added dependencies, while remaining largely compatible with the +//! This `bevy` plugin makes it possible to build high-precision worlds that exceed the size of the +//! observable universe, with no added dependencies, while remaining largely compatible with the //! rest of the Bevy ecosystem. //! //! The next section explains the problem this solves in more detail, how this plugin works, and a @@ -55,9 +55,9 @@ //! multiplayer - the server needs a source of truth for position that doesn't drift over time. //! - Virtually limitless volume and scale; you can work at the scale of subatomic particles, across //! the width of the observable universe. Double precision is downright suffocating in comparison. -//! - Uniform precision across the play area. Unlike double precision, the available precision -//! does not decrease as you move to the edge of the play area, it is instead relative to the -//! distance from the origin of the current grid cell. +//! - Uniform precision across the play area. Unlike double precision, the available precision does +//! not decrease as you move to the edge of the play area, it is instead relative to the distance +//! from the origin of the current grid cell. //! - High precision coordinates are invisible if you don't need them. You can move objects using //! their `Transform` alone, which results in decent ecosystem compatibility. //! - High precision is completely opt-in. If you don't add the `GridCell` component to an entity, @@ -179,6 +179,10 @@ #![allow(clippy::type_complexity)] #![warn(missing_docs)] +use bevy_ecs::prelude::*; +use bevy_hierarchy::prelude::*; +use bevy_transform::prelude::*; + pub mod bundles; pub mod commands; pub mod floating_origins; @@ -196,8 +200,6 @@ pub mod debug; #[cfg(test)] mod tests; -use bevy::prelude::*; - pub use bundles::{BigReferenceFrameBundle, BigSpaceRootBundle, BigSpatialBundle}; pub use commands::{BigSpaceCommands, ReferenceFrameCommands, SpatialEntityCommands}; pub use floating_origins::{BigSpace, FloatingOrigin}; diff --git a/src/plugin.rs b/src/plugin.rs index b1fd128..832e7fe 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,6 +1,9 @@ //! The bevy plugin for big_space. -use bevy::{prelude::*, transform::TransformSystem}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; +use bevy_reflect::prelude::*; +use bevy_transform::{prelude::*, TransformSystem}; use std::marker::PhantomData; use crate::{ @@ -100,16 +103,16 @@ impl Plugin for BigSpacePlu .add_systems( PostStartup, ( - bevy::transform::systems::sync_simple_transforms, - bevy::transform::systems::propagate_transforms, + bevy_transform::systems::sync_simple_transforms, + bevy_transform::systems::propagate_transforms, ) .in_set(TransformSystem::TransformPropagate), ) .add_systems( PostUpdate, ( - bevy::transform::systems::sync_simple_transforms, - bevy::transform::systems::propagate_transforms, + bevy_transform::systems::sync_simple_transforms, + bevy_transform::systems::propagate_transforms, ) .in_set(TransformSystem::TransformPropagate), ); diff --git a/src/precision.rs b/src/precision.rs index 0dcda5f..5007fcc 100644 --- a/src/precision.rs +++ b/src/precision.rs @@ -2,7 +2,7 @@ use std::{hash::Hash, ops::Add}; -use bevy::reflect::Reflect; +use bevy_reflect::Reflect; /// Used to make the floating origin plugin generic over many grid sizes. /// diff --git a/src/reference_frame/local_origin.rs b/src/reference_frame/local_origin.rs index 14f00bb..01f38aa 100644 --- a/src/reference_frame/local_origin.rs +++ b/src/reference_frame/local_origin.rs @@ -2,19 +2,17 @@ //! frames, and used to compute the floating origin's position relative to each reference frame. See //! [`LocalFloatingOrigin`]. -use bevy::{ - ecs::{ - prelude::*, - system::{ - lifetimeless::{Read, Write}, - SystemParam, - }, +use bevy_ecs::{ + prelude::*, + system::{ + lifetimeless::{Read, Write}, + SystemParam, }, - hierarchy::prelude::*, - log::prelude::*, - math::{prelude::*, DAffine3, DQuat}, - transform::prelude::*, }; +use bevy_hierarchy::prelude::*; +use bevy_log::prelude::*; +use bevy_math::{prelude::*, DAffine3, DQuat}; +use bevy_transform::prelude::*; pub use inner::LocalFloatingOrigin; @@ -24,17 +22,15 @@ use super::ReferenceFrame; /// A module kept private to enforce use of setters and getters within the parent module. mod inner { - use bevy::{ - math::{prelude::*, DAffine3, DMat3, DQuat}, - reflect::prelude::*, - }; + use bevy_math::{prelude::*, DAffine3, DMat3, DQuat}; + use bevy_reflect::prelude::*; use crate::{precision::GridPrecision, GridCell}; /// An isometry that describes the location of the floating origin's grid cell's origin, in the /// local reference frame. /// - /// Used to compute the [`GlobalTransform`](bevy::transform::components::GlobalTransform) of + /// Used to compute the [`GlobalTransform`](bevy_transform::components::GlobalTransform) of /// every entity within a reference frame. Because this tells us where the floating origin cell /// is located in the local frame, we can compute the inverse transform once, then use it to /// transform every entity relative to the floating origin. @@ -633,7 +629,7 @@ mod tests { Vec3::new(5.0, 5.0, 0.0), DQuat::from_rotation_z(-std::f64::consts::FRAC_PI_2), ), - ..default() + ..Default::default() }, )) .id(); diff --git a/src/reference_frame/mod.rs b/src/reference_frame/mod.rs index f1434db..16b0d72 100644 --- a/src/reference_frame/mod.rs +++ b/src/reference_frame/mod.rs @@ -2,12 +2,10 @@ //! through space together, like entities on a planet, rotating about the planet's axis, and, //! orbiting a star. -use bevy::{ - ecs::prelude::*, - math::{Affine3A, DAffine3, DVec3, Vec3}, - reflect::Reflect, - transform::prelude::*, -}; +use bevy_ecs::prelude::*; +use bevy_math::{prelude::*, Affine3A, DAffine3, DVec3}; +use bevy_reflect::prelude::*; +use bevy_transform::prelude::*; use crate::{precision::GridPrecision, GridCell}; diff --git a/src/reference_frame/propagation.rs b/src/reference_frame/propagation.rs index d70fa4b..7272b69 100644 --- a/src/reference_frame/propagation.rs +++ b/src/reference_frame/propagation.rs @@ -1,7 +1,10 @@ //! Logic for propagating transforms through the hierarchy of reference frames. +use bevy_ecs::prelude::*; +use bevy_hierarchy::prelude::*; +use bevy_transform::prelude::*; + use crate::{precision::GridPrecision, reference_frame::ReferenceFrame, GridCell}; -use bevy::prelude::*; impl ReferenceFrame

{ /// Update the `GlobalTransform` of entities with a [`GridCell`], using the [`ReferenceFrame`] diff --git a/src/validation.rs b/src/validation.rs index dc7a04d..ff72582 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -2,8 +2,11 @@ use std::marker::PhantomData; -use bevy::prelude::*; -use bevy::utils::HashMap; +use bevy_ecs::prelude::*; +use bevy_hierarchy::prelude::*; +use bevy_log::prelude::*; +use bevy_transform::prelude::*; +use bevy_utils::HashMap; use crate::{ precision::GridPrecision, reference_frame::ReferenceFrame, BigSpace, FloatingOrigin, GridCell, diff --git a/src/world_query.rs b/src/world_query.rs index 816314b..bf528f5 100644 --- a/src/world_query.rs +++ b/src/world_query.rs @@ -1,9 +1,9 @@ //! A helper query argument that ensures you don't forget to handle //! the [`GridCell`] when you work with a [`Transform`]. -use bevy::ecs::query::QueryData; -use bevy::math::DVec3; -use bevy::prelude::*; +use bevy_ecs::query::QueryData; +use bevy_math::{prelude::*, DVec3}; +use bevy_transform::prelude::*; use crate::GridCell; use crate::{precision::GridPrecision, reference_frame::ReferenceFrame};