Change precision features to be more flexible. (#41)

This commit is contained in:
Aevyrie 2025-03-29 22:23:28 -07:00 committed by GitHub
parent e513c7ab82
commit 09e0fe513a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -244,17 +244,16 @@ pub mod prelude {
pub use world_query::{GridTransform, GridTransformOwned, GridTransformReadOnly}; pub use world_query::{GridTransform, GridTransformOwned, GridTransformReadOnly};
} }
/// Contains [`GridPrecision`], allowing `big_space` to work with many grid integer sizes. /// Contains the [`GridPrecision`] integer index type, which defines how much precision is available
/// when indexing into a [`Grid`].
/// ///
/// The integer type used is controlled with compile time feature flags like `i8`. The crate /// The integer type is controlled with feature flags like `i8`. The crate defaults to `i64` grids
/// defaults to `i64` grids if none is specified. /// if none is specified. If multiple integer precisions are enabled, the largest enabled precision
/// will be used.
/// ///
/// Larger grids result in a larger usable volume, at the cost of increased memory usage. In /// Larger grids result in a larger usable volume, at the cost of increased memory usage. Assuming
/// addition, some platforms may be unable to use larger numeric types (e.g. [`i128`]). /// you are using a grid cell edge length of 10,000 meters, and `1.0` == 1 meter, these correspond
/// /// to a total usable volume of a cube with the following edge lengths:
/// [`big_space`](crate) is generic over a few integer types to allow you to select the grid size
/// you need. Assuming you are using a grid cell edge length of 10,000 meters, and `1.0` == 1 meter,
/// these correspond to a total usable volume of a cube with the following edge lengths:
/// ///
/// - `i8`: 2,560 km = 74% of the diameter of the Moon /// - `i8`: 2,560 km = 74% of the diameter of the Moon
/// - `i16`: 655,350 km = 85% of the diameter of the Moon's orbit around Earth /// - `i16`: 655,350 km = 85% of the diameter of the Moon's orbit around Earth
@ -272,21 +271,42 @@ pub mod precision {
#[allow(unused_imports)] // Docs #[allow(unused_imports)] // Docs
use super::*; use super::*;
#[cfg(feature = "i8")] #[cfg(all(
/// Adds 8 bits of precision to bevy's [`Transform`]. See [`precision`]. feature = "i8",
not(any(feature = "i128", feature = "i64", feature = "i32", feature = "i16"))
))]
/// The integer type used as the index for a `big_space` grid. Adds 8 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 40 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i8; pub type GridPrecision = i8;
#[cfg(feature = "i16")]
/// Adds 16 bits of precision to bevy's [`Transform`]. See [`precision`]. #[cfg(all(
feature = "i16",
not(any(feature = "i128", feature = "i64", feature = "i32"))
))]
/// The integer type used as the index for a `big_space` grid. Adds 16 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 48 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i16; pub type GridPrecision = i16;
#[cfg(feature = "i32")]
/// Adds 32 bits of precision to bevy's [`Transform`]. See [`precision`]. #[cfg(all(feature = "i32", not(any(feature = "i128", feature = "i64"))))]
/// The integer type used as the index for a `big_space` grid. Adds 32 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 64 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i32; pub type GridPrecision = i32;
#[cfg(feature = "i64")]
/// Adds 64 bits of precision to bevy's [`Transform`]. See [`precision`]. #[cfg(all(feature = "i64", not(feature = "i128")))]
/// The integer type used as the index for a `big_space` grid. Adds 64 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 96 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i64; pub type GridPrecision = i64;
#[cfg(feature = "i128")] #[cfg(feature = "i128")]
/// Adds 128 bits of precision to bevy's [`Transform`]. See [`precision`]. /// The integer type used as the index for a `big_space` grid. Adds 128 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 160 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i128; pub type GridPrecision = i128;
#[cfg(not(any( #[cfg(not(any(
feature = "i8", feature = "i8",
feature = "i16", feature = "i16",
@ -294,6 +314,10 @@ pub mod precision {
feature = "i64", feature = "i64",
feature = "i128" feature = "i128"
)))] )))]
/// Adds 64 bits of precision to bevy's [`Transform`]. See [`precision`]. /// No integer [`precision`] feature was enabled; `i64` is used by default.
///
/// The integer type used as the index for a `big_space` grid. Adds 64 bits of precision, in
/// addition to bevy's 32 bit [`Transform`], for a total of 96 bits of translational precision.
/// See [`precision`].
pub type GridPrecision = i64; pub type GridPrecision = i64;
} }