Skip to content

Commit

Permalink
Fix a lot of capitalized reals, and rename precision-double to double…
Browse files Browse the repository at this point in the history
…-precision
  • Loading branch information
lilizoey committed Mar 6, 2023
1 parent bc189f8 commit 8cffe7f
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 96 deletions.
20 changes: 5 additions & 15 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: linux-double
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features precision-double
rust-extra-args: --features double-precision
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -106,21 +106,18 @@ jobs:
os: windows-latest
rust-toolchain: stable-x86_64-pc-windows-msvc
godot-binary: godot.windows.editor.dev.x86_64.exe
with-llvm: false

- name: windows-double
os: windows-latest
rust-toolchain: stable-x86_64-pc-windows-msvc
godot-binary: godot.windows.editor.dev.double.x86_64.exe
with-llvm: false

# Don't use latest Ubuntu (22.04) as it breaks lots of ecosystem compatibility.
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
- name: linux
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.x86_64
with-llvm: false

- name: linux
os: ubuntu-20.04
Expand All @@ -133,8 +130,7 @@ jobs:
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features precision-double
with-llvm: false
rust-extra-args: --features double-precision

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -194,29 +190,26 @@ jobs:
os: macos-12
rust-toolchain: stable
godot-binary: godot.macos.editor.dev.double.x86_64
rust-extra-args: --features precision-double
rust-extra-args: --features double-precision
with-llvm: true

- name: windows
os: windows-latest
rust-toolchain: stable-x86_64-pc-windows-msvc
godot-binary: godot.windows.editor.dev.x86_64.exe
with-llvm: false

- name: windows-double
os: windows-latest
rust-toolchain: stable-x86_64-pc-windows-msvc
godot-binary: godot.windows.editor.dev.double.x86_64.exe
rust-extra-args: --features precision-double
with-llvm: false
rust-extra-args: --features double-precision

# Don't use latest Ubuntu (22.04) as it breaks lots of ecosystem compatibility.
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
- name: linux
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.x86_64
with-llvm: false

# Special Godot binaries compiled with AddressSanitizer/LeakSanitizer to detect UB/leaks.
# Additionally, the Godot source is patched to make dlclose() a no-op, as unloading dynamic libraries loses stacktrace and
Expand All @@ -226,20 +219,17 @@ jobs:
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.x86_64.san
with-llvm: false

- name: linux-memcheck-clang
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
with-llvm: false

- name: linux-double
os: ubuntu-20.04
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features precision-double
with-llvm: false
rust-extra-args: --features double-precision

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/minimal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: linux-double
rust-toolchain: stable
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features precision-double
rust-extra-args: --features double-precision
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ Certain types in Godot use either a single or double-precision float internally,
use the `real` type instead of choosing either `f32` or `f64`. Thus our code is portable between Godot binaries compiled with
`precision=single` or `precision=double`.

To run the testing suite with `precision-double` enabled you may add `--features precision-double` to a `check.sh` invocation:
To run the testing suite with `double-precision` enabled you may add `--features double-precision` to a `check.sh` invocation:
```
$ check.sh --features precision-double
$ check.sh --features double-precision
```

[GitHub issue]: https://github.com/godot-rust/gdextension/issues
Expand Down
2 changes: 1 addition & 1 deletion check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for arg in $@; do
echo "Examples:"
echo " check.sh fmt clippy"
echo " check.sh"
echo " check.sh --features precision-double clippy"
echo " check.sh --features double-precision clippy"
exit 0
fi
done
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["game-engines", "graphics"]
[features]
codegen-fmt = []
codegen-full = []
precision-double = []
double-precision = []

[dependencies]
quote = "1"
Expand Down
4 changes: 2 additions & 2 deletions godot-codegen/src/api_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ pub fn load_extension_api(watch: &mut StopWatch) -> (ExtensionApi, &'static str)
// For float/double inference, see:
// * https://github.com/godotengine/godot-proposals/issues/892
// * https://github.com/godotengine/godot-cpp/pull/728
#[cfg(feature = "precision-double")]
#[cfg(feature = "double-precision")]
let build_config = "double_64"; // TODO infer this
#[cfg(not(feature = "precision-double"))]
#[cfg(not(feature = "double-precision"))]
let build_config = "float_64"; // TODO infer this

let json: String = godot_exe::load_extension_api_json(watch);
Expand Down
2 changes: 1 addition & 1 deletion godot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default = []
trace = []
codegen-fmt = ["godot-ffi/codegen-fmt"]
codegen-full = ["godot-codegen/codegen-full"]
precision-double = ["godot-codegen/precision-double"]
double-precision = ["godot-codegen/double-precision"]

[dependencies]
godot-ffi = { path = "../godot-ffi" }
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl GlamType for RMat3 {
}
}

#[cfg(not(feature = "precision-double"))]
#[cfg(not(feature = "double-precision"))]
impl GlamType for glam::Mat3A {
type Mapped = Basis;

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/glam_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// Nice:
// self.glam2(&with, |a, b| a.dot(b))
// self.glam2(&with, glam::Real::Quat::dot)
// self.glam2(&with, glam::f32::Quat::dot)
//
// Alternative with only conversions:
// self.glam().dot(b.glam())
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ mod test {
#[test]
fn lerp_angle_test() {
assert_eq_approx!(lerp_angle(0.0, PI, 0.5), -FRAC_PI_2, is_angle_equal_approx);
#[cfg(not(feature = "precision-double"))]
#[cfg(not(feature = "double-precision"))]
assert_eq_approx!(
lerp_angle(0.0, PI + 3.0 * TAU, 0.5),
FRAC_PI_2,
is_angle_equal_approx
);
#[cfg(feature = "precision-double")]
#[cfg(feature = "double-precision")]
assert_eq_approx!(
lerp_angle(0.0, PI + 3.0 * TAU, 0.5),
-FRAC_PI_2,
Expand Down
77 changes: 28 additions & 49 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ pub(crate) fn u8_to_bool(u: u8) -> bool {
}
}

/// Clippy often complains if you do `f as f64` when `f` is already an `f64`.
/// This trait exists to make it easy to convert between the different reals
/// and floats without a lot of allowing clippy lints for your code.
/// Clippy often complains if you do `f as f64` when `f` is already an `f64`. This trait exists to make it easy to
/// convert between the different reals and floats without a lot of allowing clippy lints for your code.
pub trait RealConv {
/// Cast this [`real`] to an [`f32`] using `as`.
// Clippy complains that this is an `as_*` function but it takes a `self`
Expand All @@ -154,16 +153,15 @@ pub trait RealConv {
fn from_f64(f: f64) -> Self;
}

#[cfg(not(feature = "precision-double"))]
#[cfg(not(feature = "double-precision"))]
mod real_mod {
//! Definitions for single-precision `real`.
/// Floating point type used for many structs and functions in Godot.
///
/// This is not the `float` type in gdscript, that type is always 64-bits.
/// Rather, many structs in Godot may use either 32-bit or 64-bit floats
/// such as [`Vector2`](super::Vector2). To convert between [`real`] and
/// [`f32`] or [`f64`] see [`RealConv`](super::RealConv).
/// This is not the `float` type in GDScript; that type is always 64-bits. Rather, many structs in Godot may use
/// either 32-bit or 64-bit floats such as [`Vector2`](super::Vector2). To convert between [`real`] and [`f32`] or
/// [`f64`] see [`RealConv`](super::RealConv).
///
/// See also the [Godot docs on float](https://docs.godotengine.org/en/stable/classes/class_float.html).
///
Expand Down Expand Up @@ -196,48 +194,38 @@ mod real_mod {

pub use std::f32::consts;

/// A glam [`Vec2`](glam::Vec2) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec2`](glam::Vec2) with floating-point format compatible with [`real`].
pub use glam::Vec2 as RVec2;
/// A glam [`Vec3`](glam::Vec3) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec3`](glam::Vec3) with floating-point format compatible with [`real`].
pub use glam::Vec3 as RVec3;
/// A glam [`Vec4`](glam::Vec4) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec4`](glam::Vec4) with floating-point format compatible with [`real`].
pub use glam::Vec4 as RVec4;

/// A glam [`Mat2`](glam::Mat2) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat2`](glam::Mat2) with floating-point format compatible with [`real`].
pub use glam::Mat2 as RMat2;
/// A glam [`Mat3`](glam::Mat3) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat3`](glam::Mat3) with floating-point format compatible with [`real`].
pub use glam::Mat3 as RMat3;
/// A glam [`Mat4`](glam::Mat4) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat4`](glam::Mat4) with floating-point format compatible with [`real`].
pub use glam::Mat4 as RMat4;

/// A glam [`Quat`](glam::Quat) with floating-point format compatible
/// with [`real`].
/// A glam [`Quat`](glam::Quat) with floating-point format compatible with [`real`].
pub use glam::Quat as RQuat;

/// A glam [`Affine2`](glam::Affine2) with floating-point format
/// compatible with [`real`].
/// A glam [`Affine2`](glam::Affine2) with floating-point format compatible with [`real`].
pub use glam::Affine2 as RAffine2;
/// A glam [`Affine3`](glam::Affine3A) with floating-point format
/// compatible with [`real`].
/// A glam [`Affine3`](glam::Affine3A) with floating-point format compatible with [`real`].
pub use glam::Affine3A as RAffine3;
}

#[cfg(feature = "precision-double")]
#[cfg(feature = "double-precision")]
mod real_mod {
//! Definitions for double-precision `real`.
/// Floating point type used for many structs and functions in Godot.
///
/// This is not the `float` type in gdscript, that type is always 64-bits.
/// Rather, many structs in Godot may use either 32-bit or 64-bit floats
/// such as [`Vector2`](super::Vector2). To convert between [`real`] and
/// [`f32`] or [`f64`] see [`RealConv`](super::RealConv).
/// This is not the `float` type in GDScript; that type is always 64-bits. Rather, many structs in Godot may use
/// either 32-bit or 64-bit floats such as [`Vector2`](super::Vector2). To convert between [`real`] and [`f32`] or
/// [`f64`] see [`RealConv`](super::RealConv).
///
/// See also the [Godot docs on float](https://docs.godotengine.org/en/stable/classes/class_float.html).
///
Expand Down Expand Up @@ -270,35 +258,26 @@ mod real_mod {

pub use std::f64::consts;

/// A glam [`Vec2`](glam::DVec2) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec2`](glam::DVec2) with floating-point format compatible with [`real`].
pub use glam::DVec2 as RVec2;
/// A glam [`Vec3`](glam::DVec3) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec3`](glam::DVec3) with floating-point format compatible with [`real`].
pub use glam::DVec3 as RVec3;
/// A glam [`Vec4`](glam::DVec4) with floating-point format compatible
/// with [`real`].
/// A glam [`Vec4`](glam::DVec4) with floating-point format compatible with [`real`].
pub use glam::DVec4 as RVec4;

/// A glam [`Mat2`](glam::DMat2) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat2`](glam::DMat2) with floating-point format compatible with [`real`].
pub use glam::DMat2 as RMat2;
/// A glam [`Mat3`](glam::DMat3) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat3`](glam::DMat3) with floating-point format compatible with [`real`].
pub use glam::DMat3 as RMat3;
/// A glam [`Mat4`](glam::DMat4) with floating-point format compatible
/// with [`real`].
/// A glam [`Mat4`](glam::DMat4) with floating-point format compatible with [`real`].
pub use glam::DMat4 as RMat4;

/// A glam [`Quat`](glam::DQuat) with floating-point format compatible
/// with [`real`].
/// A glam [`Quat`](glam::DQuat) with floating-point format compatible with [`real`].
pub use glam::DQuat as RQuat;

/// A glam [`Affine2`](glam::DAffine2) with floating-point format
/// compatible with [`real`].
/// A glam [`Affine2`](glam::DAffine2) with floating-point format compatible with [`real`].
pub use glam::DAffine2 as RAffine2;
/// A glam [`Affine3`](glam::DAffine3) with floating-point format
/// compatible with [`real`].
/// A glam [`Affine3`](glam::DAffine3) with floating-point format compatible with [`real`].
pub use glam::DAffine3 as RAffine3;
}

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Projection {
///
/// _Godot equivalent: Projection.get_fov()_
pub fn fov(&self) -> real {
self.as_inner().get_fov() as real
real::from_f64(self.as_inner().get_fov())
}

/// Returns the vertical field of view of a projection (in degrees) which
Expand Down
10 changes: 5 additions & 5 deletions godot-core/src/builtin/quaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ impl Quaternion {
inv_factor * self + new_factor * to
}

// pub fn spherical_cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, weight: Real) -> Self {}
// pub fn spherical_cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, weight: real) -> Self {}
// TODO: Implement godot's function in rust
/*
pub fn spherical_cubic_interpolate_in_time(
self,
b: Self,
pre_a: Self,
post_b: Self,
weight: Real,
b_t: Real,
pre_a_t: Real,
post_b_t: Real,
weight: real,
b_t: real,
pre_a_t: real,
post_b_t: real,
) -> Self {
}
*/
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/transform3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl GlamType for RAffine3 {
Transform3D::new(self.matrix3.to_front(), self.translation.to_front())
}

// When `precision-double` is enabled this will complain. But it is
// When `double-precision` is enabled this will complain. But it is
// needed for when it is not enabled.
#[allow(clippy::useless_conversion)]
fn from_front(mapped: &Self::Mapped) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/vector2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Vector2 {
/// Vector with all components set to `1.0`.
pub const ONE: Self = Self::splat(1.0);

/// Vector with all components set to `Real::INFINITY`.
/// Vector with all components set to `real::INFINITY`.
pub const INF: Self = Self::splat(real::INFINITY);

/// Unit vector in -X direction (right in 2D coordinate system).
Expand Down Expand Up @@ -305,7 +305,7 @@ impl fmt::Display for Vector2 {
}
}

impl_common_vector_fns!(Vector2, Real);
impl_common_vector_fns!(Vector2, real);
impl_float_vector_fns!(Vector2, real);
impl_vector_operators!(Vector2, real, (x, y));
impl_vector_index!(Vector2, real, (x, y), Vector2Axis, (X, Y));
Expand Down
Loading

0 comments on commit 8cffe7f

Please sign in to comment.