Skip to content

Commit 341bc96

Browse files
committed
Add support for precision=double
add transform2d/3d-itests back Add --double to check.sh Make check.sh run in the stable toolchain, since that's what the CI does
1 parent 7d42ebb commit 341bc96

28 files changed

+740
-386
lines changed

.github/workflows/full-ci.yml

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,20 @@ jobs:
4444

4545

4646
clippy:
47+
name: clippy (${{ matrix.name }})
4748
runs-on: ubuntu-20.04
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
include:
53+
- name: linux
54+
rust-toolchain: stable
55+
godot-binary: godot.linuxbsd.editor.dev.x86_64
56+
57+
- name: linux-double
58+
rust-toolchain: stable
59+
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
60+
rust-extra-args: --features double-precision
4861
steps:
4962
- uses: actions/checkout@v3
5063

@@ -56,13 +69,14 @@ jobs:
5669
- name: "Install Godot"
5770
uses: ./.github/composite/godot-install
5871
with:
59-
artifact-name: godot-linux
60-
godot-binary: godot.linuxbsd.editor.dev.x86_64
72+
artifact-name: godot-${{ matrix.name }}
73+
godot-binary: ${{ matrix.godot-binary }}
6174

6275
- name: "Check clippy"
6376
run: |
64-
cargo clippy --all-targets $GDEXT_FEATURES -- -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \
65-
-D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings
77+
cargo clippy --all-targets $GDEXT_FEATURES ${{ matrix.rust-extra-args }} -- \
78+
-D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \
79+
-D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings
6680
6781
6882
unit-test:
@@ -80,12 +94,24 @@ jobs:
8094
os: macos-11
8195
rust-toolchain: stable
8296
godot-binary: godot.macos.editor.dev.x86_64
97+
with-llvm: true
98+
99+
- name: macos-double
100+
os: macos-11
101+
rust-toolchain: stable
102+
godot-binary: godot.macos.editor.dev.double.x86_64
103+
with-llvm: true
83104

84105
- name: windows
85106
os: windows-latest
86107
rust-toolchain: stable-x86_64-pc-windows-msvc
87108
godot-binary: godot.windows.editor.dev.x86_64.exe
88109

110+
- name: windows-double
111+
os: windows-latest
112+
rust-toolchain: stable-x86_64-pc-windows-msvc
113+
godot-binary: godot.windows.editor.dev.double.x86_64.exe
114+
89115
# Don't use latest Ubuntu (22.04) as it breaks lots of ecosystem compatibility.
90116
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
91117
- name: linux
@@ -98,6 +124,12 @@ jobs:
98124
rust-toolchain: stable
99125
rust-special: -minimal-deps
100126
godot-binary: godot.linuxbsd.editor.dev.x86_64
127+
128+
- name: linux-double
129+
os: ubuntu-20.04
130+
rust-toolchain: stable
131+
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
132+
rust-extra-args: --features double-precision
101133

102134
steps:
103135
- uses: actions/checkout@v3
@@ -107,7 +139,7 @@ jobs:
107139
with:
108140
rust: stable
109141
cache-key: ${{ matrix.rust-special }} # 'minimal-deps' or empty/not defined
110-
with-llvm: ${{ matrix.name == 'macos' }}
142+
with-llvm: ${{ matrix.with-llvm }}
111143

112144
- name: "Install Rust nightly (minimal deps)"
113145
uses: ./.github/composite/rust
@@ -129,10 +161,10 @@ jobs:
129161
godot-binary: ${{ matrix.godot-binary }}
130162

131163
- name: "Compile tests"
132-
run: cargo test $GDEXT_FEATURES --no-run
164+
run: cargo test $GDEXT_FEATURES --no-run ${{ matrix.rust-extra-args }}
133165

134166
- name: "Test"
135-
run: cargo test $GDEXT_FEATURES
167+
run: cargo test $GDEXT_FEATURES ${{ matrix.rust-extra-args }}
136168

137169

138170
godot-itest:
@@ -151,12 +183,26 @@ jobs:
151183
os: macos-12
152184
rust-toolchain: stable
153185
godot-binary: godot.macos.editor.dev.x86_64
186+
with-llvm: true
187+
188+
- name: macos-double
189+
os: macos-12
190+
rust-toolchain: stable
191+
godot-binary: godot.macos.editor.dev.double.x86_64
192+
rust-extra-args: --features double-precision
193+
with-llvm: true
154194

155195
- name: windows
156196
os: windows-latest
157197
rust-toolchain: stable-x86_64-pc-windows-msvc
158198
godot-binary: godot.windows.editor.dev.x86_64.exe
159199

200+
- name: windows-double
201+
os: windows-latest
202+
rust-toolchain: stable-x86_64-pc-windows-msvc
203+
godot-binary: godot.windows.editor.dev.double.x86_64.exe
204+
rust-extra-args: --features double-precision
205+
160206
# Don't use latest Ubuntu (22.04) as it breaks lots of ecosystem compatibility.
161207
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
162208
- name: linux
@@ -182,6 +228,12 @@ jobs:
182228
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
183229
godot-args: -- --disallow-focus
184230

231+
- name: linux-double
232+
os: ubuntu-20.04
233+
rust-toolchain: stable
234+
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
235+
rust-extra-args: --features double-precision
236+
185237
steps:
186238
- uses: actions/checkout@v3
187239

@@ -191,7 +243,8 @@ jobs:
191243
artifact-name: godot-${{ matrix.name }}
192244
godot-binary: ${{ matrix.godot-binary }}
193245
godot-args: ${{ matrix.godot-args }}
194-
with-llvm: ${{ matrix.name == 'macos' }}
246+
with-llvm: ${{ matrix.with-llvm }}
247+
rust-extra-args: ${{ matrix.rust-extra-args }}
195248

196249

197250
license-guard:

.github/workflows/minimal-ci.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,20 @@ jobs:
4444

4545

4646
clippy:
47+
name: clippy (${{ matrix.name }})
4748
runs-on: ubuntu-20.04
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
include:
53+
- name: linux
54+
rust-toolchain: stable
55+
godot-binary: godot.linuxbsd.editor.dev.x86_64
56+
57+
- name: linux-double
58+
rust-toolchain: stable
59+
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
60+
rust-extra-args: --features double-precision
4861
steps:
4962
- uses: actions/checkout@v3
5063

@@ -56,12 +69,13 @@ jobs:
5669
- name: "Install Godot"
5770
uses: ./.github/composite/godot-install
5871
with:
59-
artifact-name: godot-linux
60-
godot-binary: godot.linuxbsd.editor.dev.x86_64
72+
artifact-name: godot-${{ matrix.name }}
73+
godot-binary: ${{ matrix.godot-binary }}
6174

6275
- name: "Check clippy"
6376
run: |
64-
cargo clippy --all-targets $GDEXT_FEATURES -- -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \
77+
cargo clippy --all-targets $GDEXT_FEATURES ${{ matrix.rust-extra-args }} -- \
78+
-D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \
6579
-D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings
6680
6781

Contributing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,16 @@ $ cargo fmt
6060
$ check.sh clippy
6161
```
6262

63+
## Real
64+
65+
Certain types in Godot use either a single or double-precision float internally, such as `Vector2`. When using these types we
66+
use the `real` type instead of choosing either `f32` or `f64`. Thus our code is portable between Godot binaries compiled with
67+
`precision=single` or `precision=double`.
68+
69+
To run the testing suite with `double-precision` enabled you may add `--double` to a `check.sh` invocation:
70+
```
71+
$ check.sh --double
72+
```
73+
6374
[GitHub issue]: https://github.com/godot-rust/gdextension/issues
6475
[Discord]: https://discord.gg/aKUCJ8rJsc

check.sh

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
# Note: at the moment, there is a lot of useless recompilation.
1010
# This should be better once unit tests and #[cfg] are sorted out.
1111

12-
# No args specified: do everything
13-
if [ "$#" -eq 0 ]; then
14-
args=("fmt" "clippy" "test" "itest")
15-
else
16-
args=("$@")
17-
fi
18-
1912
# --help menu
20-
for arg in "${args[@]}"; do
13+
for arg in $@; do
2114
if [ "$arg" == "--help" ]; then
22-
echo "Usage: check.sh [<commands>]"
15+
echo "Usage: check.sh [--double] [<commands>]"
2316
echo ""
2417
echo "Each specified command will be run (until one fails)."
2518
echo "If no commands are specified, all checks are run (no doc; may take several minutes)."
@@ -32,13 +25,37 @@ for arg in "${args[@]}"; do
3225
echo " doc generate docs for 'godot' crate"
3326
echo " dok generate docs and open in browser"
3427
echo ""
28+
echo "Options:"
29+
echo " --double run check with double-precision"
30+
echo ""
3531
echo "Examples:"
3632
echo " check.sh fmt clippy"
3733
echo " check.sh"
34+
echo " check.sh --double clippy"
3835
exit 0
3936
fi
4037
done
4138

39+
firstArg=1
40+
toolchain=""
41+
extraArgs=()
42+
43+
if [[ "$1" == "--double" ]]; then
44+
firstArg=2
45+
extraArgs+=("--features double-precision")
46+
fi
47+
48+
args=()
49+
50+
for arg in "${@:$firstArg}"; do
51+
args+=("$arg")
52+
done
53+
54+
# No args specified: do everything
55+
if [ ${#args[@]} -eq 0 ]; then
56+
args=("fmt" "clippy" "test" "itest")
57+
fi
58+
4259
# For integration tests
4360
function findGodot() {
4461
# User-defined GODOT4_BIN
@@ -67,32 +84,31 @@ function findGodot() {
6784
fi
6885
}
6986

70-
#features="--features crate/feature"
71-
features=""
7287
cmds=()
88+
extraArgs="${extraArgs[@]}"
7389

7490
for arg in "${args[@]}"; do
7591
case "$arg" in
7692
fmt)
77-
cmds+=("cargo fmt --all -- --check")
93+
cmds+=("cargo $toolchain fmt --all -- --check")
7894
;;
7995
clippy)
80-
cmds+=("cargo clippy $features -- -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings")
96+
cmds+=("cargo $toolchain clippy $extraArgs -- -D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings")
8197
;;
8298
test)
83-
cmds+=("cargo test $features")
99+
cmds+=("cargo $toolchain test $extraArgs")
84100
;;
85101
itest)
86102
findGodot
87103

88-
cmds+=("cargo build -p itest")
104+
cmds+=("cargo $toolchain build -p itest $extraArgs")
89105
cmds+=("$godotBin --path itest/godot --headless")
90106
;;
91107
doc)
92-
cmds+=("cargo doc --lib -p godot --no-deps $features")
108+
cmds+=("cargo $toolchain doc --lib -p godot --no-deps $extraArgs")
93109
;;
94110
dok)
95-
cmds+=("cargo doc --lib -p godot --no-deps $features --open")
111+
cmds+=("cargo $toolchain doc --lib -p godot --no-deps $extraArgs --open")
96112
;;
97113
*)
98114
echo "Unrecognized command '$arg'"

examples/dodge-the-creeps/rust/src/main_scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Main {
104104
let range = rng.gen_range(mob.min_speed..mob.max_speed);
105105

106106
mob.set_linear_velocity(Vector2::new(range, 0.0));
107-
let lin_vel = mob.get_linear_velocity().rotated(direction as f32);
107+
let lin_vel = mob.get_linear_velocity().rotated(real::from_f64(direction));
108108
mob.set_linear_velocity(lin_vel);
109109
}
110110

examples/dodge-the-creeps/rust/src/mob.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const MOB_TYPES: [MobType; 3] = [MobType::Walk, MobType::Swim, MobType::Fly];
2626
#[derive(GodotClass)]
2727
#[class(base=RigidBody2D)]
2828
pub struct Mob {
29-
pub min_speed: f32,
30-
pub max_speed: f32,
29+
pub min_speed: real,
30+
pub max_speed: real,
3131

3232
#[base]
3333
base: Base<RigidBody2D>,

examples/dodge-the-creeps/rust/src/player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use godot::prelude::*;
44
#[derive(GodotClass)]
55
#[class(base=Area2D)]
66
pub struct Player {
7-
speed: f32,
7+
speed: real,
88
screen_size: Vector2,
99

1010
#[base]
@@ -100,7 +100,7 @@ impl GodotExt for Player {
100100
animated_sprite.stop();
101101
}
102102

103-
let change = velocity * delta as f32;
103+
let change = velocity * real::from_f64(delta);
104104
let position = self.base.get_global_position() + change;
105105
let position = Vector2::new(
106106
position.x.clamp(0.0, self.screen_size.x),

godot-codegen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ categories = ["game-engines", "graphics"]
1010
[features]
1111
codegen-fmt = []
1212
codegen-full = []
13+
double-precision = []
1314

1415
[dependencies]
1516
quote = "1"

godot-codegen/src/api_parser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ pub fn load_extension_api(watch: &mut StopWatch) -> (ExtensionApi, &'static str)
222222
// For float/double inference, see:
223223
// * https://github.com/godotengine/godot-proposals/issues/892
224224
// * https://github.com/godotengine/godot-cpp/pull/728
225+
#[cfg(feature = "double-precision")]
226+
let build_config = "double_64"; // TODO infer this
227+
#[cfg(not(feature = "double-precision"))]
225228
let build_config = "float_64"; // TODO infer this
226229

227230
let json: String = godot_exe::load_extension_api_json(watch);

godot-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ default = []
1212
trace = []
1313
codegen-fmt = ["godot-ffi/codegen-fmt"]
1414
codegen-full = ["godot-codegen/codegen-full"]
15+
double-precision = ["godot-codegen/double-precision"]
1516

1617
[dependencies]
1718
godot-ffi = { path = "../godot-ffi" }

0 commit comments

Comments
 (0)