Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Refactor cpp and rust(rapier) code #45

Merged
merged 22 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ inputs:
sconsflags:
required: true
description: Extra flags
precision:
required: true
description: single or double
features:
required: true
description: simd-nightly,simd-stable,parallel,enhanced-determinism

runs:
using: composite
Expand All @@ -42,22 +48,26 @@ runs:
SCONS_CACHE: .scons-cache
SCONS_CACHE_DIR: .scons-cache
run: |
cd godot-cpp && scons target=${{ inputs.target }} platform=${{ inputs.platform }} arch=${{ inputs.arch }} generate_bindings=yes ${{ inputs.sconsflags }}
cd godot-cpp && \
scons target=${{ inputs.target }} platform=${{ inputs.platform }} arch=${{ inputs.arch }} generate_bindings=yes ${{ inputs.sconsflags }} precision=${{ inputs.precision }}
- name: Build Rapier
shell: sh
run: |
cd src/rapier2d-wrapper && cargo build ${{ inputs.rust_target }} --release
cd src/rapier2d-wrapper && \
cargo build ${{ inputs.rust_target }} --release --features=${{ inputs.features }}
- name: Build Rapier Macos Universal
shell: sh

# we already built for x86_64-apple-darwin for mac, now build arm64
if: ${{ inputs.platform == 'macos'}}
run: |
cd src/rapier2d-wrapper && mkdir release && rustup target add aarch64-apple-darwin && cargo build --target=aarch64-apple-darwin --release && lipo -create -output target/release/librapier2d_wrapper.a target/aarch64-apple-darwin/release/librapier2d_wrapper.a target/x86_64-apple-darwin/release/librapier2d_wrapper.a
cd src/rapier2d-wrapper && mkdir release && rustup target add aarch64-apple-darwin && \
cargo build --target=aarch64-apple-darwin --release --features=${{ inputs.features }} && \
lipo -create -output target/release/librapier2d_wrapper.a target/aarch64-apple-darwin/release/librapier2d_wrapper.a target/x86_64-apple-darwin/release/librapier2d_wrapper.a
- name: Build Physics Server Rapier
shell: sh
env:
SCONS_CACHE: .scons-cache
SCONS_CACHE_DIR: .scons-cache
run: |
scons target=${{ inputs.target }} platform=${{ inputs.platform }} arch=${{ inputs.arch }} generate_bindings=no ${{ inputs.sconsflags }}
scons target=${{ inputs.target }} platform=${{ inputs.platform }} arch=${{ inputs.arch }} generate_bindings=no ${{ inputs.sconsflags }} precision=${{ inputs.precision }}
10 changes: 9 additions & 1 deletion .github/actions/upload/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
name: Physics Server Rapier Upload
description: Upload Godot Cpp and the Physics Server 2D Extension.

inputs:
precision:
required: true
description: single or double
features:
required: true
description: simd-nightly,simd-stable,parallel,enhanced-determinism

runs:
using: composite
steps:
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Godot Rapier 2D
name: Godot Rapier 2D ${{ inputs.precision }} ${{ inputs.features }}
path: |
${{ github.workspace }}/bin/**
retention-days: 14
13 changes: 10 additions & 3 deletions .github/workflows/android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ env:
jobs:
android:
runs-on: "ubuntu-20.04"
name: Android Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [x86_64] # Todo reenable arm64
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
Expand All @@ -26,13 +28,18 @@ jobs:
distribution: temurin
java-version: 11

- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: android
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}
13 changes: 10 additions & 3 deletions .github/workflows/ios_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,31 @@ env:
jobs:
ios:
runs-on: "macos-latest"
name: iOS Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [arm64]
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: ios
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}
13 changes: 10 additions & 3 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,33 @@ env:
jobs:
linux:
runs-on: ubuntu-20.04
name: Linux Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [x86_64]
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: linux
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

15 changes: 11 additions & 4 deletions .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@ env:
jobs:
macos:
runs-on: "macos-latest"
name: macOS Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [universal]
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: macos
rust_target: --target=x86_64-apple-darwin
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Sign frameworks
- name: Sign frameworks ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
shell: pwsh
env:
APPLE_CERT_BASE64: ${{ secrets.PROD_MACOS_CERTIFICATE }}
Expand All @@ -43,5 +47,8 @@ jobs:
run: ./scripts/ci-sign-macos.ps1 bin/addons/godot-rapier2d/bin/libphysics_server_rapier2d.macos.${{ matrix.target }}.framework
if: ${{ env.APPLE_DEV_ID }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}
13 changes: 10 additions & 3 deletions .github/workflows/web_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ env:
jobs:
web:
runs-on: ubuntu-20.04
name: Web Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [wasm32]
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
Expand All @@ -33,14 +35,19 @@ jobs:
run: |
emcc -v

- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: javascript
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

13 changes: 10 additions & 3 deletions .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ env:
jobs:
build-windows:
runs-on: "windows-latest"
name: Windows Build ${{ matrix.target }} ${{ matrix.arch }}
name: ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
strategy:
fail-fast: false
matrix:
target: [template_debug, template_release]
arch: [x86_64] # Rust doesn't have built in config for 32 bit windows build.
precision: [single, double]
features: [simd-stable, enhanced-determinism]

steps:
- uses: actions/checkout@v3
Expand All @@ -23,13 +25,18 @@ jobs:
- name: Setup MSVC problem matcher
uses: ammaraskar/msvc-problem-matcher@master

- name: Build ${{ matrix.target }} ${{ matrix.arch }}
- name: Build ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/build
with:
sconsflags: ${{ env.SCONSFLAGS }}
arch: ${{ matrix.arch }}
platform: windows
target: ${{ matrix.target }}
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}

- name: Upload ${{ matrix.target }} ${{ matrix.arch }}
- name: Upload ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.precision }} ${{ matrix.features }}
uses: ./.github/actions/upload
with:
precision: ${{ matrix.precision }}
features: ${{ matrix.features }}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ A 2d [rapier](https://github.com/dimforge/rapier) physics server for [Godot Engi
- Shape scaling doesn't work (WIP)
- Changing properties before they are added in world doesn't work (WIP)

# Installation
# Build Features

## Float Precision

This plugin is built for both single and double precision builds.

## Rapier Features

This package supports the following features of rapier ([more on this here](https://rapier.rs/docs/user_guides/rust/getting_started)):

- simd-stable: enables explicit SIMD optimizations using the wide crate. Has limited cross-platform support but can be used with a stable version of the Rust compiler.
- enhanced-determinism: enables cross-platform determinism (assuming the rest of your code is also deterministic) across all 32-bit and 64-bit platforms that implements the IEEE 754-2008 standard strictly. This includes most modern processors as well as WASM targets.

# 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.

Expand Down
6 changes: 5 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ env.Append(LIBS=[lib])

## Sources
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
sources = [Glob("src/*.cpp"),Glob("src/bodies/*.cpp"),Glob("src/joints/*.cpp"),Glob("src/servers/*.cpp"),Glob("src/shapes/*.cpp"),Glob("src/spaces/*.cpp")]

if env["platform"] == "windows":
env.Append(CPPDEFINES="WINDOWS_ENABLED")

if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
else:
env.Append(CPPDEFINES=["REAL_T_IS_FLOAT"])
if env["platform"] == "macos":
library = env.SharedLibrary(
"bin/addons/godot-rapier2d/bin/libphysics_server_rapier2d.{}.{}.framework/libphysics_server_rapier2d.{}.{}".format(
Expand Down
4 changes: 2 additions & 2 deletions src/rapier_area_2d.cpp → src/bodies/rapier_area_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "rapier_area_2d.h"
#include "../servers/rapier_physics_server_2d.h"
#include "../spaces/rapier_space_2d.h"
#include "rapier_body_2d.h"
#include "rapier_physics_server_2d.h"
#include "rapier_space_2d.h"

void RapierArea2D::set_space(RapierSpace2D *p_space) {
if (p_space == get_space()) {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/rapier_body_2d.cpp → src/bodies/rapier_body_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "rapier_body_2d.h"

#include "rapier_body_direct_state_2d.h"
#include "rapier_space_2d.h"
#include "../spaces/rapier_space_2d.h"
#include "rapier_direct_body_state_2d.h"

void RapierBody2D::_mass_properties_changed() {
if (!get_space()) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rapier_collision_object_2d.h"
#include "rapier_physics_server_2d.h"
#include "rapier_space_2d.h"

#include "../servers/rapier_physics_server_2d.h"
#include "../spaces/rapier_space_2d.h"

void RapierCollisionObject2D::add_shape(RapierShape2D *p_shape, const Transform2D &p_transform, bool p_disabled) {
Shape shape;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef RAPIER_COLLISION_OBJECT_2D_H
#define RAPIER_COLLISION_OBJECT_2D_H

#include "rapier_shape_2d.h"

#include "rapier_include.h"
#include "../shapes/rapier_shape_2d.h"

#include "../rapier_include.h"
#include <godot_cpp/classes/physics_server2d.hpp>
#include <godot_cpp/templates/local_vector.hpp>
#include <godot_cpp/templates/self_list.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "rapier_body_direct_state_2d.h"
#include "rapier_direct_body_state_2d.h"

#include "../servers/rapier_physics_server_2d.h"
#include "../spaces/rapier_direct_space_state_2d.h"
#include "rapier_body_2d.h"
#include "rapier_physics_server_2d.h"
#include "rapier_space_2d.h"

Vector2 RapierDirectBodyState2D::_get_total_gravity() const {
ERR_FAIL_COND_V(body->get_space(), Vector2());
Expand Down
Loading