Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various new features, examples and fixes #12

Merged
merged 19 commits into from
Jul 23, 2024
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
22 changes: 22 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Checks:
- bugprone-*
- -bugprone-easily-swappable-parameters
- cert-*
- clang-analyzer-*
- concurrency-*
- cppcoreguidelines-*
- -cppcoreguidelines-init-variables # Produces false positves when initialization happens later
- -cppcoreguidelines-avoid-magic-numbers # This also triggers with literals like 3.1415
- -cppcoreguidelines-avoid-non-const-global-variables
- misc-*
- -misc-non-private-member-variables-in-classes
- -misc-use-anonymous-namespace
- -misc-include-cleaner
- performance-*
- portability-*
- readability-*
- -readability-braces-around-statements
- -readability-uppercase-literal-suffix
- -readability-magic-numbers # This also triggers with literals like 3.1415
- -readability-redundant-access-specifiers
- -readability-implicit-bool-conversion
6 changes: 6 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CompileFlags:
Remove:
- -fno-gnu-unique
Add:
- -Wall
- -Wextra
147 changes: 60 additions & 87 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,117 +1,87 @@
# Adapted from https://github.com/nathanfranke/gdextension/blob/main/.github/workflows/build.yml
name: Builds
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
inputs:
git-ref:
description: A commit, branch or tag to build.
type: string
required: true
workflow_call:
inputs:
git-ref:
description: A commit, branch or tag to build.
type: string
required: true

jobs:
build:
runs-on: ${{ matrix.runner }}
name: ${{ matrix.name }}
name: ${{ matrix.platform }} ${{ matrix.target }} ${{ matrix.arch }} ${{ matrix.optimize }}
strategy:
fail-fast: false
matrix:
target: [ template_debug, template_release ]
identifier: [ windows, linux, macos, android, android_arm64 ]

include:
# Linux
- identifier: linux-debug
name: Linux Debug
runner: ubuntu-20.04
target: template_debug
platform: linux
arch: x86_64
# Defaults
- runner: ubuntu-latest
- optimize: speed
- arch: x86_64

- identifier: linux-release
name: Linux Release
runner: ubuntu-20.04
target: template_release
platform: linux
arch: x86_64
# Debug build settings
- target: template_debug
optimize: speed_trace

# Windows
- identifier: windows-debug
name: Windows Debug
runner: ubuntu-20.04
target: template_debug
# Map identifiers to platforms + special settings
- identifier: windows
platform: windows
arch: x86_64

- identifier: windows-release
name: Windows Release
runner: ubuntu-20.04
target: template_release
platform: windows
arch: x86_64

# Android Arm64
- identifier: android-release
name: Android Release Arm64
runner: ubuntu-20.04
target: template_release
platform: android
arch: arm64
- identifier: macos
platform: macos
runner: macos-latest
arch: universal

- identifier: android-debug
name: Android Debug Arm64
runner: ubuntu-20.04
target: template_debug
platform: android
arch: arm64
- identifier: linux
platform: linux

# Android x86_64
- identifier: android-release
name: Android Release x86_64
runner: ubuntu-20.04
target: template_release
- identifier: android
platform: android
arch: x86_64

- identifier: android-debug
name: Android Debug x86_64
runner: ubuntu-20.04
target: template_debug
- identifier: android_arm64
platform: android
arch: x86_64

# Mac
- identifier: macos-debug
name: macOS (universal) Debug
runner: macos-latest
target: template_debug
platform: macos
arch: universal

- identifier: macos-release
name: macOS (universal) Release
runner: macos-latest
target: template_release
platform: macos
arch: universal
arch: arm64

steps:
- name: Check settings
if: ${{ matrix.platform == '' || matrix.target == '' || matrix.runner == '' || matrix.optimize == '' || matrix.arch == ''}}
run: |
echo "One of the matrix values is not set."
exit 1

- name: (Windows) Install mingw64
if: ${{ startsWith(matrix.identifier, 'windows-') }}
if: ${{ matrix.platform == 'windows' }}
shell: sh
run: |
sudo apt-get install mingw-w64
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix

- name: (Android) Install JDK 17
if: ${{ startsWith(matrix.identifier, 'android-') }}
if: ${{ matrix.platform == 'android' }}
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: (Android) Install Android SDK
if: ${{ startsWith(matrix.identifier, 'android-') }}
if: ${{ matrix.platform == 'android' }}
uses: android-actions/setup-android@v3

# From Godot docs, might not be necessary.
#- name: (Android) Install Android Tools
# if: ${{ startsWith(matrix.identifier, 'android-') }}
# if: ${{ matrix.platform == 'android' }}
# shell: sh
# run: |
# "$ANDROID_SDK_ROOT"/cmdline-tools/latest/bin/sdkmanager --sdk_root="$ANDROID_SDK_ROOT" "platform-tools" "build-tools;30.0.3" "platforms;android-29" "cmdline-tools;latest" "cmake;3.10.2.4988404"
Expand All @@ -124,19 +94,22 @@ jobs:
link-to-sdk: true

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Set up SCons
shell: bash
run: |
python -c "import sys; print(sys.version)"
python -m pip install scons
python -m pip install scons==4.7.0
scons --version

- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ inputs.git-ref }}

# TODO: Cache doesn't work yet. SCons rebuilds the objects even if they already exist. Could be caused by modification dates or extension_api.json.
# fetch-depth: 0 May be needed for cache. See: <https://github.com/actions/checkout/issues/468>.
Expand All @@ -147,30 +120,30 @@ jobs:
# ${{ github.workspace }}/.scons-cache/
# ${{ github.workspace }}/**/.sconsign.dblite
# ${{ github.workspace }}/godot-cpp/gen/
# key: ${{ matrix.identifier }}-${{ github.ref }}-${{ github.sha }}
# key: ${{ matrix.platform }}-${{ github.ref }}-${{ github.sha }}
# restore-keys: |
# ${{ matrix.identifier }}-${{ github.ref }}-${{ github.sha }}
# ${{ matrix.identifier }}-${{ github.ref }}
# ${{ matrix.identifier }}
# ${{ matrix.platform }}-${{ github.ref }}-${{ github.sha }}
# ${{ matrix.platform }}-${{ github.ref }}
# ${{ matrix.platform }}

- name: Compile extension
shell: sh
# env:
# SCONS_CACHE: '${{ github.workspace }}/.scons-cache/'
# SCONS_CACHE_LIMIT: 8192
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' -j2
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' optimize=${{ matrix.optimize }} -j2
ls -l demo/addons/*/bin/

- name: Copy extra files to addon
- name: Prepare files for publish
shell: sh
run: |
for addon in ${{ github.workspace }}/demo/addons/*/; do
cp -n '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' "$addon"
done
cp -n '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' '${{ github.workspace }}/demo/addons/ropesim/'
rm -rf '${{ github.workspace }}/demo/addons/diagnosticlist'
rm '${{ github.workspace }}/demo/project.godot'

- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: |
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI
on:
push:
# branches: [ master ]
pull_request:
# branches: [ master ]

jobs:
ci:
name: "CI"
uses: ./.github/workflows/build.yml
with:
git-ref: ${{ github.ref }}

20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img src="https://github.com/mphe/GDNative-Ropesim/assets/7116001/272f4f65-cb79-4798-97ba-f0d43589caef" width=128px align="right"/>

A 2D verlet integration based rope simulation for Godot 4.2.
A 2D verlet integration based rope simulation for Godot 4.2+.

The computation-heavy simulation part is written in C++ using GDExtension, the rest in GDScript. This allows for fast processing and easy extendability, while keeping the code readable.

Expand All @@ -15,9 +15,9 @@ The last Godot 3.x version can be found on the [3.x branch](https://github.com/m
* [Download](https://github.com/mphe/GDNative-Ropesim/releases/latest) the latest release from the release page, or
* [Download](https://github.com/mphe/GDNative-Ropesim/actions) it from the latest GitHub Actions run, or
* [Compile](#building) it yourself.
3. Copy or symlink `addons/ropesim` to your project's `addons/` directory
4. Enable the addon in the project settings
5. Restart Godot
2. Copy or symlink `addons/ropesim` to your project's `addons/` directory
3. Enable the addon in the project settings
4. Restart Godot

# Building

Expand All @@ -29,7 +29,7 @@ To compile for Linux, run the following commands.
Compiling for other platforms works analogously.

```sh
$ scons target=template_release platform=linux arch=x86_64 -j8
$ scons target=template_release platform=linux optimize=speed arch=x86_64 -j8
$ scons target=template_debug platform=linux arch=x86_64 -j8
```

Expand All @@ -43,15 +43,17 @@ Following nodes exist:
* `RopeHandle`: A handle that can be used to control, animate, or fixate parts of the rope.
* `RopeRendererLine2D`: Renders a target rope using `Line2D`.
* `RopeCollisionShapeGenerator`: Can be used e.g. in an `Area2D` to detect collisions with the target rope.

See inline comments for further information and documentation of node properties.

The included demo project and the showcase video below provide some usage examples.
* `RopeInteraction`: Handles mutual interaction of a target node with a rope. Useful for rope grabbing or pulling mechanics where an object should be able to affect the rope and vice-versa.

When one of these nodes is selected, a "Ropesim" menu appears in the editor toolbar that can be used to toggle live preview in the editor on and off.

All rope related tools, automatically pause themselves when their target rope is paused to save performance.

Use the in-engine help to view the full documentation for each node.

The project also includes various example scenes that demonstrate the features of this plugin.
See also the [showcase video](#showcase) for a basic usage example.

# Showcase

A quick overview of how to use each node.
Expand Down
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ opts.Update(env)
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

env.Append(CCFLAGS="-fdiagnostics-color")


# Sources
env.Append(CPPPATH=["src/"])
Expand Down
2 changes: 1 addition & 1 deletion compile_debug.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

scons compiledb=yes optimize=debug
scons compiledb=yes optimize=debug use_llvm=yes
3 changes: 3 additions & 0 deletions compile_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

scons optimize=speed target=template_release
Empty file.
34 changes: 34 additions & 0 deletions demo/addons/diagnosticlist/Diagnostic.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
extends RefCounted
class_name DiagnosticList_Diagnostic


class Pack extends RefCounted:
var res_uri: StringName
var diagnostics: Array[DiagnosticList_Diagnostic]


enum Severity {
Error,
Warning,
Info,
Hint,
}


## Represents the file path as res:// path
@export var res_uri: StringName
@export var line_start: int # zero-based
@export var column_start: int # zero-based
@export var severity: Severity
@export var message: String

var _filename: StringName


## Returns the filename, i.e. the last component of the path including the extension.
func get_filename() -> StringName:
if _filename.is_empty():
_filename = StringName(res_uri.get_file())
return _filename


Loading
Loading