Skip to content

Commit

Permalink
Dependency Reduction (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jun 30, 2024
1 parent 8721911 commit 27801da
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 92 deletions.
23 changes: 16 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 16 additions & 14 deletions src/bundles.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -130,7 +132,7 @@ impl CameraInput {
pub fn reset(&mut self) {
*self = CameraInput {
defaults_disabled: self.defaults_disabled,
..default()
..Default::default()
};
}

Expand Down
19 changes: 9 additions & 10 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::marker::PhantomData;

use crate::{reference_frame::ReferenceFrame, *};
use bevy::prelude::*;

use self::precision::GridPrecision;

Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/floating_origins.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/grid_cell.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Contains the grid cell implementation

use bevy::prelude::*;
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;

use crate::*;

Expand Down
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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};
Expand Down
13 changes: 8 additions & 5 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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),
);
Expand Down
2 changes: 1 addition & 1 deletion src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Loading

0 comments on commit 27801da

Please sign in to comment.