diff --git a/.github/workflows/web_builds.yml b/.github/workflows/web_builds.yml index 11c745e4..0dc6d1ab 100644 --- a/.github/workflows/web_builds.yml +++ b/.github/workflows/web_builds.yml @@ -43,7 +43,7 @@ jobs: rust_extra_flags: ${{ matrix.arch.rust_extra_flags }} platform: web precision: ${{ matrix.precision }} - features: ${{ matrix.features }},wasm-bindgen + features: ${{ matrix.features }} rust_env_flags: "-C target-feature=+atomics,+bulk-memory" - name: Upload ${{ matrix.arch.arch }} ${{ matrix.precision }} ${{ matrix.features }} diff --git a/README.md b/README.md index b2e3a5f1..aa25d106 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,14 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engine](https://github.com/godotengine/godot), implemented as a GDExtension. -## Supported Platforms +## Table of Contents -- Windows (x86_64, x86_32) -- macOS (x86-64 + arm64 Universal) -- Linux (x86_64) -- Android (x86_64, arm64) -- iOS (arm64) without signing - -# Features - -- Single and double float precision build -- SIMD (Single instruction, multiple data) build -- Cross-platform determinism (assuming the rest of your code is also deterministic) - -[More on different rapier features](https://rapier.rs/docs/user_guides/rust/getting_started) +1. [Limitations](#limitations) +2. [Supported Platforms](#supported-platforms) +3. [Installation](#installation) +4. [Features](#features) +5. [Comparison](#comparison) +6. [License](#license) # Limitations @@ -47,6 +40,14 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engi - Shape skewing missing. - Shape Cast Margin isn't supported. +# Supported Platforms + +- Windows (x86_64, x86_32) +- macOS (x86-64 + arm64 Universal) +- Linux (x86_64) +- Android (x86_64, arm64) +- iOS (arm64) without signing + # Installation - Automatic (Recommended): Download the plugin from the official [Godot Asset Store](https://godotengine.org/asset-library/asset/2267) using the `AssetLib` tab in Godot. @@ -57,6 +58,27 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engi After installing, go to `Advanced Settings` -> `Physics` -> `2D`. Change `Physics Engine` to `Rapier2D`. +Video Tutorial: + +[![Tutorial](https://img.youtube.com/vi/KgKWAZ49T9E/0.jpg)](https://www.youtube.com/watch?v=KgKWAZ49T9E) + +# Features + +- Single and double float precision build +- SIMD (Single instruction, multiple data) build +- Cross-platform determinism (assuming the rest of your code is also deterministic) + +[More on different rapier features](https://rapier.rs/docs/user_guides/rust/getting_started) + +# Comparison + +Watch a comparison to Godot Physics 2D and [Box2D](https://github.com/appsinacup/godot-box-2d) physics plugin: + +[![Comparison](https://img.youtube.com/vi/wgUiZ7E19eM/0.jpg)](https://www.youtube.com/watch?v=wgUiZ7E19eM) + +Or read about it on [appsinacup.com/godot-physics-vs-box2d-vs-rapier2d](https://appsinacup.com/godot-physics-vs-box2d-vs-rapier2d/) + + # Roadmap - Fix all other issues from Limitations. diff --git a/src/rapier2d-wrapper/Cargo.toml b/src/rapier2d-wrapper/Cargo.toml index 370f5770..4f594b74 100644 --- a/src/rapier2d-wrapper/Cargo.toml +++ b/src/rapier2d-wrapper/Cargo.toml @@ -15,7 +15,7 @@ double = [] enhanced-determinism = ["rapier2d/enhanced-determinism", "rapier2d-f64/enhanced-determinism"] simd-stable = ["rapier2d/simd-stable", "rapier2d-f64/simd-stable"] simd-nightly = ["rapier2d/simd-nightly", "rapier2d-f64/simd-nightly"] -wasm-bindgen = ["rapier2d/wasm-bindgen", "rapier2d-f64/wasm-bindgen"] +# wasm-bindgen = ["rapier2d/wasm-bindgen", "rapier2d-f64/wasm-bindgen"] parallel = ["rapier2d/parallel", "rapier2d-f64/parallel"] [dependencies] diff --git a/src/rapier2d-wrapper/includes/rapier2d_wrapper.h b/src/rapier2d-wrapper/includes/rapier2d_wrapper.h index a9f70106..464239ce 100644 --- a/src/rapier2d-wrapper/includes/rapier2d_wrapper.h +++ b/src/rapier2d-wrapper/includes/rapier2d_wrapper.h @@ -463,6 +463,8 @@ Handle world_create(const WorldSettings *settings); void world_destroy(Handle world_handle); +size_t world_get_active_objects_count(Handle world_handle); + void world_set_active_body_callback(Handle world_handle, ActiveBodyCallback callback); void world_set_body_collision_filter_callback(Handle world_handle, diff --git a/src/rapier2d-wrapper/src/physics_world.rs b/src/rapier2d-wrapper/src/physics_world.rs index c344011d..3baabb24 100644 --- a/src/rapier2d-wrapper/src/physics_world.rs +++ b/src/rapier2d-wrapper/src/physics_world.rs @@ -534,3 +534,10 @@ pub extern "C" fn world_set_contact_point_callback(world_handle : Handle, callba let physics_world = physics_engine.get_world(world_handle); physics_world.contact_point_callback = callback; } + +#[no_mangle] +pub extern "C" fn world_get_active_objects_count(world_handle : Handle) -> usize { + let mut physics_engine = SINGLETON.lock().unwrap(); + let physics_world = physics_engine.get_world(world_handle); + return physics_world.island_manager.active_dynamic_bodies().len(); +} diff --git a/src/servers/rapier_physics_server_2d.cpp b/src/servers/rapier_physics_server_2d.cpp index 12eb8a7d..e6f160f1 100644 --- a/src/servers/rapier_physics_server_2d.cpp +++ b/src/servers/rapier_physics_server_2d.cpp @@ -1238,20 +1238,16 @@ void RapierPhysicsServer2D::_step(double p_step) { ++frame; + island_count = 0; + active_objects = 0; + collision_pairs = 0; for (auto const &iterator : active_spaces) { RapierSpace2D *space = iterator.value; space->step(p_step); + island_count += space->get_island_count(); + active_objects += space->get_active_objects(); + collision_pairs += space->get_collision_pairs(); } - - // island_count = 0; - // active_objects = 0; - // collision_pairs = 0; - // for (const RapierSpace2D *space : active_spaces) { - // stepper->step(space, p_step); - // island_count += space->get_island_count(); - // active_objects += space->get_active_objects(); - // collision_pairs += space->get_collision_pairs(); - // } } void RapierPhysicsServer2D::_sync() { diff --git a/src/spaces/rapier_space_2d.cpp b/src/spaces/rapier_space_2d.cpp index 0eceed21..5ac71f7e 100644 --- a/src/spaces/rapier_space_2d.cpp +++ b/src/spaces/rapier_space_2d.cpp @@ -453,6 +453,7 @@ void RapierSpace2D::step(real_t p_step) { body_iterator = body_iterator->next(); body->on_update_active(); } + active_objects = rapier2d::world_get_active_objects_count(handle); } // Returns true to ignore the collider diff --git a/src/spaces/rapier_space_2d.h b/src/spaces/rapier_space_2d.h index 2b799fab..7101f35e 100644 --- a/src/spaces/rapier_space_2d.h +++ b/src/spaces/rapier_space_2d.h @@ -148,7 +148,6 @@ class RapierSpace2D { void set_island_count(int p_island_count) { island_count = p_island_count; } int get_island_count() const { return island_count; } - void set_active_objects(int p_active_objects) { active_objects = p_active_objects; } int get_active_objects() const { return active_objects; } int get_collision_pairs() const { return collision_pairs; }