diff --git a/.cargo/config.nothreads.toml b/.cargo/config.nothreads.toml index 7a4d27d8..4b731dee 100644 --- a/.cargo/config.nothreads.toml +++ b/.cargo/config.nothreads.toml @@ -21,4 +21,4 @@ linker = "aarch64-linux-android23-clang" [target.x86_64-linux-android] linker = "x86_64-linux-android23-clang" [target.i686-linux-android] -linker = "i686-linux-android23-clang" \ No newline at end of file +linker = "i686-linux-android23-clang" diff --git a/.cargo/config.toml b/.cargo/config.toml index c9bf7ae7..01eb522c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,20 +1,15 @@ [target.wasm32-unknown-emscripten] rustflags = [ - "-C", - "link-args=-sSIDE_MODULE=2", - "-C", - "link-args=-pthread", - "-C", - "target-feature=+atomics,+bulk-memory,+mutable-globals", - "-Clink-args=-sEXPORT_ALL=1", - "-Clink-arg=-fwasm-exceptions", - "-C", - "link-args=-sSUPPORT_LONGJMP=wasm", - "-Cllvm-args=-enable-emscripten-cxx-exceptions=0", - "-Cllvm-args=-wasm-enable-sjlj", - "-C", - "link-args=-sDISABLE_EXCEPTION_CATCHING=1", - "-Zlink-native-libraries=no", + "-C", "link-args=-sSIDE_MODULE=2", + "-C", "link-args=-pthread", + "-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", + "-C", "link-args=-sEXPORT_ALL=1", + "-C", "link-arg=-fwasm-exceptions", + "-C", "link-args=-sSUPPORT_LONGJMP=wasm", + "-C", "llvm-args=-enable-emscripten-cxx-exceptions=0", + "-C", "llvm-args=-wasm-enable-sjlj", + "-C", "link-args=-sDISABLE_EXCEPTION_CATCHING=1", + "-Z", "link-native-libraries=no", ] [target.armv7-linux-androideabi] linker = "armv7a-linux-androideabi23-clang" @@ -23,4 +18,4 @@ linker = "aarch64-linux-android23-clang" [target.x86_64-linux-android] linker = "x86_64-linux-android23-clang" [target.i686-linux-android] -linker = "i686-linux-android23-clang" \ No newline at end of file +linker = "i686-linux-android23-clang" diff --git a/.github/workflows/android_builds.yml b/.github/workflows/android_builds.yml index 39891916..67d0da8f 100644 --- a/.github/workflows/android_builds.yml +++ b/.github/workflows/android_builds.yml @@ -11,7 +11,7 @@ jobs: matrix: # disabled_arch: ["armv7-linux-androideabi"] arch: ["x86_64-linux-android", "aarch64-linux-android", "i686-linux-android"] - precision: [single] + precision: [single] #, double] dimensions: [{"feature": "dim2", "short": "2d"}, {"feature": "dim3", "short": "3d"}] features: [{"feature":"simd-stable,serde-serialize,experimental-threads", "name": "simd-parallel"}, {"feature":"enhanced-determinism,serde-serialize,experimental-threads", "name": "enhanced-determinism"}] diff --git a/.github/workflows/godot_builds.yml b/.github/workflows/godot_builds.yml index 0addf928..95222c26 100644 --- a/.github/workflows/godot_builds.yml +++ b/.github/workflows/godot_builds.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - precision: [single] + precision: [single] #, double] dimensions: ["2d", "3d"] features: ["simd-parallel", "enhanced-determinism"] diff --git a/.github/workflows/ios_builds.yml b/.github/workflows/ios_builds.yml index 9b342a82..3c6e3dc1 100644 --- a/.github/workflows/ios_builds.yml +++ b/.github/workflows/ios_builds.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: arch: ["aarch64-apple-ios"] - precision: [single] + precision: [single] #, double] dimensions: [{"feature": "dim2", "short": "2d"}, {"feature": "dim3", "short": "3d"}] features: [{"feature":"simd-stable,serde-serialize,experimental-threads", "name": "simd-parallel"}, {"feature":"enhanced-determinism,serde-serialize,experimental-threads", "name": "enhanced-determinism"}] diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index 8671feeb..112a90d2 100644 --- a/.github/workflows/linux_builds.yml +++ b/.github/workflows/linux_builds.yml @@ -11,7 +11,7 @@ jobs: matrix: #arch: ["i686-unknown-linux-gnu", "aarch64-unknown-linux-gnu"] arch: ["x86_64-unknown-linux-gnu"] - precision: [single] + precision: [single] #, double] dimensions: [{"feature": "dim2", "short": "2d"}, {"feature": "dim3", "short": "3d"}] features: [{"feature":"simd-stable,serde-serialize,experimental-threads", "name": "simd-parallel"}, {"feature":"enhanced-determinism,serde-serialize,experimental-threads", "name": "enhanced-determinism"}] diff --git a/.github/workflows/macos_builds.yml b/.github/workflows/macos_builds.yml index cd9a9b0e..d77ace53 100644 --- a/.github/workflows/macos_builds.yml +++ b/.github/workflows/macos_builds.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: arch: ["x86_64-apple-darwin"] - precision: [single] + precision: [single] #, double] dimensions: [{"feature": "dim2", "short": "2d"}, {"feature": "dim3", "short": "3d"}] features: [{"feature":"simd-stable,serde-serialize,experimental-threads", "name": "simd-parallel"}, {"feature":"enhanced-determinism,serde-serialize,experimental-threads", "name": "enhanced-determinism"}] diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 0b6e2909..424792e3 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -32,6 +32,7 @@ jobs: shell: sh run: | cargo clippy --all-targets --features="build3d" --no-default-features -- -D warnings + gdlint: name: GDLint runs-on: ubuntu-latest diff --git a/.github/workflows/web_builds.yml b/.github/workflows/web_builds.yml index 7b93fdec..d15ca602 100644 --- a/.github/workflows/web_builds.yml +++ b/.github/workflows/web_builds.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: arch: ["wasm32-unknown-emscripten"] - precision: [single] + precision: [single] #, double] build_param: [ { "feature": "experimental-wasm", "folder": "" }, { "feature": "experimental-wasm,experimental-wasm-nothreads", "folder": "wasm-nothreads" } ] diff --git a/.github/workflows/windows_builds.yml b/.github/workflows/windows_builds.yml index 5d42a5ad..b091fb94 100644 --- a/.github/workflows/windows_builds.yml +++ b/.github/workflows/windows_builds.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: arch: ["x86_64-pc-windows-msvc", "i686-pc-windows-msvc", "aarch64-pc-windows-msvc"] - precision: [single] + precision: [single] #, double] dimensions: [{"feature": "dim2", "short": "2d"}, {"feature": "dim3", "short": "3d"}] features: [{"feature":"simd-stable,serde-serialize,experimental-threads", "name": "simd-parallel"}, {"feature":"enhanced-determinism,serde-serialize,experimental-threads", "name": "enhanced-determinism"}] diff --git a/CHANGELOG.md b/CHANGELOG.md index c30fd85c..040af28f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.8.9 + +- Reduce size of builds + ## v0.8.8 - Fix points getting removed and empty points warning. diff --git a/Cargo.lock b/Cargo.lock index 0a3e8382..793d2cf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,26 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.68.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn", +] + [[package]] name = "bit-vec" version = "0.7.0" @@ -92,12 +112,32 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "crossbeam" version = "0.8.4" @@ -172,6 +212,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "fnv" version = "1.0.7" @@ -221,6 +271,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "godot" version = "0.1.3" @@ -235,7 +291,10 @@ name = "godot-bindings" version = "0.1.3" source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" dependencies = [ + "bindgen", "gdextension-api", + "regex", + "which", ] [[package]] @@ -295,7 +354,7 @@ dependencies = [ [[package]] name = "godot-rapier" -version = "0.8.0" +version = "0.8.9" dependencies = [ "bincode", "godot", @@ -305,7 +364,9 @@ dependencies = [ "rapier3d", "rapier3d-f64", "salva2d", + "salva2d-f64", "salva3d", + "salva3d-f64", "serde", "serde_json", ] @@ -352,6 +413,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + [[package]] name = "indexmap" version = "2.6.0" @@ -387,18 +457,46 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + [[package]] name = "libm" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" version = "0.4.22" @@ -430,6 +528,12 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "nalgebra" version = "0.33.0" @@ -473,6 +577,16 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e943b2c21337b7e3ec6678500687cdc741b7639ad457f234693352075c082204" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -565,7 +679,7 @@ dependencies = [ "num-derive", "num-traits", "ordered-float", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "slab", @@ -590,7 +704,7 @@ dependencies = [ "num-derive", "num-traits", "ordered-float", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "slab", @@ -616,7 +730,7 @@ dependencies = [ "num-traits", "ordered-float", "rstar", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "slab", @@ -642,7 +756,7 @@ dependencies = [ "num-traits", "ordered-float", "rstar", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "slab", @@ -657,6 +771,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "proc-macro2" version = "1.0.87" @@ -693,7 +813,7 @@ dependencies = [ "ordered-float", "parry2d", "rayon", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "thiserror", @@ -718,7 +838,7 @@ dependencies = [ "ordered-float", "parry2d-f64", "rayon", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "thiserror", @@ -743,7 +863,7 @@ dependencies = [ "ordered-float", "parry3d", "rayon", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "thiserror", @@ -768,7 +888,7 @@ dependencies = [ "ordered-float", "parry3d-f64", "rayon", - "rustc-hash", + "rustc-hash 2.0.0", "serde", "simba", "thiserror", @@ -847,12 +967,31 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hash" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.18" @@ -871,7 +1010,7 @@ dependencies = [ [[package]] name = "salva2d" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=use-rapier-master#24267a9c9fa1f3a6281b566db10288b6cf532528" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" dependencies = [ "approx", "fnv", @@ -884,10 +1023,26 @@ dependencies = [ "rapier2d", ] +[[package]] +name = "salva2d-f64" +version = "0.9.0" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +dependencies = [ + "approx", + "fnv", + "generational-arena", + "instant", + "itertools", + "nalgebra", + "num-traits", + "parry2d-f64", + "rapier2d-f64", +] + [[package]] name = "salva3d" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=use-rapier-master#24267a9c9fa1f3a6281b566db10288b6cf532528" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" dependencies = [ "approx", "fnv", @@ -900,6 +1055,22 @@ dependencies = [ "rapier3d", ] +[[package]] +name = "salva3d-f64" +version = "0.9.0" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +dependencies = [ + "approx", + "fnv", + "generational-arena", + "instant", + "itertools", + "nalgebra", + "num-traits", + "parry3d-f64", + "rapier3d-f64", +] + [[package]] name = "serde" version = "1.0.210" @@ -932,6 +1103,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simba" version = "0.9.0" @@ -1065,6 +1242,18 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "which" +version = "6.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", +] + [[package]] name = "wide" version = "0.7.28" @@ -1075,6 +1264,85 @@ dependencies = [ "safe_arch", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index f1724916..419ea8db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "godot-rapier" -version = "0.8.0" +version = "0.8.9" edition = "2021" license = "MIT" rust-version = "1.82" @@ -10,14 +10,16 @@ publish = false crate-type = ["cdylib"] [features] -default = ["build3d", "test"] +default = ["build2d", "test"] test = [] build2d = ["single-dim2", "serde-serialize", "simd-stable"] build3d = ["single-dim3", "serde-serialize", "simd-stable"] +build2d-f64 = ["double-dim2", "serde-serialize", "simd-stable"] +build3d-f64 = ["double-dim3", "serde-serialize", "simd-stable"] dim2 = [] dim3 = [] -single = [] -double = [] +single = ["godot/api-4-3"] +double = ["godot/double-precision", "godot/api-custom"] enhanced-determinism = ["rapier2d/enhanced-determinism", "rapier2d-f64/enhanced-determinism", "rapier3d/enhanced-determinism", "rapier3d-f64/enhanced-determinism"] serde-serialize = ["serde", "hashbrown/serde", "bincode", "serde_json", "godot/serde", "rapier2d/serde-serialize", "rapier2d-f64/serde-serialize", "rapier3d/serde-serialize", "rapier3d-f64/serde-serialize" ] simd-stable = ["rapier2d/simd-stable", "rapier2d-f64/simd-stable", "rapier3d/simd-stable", "rapier3d-f64/simd-stable"] @@ -27,23 +29,25 @@ experimental-wasm-nothreads = ["godot/experimental-wasm-nothreads", "godot/lazy- experimental-wasm = ["godot/experimental-wasm", "godot/lazy-function-tables"] experimental-threads = ["godot/experimental-threads"] single-dim2 = ["single", "dim2", "rapier2d", "salva2d"] -double-dim2 = ["double", "dim2", "rapier2d-f64", "salva2d"] +double-dim2 = ["double", "dim2", "rapier2d-f64", "salva2d-f64"] single-dim3 = ["single", "dim3", "rapier3d", "salva3d"] -double-dim3 = ["double", "dim3", "rapier3d-f64", "salva3d"] +double-dim3 = ["double", "dim3", "rapier3d-f64", "salva3d-f64"] [dependencies] bincode = { version = "1", optional = true } hashbrown = { version = "0.14" } #godot = { git = "https://github.com/Ughuuu/gdext", branch = "remove-hook", features=["api-4-3", "register-docs", "experimental-threads"] } -godot = { git = "https://github.com/godot-rust/gdext", branch = "master", features=["api-4-3", "register-docs"] } +godot = { git = "https://github.com/godot-rust/gdext", branch = "master", features=["register-docs"] } rapier2d = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true } rapier2d-f64 = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true} rapier3d = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true} rapier3d-f64 = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true} -salva2d = { git = "https://github.com/ughuuu/salva", branch = "use-rapier-master", features = ["rapier"], optional = true } -salva3d = { git = "https://github.com/ughuuu/salva", branch = "use-rapier-master", features = ["rapier"], optional = true } +salva2d = { git = "https://github.com/ughuuu/salva", branch = "custom-changes", features = ["rapier"], optional = true } +salva2d-f64 = { git = "https://github.com/ughuuu/salva", branch = "custom-changes", features = ["rapier"], optional = true } +salva3d = { git = "https://github.com/ughuuu/salva", branch = "custom-changes", features = ["rapier"], optional = true } +salva3d-f64 = { git = "https://github.com/ughuuu/salva", branch = "custom-changes", features = ["rapier"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } @@ -59,8 +63,9 @@ parry3d = {git = "https://github.com/ughuuu/parry", branch = "custom-changes"} parry3d-f64 = {git = "https://github.com/ughuuu/parry", branch = "custom-changes"} [profile.release] -opt-level = 3 -debug = 2 +#opt-level = 3 +opt-level = "z" +#debug = 2 strip = "debuginfo" lto = "fat" codegen-units = 1 diff --git a/README.md b/README.md index b1145154..f6f250cb 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,13 @@ Godot Rapier Physics is a **2D and 3D** physics drop-in replacement for the [God # Features -Stability|Ghost Collisions +Stability|No Vibrations -|- -![](docs/rapier-vid.gif)|![](docs/ghost_collisions.gif) +![](docs/rapier-vid.gif)|![](docs/stability-comparison.gif) + +No Ghost Collisions|No CCD Issues +-|- +![](docs/ghost_collisions.gif)|![](docs/ccd-comparison.gif) Fluids 2D| Fluids 3D -|- diff --git a/bin2d/addons/godot-rapier2d/plugin.info.cfg b/bin2d/addons/godot-rapier2d/plugin.info.cfg index 189cbb0d..765f6af5 100644 --- a/bin2d/addons/godot-rapier2d/plugin.info.cfg +++ b/bin2d/addons/godot-rapier2d/plugin.info.cfg @@ -3,6 +3,6 @@ name="Godot Rapier 2D" description="A 2D and 3D drop-in replacement for the Godot engine that adds stability and fluids." author="appsinacup" -version="0.8.8" +version="0.8.9" flavour="" script="" diff --git a/bin3d/addons/godot-rapier3d/plugin.info.cfg b/bin3d/addons/godot-rapier3d/plugin.info.cfg index 5f22bfcb..d1d7b0ab 100644 --- a/bin3d/addons/godot-rapier3d/plugin.info.cfg +++ b/bin3d/addons/godot-rapier3d/plugin.info.cfg @@ -3,6 +3,6 @@ name="Godot Rapier 3D" description="A 2D and 3D drop-in replacement for the Godot engine that adds stability and fluids." author="appsinacup" -version="0.8.8" +version="0.8.9" flavour="" script="" diff --git a/bin3d/tests/nodes/Area/area_2d.tscn b/bin3d/tests/nodes/Area/area_2d.tscn deleted file mode 100644 index bbafec8b..00000000 --- a/bin3d/tests/nodes/Area/area_2d.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=4 format=3 uid="uid://dw5fjp1ehoisl"] - -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_6eclx"] -[ext_resource type="PackedScene" uid="uid://bi8fhkhrlsbc6" path="res://tests/nodes/Area/tests/2d/basic_api.tscn" id="2_j0ocs"] -[ext_resource type="PackedScene" uid="uid://cqv4g2347xrx5" path="res://tests/nodes/Area/tests/2d/space_override.tscn" id="3_10ilb"] - -[node name="area_2d" type="Node2D"] -script = ExtResource("1_6eclx") - -[node name="basic_api" parent="." instance=ExtResource("2_j0ocs")] - -[node name="space_override" parent="." instance=ExtResource("3_10ilb")] diff --git a/bin3d/tests/nodes/Area/tests/2d/basic_api.gd b/bin3d/tests/nodes/Area/tests/2d/basic_api.gd deleted file mode 100644 index 4955830b..00000000 --- a/bin3d/tests/nodes/Area/tests/2d/basic_api.gd +++ /dev/null @@ -1,228 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks the basic API for [Area2D] - """ - -func test_name() -> String: - return "Area2D | testing the basic API" - -func test_start() -> void: - # Add Area in the center - var area := add_area(CENTER) - area.monitoring = true - area.monitorable = false - - # Add rigid body - var rigid_body := add_rigid_body(CENTER) - - # Prepare added rigid body for later - var rigid_body_add := add_rigid_body(CENTER) - rigid_body_add.disable_mode = CollisionObject2D.DISABLE_MODE_REMOVE - rigid_body_add.process_mode = Node.PROCESS_MODE_DISABLED - - # Add rigid body on different collision layer - var rigid_body2 := add_rigid_body(CENTER) - rigid_body2.set_collision_layer_value(1, false) - rigid_body2.set_collision_layer_value(2, true) - rigid_body2.set_collision_mask_value(1, false) - rigid_body2.set_collision_mask_value(2, true) - - # Add rigid body with multiple shapes - var area_bottom_center := add_area(BOTTOM_CENTER) - var rigid_body_composite := add_rigid_body(BOTTOM_CENTER) - var body_shape2 := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.CIRCLE, 2) - rigid_body_composite.add_child(body_shape2) - - # Add area and kinematic body in the top left - var area_top_left := add_area(TOP_LEFT) - var kinematic_body := add_rigid_body(TOP_LEFT) - kinematic_body.freeze_mode = RigidBody2D.FREEZE_MODE_KINEMATIC - kinematic_body.freeze = true - - # Add area and static body in the top right - var area_top_right := add_area(TOP_RIGHT) - var static_body := add_static_body(TOP_RIGHT) - - # Add Area to be detected but with detection disabled - var area_detected := add_area(CENTER) - area_detected.monitoring = false - area_detected.monitorable = true - - # Add Area not to be detected and with detection disabled - var area_inactive := add_area(CENTER) - area_inactive.monitoring = false - area_inactive.monitorable = false - - # Add Area in the center left - var area_center_left := add_area(CENTER_LEFT) - area_center_left.monitoring = true - area_center_left.monitorable = false - - var checks_point = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - if true: # limit the scope - p_monitor.add_test("Detect rigid body") - var result := area.overlaps_body(rigid_body) - p_monitor.add_test_result(result) - - if true: # limit the scope - p_monitor.add_test("Don't detect disabled rigid body") - var result := area.overlaps_body(rigid_body_add) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Detect rigid body with multiple shapes") - var result := area_bottom_center.overlaps_body(rigid_body_composite) - p_monitor.add_test_result(result) - - if true: - p_monitor.add_test("Detect kinematic body") - var result := area_top_left.overlaps_body(kinematic_body) - p_monitor.add_test_result(result) - - if true: - p_monitor.add_test("Detect static body") - var result := area_top_right.overlaps_body(static_body) - p_monitor.add_test_result(result) - - if true: - p_monitor.add_test("Don't detect rigid body on collision layer 2") - var result := area.overlaps_body(rigid_body2) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Detect monitorable area") - var result := area.overlaps_area(area_detected) - p_monitor.add_test_result(result) - - if true: - p_monitor.add_test("Don't detect unmonitorable area") - var result := area.overlaps_area(area_inactive) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Don't detect rigid body when not monitoring") - var result := area_inactive.overlaps_body(rigid_body) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Don't detect monitorable area when not monitoring") - var result := area_inactive.overlaps_body(area_detected) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Don't detect anything when not overlapping") - var result_bodies := area_center_left.has_overlapping_bodies() - var result_areas := area_center_left.has_overlapping_areas() - if result_bodies: - p_monitor.add_test_error("Body detected.") - if result_areas: - p_monitor.add_test_error("Area detected.") - p_monitor.add_test_result(!result_bodies && !result_areas) - - # Add rigid body - rigid_body_add.process_mode = Node.PROCESS_MODE_INHERIT - - # Remove rigid body - rigid_body.disable_mode = CollisionObject2D.DISABLE_MODE_REMOVE - rigid_body.process_mode = Node.PROCESS_MODE_DISABLED - - # Disable a shape from the composite rigid body - body_shape2.disabled = true - - if p_monitor.frame == 3: # wait for one frame - # Tests after modifications - - if true: - p_monitor.add_test("Detect added rigid body") - var result := area.overlaps_body(rigid_body_add) - p_monitor.add_test_result(result) - - if true: - p_monitor.add_test("Don't detect removed rigid body") - var result := area.overlaps_body(rigid_body) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Detect rigid body with one shape disabled") - var result := area_bottom_center.overlaps_body(rigid_body_composite) - p_monitor.add_test_result(result) - - # Disable remaining shape for composite rigid body - rigid_body_composite.get_child(0).disabled = true - - # Move added rigid body - var new_transform = Transform2D(0.0, CENTER_LEFT) - PhysicsServer2D.body_set_state(rigid_body_add.get_rid(), PhysicsServer2D.BODY_STATE_TRANSFORM, new_transform) - - # Re-add rigid body - rigid_body.process_mode = Node.PROCESS_MODE_INHERIT - - if p_monitor.frame == 4: # wait for one frame - # Tests after modifications - - if true: - p_monitor.add_test("Don't detect rigid body with all shapes disabled") - var result := area_bottom_center.overlaps_body(rigid_body_composite) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Don't detect rigid body moved outside area") - var result := area.overlaps_body(rigid_body_add) - p_monitor.add_test_result(!result) - - if true: - p_monitor.add_test("Detect rigid body moved inside area") - var result := area_center_left.overlaps_body(rigid_body_add) - p_monitor.add_test_result(result) - - # Disable area - area.disable_mode = CollisionObject2D.DISABLE_MODE_REMOVE - area.process_mode = Node.PROCESS_MODE_DISABLED - - if p_monitor.frame == 5: # wait for one frame - # Tests after modifications - - if true: - p_monitor.add_test("Don't detect anything for disabled area") - var result_bodies := area.has_overlapping_bodies() - var result_areas := area.has_overlapping_areas() - if result_bodies: - p_monitor.add_test_error("Body detected.") - if result_areas: - p_monitor.add_test_error("Area detected.") - p_monitor.add_test_result(!result_bodies && !result_areas) - - p_monitor.monitor_completed() - - create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_static_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.CIRCLE, 2) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_rigid_body(p_position: Vector2, p_add_child := true) -> RigidBody2D: - var body := RigidBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.CIRCLE, 2) - body.add_child(body_shape) - body.position = p_position - body.gravity_scale = 0.0 - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area diff --git a/bin3d/tests/nodes/Area/tests/2d/basic_api.tscn b/bin3d/tests/nodes/Area/tests/2d/basic_api.tscn deleted file mode 100644 index 0f3e926b..00000000 --- a/bin3d/tests/nodes/Area/tests/2d/basic_api.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bi8fhkhrlsbc6"] - -[ext_resource type="Script" path="res://tests/nodes/Area/tests/2d/basic_api.gd" id="1_yxddu"] - -[node name="basic_api" type="Node2D"] -script = ExtResource("1_yxddu") diff --git a/bin3d/tests/nodes/Area/tests/2d/space_override.gd b/bin3d/tests/nodes/Area/tests/2d/space_override.gd deleted file mode 100644 index 4bdaff42..00000000 --- a/bin3d/tests/nodes/Area/tests/2d/space_override.gd +++ /dev/null @@ -1,128 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks space override for [Area2D] - """ - -func test_name() -> String: - return "Area2D | testing space override" - -func test_start() -> void: - # Add Area with disabled gravity - var area_no_gravity := add_area(CENTER) - area_no_gravity.monitoring = true - area_no_gravity.monitorable = false - area_no_gravity.gravity_space_override = Area2D.SPACE_OVERRIDE_REPLACE - area_no_gravity.gravity = 0.0 - - # Add Area with custom gravity - var area_custom_gravity := add_area(TOP_CENTER) - area_custom_gravity.monitoring = true - area_custom_gravity.monitorable = false - area_custom_gravity.gravity_space_override = Area2D.SPACE_OVERRIDE_REPLACE - area_custom_gravity.gravity_direction = Vector2.LEFT - area_custom_gravity.gravity = 500.0 - - # Add rigid body - var rigid_body := add_rigid_body(CENTER) - rigid_body.linear_damp_mode = RigidBody2D.DAMP_MODE_REPLACE - rigid_body.linear_damp = 0.0 - rigid_body.gravity_scale = 0.0 - - # Add rigid body - var rigid_body2 := add_rigid_body(TOP_CENTER) - rigid_body2.linear_damp_mode = RigidBody2D.DAMP_MODE_REPLACE - rigid_body2.linear_damp = 0.0 - rigid_body2.gravity_scale = 0.0 - - # Add rigid body outside area - var rigid_body_outside := add_rigid_body(CENTER_RIGHT) - rigid_body_outside.linear_damp_mode = RigidBody2D.DAMP_MODE_REPLACE - rigid_body_outside.linear_damp = 0.0 - rigid_body_outside.gravity_scale = 0.0 - - var dt := 1.0/60.0 - var default_gravity : Vector2 = ProjectSettings.get_setting("physics/2d/default_gravity_vector") - default_gravity *= ProjectSettings.get_setting("physics/2d/default_gravity") - - var custom_gravity := area_custom_gravity.gravity_direction - custom_gravity *= area_custom_gravity.gravity - - var checks_point = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - rigid_body.sleeping = false - rigid_body_outside.sleeping = false - - if p_monitor.frame == 2: - rigid_body.gravity_scale = 1.0 - rigid_body2.gravity_scale = 1.0 - rigid_body_outside.gravity_scale = 1.0 - - p_monitor.data["rigid_body_pos"] = rigid_body.position - p_monitor.data["rigid_body2_pos"] = rigid_body2.position - p_monitor.data["rigid_body_outside_pos"] = rigid_body_outside.position - - if p_monitor.frame == 22: - if true: # limit the scope - p_monitor.add_test("Rigid body in area with no gravity doesn't move") - var pos_start = p_monitor.data["rigid_body_pos"] - var motion = rigid_body.position - pos_start - var expected = Vector2.ZERO - var success := Utils.vec2_equals(motion, expected, 0.001) - if not success: - p_monitor.add_test_error("Disabled gravity was not applied correctly in area, expected motion %v, got %v" % [expected, motion]) - p_monitor.add_test_result(success) - - if true: # limit the scope - p_monitor.add_test("Rigid body in area with custom gravity moves to the left") - var pos_start = p_monitor.data["rigid_body2_pos"] - var motion = rigid_body2.position - pos_start - var time := 20.0 * dt - var expected = 0.5 * custom_gravity * time * time - var success := Utils.vec2_equals(motion, expected, 4) - if not success: - p_monitor.add_test_error("Custom gravity was not applied correctly in area, expected motion %v, got %v" % [expected, motion]) - p_monitor.add_test_result(success) - - if true: # limit the scope - p_monitor.add_test("Rigid body outside of area has default gravity applied") - var pos_start = p_monitor.data["rigid_body_outside_pos"] - var motion = rigid_body_outside.position - pos_start - var time := 20.0 * dt - var expected = 0.5 * default_gravity * time * time - var success := Utils.vec2_equals(motion, expected, 4.0) - if not success: - p_monitor.add_test_error("Default gravity was not applied correctly outside of area, expected motion %v, got %v" % [expected, motion]) - p_monitor.add_test_result(success) - - p_monitor.monitor_completed() - - create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_static_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.CIRCLE, 2) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_rigid_body(p_position: Vector2, p_add_child := true) -> RigidBody2D: - var body := RigidBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.CIRCLE, 2) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area - diff --git a/bin3d/tests/nodes/Area/tests/2d/space_override.tscn b/bin3d/tests/nodes/Area/tests/2d/space_override.tscn deleted file mode 100644 index 194eda0a..00000000 --- a/bin3d/tests/nodes/Area/tests/2d/space_override.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cqv4g2347xrx5"] - -[ext_resource type="Script" path="res://tests/nodes/Area/tests/2d/space_override.gd" id="1_usnhb"] - -[node name="space_override" type="Node2D"] -script = ExtResource("1_usnhb") diff --git a/bin3d/tests/nodes/CharacterBody/character_body_2d.tscn b/bin3d/tests/nodes/CharacterBody/character_body_2d.tscn deleted file mode 100644 index 1a0bbfe9..00000000 --- a/bin3d/tests/nodes/CharacterBody/character_body_2d.tscn +++ /dev/null @@ -1,18 +0,0 @@ -[gd_scene load_steps=6 format=3 uid="uid://dl8jh1yybnmc7"] - -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_dma0p"] -[ext_resource type="PackedScene" uid="uid://bcvyoyk4gx8hd" path="res://tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.tscn" id="2_eie1l"] -[ext_resource type="PackedScene" uid="uid://clt6d1xruk034" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.tscn" id="3_6m7xl"] -[ext_resource type="PackedScene" path="res://tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.tscn" id="4_c1exd"] -[ext_resource type="PackedScene" uid="uid://b8c3ipxt4fjlo" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.tscn" id="5_q1u5f"] - -[node name="Scene" type="Node"] -script = ExtResource("1_dma0p") - -[node name="detect_surface_type_with_pressure" parent="." instance=ExtResource("2_eie1l")] - -[node name="testing_floor_snap_circle" parent="." instance=ExtResource("3_6m7xl")] - -[node name="testing_slide_on_ceiling_cap" parent="." instance=ExtResource("4_c1exd")] - -[node name="constant_speed" parent="." instance=ExtResource("5_q1u5f")] diff --git a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_collide.gd b/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_collide.gd deleted file mode 100644 index c8e1e7a9..00000000 --- a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_collide.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends CharacterBody2D - -var distance: Vector2 -var test_only: bool = false - -func _physics_process(delta: float) -> void: - move_and_collide(distance, test_only, safe_margin) diff --git a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd b/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd deleted file mode 100644 index 135485af..00000000 --- a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd +++ /dev/null @@ -1,4 +0,0 @@ -extends CharacterBody2D - -func _physics_process(_delta: float) -> void: - move_and_slide() diff --git a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd b/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd deleted file mode 100644 index 2d54f42a..00000000 --- a/bin3d/tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends CharacterBody2D - -var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") - -func _physics_process(delta: float) -> void: - - # Add the gravity. - if not is_on_floor(): - velocity.y += gravity * delta - - move_and_slide() diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.gd deleted file mode 100644 index c61888cd..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.gd +++ /dev/null @@ -1,76 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_mode: CharacterBody2D.MotionMode = CharacterBody2D.MotionMode.MOTION_MODE_GROUNDED -var speed := 1500 -var simulation_duration := 2.0 - -func test_description() -> String: - return """Checks that the surface is detected (wall, ground, ceiling), without constant preessure, - only one surface at a time should be detected, and only when the body touches them, not during the movement. - Param [body_mode]: in Floating mode only wall should be detected. - """ - -func test_name() -> String: - var mode = "Grounded" if body_mode == CharacterBody2D.MOTION_MODE_GROUNDED else "Floating" - return "CharacterBody2D | testing surface detection when the body don't push against the surface [mode=%s]" % [mode] - -func test_start() -> void: - add_collision_boundaries(150) - - # checks all collision type - var test_lambda - if body_mode == CharacterBody2D.MOTION_MODE_GROUNDED: - test_lambda = func(p_step, p_target: CharacterBody2D, p_monitor: GenericStepMonitor): - if p_step == 0: return p_target.get_slide_collision_count() == 0 # idle - elif p_step == 1: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # touch right wall - elif p_step == 2: return p_target.get_slide_collision_count() == 0 # go up - elif p_step == 3: return p_target.is_on_ceiling_only() and p_target.get_slide_collision_count() == 1 # hit the ceiling - elif p_step == 4: return p_target.get_slide_collision_count() == 0 # move left - elif p_step == 5: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # hit the left wall - elif p_step == 6: return p_target.get_slide_collision_count() == 0 # move down - elif p_step == 7: return p_target.is_on_floor_only() and p_target.get_slide_collision_count() == 1 # hit the floor - elif p_step == 8: return p_target.get_slide_collision_count() == 0 # move right - elif body_mode == CharacterBody2D.MOTION_MODE_FLOATING: - test_lambda = func(p_step, p_target: CharacterBody2D, p_monitor: GenericStepMonitor): - if p_step == 0: return p_target.get_slide_collision_count() == 0 # idle - elif p_step == 1: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # touch right wall - elif p_step == 2: return p_target.get_slide_collision_count() == 0 # go up - elif p_step == 3: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # hit the ceiling - elif p_step == 4: return p_target.get_slide_collision_count() == 0 # move left - elif p_step == 5: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # hit the left wall - elif p_step == 6: return p_target.get_slide_collision_count() == 0 # move down - elif p_step == 7: return p_target.is_on_wall_only() and p_target.get_slide_collision_count() == 1 # hit the floor - elif p_step == 8: return p_target.get_slide_collision_count() == 0 # move right - - var physics_step_cbk = func(p_step: int, p_target: CharacterBody2D, p_is_transition: bool, p_monitor: Monitor): - if not p_is_transition: - return - if p_step == 0: p_target.velocity = Vector2(speed, 0) # right - elif p_step == 1: p_target.velocity = Vector2(0, -speed) # up - elif p_step == 3: p_target.velocity = Vector2(-speed, 0) # left - elif p_step == 5: p_target.velocity = Vector2(0, speed) # down - elif p_step == 7: p_target.velocity = Vector2(speed, 0) # right - - var cpt_layer := 1 - for shape_type in PhysicsTest2D.TestCollisionShape.values(): - if shape_type == PhysicsTest2D.TestCollisionShape.WORLD_BOUNDARY or shape_type == PhysicsTest2D.TestCollisionShape.CONCAVE_SEGMENT: - continue - # Create character - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd") - character.motion_mode = body_mode - character.position = CENTER - character.collision_layer = 0 - character.collision_mask = 0 - character.set_collision_layer_value(cpt_layer, true) - character.set_collision_mask_value(cpt_layer, true) - - var body_col: Node2D = get_default_collision_shape(shape_type, 2) - character.add_child(body_col) - - add_child(character) - - var contact_monitor := create_generic_step_monitor(character, test_lambda, physics_step_cbk, simulation_duration) - contact_monitor.test_name = "%s detects collisions correctly" % [shape_name(shape_type)] - - cpt_layer += 1 diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.tscn deleted file mode 100644 index 4bd7a4cf..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dnhgqjtnu71n"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/_to_remove_detect_surface_type_without_pressure.gd" id="1_qjnxc"] - -[node name="detect_wall_type_without_pressure" type="Node2D"] -script = ExtResource("1_qjnxc") diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.gd deleted file mode 100644 index ac8b004e..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.gd +++ /dev/null @@ -1,57 +0,0 @@ -extends PhysicsUnitTest2D - -var speed := 1500 -var simulation_duration := 2.0 - -func test_description() -> String: - return """Checks that the surface is detected (wall, ground, ceiling), if the body maintains pressure, - we should have 2 surfaces detected in the corners and one otherwise. - """ - -func test_name() -> String: - return "CharacterBody2D | testing surface detection when the body constantly push against the surface" - -func test_start() -> void: - add_collision_boundaries(150) - - # checks all collision type - var test_lambda = func(p_step: int, p_body: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return p_body.get_slide_collision_count() == 0 - elif p_step == 1: return p_body.is_on_wall_only() - elif p_step == 2: return p_body.is_on_wall() and p_body.is_on_ceiling() - elif p_step == 3: return p_body.is_on_ceiling_only() - elif p_step == 4: return p_body.is_on_wall() and p_body.is_on_ceiling() - elif p_step == 5: return p_body.is_on_wall_only() - elif p_step == 6: return p_body.is_on_wall() and p_body.is_on_floor() - elif p_step == 7: return p_body.is_on_floor_only() - - var physics_step_cbk = func(p_step: int, p_body: CharacterBody2D, _p_is_transition: bool, _p_monitor: GenericStepMonitor): - if p_step == 0: p_body.velocity = Vector2(speed, 0) # right - elif p_step < 2: p_body.velocity = Vector2(speed, -speed) # up right - elif p_step < 4: p_body.velocity = Vector2(-speed, -speed) # up left - elif p_step < 6: p_body.velocity = Vector2(-speed, speed) # down left - elif p_step == 6: p_body.velocity = Vector2(speed, speed) # down right - - var cpt_layer := 1 - for shape_type in PhysicsTest2D.TestCollisionShape.values(): - if shape_type == PhysicsTest2D.TestCollisionShape.WORLD_BOUNDARY or shape_type == PhysicsTest2D.TestCollisionShape.CONCAVE_SEGMENT: - continue - # Create character - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd") - character.motion_mode = CharacterBody2D.MOTION_MODE_GROUNDED - character.position = CENTER - character.collision_layer = 0 - character.collision_mask = 0 - character.set_collision_layer_value(cpt_layer, true) - character.set_collision_mask_value(cpt_layer, true) - - var body_col: Node2D = PhysicsTest2D.get_default_collision_shape(shape_type, 2) - character.add_child(body_col) - - add_child(character) - - var contact_monitor := create_generic_step_monitor(character, test_lambda, physics_step_cbk, simulation_duration) - contact_monitor.test_name = "%s detects collisions correctly" % [PhysicsTest2D.shape_name(shape_type)] - - cpt_layer += 1 diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.tscn deleted file mode 100644 index 0d2e4bbc..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bcvyoyk4gx8hd"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/detect_surface_type_with_pressure.gd" id="1_byyuh"] - -[node name="detect_wall_type_with_pressure" type="Node2D"] -script = ExtResource("1_byyuh") diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.gd deleted file mode 100644 index a2d4b322..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.gd +++ /dev/null @@ -1,51 +0,0 @@ -extends PhysicsUnitTest2D - -var speed := 750 -var tolerance = 1.5 -var simulation_duration := 1 - - -@onready var spawn_1 := $Spawn1 # max_x == 275 (300-25) -@onready var spawn_2 := $Spawn2 # max_x > 875 (900-25) - -func test_description() -> String: - return """Checks that the body is stop when is [floor_block_on_wall] is ON, - without this option the body can climb a bit on a wall, causing jitter. - """ - -func test_name() -> String: - return "CharacterBody2D | testing [floor_block_on_wall]" - -func test_start() -> void: - var test_lambda: Callable = func(p_target: CharacterBody2D, p_monitor: GenericExpirationMonitor): - if p_target.floor_block_on_wall: - return p_monitor.data["maximum_x"] > (275 - p_target.safe_margin) and p_monitor.data["maximum_x"] < (275 + p_target.safe_margin) - return p_monitor.data["maximum_x"] > (875 + p_target.safe_margin) - - var callback_lambda = func(p_target: CharacterBody2D, p_monitor: GenericExpirationMonitor): - if p_target.is_on_floor(): - p_target.velocity = Vector2(speed, 0) - if p_target.position.x > p_monitor.data["maximum_x"]: - p_monitor.data["maximum_x"] = p_target.position.x - - var character_blocked := create_character(spawn_1.position, true) - var character_not_blocked := create_character(spawn_2.position, false) - - var monitor_blocked := create_generic_expiration_monitor(character_blocked, test_lambda, callback_lambda, simulation_duration) - monitor_blocked.test_name = "The body is properly blocked when [floor_block_on_wall] is ON" - monitor_blocked.data["maximum_x"] = 0 - - var monitor_not_blocked := create_generic_expiration_monitor(character_not_blocked, test_lambda, callback_lambda, simulation_duration) - monitor_not_blocked.test_name = "The body is not blocked when [floor_block_on_wall] is OFF" - monitor_not_blocked.data["maximum_x"] = 0 - -func create_character(p_position: Vector2, p_block_on_wall, p_body_shape := PhysicsTest2D.TestCollisionShape.RECTANGLE) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - character.position = p_position - character.floor_block_on_wall = p_block_on_wall - character.floor_max_angle = deg_to_rad(44) - var body_col: Node2D = get_default_collision_shape(p_body_shape, 2) - character.add_child(body_col) - add_child(character) - return character diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.tscn deleted file mode 100644 index f652c063..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.tscn +++ /dev/null @@ -1,17 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bhdm8lk4jkhw8"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_block_on_wall.gd" id="1_86h11"] - -[node name="block_on_wall" type="Node2D"] -script = ExtResource("1_86h11") - -[node name="StaticBody2D" type="StaticBody2D" parent="."] - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(300, 400, 400, 300, 600, 300, 600, 400, 900, 400, 1000, 300, 1152, 300, 1152, 647, 0, 648, 0, 400) - -[node name="Spawn1" type="Marker2D" parent="."] -position = Vector2(120, 300) - -[node name="Spawn2" type="Marker2D" parent="."] -position = Vector2(720, 300) diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.gd deleted file mode 100644 index 44bfdeca..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.gd +++ /dev/null @@ -1,60 +0,0 @@ -extends PhysicsUnitTest2D - -var speed = 750 -var tolerance = 1.5 - -func test_description() -> String: - return """Checks that the body speed is stable in slopes when [floor_constant_speed] - is activated. - """ - -func test_name() -> String: - return "CharacterBody2D | testing [floor_constant_speed], params: [speed:%s, tolerance:%.1f]" % [speed, tolerance] - -func test_start() -> void: - var test_lambda = func(p_step: int, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor_only() - elif p_step == 2: return p_target.is_on_wall() - - var physics_step_cbk = func(p_step: int, p_target: CharacterBody2D, is_transition: bool, p_monitor: GenericStepMonitor): - if is_transition and p_step == 1: - p_target.velocity.x = speed - p_monitor.data["speed"] = 0.0 - p_monitor.data["cpt_speed"] = 0 - elif p_step >= 1 and p_target.is_on_floor_only(): - p_monitor.data["speed"] += p_target.get_real_velocity().length() - p_monitor.data["cpt_speed"] += 1 - elif p_step == 2: - var average: float = p_monitor.data["speed"] / p_monitor.data["cpt_speed"] - p_monitor.test_name += " | average=%.2f" % [average] - if average < (speed - tolerance) or average > (speed + tolerance): - p_monitor.failed() - - for i in range(2): - var spawn_position = $SpawnBottom.position if i==0 else $SpawnTop.position - var type = "ascending" if i== 0 else "descenting" - var cpt := 1 - for shape_type in PhysicsTest2D.TestCollisionShape.values(): - if shape_type == PhysicsTest2D.TestCollisionShape.WORLD_BOUNDARY or shape_type == PhysicsTest2D.TestCollisionShape.CONCAVE_SEGMENT: - continue - var body := create_character(cpt, spawn_position, shape_type) - add_child(body) - var monitor := create_generic_step_monitor(body, test_lambda, physics_step_cbk) - monitor.test_name = "speed is constant when %s with %s" % [type, PhysicsTest2D.shape_name(shape_type)] - cpt += 1 - -func create_character(p_layer: int, p_position: Vector2, p_body_shape := PhysicsTest2D.TestCollisionShape.CONCAVE_POLYGON) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - character.floor_snap_length = 100 - character.position = p_position - character.collision_layer = 0 - character.collision_mask = 0 - character.floor_constant_speed = true - character.floor_max_angle = deg_to_rad(50) - character.set_collision_layer_value(p_layer, true) - character.set_collision_mask_value(p_layer, true) - var body_col: Node2D = PhysicsTest2D.get_default_collision_shape(p_body_shape, 2) - character.add_child(body_col) - return character diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.tscn deleted file mode 100644 index 9311b6f6..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.tscn +++ /dev/null @@ -1,19 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://b8c3ipxt4fjlo"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_constant_speed.gd" id="1_bcupp"] - -[node name="constant_speed" type="Node2D"] -script = ExtResource("1_bcupp") - -[node name="StaticBody2D" type="StaticBody2D" parent="."] -collision_layer = 65535 -collision_mask = 65535 - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(0, 507, 0, 0, 64, 0, 64, 507, 502, 155, 502, 0, 634, 0, 634, 155, 1072, 507, 1072, 0, 1152, 0, 1152, 648, 0, 648) - -[node name="SpawnBottom" type="Marker2D" parent="."] -position = Vector2(120, 314) - -[node name="SpawnTop" type="Marker2D" parent="."] -position = Vector2(680, 70) diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.gd deleted file mode 100644 index 291f4d6f..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.gd +++ /dev/null @@ -1,54 +0,0 @@ -extends PhysicsUnitTest2D - -var speed := 750 -var tolerance = 1.5 -var simulation_duration := 1 - -@onready var spawn_1 := $Spawn1 # max_x < 375 (400-25) -@onready var spawn_2 := $Spawn2 # max_x > 975 (100-25) - -func test_description() -> String: - return """Checks if [floor_max_angle] working properly, the body shoould not detect an angle, - if the slope angle is greather than [floor_max_angle]. - """ - -func test_name() -> String: - return "CharacterBody2D | testing [floor_max_angle]" - -func test_start() -> void: - var test_lambda: Callable = func(p_target: CharacterBody2D, p_monitor: GenericExpirationMonitor): - if p_monitor.data["max_angle"] == 44: - return p_monitor.data["maximum_x"] < 375 - else: - return p_monitor.data["maximum_x"] > 975 - - var callback_lambda = func(p_target: CharacterBody2D, p_monitor: GenericExpirationMonitor): - if p_target.is_on_floor(): - p_target.velocity = Vector2(speed, 0) - if p_target.position.x > p_monitor.data["maximum_x"]: - p_monitor.data["maximum_x"] = p_target.position.x - - var character_angle_lower := create_character(spawn_1.position, 44) - var character_angle_greater := create_character(spawn_2.position, 45) - - var monitor_angle_lower := create_generic_expiration_monitor(character_angle_lower, test_lambda, callback_lambda, simulation_duration) - monitor_angle_lower.test_name = "If [floor_max_angle] is lower than the slope, the body can't climb" - monitor_angle_lower.data["max_angle"] = 44 - monitor_angle_lower.data["maximum_x"] = 0 - - var monitor_angle_greater := create_generic_expiration_monitor(character_angle_greater, test_lambda, callback_lambda, simulation_duration) - monitor_angle_greater.test_name = "If [floor_max_angle] is greater or equal than the slope, the body can climb" - monitor_angle_greater.data["max_angle"] = 45 - monitor_angle_greater.data["maximum_x"] = 0 - -func create_character(p_position: Vector2, p_angle_degree: int, p_body_shape := PhysicsTest2D.TestCollisionShape.RECTANGLE) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - character.position = p_position - character.floor_block_on_wall = false - character.floor_max_angle = deg_to_rad(p_angle_degree) - character.floor_snap_length = 50 - var body_col: Node2D = get_default_collision_shape(p_body_shape, 2) - character.add_child(body_col) - add_child(character) - return character diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.tscn deleted file mode 100644 index 510d80a7..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.tscn +++ /dev/null @@ -1,17 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://d1dhxcp2scxyl"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_max_angle.gd" id="1_ttd14"] - -[node name="floor_max_angle" type="Node2D"] -script = ExtResource("1_ttd14") - -[node name="StaticBody2D" type="StaticBody2D" parent="."] - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(300, 400, 400, 300, 600, 300, 600, 400, 900, 400, 1000, 300, 1152, 300, 1152, 647, 0, 648, 0, 400) - -[node name="Spawn1" type="Marker2D" parent="."] -position = Vector2(120, 300) - -[node name="Spawn2" type="Marker2D" parent="."] -position = Vector2(720, 300) diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.gd deleted file mode 100644 index 03477ed8..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.gd +++ /dev/null @@ -1,78 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.CAPSULE - -var spawn_position = Vector2(150, 400) -var speed = 750 - -func test_description() -> String: - return """Tests whether the body is firmly attached to the ground when a [floor_snap_length] is applied, - and only when the velocity points downwards. - """ - -func test_name() -> String: - return "CharacterBody2D | testing [floor floor_snap_length] [shape: %s]" % [PhysicsTest2D.shape_name(body_shape)] - -func test_start() -> void: - # C1 start in air, touch the ground until he reach the wall - var character1 := create_character(1) # checks behaviour without snap - character1.position = spawn_position - add_child(character1) - - var c1_test_lambda = func(p_step: int, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor_only() - elif p_step == 2: return p_target.is_on_wall() - - var physics_step_cbk = func(p_step: int, p_target: CharacterBody2D, is_transition: bool, _p_monitor: GenericStepMonitor): - if is_transition and p_step == 1: - p_target.velocity.x = speed - - var c1_monitor := create_generic_step_monitor(character1, c1_test_lambda, physics_step_cbk) - c1_monitor.test_name = "Snapping works as expected (stick to the floor)" - - # C2 without snap it should be not stick to the ground - var character2 := create_character(2) # checks behaviour with snap - character2.position = spawn_position - character2.floor_snap_length = 0 # turn off snapping ton confirm different behavior - add_child(character2) - - var c2_test_lambda = func(p_step: int, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor_only() - elif p_step == 2: return not p_target.is_on_wall() - elif p_step == 3: return p_target.is_on_wall() - - var c2_monitor := create_generic_step_monitor(character2, c2_test_lambda, physics_step_cbk) - c2_monitor.test_name = "Snapping has a different behaviour than without it" - - # C3 try to jump with - var character3 := create_character(3) # checks if the body can jump - character3.position = spawn_position - add_child(character3) - - var c3_test_lambda = func(p_step: int, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor_only() - elif p_step == 2: return not p_target.is_on_floor() - elif p_step == 3: return p_target.is_on_floor() - - var cbk_jump_lambda = func(step: int, p_target: CharacterBody2D, p_is_transition: bool, _p_monitor: GenericStepMonitor): - if p_is_transition and step == 1: - p_target.velocity.y = -500 - - var c3_monitor := create_generic_step_monitor(character3, c3_test_lambda, cbk_jump_lambda) - c3_monitor.test_name = "Can jump when snapping is applied" - -func create_character(layer: int) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - character.floor_snap_length = 10 - character.position = Vector2(-350, 50) - character.collision_layer = 0 - character.collision_mask = 0 - character.set_collision_layer_value(layer, true) - character.set_collision_mask_value(layer, true) - var body_col: Node2D = PhysicsTest2D.get_default_collision_shape(body_shape, 2) - character.add_child(body_col) - return character diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.tscn deleted file mode 100644 index 3c621cea..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.tscn +++ /dev/null @@ -1,13 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://clt6d1xruk034"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/floor_snap_length.gd" id="1_nyh6l"] - -[node name="testing_floor_snap" type="Node2D"] -script = ExtResource("1_nyh6l") - -[node name="StaticBody2D" type="StaticBody2D" parent="."] -collision_layer = 65535 -collision_mask = 65535 - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(0, 0, 80, 0, 80, 496, 318, 496, 478, 383, 547, 383, 700, 496, 944, 496, 944, 0, 1152, 0, 1152, 648, 0, 648) diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.gd b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.gd deleted file mode 100644 index b4db7c1f..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.gd +++ /dev/null @@ -1,64 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.RECTANGLE -var jump_force := -2000 -var spawn_position := Vector2(280, 320) -var max_x_position := 145 - -func test_description() -> String: - return """Testing [slide_on_ceiling], when ON, the body will slide on the ceiling (position.x will change), - and when it's off, the body should not have his position.x be changed. - """ - -func test_name() -> String: - return "CharacterBody2D | testing slide on ceiling [shape: %s]" % [PhysicsTest2D.shape_name(body_shape)] - -func test_start() -> void: - # C1 Jump in the ceiling and expect to move in x - var character1 := create_character(1) - character1.slide_on_ceiling = true - character1.floor_max_angle = deg_to_rad(80) - add_child(character1) - - var c1_test_lambda = func(p_step: int, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor() - elif p_step == 2: return not p_target.is_on_floor() and not p_target.is_on_ceiling() - elif p_step == 3: return p_target.is_on_ceiling() - elif p_step == 4: return p_target.position.x < 450 - elif p_step == 5: return p_target.position.x >= 450 - - var physics_step_cbk = func(p_step: int, p_target: CharacterBody2D, p_is_transition: bool, _p_monitor: GenericStepMonitor): - if p_is_transition and p_step == 1: - p_target.velocity.y = jump_force - - var c1_monitor := create_generic_step_monitor(character1, c1_test_lambda, physics_step_cbk) - c1_monitor.test_name = "Slide enough to go through the platform" - - # C2 without slide on ceiling, the body should not move in x - var character2 := create_character(2) - character2.slide_on_ceiling = false - character2.floor_max_angle = deg_to_rad(80) - add_child(character2) - - var c2_test_lambda = func(p_step, p_target: CharacterBody2D, _p_monitor: GenericStepMonitor): - if p_step == 0: return not p_target.is_on_floor() - elif p_step == 1: return p_target.is_on_floor() - elif p_step == 2: return not p_target.is_on_floor() and not p_target.is_on_ceiling() - elif p_step == 3: return p_target.is_on_ceiling() - elif p_step == 4: return is_equal_approx(p_target.position.x, spawn_position.x) - - var c2_monitor := create_generic_step_monitor(character2, c2_test_lambda, physics_step_cbk) - c2_monitor.test_name = "Without sliding, the x position of the body will not change" - -func create_character(layer: int) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - character.collision_layer = 0 - character.collision_mask = 0 - character.position = spawn_position - character.set_collision_layer_value(layer, true) - character.set_collision_mask_value(layer, true) - var body_col: Node2D = PhysicsTest2D.get_default_collision_shape(body_shape, 2) - character.add_child(body_col) - return character diff --git a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.tscn b/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.tscn deleted file mode 100644 index 06b7f661..00000000 --- a/bin3d/tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.tscn +++ /dev/null @@ -1,13 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dplo6k3cmfows"] - -[ext_resource type="Script" path="res://tests/nodes/CharacterBody/tests/character_body_2d/slide_on_ceiling.gd" id="1_ypb7w"] - -[node name="testing_slide_on_ceiling" type="Node2D"] -script = ExtResource("1_ypb7w") - -[node name="StaticBody2D" type="StaticBody2D" parent="."] -collision_layer = 3 -collision_mask = 3 - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(400, 150, 145, 337, 145, 440, 345, 440, 345, 600, 0, 600, 1, 150) diff --git a/bin3d/tests/nodes/CollisionShape/collision_shape_2d.tscn b/bin3d/tests/nodes/CollisionShape/collision_shape_2d.tscn deleted file mode 100644 index 3a4510db..00000000 --- a/bin3d/tests/nodes/CollisionShape/collision_shape_2d.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=4 format=3 uid="uid://c6prk86pe8y63"] - -[ext_resource type="PackedScene" uid="uid://crocifwg477on" path="res://tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.tscn" id="1_dop01"] -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_leel8"] -[ext_resource type="PackedScene" uid="uid://cbd4dqylsy8kx" path="res://tests/nodes/CollisionShape/tests/2d/character_one_way_collision.tscn" id="2_krm28"] - -[node name="collision_shape_2d" type="Node2D"] -script = ExtResource("1_leel8") - -[node name="characteer_one_way_collision" parent="." instance=ExtResource("2_krm28")] - -[node name="rigid_one_way_collision" parent="." instance=ExtResource("1_dop01")] diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.gd b/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.gd deleted file mode 100644 index f1b24529..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.gd +++ /dev/null @@ -1,87 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.CAPSULE -var speed := 30 -var simulation_duration := 1 - -func test_description() -> String: - return """Checks if [One Way Collision] works properly with CharacterBody2D, - it must only collide on the edge that face up (relative to CollisionPolygon2D's rotation). - In this test, the platform should only collide when the angle is > 180°. - """ - -func test_name() -> String: - return "CollisionShape2D | testing [One Way Collision] with CharacterBody2D" - -var bodies = [] -var platforms_center_pos = [] -var platforms = [] -var labels = [] - -func test_start() -> void: - var offset_x = (Global.WINDOW_SIZE.x - 57) / 29.0 # 30 columns - var offset_y = (Global.WINDOW_SIZE.y - 72) / 11.0 # 12 rows - 72 + 528 - var deg := 0 - for y in range(12): - for x in range(30): - var wall_on_way = PhysicsTest2D.get_static_body_with_collision_shape(Rect2(Vector2(0,0), Vector2(20,20)), TestCollisionShape.RECTANGLE) - var center = Vector2(28 + offset_x * x , 36 + offset_y * y) - platforms_center_pos.append(center) - wall_on_way.position = center - var collision_shape: CollisionShape2D = wall_on_way.get_child(0) - collision_shape.one_way_collision = true - wall_on_way.rotate(deg_to_rad(deg)) - wall_on_way.set_collision_layer_value(1, true) - wall_on_way.set_collision_layer_value(2, true) - add_child(wall_on_way) - platforms.append(wall_on_way) - - var label := Label.new() - label.text = "%d°" % [deg] - label.position = center + Vector2(0, -28) - label.set("theme_override_font_sizes/font_size", 8) - add_child(label) - labels.append(label) - - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide.gd") - character.add_child(PhysicsTest2D.get_default_collision_shape(body_shape, 0.5)) - character.position = center + Vector2(-20, 0) - character.velocity = Vector2(speed, 0) - bodies.append(character) - add_child(character) - - wall_on_way.collision_layer = 0 - wall_on_way.collision_mask = 0 - wall_on_way.set_collision_layer_value(x + 1, true) - - character.collision_layer = 0 - character.collision_mask = 0 - character.set_collision_mask_value(x + 1, true) - - deg += 1 - - var lambda: Callable = func(p_target: PhysicsUnitTest2D, p_monitor: GenericExpirationMonitor): - var error_cpt := 0 - for body in bodies as Array[RigidBody2D]: - var idx = bodies.find(body) - var should_collide = fposmod(idx, 360) > 180 - var collided = body.position.x < platforms_center_pos[idx].x - - if(should_collide == collided): - p_target.remove_child(body) - p_target.remove_child(platforms[idx]) - p_target.remove_child(labels[idx]) - else: - labels[idx].set("theme_override_colors/font_color", Color.RED) - body.velocity = Vector2.ZERO - error_cpt += 1 - - if error_cpt == 0: - return true - p_monitor.error_message = "%d angles failed" % [error_cpt] - return false - - var monitor := create_generic_expiration_monitor(self, lambda, null, simulation_duration) - monitor.test_name = "Only collide if the platform rotation > 180°" - monitor.expected_to_fail = true diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.tscn b/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.tscn deleted file mode 100644 index a73dfeb3..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/character_one_way_collision.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cbd4dqylsy8kx"] - -[ext_resource type="Script" path="res://tests/nodes/CollisionShape/tests/2d/character_one_way_collision.gd" id="1_rjuqy"] - -[node name="characteer_one_way_collision" type="Node2D"] -script = ExtResource("1_rjuqy") diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.gd b/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.gd deleted file mode 100644 index c20f9bc1..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.gd +++ /dev/null @@ -1,87 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.CAPSULE -var speed := 55 -var simulation_duration := 1 - -func test_description() -> String: - return """Checks if [One Way Collision] works properly with RigidBody2D, - it must only collide on the edge that face up (relative to CollisionPolygon2D's rotation). - In this test, the platform should only collide when the angle is > 180°. - """ - -func test_name() -> String: - return "CollisionShape2D | testing [One Way Collision] with RigidBody2D" - -var bodies = [] -var platforms_center_pos = [] -var platforms = [] -var labels = [] - -func test_start() -> void: - var offset_x = (Global.WINDOW_SIZE.x - 57) / 29.0 # 30 columns - var offset_y = (Global.WINDOW_SIZE.y - 72) / 11.0 # 12 rows - 72 + 528 - var deg := 0 - for y in range(12): - for x in range(30): - var wall_on_way = PhysicsTest2D.get_static_body_with_collision_shape(Rect2(Vector2(0,0), Vector2(20,20)), TestCollisionShape.RECTANGLE) - var center = Vector2(28 + offset_x * x , 36 + offset_y * y) - platforms_center_pos.append(center) - wall_on_way.position = center - var collision_shape: CollisionShape2D = wall_on_way.get_child(0) - collision_shape.one_way_collision = true - wall_on_way.rotate(deg_to_rad(deg)) - wall_on_way.set_collision_layer_value(1, true) - wall_on_way.set_collision_layer_value(2, true) - add_child(wall_on_way) - platforms.append(wall_on_way) - - var label := Label.new() - label.text = "%d°" % [deg] - label.position = center + Vector2(0, -28) - label.set("theme_override_font_sizes/font_size", 8) - add_child(label) - labels.append(label) - - var rigid = RigidBody2D.new() - rigid.add_child(PhysicsTest2D.get_default_collision_shape(body_shape, 0.5)) - rigid.gravity_scale = 0 - rigid.position = center + Vector2(-20, 0) - bodies.append(rigid) - add_child(rigid) - rigid.add_constant_force(Vector2(speed, 0)) - - wall_on_way.collision_layer = 0 - wall_on_way.collision_mask = 0 - wall_on_way.set_collision_layer_value(x + 1, true) - - rigid.collision_layer = 0 - rigid.collision_mask = 0 - rigid.set_collision_mask_value(x + 1, true) - - deg += 1 - - var lambda: Callable = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericExpirationMonitor): - var error_cpt := 0 - for body in bodies as Array[RigidBody2D]: - var idx = bodies.find(body) - var should_collide = fposmod(idx, 360) > 180 - var collided = body.position.x < platforms_center_pos[idx].x - - if(should_collide == collided): - remove_child(bodies[idx]) - remove_child(platforms[idx]) - remove_child(labels[idx]) - else: - labels[idx].set("theme_override_colors/font_color", Color.RED) - bodies[idx].freeze = true - error_cpt += 1 - - if error_cpt == 0: - return true - p_monitor.error_message = "%d angles failed" % [error_cpt] - return false - - var monitor := create_generic_expiration_monitor(self, lambda, null, simulation_duration) - monitor.test_name = "Only collide if the platform rotation > 180°" - monitor.expected_to_fail = true diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.tscn b/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.tscn deleted file mode 100644 index fe28d9ae..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://crocifwg477on"] - -[ext_resource type="Script" path="res://tests/nodes/CollisionShape/tests/2d/rigid_one_way_collision.gd" id="1_lx67j"] - -[node name="rigid_one_way_collision" type="Node2D"] -script = ExtResource("1_lx67j") diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.gd b/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.gd deleted file mode 100644 index 1049caba..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.gd +++ /dev/null @@ -1,37 +0,0 @@ -extends PhysicsUnitTest2D - -func test_description() -> String: - return """ - """ - -func test_name() -> String: - return "CollisionShape2D | testing [One Way Collision] with World Boundary 2D" - -func test_start() -> void: - var world_boundary := create_static_body(-25, CENTER) - world_boundary.position = BOTTOM_CENTER - Vector2(0, 50) - var body := create_character(1) - body.position = CENTER - -func create_static_body(p_rotation: float, p_force: Vector2) -> StaticBody2D: - var body := StaticBody2D.new() - var world_boundary := WorldBoundaryShape2D.new() - var collision_shape := CollisionShape2D.new() - collision_shape.shape = world_boundary - collision_shape.rotation = deg_to_rad(p_rotation) - body.name = "world_boundary" - body.add_child(collision_shape) - add_child(body) - return body - -func create_character(p_layer: int, p_body_shape := PhysicsTest2D.TestCollisionShape.RECTANGLE) -> CharacterBody2D: - var character = CharacterBody2D.new() - character.script = load("res://tests/nodes/CharacterBody/scripts/2d/character_body_2d_move_and_slide_with_gravity.gd") - #character.collision_layer = 0 - #character.collision_mask = 0 - character.set_collision_layer_value(p_layer, true) - character.set_collision_mask_value(p_layer, true) - var body_col: Node2D = get_default_collision_shape(p_body_shape, 2) - character.add_child(body_col) - add_child(character) - return character diff --git a/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.tscn b/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.tscn deleted file mode 100644 index 7e89059b..00000000 --- a/bin3d/tests/nodes/CollisionShape/tests/2d/world_boundary_2d.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cwjsl5we6olkq"] - -[ext_resource type="Script" path="res://tests/nodes/CollisionShape/tests/2d/world_boundary_2d.gd" id="1_jtm1r"] - -[node name="world_boundary_2d" type="Node2D"] -script = ExtResource("1_jtm1r") diff --git a/bin3d/tests/nodes/DirectSpaceState/direct_space_state_2d.tscn b/bin3d/tests/nodes/DirectSpaceState/direct_space_state_2d.tscn deleted file mode 100644 index dc50c4a6..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/direct_space_state_2d.tscn +++ /dev/null @@ -1,21 +0,0 @@ -[gd_scene load_steps=6 format=3 uid="uid://du31nbhldjjtp"] - -[ext_resource type="PackedScene" uid="uid://c8jq3yssvlovo" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_ray.tscn" id="1_0n16d"] -[ext_resource type="PackedScene" uid="uid://byf328f57nfhv" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_point.tscn" id="2_la0b3"] -[ext_resource type="PackedScene" uid="uid://bom2b1633g6fb" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_shape.tscn" id="3_wf6g0"] -[ext_resource type="PackedScene" uid="uid://o8o38bifkam6" path="res://tests/nodes/DirectSpaceState/tests/2d/cast_motion.tscn" id="4_a0mm1"] - -[sub_resource type="GDScript" id="GDScript_weqxb"] -script/source = "extends TestScene -" - -[node name="direct_space_state_2d" type="Node2D"] -script = SubResource("GDScript_weqxb") - -[node name="intersect_ray" parent="." instance=ExtResource("1_0n16d")] - -[node name="intersect_point" parent="." instance=ExtResource("2_la0b3")] - -[node name="intersect_shape" parent="." instance=ExtResource("3_wf6g0")] - -[node name="cast_motion" parent="." instance=ExtResource("4_a0mm1")] diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.gd b/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.gd deleted file mode 100644 index 0e644d7f..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.gd +++ /dev/null @@ -1,185 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks all the [PhysicsShapeQueryParameters2D] of [cast_motion] - """ - -func test_name() -> String: - return "DirectSpaceState2D | testing [cast_motion] from [get_world_2d().direct_space_state]" - -func test_start() -> void: - - # Add Area on the LEFT - var area := add_area(CENTER_LEFT) - - # Add Body on the RIGHT - var body := add_body(CENTER_RIGHT) - body.set_collision_layer_value(2, true) - body.set_collision_mask_value(2, true) - var body2 := add_body(BOTTOM_RIGHT) - - var mid_screen_width := Global.WINDOW_SIZE.x/2 - - var d_space := get_world_2d().direct_space_state - var shape_rid = PhysicsServer2D.rectangle_shape_create() - var size = Vector2(20,20) - PhysicsServer2D.shape_set_data(shape_rid, size) - - var checks_point = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame != 2: # avoid a bug in first frame - return - - if true: # limit the scope - p_monitor.add_test("Can collide with Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.collide_with_bodies = true - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, CENTER) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - var result = d_space.cast_motion(body_query) - p_monitor.add_test_result(!result.is_empty() and is_between(result, 0.0126, 0.016)) - - if true: # limit the scope - p_monitor.add_test("Return [1,1] when shape is inside a Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.collide_with_bodies = true - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, CENTER_RIGHT) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - var result = d_space.cast_motion(body_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: # limit the scope - p_monitor.add_test("Can not collide with Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.collide_with_bodies = false - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, CENTER) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - var result = d_space.cast_motion(body_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: - p_monitor.add_test("Can collide with Area") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.shape_rid = shape_rid - area_query.transform = Transform2D(0, CENTER) - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = true - var result = d_space.cast_motion(area_query) - p_monitor.add_test_result(!result.is_empty() and is_between(result, 0.0126, 0.016)) - - if true: - p_monitor.add_test("Can not collide with Area") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.shape_rid = shape_rid - area_query.transform = Transform2D(0, CENTER) - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = false - var result = d_space.cast_motion(area_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - # Can exclude a RID - if true: - p_monitor.add_test("Can exclude a Body by RID") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.transform = Transform2D(0, CENTER) - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(mid_screen_width / 0.016, 0) - exclude_rid_query.exclude = [body.get_rid()] - var result = d_space.cast_motion(exclude_rid_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: - p_monitor.add_test("Can exclude an Area by RID") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.shape_rid = shape_rid - area_query.transform = Transform2D(0, CENTER) - area_query.collide_with_areas = true - area_query.exclude = [area.get_rid()] - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - var result = d_space.cast_motion(area_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: - p_monitor.add_test("Can exclude multiple RID") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.transform = Transform2D(0, TOP_RIGHT) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(0 ,mid_screen_width / 0.016) - exclude_rid_query.exclude = [body.get_rid(), body2.get_rid()] - var result = d_space.cast_motion(exclude_rid_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: - p_monitor.add_test("Don't report collision in the wrong collision layer") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.shape_rid = shape_rid - area_query.transform = Transform2D(0, CENTER) - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = true - area_query.collision_mask = int(pow(2, 2-1)) # second layer - var result = d_space.cast_motion(area_query) - p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) - - if true: - p_monitor.add_test("Report collision in good collision layer") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, CENTER) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - body_query.collide_with_bodies = true - body_query.collision_mask = int(pow(2, 2-1)) # second layer - var result = d_space.cast_motion(body_query) - p_monitor.add_test_result(!result.is_empty() and is_between(result, 0.0126, 0.016)) - - # Rotation - if true: - p_monitor.add_test("Can apply rotation to the shape") - # Without Rotation Don't collide - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, Vector2(CENTER.x, 261-10)) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - body_query.collide_with_bodies = true - var result1 = d_space.cast_motion(body_query) - # With rotation collide - var body_query_rot := PhysicsShapeQueryParameters2D.new() - body_query_rot.shape_rid = shape_rid - body_query_rot.transform = Transform2D(deg_to_rad(45), Vector2(CENTER.x, 261-10)) - body_query_rot.motion = Vector2(mid_screen_width / 0.016, 0) - body_query_rot.collide_with_bodies = true - var result2 = d_space.cast_motion(body_query_rot) - p_monitor.add_test_result(!result1.is_empty() and !result2.is_empty() and is_eq(result1, [1,1]) and is_between(result2, 0.0126, 0.016)) - - PhysicsServer2D.free_rid(shape_rid) - p_monitor.monitor_completed() - - create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area - -func is_between(p_array: PackedFloat32Array, p_min: float, p_max: float, p_epsilon :=0.00001): - return (p_min - p_epsilon) <= p_array[0] and p_array[0] <= (p_max + p_epsilon) and (p_min - p_epsilon) <= p_array[1] and p_array[1] <= (p_max + p_epsilon) - -func is_eq(p_array: PackedFloat32Array, p_value: Array): - return p_array[0] == p_value[0] and p_array[1] == p_value[1] diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.tscn b/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.tscn deleted file mode 100644 index 1e1f4f57..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://o8o38bifkam6"] - -[ext_resource type="Script" path="res://tests/nodes/DirectSpaceState/tests/2d/cast_motion.gd" id="1_clbiv"] - -[node name="cast_motion" type="Node2D"] -script = ExtResource("1_clbiv") diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.gd b/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.gd deleted file mode 100644 index ae8cc91d..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.gd +++ /dev/null @@ -1,187 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks all the [PhysicsShapeQueryParameters2D] of [collide_shape] - """ - -func test_name() -> String: - return "DirectSpaceState2D | testing [collide_shape] from [get_world_2d().direct_space_state]" - -var result = [] -func test_start() -> void: - - # Add Area on the LEFT - var area := add_area(CENTER_LEFT) - - # Add Body on the RIGHT - var body := add_body(CENTER_RIGHT - Vector2(100, 0)) - body.set_collision_layer_value(2, true) - body.set_collision_mask_value(2, true) - var body2 := add_body(BOTTOM_RIGHT) - - var mid_screen_width := Global.WINDOW_SIZE.x/2 - - var d_space := get_world_2d().direct_space_state - var shape_rid = PhysicsServer2D.rectangle_shape_create() - var size = Vector2(20,20) - var shape_type = PhysicsServer2D.shape_get_type(shape_rid) - PhysicsServer2D.shape_set_data(shape_rid, size) - - var checks_point = func(p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame != 2: # avoid a bug in first frame - return - - if true: # limit the scope - p_monitor.add_test("Can collide with Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.collide_with_bodies = true - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, CENTER) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - result = d_space.collide_shape(body_query) - queue_redraw() - -# if true: # limit the scope -# p_monitor.add_test("Return [1,1] when shape is inside a Body") -# var body_query := PhysicsShapeQueryParameters2D.new() -# body_query.collide_with_bodies = true -# body_query.shape_rid = shape_rid -# body_query.transform = Transform2D(0, CENTER_RIGHT) -# body_query.motion = Vector2(mid_screen_width / 0.016, 0) -# var result = d_space.cast_motion(body_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: # limit the scope -# p_monitor.add_test("Can not collide with Body") -# var body_query := PhysicsShapeQueryParameters2D.new() -# body_query.collide_with_bodies = false -# body_query.shape_rid = shape_rid -# body_query.transform = Transform2D(0, CENTER) -# body_query.motion = Vector2(mid_screen_width / 0.016, 0) -# var result = d_space.cast_motion(body_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: -# p_monitor.add_test("Can collide with Area") -# var area_query := PhysicsShapeQueryParameters2D.new() -# area_query.shape_rid = shape_rid -# area_query.transform = Transform2D(0, CENTER) -# area_query.motion = Vector2(-mid_screen_width / 0.016, 0) -# area_query.collide_with_areas = true -# var result = d_space.cast_motion(area_query) -# p_monitor.add_test_result(!result.is_empty() and is_between(result, 0.0126, 0.016)) -# -# if true: -# p_monitor.add_test("Can not collide with Area") -# var area_query := PhysicsShapeQueryParameters2D.new() -# area_query.shape_rid = shape_rid -# area_query.transform = Transform2D(0, CENTER) -# area_query.motion = Vector2(-mid_screen_width / 0.016, 0) -# area_query.collide_with_areas = false -# var result = d_space.cast_motion(area_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# # Can exclude a RID -# if true: -# p_monitor.add_test("Can exclude a Body by RID") -# var exclude_rid_query := PhysicsShapeQueryParameters2D.new() -# exclude_rid_query.collide_with_bodies = true -# exclude_rid_query.transform = Transform2D(0, CENTER) -# exclude_rid_query.shape_rid = shape_rid -# exclude_rid_query.motion = Vector2(mid_screen_width / 0.016, 0) -# exclude_rid_query.exclude = [body.get_rid()] -# var result = d_space.cast_motion(exclude_rid_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: -# p_monitor.add_test("Can exclude an Area by RID") -# var area_query := PhysicsShapeQueryParameters2D.new() -# area_query.shape_rid = shape_rid -# area_query.transform = Transform2D(0, CENTER) -# area_query.collide_with_areas = true -# area_query.exclude = [area.get_rid()] -# area_query.motion = Vector2(-mid_screen_width / 0.016, 0) -# var result = d_space.cast_motion(area_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: -# p_monitor.add_test("Can exclude multiple RID") -# var exclude_rid_query := PhysicsShapeQueryParameters2D.new() -# exclude_rid_query.transform = Transform2D(0, TOP_RIGHT) -# exclude_rid_query.collide_with_bodies = true -# exclude_rid_query.shape_rid = shape_rid -# exclude_rid_query.motion = Vector2(0 ,mid_screen_width / 0.016) -# exclude_rid_query.exclude = [body.get_rid(), body2.get_rid()] -# var result = d_space.cast_motion(exclude_rid_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: -# p_monitor.add_test("Don't report collision in the wrong collision layer") -# var area_query := PhysicsShapeQueryParameters2D.new() -# area_query.shape_rid = shape_rid -# area_query.transform = Transform2D(0, CENTER) -# area_query.motion = Vector2(-mid_screen_width / 0.016, 0) -# area_query.collide_with_areas = true -# area_query.collision_mask = pow(2, 2-1) # second layer -# var result = d_space.cast_motion(area_query) -# p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1])) -# -# if true: -# p_monitor.add_test("Report collision in good collision layer") -# var body_query := PhysicsShapeQueryParameters2D.new() -# body_query.shape_rid = shape_rid -# body_query.transform = Transform2D(0, CENTER) -# body_query.motion = Vector2(mid_screen_width / 0.016, 0) -# body_query.collide_with_bodies = true -# body_query.collision_mask = pow(2, 2-1) # second layer -# var result = d_space.cast_motion(body_query) -# p_monitor.add_test_result(!result.is_empty() and is_between(result, 0.0126, 0.016)) -# -# # Rotation -# if true: -# p_monitor.add_test("Can apply rotation to the shape") -# # Without Rotation Don't collide -# var body_query := PhysicsShapeQueryParameters2D.new() -# body_query.shape_rid = shape_rid -# body_query.transform = Transform2D(0, Vector2(CENTER.x, 261-10)) -# body_query.motion = Vector2(mid_screen_width / 0.016, 0) -# body_query.collide_with_bodies = true -# var result1 = d_space.cast_motion(body_query) -# # With rotation collide -# var body_query_rot := PhysicsShapeQueryParameters2D.new() -# body_query_rot.shape_rid = shape_rid -# body_query_rot.transform = Transform2D(deg_to_rad(45), Vector2(CENTER.x, 261-10)) -# body_query_rot.motion = Vector2(mid_screen_width / 0.016, 0) -# body_query_rot.collide_with_bodies = true -# var result2 = d_space.cast_motion(body_query_rot) -# p_monitor.add_test_result(!result1.is_empty() and !result2.is_empty() and is_eq(result1, [1,1]) and is_between(result2, 0.0126, 0.016)) - - PhysicsServer2D.free_rid(shape_rid) - #p_monitor.monitor_completed() - - var check_max_stability_monitor := create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area - -func _process(delta: float) -> void: - queue_redraw() -func _draw() -> void: - for col in result: - draw_circle(col, 1, Color.RED) diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.tscn b/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.tscn deleted file mode 100644 index 0e5704b5..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/collide_shape.tscn +++ /dev/null @@ -1,13 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://gm2tqd86yds4"] - -[ext_resource type="Script" path="res://tests/nodes/DirectSpaceState/tests/2d/collide_shape.gd" id="1_7nci6"] - -[sub_resource type="RectangleShape2D" id="RectangleShape2D_88710"] -size = Vector2(40, 40) - -[node name="collide_shape" type="Node2D"] -script = ExtResource("1_7nci6") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2(800, 320) -shape = SubResource("RectangleShape2D_88710") diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.gd b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.gd deleted file mode 100644 index efcbad36..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.gd +++ /dev/null @@ -1,222 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks all the [PhysicsPointQueryParameters2D] of [intersect_point] - """ - -func test_name() -> String: - return "DirectSpaceState2D | testing [intersect_point] from [get_world_2d().direct_space_state]" - -func test_start() -> void: - - # Add Area on the LEFT - var area := add_area(CENTER_LEFT) - - # Add Body on the RIGHT - var body := add_body(CENTER_RIGHT) - body.set_collision_layer_value(2, true) - body.set_collision_mask_value(2, true) - - # Add two body in the center - add_area(CENTER) - add_body(CENTER) - add_area(CENTER) - add_body(CENTER) - - # Add Canvas Layers - var canvas := CanvasLayer.new() - canvas.layer = 1 - var canvas_area := add_area(TOP_CENTER, false) - canvas.add_child(canvas_area) - add_child(canvas) - - var canvas2 := CanvasLayer.new() - canvas2.layer = 2 - var canvas_area2 := add_area(TOP_CENTER, false) - canvas2.add_child(canvas_area2) - add_child(canvas2) - - var canvas3 := CanvasLayer.new() - canvas3.layer = 3 - var canvas_area3 := add_area(TOP_CENTER, false) - canvas3.add_child(canvas_area3) - add_child(canvas3) - - var canvas_empty := CanvasLayer.new() - canvas_empty.layer = 4 - add_child(canvas_empty) - - var d_space := get_world_2d().direct_space_state - var checks_point = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame != 2: # avoid a bug in first frame - return - - if true: # limit the scope - p_monitor.add_test("Don't collide at 1px left from the body") - var body_query := PhysicsPointQueryParameters2D.new() - body_query.position = CENTER_RIGHT - (Vector2(51,0)) # Rectangle is 100px wide - body_query.collide_with_bodies = true - var result := d_space.intersect_point(body_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Can collide with Body at the left border") - var body_query := PhysicsPointQueryParameters2D.new() - body_query.position = CENTER_RIGHT - (Vector2(50,0)) - body_query.collide_with_bodies = true - var result := d_space.intersect_point(body_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 1) - - if true: - p_monitor.add_test("Can not collide with Body") - var body_query := PhysicsPointQueryParameters2D.new() - body_query.position = CENTER_RIGHT - body_query.collide_with_bodies = false - var result := d_space.intersect_point(body_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Can collide with Area") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER_LEFT - area_query.collide_with_areas = true - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 1) - - if true: - p_monitor.add_test("Can not collide with Area") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER_LEFT - area_query.collide_with_areas = false - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - # Can exclude a RID - if true: - p_monitor.add_test("Can exclude a Body by RID") - var exclude_rid_query := PhysicsPointQueryParameters2D.new() - exclude_rid_query.position = CENTER_RIGHT - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.exclude = [body.get_rid()] - var result := d_space.intersect_point(exclude_rid_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Can exclude an Area by RID") - var exclude_rid_query := PhysicsPointQueryParameters2D.new() - exclude_rid_query.position = CENTER_LEFT - exclude_rid_query.collide_with_areas = true - exclude_rid_query.exclude = [area.get_rid()] - var result := d_space.intersect_point(exclude_rid_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - # Canvas Layer - if true: - p_monitor.add_test("Should not detect a collision outside the canvas") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER_LEFT - area_query.collide_with_areas = true - area_query.canvas_instance_id = canvas.get_instance_id() - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Should not detect a collision inside the empty canvas") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = TOP_CENTER - area_query.collide_with_areas = true - area_query.canvas_instance_id = canvas_empty.get_instance_id() - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Should detect one collision inside the canvas") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = TOP_CENTER - area_query.collide_with_areas = true - area_query.canvas_instance_id = canvas2.get_instance_id() - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - var correct_result = false - if result_count > 1: - p_monitor.add_test_error("Found too many results.") - for index in range(result_count): - var collider: CollisionObject2D = result[index].collider - if collider.get_canvas() == canvas2.get_canvas(): - correct_result = true - else: - p_monitor.add_test_error("Found a result in the wrong canvas layer.") - p_monitor.add_test_result(result_count == 1 && correct_result) - - if true: - p_monitor.add_test("Can detect multiple collision") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER - area_query.collide_with_bodies = true - area_query.collide_with_areas = true - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 4) - - if true: - p_monitor.add_test("Can limit multiple collision") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER - area_query.collide_with_bodies = true - area_query.collide_with_areas = true - var result := d_space.intersect_point(area_query, 2) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 2) - - if true: - p_monitor.add_test("Don't report collision in the wrong collision layer") - var area_query := PhysicsPointQueryParameters2D.new() - area_query.position = CENTER_LEFT - area_query.collide_with_areas = true - area_query.collision_mask = int(pow(2, 2-1)) # second layer - var result := d_space.intersect_point(area_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 0) - - if true: - p_monitor.add_test("Report collision in good collision layer") - var body_query := PhysicsPointQueryParameters2D.new() - body_query.position = CENTER_RIGHT # Rectangle is 100px wide - body_query.collide_with_bodies = true - body_query.collision_mask = int(pow(2, 2-1)) # second layer - var result := d_space.intersect_point(body_query) - var result_count = result.size() if result else 0 - p_monitor.add_test_result(result_count == 1) - - p_monitor.monitor_completed() - - create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area - diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.tscn b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.tscn deleted file mode 100644 index 6e31cb0a..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_point.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://byf328f57nfhv"] - -[ext_resource type="Script" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_point.gd" id="1_w7mhd"] - -[node name="intersect_point" type="Node2D"] -script = ExtResource("1_w7mhd") diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.gd b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.gd deleted file mode 100644 index 79d78e9e..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.gd +++ /dev/null @@ -1,123 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks all the [PhysicsRayQueryParameters2D] of [intersect_ray] - """ - -func test_name() -> String: - return "DirectSpaceState2D | testing [intersect_ray] from [get_world_2d().direct_space_state]" - -func test_start() -> void: - - # Add Area - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = CENTER_LEFT - add_child(area) - - # Add Body - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4) - body.set_collision_layer_value(2, true) - body.set_collision_mask_value(2, true) - body.add_child(body_shape) - body.position = CENTER_RIGHT - add_child(body) - - var d_space := get_world_2d().direct_space_state - var checks_ray = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame != 2: # avoid a bug in first frame - return - - if true: # limit the scope - p_monitor.add_test("Can collide with Body") - var body_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_RIGHT) - body_query.collide_with_bodies = true - var collide = true if d_space.intersect_ray(body_query) else false - p_monitor.add_test_result(collide) - - if true: - p_monitor.add_test("Can not collide with Body") - var body_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_RIGHT) - body_query.collide_with_bodies = false - var collide = true if d_space.intersect_ray(body_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can collide with Area") - var area_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_LEFT) - area_query.collide_with_areas = true - var collide = true if d_space.intersect_ray(area_query) else false - p_monitor.add_test_result(collide) - - if true: - p_monitor.add_test("Can not collide with Area") - var area_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_LEFT) - area_query.collide_with_areas = false - var collide = true if d_space.intersect_ray(area_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Detects Hit from inside") - var hit_inside_query := PhysicsRayQueryParameters2D.create(CENTER_RIGHT, CENTER) - hit_inside_query.collide_with_bodies = true - hit_inside_query.hit_from_inside = true - var collide = true if d_space.intersect_ray(hit_inside_query) else false - p_monitor.add_test_result(collide) - - if true: - p_monitor.add_test("Can NOT detects Hit from inside") - var hit_inside_query := PhysicsRayQueryParameters2D.create(CENTER_RIGHT, CENTER) - hit_inside_query.collide_with_bodies = true - hit_inside_query.hit_from_inside = false - var collide = true if d_space.intersect_ray(hit_inside_query) else false - p_monitor.add_test_result(not collide) - - # Can exclude a RID - if true: - p_monitor.add_test("Can exclude a Body by RID") - var exclude_rid_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_RIGHT) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.exclude = [body.get_rid()] - var collide = true if d_space.intersect_ray(exclude_rid_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can exclude an Area by RID") - var exclude_rid_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_LEFT) - exclude_rid_query.collide_with_areas = true - exclude_rid_query.exclude = [area.get_rid()] - var collide = true if d_space.intersect_ray(exclude_rid_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can exclude multiple RID") - var exclude_rid_query := PhysicsRayQueryParameters2D.create(CENTER_LEFT, CENTER_RIGHT) - exclude_rid_query.collide_with_areas = true - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.hit_from_inside = true - exclude_rid_query.exclude = [body.get_rid(), area.get_rid()] - var collide = true if d_space.intersect_ray(exclude_rid_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Don't report collision in the wrong collision layer") - var area_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_LEFT) - area_query.collide_with_areas = true - area_query.collision_mask = int(pow(2, 2-1)) # second layer - var collide = true if d_space.intersect_ray(area_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Report collision in good collision layer") - var body_query := PhysicsRayQueryParameters2D.create(CENTER, CENTER_RIGHT) - body_query.collide_with_bodies = true - body_query.collision_mask = int(pow(2, 2-1)) # second layer - var collide = true if d_space.intersect_ray(body_query) else false - p_monitor.add_test_result(collide) - - p_monitor.monitor_completed() - - var _check_max_stability_monitor := create_generic_manual_monitor(self, checks_ray, simulation_duration) diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.tscn b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.tscn deleted file mode 100644 index ec8148df..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_ray.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://c8jq3yssvlovo"] - -[ext_resource type="Script" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_ray.gd" id="1_qsxiu"] - -[node name="intersect_ray" type="Node2D"] -script = ExtResource("1_qsxiu") diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.gd b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.gd deleted file mode 100644 index 532e5c01..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.gd +++ /dev/null @@ -1,189 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10 - -func test_description() -> String: - return """Checks all the [PhysicsShapeQueryParameters2D] of [intersect_shape] - """ - -func test_name() -> String: - return "DirectSpaceState2D | testing [intersect_shape] from [get_world_2d().direct_space_state]" - -func test_start() -> void: - - var mid_screen_width := Global.WINDOW_SIZE.x/2 - - # Add Area on the LEFT - var area := add_area(CENTER_LEFT) - - # Add Body on the RIGHT - var body := add_body(CENTER_RIGHT) - body.set_collision_layer_value(2, true) - body.set_collision_mask_value(2, true) - var body2 := add_body(BOTTOM_RIGHT) - - var d_space := get_world_2d().direct_space_state - var shape_rid = PhysicsServer2D.rectangle_shape_create() - var size = Vector2(20,20) - PhysicsServer2D.shape_set_data(shape_rid, size) - - var checks_point = func(_p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - if p_monitor.frame != 2: # avoid a bug in first frame - return - - if true: # limit the scope - p_monitor.add_test("Can collide with Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.transform = Transform2D(0, CENTER) - body_query.collide_with_bodies = true - body_query.shape_rid = shape_rid - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - var collide = true if d_space.intersect_shape(body_query) else false - p_monitor.add_test_result(collide) - - if true: # limit the scope - p_monitor.add_test("Can not collide with Body") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.transform = Transform2D(0, CENTER) - body_query.collide_with_bodies = false - body_query.shape_rid = shape_rid - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - var collide = true if d_space.intersect_shape(body_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can collide with Area") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.transform = Transform2D(0, CENTER) - area_query.shape_rid = shape_rid - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = true - var collide = true if d_space.intersect_shape(area_query) else false - p_monitor.add_test_result(collide) - - if true: - p_monitor.add_test("Can not collide with Area") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.transform = Transform2D(0, CENTER) - area_query.shape_rid = shape_rid - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = false - var collide = true if d_space.intersect_shape(area_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can detects multiple collision") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.transform = Transform2D(0, TOP_RIGHT) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(0, BOTTOM_CENTER.y / 0.016) - var result := d_space.intersect_shape(exclude_rid_query) - p_monitor.add_test_result(result.size() == 2) - - if true: - p_monitor.add_test("Can limit result multiple collision") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.transform = Transform2D(0, TOP_RIGHT) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(0, BOTTOM_CENTER.y / 0.016) - var result := d_space.intersect_shape(exclude_rid_query, 1) - p_monitor.add_test_result(result.size() == 1) - - # Can exclude a RID - if true: - p_monitor.add_test("Can exclude a Body by RID") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.transform = Transform2D(0, CENTER) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(CENTER_RIGHT / 0.016) - exclude_rid_query.exclude = [body.get_rid()] - var collide = true if d_space.intersect_shape(exclude_rid_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can exclude an Area by RID") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.transform = Transform2D(0, CENTER) - area_query.shape_rid = shape_rid - area_query.collide_with_areas = true - area_query.exclude = [area.get_rid()] - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - var collide = true if d_space.intersect_shape(area_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Can exclude multiple RID") - var exclude_rid_query := PhysicsShapeQueryParameters2D.new() - exclude_rid_query.transform = Transform2D(0, TOP_RIGHT) - exclude_rid_query.collide_with_bodies = true - exclude_rid_query.shape_rid = shape_rid - exclude_rid_query.motion = Vector2(BOTTOM_CENTER.x / 0.016, 0) - exclude_rid_query.exclude = [body.get_rid(), body2.get_rid()] - var collide = true if d_space.intersect_shape(exclude_rid_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Don't report collision in the wrong collision layer") - var area_query := PhysicsShapeQueryParameters2D.new() - area_query.transform = Transform2D(0, CENTER) - area_query.shape_rid = shape_rid - area_query.motion = Vector2(-mid_screen_width / 0.016, 0) - area_query.collide_with_areas = true - area_query.collision_mask = int(pow(2, 2-1)) # second layer - var collide = true if d_space.intersect_shape(area_query) else false - p_monitor.add_test_result(not collide) - - if true: - p_monitor.add_test("Report collision in good collision layer") - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.transform = Transform2D(0, CENTER) - body_query.shape_rid = shape_rid - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - body_query.collide_with_bodies = true - body_query.collision_mask = int(pow(2, 2-1)) # second layer - var collide = true if d_space.intersect_shape(body_query) else false - p_monitor.add_test_result(collide) - - # Rotation - if true: - p_monitor.add_test("Can apply rotation to the shape") - # Without Rotation Don't collide - var body_query := PhysicsShapeQueryParameters2D.new() - body_query.shape_rid = shape_rid - body_query.transform = Transform2D(0, Vector2(CENTER.x, 261-10)) - body_query.motion = Vector2(mid_screen_width / 0.016, 0) - body_query.collide_with_bodies = true - var collide1 = true if d_space.intersect_shape(body_query) else false - # With rotation collide - var body_query_rot := PhysicsShapeQueryParameters2D.new() - body_query_rot.shape_rid = shape_rid - body_query_rot.transform = Transform2D(deg_to_rad(45), Vector2(CENTER.x, 261-10)) - body_query_rot.motion = Vector2(mid_screen_width / 0.016, 0) - body_query_rot.collide_with_bodies = true - var collide2 = true if d_space.intersect_shape(body_query_rot) else false - p_monitor.add_test_result(not collide1 and collide2) - - PhysicsServer2D.free_rid(shape_rid) - p_monitor.monitor_completed() - - create_generic_manual_monitor(self, checks_point, simulation_duration) - -func add_body(p_position: Vector2, p_add_child := true) -> StaticBody2D: - var body := StaticBody2D.new() - var body_shape := PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4) - body.add_child(body_shape) - body.position = p_position - if p_add_child: - add_child(body) - return body - -func add_area(p_position: Vector2, p_add_child := true) -> Area2D: - var area := Area2D.new() - area.add_child(PhysicsTest2D.get_default_collision_shape(PhysicsTest2D.TestCollisionShape.RECTANGLE, 4)) - area.position = p_position - if p_add_child: - add_child(area) - return area diff --git a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.tscn b/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.tscn deleted file mode 100644 index c779928f..00000000 --- a/bin3d/tests/nodes/DirectSpaceState/tests/2d/intersect_shape.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bom2b1633g6fb"] - -[ext_resource type="Script" path="res://tests/nodes/DirectSpaceState/tests/2d/intersect_shape.gd" id="1_egbqd"] - -[node name="intersect_shape" type="Node2D"] -script = ExtResource("1_egbqd") diff --git a/bin3d/tests/nodes/Raycast/raycast_2d.tscn b/bin3d/tests/nodes/Raycast/raycast_2d.tscn deleted file mode 100644 index 8809f241..00000000 --- a/bin3d/tests/nodes/Raycast/raycast_2d.tscn +++ /dev/null @@ -1,9 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://x40dqk57sgfk"] - -[ext_resource type="PackedScene" uid="uid://d2qj82urtqssc" path="res://tests/nodes/Raycast/tests/collision_detection.tscn" id="1_d6q40"] -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_r165l"] - -[node name="raycast_2d" type="Node2D"] -script = ExtResource("1_r165l") - -[node name="collision_detection" parent="." instance=ExtResource("1_d6q40")] diff --git a/bin3d/tests/nodes/Raycast/tests/collision_detection.gd b/bin3d/tests/nodes/Raycast/tests/collision_detection.gd deleted file mode 100644 index 50867752..00000000 --- a/bin3d/tests/nodes/Raycast/tests/collision_detection.gd +++ /dev/null @@ -1,91 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := .5 - -func test_description() -> String: - return """Checks that [Raycast2D] collisions work correctly with all parameters [exclude_parent], - [hit_from_inside], [enabled]""" - -func test_name() -> String: - return "Raycast2D | testing collision" - -func test_start() -> void: - - var ray_lambda = func(p_target: RigidBody2D, p_monitor: Monitor): - - var ray1 = p_target.get_child(1) # from up - if ray1.is_colliding(): - p_monitor.error_message = "Raycast not entabled should not collidee" - return false - var ray2 = p_target.get_child(2) # from up - if not ray2.is_colliding(): - p_monitor.error_message = "Raycast from up to bottom should collide" - return false - var ray3 = p_target.get_child(3) # from up excluded - - if ray3.is_colliding(): - p_monitor.error_message = "Raycast from up to bottom with [exclude parent] ON should not collide" - return false - var ray4 = p_target.get_child(4) # inside - if not ray4.is_colliding(): - p_monitor.error_message = "Raycast inside with [hit inside] ON should collide" - return false - var ray5 = p_target.get_child(5) # inside without hit inside - if ray5.is_colliding(): - p_monitor.error_message = "Raycast inside with [hit inside] OFF should not collide" - return false - - if p_target.name != "Concave Polygon": # not true because of concave decomposition - var ray6 = p_target.get_child(6) # from center to bottom - if ray6.is_colliding(): - p_monitor.error_message = "Raycast from center to bottom with [hit inside] OFF should not collide" - return false - - var ray7 = p_target.get_child(7) - if not ray7.is_colliding(): - p_monitor.error_message = "Raycast from center to bottom with [hit inside] OFF should collide with the bottom box" - return false - - return true - - var offset := (Global.WINDOW_SIZE.x) / (PhysicsTest2D.TestCollisionShape.values().size() -1) - var cpt := 0 - var bottom_box := PhysicsTest2D.get_static_body_with_collision_shape(Rect2(Vector2(600, 600), Vector2(850,20)), PhysicsTest2D.TestCollisionShape.RECTANGLE) - bottom_box.position = Vector2(500, 600) - add_child(bottom_box) - for shape_type in PhysicsTest2D.TestCollisionShape.values(): - if shape_type == PhysicsTest2D.TestCollisionShape.WORLD_BOUNDARY or shape_type == PhysicsTest2D.TestCollisionShape.CONCAVE_SEGMENT: - continue - var body := create_rigid_body(Vector2(100 + offset * cpt, CENTER.y), shape_type) - body.name = PhysicsTest2D.shape_name(shape_type) - var monitor := create_generic_expiration_monitor(body, ray_lambda, null, simulation_duration) - monitor.test_name = "Testing Raycast collision with %s" % [PhysicsTest2D.shape_name(shape_type)] - cpt += 1 - -func create_rigid_body(p_position: Vector2, p_collision_shape: PhysicsTest2D.TestCollisionShape) -> RigidBody2D: - var body := RigidBody2D.new() - body.gravity_scale = 0 - body.add_child(PhysicsTest2D.get_default_collision_shape(p_collision_shape, 6)) - body.position = p_position - add_child(body) - - create_raycast(body, Vector2(10, -200), 200, true, false, false) # up from center not enabled - create_raycast(body, Vector2(-20, -200), 200) # up from center - create_raycast(body, Vector2(20, -200), 200, false, true) # up from center but exclude parent - create_raycast(body, Vector2(-20, 10), 10, true) # inside with hit - create_raycast(body, Vector2(20, 10), 10) # inside without hit - create_raycast(body, Vector2(-3,0), 200) # center from outside - create_raycast(body, Vector2(3,0), 300) # center with hit outside - - return body - -func create_raycast(p_parent: RigidBody2D, p_position: Vector2, p_size: int, p_hit_from_inside := false, p_exclude_parent := false, enabled := true) -> RayCast2D: - var ray := RayCast2D.new() - ray.position = p_position - ray.is_colliding() - ray.enabled = enabled - ray.exclude_parent = p_exclude_parent - ray.target_position = Vector2(0, p_size) - ray.hit_from_inside = p_hit_from_inside - p_parent.add_child(ray) - return ray diff --git a/bin3d/tests/nodes/Raycast/tests/collision_detection.tscn b/bin3d/tests/nodes/Raycast/tests/collision_detection.tscn deleted file mode 100644 index 31461392..00000000 --- a/bin3d/tests/nodes/Raycast/tests/collision_detection.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://d2qj82urtqssc"] - -[ext_resource type="Script" path="res://tests/nodes/Raycast/tests/collision_detection.gd" id="1_b4kw5"] - -[node name="collision_detection" type="Node2D"] -script = ExtResource("1_b4kw5") diff --git a/bin3d/tests/nodes/RigidBody/rigid_body_2d.tscn b/bin3d/tests/nodes/RigidBody/rigid_body_2d.tscn deleted file mode 100644 index 52f3cfa4..00000000 --- a/bin3d/tests/nodes/RigidBody/rigid_body_2d.tscn +++ /dev/null @@ -1,27 +0,0 @@ -[gd_scene load_steps=8 format=3 uid="uid://jd2c3mg4v3bh"] - -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_6eclx"] -[ext_resource type="PackedScene" uid="uid://bxrk6vpptw3in" path="res://tests/nodes/RigidBody/tests/2d/rectangle_stack.tscn" id="1_cclgc"] -[ext_resource type="PackedScene" uid="uid://3o0nkl6b4h10" path="res://tests/nodes/RigidBody/tests/2d/maximum_rectangle.tscn" id="2_p0tuo"] -[ext_resource type="PackedScene" uid="uid://7usnv0hqg67g" path="res://tests/nodes/RigidBody/tests/2d/continuous_detection.tscn" id="3_2mxd6"] -[ext_resource type="PackedScene" uid="uid://nqktmpb0a6er" path="res://tests/nodes/RigidBody/tests/2d/contact_monitor.tscn" id="4_n6ed2"] -[ext_resource type="PackedScene" uid="uid://bn1ox1w8nnydx" path="res://tests/nodes/RigidBody/tests/2d/rectangle_pyramid.tscn" id="6_wt8n6"] -[ext_resource type="PackedScene" uid="uid://c8rd0ut3utr8l" path="res://tests/nodes/RigidBody/tests/2d/basic_api.tscn" id="7_8ojwc"] - -[node name="rigid_dynamic_body_2d" type="Node2D"] -script = ExtResource("1_6eclx") - -[node name="rectangle_stack" parent="." instance=ExtResource("1_cclgc")] - -[node name="maximum_rectangle" parent="." instance=ExtResource("2_p0tuo")] - -[node name="continuous_detection_box" parent="." instance=ExtResource("3_2mxd6")] - -[node name="continuous_detection_concave" parent="." instance=ExtResource("3_2mxd6")] -wall_type = 1 - -[node name="contact_monitor" parent="." instance=ExtResource("4_n6ed2")] - -[node name="rectangle_pyramid" parent="." instance=ExtResource("6_wt8n6")] - -[node name="basic_api" parent="." instance=ExtResource("7_8ojwc")] diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.gd b/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.gd deleted file mode 100644 index fa2e8e0f..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.gd +++ /dev/null @@ -1,471 +0,0 @@ -extends PhysicsUnitTest2D - -var simulation_duration := 10.0 - -func test_description() -> String: - return """Checks the basic API for [RigidBody2D] - """ - -func test_name() -> String: - return "RigidBody2D | testing the basic API" - -var test_layer := 0 - -var dt := 1.0/60.0 -var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") - -func test_start() -> void: - - # Bug where you can't change the position two time - if true: - var body := create_rigid_body(next_test_layer(), Vector2(-2000, - 2000)) - - body.position = Vector2(-1000, -1000) - - var position_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 1: - p_monitor.add_test("Position can be change properly") - var success:= p_target.position == Vector2(-1000, -1000) - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - create_generic_manual_monitor(body, position_test, simulation_duration) - if true: - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - body.gravity_scale = 1 - - var gravity_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - # Apply the force 20 frames - if p_monitor.frame == 20: - var travel = p_target.position - p_monitor.data["position"] - var expected = 0.5 * Vector2(0, gravity) * pow((dt * 20.0), 2) # x(t) = (1/2)at2 + v0t + x0 - p_monitor.add_test("Gravity is applied properly") - var success:= Utils.vec2_equals(travel, expected, 6) - if not success: - p_monitor.add_test_error("Gravity is not applied properly, expected %v, get %v" % [expected, travel]) - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - var monitor := create_generic_manual_monitor(body, gravity_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - body.gravity_scale = 0 - body.mass = 10 - - var gravity_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - # Apply the force 20 frames - if p_monitor.frame == 20: - p_monitor.add_test("Gravity scale works") - var success:= Utils.vec2_equals(p_target.position, p_monitor.data["position"]) - p_monitor.add_test_result(success) - - p_monitor.monitor_completed() - var monitor = create_generic_manual_monitor(body, gravity_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - var test_position = next_test_position() - var current_layer = next_test_layer() - var body := create_rigid_body(current_layer, test_position) - body.gravity_scale = 1 - body.mass = 10 - create_static_body(current_layer, test_position + Vector2(20, 50)) - - var rotation_test = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - return body.rotation != 0 - - var monitor := create_generic_expiration_monitor(self, rotation_test, null, 0.5) - monitor.test_name = "Rotation works" - - if true: - var test_position = next_test_position() - var current_layer = next_test_layer() - var body := create_rigid_body(current_layer, test_position) - body.gravity_scale = 1 - body.lock_rotation = true - body.mass = 10 - var static_body := create_static_body(current_layer, test_position) - static_body.position += Vector2(20, 50) - - var lock_rotation_test = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - return body.rotation == 0 - - var monitor := create_generic_expiration_monitor(self, lock_rotation_test, null, 0.5) - monitor.test_name = "Lock_rotation works" - - if true: - var test_position = next_test_position() - var current_layer = next_test_layer() - var body1 := create_rigid_body(current_layer, test_position) - body1.position += Vector2(-20, 0) - body1.gravity_scale = 1 - body1.can_sleep = true - - var body2 := create_rigid_body(current_layer, test_position) - body2.position += Vector2(20, 0) - body2.gravity_scale = 1 - body2.can_sleep = false - - var static_body := create_static_body(current_layer, test_position, 3) - static_body.position += Vector2(0, 100) - - var sleep_test = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - return body1.sleeping and not body2.sleeping - - var monitor := create_generic_expiration_monitor(self, sleep_test, null, 1) - monitor.test_name = "Can sleep works" - - if true: - var test_position = next_test_position() - var current_layer = next_test_layer() - var next_layer = next_test_layer() - var body1 := create_rigid_body(current_layer, test_position) - body1.position += Vector2(-30, 0) - body1.gravity_scale = 1 - - var body2 := create_rigid_body(current_layer, test_position) - body2.position += Vector2(-0, 0) - body2.gravity_scale = 1 - body2.set_collision_mask_value(next_layer, true) - - var static_body := create_static_body(next_layer, test_position + Vector2(0, 80), 3) - - var mask_test = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - return body1.position.y > static_body.position.y and body2.position.y < static_body.position.y - - var monitor := create_generic_expiration_monitor(self, mask_test, null, 1) - monitor.test_name = "Layers and masks works" - - if true: - # Check constant central force API - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - body.mass = 10 - - var constant_central_force_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.add_constant_central_force(Vector2(100, 0)) - p_target.add_constant_central_force(Vector2(100, 0)) - # Apply the force 20 frames - if p_monitor.frame == 22: - var travel = p_target.position - p_monitor.data["position"] - var expected = 0.5 * Vector2(200, 0) * pow((dt * 20), 2) / 10 # x(t) = (1/2)at2 + v0t + x0 - p_monitor.add_test("Constant force is applied") - var success:= Utils.vec2_equals(travel, expected, 1) - if not success: - p_monitor.add_test_error("Constant central force is not applied correctly: expected %v, get %v" % [expected, travel]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 23: - p_monitor.add_test("Constant force can be retrieved") - var success := p_target.constant_force == Vector2(200, 0) - if not success: - p_monitor.add_test_error("Constant central force is not retrieved correctly: expected %v, get %v" % [Vector2(200, 0), p_target.constant_force]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 24: - p_target.constant_force = Vector2.ZERO # Reset the constant force - - if p_monitor.frame == 25: - p_monitor.add_test("Constant force can be removed") - var success := p_target.constant_force == Vector2.ZERO - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - - var monitor := create_generic_manual_monitor(body, constant_central_force_test, simulation_duration) - monitor.data["position"] = test_position - - # TO DO: check with the right formula - if true: - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer()) - body.global_position = test_position + Vector2(0, 200) - - var force_position_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.add_constant_force(Vector2(200, 0), Vector2(0, 5)) - # Apply the force 20 frames - if p_monitor.frame == 22: - var travel = p_target.position - p_monitor.data["position"] - var expected = 0.5 * Vector2(200, 0) * pow((dt * 20), 2) # x(t) = (1/2)at2 + v0t + x0 - p_monitor.add_test("Constant force at specific position is applied") - var success:= Utils.f_equals(travel.x, expected.x, 1) and p_target.rotation != 0 - if not success: - p_monitor.add_test_error("Constant force at specific position is not applied correctly: expected %f, get %f, rotation %f" % [expected.x, travel.x, p_target.rotation]) - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - - var monitor := create_generic_manual_monitor(body, force_position_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - - var force_position_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame <= 20: - p_target.apply_force(Vector2(200, 0), Vector2(0,5)) - # Apply the force 20 frames - if p_monitor.frame == 21: - var travel = p_target.position - p_monitor.data["position"] - var expected := 0.5 * Vector2(200, 0) * pow((dt * 20), 2) # x(t) = (1/2)at2 + v0t + x0 - p_monitor.add_test("Apply force at specific position is applied") - var success:= Utils.f_equals(travel.x, expected.x, 0.6) and p_target.rotation != 0 - if not success: - p_monitor.add_test_error("apply force at specific position is not applied correctly: expected %f, get %f, rotation %f" % [expected.x, travel.x, p_target.rotation]) - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - - var monitor := create_generic_manual_monitor(body, force_position_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - # Check impulse force API - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - - var force_impulse_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.apply_central_impulse(Vector2(200, 0)) - # Apply the force 20 frames - if p_monitor.frame == 22: - var travel = p_target.position - p_monitor.data["position"] - var expected = Vector2(200, 0) * dt * 20 # x(t) = at + v0t + x0 - p_monitor.add_test("Force impulse is applied") - var success:= Utils.vec2_equals(travel, expected, 0.01) - if not success: - p_monitor.add_test_error("Force impulse is not applied correctly: expected %v, get %v" % [expected, travel]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 23: - p_monitor.add_test("Linear velocity can be retrieved") - var success := p_target.linear_velocity == Vector2(200, 0) - if not success: - p_monitor.add_test_error("Linear velocity is not retrieved correctly: expected %v, get %v" % [Vector2(200, 0), p_target.constant_force]) - p_monitor.add_test_result(success) - - p_monitor.monitor_completed() - var monitor := create_generic_manual_monitor(body, force_impulse_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - # Check impulse force API 2 - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - body.mass = 10 - - var force_impulse_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.apply_central_impulse(Vector2(200, 0)) - # Apply the force 20 frames - if p_monitor.frame == 22: - var travel = p_target.position - p_monitor.data["position"] - var expected = Vector2(200, 0) * dt * 20 / 10 # x(t) = at + v0t + x0 - p_monitor.add_test("Force impulse with mass is applied") - var success:= Utils.vec2_equals(travel, expected, 0.01) - if not success: - p_monitor.add_test_error("Force impulse with mass is not applied correctly: expected %v, get %v" % [expected, travel]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 23: - p_monitor.add_test("Linear velocity can be retrieved from with mass") - var success := p_target.linear_velocity == Vector2(20, 0) - if not success: - p_monitor.add_test_error("Linear velocity is not retrieved from with mass correctly: expected %v, get %v" % [Vector2(200, 0), p_target.constant_force]) - p_monitor.add_test_result(success) - - p_monitor.monitor_completed() - var monitor := create_generic_manual_monitor(body, force_impulse_test, simulation_duration) - monitor.data["position"] = test_position - -# TO DO: verify this test - if true: - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - - var force_impulse_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: # first frame is not good because inv_inertia = 0 - p_target.apply_impulse(Vector2(200, 0), Vector2(0, 5)) - # Apply the force 20 frames - if p_monitor.frame == 22: - var travel = p_target.position - p_monitor.data["position"] - var expected = Vector2(200, 0) * dt * 20 # x(t) = at + v0t + x0 - p_monitor.add_test("Force impulse at specific position is applied") - var success:= Utils.vec2_equals(travel, expected, 0.01) and p_target.rotation != 0 - if not success: - p_monitor.add_test_error("Force impulse at specific position is not applied correctly: expected %f, get %f, rotation %f" % [expected.x, travel.x, p_target.rotation]) - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - var monitor := create_generic_manual_monitor(body, force_impulse_test, simulation_duration) - monitor.data["position"] = test_position - - if true: - # Constant Torque - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - - var constant_torque_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.add_constant_torque(500) - # Apply the force 20 frames - if p_monitor.frame == 22: - p_monitor.add_test("Constant torque is applied") - var inertia : float = PhysicsServer2D.body_get_param(p_target.get_rid(), PhysicsServer2D.BODY_PARAM_INERTIA) - var expected = 0.5 * (500.0 / inertia) * pow((dt * 20.0), 2.0) # x(t) = (1/2)at2 + v0t + x0 - var result = p_target.rotation - var success:= Utils.f_equals(result, expected, 0.02) - if not success: - p_monitor.add_test_error("Constant torque is not applied correctly: expected %f, get %f" % [expected, result]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 23: - p_monitor.add_test("Constant torque can be retrieved") - var success := p_target.constant_torque == 500 - if not success: - p_monitor.add_test_error("Constant torque is not retrieved correctly: expected %f, get %f" % [50, p_target.constant_torque]) - p_monitor.add_test_result(success) - - if p_monitor.frame == 23: - p_target.constant_torque = 0# Reset the constant torque - - if p_monitor.frame == 24: - p_monitor.add_test("Constant torque can be removed") - var success := p_target.constant_torque == 0 - p_monitor.add_test_result(success) - p_monitor.monitor_completed() - - create_generic_manual_monitor(body, constant_torque_test, simulation_duration) - - if true: - # Impulse Torque - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - - var impulse_torque_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - p_target.apply_torque_impulse(500) - - # Apply the force 20 frames - if p_monitor.frame == 22: - var inertia : float = PhysicsServer2D.body_get_param(p_target.get_rid(), PhysicsServer2D.BODY_PARAM_INERTIA) - var angular_acc_expected = (1.0/inertia) * 500.0 # θ(t) = (1/I)τ0t + θ0 - if true: - p_monitor.add_test("The impulse torque is applied to the angular velocity") - var success_vel:= Utils.f_equals(p_target.angular_velocity, angular_acc_expected) - if not success_vel: - p_monitor.add_test_error("Impulse torque is not applied correctly to the angular velocity: expected %f, get %f" % [angular_acc_expected, p_target.angular_velocity]) - p_monitor.add_test_result(success_vel) - - if true: - p_monitor.add_test("The impulse torque makes the body rotate correctly") - var angular_rotation_expected = (angular_acc_expected * dt) * 20.0 - var success_rot:= Utils.f_equals(p_target.rotation, angular_rotation_expected) - if not success_rot: - p_monitor.add_test_error("The impulse torque is not applied correctly to the rotation: expected %f, get %f" % [angular_rotation_expected, p_target.rotation]) - p_monitor.add_test_result(success_rot) - - p_monitor.monitor_completed() - - create_generic_manual_monitor(body, impulse_torque_test, simulation_duration) - - if true: - # Check freeze API - var test_position = next_test_position() - var body := create_rigid_body(next_test_layer(), test_position) - body.freeze = true - var right_constant_force = Vector2(200, 0) - - var freeze_test = func(p_target: RigidBody2D, p_monitor: GenericManualMonitor): - if p_monitor.frame == 2: - # Setup the force - p_target.add_constant_central_force(right_constant_force) - if p_monitor.frame == 22: - if true: - p_monitor.add_test("Body can be freeze") - var success: bool = p_target.global_position == p_monitor.data["position"] - p_monitor.add_test_result(success) - reset_body(p_target) - - p_monitor.monitor_completed() - var body_freeze_monitor := create_generic_manual_monitor(body, freeze_test, simulation_duration) - body_freeze_monitor.data["position"] = test_position - - - if true: - var test_position = next_test_position() - var current_layer = next_test_layer() - var body_with_damping := create_rigid_body(current_layer, test_position + Vector2(0, -60), false) # Damping - var body_without_damping := create_rigid_body(current_layer, test_position, true) # No Damping - body_with_damping.add_constant_force(Vector2(200, 0)) - body_without_damping.add_constant_force(Vector2(200, 0)) - - var damping_test = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - return body_with_damping.position.x < body_without_damping.position.x - - var monitor := create_generic_expiration_monitor(self, damping_test, null, 1) - monitor.test_name = "Damping works" - -func reset_body(p_body: RigidBody2D) -> void: - p_body.freeze = false - p_body.constant_force = Vector2.ZERO - p_body.constant_torque = 0.0 - p_body.linear_velocity = Vector2.ZERO - p_body.angular_velocity = 0.0 - p_body.global_position = CENTER - -func create_static_body(p_layer := 1, p_position := CENTER, p_scale := 1) -> StaticBody2D: - var body := StaticBody2D.new() - body.position = p_position - body.add_child(PhysicsTest2D.get_default_collision_shape(TestCollisionShape.RECTANGLE, p_scale)) - body.collision_mask = 0 - body.collision_layer = 0 - body.set_collision_layer_value(p_layer, true) - body.set_collision_mask_value(p_layer, true) - add_child(body) - return body - -func create_rigid_body(p_layer := 1, p_position := CENTER, p_remove_damping := true, p_scale := 1) -> RigidBody2D: - var body := RigidBody2D.new() - body.position = p_position - body.add_child(PhysicsTest2D.get_default_collision_shape(TestCollisionShape.RECTANGLE, p_scale)) - - body.gravity_scale = 0 - - if p_remove_damping: - body.linear_damp = 0 - body.angular_damp = 0 - body.linear_damp_mode = RigidBody2D.DAMP_MODE_REPLACE - body.angular_damp_mode = RigidBody2D.DAMP_MODE_REPLACE - - body.collision_mask = 0 - body.collision_layer = 0 - body.set_collision_layer_value(p_layer, true) - body.set_collision_mask_value(p_layer, true) - - add_child(body) - return body - -var current_test_nb := 0 -func next_test_position() -> Vector2: - var nb_horizontal_items := 7 - var nb_vertical_items := 3 - - var column = current_test_nb % nb_horizontal_items - var row = int((current_test_nb ) / 6.0) - column += 1 - row += 1 - - var x_pos = (Global.WINDOW_SIZE.x / (nb_horizontal_items + 1)) * column - var y_pos = (Global.WINDOW_SIZE.y / (nb_vertical_items + 1)) * row - - current_test_nb += 1 - return Vector2(x_pos, y_pos) - - -func next_test_layer() -> int: - test_layer += 1 - assert(test_layer <= 32) - return test_layer - diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.tscn deleted file mode 100644 index 2dd559ce..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/basic_api.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://c8rd0ut3utr8l"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/basic_api.gd" id="1_cdttp"] - -[node name="basic_api" type="Node2D"] -script = ExtResource("1_cdttp") diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.gd b/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.gd deleted file mode 100644 index 1fd943ae..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.gd +++ /dev/null @@ -1,66 +0,0 @@ -extends PhysicsUnitTest2D - -@export var body_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.CIRCLE -var simulation_duration := 3 -var speed := 50000 - -func test_description() -> String: - return """Checks if the contact is correctly reported when [contact_monitor] is turn ON""" - -func test_name() -> String: - return "RigidBody2D | testing [contact_monitor]" - -func test_start() -> void: - var wall_top = PhysicsTest2D.get_static_body_with_collision_shape(Rect2(Vector2(0,0), Vector2(2, Global.WINDOW_SIZE.y/2)), PhysicsTest2D.TestCollisionShape.RECTANGLE, true) - wall_top.position = CENTER + Vector2(100, 0) - wall_top.rotate(deg_to_rad(45)) - wall_top.set_collision_layer_value(1, true) - wall_top.set_collision_layer_value(2, true) - - var wall_bot = PhysicsTest2D.get_static_body_with_collision_shape(Rect2(Vector2(0,0), Vector2(2, Global.WINDOW_SIZE.y/2)), PhysicsTest2D.TestCollisionShape.RECTANGLE, true) - wall_bot.position = CENTER + Vector2(100, 0) - wall_bot.rotate(deg_to_rad(135)) - wall_bot.set_collision_layer_value(1, true) - wall_bot.set_collision_layer_value(2, true) - - add_child(wall_bot) - add_child(wall_top) - - var body := create_rigid_body(1) - body.position = CENTER - Vector2(100, 0) - body.linear_damp = 1 - var contact_lambda = func(p_step: int, _p_target: PhysicsTest2D, _p_monitor: GenericStepMonitor): - if p_step == 0: - return body.get_colliding_bodies().size() == 0 - elif p_step == 1: - return body.get_colliding_bodies().size() > 0 or not body.sleeping - elif p_step == 2: - return body.sleeping - - var contact_monitor := create_generic_step_monitor(self, contact_lambda, null, simulation_duration) - contact_monitor.add_test(1, "Collisions are reported") - contact_monitor.add_test(2, "The body sleep") - - var body_no_contact := create_rigid_body(2, 0) - body_no_contact.position = CENTER - Vector2(100, 0) - body_no_contact.linear_damp = 1 - - var lambda_no_contact = func(p_body, p_monitor: GenericManualMonitor): - if p_body.get_colliding_bodies().size() != 0: - p_monitor.failed("%d collision(s) detected" % [p_body.get_colliding_bodies().size()]) - - var no_contact_monitor := create_generic_manual_monitor(body_no_contact, lambda_no_contact, simulation_duration, false) - no_contact_monitor.test_name = "No contact reported when [contacts_reported] is 0" - -func create_rigid_body(p_layer := 1, p_report_contact := 20) -> RigidBody2D: - var player := RigidBody2D.new() - player.add_child(PhysicsTest2D.get_default_collision_shape(body_shape)) - player.gravity_scale = 0 - player.contact_monitor = true - player.max_contacts_reported = p_report_contact - player.collision_mask = 0 - player.collision_layer = 0 - player.set_collision_mask_value(p_layer, true) - add_child(player) - player.apply_force(Vector2(speed, 0)) - return player diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.tscn deleted file mode 100644 index bde04b46..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/contact_monitor.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://nqktmpb0a6er"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/contact_monitor.gd" id="1_dtxqi"] - -[node name="contact_monitor" type="Node2D"] -script = ExtResource("1_dtxqi") diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.gd b/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.gd deleted file mode 100644 index 121b8a78..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.gd +++ /dev/null @@ -1,114 +0,0 @@ -extends PhysicsUnitTest2D - -enum WallType { - BOX, - CONCAVE_BOX -} - -@export var wall_type: WallType = WallType.BOX -@export var speed: float = 25000 -@export var simulation_duration : float = 0.1 - -func test_description() -> String: - return """Checks if the Continuous Collision Detection (CCD) is working, it must ensure that moving - objects does not go through objects (tunnelling). - """ - -func test_name() -> String: - return "RigidBody2D | testing Continuous Collision Detection (CCD)" - -var detect_x_collision := false -var detect_y_collision := false - -func test_start() -> void: - var vertical_wall := StaticBody2D.new() - var vertical_wall_shape: Node2D = null - if wall_type == WallType.BOX: - vertical_wall_shape = PhysicsTest2D.get_collision_shape(Rect2(Vector2(0,0), Vector2(2, Global.WINDOW_SIZE.y)), PhysicsTest2D.TestCollisionShape.RECTANGLE, true) - elif wall_type == WallType.CONCAVE_BOX: - vertical_wall_shape = PhysicsTest2D.get_collision_shape(PhysicsTest2D.get_box_segments(2, Global.WINDOW_SIZE.y), PhysicsTest2D.TestCollisionShape.CONCAVE_POLYGON) - vertical_wall_shape.position += Vector2(1, 0.5 * Global.WINDOW_SIZE.y) - vertical_wall.add_child(vertical_wall_shape) - vertical_wall.position = Vector2(TOP_RIGHT.x - Global.WINDOW_SIZE.y/2 -1, 0) - add_child(vertical_wall) - - var horizontal_wall := StaticBody2D.new() - var horizontal_wall_shape: Node2D = null - if wall_type == WallType.BOX: - horizontal_wall_shape = PhysicsTest2D.get_collision_shape(Rect2(Vector2(0,0), Vector2(0.5 * Global.WINDOW_SIZE.y, 2)), PhysicsTest2D.TestCollisionShape.RECTANGLE, true) - elif wall_type == WallType.CONCAVE_BOX: - horizontal_wall_shape = PhysicsTest2D.get_collision_shape(PhysicsTest2D.get_box_segments(0.5 * Global.WINDOW_SIZE.y, 2), PhysicsTest2D.TestCollisionShape.CONCAVE_POLYGON) - horizontal_wall_shape.position += Vector2(0.25 * Global.WINDOW_SIZE.y, 1) - horizontal_wall.add_child(horizontal_wall_shape) - horizontal_wall.position = Vector2(BOTTOM_RIGHT.x - Global.WINDOW_SIZE.y/2, BOTTOM_RIGHT.y -50) - add_child(horizontal_wall) - - var rigid_x_ccd_ray := create_rigid_body(RigidBody2D.CCD_MODE_CAST_RAY) - rigid_x_ccd_ray.position = Vector2(50, 150) - rigid_x_ccd_ray.body_entered.connect(x_collide.bind(rigid_x_ccd_ray)) - - var rigid_x_ccd_shape := create_rigid_body(RigidBody2D.CCD_MODE_CAST_SHAPE) - rigid_x_ccd_shape.position = Vector2(50, 250) - - var rigid_y_ccd_ray := create_rigid_body(RigidBody2D.CCD_MODE_CAST_RAY, false) - rigid_y_ccd_ray.position = Vector2(vertical_wall.position.x + 150, 50) - rigid_y_ccd_ray.body_entered.connect(y_collide.bind(rigid_y_ccd_ray)) - - var rigid_y_ccd_shape := create_rigid_body(RigidBody2D.CCD_MODE_CAST_SHAPE, false) - rigid_y_ccd_shape.position = Vector2(vertical_wall.position.x + 250, 50) - - var x_lambda = func(p_target: RigidBody2D, _p_monitor: GenericExpirationMonitor): - return p_target.position.x <= vertical_wall.position.x # good - - var y_lambda = func(p_target: RigidBody2D, _p_monitor: GenericExpirationMonitor): - return p_target.position.y <= horizontal_wall.position.y # good - - var collide_x_lambda = func(_p_target: RigidBody2D, _p_monitor: GenericExpirationMonitor): - return detect_x_collision - - var collide_y_lambda = func(_p_target: RigidBody2D, _p_monitor: GenericExpirationMonitor): - return detect_y_collision - - var x_ray_ccd_monitor := create_generic_expiration_monitor(rigid_x_ccd_ray, x_lambda, null, simulation_duration) - x_ray_ccd_monitor.test_name = "Rigid moving in x with CCD Ray does not pass through the wall" - x_ray_ccd_monitor.expected_to_fail = true - - var x_shape_ccd_monitor := create_generic_expiration_monitor(rigid_x_ccd_shape, x_lambda, null, simulation_duration) - x_shape_ccd_monitor.test_name = "Rigid moving in x with CCD Cast shape does not pass through the wall" - x_shape_ccd_monitor.expected_to_fail = true - - var y_ray_ccd_monitor := create_generic_expiration_monitor(rigid_y_ccd_ray, y_lambda, null, simulation_duration) - y_ray_ccd_monitor.test_name = "Rigid moving in y with CCD Ray does not pass through the wall" - - var y_shape_ccd_monitor := create_generic_expiration_monitor(rigid_y_ccd_shape, y_lambda, null, simulation_duration) - y_shape_ccd_monitor.test_name = "Rigid moving in y with CCD Cast shape does not pass through the wall" - y_shape_ccd_monitor.expected_to_fail = true - - var x_collision_monitor := create_generic_expiration_monitor(rigid_x_ccd_ray, collide_x_lambda, null, simulation_duration) - x_collision_monitor.test_name = "Rigid moving in x with CCD detects collision" - - var y_collision_monitor := create_generic_expiration_monitor(rigid_y_ccd_ray, collide_y_lambda, null, simulation_duration) - y_collision_monitor.test_name = "Rigid moving in y with CCD detects collision" - - #process_mode = Node.PROCESS_MODE_DISABLED # to be able to see something - #await get_tree().create_timer(.5).timeout - #process_mode = Node.PROCESS_MODE_INHERIT - -func create_rigid_body(p_ccd_mode: RigidBody2D.CCDMode, p_horizontal := true, p_shape: PhysicsTest2D.TestCollisionShape = TestCollisionShape.RECTANGLE) -> RigidBody2D: - var player = RigidBody2D.new() - player.add_child(PhysicsTest2D.get_default_collision_shape(p_shape)) - player.gravity_scale = 0 - player.continuous_cd = p_ccd_mode - player.contact_monitor = true - player.max_contacts_reported = 2 - player.rotation = 90 # Case where the movement vector was not properly being transformed into local space, see #69934 - var force = Vector2(speed, 0) if p_horizontal else Vector2(0, speed) - add_child(player) - player.apply_central_impulse(force) - return player - -func x_collide(_body, _player): - detect_x_collision = true - -func y_collide(_body, _player): - detect_y_collision = true diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.tscn deleted file mode 100644 index 721c1d20..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/continuous_detection.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://7usnv0hqg67g"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/continuous_detection.gd" id="1_wlpyc"] - -[node name="continuous_detection" type="Node2D"] -script = ExtResource("1_wlpyc") diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.gd b/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.gd deleted file mode 100644 index 9399dd01..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.gd +++ /dev/null @@ -1,56 +0,0 @@ -extends PhysicsUnitTest2D - -var timer: Timer -var body_size := Vector2(25, 25) -var min_body_expected := 550 -var simulation_duration := 15 - -var bodies : Array[RigidBody2D] = [] - -func test_description() -> String: - return """Checks the maximum number of supported rectangles before the simulation goes crazy. - """ - -func test_name() -> String: - return "RigidBody2D | testing if %d rectangles can be handled before instablity" % [min_body_expected] - -func test_start() -> void: - add_collision_bottom(1) - - timer = Timer.new() - timer.wait_time = 0.2 - timer.process_callback =Timer.TIMER_PROCESS_PHYSICS - timer.timeout.connect(spawn_body) - add_child(timer) - timer.start() - - - var maximum_bodies_supported = func(p_target: PhysicsUnitTest2D, p_monitor: GenericManualMonitor): - var _bodies := p_target.bodies as Array[RigidBody2D] - for body in _bodies: - if body.position.y > (Global.WINDOW_SIZE.y) or _bodies.size() >= min_body_expected: - p_target.timer.stop() - if _bodies.size() >= min_body_expected: - p_monitor.passed() - else: - p_monitor.test_name += " → [color=orange]failed at %d[/color]" % [_bodies.size()] - p_monitor.failed() - - var check_max_stability_monitor := create_generic_manual_monitor(self, maximum_bodies_supported, simulation_duration) - check_max_stability_monitor.test_name = "Handle at least %d bodies" % [min_body_expected] - -func spawn_body() -> void: - var offset = (Global.WINDOW_SIZE.x - 100) / 19 - for i in range(20): - var body = _get_rigid_body(TOP_LEFT + Vector2(50 + i * offset, 0)) - bodies.append(body) - add_child(body) - -func _get_rigid_body(p_position: Vector2) -> RigidBody2D: - var body = RigidBody2D.new() - var shape = PhysicsTest2D.get_collision_shape(Rect2(Vector2(0, 0), body_size), TestCollisionShape.RECTANGLE, false) - body.add_child(shape) - p_position.x = int(p_position.x) - p_position.y = int(p_position.y) - body.position = p_position - return body diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.tscn deleted file mode 100644 index aac45bcc..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/maximum_rectangle.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://3o0nkl6b4h10"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/maximum_rectangle.gd" id="1_rq8tb"] - -[node name="maximum_rectangle" type="Node2D"] -script = ExtResource("1_rq8tb") diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.gd b/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.gd deleted file mode 100644 index 7f7f00bf..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.gd +++ /dev/null @@ -1,82 +0,0 @@ -extends PhysicsUnitTest2D - -@export var height := 40 -@export var box_size := Vector2(20.0, 20.0) -@export var box_spacing := Vector2(0.01,0.01) -var simulation_duration := 4 -var size_boundary := 20 -var tolerance := Vector2(0.5, 0.5) - -var bodies := [] -var top_last_position := Vector2.ZERO - -func test_description() -> String: - return """Checks the stability of the RigidBody Simulation. The pyramid should be stable and the RigidBody - should sleep after the [simulation_duration] - """ - -func test_name() -> String: - return "RigidBody2D | testing the stability with a pyramid [tolerance %.2v]" % [tolerance] - -func test_start() -> void: - add_collision_bottom(size_boundary) - create_pyramid() - - var test_sleep: Callable = func(_p_target: PhysicsTest2D, _p_monitor: GenericExpirationMonitor): - for body_parent in bodies as Array[Node2D]: - var body: RigidBody2D = body_parent.get_child(0) - if not body.sleeping: - return false - return true - - var test_head_position: Callable = func(_p_target: PhysicsTest2D, p_monitor: GenericExpirationMonitor): - var last_cube_parent: Node2D = bodies[bodies.size() - 1] - var end_simulation_pos := Vector2(last_cube_parent.get_child(0).position.x, last_cube_parent.position.y) - if end_simulation_pos.x < top_last_position.x - tolerance.x or end_simulation_pos.x > top_last_position.x + tolerance.x: - p_monitor.error_message = "Moved too much in x, expected: %v , actual %v" % [top_last_position, end_simulation_pos] - return false - if end_simulation_pos.y < top_last_position.y - tolerance.y or end_simulation_pos.y > top_last_position.y + tolerance.y: - p_monitor.error_message = "Moved too much in y, expected: %v , actual %v" % [top_last_position, end_simulation_pos] - return false - - return true - - var pyramid_sleep := create_generic_expiration_monitor(self, test_sleep, null, simulation_duration) - pyramid_sleep.test_name = "All body are sleep" - - var pyramid_top_cube := create_generic_expiration_monitor(self, test_head_position, null, simulation_duration) - pyramid_top_cube.test_name = "The top cube did not move" - -func create_pyramid(): - var pos_y = -0.5 * box_size.y - box_spacing.y + Global.WINDOW_SIZE.y - size_boundary - var pos_x - for level in height: - var level_index = height - level - 1 - var num_boxes = 2 * level_index + 1 - - var row_node = Node2D.new() - row_node.position = Vector2(0.0, pos_y) - row_node.name = "Row%02d" % (level + 1) - add_child(row_node) - bodies.append(row_node) - - pos_x = -0.5 * (num_boxes - 1) * (box_size.x + box_spacing.x) + Global.WINDOW_SIZE.x/2 - - for box_index in range(num_boxes): - var box = get_rigid_body() - box.position = Vector2(pos_x, 0.0) - box.name = "Box%02d" % (box_index + 1) - box.mass = 10 - row_node.add_child(box) - - pos_x += box_size.x + box_spacing.x - - pos_y -= box_size.y + box_spacing.y - - top_last_position = Vector2(pos_x - box_size.x + box_spacing.x, pos_y + box_size.y - box_spacing.y) - -func get_rigid_body() -> RigidBody2D: - var body = RigidBody2D.new() - var shape = PhysicsTest2D.get_collision_shape(Rect2(Vector2(0, 0), box_size), TestCollisionShape.RECTANGLE, false) - body.add_child(shape) - return body diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.tscn deleted file mode 100644 index b94cbfaa..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_pyramid.tscn +++ /dev/null @@ -1,8 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bn1ox1w8nnydx"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/rectangle_pyramid.gd" id="1_33db6"] - -[node name="rectangle_pyramid" type="Node2D"] -script = ExtResource("1_33db6") - -[node name="Camera2D" type="Camera2D" parent="."] diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.gd b/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.gd deleted file mode 100644 index 78f35711..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.gd +++ /dev/null @@ -1,96 +0,0 @@ -extends PhysicsUnitTest2D - -var stack_height := 30 -var max_horizontal_movement := 5.0 -var body_size := Vector2(25, 25) -var body_spacing := 1 -var body_shape: PhysicsTest2D.TestCollisionShape = PhysicsTest2D.TestCollisionShape.RECTANGLE -var simulation_duration := 3 -var tolerance := 3.3 - -func test_description() -> String: - return """Checks the stability of the RigidBody Simulation. The stack should be stable and the RigidBody - should sleep after the [simulation_duration] - """ - -func test_name() -> String: - return "RigidBody2D | testing the box stack stability" - -func test_start() -> void: - add_collision_boundaries(20, false) - - var stack = Node2D.new() - stack.position = BOTTOM_CENTER - Vector2(0, 20 + -body_size.y * 0.5) - - var bodies_array : Array[RigidBody2D] = [] - for i in range(stack_height): - var body := RigidBody2D.new() - var body_col: Node2D = PhysicsTest2D.get_collision_shape(Rect2(Vector2(-body_size.x * 0.5, -body_size.y * 0.5), body_size), body_shape, true) - body.add_child(body_col) - - # Spawn the body - body.position = Vector2(0, -(body_size.y + body_spacing) * (i+1)) - bodies_array.append(body) - stack.add_child(body) - - add_child(stack) - - # 1. Should be sleeping - var should_be_sleep = func(_p_target: Node2D, _p_monitor: GenericExpirationMonitor): - for body in bodies_array as Array[RigidBody2D]: - if not body.sleeping: - return false - return true - - var sleep_monitor := create_generic_expiration_monitor(stack, should_be_sleep, null, simulation_duration) - sleep_monitor.test_name = "The bodies are sleeping" - - # 2. Should not move horizontally - var should_not_move_in_x: Callable = func(_p_target: Node2D, p_monitor: GenericExpirationMonitor): - for body in bodies_array as Array[RigidBody2D]: - if not (body.position.x > -tolerance and body.position.x < tolerance): - p_monitor.error_message = "A body moved by %.1f px" % [body.position.x] - return false - return true - - var horizontal_monitor := create_generic_expiration_monitor(stack, should_not_move_in_x, null, simulation_duration) - horizontal_monitor.test_name = "The bodies did not move horizontally more than %.1f px" % [tolerance] - - # 3. Should be sorted vertically - var should_be_sorted_vertically = func(_p_target: Node2D, _p_monitor: GenericExpirationMonitor): - var child_height = -INF - for body in bodies_array as Array[RigidBody2D]: - var height = -body.position.y # easier, because the smaller the y, the higher it is (a bit counter intuitive) - if height > child_height: - child_height = height - else: - return false - return true - - var sorted_vertically_monitor := create_generic_expiration_monitor(stack, should_be_sorted_vertically, null, simulation_duration) - sorted_vertically_monitor.test_name = "The bodies are sorted vertically" - - # 4. Only neighboring children overlap - var shoud_overlaps_with_neighbours= func(p_target: Node2D, _p_monitor: GenericExpirationMonitor): - var bodies := bodies_array as Array[RigidBody2D] - for child_idx in bodies.size(): - var body := bodies[child_idx] - for shape_owner_id in body.get_shape_owners(): - for shape_id in body.shape_owner_get_shape_count(shape_owner_id): - var shape = body.shape_owner_get_shape(shape_owner_id, shape_id) - var parameters := PhysicsShapeQueryParameters2D.new() - parameters.transform = body.global_transform * body.shape_owner_get_transform(shape_owner_id) - parameters.set_shape(shape) - var results = p_target.get_world_2d().direct_space_state.intersect_shape(parameters) - for result in results: - if not result.collider is RigidBody2D: # can be the level - continue - var sibling_idx = bodies.find(result.collider) - if sibling_idx == -1 or sibling_idx == child_idx: - continue - if abs(child_idx - sibling_idx) > 1: # sibling is not a neighbor - return false - return true - - var overlaps_with_neighbours_monitor := create_generic_expiration_monitor(stack, shoud_overlaps_with_neighbours, null, simulation_duration) - overlaps_with_neighbours_monitor.test_name = "Only neighboring children overlap" diff --git a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.tscn b/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.tscn deleted file mode 100644 index c32f3ae7..00000000 --- a/bin3d/tests/nodes/RigidBody/tests/2d/rectangle_stack.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bxrk6vpptw3in"] - -[ext_resource type="Script" path="res://tests/nodes/RigidBody/tests/2d/rectangle_stack.gd" id="1_abyb0"] - -[node name="rectangle_stack" type="Node2D"] -script = ExtResource("1_abyb0") diff --git a/bin3d/tests/performance/collisions/collisions_2d.tscn b/bin3d/tests/performance/collisions/collisions_2d.tscn deleted file mode 100644 index 9efbc6de..00000000 --- a/bin3d/tests/performance/collisions/collisions_2d.tscn +++ /dev/null @@ -1,33 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://baeob8hdpg7rs"] - -[ext_resource type="Script" path="res://base/class/test_scene_child.gd" id="1_eq855"] -[ext_resource type="PackedScene" uid="uid://d32ame83cs40t" path="res://tests/performance/collisions/tests/2d/avg_fps_before_low_fps.tscn" id="3_tl4jl"] - -[node name="Scene" type="Node2D"] -script = ExtResource("1_eq855") - -[node name="maximum_bodies_before_low_fps_capsule-capsule" parent="." instance=ExtResource("3_tl4jl")] -position = Vector2(-4, 7) -shape1 = 5 -shape2 = 5 - -[node name="maximum_bodies_before_low_fps_polygon-polygon" parent="." instance=ExtResource("3_tl4jl")] -position = Vector2(-4, 7) -shape1 = 7 -shape2 = 7 - -[node name="maximum_bodies_before_low_fps_circle-circle" parent="." instance=ExtResource("3_tl4jl")] -position = Vector2(-4, 7) -shape2 = 3 - -[node name="maximum_bodies_before_low_fps_convex-convex" parent="." instance=ExtResource("3_tl4jl")] -position = Vector2(-4, 7) -shape1 = 6 -shape2 = 6 - -[node name="maximum_bodies_before_low_fps_rect-rect" parent="." instance=ExtResource("3_tl4jl")] -position = Vector2(-4, 7) - -[node name="HFlowContainer" type="HFlowContainer" parent="."] -offset_right = 40.0 -offset_bottom = 40.0 diff --git a/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.gd b/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.gd deleted file mode 100644 index 63126562..00000000 --- a/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.gd +++ /dev/null @@ -1,120 +0,0 @@ -extends PhysicsPerformanceTest2D - -@export var shape1: PhysicsTest2D.TestCollisionShape = PhysicsTest2D.TestCollisionShape.RECTANGLE -@export var shape2: PhysicsTest2D.TestCollisionShape = PhysicsTest2D.TestCollisionShape.RECTANGLE -@export var MINIMUM_FPS := 30 # The minimum FPS to be reached to stop the test. -@export var NB_BODY_FOR_ONE_STEP := 500 # The number of bodies to perform an average. -@export var NB_ITERATION := 3 # The number of times the test should be run -@export var NUMBER_BODIES_PER_SPAWN := 20 -@export var SPAWN_DELAY := 0.25 -var MAXIMUM_STEP := 25 # The size of the table that records the steps. - -var timer : Timer -var bodies = [] -var current_step := 0 -var label_number : Label -var swap := false # change order bodies fall - -var avg_fps: float = 0 -var avg_max_bodies: float = 0 -var nb_tick: float = 0 -var iteration := 1 -var array_index := 0 -var avg_result_arr := [] - -# Waiting before starting the test to stabilise the FPS -var NB_FRAME_WAITING = 20 -var waiting = true -var cpt_waiting := 0 - -func test_name() -> String: - return "Average FPS per %d bodies until FPS are less than %d (%s vs %s)" % [NB_BODY_FOR_ONE_STEP, MINIMUM_FPS, PhysicsTest2D.shape_name(shape1), PhysicsTest2D.shape_name(shape2)] - -func test_start() -> void: - avg_result_arr.resize(MAXIMUM_STEP) - avg_result_arr.fill(0) - label_number = Label.new() - label_number.position = TOP_LEFT + Vector2(20,60) - label_number.set("theme_override_font_sizes/font_size", 18) - add_child(label_number) - - # ground - add_child(PhysicsTest2D.get_static_body_with_collision_shape(Rect2(BOTTOM_LEFT - Vector2(5000, 100), Vector2(Global.WINDOW_SIZE.x + 10000, 100)), TestCollisionShape.RECTANGLE, true)) - timer = Timer.new() - timer.wait_time = SPAWN_DELAY - timer.process_callback =Timer.TIMER_PROCESS_PHYSICS - timer.timeout.connect(spawn_body) - add_child(timer) - super() # launch the test - -func _physics_process(_delta: float) -> void: - label_number.text = "Bodies: %d" % bodies.size() - label_number.text += "\nIteration n° %d" % iteration - if waiting and cpt_waiting < NB_FRAME_WAITING: - cpt_waiting += 1 - return - elif waiting and cpt_waiting == NB_FRAME_WAITING: - timer.start() - waiting = false - cpt_waiting = 0 - return - - if bodies.size() != 0: - avg_fps += get_fps() - nb_tick += 1 - - if get_smoothed_fps() <= MINIMUM_FPS and not waiting: - timer.stop() - avg_max_bodies += bodies.size() - if iteration == NB_ITERATION: - var final_result = avg_result_arr.map(func(number:float) : return (number/NB_ITERATION )) - var formated_str = "" - var cpt = 0 - - var max_bodies = int(avg_max_bodies / NB_ITERATION) - var max_cpt = floor(float(max_bodies) / float(NB_BODY_FOR_ONE_STEP)) - for v in final_result: - if is_zero_approx(v) or cpt == max_cpt: - break - cpt += 1 - formated_str += "[%d] = %2.f, " % [cpt * NB_BODY_FOR_ONE_STEP, v] - formated_str = formated_str.substr(0, formated_str.length() - 3) - register_result("FPS AVG", formated_str) - register_result("Maximum bodies", "%d" % max_bodies) - test_completed() - else: - clean() - nb_tick = 0.0 - avg_fps = 0.0 - array_index = 0 - iteration += 1 - cpt_waiting = 0 - waiting = true - -func clean() -> void: - for body in bodies: - remove_child(body) - bodies.clear() - -func spawn_body() -> void: - var offset = (Global.WINDOW_SIZE.x - 100) / 19 - swap = not swap - for i in range(NUMBER_BODIES_PER_SPAWN): - var shape := shape1 if swap else shape2 - var body = _get_rigid_body(TOP_LEFT + Vector2(50 + randf() * 25 + i * offset, 0), shape) - bodies.append(body) - add_child(body) - - if bodies.size() % NB_BODY_FOR_ONE_STEP == 0: - assert(array_index >= 0 and array_index < avg_result_arr.size()) # If this assertion fails, increase MAXIMUM_STEP - avg_result_arr[array_index] += avg_fps/nb_tick - array_index += 1 - nb_tick = 0.0 - avg_fps = 0.0 - -func _get_rigid_body(p_position: Vector2, p_shape: PhysicsTest2D.TestCollisionShape) -> RigidBody2D: - var body = RigidBody2D.new() - var shape = PhysicsTest2D.get_default_collision_shape(p_shape) - body.add_child(shape) - body.position = p_position - return body diff --git a/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.tscn b/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.tscn deleted file mode 100644 index ceed440e..00000000 --- a/bin3d/tests/performance/collisions/tests/2d/avg_fps_before_low_fps.tscn +++ /dev/null @@ -1,10 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://d32ame83cs40t"] - -[ext_resource type="Script" path="res://tests/performance/collisions/tests/2d/avg_fps_before_low_fps.gd" id="1_ov27a"] - -[node name="maximum_bodies_before_low_fps" type="Node2D"] -script = ExtResource("1_ov27a") -shape1 = 3 -NB_ITERATION = 1 -NUMBER_BODIES_PER_SPAWN = 40 -SPAWN_DELAY = 0.1 diff --git a/bin3d/tests/performance/collisions/tests/2d/collision_shape_instability.tscn b/bin3d/tests/performance/collisions/tests/2d/collision_shape_instability.tscn deleted file mode 100644 index af575c3f..00000000 --- a/bin3d/tests/performance/collisions/tests/2d/collision_shape_instability.tscn +++ /dev/null @@ -1,65 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://us4eb3bjc0o4"] - -[sub_resource type="GDScript" id="GDScript_f3u78"] -script/source = "extends PhysicsPerformanceTest2D - -@export var shape1: PhysicsTest2D.TestCollisionShape = PhysicsTest2D.TestCollisionShape.RECTANGLE -@export var shape2: PhysicsTest2D.TestCollisionShape = PhysicsTest2D.TestCollisionShape.RECTANGLE - -var timer : Timer -var bodies = [] -var current_step := 0 -var label_number : Label -var swap := false - -func test_name() -> String: - return \"Maximum bodies before instability (%s vs %s)\" % [PhysicsTest2D.shape_name(shape1), PhysicsTest2D.shape_name(shape2)] - -func test_start() -> void: - label_number = Label.new() - label_number.position = TOP_LEFT + Vector2(20,60) - label_number.set(\"theme_override_font_sizes/font_size\", 18) - add_child(label_number) - - add_collision_boundaries(1, false) - - timer = Timer.new() - timer.wait_time = 0.2 - timer.process_callback =Timer.TIMER_PROCESS_PHYSICS - timer.timeout.connect(spawn_body) - add_child(timer) - timer.start() - super() # launch the test - -func _physics_process(_delta: float) -> void: - label_number.text = \"Bodies: \" + str(bodies.size()) - - for body in bodies: - if body.position.y > Global.WINDOW_SIZE.y: - timer.stop() - register_result(\"Maximum bodies\", str(bodies.size())) - test_completed() - -func clean() -> void: - for body in bodies: - remove_child(body) - -func spawn_body() -> void: - var offset = (Global.WINDOW_SIZE.x - 100) / 19 - swap = not swap - for i in range(20): - var shape := shape1 if swap else shape2 - var body = _get_rigid_body(TOP_LEFT + Vector2(50 + i * offset, 0), shape) - bodies.append(body) - add_child(body) - -func _get_rigid_body(p_position: Vector2, p_shape: PhysicsTest2D.TestCollisionShape) -> RigidBody2D: - var body = RigidBody2D.new() - var shape = PhysicsTest2D.get_default_collision_shape(p_shape) - body.add_child(shape) - body.position = p_position - return body -" - -[node name="2d_collision_shape_instability" type="Node2D"] -script = SubResource("GDScript_f3u78") diff --git a/docs/stability-comparison.gif b/docs/stability-comparison.gif new file mode 100644 index 00000000..ebcab2cb Binary files /dev/null and b/docs/stability-comparison.gif differ diff --git a/scripts/build-dev-2d-f64.sh b/scripts/build-dev-2d-f64.sh new file mode 100755 index 00000000..27faff98 --- /dev/null +++ b/scripts/build-dev-2d-f64.sh @@ -0,0 +1,12 @@ +cargo fmt -- --config-path rustfmt.toml +cargo clippy --fix --allow-dirty +if [ "${OSTYPE#darwin}" != "$OSTYPE" ]; then + cargo build --features="build2d-f64,test" --no-default-features + echo "Running on macOS" + rm -f bin2d/addons/godot-rapier2d/bin/libgodot_rapier.macos.framework/libgodot_rapier.macos.dylib + cp target/debug/libgodot_rapier.dylib bin2d/addons/godot-rapier2d/bin/libgodot_rapier.macos.framework/libgodot_rapier.macos.dylib +else + cargo build --features="build2d,test" --no-default-features --target=x86_64-unknown-linux-gnu + echo "Running on Linux" + cp target/x86_64-unknown-linux-gnu/debug/libgodot_rapier.so bin2d/addons/godot-rapier2d/bin/libgodot_rapier.linux.x86_64-unknown-linux-gnu.so +fi diff --git a/src/lib.rs b/src/lib.rs index d45510eb..8762f10e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,11 +12,11 @@ extern crate rapier3d_f64 as rapier; #[cfg(all(feature = "single", feature = "dim2"))] extern crate salva2d as salva; #[cfg(all(feature = "double", feature = "dim2"))] -extern crate salva2d as salva; +extern crate salva2d_f64 as salva; #[cfg(all(feature = "single", feature = "dim3"))] extern crate salva3d as salva; #[cfg(all(feature = "double", feature = "dim3"))] -extern crate salva3d as salva; +extern crate salva3d_f64 as salva; mod bodies; mod fluids; mod joints;