Skip to content
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ compile_commands.json
*.dylib
*.o
*.wasm
*.obj
*.pdb
*.lib
*.exp

# Godot-specific ignores
.godot/
Expand All @@ -25,3 +29,5 @@ export_presets.cfg
# Mono-specific ignores
.mono/
data_*/

src/gen/*
12 changes: 11 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ opts.Update(env)
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

env.Append(CCFLAGS="-fdiagnostics-color")
if os.name == "posix":
env.Append(CCFLAGS="-fdiagnostics-color")


scons_cache_path = os.environ.get("SCONS_CACHE")
Expand All @@ -40,6 +41,13 @@ if scons_cache_path:
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

# Docs
if env["target"] in ["editor", "template_debug"]:
try:
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
sources.append(doc_data)
except AttributeError:
print("Not including class reference as we're targeting a pre-4.3 baseline.")

# Build
if env["platform"] == "macos":
Expand All @@ -51,4 +59,6 @@ if env["platform"] == "macos":
else:
library = env.SharedLibrary(f"{TARGET_PATH}{env['suffix']}{env['SHLIBSUFFIX']}", source=sources)



Default(library)
10 changes: 10 additions & 0 deletions compile_debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
setlocal

set SCONS_CACHE=%CD%\.scons_cache_debug

scons compiledb=yes optimize=debug debug_symbols=yes %*

:: platform=web threads=no

endlocal
3 changes: 3 additions & 0 deletions compile_release.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

scons optimize=speed target=template_release %*
5 changes: 5 additions & 0 deletions demo/addons/ropesim/Rope.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ signal on_point_count_changed()
## significantly by providing more segments at the beginning and less segments to the end.
@export var segment_length_distribution: Curve: set = _set_seg_dist

@export_group("Forces")

## Stiffness forces the rope to return to its resting position.
## The resting direction is downwards and affected by the the node's rotation.
## Might not produce 100% realistic results with fixed points.
Expand All @@ -41,6 +43,9 @@ signal on_point_count_changed()
## Gravity direction. Will not be normalized.
@export var gravity_direction: Vector2 = Vector2.DOWN

## Optional parameters for wind simulation.
@export var wind: RopeWindParameters

## Dampens the velocity of the rope.
@export var damping: float = 0

Expand Down
2 changes: 1 addition & 1 deletion demo/addons/ropesim/libropesim.gdextension
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[configuration]

entry_symbol = "libropesim_init"
compatibility_minimum = "4.2"
compatibility_minimum = "4.3"

[libraries]

Expand Down
616 changes: 616 additions & 0 deletions demo/rope_examples/wind.tscn

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions doc_classes/NativeRopeServer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="NativeRopeServer" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_computation_time" qualifiers="const">
<return type="float" />
<description>
</description>
</method>
<method name="get_num_ropes" qualifiers="const">
<return type="int" />
<description>
</description>
</method>
<method name="register_rope">
<return type="void" />
<param index="0" name="rope" type="Node2D" />
<description>
</description>
</method>
<method name="unregister_rope">
<return type="void" />
<param index="0" name="rope" type="Node2D" />
<description>
</description>
</method>
</methods>
<members>
<member name="update_in_editor" type="bool" setter="set_update_in_editor" getter="get_update_in_editor" default="false">
</member>
</members>
<signals>
<signal name="on_post_post_update">
<description>
</description>
</signal>
<signal name="on_post_update">
<description>
</description>
</signal>
<signal name="on_pre_pre_update">
<description>
</description>
</signal>
<signal name="on_pre_update">
<description>
</description>
</signal>
</signals>
</class>
27 changes: 27 additions & 0 deletions doc_classes/RopeWindParameters.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RopeWindParameters" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
Data for rope wind.
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<members>
<member name="direction" type="float" setter="set_direction" getter="get_direction" default="0.0">
The angle the wind force is pushing the rope.
</member>
<member name="noise" type="FastNoiseLite" setter="set_noise" getter="get_noise">
Noise function used when generating oscillating wind forces.
</member>
<member name="oscillation_strength" type="float" setter="set_oscillation_strength" getter="get_oscillation_strength" default="0.0">
Amplitude of oscillations in the wind noise. Higher values increase the oscillations perpendicular to the wind direction.
</member>
<member name="wind_strength" type="float" setter="set_wind_strength" getter="get_wind_strength" default="0.0">
How taut the wind force is pulling the rope. Lower values allow the noise to move easier, higher can straighten the rope out even with high noise oscillation strength.
</member>
<member name="enable_wind" type="bool" setter="set_wind_enabled" getter="get_wind_enabled" default="true">
Enables or disables wind for all ropes who reference this resource.
</member>
</members>
</class>
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 67 files
+1 −1 .github/ISSUE_TEMPLATE/bug_report.yml
+3 −3 .github/workflows/ci.yml
+14 −12 README.md
+213 −118 binding_generator.py
+40,645 −20,146 gdextension/extension_api.json
+377 −37 gdextension/gdextension_interface.h
+4 −4 include/godot_cpp/classes/ref.hpp
+78 −21 include/godot_cpp/classes/wrapped.hpp
+22 −7 include/godot_cpp/core/class_db.hpp
+0 −4 include/godot_cpp/core/defs.hpp
+6 −3 include/godot_cpp/core/memory.hpp
+1 −0 include/godot_cpp/core/method_ptrcall.hpp
+2 −0 include/godot_cpp/core/object.hpp
+73 −0 include/godot_cpp/core/print_string.hpp
+11 −0 include/godot_cpp/core/property_info.hpp
+20 −10 include/godot_cpp/core/type_info.hpp
+19 −3 include/godot_cpp/godot.hpp
+42 −24 include/godot_cpp/templates/list.hpp
+4 −0 include/godot_cpp/templates/local_vector.hpp
+2 −2 include/godot_cpp/variant/aabb.hpp
+1 −1 include/godot_cpp/variant/basis.hpp
+1 −0 include/godot_cpp/variant/callable_custom.hpp
+25 −0 include/godot_cpp/variant/callable_method_pointer.hpp
+1 −1 include/godot_cpp/variant/color.hpp
+1 −1 include/godot_cpp/variant/plane.hpp
+1 −1 include/godot_cpp/variant/projection.hpp
+1 −1 include/godot_cpp/variant/quaternion.hpp
+6 −10 include/godot_cpp/variant/rect2.hpp
+6 −10 include/godot_cpp/variant/rect2i.hpp
+1 −1 include/godot_cpp/variant/transform2d.hpp
+1 −1 include/godot_cpp/variant/transform3d.hpp
+10 −0 include/godot_cpp/variant/typed_array.hpp
+3 −0 include/godot_cpp/variant/variant.hpp
+11 −1 include/godot_cpp/variant/vector2.hpp
+15 −1 include/godot_cpp/variant/vector2i.hpp
+12 −1 include/godot_cpp/variant/vector3.hpp
+23 −1 include/godot_cpp/variant/vector3i.hpp
+12 −1 include/godot_cpp/variant/vector4.hpp
+23 −1 include/godot_cpp/variant/vector4i.hpp
+1 −0 misc/scripts/check_get_file_list.py
+9 −0 src/classes/low_level.cpp
+37 −25 src/classes/wrapped.cpp
+46 −0 src/core/class_db.cpp
+39 −0 src/core/print_string.cpp
+76 −6 src/godot.cpp
+16 −2 src/variant/callable_custom.cpp
+11 −2 src/variant/callable_method_pointer.cpp
+4 −4 src/variant/char_string.cpp
+19 −0 src/variant/packed_arrays.cpp
+9 −0 src/variant/variant.cpp
+12 −0 src/variant/vector2.cpp
+26 −0 src/variant/vector2i.cpp
+19 −0 src/variant/vector3.cpp
+21 −0 src/variant/vector3i.cpp
+21 −0 src/variant/vector4.cpp
+24 −0 src/variant/vector4i.cpp
+4 −0 test/SConstruct
+25 −0 test/doc_classes/Example.xml
+5 −0 test/project/example.gd
+14 −1 test/project/main.gd
+3 −1 test/project/main.tscn
+1 −1 test/project/project.godot
+54 −1 test/src/example.cpp
+26 −0 test/src/example.h
+1 −0 test/src/register_types.cpp
+48 −1 tools/godotcpp.py
+4 −0 tools/web.py
30 changes: 23 additions & 7 deletions src/NativeRopeContext.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "NativeRopeContext.hpp"
#include "godot_cpp/classes/physics_direct_space_state2d.hpp"
#include "godot_cpp/classes/physics_server2d.hpp"
#include "godot_cpp/classes/physics_shape_query_parameters2d.hpp"
#include "godot_cpp/classes/world2d.hpp"
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/physics_direct_space_state2d.hpp>
#include <godot_cpp/classes/physics_server2d.hpp>
#include <godot_cpp/classes/world2d.hpp>
#include <godot_cpp/classes/time.hpp>

using namespace godot;

Expand Down Expand Up @@ -53,6 +51,7 @@ void NativeRopeContext::load_context(Node2D* rope)
damping_curve = rope->get("damping_curve");
gravity = rope->get("gravity");
gravity_direction = rope->get("gravity_direction");
wind = rope->get("wind");
damping = rope->get("damping");
stiffness = rope->get("stiffness");
max_endpoint_distance = rope->get("max_endpoint_distance");
Expand Down Expand Up @@ -123,7 +122,7 @@ void NativeRopeContext::_simulate_velocities(double delta)
for (int i = first_idx; i < size; ++i)
velocities[i] = points[i] - oldpoints[i];

// Stiffness
_simulate_wind(&velocities);
_simulate_stiffness(&velocities);

// Apply velocity and damping
Expand All @@ -144,6 +143,23 @@ void NativeRopeContext::_simulate_velocities(double delta)
std::swap(oldpoints, points);
}

void NativeRopeContext::_simulate_wind(PackedVector2Array* velocities) const
{
if (wind.is_null() || !wind->get_enable_wind() || wind->get_noise().is_null())
return;

const float time = (float)Time::get_singleton()->get_ticks_msec();
const Vector2 wind_velocity = wind->get_direction_vector() * wind->get_wind_strength();
const Vector2 orth_strength = wind->get_direction_vector().orthogonal() * wind->get_oscillation_strength();

for (int i = 0; i < points.size(); ++i)
{
const float noise = wind->get_noise()->get_noise_3d(points[i].x, points[i].y, time);
const Vector2 noise_velocity = orth_strength * noise;
(*velocities)[i] += wind_velocity + noise_velocity;
}
}

void NativeRopeContext::_simulate_stiffness(PackedVector2Array* velocities) const
{
// NOTE: oldpoints should not be used here, see comments in simulate_velocities().
Expand Down
9 changes: 6 additions & 3 deletions src/NativeRopeContext.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "godot_cpp/classes/curve.hpp"
#include "godot_cpp/classes/node2d.hpp"
#include "godot_cpp/classes/physics_shape_query_parameters2d.hpp"
#include "RopeWindParameters.hpp"
#include <godot_cpp/classes/curve.hpp>
#include <godot_cpp/classes/node2d.hpp>
#include <godot_cpp/classes/physics_shape_query_parameters2d.hpp>

namespace godot {

Expand All @@ -20,6 +21,7 @@ class NativeRopeContext // NOLINT(cppcoreguidelines-special-member-functions)

protected:
void _simulate_velocities(double delta);
void _simulate_wind(PackedVector2Array* velocities) const;
void _simulate_stiffness(PackedVector2Array* velocities) const;
void _resolve_collisions(double delta, bool disable_contact_reporting);
void _constraint(double delta);
Expand All @@ -39,6 +41,7 @@ class NativeRopeContext // NOLINT(cppcoreguidelines-special-member-functions)
PackedFloat32Array simulation_weights;
float gravity = 0.0;
Vector2 gravity_direction;
Ref<RopeWindParameters> wind;
float damping = 0.0;
Ref<Curve> damping_curve;
float stiffness = 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/NativeRopeServer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "NativeRopeServer.hpp"
#include "NativeRopeContext.hpp"
#include "godot_cpp/classes/window.hpp"
#include "godot_cpp/core/class_db.hpp"
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/vector2.hpp>
#include <godot_cpp/variant/packed_vector2_array.hpp>
#include <godot_cpp/variant/packed_float32_array.hpp>
Expand Down
99 changes: 99 additions & 0 deletions src/RopeWindParameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "RopeWindParameters.hpp"

using namespace godot;

void RopeWindParameters::set_direction(float angle)
{
if (_angle == angle)
return;

_angle = angle;
_wind_direction = Vector2::from_angle(angle);
emit_changed();
}

float RopeWindParameters::get_direction() const
{
return _angle;
}

Vector2 RopeWindParameters::get_direction_vector() const
{
return _wind_direction;
}

void RopeWindParameters::set_wind_strength(float strength)
{
if (_wind_strength == strength)
return;

_wind_strength = strength;
emit_changed();
}

float RopeWindParameters::get_wind_strength() const
{
return _wind_strength;
}

void RopeWindParameters::set_oscillation_strength(float oscillation_strength)
{
if (_oscillation_strength == oscillation_strength)
return;

_oscillation_strength = oscillation_strength;
emit_changed();
}

float RopeWindParameters::get_oscillation_strength() const
{
return _oscillation_strength;
}

void RopeWindParameters::set_noise(Ref<FastNoiseLite> noise)
{
if (_noise == noise)
return;

_noise = noise;
emit_changed();
}

Ref<FastNoiseLite> RopeWindParameters::get_noise() const
{
return _noise;
}

void RopeWindParameters::set_enable_wind(bool wind_enabled)
{
if (_enable_wind == wind_enabled)
return;

_enable_wind = wind_enabled;
emit_changed();
}

bool RopeWindParameters::get_enable_wind() const
{
return _enable_wind;
}

void RopeWindParameters::_bind_methods()
{
ClassDB::bind_method(D_METHOD("set_direction", "direction"), &RopeWindParameters::set_direction);
ClassDB::bind_method(D_METHOD("get_direction"), &RopeWindParameters::get_direction);
ClassDB::bind_method(D_METHOD("set_wind_strength", "strength"), &RopeWindParameters::set_wind_strength);
ClassDB::bind_method(D_METHOD("get_wind_strength"), &RopeWindParameters::get_wind_strength);
ClassDB::bind_method(D_METHOD("set_oscillation_strength", "strength"), &RopeWindParameters::set_oscillation_strength);
ClassDB::bind_method(D_METHOD("get_oscillation_strength"), &RopeWindParameters::get_oscillation_strength);
ClassDB::bind_method(D_METHOD("set_noise", "noise"), &RopeWindParameters::set_noise);
ClassDB::bind_method(D_METHOD("get_noise"), &RopeWindParameters::get_noise);
ClassDB::bind_method(D_METHOD("set_enable_wind", "enabled"), &RopeWindParameters::set_enable_wind);
ClassDB::bind_method(D_METHOD("get_enable_wind"), &RopeWindParameters::get_enable_wind);

ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "direction", PROPERTY_HINT_RANGE, "0,360,0.1,radians_as_degrees"), "set_direction", "get_direction");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wind_strength"), "set_wind_strength", "get_wind_strength");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oscillation_strength"), "set_oscillation_strength", "get_oscillation_strength");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "FastNoiseLite"), "set_noise", "get_noise");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_wind"), "set_enable_wind", "get_enable_wind");
}
Loading
Loading