Skip to content

Commit 37f57c6

Browse files
authored
feat: add support for bevy 0.8 (#27)
1 parent 9f74d87 commit 37f57c6

File tree

8 files changed

+95
-30
lines changed

8 files changed

+95
-30
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_dispatch:
1010

1111
env:
12-
RUST_VERSION: 1.58.1
12+
RUST_VERSION: 1.62.0
1313

1414
jobs:
1515
test:
@@ -28,29 +28,25 @@ jobs:
2828
profile: minimal
2929
target: thumbv6m-none-eabi
3030

31-
- run: cargo update -p async-global-executor --precise 2.0.4
3231
- run: cargo check --all-targets
3332

3433
- name: Check no_std
3534
run: cargo check --no-default-features --target thumbv6m-none-eabi
3635

3736
- run: cargo test --no-default-features
37+
- run: cargo test
3838
- run: cargo test --no-default-features --features std
39+
- run: cargo test --no-default-features --features bvh-arena
40+
- run: cargo test --no-default-features --features bevy-transform-08
41+
- run: cargo test --no-default-features --features bevy-ecs-08
42+
- run: cargo test --no-default-features --features bevy-08
3943
- run: cargo test --no-default-features --features bevy-transform-07
4044
- run: cargo test --no-default-features --features bevy-ecs-07
4145
- run: cargo test --no-default-features --features bevy-07
4246
- run: cargo test --no-default-features --features bevy-transform-06
4347
- run: cargo test --no-default-features --features bevy-ecs-06
4448
- run: cargo test --no-default-features --features bevy-06
45-
- run: cargo test
46-
- run: cargo test --features bevy-transform-07
47-
- run: cargo test --features bevy-ecs-07
48-
- run: cargo test --features bevy-07
49-
- run: cargo test --features bevy-transform-06
50-
- run: cargo test --features bevy-ecs-06
51-
- run: cargo test --features bevy-06
5249
- run: cargo test --all-features
53-
- run: cargo test --all-features -- --ignored
5450

5551
code-style:
5652
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.4.0"
44
license = "Unlicense"
55
authors = ["Jonathan Cornaz"]
66
edition = "2021"
7-
rust-version = "1.58"
7+
rust-version = "1.62"
88
description = "2d collision test for arbitrary convex shapes"
99
repository = "https://github.com/jcornaz/impacted"
1010
categories = ["game-development"]
@@ -16,16 +16,27 @@ all-features = true
1616
[features]
1717
default = ["std"]
1818
std = ["glam/std", "thiserror"]
19-
bevy-06 = ["bevy-transform-06", "bevy-ecs-06"]
19+
bevy-08 = ["bevy-transform-08", "bevy-ecs-08"]
20+
bevy-transform-08 = ["dep:bevy-transform-08", "bevy-math-08"]
2021
bevy-07 = ["bevy-transform-07", "bevy-ecs-07"]
22+
bevy-06 = ["bevy-transform-06", "bevy-ecs-06"]
2123

2224
[dependencies]
2325
# Public
24-
bevy-transform-06 = { package = "bevy_transform", version = "0.6.0", default-features = false, optional = true }
26+
bvh-arena = { version = "1.1", default-features = false, optional = true }
27+
28+
## Bevy 0.8
29+
bevy-ecs-08 = { package = "bevy_ecs", version = "0.8.0", default-features = false, optional = true }
30+
bevy-transform-08 = { package = "bevy_transform", version = "0.8.0", default-features = false, optional = true }
31+
bevy-math-08 = { package = "bevy_math", version = "0.8.0", default-features = false, optional = true }
32+
33+
## Bevy 0.7
34+
bevy-ecs-07 = { package = "bevy_ecs", version = "0.7.0", default-features = false, optional = true }
2535
bevy-transform-07 = { package = "bevy_transform", version = "0.7.0", default-features = false, optional = true }
36+
37+
## Bevy 0.6
2638
bevy-ecs-06 = { package = "bevy_ecs", version = "0.6.0", default-features = false, optional = true }
27-
bevy-ecs-07 = { package = "bevy_ecs", version = "0.7.0", default-features = false, optional = true }
28-
bvh-arena = { version = "1.1", default-features = false, optional = true }
39+
bevy-transform-06 = { package = "bevy_transform", version = "0.6.0", default-features = false, optional = true }
2940

3041
# Private
3142
glam = { version = "0.20.5", default-features = false, features = ["libm"] }
@@ -34,7 +45,7 @@ smallvec = { version = "1.9", default-features = false }
3445

3546
[dev-dependencies]
3647
rstest = "0.13.0"
37-
bevy = { version = "0.7.0", default-features = false, features = ["bevy_winit", "render", "x11"]}
48+
bevy = { version = "0.8.0", default-features = false, features = ["bevy_winit", "render", "x11"]}
3849
glam = { version = "0.20.5", default-features = false, features = ["libm", "approx"] }
3950
approx = "0.5.1"
4051

@@ -43,4 +54,4 @@ rustc_version = "0.4.0"
4354

4455
[[example]]
4556
name = "bevy"
46-
required-features = ["bevy-07"]
57+
required-features = ["bevy-08"]

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,25 @@ impacted = { version = "1", features = ["bevy-07"] }
7272

7373
## Cargo features
7474

75-
* `std` (enabled by default) Allow to use the standard library (need to be disabled for `no_std` crates)
76-
* `bvh-arena` Interoperability with [bvh-arena](https://crates.io/crates/bvh-arena) bounding volumes
77-
* `bevy-07` All [bevy](https://bevyengine.org) 0.7 interop (alias for `["bevy-transform-07", "bevy-ecs-07"]`)
78-
* `bevy-06` All [bevy](https://bevyengine.org) 0.6 interop (alias for `["bevy-transform-06", "bevy-ecs-06"]`)
79-
* `bevy-transform-07` Interoperability with [bevy_transform](https://crates.io/crates/bevy_transform) 0.7
80-
* `bevy-transform-06` Interoperability with [bevy_transform](https://crates.io/crates/bevy_transform) 0.6
81-
* `bevy-ecs-07` Interoperability with [bevy_ecs](https://crates.io/crates/bevy_ecs) 0.7
82-
* `bevy-ecs-06` Interoperability with [bevy_ecs](https://crates.io/crates/bevy_ecs) 0.6
83-
75+
| Feature | Description |
76+
|---------------------|-----------------------------------------------------------------------------------|
77+
| `std` (default) | Allow to use rust the standard library (need to be disabled for `no_std` crates) |
78+
| `bvh-arena` | Integration with [bvh-arena](https://crates.io/crates/bvh-arena) bounding volumes |
79+
| `bevy-ecs-08` | Integration with [bevy_ecs](https://crates.io/crates/bevy_ecs) 0.8 |
80+
| `bevy-transform-08` | Integration with [bevy_transform](https://crates.io/crates/bevy_transform) 0.8 |
81+
| `bevy-08` | All bevy 0.8 integrations (alias for `["bevy-ecs-08", "bevy-transform-08"]`) |
82+
| `bevy-ecs-07` | Integration with [bevy_ecs](https://crates.io/crates/bevy_ecs) 0.7 |
83+
| `bevy-transform-07` | Integration with [bevy_transform](https://crates.io/crates/bevy_transform) 0.7 |
84+
| `bevy-07` | All bevy 0.7 integrations (alias for `["bevy-ecs-07", "bevy-transform-07"]`) |
85+
| `bevy-ecs-06` | Integration with [bevy_ecs](https://crates.io/crates/bevy_ecs) 0.6 |
86+
| `bevy-transform-06` | Integration with [bevy_transform](https://crates.io/crates/bevy_transform) 0.6 |
87+
| `bevy-06` | All bevy 0.6 integrations (alias for `["bevy-ecs-06", "bevy-transform-06"]`) |
88+
89+
*Feature flags not listed in the table above are not part of the public API and are subject to breaking changes*
8490

8591
## MSRV
8692

87-
The minimum supported rust version is currently: `1.58`
93+
The minimum supported rust version is currently: `1.62`
8894

8995
It may be increased to a newer stable version in a minor release.
9096

deny.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ copyleft = "deny"
1212
allow = [
1313
"Unlicense",
1414
"MIT",
15+
"MIT-0",
1516
"Apache-2.0",
1617
"Zlib",
1718
"BSD-3-Clause",
1819
"CC0-1.0",
1920
"ISC",
21+
"Unicode-DFS-2016",
2022
]
2123

2224

examples/bevy.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::f32::consts;
22

3-
use bevy::input::system::exit_on_esc_system;
43
use bevy::prelude::*;
54
use bevy::transform::TransformSystem;
65

@@ -16,7 +15,6 @@ fn main() {
1615
.add_plugins(DefaultPlugins)
1716
.add_startup_system(startup)
1817
.add_system(control_shape)
19-
.add_system(exit_on_esc_system)
2018
// Collision detection
2119
.add_system_to_stage(
2220
CoreStage::PostUpdate,
@@ -30,7 +28,7 @@ fn main() {
3028
/// Initialize the "game"
3129
fn startup(mut commands: Commands) {
3230
// Camera
33-
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
31+
commands.spawn_bundle(Camera2dBundle::default());
3432

3533
// Left shape (controlled)
3634
commands

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,8 @@ impl bevy_ecs_06::prelude::Component for CollisionShape {
186186
impl bevy_ecs_07::prelude::Component for CollisionShape {
187187
type Storage = bevy_ecs_07::component::SparseStorage;
188188
}
189+
190+
#[cfg(feature = "bevy-ecs-08")]
191+
impl bevy_ecs_08::prelude::Component for CollisionShape {
192+
type Storage = bevy_ecs_08::component::SparseStorage;
193+
}

src/transform/bevy_transform_08.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use bevy_math_08::{Quat, Vec3};
2+
use bevy_transform_08::prelude::GlobalTransform;
3+
4+
#[cfg(feature = "bevy-transform-08")] // Repeated to appear in the docs
5+
impl From<GlobalTransform> for crate::Transform {
6+
#[inline]
7+
fn from(transform: GlobalTransform) -> Self {
8+
let (scale, rotation, translation) = transform.to_scale_rotation_translation();
9+
Self::from_scale_angle_translation(
10+
scale.truncate(),
11+
angle_2d_from_quat(rotation),
12+
translation.truncate(),
13+
)
14+
}
15+
}
16+
17+
fn angle_2d_from_quat(quat: Quat) -> f32 {
18+
if quat.is_near_identity() {
19+
return 0.0;
20+
}
21+
let projected = quat.to_scaled_axis().project_onto(Vec3::Z);
22+
let angle = projected.length();
23+
if projected.z < 0.0 {
24+
-angle
25+
} else {
26+
angle
27+
}
28+
}
29+
30+
#[cfg(all(test, feature = "std"))]
31+
mod angle_from_quat {
32+
use rstest::rstest;
33+
34+
use super::*;
35+
36+
#[rstest]
37+
#[case(Quat::from_axis_angle(Vec3::Z, 1.0), 1.0)]
38+
#[case(Quat::from_axis_angle(- Vec3::Z, 1.0), - 1.0)]
39+
#[case(Quat::from_axis_angle(Vec3::Z, - 1.0), - 1.0)]
40+
#[case(Quat::from_axis_angle(- Vec3::Z, - 1.0), 1.0)]
41+
fn angle_from_quat(#[case] quat: Quat, #[case] expected: f32) {
42+
assert!((angle_2d_from_quat(quat) - expected).abs() < f32::EPSILON);
43+
}
44+
}

src/transform/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ mod bevy_transform_06;
88
#[cfg(feature = "bevy-transform-07")]
99
mod bevy_transform_07;
1010

11+
#[cfg(feature = "bevy-transform-08")]
12+
mod bevy_transform_08;
13+
1114
/// Transform that can be used for a [`CollisionShape`]
1215
#[derive(Debug, Clone)]
1316
pub struct Transform {

0 commit comments

Comments
 (0)