Skip to content

Commit bbdf54b

Browse files
committed
Merge branch 'master' into feature/godot-3.5
# Conflicts: # README.md # gdnative-core/src/core_types/geom/transform2d.rs
2 parents c5fd091 + 46a154b commit bbdf54b

File tree

16 files changed

+130
-36
lines changed

16 files changed

+130
-36
lines changed

CHANGELOG.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `Transform2D::from_rotation_translation_scale()` constructor needs more intuitive API ([#910](https://github.com/godot-rust/godot-rust/pull/910))
1818

1919

20-
## [0.10.2] - unreleased
20+
## [0.10.2] - 2022-10-02
2121

2222
Last maintenance release for Godot 3.4.
2323

24-
# Added
24+
### Added
2525

26-
- `globalscope::load` method ([#940](https://github.com/godot-rust/godot-rust/pull/940), [#941](https://github.com/godot-rust/godot-rust/pull/941))
26+
- `globalscope::load()` function ([#940](https://github.com/godot-rust/godot-rust/pull/940), [#941](https://github.com/godot-rust/godot-rust/pull/941))
2727
- `Color` constructors from HTML string and integers ([#939](https://github.com/godot-rust/godot-rust/pull/939))
2828
- Version check to warn if Godot is not 3.4 ([#942](https://github.com/godot-rust/godot-rust/pull/942))
29+
- Support for iOS simulator on Mac M1 ([#944](https://github.com/godot-rust/godot-rust/pull/944))
30+
31+
### Fixed
32+
33+
- During tests, `get_api()` no longer aborts ([#929](https://github.com/godot-rust/godot-rust/pull/929))
34+
- Confusing `Transform2D` constructor ([#930](https://github.com/godot-rust/godot-rust/pull/930))
35+
- Bug in `Rect2::intersects()` ([#948](https://github.com/godot-rust/godot-rust/pull/948))
36+
- Bug in `Vector2::rotated()` ([#952](https://github.com/godot-rust/godot-rust/pull/952))
37+
2938

3039
## [0.10.1] - 2022-09-03
3140

bindings-generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/crate/gdnative_bindings_generator"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
88
license = "MIT"
9-
version = "0.10.1"
9+
version = "0.10.2"
1010
workspace = ".."
1111
edition = "2021"
1212
rust-version = "1.63"

gdnative-async/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Runtime async support for godot-rust."
55
documentation = "https://docs.rs/crate/gdnative-async"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.10.1"
8+
version = "0.10.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -14,9 +14,9 @@ rust-version = "1.63"
1414
[features]
1515

1616
[dependencies]
17-
gdnative-derive = { path = "../gdnative-derive", version = "=0.10.1" }
18-
gdnative-core = { path = "../gdnative-core", version = "=0.10.1" }
19-
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.10.1" }
17+
gdnative-derive = { path = "../gdnative-derive", version = "=0.10.2" }
18+
gdnative-core = { path = "../gdnative-core", version = "=0.10.2" }
19+
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.10.2" }
2020
atomic-waker = "1"
2121
crossbeam-channel = "0.5"
2222
futures-task = "0.3"

gdnative-bindings/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "The Godot game engine's automatcally generated bindings to Godot
55
documentation = "https://docs.rs/crate/gdnative-bindings"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.10.1"
8+
version = "0.10.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -17,8 +17,8 @@ one-class-one-file = []
1717
custom-godot = ["gdnative_bindings_generator/custom-godot"]
1818

1919
[dependencies]
20-
gdnative-core = { path = "../gdnative-core", version = "=0.10.1" }
20+
gdnative-core = { path = "../gdnative-core", version = "=0.10.2" }
2121
libc = "0.2"
2222

2323
[build-dependencies]
24-
gdnative_bindings_generator = { path = "../bindings-generator", version = "=0.10.1" }
24+
gdnative_bindings_generator = { path = "../bindings-generator", version = "=0.10.2" }

gdnative-core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "The Godot game engine's gdnative core bindings."
55
documentation = "https://docs.rs/crate/gdnative-core"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.10.1"
8+
version = "0.10.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -17,8 +17,8 @@ gd-test = []
1717
type-tag-fallback = []
1818

1919
[dependencies]
20-
gdnative-sys = { path = "../gdnative-sys", version = "=0.10.1" }
21-
gdnative-impl-proc-macros = { path = "../impl/proc-macros", version = "=0.10.1" }
20+
gdnative-sys = { path = "../gdnative-sys", version = "=0.10.2" }
21+
gdnative-impl-proc-macros = { path = "../impl/proc-macros", version = "=0.10.2" }
2222
ahash = "0.8"
2323
approx = "0.5"
2424
atomic-take = "1"

gdnative-core/src/core_types/geom/rect2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Rect2 {
115115
self.position.x < b.position.x + b.size.x
116116
&& self.position.x + self.size.x > b.position.x
117117
&& self.position.y < b.position.y + b.size.y
118-
&& self.position.y + self.size.y > b.size.y
118+
&& self.position.y + self.size.y > b.position.y
119119
}
120120

121121
/// Returns true if the rectangle overlaps with `b` (i.e. they have at least one point in
@@ -130,7 +130,7 @@ impl Rect2 {
130130
self.position.x <= b.position.x + b.size.x
131131
&& self.position.x + self.size.x >= b.position.x
132132
&& self.position.y <= b.position.y + b.size.y
133-
&& self.position.y + self.size.y >= b.size.y
133+
&& self.position.y + self.size.y >= b.position.y
134134
}
135135

136136
/// Returns true if this rectangle (inclusively) encloses `b`.

gdnative-core/src/core_types/geom/transform2d.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ impl Transform2D {
7575
}
7676
}
7777

78+
/// Constructs the transform from a given scale, angle (in radians), and origin.
79+
///
80+
/// This is **NOT** equivalent to either of these two lines:
81+
/// ```ignore
82+
/// Transform2D::IDENTITY.scaled(scale).rotated(rotation).translated(origin)
83+
/// Transform2D::IDENTITY.translated(origin).rotated(rotation).scaled(scale)
84+
/// ```
85+
///
86+
/// Those transformations do not preserve the given origin; see documentation for [`rotated`], [`scaled`], and [`translated`].
87+
///
88+
/// [`rotated`]: Self::rotated
89+
/// [`scaled`]: Self::scaled
90+
/// [`translated`]: Self::translated
91+
#[inline]
92+
pub fn from_scale_rotation_origin(scale: Vector2, rotation: f32, origin: Vector2) -> Self {
93+
let mut tr = Self::IDENTITY;
94+
tr.set_scale(scale);
95+
tr.set_rotation(rotation);
96+
tr.origin = origin;
97+
98+
tr
99+
}
100+
78101
/// Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
79102
#[inline]
80103
pub fn affine_inverse(&self) -> Self {
@@ -151,7 +174,7 @@ impl Transform2D {
151174
self.set_scale(scale);
152175
}
153176

154-
/// Rotates the transform by the given angle (in radians), using matrix multiplication.
177+
/// Rotates the transform by the given angle (in radians), using matrix multiplication. This will modify the transform's origin.
155178
#[inline]
156179
pub fn rotated(&self, rotation: f32) -> Self {
157180
let mut tr = Self::IDENTITY;
@@ -173,7 +196,7 @@ impl Transform2D {
173196
self.b = self.b.normalized() * scale.y;
174197
}
175198

176-
/// Scales the transform by the given scale factor, using matrix multiplication.
199+
/// Scales the transform by the given scale factor, using matrix multiplication. This will modify the transform's origin.
177200
#[inline]
178201
pub fn scaled(&self, scale: Vector2) -> Self {
179202
let mut new = *self;
@@ -432,3 +455,25 @@ godot_test!(
432455
test_transform2d_behavior_impl()
433456
}
434457
);
458+
459+
#[test]
460+
fn test_transform2d_constructor() {
461+
use std::f32::consts::PI;
462+
463+
let scale = Vector2::new(2.0, 0.5);
464+
let rotation = PI / 4.0;
465+
let origin = Vector2::new(250.0, 150.0);
466+
467+
let tr = Transform2D::from_scale_rotation_origin(scale, rotation, origin);
468+
469+
assert_eq!(tr.origin, origin);
470+
471+
let actual_local_right = tr.basis_xform(Vector2::RIGHT);
472+
let expected_local_right = Vector2::RIGHT.rotated(-rotation) * scale;
473+
assert!(
474+
actual_local_right.is_equal_approx(expected_local_right),
475+
"{:?} != {:?}",
476+
actual_local_right,
477+
expected_local_right
478+
);
479+
}

gdnative-core/src/core_types/vector2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl Vector2 {
251251
#[inline]
252252
pub fn rotated(self, angle: f32) -> Self {
253253
let (cos, sin) = (angle.cos(), angle.sin());
254-
Self::new(cos * self.x + sin * self.y, sin * self.x + cos * self.y)
254+
Self::new(cos * self.x - sin * self.y, sin * self.x + cos * self.y)
255255
}
256256

257257
/// Returns the vector with all components rounded to the nearest integer, with halfway cases

gdnative-core/src/macros.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ macro_rules! godot_test_impl {
245245
).is_ok();
246246

247247
if !ok {
248-
$crate::godot_error!(" !! Test {} failed", str_name);
248+
if ::std::panic::catch_unwind(|| {
249+
$crate::godot_error!(" !! Test {} failed", str_name);
250+
}).is_err() {
251+
eprintln!(" !! Test {} failed", str_name);
252+
eprintln!(" !! And failed to call Godot API to log error message");
253+
}
249254
}
250255

251256
ok

gdnative-core/src/private.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,44 @@ unsafe fn check_api_compatibility(
8080
/// Returns a reference to the current API struct.
8181
///
8282
/// This function is intended to be part of the internal API. It should only be called after
83-
/// `gdnative_init` and before `gdnative_terminate`. **Calling this function when the API is
84-
/// not bound will lead to an abort**, since in most cases there is simply no point to continue
85-
/// if `get_api` failed. This allows it to be used in FFI contexts without a `catch_unwind`.
83+
/// `gdnative_init` and before `gdnative_terminate`.
84+
///
85+
/// # Panics
86+
///
87+
/// **Calling this function when the API is not bound will panic**. Note that it will abort
88+
/// directly during tests (i.e. in unit testing or enable `feature = gd-test`). Since in
89+
/// most cases there is simply no point to continue if `get_api` failed. This allows it to
90+
/// be used in FFI contexts without a `catch_unwind`. (Unwinding across FFI boundary is an
91+
/// undefined behavior.)
92+
///
93+
/// In testing environment, this function use `Option::expect` because unwinding in this
94+
/// scenario should be safe.
95+
///
96+
/// See more: https://github.com/godot-rust/godot-rust/pull/929
8697
#[inline]
87-
#[allow(clippy::redundant_closure)] // clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7812
8898
pub fn get_api() -> &'static sys::GodotApi {
89-
unsafe { GODOT_API.as_ref().unwrap_or_else(|| std::process::abort()) }
99+
const ERR_MSG: &str = "
100+
This code requires the Godot engine to be running and the GDNative initialization \
101+
to have completed. It cannot execute as a standalone Rust program.
102+
103+
Hint: If you encounter this issue during unit testing, you might \
104+
need to use the godot_test! macro, and invoke the test functions in test/src/lib.rs.
105+
";
106+
107+
// Unwinding during tests should be safe and provide more ergonomic UI.
108+
#[cfg(any(test, feature = "gd-test"))]
109+
unsafe {
110+
return GODOT_API.as_ref().expect(ERR_MSG);
111+
}
112+
113+
// Abort directly to avoid undefined behaviors.
114+
#[cfg(not(any(test, feature = "gd-test")))]
115+
unsafe {
116+
return GODOT_API.as_ref().unwrap_or_else(|| {
117+
eprintln!("{}", ERR_MSG);
118+
std::process::abort();
119+
});
120+
}
90121
}
91122

92123
/// Returns a reference to the current API struct if it is bounds, or `None` otherwise.

0 commit comments

Comments
 (0)