diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 63fee5e..98cf899 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo check --all-features --all-targets + - run: cargo check --features=all --all-targets check-no-defaults: runs-on: ubuntu-latest @@ -48,7 +48,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - run: rustup component add clippy - - run: cargo clippy --all-features --all-targets -- -D warnings + - run: cargo clippy --features=all --all-targets -- -D warnings doc: runs-on: ubuntu-latest @@ -57,7 +57,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo doc --all-features --no-deps + - run: cargo doc --features=all --no-deps env: RUSTDOCFLAGS: -D warnings @@ -68,7 +68,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo test --all-features + - run: cargo test --features=all doctest: runs-on: ubuntu-latest @@ -77,4 +77,4 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo test --all-features --doc \ No newline at end of file + - run: cargo test --features=all --doc \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b10c5fb..2a6ed68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,14 @@ documentation = "https://docs.rs/crate/big_space/latest" [features] default = [] +all = ["debug", "camera"] # Can't use all-features, integer type features are incompatible. debug = ["bevy_gizmos", "bevy_color"] camera = ["bevy_render", "bevy_time", "bevy_input"] +i8 = [] +i16 = [] +i32 = [] +i64 = [] +i128 = [] [dependencies] tracing = "0.1" # Less deps than pulling in bevy_log @@ -69,8 +75,10 @@ doc-scrape-examples = false [[example]] name = "demo" path = "examples/demo.rs" +required-features = ["i128"] doc-scrape-examples = false + [[example]] name = "error_child" path = "examples/error_child.rs" @@ -84,6 +92,7 @@ doc-scrape-examples = false [[example]] name = "infinite" path = "examples/infinite.rs" +required-features = ["i8"] doc-scrape-examples = false [[example]] diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index 2287e2d..325fa26 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -38,10 +38,10 @@ fn deep_hierarchy(c: &mut Criterion) { let mut group = c.benchmark_group(format!("deep_hierarchy {N_SPAWN}")); fn setup(mut commands: Commands) { - commands.spawn_big_space::(Grid::new(10000.0, 0.0), |root| { + commands.spawn_big_space(Grid::new(10000.0, 0.0), |root| { let mut parent = root.spawn_grid_default(()).id(); for _ in 0..N_SPAWN { - let child = root.commands().spawn(BigGridBundle::::default()).id(); + let child = root.commands().spawn(BigGridBundle::default()).id(); root.commands().entity(parent).add_child(child); parent = child; } @@ -58,8 +58,8 @@ fn deep_hierarchy(c: &mut Criterion) { let mut app = App::new(); app.add_plugins(( MinimalPlugins, - GridHashPlugin::::default(), - BigSpacePlugin::::default(), + GridHashPlugin::<()>::default(), + BigSpacePlugin::default(), )) .add_systems(Startup, setup) .add_systems(Update, translate) @@ -80,7 +80,7 @@ fn wide_hierarchy(c: &mut Criterion) { let mut group = c.benchmark_group(format!("wide_hierarchy {N_SPAWN}")); fn setup(mut commands: Commands) { - commands.spawn_big_space::(Grid::new(10000.0, 0.0), |root| { + commands.spawn_big_space(Grid::new(10000.0, 0.0), |root| { for _ in 0..N_SPAWN { root.spawn_spatial(()); } @@ -97,8 +97,8 @@ fn wide_hierarchy(c: &mut Criterion) { let mut app = App::new(); app.add_plugins(( MinimalPlugins, - GridHashPlugin::::default(), - BigSpacePlugin::::default(), + GridHashPlugin::<()>::default(), + BigSpacePlugin::default(), )) .add_systems(Startup, setup) .add_systems(Update, translate) @@ -115,20 +115,20 @@ fn wide_hierarchy(c: &mut Criterion) { fn spatial_hashing(c: &mut Criterion) { let mut group = c.benchmark_group("spatial_hashing"); - const HALF_WIDTH: i32 = 100; + const HALF_WIDTH: i64 = 100; /// Total number of entities to spawn const N_SPAWN: usize = 10_000; /// Number of entities that move into a different cell each update const N_MOVE: usize = 1_000; fn setup(mut commands: Commands) { - commands.spawn_big_space::(Grid::new(1.0, 0.0), |root| { + commands.spawn_big_space(Grid::new(1.0, 0.0), |root| { let rng = Rng::with_seed(342525); let values: Vec<_> = repeat_with(|| { [ - rng.i32(-HALF_WIDTH..=HALF_WIDTH), - rng.i32(-HALF_WIDTH..=HALF_WIDTH), - rng.i32(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), ] }) .take(N_SPAWN) @@ -140,14 +140,14 @@ fn spatial_hashing(c: &mut Criterion) { }); } - fn translate(mut cells: Query<&mut GridCell>) { + fn translate(mut cells: Query<&mut GridCell>) { cells.iter_mut().take(N_MOVE).for_each(|mut cell| { *cell += GridCell::ONE; }) } let mut app = App::new(); - app.add_plugins(GridHashPlugin::::default()) + app.add_plugins(GridHashPlugin::<()>::default()) .add_systems(Startup, setup) .update(); @@ -164,7 +164,7 @@ fn spatial_hashing(c: &mut Criterion) { }); }); - let map = app.world().resource::>(); + let map = app.world().resource::(); let first = map .all_entries() .find(|(_, entry)| !entry.entities.is_empty()) @@ -185,8 +185,8 @@ fn spatial_hashing(c: &mut Criterion) { }); }); - // let parent = app .world_mut() .query::<&GridHash>() .get(app.world(), ent) - // .unwrap(); let map = app.world().resource::>(); let entry = + // let parent = app .world_mut() .query::<&GridHash>() .get(app.world(), ent) + // .unwrap(); let map = app.world().resource::(); let entry = // map.get(parent).unwrap(); // group.bench_function("Neighbors radius: 4", |b| { @@ -204,8 +204,8 @@ fn spatial_hashing(c: &mut Criterion) { // }); // }); - fn setup_uniform(mut commands: Commands) { - commands.spawn_big_space::(Grid::new(1.0, 0.0), |root| { + fn setup_uniform(mut commands: Commands) { + commands.spawn_big_space(Grid::new(1.0, 0.0), |root| { for x in HALF_EXTENT.neg()..HALF_EXTENT { for y in HALF_EXTENT.neg()..HALF_EXTENT { for z in HALF_EXTENT.neg()..HALF_EXTENT { @@ -219,7 +219,7 @@ fn spatial_hashing(c: &mut Criterion) { // Uniform Grid Population 1_000 let mut app = App::new(); - app.add_plugins(GridHashPlugin::::default()) + app.add_plugins(GridHashPlugin::<()>::default()) .add_systems(Startup, setup_uniform::<5>) .update(); @@ -227,7 +227,7 @@ fn spatial_hashing(c: &mut Criterion) { .world_mut() .query_filtered::>() .single(app.world()); - let spatial_map = app.world().resource::>(); + let spatial_map = app.world().resource::(); let hash = GridHash::__new_manual(parent, &GridCell { x: 0, y: 0, z: 0 }); let entry = spatial_map.get(&hash).unwrap(); @@ -247,7 +247,7 @@ fn spatial_hashing(c: &mut Criterion) { // Uniform Grid Population 1_000_000 let mut app = App::new(); - app.add_plugins(GridHashPlugin::::default()) + app.add_plugins(GridHashPlugin::<()>::default()) .add_systems(Startup, setup_uniform::<50>) .update(); @@ -255,7 +255,7 @@ fn spatial_hashing(c: &mut Criterion) { .world_mut() .query_filtered::>() .single(app.world()); - let spatial_map = app.world().resource::>(); + let spatial_map = app.world().resource::(); let hash = GridHash::__new_manual(parent, &GridCell { x: 0, y: 0, z: 0 }); let entry = spatial_map.get(&hash).unwrap(); @@ -279,7 +279,7 @@ fn hash_filtering(c: &mut Criterion) { const N_ENTITIES: usize = 100_000; const N_PLAYERS: usize = 100; const N_MOVE: usize = 1_000; - const HALF_WIDTH: i32 = 100; + const HALF_WIDTH: i64 = 100; #[derive(Component)] struct Player; @@ -288,15 +288,15 @@ fn hash_filtering(c: &mut Criterion) { let rng = Rng::with_seed(342525); let values: Vec<_> = repeat_with(|| { [ - rng.i32(-HALF_WIDTH..=HALF_WIDTH), - rng.i32(-HALF_WIDTH..=HALF_WIDTH), - rng.i32(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), + rng.i64(-HALF_WIDTH..=HALF_WIDTH), ] }) .take(N_ENTITIES) .collect(); - commands.spawn_big_space_default::(|root| { + commands.spawn_big_space_default(|root| { for (i, pos) in values.iter().enumerate() { let mut cmd = root.spawn_spatial(GridCell::new(pos[0], pos[1], pos[2])); if i < N_PLAYERS { @@ -306,7 +306,7 @@ fn hash_filtering(c: &mut Criterion) { }); } - fn translate(mut cells: Query<&mut GridCell>) { + fn translate(mut cells: Query<&mut GridCell>) { cells.iter_mut().take(N_MOVE).for_each(|mut cell| { *cell += IVec3::ONE; }); @@ -317,7 +317,7 @@ fn hash_filtering(c: &mut Criterion) { .add_systems(Update, translate) .update(); app.update(); - app.add_plugins((GridHashPlugin::::default(),)); + app.add_plugins((GridHashPlugin::<()>::default(),)); group.bench_function("No Filter Plugin", |b| { b.iter(|| { black_box(app.update()); @@ -329,7 +329,7 @@ fn hash_filtering(c: &mut Criterion) { .add_systems(Update, translate) .update(); app.update(); - app.add_plugins((GridHashPlugin::>::default(),)); + app.add_plugins((GridHashPlugin::>::default(),)); group.bench_function("With Player Plugin", |b| { b.iter(|| { black_box(app.update()); @@ -341,7 +341,7 @@ fn hash_filtering(c: &mut Criterion) { .add_systems(Update, translate) .update(); app.update(); - app.add_plugins((GridHashPlugin::>::default(),)); + app.add_plugins((GridHashPlugin::>::default(),)); group.bench_function("Without Player Plugin", |b| { b.iter(|| { black_box(app.update()); @@ -353,9 +353,9 @@ fn hash_filtering(c: &mut Criterion) { .add_systems(Update, translate) .update(); app.update(); - app.add_plugins((GridHashPlugin::::default(),)) - .add_plugins((GridHashPlugin::>::default(),)) - .add_plugins((GridHashPlugin::>::default(),)); + app.add_plugins((GridHashPlugin::<()>::default(),)) + .add_plugins((GridHashPlugin::>::default(),)) + .add_plugins((GridHashPlugin::>::default(),)); group.bench_function("All Plugins", |b| { b.iter(|| { black_box(app.update()); @@ -383,7 +383,7 @@ fn vs_bevy(c: &mut Criterion) { } fn setup_big(mut commands: Commands) { - commands.spawn_big_space_default::(|root| { + commands.spawn_big_space_default(|root| { for _ in 0..N_ENTITIES { root.spawn_spatial(()); } @@ -403,7 +403,7 @@ fn vs_bevy(c: &mut Criterion) { }); let mut app = App::new(); - app.add_plugins((MinimalPlugins, BigSpacePlugin::::default())) + app.add_plugins((MinimalPlugins, BigSpacePlugin::default())) .add_systems(Startup, setup_big) .update(); @@ -432,7 +432,7 @@ fn vs_bevy(c: &mut Criterion) { }); let mut app = App::new(); - app.add_plugins((MinimalPlugins, BigSpacePlugin::::default())) + app.add_plugins((MinimalPlugins, BigSpacePlugin::default())) .add_systems(Startup, setup_big) .add_systems(Update, translate) .update(); diff --git a/examples/debug.rs b/examples/debug.rs index 3d0eff6..5b06c38 100644 --- a/examples/debug.rs +++ b/examples/debug.rs @@ -7,8 +7,8 @@ fn main() { App::new() .add_plugins(( DefaultPlugins, - BigSpacePlugin::::default(), - big_space::debug::FloatingOriginDebugPlugin::::default(), + BigSpacePlugin::default(), + big_space::debug::FloatingOriginDebugPlugin::default(), )) .add_systems(Startup, setup) .add_systems(Update, (movement, rotation)) @@ -64,7 +64,7 @@ fn setup( ..default() }); - commands.spawn_big_space::(Grid::new(1.0, 0.01), |root| { + commands.spawn_big_space(Grid::new(1.0, 0.01), |root| { root.spawn_spatial(( Mesh3d(mesh_handle.clone()), MeshMaterial3d(matl_handle.clone()), diff --git a/examples/demo.rs b/examples/demo.rs index e84e80e..f6dbd58 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -14,9 +14,9 @@ fn main() { App::new() .add_plugins(( DefaultPlugins, - BigSpacePlugin::::default(), - FloatingOriginDebugPlugin::::default(), - big_space::camera::CameraControllerPlugin::::default(), + BigSpacePlugin::default(), + FloatingOriginDebugPlugin::default(), + big_space::camera::CameraControllerPlugin::default(), )) .insert_resource(ClearColor(Color::BLACK)) .add_systems(Startup, (setup, ui_setup)) @@ -33,7 +33,7 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands.spawn_big_space_default::(|root| { + commands.spawn_big_space_default(|root| { root.spawn_spatial(( Camera3d::default(), Projection::Perspective(PerspectiveProjection { @@ -150,9 +150,9 @@ fn ui_text_system( (With, Without), >, mut fun_text: Query<&mut Text, (With, Without)>, - grids: Grids, + grids: Grids, time: Res