Dependency Reduction (#23)

This commit is contained in:
Aevyrie 2024-06-30 01:31:16 -07:00 committed by GitHub
parent 8721911b49
commit 27801da98c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 119 additions and 92 deletions

View File

@ -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"

View File

@ -18,7 +18,6 @@ fn main() {
big_space::BigSpacePlugin::<i128>::default(),
big_space::debug::FloatingOriginDebugPlugin::<i128>::default(),
big_space::camera::CameraControllerPlugin::<i128>::default(),
bevy_framepace::FramepacePlugin,
))
.insert_resource(ClearColor(Color::BLACK))
.add_systems(Startup, (setup, ui_setup))

View File

@ -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<P: GridPrecision> {
/// 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<P: GridPrecision> {
pub cell: GridCell<P>,
}
/// 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<P: GridPrecision> {
/// 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<P: GridPrecision> {
pub struct BigSpaceRootBundle<P: GridPrecision> {
/// 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<P>,
/// Tracks the current floating origin

View File

@ -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()
};
}

View File

@ -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<P: GridPrecision> BigSpaceCommands<P> 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::<P>::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::<P>::default(),

View File

@ -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<P: GridPrecision> Plugin for FloatingOriginDebugPlugin<P> {
PostUpdate,
(update_debug_bounds::<P>, update_reference_frame_axes::<P>)
.chain()
.after(bevy::transform::TransformSystem::TransformPropagate),
.after(bevy_transform::TransformSystem::TransformPropagate),
);
}
}

View File

@ -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.

View File

@ -1,6 +1,7 @@
//! Contains the grid cell implementation
use bevy::prelude::*;
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;
use crate::*;

View File

@ -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};

View File

@ -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<P: GridPrecision + Reflect + FromReflect + TypePath> 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),
);

View File

@ -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.
///

View File

@ -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();

View File

@ -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};

View File

@ -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<P: GridPrecision> ReferenceFrame<P> {
/// Update the `GlobalTransform` of entities with a [`GridCell`], using the [`ReferenceFrame`]

View File

@ -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,

View File

@ -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};