summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/array.cpp11
-rw-r--r--core/array.h6
-rw-r--r--core/bind/core_bind.cpp6
-rw-r--r--core/bind/core_bind.h1
-rw-r--r--core/callable.cpp29
-rw-r--r--core/callable.h6
-rw-r--r--core/callable_bind.cpp193
-rw-r--r--core/callable_bind.h85
-rw-r--r--core/callable_method_pointer.h249
-rw-r--r--core/core_string_names.cpp2
-rw-r--r--core/core_string_names.h2
-rw-r--r--core/io/http_client.cpp4
-rw-r--r--core/math/aabb.cpp16
-rw-r--r--core/math/aabb.h4
-rw-r--r--core/math/geometry_3d.h48
-rw-r--r--core/math/plane.cpp26
-rw-r--r--core/math/plane.h7
-rw-r--r--core/math/rect2.h8
-rw-r--r--core/math/vector2.h8
-rw-r--r--core/object.cpp14
-rw-r--r--core/object.h1
-rw-r--r--core/simple_type.h5
-rw-r--r--core/thread_work_pool.h27
-rw-r--r--core/ustring.cpp63
-rw-r--r--core/ustring.h5
-rw-r--r--core/variant.h28
-rw-r--r--core/variant_call.cpp2887
-rw-r--r--core/variant_internal.h534
-rw-r--r--doc/classes/Animation.xml16
-rw-r--r--doc/classes/Area2D.xml6
-rw-r--r--doc/classes/Area3D.xml6
-rw-r--r--doc/classes/ArrayMesh.xml1
-rw-r--r--doc/classes/BaseButton.xml3
-rw-r--r--doc/classes/Basis.xml2
-rw-r--r--doc/classes/Callable.xml14
-rw-r--r--doc/classes/CanvasItem.xml6
-rw-r--r--doc/classes/FuncRef.xml16
-rw-r--r--doc/classes/GPUParticles3D.xml2
-rw-r--r--doc/classes/GPUParticlesAttractor3D.xml23
-rw-r--r--doc/classes/GPUParticlesAttractorBox.xml17
-rw-r--r--doc/classes/GPUParticlesAttractorSphere.xml17
-rw-r--r--doc/classes/GPUParticlesAttractorVectorField.xml19
-rw-r--r--doc/classes/GPUParticlesCollision3D.xml17
-rw-r--r--doc/classes/GPUParticlesCollisionBox.xml17
-rw-r--r--doc/classes/GPUParticlesCollisionHeightField.xml43
-rw-r--r--doc/classes/GPUParticlesCollisionSDF.xml37
-rw-r--r--doc/classes/GPUParticlesCollisionSphere.xml17
-rw-r--r--doc/classes/Geometry3D.xml9
-rw-r--r--doc/classes/KinematicBody2D.xml6
-rw-r--r--doc/classes/KinematicBody3D.xml6
-rw-r--r--doc/classes/LinkButton.xml1
-rw-r--r--doc/classes/MenuButton.xml1
-rw-r--r--doc/classes/MultiMesh.xml2
-rw-r--r--doc/classes/Node3D.xml2
-rw-r--r--doc/classes/ParticlesMaterial.xml10
-rw-r--r--doc/classes/ProjectSettings.xml10
-rw-r--r--doc/classes/RandomNumberGenerator.xml1
-rw-r--r--doc/classes/RenderingServer.xml21
-rw-r--r--doc/classes/RigidBody2D.xml2
-rw-r--r--doc/classes/RigidBody3D.xml2
-rw-r--r--doc/classes/VisualShaderNode.xml6
-rw-r--r--drivers/dummy/rasterizer_dummy.h24
-rw-r--r--editor/editor_node.cpp6
-rw-r--r--editor/editor_properties.cpp2
-rw-r--r--editor/editor_run_native.cpp6
-rw-r--r--editor/import/resource_importer_layered_texture.cpp2
-rw-r--r--editor/localization_editor.cpp2
-rw-r--r--editor/node_3d_editor_gizmos.cpp261
-rw-r--r--editor/node_3d_editor_gizmos.h17
-rw-r--r--editor/plugins/animation_state_machine_editor.cpp6
-rw-r--r--editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp201
-rw-r--r--editor/plugins/gpu_particles_collision_sdf_editor_plugin.h74
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp9
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp25
-rw-r--r--editor/plugins/tile_map_editor_plugin.h1
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp328
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h8
-rw-r--r--editor/scene_tree_dock.cpp2
-rw-r--r--editor/shader_globals_editor.cpp4
-rw-r--r--misc/dist/html/editor.html475
-rw-r--r--modules/bullet/rigid_body_bullet.cpp1
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml1
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp1
-rw-r--r--modules/mono/csharp_script.cpp190
-rw-r--r--modules/mono/csharp_script.h1
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.nuspec2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs2
-rwxr-xr-xmodules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs4
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs12
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp1
-rw-r--r--modules/webrtc/doc_classes/WebRTCPeerConnection.xml2
-rw-r--r--platform/javascript/SCsub3
-rw-r--r--platform/javascript/api/api.cpp2
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.cpp153
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.h62
-rw-r--r--platform/javascript/detect.py2
-rw-r--r--platform/javascript/engine/engine.js8
-rw-r--r--platform/javascript/native/utils.js21
-rw-r--r--platform/linuxbsd/display_server_x11.cpp37
-rw-r--r--platform/uwp/detect.py2
-rw-r--r--platform/uwp/export/export.cpp2
-rw-r--r--platform/windows/detect.py2
-rw-r--r--scene/3d/gpu_particles_3d.cpp14
-rw-r--r--scene/3d/gpu_particles_3d.h3
-rw-r--r--scene/3d/gpu_particles_collision_3d.cpp901
-rw-r--r--scene/3d/gpu_particles_collision_3d.h342
-rw-r--r--scene/gui/base_button.cpp15
-rw-r--r--scene/gui/base_button.h4
-rw-r--r--scene/gui/code_edit.cpp3
-rw-r--r--scene/gui/link_button.cpp1
-rw-r--r--scene/gui/menu_button.cpp1
-rw-r--r--scene/gui/tree.cpp3
-rw-r--r--scene/main/window.cpp4
-rw-r--r--scene/register_scene_types.cpp10
-rw-r--r--scene/resources/particles_material.cpp98
-rw-r--r--scene/resources/particles_material.h34
-rw-r--r--scene/resources/visual_shader.cpp1
-rw-r--r--servers/audio/effects/audio_effect_spectrum_analyzer.cpp19
-rw-r--r--servers/rendering/rasterizer.h24
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp1
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp33
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h1
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp17
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_rd.h3
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp418
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_storage_rd.h100
-rw-r--r--servers/rendering/rasterizer_rd/shaders/particles.glsl333
-rw-r--r--servers/rendering/rendering_server_raster.cpp3
-rw-r--r--servers/rendering/rendering_server_raster.h16
-rw-r--r--servers/rendering/rendering_server_scene.cpp50
-rw-r--r--servers/rendering/rendering_server_scene.h3
-rw-r--r--servers/rendering/rendering_server_wrap_mt.cpp1
-rw-r--r--servers/rendering/rendering_server_wrap_mt.h17
-rw-r--r--servers/rendering/shader_language.cpp59
-rw-r--r--servers/rendering/shader_language.h1
-rw-r--r--servers/rendering/shader_types.cpp6
-rw-r--r--servers/rendering_server.cpp5
-rw-r--r--servers/rendering_server.h39
143 files changed, 6973 insertions, 2233 deletions
diff --git a/core/array.cpp b/core/array.cpp
index d1c0688e63..3c6c8e768b 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -330,9 +330,8 @@ struct _ArrayVariantSort {
}
};
-Array &Array::sort() {
+void Array::sort() {
_p->array.sort_custom<_ArrayVariantSort>();
- return *this;
}
struct _ArrayVariantSortCustom {
@@ -349,14 +348,13 @@ struct _ArrayVariantSortCustom {
return res;
}
};
-Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
- ERR_FAIL_NULL_V(p_obj, *this);
+void Array::sort_custom(Object *p_obj, const StringName &p_function) {
+ ERR_FAIL_NULL(p_obj);
SortArray<Variant, _ArrayVariantSortCustom, true> avs;
avs.compare.obj = p_obj;
avs.compare.func = p_function;
avs.sort(_p->array.ptrw(), _p->array.size());
- return *this;
}
void Array::shuffle() {
@@ -415,9 +413,8 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam
return bisect(_p->array, p_value, p_before, less);
}
-Array &Array::invert() {
+void Array::invert() {
_p->array.invert();
- return *this;
}
void Array::push_front(const Variant &p_value) {
diff --git a/core/array.h b/core/array.h
index d2e0537ad5..34367088e4 100644
--- a/core/array.h
+++ b/core/array.h
@@ -75,12 +75,12 @@ public:
Variant front() const;
Variant back() const;
- Array &sort();
- Array &sort_custom(Object *p_obj, const StringName &p_function);
+ void sort();
+ void sort_custom(Object *p_obj, const StringName &p_function);
void shuffle();
int bsearch(const Variant &p_value, bool p_before = true);
int bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before = true);
- Array &invert();
+ void invert();
int find(const Variant &p_value, int p_from = 0) const;
int rfind(const Variant &p_value, int p_from = -1) const;
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 88e31c56fe..baf5d4b928 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1156,10 +1156,6 @@ Vector<Vector3> _Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const
return Geometry3D::clip_polygon(p_points, p_plane);
}
-int _Geometry3D::get_uv84_normal_bit(const Vector3 &p_vector) {
- return Geometry3D::get_uv84_normal_bit(p_vector);
-}
-
void _Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry3D::build_box_planes);
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
@@ -1171,8 +1167,6 @@ void _Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &_Geometry3D::get_closest_point_to_segment_uncapped);
- ClassDB::bind_method(D_METHOD("get_uv84_normal_bit", "normal"), &_Geometry3D::get_uv84_normal_bit);
-
ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry3D::ray_intersects_triangle);
ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry3D::segment_intersects_triangle);
ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry3D::segment_intersects_sphere);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 5c9520d7fe..e75e740cd5 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -344,7 +344,6 @@ public:
Vector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
Vector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
Vector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
- int get_uv84_normal_bit(const Vector3 &p_vector);
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
diff --git a/core/callable.cpp b/core/callable.cpp
index b7bdc715f8..c368565687 100644
--- a/core/callable.cpp
+++ b/core/callable.cpp
@@ -30,6 +30,7 @@
#include "callable.h"
+#include "callable_bind.h"
#include "core/script_language.h"
#include "message_queue.h"
#include "object.h"
@@ -53,6 +54,18 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu
}
}
+Callable Callable::bind(const Variant **p_arguments, int p_argcount) const {
+ Vector<Variant> args;
+ args.resize(p_argcount);
+ for (int i = 0; i < p_argcount; i++) {
+ args.write[i] = *p_arguments[i];
+ }
+ return Callable(memnew(CallableCustomBind(*this, args)));
+}
+Callable Callable::unbind(int p_argcount) const {
+ return Callable(memnew(CallableCustomUnbind(*this, p_argcount)));
+}
+
Object *Callable::get_object() const {
if (is_null()) {
return nullptr;
@@ -85,6 +98,18 @@ CallableCustom *Callable::get_custom() const {
return custom;
}
+const Callable *Callable::get_base_comparator() const {
+ const Callable *comparator = nullptr;
+ if (is_custom()) {
+ comparator = custom->get_base_comparator();
+ }
+ if (comparator) {
+ return comparator;
+ } else {
+ return this;
+ }
+}
+
uint32_t Callable::hash() const {
if (is_custom()) {
return custom->hash();
@@ -258,6 +283,10 @@ Callable::~Callable() {
}
}
+const Callable *CallableCustom::get_base_comparator() const {
+ return nullptr;
+}
+
CallableCustom::CallableCustom() {
ref_count.init();
}
diff --git a/core/callable.h b/core/callable.h
index 7fd6b54cf7..936272a681 100644
--- a/core/callable.h
+++ b/core/callable.h
@@ -80,6 +80,9 @@ public:
return method != StringName();
}
+ Callable bind(const Variant **p_arguments, int p_argcount) const;
+ Callable unbind(int p_argcount) const;
+
Object *get_object() const;
ObjectID get_object_id() const;
StringName get_method() const;
@@ -87,6 +90,8 @@ public:
uint32_t hash() const;
+ const Callable *get_base_comparator() const; //used for bind/unbind to do less precise comparisons (ignoring binds) in signal connect/disconnect
+
bool operator==(const Callable &p_callable) const;
bool operator!=(const Callable &p_callable) const;
bool operator<(const Callable &p_callable) const;
@@ -119,6 +124,7 @@ public:
virtual CompareLessFunc get_compare_less_func() const = 0;
virtual ObjectID get_object() const = 0; //must always be able to provide an object
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const = 0;
+ virtual const Callable *get_base_comparator() const;
CallableCustom();
virtual ~CallableCustom() {}
diff --git a/core/callable_bind.cpp b/core/callable_bind.cpp
new file mode 100644
index 0000000000..da08d3ccbd
--- /dev/null
+++ b/core/callable_bind.cpp
@@ -0,0 +1,193 @@
+/*************************************************************************/
+/* callable_bind.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "callable_bind.h"
+
+//////////////////////////////////
+
+uint32_t CallableCustomBind::hash() const {
+ return callable.hash();
+}
+String CallableCustomBind::get_as_text() const {
+ return callable.operator String();
+}
+
+bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomBind *a = (const CallableCustomBind *)p_a;
+ const CallableCustomBind *b = (const CallableCustomBind *)p_b;
+
+ if (!(a->callable != b->callable)) {
+ return false;
+ }
+
+ if (a->binds.size() != b->binds.size()) {
+ return false;
+ }
+
+ return true;
+}
+
+bool CallableCustomBind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomBind *a = (const CallableCustomBind *)p_a;
+ const CallableCustomBind *b = (const CallableCustomBind *)p_b;
+
+ if (a->callable < b->callable) {
+ return true;
+ } else if (b->callable < a->callable) {
+ return false;
+ }
+
+ return a->binds.size() < b->binds.size();
+}
+
+CallableCustom::CompareEqualFunc CallableCustomBind::get_compare_equal_func() const {
+ return _equal_func;
+}
+CallableCustom::CompareLessFunc CallableCustomBind::get_compare_less_func() const {
+ return _less_func;
+}
+ObjectID CallableCustomBind::get_object() const {
+ return callable.get_object_id();
+}
+const Callable *CallableCustomBind::get_base_comparator() const {
+ return &callable;
+}
+
+void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount));
+ for (int i = 0; i < p_argcount; i++) {
+ args[i] = (const Variant *)p_arguments[i];
+ }
+ for (int i = 0; i < binds.size(); i++) {
+ args[i + p_argcount] = (const Variant *)&binds[i];
+ }
+
+ callable.call(args, p_argcount + binds.size(), r_return_value, r_call_error);
+}
+
+CallableCustomBind::CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds) {
+ callable = p_callable;
+ binds = p_binds;
+}
+
+CallableCustomBind::~CallableCustomBind() {
+}
+
+//////////////////////////////////
+
+uint32_t CallableCustomUnbind::hash() const {
+ return callable.hash();
+}
+String CallableCustomUnbind::get_as_text() const {
+ return callable.operator String();
+}
+
+bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a;
+ const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b;
+
+ if (!(a->callable != b->callable)) {
+ return false;
+ }
+
+ if (a->argcount != b->argcount) {
+ return false;
+ }
+
+ return true;
+}
+
+bool CallableCustomUnbind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) {
+ const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a;
+ const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b;
+
+ if (a->callable < b->callable) {
+ return true;
+ } else if (b->callable < a->callable) {
+ return false;
+ }
+
+ return a->argcount < b->argcount;
+}
+
+CallableCustom::CompareEqualFunc CallableCustomUnbind::get_compare_equal_func() const {
+ return _equal_func;
+}
+CallableCustom::CompareLessFunc CallableCustomUnbind::get_compare_less_func() const {
+ return _less_func;
+}
+ObjectID CallableCustomUnbind::get_object() const {
+ return callable.get_object_id();
+}
+const Callable *CallableCustomUnbind::get_base_comparator() const {
+ return &callable;
+}
+
+void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+ if (argcount > p_argcount) {
+ r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_call_error.argument = 0;
+ r_call_error.expected = argcount;
+ return;
+ }
+ callable.call(p_arguments, p_argcount - argcount, r_return_value, r_call_error);
+}
+
+CallableCustomUnbind::CallableCustomUnbind(const Callable &p_callable, int p_argcount) {
+ callable = p_callable;
+ argcount = p_argcount;
+}
+
+CallableCustomUnbind::~CallableCustomUnbind() {
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1) {
+ return p_callable.bind((const Variant **)&p_arg1, 1);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2) {
+ const Variant *args[2] = { &p_arg1, &p_arg2 };
+ return p_callable.bind(args, 2);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
+ const Variant *args[3] = { &p_arg1, &p_arg2, &p_arg3 };
+ return p_callable.bind(args, 3);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
+ const Variant *args[4] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4 };
+ return p_callable.bind(args, 4);
+}
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) {
+ const Variant *args[5] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5 };
+ return p_callable.bind(args, 5);
+}
diff --git a/core/callable_bind.h b/core/callable_bind.h
new file mode 100644
index 0000000000..21b9228be3
--- /dev/null
+++ b/core/callable_bind.h
@@ -0,0 +1,85 @@
+/*************************************************************************/
+/* callable_bind.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef CALLABLE_BIND_H
+#define CALLABLE_BIND_H
+
+#include "core/callable.h"
+#include "core/variant.h"
+
+class CallableCustomBind : public CallableCustom {
+ Callable callable;
+ Vector<Variant> binds;
+
+ static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
+ static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
+
+public:
+ //for every type that inherits, these must always be the same for this type
+ virtual uint32_t hash() const;
+ virtual String get_as_text() const;
+ virtual CompareEqualFunc get_compare_equal_func() const;
+ virtual CompareLessFunc get_compare_less_func() const;
+ virtual ObjectID get_object() const; //must always be able to provide an object
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
+ virtual const Callable *get_base_comparator() const;
+
+ CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds);
+ virtual ~CallableCustomBind();
+};
+
+class CallableCustomUnbind : public CallableCustom {
+ Callable callable;
+ int argcount;
+
+ static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
+ static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
+
+public:
+ //for every type that inherits, these must always be the same for this type
+ virtual uint32_t hash() const;
+ virtual String get_as_text() const;
+ virtual CompareEqualFunc get_compare_equal_func() const;
+ virtual CompareLessFunc get_compare_less_func() const;
+ virtual ObjectID get_object() const; //must always be able to provide an object
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
+ virtual const Callable *get_base_comparator() const;
+
+ CallableCustomUnbind(const Callable &p_callable, int p_argcount);
+ virtual ~CallableCustomUnbind();
+};
+
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4);
+Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5);
+
+#endif // CALLABLE_BIND_H
diff --git a/core/callable_method_pointer.h b/core/callable_method_pointer.h
index 1bb89e53e1..a2275452b4 100644
--- a/core/callable_method_pointer.h
+++ b/core/callable_method_pointer.h
@@ -36,6 +36,7 @@
#include "core/object.h"
#include "core/os/copymem.h"
#include "core/simple_type.h"
+#include "core/variant_internal.h"
class CallableCustomMethodPointerBase : public CallableCustom {
uint32_t *comp_ptr;
@@ -115,7 +116,7 @@ struct VariantCasterAndValidate<const T &> {
#endif // DEBUG_METHODS_ENABLED
-// GCC 8 raises "parameter 'p_args' set but not used" here, probably using a
+// GCC raises "parameter 'p_args' set but not used" here, probably using a
// template version that does not have arguments and thus sees it unused, but
// obviously the template can be used for functions with and without them, and
// the optimizer will get rid of it anyway.
@@ -135,9 +136,49 @@ void call_with_variant_args_helper(T *p_instance, void (T::*p_method)(P...), con
#endif
}
-#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
+#ifdef PTRCALL_ENABLED
+
+template <class T, class... P, size_t... Is>
+void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
+ (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_ptr_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
+ PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret, IndexSequence<Is...>) {
+ PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
+ PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret);
+}
+
+#endif // PTRCALL_ENABLED
+
+template <class T, class... P, size_t... Is>
+void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
+ (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_validated_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
+ VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_validated_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
+ VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
+}
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_validated_variant_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
+ VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
+}
template <class T, class... P>
void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
@@ -157,6 +198,91 @@ void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Vari
call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
}
+#ifdef PTRCALL_ENABLED
+
+template <class T, class... P>
+void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) {
+ call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_ptr_args_ret(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret) {
+ call_with_ptr_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_ptr_args_retc(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret) {
+ call_with_ptr_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret) {
+ call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+#endif // PTRCALL_ENABLED
+
+template <class T, class... P>
+void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) {
+ call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_validated_variant_args_ret(Variant *base, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_ret_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_validated_variant_args_retc(Variant *base, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+void call_with_validated_variant_args_static_retc(Variant *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_static_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
+}
+
+#ifdef DEBUG_METHODS_ENABLED
+
+template <class Q>
+void call_get_argument_type_helper(int p_arg, int &index, Variant::Type &type) {
+ if (p_arg == index) {
+ type = GetTypeInfo<Q>::VARIANT_TYPE;
+ }
+ index++;
+}
+
+// GCC's warnings checker really doesn't like variadic voodoo.
+// It sees `index` unused below in some branches, so it raises a warning.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+
+template <class... P>
+Variant::Type call_get_argument_type(int p_arg) {
+ Variant::Type type = Variant::NIL;
+ int index = 0;
+ // I think rocket science is simpler than modern C++.
+ using expand_type = int[];
+ expand_type a{ 0, (call_get_argument_type_helper<P>(p_arg, index, type), 0)... };
+ (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
+ return type;
+}
+
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
+#else
+
+template <class... P>
+Variant::Type call_get_argument_type(int p_arg) {
+ return Variant::NIL;
+}
+
+#endif // DEBUG_METHODS_ENABLED
+
template <class T, class... P>
class CallableCustomMethodPointer : public CallableCustomMethodPointerBase {
struct Data {
@@ -212,15 +338,6 @@ Callable create_custom_callable_function_pointer(T *p_instance,
// VERSION WITH RETURN
-// GCC 8 raises "parameter 'p_args' set but not used" here, probably using a
-// template version that does not have arguments and thus sees it unused, but
-// obviously the template can be used for functions with and without them, and
-// the optimizer will get rid of it anyway.
-#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
-#endif
-
template <class T, class R, class... P, size_t... Is>
void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
r_error.error = Callable::CallError::CALL_OK;
@@ -228,14 +345,10 @@ void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), co
#ifdef DEBUG_METHODS_ENABLED
r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
#else
- (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
+ r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
#endif
}
-#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
template <class T, class R, class... P>
void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
#ifdef DEBUG_METHODS_ENABLED
@@ -308,10 +421,110 @@ Callable create_custom_callable_function_pointer(T *p_instance,
return Callable(ccmp);
}
+// CONST VERSION WITH RETURN
+
+template <class T, class R, class... P, size_t... Is>
+void call_with_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
+ r_error.error = Callable::CallError::CALL_OK;
+
+#ifdef DEBUG_METHODS_ENABLED
+ r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
+#else
+ r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
+#endif
+}
+
+template <class T, class R, class... P>
+void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+#ifdef DEBUG_METHODS_ENABLED
+ if ((size_t)p_argcount > sizeof...(P)) {
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+ return;
+ }
+
+ if ((size_t)p_argcount < sizeof...(P)) {
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+ return;
+ }
+#endif
+ call_with_variant_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
+}
+
+template <class T, class R, class... P>
+class CallableCustomMethodPointerRetC : public CallableCustomMethodPointerBase {
+ struct Data {
+ T *instance;
+#ifdef DEBUG_ENABLED
+ uint64_t object_id;
+#endif
+ R(T::*method)
+ (P...) const;
+ } data;
+
+public:
+ virtual ObjectID get_object() const {
+#ifdef DEBUG_ENABLED
+ if (ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr) {
+ return ObjectID();
+ }
+#endif
+ return data.instance->get_instance_id();
+ }
+
+ virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method.");
+#endif
+ call_with_variant_args_retc(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
+ }
+
+ CallableCustomMethodPointerRetC(T *p_instance, R (T::*p_method)(P...) const) {
+ zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes.
+ data.instance = p_instance;
+#ifdef DEBUG_ENABLED
+ data.object_id = p_instance->get_instance_id();
+#endif
+ data.method = p_method;
+ _setup((uint32_t *)&data, sizeof(Data));
+ }
+};
+
+template <class T, class R, class... P>
+Callable create_custom_callable_function_pointer(T *p_instance,
+#ifdef DEBUG_METHODS_ENABLED
+ const char *p_func_text,
+#endif
+ R (T::*p_method)(P...) const) {
+
+ typedef CallableCustomMethodPointerRetC<T, R, P...> CCMP; // Messes with memnew otherwise.
+ CCMP *ccmp = memnew(CCMP(p_instance, p_method));
+#ifdef DEBUG_METHODS_ENABLED
+ ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
+#endif
+ return Callable(ccmp);
+}
+
#ifdef DEBUG_METHODS_ENABLED
#define callable_mp(I, M) create_custom_callable_function_pointer(I, #M, M)
#else
#define callable_mp(I, M) create_custom_callable_function_pointer(I, M)
#endif
+template <class T, class R, class... P, size_t... Is>
+void call_with_variant_args_retc_static_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
+ r_error.error = Callable::CallError::CALL_OK;
+
+#ifdef DEBUG_METHODS_ENABLED
+ r_ret = (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
+#else
+ r_ret = (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...);
+#endif
+}
+
+#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
#endif // CALLABLE_METHOD_POINTER_H
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index 1d3b333efc..6f86f107e6 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -73,6 +73,8 @@ CoreStringNames::CoreStringNames() :
a8(StaticCString::create("a8")),
call(StaticCString::create("call")),
call_deferred(StaticCString::create("call_deferred")),
+ bind(StaticCString::create("bind")),
+ unbind(StaticCString::create("unbind")),
emit(StaticCString::create("emit")),
notification(StaticCString::create("notification")) {
}
diff --git a/core/core_string_names.h b/core/core_string_names.h
index 1a18c84572..43597ef301 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -92,6 +92,8 @@ public:
StringName call;
StringName call_deferred;
+ StringName bind;
+ StringName unbind;
StringName emit;
StringName notification;
};
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 46e45500bf..a25413b21b 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -96,6 +96,10 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object.");
+ if (connection == p_connection) {
+ return;
+ }
+
close();
connection = p_connection;
status = STATUS_CONNECTED;
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index f5c667dab0..e868ebc7c8 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -31,6 +31,7 @@
#include "aabb.h"
#include "core/print_string.h"
+#include "core/variant.h"
real_t AABB::get_area() const {
return size.x * size.y * size.z;
@@ -375,6 +376,21 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
}
+Variant AABB::intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const {
+ Vector3 inters;
+ if (intersects_segment(p_from, p_to, &inters)) {
+ return inters;
+ }
+ return Variant();
+}
+Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const {
+ Vector3 inters;
+ if (intersects_ray(p_from, p_dir, &inters)) {
+ return inters;
+ }
+ return Variant();
+}
+
AABB::operator String() const {
return String() + position + " - " + size;
}
diff --git a/core/math/aabb.h b/core/math/aabb.h
index bd1f3a1a36..8c08754e1c 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -39,6 +39,7 @@
* AABB / AABB (Axis Aligned Bounding Box)
* This is implemented by a point (position) and the box size
*/
+class Variant;
class AABB {
public:
@@ -103,6 +104,9 @@ public:
return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs());
}
+ Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const;
+ Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
+
operator String() const;
_FORCE_INLINE_ AABB() {}
diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h
index 6bbf518141..11cac8f108 100644
--- a/core/math/geometry_3d.h
+++ b/core/math/geometry_3d.h
@@ -636,54 +636,6 @@ public:
void optimize_vertices();
};
- _FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) {
- int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5));
-
- if (lat == 0) {
- return 24;
- } else if (lat == 4) {
- return 25;
- }
-
- int lon = Math::fast_ftoi(Math::floor((Math_PI + Math::atan2(p_vector.x, p_vector.z)) * 8.0 / (Math_PI * 2.0) + 0.5)) % 8;
-
- return lon + (lat - 1) * 8;
- }
-
- _FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) {
- if (p_idx == 24) {
- return 1 | 2 | 4 | 8;
- } else if (p_idx == 25) {
- return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20);
- } else {
- int ret = 0;
- if ((p_idx % 8) == 0) {
- ret |= (1 << (p_idx + 7));
- } else {
- ret |= (1 << (p_idx - 1));
- }
- if ((p_idx % 8) == 7) {
- ret |= (1 << (p_idx - 7));
- } else {
- ret |= (1 << (p_idx + 1));
- }
-
- int mask = ret | (1 << p_idx);
- if (p_idx < 8) {
- ret |= 24;
- } else {
- ret |= mask >> 8;
- }
-
- if (p_idx >= 16) {
- ret |= 25;
- } else {
- ret |= mask << 8;
- }
-
- return ret;
- }
- }
static MeshData build_convex_mesh(const Vector<Plane> &p_planes);
static Vector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis = Vector3::AXIS_Z);
static Vector<Plane> build_box_planes(const Vector3 &p_extents);
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 4200484c59..ae2021d2f6 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -31,6 +31,7 @@
#include "plane.h"
#include "core/math/math_funcs.h"
+#include "core/variant.h"
void Plane::set_normal(const Vector3 &p_normal) {
normal = p_normal;
@@ -138,6 +139,31 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec
return true;
}
+Variant Plane::intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const {
+ Vector3 inters;
+ if (intersect_3(p_plane1, p_plane2, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const {
+ Vector3 inters;
+ if (intersects_ray(p_from, p_dir, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+Variant Plane::intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const {
+ Vector3 inters;
+ if (intersects_segment(p_begin, p_end, &inters)) {
+ return inters;
+ } else {
+ return Variant();
+ }
+}
+
/* misc */
bool Plane::is_equal_approx_any_side(const Plane &p_plane) const {
diff --git a/core/math/plane.h b/core/math/plane.h
index 70a6111edd..1386b0a2cb 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -33,6 +33,8 @@
#include "core/math/vector3.h"
+class Variant;
+
class Plane {
public:
Vector3 normal;
@@ -59,6 +61,11 @@ public:
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const;
bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const;
+ // For Variant bindings.
+ Variant intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const;
+ Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
+ Variant intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const;
+
_FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const {
return p_point - normal * distance_to(p_point);
}
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 14393325ec..7660db71eb 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -197,6 +197,10 @@ struct Rect2 {
return g;
}
+ inline Rect2 grow_margin_bind(uint32_t p_margin, real_t p_amount) const {
+ return grow_margin(Margin(p_margin), p_amount);
+ }
+
inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const {
Rect2 g = *this;
g.position.x -= p_left;
@@ -363,6 +367,10 @@ struct Rect2i {
return g;
}
+ inline Rect2i grow_margin_bind(uint32_t p_margin, int p_amount) const {
+ return grow_margin(Margin(p_margin), p_amount);
+ }
+
inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const {
Rect2i g = *this;
g.position.x -= p_left;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index f41bcc15bc..c2a2656e72 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -65,6 +65,14 @@ struct Vector2 {
real_t length() const;
real_t length_squared() const;
+ Vector2 min(const Vector2 &p_vector2) const {
+ return Vector2(MIN(x, p_vector2.x), MIN(y, p_vector2.y));
+ }
+
+ Vector2 max(const Vector2 &p_vector2) const {
+ return Vector2(MAX(x, p_vector2.x), MAX(y, p_vector2.y));
+ }
+
real_t distance_to(const Vector2 &p_vector2) const;
real_t distance_squared_to(const Vector2 &p_vector2) const;
real_t angle_to(const Vector2 &p_vector2) const;
diff --git a/core/object.cpp b/core/object.cpp
index 67c605c39b..0d9e5c5116 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1315,9 +1315,10 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
Callable target = p_callable;
- if (s->slot_map.has(target)) {
+ //compare with the base callable, so binds can be ignored
+ if (s->slot_map.has(*target.get_base_comparator())) {
if (p_flags & CONNECT_REFERENCE_COUNTED) {
- s->slot_map[target].reference_count++;
+ s->slot_map[*target.get_base_comparator()].reference_count++;
return OK;
} else {
ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Signal '" + p_signal + "' is already connected to given callable '" + p_callable + "' in that object.");
@@ -1337,7 +1338,8 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
slot.reference_count = 1;
}
- s->slot_map[target] = slot;
+ //use callable version as key, so binds can be ignored
+ s->slot_map[*target.get_base_comparator()] = slot;
return OK;
}
@@ -1364,7 +1366,7 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
Callable target = p_callable;
- return s->slot_map.has(target);
+ return s->slot_map.has(*target.get_base_comparator());
//const Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.find(target);
//return (E!=nullptr );
}
@@ -1386,7 +1388,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
SignalData *s = signal_map.getptr(p_signal);
ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string()));
- ERR_FAIL_COND_MSG(!s->slot_map.has(p_callable), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + ".");
+ ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + ".");
SignalData::Slot *slot = &s->slot_map[p_callable];
@@ -1398,7 +1400,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
}
target_object->connections.erase(slot->cE);
- s->slot_map.erase(p_callable);
+ s->slot_map.erase(*p_callable.get_base_comparator());
if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) {
//not user signal, delete
diff --git a/core/object.h b/core/object.h
index 12ef600dfc..f600e597ec 100644
--- a/core/object.h
+++ b/core/object.h
@@ -31,6 +31,7 @@
#ifndef OBJECT_H
#define OBJECT_H
+#include "core/callable_bind.h"
#include "core/hash_map.h"
#include "core/list.h"
#include "core/map.h"
diff --git a/core/simple_type.h b/core/simple_type.h
index 10dc36cbd4..841ab9f384 100644
--- a/core/simple_type.h
+++ b/core/simple_type.h
@@ -48,4 +48,9 @@ struct GetSimpleTypeT<T const> {
typedef T type_t;
};
+template <class T>
+struct GetSimpleTypeT<T const &> {
+ typedef T type_t;
+};
+
#endif // SIMPLE_TYPE_H
diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h
index e21d3974ee..661060aa3f 100644
--- a/core/thread_work_pool.h
+++ b/core/thread_work_pool.h
@@ -73,13 +73,15 @@ class ThreadWorkPool {
ThreadData *threads = nullptr;
uint32_t thread_count = 0;
+ BaseWork *current_work = nullptr;
static void _thread_function(ThreadData *p_thread);
public:
template <class C, class M, class U>
- void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+ void begin_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
ERR_FAIL_COND(!threads); //never initialized
+ ERR_FAIL_COND(current_work != nullptr);
index.store(0);
@@ -90,16 +92,37 @@ public:
w->index = &index;
w->max_elements = p_elements;
+ current_work = w;
+
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].work = w;
threads[i].start.post();
}
+ }
+
+ bool is_working() const {
+ return current_work != nullptr;
+ }
+
+ uint32_t get_work_index() const {
+ return index;
+ }
+
+ void end_work() {
+ ERR_FAIL_COND(current_work == nullptr);
for (uint32_t i = 0; i < thread_count; i++) {
threads[i].completed.wait();
threads[i].work = nullptr;
}
- memdelete(w);
+ memdelete(current_work);
+ current_work = nullptr;
+ }
+
+ template <class C, class M, class U>
+ void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+ begin_work(p_elements, p_instance, p_method, p_userdata);
+ end_work();
}
void init(int p_thread_count = -1);
diff --git a/core/ustring.cpp b/core/ustring.cpp
index e382ef3746..27dab8db6e 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -4732,6 +4732,69 @@ String String::unquote() const {
return substr(1, length() - 2);
}
+Vector<uint8_t> String::to_ascii_buffer() const {
+ const String *s = this;
+ if (s->empty()) {
+ return Vector<uint8_t>();
+ }
+ CharString charstr = s->ascii();
+
+ Vector<uint8_t> retval;
+ size_t len = charstr.length();
+ retval.resize(len);
+ uint8_t *w = retval.ptrw();
+ copymem(w, charstr.ptr(), len);
+
+ return retval;
+}
+
+Vector<uint8_t> String::to_utf8_buffer() const {
+ const String *s = this;
+ if (s->empty()) {
+ return Vector<uint8_t>();
+ }
+ CharString charstr = s->utf8();
+
+ Vector<uint8_t> retval;
+ size_t len = charstr.length();
+ retval.resize(len);
+ uint8_t *w = retval.ptrw();
+ copymem(w, charstr.ptr(), len);
+
+ return retval;
+}
+
+Vector<uint8_t> String::to_utf16_buffer() const {
+ const String *s = this;
+ if (s->empty()) {
+ return Vector<uint8_t>();
+ }
+ Char16String charstr = s->utf16();
+
+ Vector<uint8_t> retval;
+ size_t len = charstr.length() * 2;
+ retval.resize(len);
+ uint8_t *w = retval.ptrw();
+ copymem(w, (const void *)charstr.ptr(), len);
+
+ return retval;
+}
+
+Vector<uint8_t> String::to_utf32_buffer() const {
+ const String *s = this;
+ if (s->empty()) {
+ return Vector<uint8_t>();
+ }
+
+ Vector<uint8_t> retval;
+ size_t len = s->length() * 4;
+ retval.resize(len);
+ uint8_t *w = retval.ptrw();
+ copymem(w, (const void *)s->ptr(), len);
+
+ return retval;
+}
+
#ifdef TOOLS_ENABLED
String TTR(const String &p_text, const String &p_context) {
if (TranslationServer::get_singleton()) {
diff --git a/core/ustring.h b/core/ustring.h
index 1f8a5d7e7d..bf9c06b9ca 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -440,6 +440,11 @@ public:
return *this;
}
+ Vector<uint8_t> to_ascii_buffer() const;
+ Vector<uint8_t> to_utf8_buffer() const;
+ Vector<uint8_t> to_utf16_buffer() const;
+ Vector<uint8_t> to_utf32_buffer() const;
+
String(const char *p_str);
String(const wchar_t *p_str);
String(const char32_t *p_str);
diff --git a/core/variant.h b/core/variant.h
index 112003a7ae..1f3ee8ec74 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -414,6 +414,34 @@ public:
static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst);
static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst);
+ class InternalMethod {
+ public:
+ enum Flags {
+ FLAG_IS_CONST = 1,
+ FLAG_RETURNS_VARIANT = 2,
+ FLAG_NO_PTRCALL = 4,
+ FLAG_VARARGS = 8
+ };
+
+ virtual int get_argument_count() const = 0;
+ virtual Type get_argument_type(int p_arg) const = 0;
+ virtual Type get_return_type() const = 0;
+ virtual uint32_t get_flags() const = 0;
+
+#ifdef DEBUG_ENABLED
+ virtual String get_argument_name(int p_arg) const = 0;
+#endif
+ virtual Vector<Variant> get_default_arguments() const = 0;
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) = 0;
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) = 0;
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) = 0;
+#endif
+ virtual ~InternalMethod() {}
+ };
+
+ static InternalMethod *get_internal_method(Type p_type, const StringName &p_method_name);
+
void call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, Callable::CallError &r_error);
Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant());
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 5fd970c8e1..06d4cf63b8 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -35,1057 +35,766 @@
#include "core/crypto/crypto_core.h"
#include "core/debugger/engine_debugger.h"
#include "core/io/compression.h"
+#include "core/oa_hash_map.h"
#include "core/object.h"
#include "core/os/os.h"
+_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) {
+}
+
+_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) {
+ arr.push_back(p_str);
+}
+
+template <class... P>
+_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) {
+ arr.push_back(p_str);
+ sarray_add_str(arr, p_args...);
+}
+
+template <class... P>
+_FORCE_INLINE_ Vector<String> sarray(P... p_args) {
+ Vector<String> arr;
+ sarray_add_str(arr, p_args...);
+ return arr;
+}
+
typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
struct _VariantCall {
- static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem));
- }
-
- struct FuncData {
- int arg_count;
- Vector<Variant> default_args;
- Vector<Variant::Type> arg_types;
- Vector<StringName> arg_names;
- Variant::Type return_type;
+ template <class T, class... P>
+ class InternalMethod : public Variant::InternalMethod {
+ public:
+ void (T::*method)(P...);
+ Vector<Variant> default_values;
+#ifdef DEBUG_ENABLED
+ Vector<String> argument_names;
+#endif
- bool _const;
- bool returns;
+ virtual int get_argument_count() const {
+ return sizeof...(P);
+ }
+ virtual Variant::Type get_argument_type(int p_arg) const {
+ return call_get_argument_type<P...>(p_arg);
+ }
+#ifdef DEBUG_ENABLED
+ virtual String get_argument_name(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String());
+ return argument_names[p_arg];
+ }
+#endif
+ virtual Vector<Variant> get_default_arguments() const {
+ return default_values;
+ }
- VariantFunc func;
+ virtual Variant::Type get_return_type() const {
+ return Variant::NIL;
+ }
+ virtual uint32_t get_flags() const {
+ return 0;
+ }
- _FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) {
- if (arg_count == 0) {
- return true;
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ const Variant **args = p_args;
+#ifdef DEBUG_ENABLED
+ if ((size_t)p_argcount > sizeof...(P)) {
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+ return;
}
+#endif
+ if ((size_t)p_argcount < sizeof...(P)) {
+ size_t missing = sizeof...(P) - (size_t)p_argcount;
+ if (missing <= (size_t)default_values.size()) {
+ args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *));
+ // GCC fails to see that `sizeof...(P)` cannot be 0 here given the previous
+ // conditions, so it raises a warning on the potential use of `i < 0` as the
+ // execution condition.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
+ for (size_t i = 0; i < sizeof...(P); i++) {
+ if (i < (size_t)p_argcount) {
+ args[i] = p_args[i];
+ } else {
+ args[i] = &default_values[i - p_argcount + (default_values.size() - missing)];
+ }
+ }
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+#ifdef DEBUG_ENABLED
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+#endif
+ return;
+ }
+ }
+ call_with_variant_args_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
+ }
- const Variant::Type *tptr = &arg_types[0];
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args(base, method, p_args);
+ }
- for (int i = 0; i < arg_count; i++) {
- if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) {
- continue; // all good
- }
- if (!Variant::can_convert(p_args[i]->type, tptr[i])) {
- r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument = i;
- r_error.expected = tptr[i];
- return false;
- }
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) {
+ call_with_ptr_args<T, P...>(reinterpret_cast<T *>(p_base), method, p_args);
+ }
+#endif
+ InternalMethod(void (T::*p_method)(P...), const Vector<Variant> &p_default_args
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_arg_names
+#endif
+ ) {
+ method = p_method;
+ default_values = p_default_args;
+#ifdef DEBUG_ENABLED
+ argument_names = p_arg_names;
+#endif
+ }
+ };
+
+ template <class T, class R, class... P>
+ class InternalMethodR : public Variant::InternalMethod {
+ public:
+ R(T::*method)
+ (P...);
+ Vector<Variant> default_values;
+#ifdef DEBUG_ENABLED
+ Vector<String> argument_names;
+#endif
+
+ virtual int get_argument_count() const {
+ return sizeof...(P);
+ }
+ virtual Variant::Type get_argument_type(int p_arg) const {
+ return call_get_argument_type<P...>(p_arg);
+ return Variant::NIL;
+ }
+#ifdef DEBUG_ENABLED
+ virtual String get_argument_name(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String());
+ return argument_names[p_arg];
+ }
+#endif
+ virtual Vector<Variant> get_default_arguments() const {
+ return default_values;
+ }
+
+ virtual Variant::Type get_return_type() const {
+#ifdef DEBUG_METHODS_ENABLED
+ return GetTypeInfo<R>::VARIANT_TYPE;
+#else
+ return Variant::NIL;
+#endif
+ }
+ virtual uint32_t get_flags() const {
+ uint32_t f = 0;
+ if (get_return_type() == Variant::NIL) {
+ f |= FLAG_RETURNS_VARIANT;
}
- return true;
+ return f;
}
- _FORCE_INLINE_ void call(Variant &r_ret, Variant &p_self, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ const Variant **args = p_args;
#ifdef DEBUG_ENABLED
- if (p_argcount > arg_count) {
+ if ((size_t)p_argcount > sizeof...(P)) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument = arg_count;
+ r_error.argument = sizeof...(P);
return;
- } else
+ }
+#endif
+ if ((size_t)p_argcount < sizeof...(P)) {
+ size_t missing = sizeof...(P) - (size_t)p_argcount;
+ if (missing <= (size_t)default_values.size()) {
+ args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *));
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
- if (p_argcount < arg_count) {
- int def_argcount = default_args.size();
+ for (size_t i = 0; i < sizeof...(P); i++) {
+ if (i < (size_t)p_argcount) {
+ args[i] = p_args[i];
+ } else {
+ args[i] = &default_values[i - p_argcount + (default_values.size() - missing)];
+ }
+ }
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
#ifdef DEBUG_ENABLED
- if (p_argcount < (arg_count - def_argcount)) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument = arg_count - def_argcount;
+ r_error.argument = sizeof...(P);
+#endif
return;
}
+ }
+ call_with_variant_args_ret_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
+ }
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_ret(base, method, p_args, r_ret);
+ }
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) {
+ call_with_ptr_args_ret<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
+ }
#endif
- ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX);
- const Variant *newargs[VARIANT_ARG_MAX];
- for (int i = 0; i < p_argcount; i++) {
- newargs[i] = p_args[i];
- }
- // fill in any remaining parameters with defaults
- int first_default_arg = arg_count - def_argcount;
- for (int i = p_argcount; i < arg_count; i++) {
- newargs[i] = &default_args[i - first_default_arg];
- }
+ InternalMethodR(R (T::*p_method)(P...), const Vector<Variant> &p_default_args
#ifdef DEBUG_ENABLED
- if (!verify_arguments(newargs, r_error)) {
- return;
- }
+ ,
+ const Vector<String> &p_arg_names
#endif
- func(r_ret, p_self, newargs);
- } else {
+ ) {
+ method = p_method;
+ default_values = p_default_args;
#ifdef DEBUG_ENABLED
- if (!verify_arguments(p_args, r_error)) {
- return;
- }
+ argument_names = p_arg_names;
#endif
- func(r_ret, p_self, p_args);
- }
}
};
- struct TypeFunc {
- Map<StringName, FuncData> functions;
- };
-
- static TypeFunc *type_funcs;
+ template <class T, class R, class... P>
+ class InternalMethodRC : public Variant::InternalMethod {
+ public:
+ R(T::*method)
+ (P...) const;
+ Vector<Variant> default_values;
+#ifdef DEBUG_ENABLED
+ Vector<String> argument_names;
+#endif
- struct Arg {
- StringName name;
- Variant::Type type;
- Arg() { type = Variant::NIL; }
- Arg(Variant::Type p_type, const StringName &p_name) :
- name(p_name),
- type(p_type) {
+ virtual int get_argument_count() const {
+ return sizeof...(P);
+ }
+ virtual Variant::Type get_argument_type(int p_arg) const {
+ return call_get_argument_type<P...>(p_arg);
+ }
+#ifdef DEBUG_ENABLED
+ virtual String get_argument_name(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String());
+ return argument_names[p_arg];
+ }
+#endif
+ virtual Vector<Variant> get_default_arguments() const {
+ return default_values;
}
- };
- //void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
+ virtual Variant::Type get_return_type() const {
+#ifdef DEBUG_METHODS_ENABLED
+ return GetTypeInfo<R>::VARIANT_TYPE;
+#else
+ return Variant::NIL;
+#endif
+ }
+ virtual uint32_t get_flags() const {
+ uint32_t f = FLAG_IS_CONST;
+ if (get_return_type() == Variant::NIL) {
+ f |= FLAG_RETURNS_VARIANT;
+ }
+ return f;
+ }
- static void make_func_return_variant(Variant::Type p_type, const StringName &p_name) {
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ const Variant **args = p_args;
#ifdef DEBUG_ENABLED
- type_funcs[p_type].functions[p_name].returns = true;
+ if ((size_t)p_argcount > sizeof...(P)) {
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+ return;
+ }
#endif
- }
+ if ((size_t)p_argcount < sizeof...(P)) {
+ size_t missing = sizeof...(P) - (size_t)p_argcount;
+ if (missing <= (size_t)default_values.size()) {
+ args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *));
+ // GCC fails to see that `sizeof...(P)` cannot be 0 here given the previous
+ // conditions, so it raises a warning on the potential use of `i < 0` as the
+ // execution condition.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
+ for (size_t i = 0; i < sizeof...(P); i++) {
+ if (i < (size_t)p_argcount) {
+ args[i] = p_args[i];
+ } else {
+ args[i] = &default_values[i - p_argcount + (default_values.size() - missing)];
+ }
+ }
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+#ifdef DEBUG_ENABLED
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+#endif
+ return;
+ }
+ }
+ call_with_variant_args_retc_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
+ }
- static void addfunc(bool p_const, Variant::Type p_type, Variant::Type p_return, bool p_has_return, const StringName &p_name, VariantFunc p_func, const Vector<Variant> &p_defaultarg, const Arg &p_argtype1 = Arg(), const Arg &p_argtype2 = Arg(), const Arg &p_argtype3 = Arg(), const Arg &p_argtype4 = Arg(), const Arg &p_argtype5 = Arg()) {
- FuncData funcdata;
- funcdata.func = p_func;
- funcdata.default_args = p_defaultarg;
- funcdata._const = p_const;
- funcdata.returns = p_has_return;
- funcdata.return_type = p_return;
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_retc(base, method, p_args, r_ret);
+ }
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) {
+ call_with_ptr_args_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
+ }
+#endif
+ InternalMethodRC(R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_arg_names
+#endif
+ ) {
+ method = p_method;
+ default_values = p_default_args;
+#ifdef DEBUG_ENABLED
+ argument_names = p_arg_names;
+#endif
+ }
+ };
- if (p_argtype1.name) {
- funcdata.arg_types.push_back(p_argtype1.type);
+ template <class T, class R, class... P>
+ class InternalMethodRS : public Variant::InternalMethod {
+ public:
+ R(*method)
+ (T *, P...);
+ Vector<Variant> default_values;
#ifdef DEBUG_ENABLED
- funcdata.arg_names.push_back(p_argtype1.name);
+ Vector<String> argument_names;
#endif
- } else {
- goto end;
+ virtual int get_argument_count() const {
+ return sizeof...(P);
+ }
+ virtual Variant::Type get_argument_type(int p_arg) const {
+ return call_get_argument_type<P...>(p_arg);
}
-
- if (p_argtype2.name) {
- funcdata.arg_types.push_back(p_argtype2.type);
#ifdef DEBUG_ENABLED
- funcdata.arg_names.push_back(p_argtype2.name);
+ virtual String get_argument_name(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String());
+ return argument_names[p_arg];
+ }
#endif
+ virtual Vector<Variant> get_default_arguments() const {
+ return default_values;
+ }
- } else {
- goto end;
+ virtual Variant::Type get_return_type() const {
+#ifdef DEBUG_METHODS_ENABLED
+ return GetTypeInfo<R>::VARIANT_TYPE;
+#else
+ return Variant::NIL;
+#endif
+ }
+ virtual uint32_t get_flags() const {
+ uint32_t f = 0;
+ if (get_return_type() == Variant::NIL) {
+ f |= FLAG_RETURNS_VARIANT;
+ }
+ return f;
}
- if (p_argtype3.name) {
- funcdata.arg_types.push_back(p_argtype3.type);
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ const Variant **args = p_args;
#ifdef DEBUG_ENABLED
- funcdata.arg_names.push_back(p_argtype3.name);
+ if ((size_t)p_argcount > sizeof...(P)) {
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+ return;
+ }
#endif
-
- } else {
- goto end;
+ if ((size_t)p_argcount < sizeof...(P)) {
+ size_t missing = sizeof...(P) - (size_t)p_argcount;
+ if (missing <= (size_t)default_values.size()) {
+ args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *));
+ // GCC fails to see that `sizeof...(P)` cannot be 0 here given the previous
+ // conditions, so it raises a warning on the potential use of `i < 0` as the
+ // execution condition.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
+ for (size_t i = 0; i < sizeof...(P); i++) {
+ if (i < (size_t)p_argcount) {
+ args[i] = p_args[i];
+ } else {
+ args[i] = &default_values[i - p_argcount + (default_values.size() - missing)];
+ }
+ }
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+#ifdef DEBUG_ENABLED
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = sizeof...(P);
+#endif
+ return;
+ }
+ }
+ call_with_variant_args_retc_static_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
}
- if (p_argtype4.name) {
- funcdata.arg_types.push_back(p_argtype4.type);
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) {
+ call_with_validated_variant_args_static_retc(base, method, p_args, r_ret);
+ }
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) {
+ call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
+ }
+#endif
+ InternalMethodRS(R (*p_method)(T *, P...), const Vector<Variant> &p_default_args
#ifdef DEBUG_ENABLED
- funcdata.arg_names.push_back(p_argtype4.name);
+ ,
+ const Vector<String> &p_arg_names
+#endif
+ ) {
+ method = p_method;
+ default_values = p_default_args;
+#ifdef DEBUG_ENABLED
+ argument_names = p_arg_names;
#endif
- } else {
- goto end;
}
+ };
- if (p_argtype5.name) {
- funcdata.arg_types.push_back(p_argtype5.type);
+ class InternalMethodVC : public Variant::InternalMethod {
+ public:
+ typedef void (*MethodVC)(Variant *, const Variant **, int, Variant &r_ret, Callable::CallError &);
+ MethodVC methodvc = nullptr;
+ uint32_t base_flags = 0;
+ Vector<String> argument_names;
+ Vector<Variant::Type> argument_types;
+ Variant::Type return_type = Variant::NIL;
+
+ virtual int get_argument_count() const {
+ return argument_names.size();
+ }
+ virtual Variant::Type get_argument_type(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_types.size(), Variant::NIL);
+ return argument_types[p_arg];
+ }
#ifdef DEBUG_ENABLED
- funcdata.arg_names.push_back(p_argtype5.name);
+ virtual String get_argument_name(int p_arg) const {
+ ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String());
+ return argument_names[p_arg];
+ }
#endif
- } else {
- goto end;
+ virtual Vector<Variant> get_default_arguments() const {
+ return Vector<Variant>();
}
- end:
+ virtual Variant::Type get_return_type() const {
+ return return_type;
+ }
+ virtual uint32_t get_flags() const {
+ return base_flags | FLAG_NO_PTRCALL;
+ }
- funcdata.arg_count = funcdata.arg_types.size();
- type_funcs[p_type].functions[p_name] = funcdata;
- }
-
-#define VCALL_LOCALMEM0(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); }
-#define VCALL_LOCALMEM0R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); }
-#define VCALL_LOCALMEM1(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); }
-#define VCALL_LOCALMEM1R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); }
-#define VCALL_LOCALMEM2(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_LOCALMEM2R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_LOCALMEM3(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_LOCALMEM3R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_LOCALMEM4(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_LOCALMEM4R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_LOCALMEM5(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-#define VCALL_LOCALMEM5R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-
- // built-in functions of localmem based types
-
- VCALL_LOCALMEM1R(String, casecmp_to);
- VCALL_LOCALMEM1R(String, nocasecmp_to);
- VCALL_LOCALMEM1R(String, naturalnocasecmp_to);
- VCALL_LOCALMEM0R(String, length);
- VCALL_LOCALMEM3R(String, count);
- VCALL_LOCALMEM3R(String, countn);
- VCALL_LOCALMEM2R(String, substr);
- VCALL_LOCALMEM2R(String, find);
- VCALL_LOCALMEM2R(String, findn);
- VCALL_LOCALMEM2R(String, rfind);
- VCALL_LOCALMEM2R(String, rfindn);
- VCALL_LOCALMEM1R(String, match);
- VCALL_LOCALMEM1R(String, matchn);
- VCALL_LOCALMEM1R(String, begins_with);
- VCALL_LOCALMEM1R(String, ends_with);
- VCALL_LOCALMEM1R(String, is_subsequence_of);
- VCALL_LOCALMEM1R(String, is_subsequence_ofi);
- VCALL_LOCALMEM0R(String, bigrams);
- VCALL_LOCALMEM1R(String, similarity);
- VCALL_LOCALMEM2R(String, format);
- VCALL_LOCALMEM2R(String, replace);
- VCALL_LOCALMEM2R(String, replacen);
- VCALL_LOCALMEM1R(String, repeat);
- VCALL_LOCALMEM2R(String, insert);
- VCALL_LOCALMEM0R(String, capitalize);
- VCALL_LOCALMEM3R(String, split);
- VCALL_LOCALMEM3R(String, rsplit);
- VCALL_LOCALMEM2R(String, split_floats);
- VCALL_LOCALMEM1R(String, join);
- VCALL_LOCALMEM0R(String, to_upper);
- VCALL_LOCALMEM0R(String, to_lower);
- VCALL_LOCALMEM1R(String, left);
- VCALL_LOCALMEM1R(String, right);
- VCALL_LOCALMEM0R(String, dedent);
- VCALL_LOCALMEM2R(String, strip_edges);
- VCALL_LOCALMEM0R(String, strip_escapes);
- VCALL_LOCALMEM1R(String, lstrip);
- VCALL_LOCALMEM1R(String, rstrip);
- VCALL_LOCALMEM0R(String, get_extension);
- VCALL_LOCALMEM0R(String, get_basename);
- VCALL_LOCALMEM1R(String, plus_file);
- VCALL_LOCALMEM1R(String, ord_at);
- VCALL_LOCALMEM2(String, erase);
- VCALL_LOCALMEM0R(String, hash);
- VCALL_LOCALMEM0R(String, md5_text);
- VCALL_LOCALMEM0R(String, sha1_text);
- VCALL_LOCALMEM0R(String, sha256_text);
- VCALL_LOCALMEM0R(String, md5_buffer);
- VCALL_LOCALMEM0R(String, sha1_buffer);
- VCALL_LOCALMEM0R(String, sha256_buffer);
- VCALL_LOCALMEM0R(String, empty);
- VCALL_LOCALMEM1R(String, humanize_size);
- VCALL_LOCALMEM0R(String, is_abs_path);
- VCALL_LOCALMEM0R(String, is_rel_path);
- VCALL_LOCALMEM0R(String, get_base_dir);
- VCALL_LOCALMEM0R(String, get_file);
- VCALL_LOCALMEM0R(String, xml_escape);
- VCALL_LOCALMEM0R(String, xml_unescape);
- VCALL_LOCALMEM0R(String, http_escape);
- VCALL_LOCALMEM0R(String, http_unescape);
- VCALL_LOCALMEM0R(String, c_escape);
- VCALL_LOCALMEM0R(String, c_unescape);
- VCALL_LOCALMEM0R(String, json_escape);
- VCALL_LOCALMEM0R(String, percent_encode);
- VCALL_LOCALMEM0R(String, percent_decode);
- VCALL_LOCALMEM0R(String, is_valid_identifier);
- VCALL_LOCALMEM0R(String, is_valid_integer);
- VCALL_LOCALMEM0R(String, is_valid_float);
- VCALL_LOCALMEM1R(String, is_valid_hex_number);
- VCALL_LOCALMEM0R(String, is_valid_html_color);
- VCALL_LOCALMEM0R(String, is_valid_ip_address);
- VCALL_LOCALMEM0R(String, is_valid_filename);
- VCALL_LOCALMEM0R(String, to_int);
- VCALL_LOCALMEM0R(String, to_float);
- VCALL_LOCALMEM0R(String, hex_to_int);
- VCALL_LOCALMEM2R(String, lpad);
- VCALL_LOCALMEM2R(String, rpad);
- VCALL_LOCALMEM1R(String, pad_decimals);
- VCALL_LOCALMEM1R(String, pad_zeros);
- VCALL_LOCALMEM1R(String, trim_prefix);
- VCALL_LOCALMEM1R(String, trim_suffix);
-
- static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- String *s = reinterpret_cast<String *>(p_self._data._mem);
- if (s->empty()) {
- r_ret = PackedByteArray();
- return;
+ virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ methodvc(base, p_args, p_argcount, r_ret, r_error);
}
- CharString charstr = s->ascii();
- PackedByteArray retval;
- size_t len = charstr.length();
- retval.resize(len);
- uint8_t *w = retval.ptrw();
- copymem(w, charstr.ptr(), len);
+ virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) {
+ ERR_FAIL_MSG("No support for validated call");
+ }
+#ifdef PTRCALL_ENABLED
+ virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) {
+ ERR_FAIL_MSG("No support for ptrcall call");
+ }
+#endif
+ InternalMethodVC(MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_arg_names
+#endif
+ ) {
+ methodvc = p_method;
+ argument_types = p_argument_types;
+ return_type = p_return_type;
+ base_flags = p_flags;
+#ifdef DEBUG_ENABLED
+ argument_names = p_arg_names;
+#endif
+ }
+ };
- r_ret = retval;
- }
+ typedef OAHashMap<StringName, Variant::InternalMethod *> MethodMap;
+ static MethodMap *type_internal_methods;
+ static List<StringName> *type_internal_method_names;
- static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- String *s = reinterpret_cast<String *>(p_self._data._mem);
- if (s->empty()) {
- r_ret = PackedByteArray();
- return;
- }
- CharString charstr = s->utf8();
+ template <class T, class... P>
+ static void _bind_method(const StringName &p_name, void (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>()
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_argument_names = Vector<String>()
+#endif
+ ) {
- PackedByteArray retval;
- size_t len = charstr.length();
- retval.resize(len);
- uint8_t *w = retval.ptrw();
- copymem(w, charstr.ptr(), len);
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+ ERR_FAIL_COND(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name));
+#endif
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args, p_argument_names));
+#else
+ Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args));
+#endif
- r_ret = retval;
+#ifdef DEBUG_METHODS_ENABLED
+ type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m);
+ type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name);
+#else
+ (void)m;
+#endif
}
- static void _call_String_to_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- String *s = reinterpret_cast<String *>(p_self._data._mem);
- if (s->empty()) {
- r_ret = PackedByteArray();
- return;
- }
- Char16String charstr = s->utf16();
+ template <class T, class R, class... P>
+ static void _bind_method(const StringName &p_name, R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args = Vector<Variant>()
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_argument_names = Vector<String>()
+#endif
+ ) {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+ ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
- PackedByteArray retval;
- size_t len = charstr.length() * 2;
- retval.resize(len);
- uint8_t *w = retval.ptrw();
- copymem(w, (const void *)charstr.ptr(), len);
+#endif
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args, p_argument_names));
+#else
+ Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args));
+#endif
- r_ret = retval;
+#ifdef DEBUG_METHODS_ENABLED
+ type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m);
+ type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name);
+#else
+ (void)m;
+#endif
}
- static void _call_String_to_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- String *s = reinterpret_cast<String *>(p_self._data._mem);
- if (s->empty()) {
- r_ret = PackedByteArray();
- return;
- }
+ template <class T, class R, class... P>
+ static void _bind_method(const StringName &p_name, R (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>()
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_argument_names = Vector<String>()
+#endif
+ ) {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+ ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+#endif
- PackedByteArray retval;
- size_t len = s->length() * 4;
- retval.resize(len);
- uint8_t *w = retval.ptrw();
- copymem(w, (const void *)s->ptr(), len);
-
- r_ret = retval;
- }
-
- VCALL_LOCALMEM1R(Vector2, distance_to);
- VCALL_LOCALMEM1R(Vector2, distance_squared_to);
- VCALL_LOCALMEM0R(Vector2, length);
- VCALL_LOCALMEM0R(Vector2, length_squared);
- VCALL_LOCALMEM0R(Vector2, normalized);
- VCALL_LOCALMEM0R(Vector2, is_normalized);
- VCALL_LOCALMEM1R(Vector2, is_equal_approx);
- VCALL_LOCALMEM1R(Vector2, posmod);
- VCALL_LOCALMEM1R(Vector2, posmodv);
- VCALL_LOCALMEM1R(Vector2, project);
- VCALL_LOCALMEM1R(Vector2, angle_to);
- VCALL_LOCALMEM1R(Vector2, angle_to_point);
- VCALL_LOCALMEM1R(Vector2, direction_to);
- VCALL_LOCALMEM2R(Vector2, lerp);
- VCALL_LOCALMEM2R(Vector2, slerp);
- VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
- VCALL_LOCALMEM2R(Vector2, move_toward);
- VCALL_LOCALMEM1R(Vector2, rotated);
- VCALL_LOCALMEM0R(Vector2, tangent);
- VCALL_LOCALMEM0R(Vector2, floor);
- VCALL_LOCALMEM0R(Vector2, ceil);
- VCALL_LOCALMEM0R(Vector2, round);
- VCALL_LOCALMEM1R(Vector2, snapped);
- VCALL_LOCALMEM0R(Vector2, aspect);
- VCALL_LOCALMEM1R(Vector2, dot);
- VCALL_LOCALMEM1R(Vector2, slide);
- VCALL_LOCALMEM1R(Vector2, bounce);
- VCALL_LOCALMEM1R(Vector2, reflect);
- VCALL_LOCALMEM0R(Vector2, angle);
- VCALL_LOCALMEM1R(Vector2, cross);
- VCALL_LOCALMEM0R(Vector2, abs);
- VCALL_LOCALMEM1R(Vector2, clamped);
- VCALL_LOCALMEM0R(Vector2, sign);
-
- VCALL_LOCALMEM0R(Vector2i, aspect);
- VCALL_LOCALMEM0R(Vector2i, sign);
- VCALL_LOCALMEM0R(Vector2i, abs);
-
- VCALL_LOCALMEM0R(Rect2, get_area);
- VCALL_LOCALMEM0R(Rect2, has_no_area);
- VCALL_LOCALMEM1R(Rect2, has_point);
- VCALL_LOCALMEM1R(Rect2, is_equal_approx);
- VCALL_LOCALMEM2R(Rect2, intersects);
- VCALL_LOCALMEM1R(Rect2, encloses);
- VCALL_LOCALMEM1R(Rect2, clip);
- VCALL_LOCALMEM1R(Rect2, merge);
- VCALL_LOCALMEM1R(Rect2, expand);
- VCALL_LOCALMEM1R(Rect2, grow);
- VCALL_LOCALMEM2R(Rect2, grow_margin);
- VCALL_LOCALMEM4R(Rect2, grow_individual);
- VCALL_LOCALMEM0R(Rect2, abs);
-
- VCALL_LOCALMEM0R(Rect2i, get_area);
- VCALL_LOCALMEM0R(Rect2i, has_no_area);
- VCALL_LOCALMEM1R(Rect2i, has_point);
- VCALL_LOCALMEM1R(Rect2i, intersects);
- VCALL_LOCALMEM1R(Rect2i, encloses);
- VCALL_LOCALMEM1R(Rect2i, clip);
- VCALL_LOCALMEM1R(Rect2i, merge);
- VCALL_LOCALMEM1R(Rect2i, expand);
- VCALL_LOCALMEM1R(Rect2i, grow);
- VCALL_LOCALMEM2R(Rect2i, grow_margin);
- VCALL_LOCALMEM4R(Rect2i, grow_individual);
- VCALL_LOCALMEM0R(Rect2i, abs);
-
- VCALL_LOCALMEM0R(Vector3, min_axis);
- VCALL_LOCALMEM0R(Vector3, max_axis);
- VCALL_LOCALMEM1R(Vector3, distance_to);
- VCALL_LOCALMEM1R(Vector3, distance_squared_to);
- VCALL_LOCALMEM0R(Vector3, length);
- VCALL_LOCALMEM0R(Vector3, length_squared);
- VCALL_LOCALMEM0R(Vector3, normalized);
- VCALL_LOCALMEM0R(Vector3, is_normalized);
- VCALL_LOCALMEM1R(Vector3, is_equal_approx);
- VCALL_LOCALMEM0R(Vector3, inverse);
- VCALL_LOCALMEM1R(Vector3, snapped);
- VCALL_LOCALMEM2R(Vector3, rotated);
- VCALL_LOCALMEM2R(Vector3, lerp);
- VCALL_LOCALMEM2R(Vector3, slerp);
- VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
- VCALL_LOCALMEM2R(Vector3, move_toward);
- VCALL_LOCALMEM1R(Vector3, dot);
- VCALL_LOCALMEM1R(Vector3, cross);
- VCALL_LOCALMEM1R(Vector3, outer);
- VCALL_LOCALMEM0R(Vector3, to_diagonal_matrix);
- VCALL_LOCALMEM0R(Vector3, abs);
- VCALL_LOCALMEM0R(Vector3, floor);
- VCALL_LOCALMEM0R(Vector3, ceil);
- VCALL_LOCALMEM0R(Vector3, round);
- VCALL_LOCALMEM1R(Vector3, posmod);
- VCALL_LOCALMEM1R(Vector3, posmodv);
- VCALL_LOCALMEM1R(Vector3, project);
- VCALL_LOCALMEM1R(Vector3, angle_to);
- VCALL_LOCALMEM1R(Vector3, direction_to);
- VCALL_LOCALMEM1R(Vector3, slide);
- VCALL_LOCALMEM1R(Vector3, bounce);
- VCALL_LOCALMEM1R(Vector3, reflect);
- VCALL_LOCALMEM0R(Vector3, sign);
-
- VCALL_LOCALMEM0R(Vector3i, min_axis);
- VCALL_LOCALMEM0R(Vector3i, max_axis);
- VCALL_LOCALMEM0R(Vector3i, sign);
-
- VCALL_LOCALMEM0R(Plane, normalized);
- VCALL_LOCALMEM0R(Plane, center);
- VCALL_LOCALMEM1R(Plane, is_equal_approx);
- VCALL_LOCALMEM1R(Plane, is_point_over);
- VCALL_LOCALMEM1R(Plane, distance_to);
- VCALL_LOCALMEM2R(Plane, has_point);
- VCALL_LOCALMEM1R(Plane, project);
-
- //return vector3 if intersected, nil if not
- static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) {
- r_ret = result;
- } else {
- r_ret = Variant();
- }
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args, p_argument_names));
+#else
+ Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args));
+#endif
+#ifdef DEBUG_METHODS_ENABLED
+ type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m);
+ type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name);
+#else
+ (void)m;
+#endif
}
- static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) {
- r_ret = result;
- } else {
- r_ret = Variant();
- }
+#ifdef DEBUG_ENABLED
+#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args, m_arg_names)
+#else
+#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args)
+#endif
+
+#ifdef DEBUG_ENABLED
+#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args, m_arg_names)
+#else
+#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args)
+#endif
+
+ template <class T, class R, class... P>
+ static void _bind_function(const StringName &p_name, R (*p_method)(T *, P...), const Vector<Variant> &p_default_args = Vector<Variant>()
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_argument_names = Vector<String>()
+#endif
+ ) {
+#ifdef DEBUG_ENABLED
+ ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+ ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name));
+#endif
+
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args, p_argument_names));
+#else
+ Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args));
+#endif
+
+#ifdef DEBUG_METHODS_ENABLED
+ type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m);
+ type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name);
+#else
+ (void)m;
+#endif
}
- static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) {
- r_ret = result;
- } else {
- r_ret = Variant();
- }
- }
-
- VCALL_LOCALMEM0R(Quat, length);
- VCALL_LOCALMEM0R(Quat, length_squared);
- VCALL_LOCALMEM0R(Quat, normalized);
- VCALL_LOCALMEM0R(Quat, is_normalized);
- VCALL_LOCALMEM1R(Quat, is_equal_approx);
- VCALL_LOCALMEM0R(Quat, inverse);
- VCALL_LOCALMEM1R(Quat, dot);
- VCALL_LOCALMEM1R(Quat, xform);
- VCALL_LOCALMEM2R(Quat, slerp);
- VCALL_LOCALMEM2R(Quat, slerpni);
- VCALL_LOCALMEM4R(Quat, cubic_slerp);
- VCALL_LOCALMEM0R(Quat, get_euler);
- VCALL_LOCALMEM1(Quat, set_euler);
- VCALL_LOCALMEM2(Quat, set_axis_angle);
-
- VCALL_LOCALMEM0R(Color, to_argb32);
- VCALL_LOCALMEM0R(Color, to_abgr32);
- VCALL_LOCALMEM0R(Color, to_rgba32);
- VCALL_LOCALMEM0R(Color, to_argb64);
- VCALL_LOCALMEM0R(Color, to_abgr64);
- VCALL_LOCALMEM0R(Color, to_rgba64);
- VCALL_LOCALMEM0R(Color, inverted);
- VCALL_LOCALMEM0R(Color, contrasted);
- VCALL_LOCALMEM2R(Color, lerp);
- VCALL_LOCALMEM1R(Color, blend);
- VCALL_LOCALMEM1R(Color, lightened);
- VCALL_LOCALMEM1R(Color, darkened);
- VCALL_LOCALMEM1R(Color, to_html);
- VCALL_LOCALMEM4R(Color, from_hsv);
- VCALL_LOCALMEM1R(Color, is_equal_approx);
-
- VCALL_LOCALMEM0R(RID, get_id);
-
- VCALL_LOCALMEM0R(NodePath, is_absolute);
- VCALL_LOCALMEM0R(NodePath, get_name_count);
- VCALL_LOCALMEM1R(NodePath, get_name);
- VCALL_LOCALMEM0R(NodePath, get_subname_count);
- VCALL_LOCALMEM1R(NodePath, get_subname);
- VCALL_LOCALMEM0R(NodePath, get_concatenated_subnames);
- VCALL_LOCALMEM0R(NodePath, get_as_property_path);
- VCALL_LOCALMEM0R(NodePath, is_empty);
-
- VCALL_LOCALMEM0R(Dictionary, size);
- VCALL_LOCALMEM0R(Dictionary, empty);
- VCALL_LOCALMEM0(Dictionary, clear);
- VCALL_LOCALMEM1R(Dictionary, has);
- VCALL_LOCALMEM1R(Dictionary, has_all);
- VCALL_LOCALMEM1R(Dictionary, erase);
- VCALL_LOCALMEM0R(Dictionary, hash);
- VCALL_LOCALMEM0R(Dictionary, keys);
- VCALL_LOCALMEM0R(Dictionary, values);
- VCALL_LOCALMEM1R(Dictionary, duplicate);
- VCALL_LOCALMEM2R(Dictionary, get);
-
- VCALL_LOCALMEM0R(Callable, is_null);
- VCALL_LOCALMEM0R(Callable, is_custom);
- VCALL_LOCALMEM0(Callable, is_standard);
- VCALL_LOCALMEM0(Callable, get_object);
- VCALL_LOCALMEM0(Callable, get_object_id);
- VCALL_LOCALMEM0(Callable, get_method);
- VCALL_LOCALMEM0(Callable, hash);
-
- VCALL_LOCALMEM0R(Signal, is_null);
- VCALL_LOCALMEM0R(Signal, get_object);
- VCALL_LOCALMEM0R(Signal, get_object_id);
- VCALL_LOCALMEM0R(Signal, get_name);
- VCALL_LOCALMEM3R(Signal, connect);
- VCALL_LOCALMEM1(Signal, disconnect);
- VCALL_LOCALMEM1R(Signal, is_connected);
- VCALL_LOCALMEM0R(Signal, get_connections);
-
- VCALL_LOCALMEM2(Array, set);
- VCALL_LOCALMEM1R(Array, get);
- VCALL_LOCALMEM0R(Array, size);
- VCALL_LOCALMEM0R(Array, empty);
- VCALL_LOCALMEM0(Array, clear);
- VCALL_LOCALMEM0R(Array, hash);
- VCALL_LOCALMEM1(Array, push_back);
- VCALL_LOCALMEM1(Array, push_front);
- VCALL_LOCALMEM0R(Array, pop_back);
- VCALL_LOCALMEM0R(Array, pop_front);
- VCALL_LOCALMEM1(Array, append);
- VCALL_LOCALMEM1(Array, resize);
- VCALL_LOCALMEM2(Array, insert);
- VCALL_LOCALMEM1(Array, remove);
- VCALL_LOCALMEM0R(Array, front);
- VCALL_LOCALMEM0R(Array, back);
- VCALL_LOCALMEM2R(Array, find);
- VCALL_LOCALMEM2R(Array, rfind);
- VCALL_LOCALMEM1R(Array, find_last);
- VCALL_LOCALMEM1R(Array, count);
- VCALL_LOCALMEM1R(Array, has);
- VCALL_LOCALMEM1(Array, erase);
- VCALL_LOCALMEM0(Array, sort);
- VCALL_LOCALMEM2(Array, sort_custom);
- VCALL_LOCALMEM0(Array, shuffle);
- VCALL_LOCALMEM2R(Array, bsearch);
- VCALL_LOCALMEM4R(Array, bsearch_custom);
- VCALL_LOCALMEM1R(Array, duplicate);
- VCALL_LOCALMEM4R(Array, slice);
- VCALL_LOCALMEM0(Array, invert);
- VCALL_LOCALMEM0R(Array, max);
- VCALL_LOCALMEM0R(Array, min);
-
- static void _call_PackedByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
+#ifdef DEBUG_ENABLED
+#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args, m_arg_names)
+#else
+#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args)
+#endif
+
+ static void _bind_custom(Variant::Type p_type, const StringName &p_name, InternalMethodVC::MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type
+#ifdef DEBUG_ENABLED
+ ,
+ const Vector<String> &p_argument_names = Vector<String>()
+#endif
+ ) {
+
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type, p_argument_names));
+#else
+ Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type));
+#endif
+
+ type_internal_methods[p_type].insert(p_name, m);
+ type_internal_method_names[p_type].push_back(p_name);
+ }
+
+#ifdef DEBUG_ENABLED
+#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names)
+#else
+#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type)
+#endif
+
+ static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) {
String s;
- if (ba->array.size() > 0) {
- const uint8_t *r = ba->array.ptr();
+ if (p_instance->size() > 0) {
+ const uint8_t *r = p_instance->ptr();
CharString cs;
- cs.resize(ba->array.size() + 1);
- copymem(cs.ptrw(), r, ba->array.size());
- cs[ba->array.size()] = 0;
+ cs.resize(p_instance->size() + 1);
+ copymem(cs.ptrw(), r, p_instance->size());
+ cs[p_instance->size()] = 0;
s = cs.get_data();
}
- r_ret = s;
+ return s;
}
- static void _call_PackedByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
-
+ static String func_PackedByteArray_get_string_from_utf8(PackedByteArray *p_instance) {
String s;
- if (ba->array.size() > 0) {
- const uint8_t *r = ba->array.ptr();
- s.parse_utf8((const char *)r, ba->array.size());
+ if (p_instance->size() > 0) {
+ const uint8_t *r = p_instance->ptr();
+ s.parse_utf8((const char *)r, p_instance->size());
}
- r_ret = s;
+ return s;
}
- static void _call_PackedByteArray_get_string_from_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
+ static String func_PackedByteArray_get_string_from_utf16(PackedByteArray *p_instance) {
String s;
- if (ba->size() > 0) {
- const uint8_t *r = ba->ptr();
- s.parse_utf16((const char16_t *)r, ba->size() / 2);
+ if (p_instance->size() > 0) {
+ const uint8_t *r = p_instance->ptr();
+ s.parse_utf16((const char16_t *)r, p_instance->size() / 2);
}
- r_ret = s;
+ return s;
}
- static void _call_PackedByteArray_get_string_from_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
+ static String func_PackedByteArray_get_string_from_utf32(PackedByteArray *p_instance) {
String s;
- if (ba->size() > 0) {
- const uint8_t *r = ba->ptr();
- s = String((const char32_t *)r, ba->size() / 4);
+ if (p_instance->size() > 0) {
+ const uint8_t *r = p_instance->ptr();
+ s = String((const char32_t *)r, p_instance->size() / 4);
}
- r_ret = s;
+ return s;
}
- static void _call_PackedByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
+ static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) {
PackedByteArray compressed;
- if (ba->array.size() > 0) {
- Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]);
- compressed.resize(Compression::get_max_compressed_buffer_size(ba->array.size(), mode));
- int result = Compression::compress(compressed.ptrw(), ba->array.ptr(), ba->array.size(), mode);
+ if (p_instance->size() > 0) {
+ Compression::Mode mode = (Compression::Mode)(p_mode);
+ compressed.resize(Compression::get_max_compressed_buffer_size(p_instance->size(), mode));
+ int result = Compression::compress(compressed.ptrw(), p_instance->ptr(), p_instance->size(), mode);
result = result >= 0 ? result : 0;
compressed.resize(result);
}
- r_ret = compressed;
+ return compressed;
}
- static void _call_PackedByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
+ static PackedByteArray func_PackedByteArray_decompress(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
PackedByteArray decompressed;
- Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
+ Compression::Mode mode = (Compression::Mode)(p_mode);
- int buffer_size = (int)(*p_args[0]);
+ int64_t buffer_size = p_buffer_size;
if (buffer_size <= 0) {
- r_ret = decompressed;
- ERR_FAIL_MSG("Decompression buffer size must be greater than zero.");
+ ERR_FAIL_V_MSG(decompressed, "Decompression buffer size must be greater than zero.");
}
decompressed.resize(buffer_size);
- int result = Compression::decompress(decompressed.ptrw(), buffer_size, ba->array.ptr(), ba->array.size(), mode);
+ int result = Compression::decompress(decompressed.ptrw(), buffer_size, p_instance->ptr(), p_instance->size(), mode);
result = result >= 0 ? result : 0;
decompressed.resize(result);
- r_ret = decompressed;
+ return decompressed;
}
- static void _call_PackedByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
+ static PackedByteArray func_PackedByteArray_decompress_dynamic(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
PackedByteArray decompressed;
- int max_output_size = (int)(*p_args[0]);
- Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
+ int64_t max_output_size = p_buffer_size;
+ Compression::Mode mode = (Compression::Mode)(p_mode);
- int result = Compression::decompress_dynamic(&decompressed, max_output_size, ba->array.ptr(), ba->array.size(), mode);
+ int result = Compression::decompress_dynamic(&decompressed, max_output_size, p_instance->ptr(), p_instance->size(), mode);
if (result == OK) {
- r_ret = decompressed;
+ return decompressed;
} else {
decompressed.clear();
- r_ret = decompressed;
- ERR_FAIL_MSG("Decompression failed.");
+ ERR_FAIL_V_MSG(decompressed, "Decompression failed.");
}
}
- static void _call_PackedByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array);
- if (ba->array.size() == 0) {
- r_ret = String();
- return;
- }
- const uint8_t *r = ba->array.ptr();
- String s = String::hex_encode_buffer(&r[0], ba->array.size());
- r_ret = s;
- }
-
-#define VCALL_PARRMEM0(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(); }
-#define VCALL_PARRMEM0R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(); }
-#define VCALL_PARRMEM1(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0]); }
-#define VCALL_PARRMEM1R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0]); }
-#define VCALL_PARRMEM2(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_PARRMEM2R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_PARRMEM3(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_PARRMEM3R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_PARRMEM4(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_PARRMEM4R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_PARRMEM5(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-#define VCALL_PARRMEM5R(m_type, m_elemtype, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-
- VCALL_PARRMEM0R(PackedByteArray, uint8_t, size);
- VCALL_PARRMEM0R(PackedByteArray, uint8_t, empty);
- VCALL_PARRMEM2(PackedByteArray, uint8_t, set);
- VCALL_PARRMEM1R(PackedByteArray, uint8_t, get);
- VCALL_PARRMEM1(PackedByteArray, uint8_t, push_back);
- VCALL_PARRMEM1(PackedByteArray, uint8_t, resize);
- VCALL_PARRMEM2R(PackedByteArray, uint8_t, insert);
- VCALL_PARRMEM1(PackedByteArray, uint8_t, remove);
- VCALL_PARRMEM1(PackedByteArray, uint8_t, append);
- VCALL_PARRMEM1(PackedByteArray, uint8_t, append_array);
- VCALL_PARRMEM1R(PackedByteArray, uint8_t, has);
- VCALL_PARRMEM0(PackedByteArray, uint8_t, sort);
- VCALL_PARRMEM0(PackedByteArray, uint8_t, invert);
- VCALL_PARRMEM2R(PackedByteArray, uint8_t, subarray);
-
- VCALL_PARRMEM0R(PackedInt32Array, int32_t, size);
- VCALL_PARRMEM0R(PackedInt32Array, int32_t, empty);
- VCALL_PARRMEM2(PackedInt32Array, int32_t, set);
- VCALL_PARRMEM1R(PackedInt32Array, int32_t, get);
- VCALL_PARRMEM1(PackedInt32Array, int32_t, push_back);
- VCALL_PARRMEM1(PackedInt32Array, int32_t, resize);
- VCALL_PARRMEM2R(PackedInt32Array, int32_t, insert);
- VCALL_PARRMEM1(PackedInt32Array, int32_t, remove);
- VCALL_PARRMEM1(PackedInt32Array, int32_t, append);
- VCALL_PARRMEM1(PackedInt32Array, int32_t, append_array);
- VCALL_PARRMEM1R(PackedInt32Array, int32_t, has);
- VCALL_PARRMEM0(PackedInt32Array, int32_t, sort);
- VCALL_PARRMEM0(PackedInt32Array, int32_t, invert);
-
- VCALL_PARRMEM0R(PackedInt64Array, int64_t, size);
- VCALL_PARRMEM0R(PackedInt64Array, int64_t, empty);
- VCALL_PARRMEM2(PackedInt64Array, int64_t, set);
- VCALL_PARRMEM1R(PackedInt64Array, int64_t, get);
- VCALL_PARRMEM1(PackedInt64Array, int64_t, push_back);
- VCALL_PARRMEM1(PackedInt64Array, int64_t, resize);
- VCALL_PARRMEM2R(PackedInt64Array, int64_t, insert);
- VCALL_PARRMEM1(PackedInt64Array, int64_t, remove);
- VCALL_PARRMEM1(PackedInt64Array, int64_t, append);
- VCALL_PARRMEM1(PackedInt64Array, int64_t, append_array);
- VCALL_PARRMEM1R(PackedInt64Array, int64_t, has);
- VCALL_PARRMEM0(PackedInt64Array, int64_t, sort);
- VCALL_PARRMEM0(PackedInt64Array, int64_t, invert);
-
- VCALL_PARRMEM0R(PackedFloat32Array, float, size);
- VCALL_PARRMEM0R(PackedFloat32Array, float, empty);
- VCALL_PARRMEM2(PackedFloat32Array, float, set);
- VCALL_PARRMEM1R(PackedFloat32Array, float, get);
- VCALL_PARRMEM1(PackedFloat32Array, float, push_back);
- VCALL_PARRMEM1(PackedFloat32Array, float, resize);
- VCALL_PARRMEM2R(PackedFloat32Array, float, insert);
- VCALL_PARRMEM1(PackedFloat32Array, float, remove);
- VCALL_PARRMEM1(PackedFloat32Array, float, append);
- VCALL_PARRMEM1(PackedFloat32Array, float, append_array);
- VCALL_PARRMEM1R(PackedFloat32Array, float, has);
- VCALL_PARRMEM0(PackedFloat32Array, float, sort);
- VCALL_PARRMEM0(PackedFloat32Array, float, invert);
-
- VCALL_PARRMEM0R(PackedFloat64Array, double, size);
- VCALL_PARRMEM0R(PackedFloat64Array, double, empty);
- VCALL_PARRMEM2(PackedFloat64Array, double, set);
- VCALL_PARRMEM1R(PackedFloat64Array, double, get);
- VCALL_PARRMEM1(PackedFloat64Array, double, push_back);
- VCALL_PARRMEM1(PackedFloat64Array, double, resize);
- VCALL_PARRMEM2R(PackedFloat64Array, double, insert);
- VCALL_PARRMEM1(PackedFloat64Array, double, remove);
- VCALL_PARRMEM1(PackedFloat64Array, double, append);
- VCALL_PARRMEM1(PackedFloat64Array, double, append_array);
- VCALL_PARRMEM1R(PackedFloat64Array, double, has);
- VCALL_PARRMEM0(PackedFloat64Array, double, sort);
- VCALL_PARRMEM0(PackedFloat64Array, double, invert);
-
- VCALL_PARRMEM0R(PackedStringArray, String, size);
- VCALL_PARRMEM0R(PackedStringArray, String, empty);
- VCALL_PARRMEM2(PackedStringArray, String, set);
- VCALL_PARRMEM1R(PackedStringArray, String, get);
- VCALL_PARRMEM1(PackedStringArray, String, push_back);
- VCALL_PARRMEM1(PackedStringArray, String, resize);
- VCALL_PARRMEM2R(PackedStringArray, String, insert);
- VCALL_PARRMEM1(PackedStringArray, String, remove);
- VCALL_PARRMEM1(PackedStringArray, String, append);
- VCALL_PARRMEM1(PackedStringArray, String, append_array);
- VCALL_PARRMEM1R(PackedStringArray, String, has);
- VCALL_PARRMEM0(PackedStringArray, String, sort);
- VCALL_PARRMEM0(PackedStringArray, String, invert);
-
- VCALL_PARRMEM0R(PackedVector2Array, Vector2, size);
- VCALL_PARRMEM0R(PackedVector2Array, Vector2, empty);
- VCALL_PARRMEM2(PackedVector2Array, Vector2, set);
- VCALL_PARRMEM1R(PackedVector2Array, Vector2, get);
- VCALL_PARRMEM1(PackedVector2Array, Vector2, push_back);
- VCALL_PARRMEM1(PackedVector2Array, Vector2, resize);
- VCALL_PARRMEM2R(PackedVector2Array, Vector2, insert);
- VCALL_PARRMEM1(PackedVector2Array, Vector2, remove);
- VCALL_PARRMEM1(PackedVector2Array, Vector2, append);
- VCALL_PARRMEM1(PackedVector2Array, Vector2, append_array);
- VCALL_PARRMEM1R(PackedVector2Array, Vector2, has);
- VCALL_PARRMEM0(PackedVector2Array, Vector2, sort);
- VCALL_PARRMEM0(PackedVector2Array, Vector2, invert);
-
- VCALL_PARRMEM0R(PackedVector3Array, Vector3, size);
- VCALL_PARRMEM0R(PackedVector3Array, Vector3, empty);
- VCALL_PARRMEM2(PackedVector3Array, Vector3, set);
- VCALL_PARRMEM1R(PackedVector3Array, Vector3, get);
- VCALL_PARRMEM1(PackedVector3Array, Vector3, push_back);
- VCALL_PARRMEM1(PackedVector3Array, Vector3, resize);
- VCALL_PARRMEM2R(PackedVector3Array, Vector3, insert);
- VCALL_PARRMEM1(PackedVector3Array, Vector3, remove);
- VCALL_PARRMEM1(PackedVector3Array, Vector3, append);
- VCALL_PARRMEM1(PackedVector3Array, Vector3, append_array);
- VCALL_PARRMEM1R(PackedVector3Array, Vector3, has);
- VCALL_PARRMEM0(PackedVector3Array, Vector3, sort);
- VCALL_PARRMEM0(PackedVector3Array, Vector3, invert);
-
- VCALL_PARRMEM0R(PackedColorArray, Color, size);
- VCALL_PARRMEM0R(PackedColorArray, Color, empty);
- VCALL_PARRMEM2(PackedColorArray, Color, set);
- VCALL_PARRMEM1R(PackedColorArray, Color, get);
- VCALL_PARRMEM1(PackedColorArray, Color, push_back);
- VCALL_PARRMEM1(PackedColorArray, Color, resize);
- VCALL_PARRMEM2R(PackedColorArray, Color, insert);
- VCALL_PARRMEM1(PackedColorArray, Color, remove);
- VCALL_PARRMEM1(PackedColorArray, Color, append);
- VCALL_PARRMEM1(PackedColorArray, Color, append_array);
- VCALL_PARRMEM1R(PackedColorArray, Color, has);
- VCALL_PARRMEM0(PackedColorArray, Color, sort);
- VCALL_PARRMEM0(PackedColorArray, Color, invert);
-
-#define VCALL_PTR0(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); }
-#define VCALL_PTR0R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); }
-#define VCALL_PTR1(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); }
-#define VCALL_PTR1R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); }
-#define VCALL_PTR2(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_PTR2R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); }
-#define VCALL_PTR3(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_PTR3R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
-#define VCALL_PTR4(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_PTR4R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
-#define VCALL_PTR5(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-#define VCALL_PTR5R(m_type, m_method) \
- static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
-
- VCALL_PTR0R(AABB, abs);
- VCALL_PTR0R(AABB, get_area);
- VCALL_PTR0R(AABB, has_no_area);
- VCALL_PTR0R(AABB, has_no_surface);
- VCALL_PTR1R(AABB, has_point);
- VCALL_PTR1R(AABB, is_equal_approx);
- VCALL_PTR1R(AABB, intersects);
- VCALL_PTR1R(AABB, encloses);
- VCALL_PTR1R(AABB, intersects_plane);
- VCALL_PTR2R(AABB, intersects_segment);
- VCALL_PTR1R(AABB, intersection);
- VCALL_PTR1R(AABB, merge);
- VCALL_PTR1R(AABB, expand);
- VCALL_PTR1R(AABB, grow);
- VCALL_PTR1R(AABB, get_support);
- VCALL_PTR0R(AABB, get_longest_axis);
- VCALL_PTR0R(AABB, get_longest_axis_index);
- VCALL_PTR0R(AABB, get_longest_axis_size);
- VCALL_PTR0R(AABB, get_shortest_axis);
- VCALL_PTR0R(AABB, get_shortest_axis_index);
- VCALL_PTR0R(AABB, get_shortest_axis_size);
- VCALL_PTR1R(AABB, get_endpoint);
-
- VCALL_PTR0R(Transform2D, inverse);
- VCALL_PTR0R(Transform2D, affine_inverse);
- VCALL_PTR0R(Transform2D, get_rotation);
- VCALL_PTR0R(Transform2D, get_origin);
- VCALL_PTR0R(Transform2D, get_scale);
- VCALL_PTR0R(Transform2D, orthonormalized);
- VCALL_PTR1R(Transform2D, rotated);
- VCALL_PTR1R(Transform2D, scaled);
- VCALL_PTR1R(Transform2D, translated);
- VCALL_PTR2R(Transform2D, interpolate_with);
- VCALL_PTR1R(Transform2D, is_equal_approx);
-
- static void _call_Transform2D_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2());
- return;
- case Variant::RECT2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2());
- return;
- case Variant::PACKED_VECTOR2_ARRAY:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator PackedVector2Array());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'xform' in base 'Transform2D'. Valid types are Vector2, Rect2, and PackedVector2Array.");
+ static String func_PackedByteArray_hex_encode(PackedByteArray *p_instance) {
+ if (p_instance->size() == 0) {
+ return String();
}
+ const uint8_t *r = p_instance->ptr();
+ String s = String::hex_encode_buffer(&r[0], p_instance->size());
+ return s;
}
- static void _call_Transform2D_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2());
- return;
- case Variant::RECT2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2());
- return;
- case Variant::PACKED_VECTOR2_ARRAY:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator PackedVector2Array());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'xform_inv' in base 'Transform2D'. Valid types are Vector2, Rect2, and PackedVector2Array.");
- }
+ static void func_Callable_call(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
+ callable->call(p_args, p_argcount, r_ret, r_error);
}
- static void _call_Transform2D_basis_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'basis_xform' in base 'Transform2D'. Only Vector2 is valid.");
- }
+ static void func_Callable_call_deferred(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
+ callable->call_deferred(p_args, p_argcount);
}
- static void _call_Transform2D_basis_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR2:
- r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'basis_xform_inv' in base 'Transform2D'. Only Vector2 is valid.");
- }
- }
-
- VCALL_PTR0R(Basis, inverse);
- VCALL_PTR0R(Basis, transposed);
- VCALL_PTR0R(Basis, determinant);
- VCALL_PTR2R(Basis, rotated);
- VCALL_PTR1R(Basis, scaled);
- VCALL_PTR0R(Basis, get_scale);
- VCALL_PTR0R(Basis, get_euler);
- VCALL_PTR0R(Basis, get_euler_xyz);
- VCALL_PTR1(Basis, set_euler_xyz);
- VCALL_PTR0R(Basis, get_euler_xzy);
- VCALL_PTR1(Basis, set_euler_xzy);
- VCALL_PTR0R(Basis, get_euler_yzx);
- VCALL_PTR1(Basis, set_euler_yzx);
- VCALL_PTR0R(Basis, get_euler_yxz);
- VCALL_PTR1(Basis, set_euler_yxz);
- VCALL_PTR0R(Basis, get_euler_zxy);
- VCALL_PTR1(Basis, set_euler_zxy);
- VCALL_PTR0R(Basis, get_euler_zyx);
- VCALL_PTR1(Basis, set_euler_zyx);
- VCALL_PTR1R(Basis, tdotx);
- VCALL_PTR1R(Basis, tdoty);
- VCALL_PTR1R(Basis, tdotz);
- VCALL_PTR1R(Basis, xform);
- VCALL_PTR1R(Basis, xform_inv);
- VCALL_PTR0R(Basis, get_orthogonal_index);
- VCALL_PTR0R(Basis, orthonormalized);
- VCALL_PTR2R(Basis, slerp);
- VCALL_PTR1R(Basis, is_equal_approx);
- VCALL_PTR0R(Basis, get_rotation_quat);
-
- VCALL_PTR0R(Transform, inverse);
- VCALL_PTR0R(Transform, affine_inverse);
- VCALL_PTR2R(Transform, rotated);
- VCALL_PTR1R(Transform, scaled);
- VCALL_PTR1R(Transform, translated);
- VCALL_PTR0R(Transform, orthonormalized);
- VCALL_PTR2R(Transform, looking_at);
- VCALL_PTR2R(Transform, interpolate_with);
- VCALL_PTR1R(Transform, is_equal_approx);
-
- static void _call_Transform_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR3:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3());
- return;
- case Variant::PLANE:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Plane());
- return;
- case Variant::AABB:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::AABB());
- return;
- case Variant::PACKED_VECTOR3_ARRAY:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::PackedVector3Array());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'xform' in base 'Transform'. Valid types are Vector3, Plane, AABB, and PackedVector3Array.");
- }
+ static void func_Callable_bind(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
+ r_ret = callable->bind(p_args, p_argcount);
}
- static void _call_Transform_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
- switch (p_args[0]->type) {
- case Variant::VECTOR3:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3());
- return;
- case Variant::PLANE:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Plane());
- return;
- case Variant::AABB:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::AABB());
- return;
- case Variant::PACKED_VECTOR3_ARRAY:
- r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::PackedVector3Array());
- return;
- default:
- r_ret = Variant();
- ERR_PRINT("Invalid type in function 'xform_inv' in base 'Transform'. Valid types are Vector3, Plane, AABB, and PackedVector3Array.");
- }
+ static void func_Signal_emit(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
+ Signal *signal = VariantGetInternalPtr<Signal>::get_ptr(v);
+ signal->emit(p_args, p_argcount);
}
struct ConstructData {
@@ -1300,9 +1009,10 @@ struct _VariantCall {
}
};
-_VariantCall::TypeFunc *_VariantCall::type_funcs = nullptr;
_VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr;
_VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
+_VariantCall::MethodMap *_VariantCall::type_internal_methods = nullptr;
+List<StringName> *_VariantCall::type_internal_method_names = nullptr;
Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
Variant ret;
@@ -1334,38 +1044,14 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
} else {
r_error.error = Callable::CallError::CALL_OK;
- Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method);
-
- if (E) {
- _VariantCall::FuncData &funcdata = E->get();
- funcdata.call(ret, *this, p_args, p_argcount, r_error);
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(p_method);
+ if (m) {
+ (*m)->call((Variant *)this, p_args, p_argcount, ret, r_error);
} else {
- //handle vararg functions manually
- bool valid = false;
- if (type == CALLABLE) {
- if (p_method == CoreStringNames::get_singleton()->call) {
- reinterpret_cast<const Callable *>(_data._mem)->call(p_args, p_argcount, ret, r_error);
- valid = true;
- }
- if (p_method == CoreStringNames::get_singleton()->call_deferred) {
- reinterpret_cast<const Callable *>(_data._mem)->call_deferred(p_args, p_argcount);
- valid = true;
- }
- } else if (type == SIGNAL) {
- if (p_method == CoreStringNames::get_singleton()->emit) {
- if (r_ret) {
- *r_ret = Variant();
- }
- reinterpret_cast<const Signal *>(_data._mem)->emit(p_args, p_argcount);
- valid = true;
- }
- }
- if (!valid) {
- //ok fail because not found
- r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- return;
- }
+ //ok fail because not found
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
+ return;
}
}
@@ -1593,126 +1279,96 @@ bool Variant::has_method(const StringName &p_method) const {
return obj->has_method(p_method);
}
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type];
- return tf.functions.has(p_method);
+ return _VariantCall::type_internal_methods[type].has(p_method);
}
Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
+ Vector<Variant::Type> types;
- const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E) {
- return Vector<Variant::Type>();
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method);
+ if (*m) {
+ types.resize((*m)->get_argument_count());
+ for (int i = 0; i < (*m)->get_argument_count(); i++) {
+ types.write[i] = (*m)->get_argument_type(i);
+ }
}
- return E->get().arg_types;
+ return types;
}
bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
-
- const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E) {
- return false;
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method);
+ if (*m) {
+ return (*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST;
}
-
- return E->get()._const;
+ return false;
}
Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
+ Vector<StringName> argnames;
- const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E) {
- return Vector<StringName>();
+#ifdef DEBUG_ENABLED
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method);
+ if (*m) {
+ argnames.resize((*m)->get_argument_count());
+ for (int i = 0; i < (*m)->get_argument_count(); i++) {
+ argnames.write[i] = (*m)->get_argument_name(i);
+ }
}
-
- return E->get().arg_names;
+#endif
+ return argnames;
}
Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
-
- const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E) {
- return Variant::NIL;
- }
-
- if (r_has_return) {
- *r_has_return = E->get().returns;
+ Variant::Type rt = Variant::NIL;
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method);
+ if (*m) {
+ rt = (*m)->get_return_type();
+ if (r_has_return) {
+ *r_has_return = ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) || rt != Variant::NIL;
+ }
}
-
- return E->get().return_type;
+ return rt;
}
Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
-
- const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E) {
- return Vector<Variant>();
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method);
+ if (*m) {
+ return (*m)->get_default_arguments();
}
-
- return E->get().default_args;
+ return Vector<Variant>();
}
void Variant::get_method_list(List<MethodInfo> *p_list) const {
- const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type];
-
- for (const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.front(); E; E = E->next()) {
- const _VariantCall::FuncData &fd = E->get();
+ for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[type].front(); E; E = E->next()) {
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(E->get());
+ ERR_CONTINUE(!*m);
MethodInfo mi;
- mi.name = E->key();
-
- if (fd._const) {
+ mi.name = E->get();
+ mi.return_val.type = (*m)->get_return_type();
+ if ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) {
+ mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
+ }
+ if ((*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST) {
mi.flags |= METHOD_FLAG_CONST;
}
-
- for (int i = 0; i < fd.arg_types.size(); i++) {
- PropertyInfo pi;
- pi.type = fd.arg_types[i];
-#ifdef DEBUG_ENABLED
- pi.name = fd.arg_names[i];
-#endif
- mi.arguments.push_back(pi);
+ if ((*m)->get_flags() & Variant::InternalMethod::FLAG_VARARGS) {
+ mi.flags |= METHOD_FLAG_VARARG;
}
- mi.default_arguments = fd.default_args;
- PropertyInfo ret;
+ for (int i = 0; i < (*m)->get_argument_count(); i++) {
+ PropertyInfo arg;
#ifdef DEBUG_ENABLED
- ret.type = fd.return_type;
- if (fd.returns) {
- ret.name = "ret";
- if (fd.return_type == Variant::NIL) {
- ret.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
- }
- }
- mi.return_val = ret;
+ arg.name = (*m)->get_argument_name(i);
+#else
+ arg.name = "arg" + itos(i + 1);
#endif
+ arg.type = (*m)->get_argument_type(i);
+ mi.arguments.push_back(arg);
+ }
- p_list->push_back(mi);
- }
-
- if (type == CALLABLE) {
- MethodInfo mi;
- mi.name = "call";
- mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
- mi.flags |= METHOD_FLAG_VARARG;
-
- p_list->push_back(mi);
-
- mi.name = "call_deferred";
- mi.return_val.usage = 0;
-
- p_list->push_back(mi);
- }
-
- if (type == SIGNAL) {
- MethodInfo mi;
- mi.name = "emit";
- mi.flags |= METHOD_FLAG_VARARG;
-
+ mi.default_arguments = (*m)->get_default_arguments();
p_list->push_back(mi);
}
}
@@ -1811,565 +1467,619 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va
return E->get();
}
-void register_variant_methods() {
- _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX);
+Variant::InternalMethod *Variant::get_internal_method(Type p_type, const StringName &p_method_name) {
+ ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, nullptr);
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method_name);
+ if (*m) {
+ return *m;
+ }
+ return nullptr;
+}
+
+void register_variant_methods() {
+ _VariantCall::type_internal_methods = memnew_arr(_VariantCall::MethodMap, Variant::VARIANT_MAX);
+ _VariantCall::type_internal_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX);
_VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX);
_VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
-#define ADDFUNC0R(m_vtype, m_ret, m_class, m_method, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
-#define ADDFUNC1R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
-#define ADDFUNC2R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
-#define ADDFUNC3R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
-#define ADDFUNC4R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
-
-#define ADDFUNC0RNC(m_vtype, m_ret, m_class, m_method, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
-#define ADDFUNC1RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
-#define ADDFUNC2RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
-#define ADDFUNC3RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
-#define ADDFUNC4RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
-
-#define ADDFUNC0(m_vtype, m_ret, m_class, m_method, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
-#define ADDFUNC1(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
-#define ADDFUNC2(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
-#define ADDFUNC3(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
-#define ADDFUNC4(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
- _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
-
-#define ADDFUNC0NC(m_vtype, m_ret, m_class, m_method, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
-#define ADDFUNC1NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
-#define ADDFUNC2NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
-#define ADDFUNC3NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
-#define ADDFUNC4NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
- _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
-
/* STRING */
- ADDFUNC1R(STRING, INT, String, casecmp_to, STRING, "to", varray());
- ADDFUNC1R(STRING, INT, String, nocasecmp_to, STRING, "to", varray());
- ADDFUNC1R(STRING, INT, String, naturalnocasecmp_to, STRING, "to", varray());
- ADDFUNC0R(STRING, INT, String, length, varray());
- ADDFUNC2R(STRING, STRING, String, substr, INT, "from", INT, "len", varray(-1));
-
- ADDFUNC2R(STRING, INT, String, find, STRING, "what", INT, "from", varray(0));
-
- ADDFUNC3R(STRING, INT, String, count, STRING, "what", INT, "from", INT, "to", varray(0, 0));
- ADDFUNC3R(STRING, INT, String, countn, STRING, "what", INT, "from", INT, "to", varray(0, 0));
-
- ADDFUNC2R(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0));
- ADDFUNC2R(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1));
- ADDFUNC2R(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1));
- ADDFUNC1R(STRING, BOOL, String, match, STRING, "expr", varray());
- ADDFUNC1R(STRING, BOOL, String, matchn, STRING, "expr", varray());
- ADDFUNC1R(STRING, BOOL, String, begins_with, STRING, "text", varray());
- ADDFUNC1R(STRING, BOOL, String, ends_with, STRING, "text", varray());
- ADDFUNC1R(STRING, BOOL, String, is_subsequence_of, STRING, "text", varray());
- ADDFUNC1R(STRING, BOOL, String, is_subsequence_ofi, STRING, "text", varray());
- ADDFUNC0R(STRING, PACKED_STRING_ARRAY, String, bigrams, varray());
- ADDFUNC1R(STRING, FLOAT, String, similarity, STRING, "text", varray());
-
- ADDFUNC2R(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
- ADDFUNC2R(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
- ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
- ADDFUNC1R(STRING, STRING, String, repeat, INT, "count", varray());
- ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
- ADDFUNC0R(STRING, STRING, String, capitalize, varray());
- ADDFUNC3R(STRING, PACKED_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
- ADDFUNC3R(STRING, PACKED_STRING_ARRAY, String, rsplit, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
- ADDFUNC2R(STRING, PACKED_FLOAT32_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true));
- ADDFUNC1R(STRING, STRING, String, join, PACKED_STRING_ARRAY, "parts", varray());
-
- ADDFUNC0R(STRING, STRING, String, to_upper, varray());
- ADDFUNC0R(STRING, STRING, String, to_lower, varray());
-
- ADDFUNC1R(STRING, STRING, String, left, INT, "position", varray());
- ADDFUNC1R(STRING, STRING, String, right, INT, "position", varray());
- ADDFUNC2R(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true));
- ADDFUNC0R(STRING, STRING, String, strip_escapes, varray());
- ADDFUNC1R(STRING, STRING, String, lstrip, STRING, "chars", varray());
- ADDFUNC1R(STRING, STRING, String, rstrip, STRING, "chars", varray());
- ADDFUNC0R(STRING, STRING, String, get_extension, varray());
- ADDFUNC0R(STRING, STRING, String, get_basename, varray());
- ADDFUNC1R(STRING, STRING, String, plus_file, STRING, "file", varray());
- ADDFUNC1R(STRING, INT, String, ord_at, INT, "at", varray());
- ADDFUNC0R(STRING, STRING, String, dedent, varray());
- ADDFUNC2(STRING, NIL, String, erase, INT, "position", INT, "chars", varray());
- ADDFUNC0R(STRING, INT, String, hash, varray());
- ADDFUNC0R(STRING, STRING, String, md5_text, varray());
- ADDFUNC0R(STRING, STRING, String, sha1_text, varray());
- ADDFUNC0R(STRING, STRING, String, sha256_text, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, md5_buffer, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, sha1_buffer, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, sha256_buffer, varray());
- ADDFUNC0R(STRING, BOOL, String, empty, varray());
- ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray());
- ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray());
- ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray());
- ADDFUNC0R(STRING, STRING, String, get_base_dir, varray());
- ADDFUNC0R(STRING, STRING, String, get_file, varray());
- ADDFUNC0R(STRING, STRING, String, xml_escape, varray());
- ADDFUNC0R(STRING, STRING, String, xml_unescape, varray());
- ADDFUNC0R(STRING, STRING, String, http_escape, varray());
- ADDFUNC0R(STRING, STRING, String, http_unescape, varray());
- ADDFUNC0R(STRING, STRING, String, c_escape, varray());
- ADDFUNC0R(STRING, STRING, String, c_unescape, varray());
- ADDFUNC0R(STRING, STRING, String, json_escape, varray());
- ADDFUNC0R(STRING, STRING, String, percent_encode, varray());
- ADDFUNC0R(STRING, STRING, String, percent_decode, varray());
- ADDFUNC0R(STRING, BOOL, String, is_valid_identifier, varray());
- ADDFUNC0R(STRING, BOOL, String, is_valid_integer, varray());
- ADDFUNC0R(STRING, BOOL, String, is_valid_float, varray());
- ADDFUNC1R(STRING, BOOL, String, is_valid_hex_number, BOOL, "with_prefix", varray(false));
- ADDFUNC0R(STRING, BOOL, String, is_valid_html_color, varray());
- ADDFUNC0R(STRING, BOOL, String, is_valid_ip_address, varray());
- ADDFUNC0R(STRING, BOOL, String, is_valid_filename, varray());
- ADDFUNC0R(STRING, INT, String, to_int, varray());
- ADDFUNC0R(STRING, FLOAT, String, to_float, varray());
- ADDFUNC0R(STRING, INT, String, hex_to_int, varray());
- ADDFUNC2R(STRING, STRING, String, lpad, INT, "min_length", STRING, "character", varray(" "));
- ADDFUNC2R(STRING, STRING, String, rpad, INT, "min_length", STRING, "character", varray(" "));
- ADDFUNC1R(STRING, STRING, String, pad_decimals, INT, "digits", varray());
- ADDFUNC1R(STRING, STRING, String, pad_zeros, INT, "digits", varray());
- ADDFUNC1R(STRING, STRING, String, trim_prefix, STRING, "prefix", varray());
- ADDFUNC1R(STRING, STRING, String, trim_suffix, STRING, "suffix", varray());
-
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_ascii, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf8, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf16, varray());
- ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf32, varray());
-
- ADDFUNC0R(VECTOR2, FLOAT, Vector2, angle, varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, angle_to, VECTOR2, "to", varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, angle_to_point, VECTOR2, "to", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, direction_to, VECTOR2, "b", varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, distance_to, VECTOR2, "to", varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, distance_squared_to, VECTOR2, "to", varray());
- ADDFUNC0R(VECTOR2, FLOAT, Vector2, length, varray());
- ADDFUNC0R(VECTOR2, FLOAT, Vector2, length_squared, varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, normalized, varray());
- ADDFUNC0R(VECTOR2, BOOL, Vector2, is_normalized, varray());
- ADDFUNC1R(VECTOR2, BOOL, Vector2, is_equal_approx, VECTOR2, "v", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmod, FLOAT, "mod", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmodv, VECTOR2, "modv", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, project, VECTOR2, "b", varray());
- ADDFUNC2R(VECTOR2, VECTOR2, Vector2, lerp, VECTOR2, "b", FLOAT, "t", varray());
- ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", FLOAT, "t", varray());
- ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", FLOAT, "t", varray());
- ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", FLOAT, "delta", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, FLOAT, "phi", varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, tangent, varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, floor, varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, ceil, varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, round, varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, snapped, VECTOR2, "by", varray());
- ADDFUNC0R(VECTOR2, FLOAT, Vector2, aspect, varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, dot, VECTOR2, "with", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, slide, VECTOR2, "n", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, bounce, VECTOR2, "n", varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "n", varray());
- ADDFUNC1R(VECTOR2, FLOAT, Vector2, cross, VECTOR2, "with", varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray());
- ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, FLOAT, "length", varray());
- ADDFUNC0R(VECTOR2, VECTOR2, Vector2, sign, varray());
-
- ADDFUNC0R(VECTOR2I, FLOAT, Vector2i, aspect, varray());
- ADDFUNC0R(VECTOR2I, VECTOR2I, Vector2i, sign, varray());
- ADDFUNC0R(VECTOR2I, VECTOR2I, Vector2i, abs, varray());
-
- ADDFUNC0R(RECT2, FLOAT, Rect2, get_area, varray());
- ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray());
- ADDFUNC1R(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray());
- ADDFUNC1R(RECT2, BOOL, Rect2, is_equal_approx, RECT2, "rect", varray());
- ADDFUNC2R(RECT2, BOOL, Rect2, intersects, RECT2, "b", BOOL, "include_borders", varray(false));
- ADDFUNC1R(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray());
- ADDFUNC1R(RECT2, RECT2, Rect2, clip, RECT2, "b", varray());
- ADDFUNC1R(RECT2, RECT2, Rect2, merge, RECT2, "b", varray());
- ADDFUNC1R(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
- ADDFUNC1R(RECT2, RECT2, Rect2, grow, FLOAT, "by", varray());
- ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", FLOAT, "by", varray());
- ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, FLOAT, "left", FLOAT, "top", FLOAT, "right", FLOAT, " bottom", varray());
- ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray());
-
- ADDFUNC0R(RECT2I, INT, Rect2i, get_area, varray());
- ADDFUNC0R(RECT2I, BOOL, Rect2i, has_no_area, varray());
- ADDFUNC1R(RECT2I, BOOL, Rect2i, has_point, VECTOR2I, "point", varray());
- ADDFUNC1R(RECT2I, BOOL, Rect2i, intersects, RECT2I, "b", varray());
- ADDFUNC1R(RECT2I, BOOL, Rect2i, encloses, RECT2I, "b", varray());
- ADDFUNC1R(RECT2I, RECT2I, Rect2i, clip, RECT2I, "b", varray());
- ADDFUNC1R(RECT2I, RECT2I, Rect2i, merge, RECT2I, "b", varray());
- ADDFUNC1R(RECT2I, RECT2I, Rect2i, expand, VECTOR2I, "to", varray());
- ADDFUNC1R(RECT2I, RECT2I, Rect2i, grow, INT, "by", varray());
- ADDFUNC2R(RECT2I, RECT2I, Rect2i, grow_margin, INT, "margin", INT, "by", varray());
- ADDFUNC4R(RECT2I, RECT2I, Rect2i, grow_individual, INT, "left", INT, "top", INT, "right", INT, " bottom", varray());
- ADDFUNC0R(RECT2I, RECT2I, Rect2i, abs, varray());
-
- ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray());
- ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray());
- ADDFUNC1R(VECTOR3, FLOAT, Vector3, angle_to, VECTOR3, "to", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray());
- ADDFUNC1R(VECTOR3, FLOAT, Vector3, distance_to, VECTOR3, "b", varray());
- ADDFUNC1R(VECTOR3, FLOAT, Vector3, distance_squared_to, VECTOR3, "b", varray());
- ADDFUNC0R(VECTOR3, FLOAT, Vector3, length, varray());
- ADDFUNC0R(VECTOR3, FLOAT, Vector3, length_squared, varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, normalized, varray());
- ADDFUNC0R(VECTOR3, BOOL, Vector3, is_normalized, varray());
- ADDFUNC1R(VECTOR3, BOOL, Vector3, is_equal_approx, VECTOR3, "v", varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, inverse, varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, VECTOR3, "by", varray());
- ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", FLOAT, "phi", varray());
- ADDFUNC2R(VECTOR3, VECTOR3, Vector3, lerp, VECTOR3, "b", FLOAT, "t", varray());
- ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", FLOAT, "t", varray());
- ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", FLOAT, "t", varray());
- ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", FLOAT, "delta", varray());
- ADDFUNC1R(VECTOR3, FLOAT, Vector3, dot, VECTOR3, "b", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
- ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());
- ADDFUNC0R(VECTOR3, BASIS, Vector3, to_diagonal_matrix, varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, abs, varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, floor, varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, ceil, varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, round, varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmod, FLOAT, "mod", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmodv, VECTOR3, "modv", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, project, VECTOR3, "b", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, slide, VECTOR3, "n", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, bounce, VECTOR3, "n", varray());
- ADDFUNC1R(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "n", varray());
- ADDFUNC0R(VECTOR3, VECTOR3, Vector3, sign, varray());
-
- ADDFUNC0R(VECTOR3I, INT, Vector3i, min_axis, varray());
- ADDFUNC0R(VECTOR3I, INT, Vector3i, max_axis, varray());
- ADDFUNC0R(VECTOR3I, VECTOR3I, Vector3i, sign, varray());
-
- ADDFUNC0R(PLANE, PLANE, Plane, normalized, varray());
- ADDFUNC0R(PLANE, VECTOR3, Plane, center, varray());
- ADDFUNC1R(PLANE, BOOL, Plane, is_equal_approx, PLANE, "plane", varray());
- ADDFUNC1R(PLANE, BOOL, Plane, is_point_over, VECTOR3, "point", varray());
- ADDFUNC1R(PLANE, FLOAT, Plane, distance_to, VECTOR3, "point", varray());
- ADDFUNC2R(PLANE, BOOL, Plane, has_point, VECTOR3, "point", FLOAT, "epsilon", varray(CMP_EPSILON));
- ADDFUNC1R(PLANE, VECTOR3, Plane, project, VECTOR3, "point", varray());
- ADDFUNC2R(PLANE, VECTOR3, Plane, intersect_3, PLANE, "b", PLANE, "c", varray());
- ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_ray, VECTOR3, "from", VECTOR3, "dir", varray());
- ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_segment, VECTOR3, "begin", VECTOR3, "end", varray());
-
- ADDFUNC0R(QUAT, FLOAT, Quat, length, varray());
- ADDFUNC0R(QUAT, FLOAT, Quat, length_squared, varray());
- ADDFUNC0R(QUAT, QUAT, Quat, normalized, varray());
- ADDFUNC0R(QUAT, BOOL, Quat, is_normalized, varray());
- ADDFUNC1R(QUAT, BOOL, Quat, is_equal_approx, QUAT, "quat", varray());
- ADDFUNC0R(QUAT, QUAT, Quat, inverse, varray());
- ADDFUNC1R(QUAT, FLOAT, Quat, dot, QUAT, "b", varray());
- ADDFUNC1R(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray());
- ADDFUNC2R(QUAT, QUAT, Quat, slerp, QUAT, "b", FLOAT, "t", varray());
- ADDFUNC2R(QUAT, QUAT, Quat, slerpni, QUAT, "b", FLOAT, "t", varray());
- ADDFUNC4R(QUAT, QUAT, Quat, cubic_slerp, QUAT, "b", QUAT, "pre_a", QUAT, "post_b", FLOAT, "t", varray());
- ADDFUNC0R(QUAT, VECTOR3, Quat, get_euler, varray());
- ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray());
- ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", FLOAT, "angle", varray());
-
- ADDFUNC0R(COLOR, INT, Color, to_argb32, varray());
- ADDFUNC0R(COLOR, INT, Color, to_abgr32, varray());
- ADDFUNC0R(COLOR, INT, Color, to_rgba32, varray());
- ADDFUNC0R(COLOR, INT, Color, to_argb64, varray());
- ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray());
- ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
- ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
- ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
- ADDFUNC2R(COLOR, COLOR, Color, lerp, COLOR, "b", FLOAT, "t", varray());
- ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray());
- ADDFUNC1R(COLOR, COLOR, Color, lightened, FLOAT, "amount", varray());
- ADDFUNC1R(COLOR, COLOR, Color, darkened, FLOAT, "amount", varray());
- ADDFUNC1R(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true));
- ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0));
- ADDFUNC1R(COLOR, BOOL, Color, is_equal_approx, COLOR, "color", varray());
-
- ADDFUNC0R(_RID, INT, RID, get_id, varray());
-
- ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_absolute, varray());
- ADDFUNC0R(NODE_PATH, INT, NodePath, get_name_count, varray());
- ADDFUNC1R(NODE_PATH, STRING, NodePath, get_name, INT, "idx", varray());
- ADDFUNC0R(NODE_PATH, INT, NodePath, get_subname_count, varray());
- ADDFUNC1R(NODE_PATH, STRING, NodePath, get_subname, INT, "idx", varray());
- ADDFUNC0R(NODE_PATH, STRING, NodePath, get_concatenated_subnames, varray());
- ADDFUNC0R(NODE_PATH, NODE_PATH, NodePath, get_as_property_path, varray());
- ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_empty, varray());
-
- ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray());
- ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray());
- ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray());
- ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
- ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
- ADDFUNC1RNC(DICTIONARY, BOOL, Dictionary, erase, NIL, "key", varray());
- ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray());
- ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray());
- ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray());
- ADDFUNC1R(DICTIONARY, DICTIONARY, Dictionary, duplicate, BOOL, "deep", varray(false));
- ADDFUNC2R(DICTIONARY, NIL, Dictionary, get, NIL, "key", NIL, "default", varray(Variant()));
-
- ADDFUNC0R(CALLABLE, BOOL, Callable, is_null, varray());
- ADDFUNC0R(CALLABLE, BOOL, Callable, is_custom, varray());
- ADDFUNC0R(CALLABLE, BOOL, Callable, is_standard, varray());
- ADDFUNC0R(CALLABLE, OBJECT, Callable, get_object, varray());
- ADDFUNC0R(CALLABLE, INT, Callable, get_object_id, varray());
- ADDFUNC0R(CALLABLE, STRING_NAME, Callable, get_method, varray());
- ADDFUNC0R(CALLABLE, INT, Callable, hash, varray());
-
- ADDFUNC0R(SIGNAL, BOOL, Signal, is_null, varray());
- ADDFUNC0R(SIGNAL, OBJECT, Signal, get_object, varray());
- ADDFUNC0R(SIGNAL, INT, Signal, get_object_id, varray());
- ADDFUNC0R(SIGNAL, STRING_NAME, Signal, get_name, varray());
-
- ADDFUNC3R(SIGNAL, INT, Signal, connect, CALLABLE, "callable", ARRAY, "binds", INT, "flags", varray(Array(), 0));
-
- ADDFUNC1R(SIGNAL, NIL, Signal, disconnect, CALLABLE, "callable", varray());
- ADDFUNC1R(SIGNAL, BOOL, Signal, is_connected, CALLABLE, "callable", varray());
- ADDFUNC0R(SIGNAL, ARRAY, Signal, get_connections, varray());
-
- ADDFUNC0R(ARRAY, INT, Array, size, varray());
- ADDFUNC0R(ARRAY, BOOL, Array, empty, varray());
- ADDFUNC0NC(ARRAY, NIL, Array, clear, varray());
- ADDFUNC0R(ARRAY, INT, Array, hash, varray());
- ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
- ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
- ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray());
- ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray());
- ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
- ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray());
- ADDFUNC1NC(ARRAY, NIL, Array, erase, NIL, "value", varray());
- ADDFUNC0R(ARRAY, NIL, Array, front, varray());
- ADDFUNC0R(ARRAY, NIL, Array, back, varray());
- ADDFUNC2R(ARRAY, INT, Array, find, NIL, "what", INT, "from", varray(0));
- ADDFUNC2R(ARRAY, INT, Array, rfind, NIL, "what", INT, "from", varray(-1));
- ADDFUNC1R(ARRAY, INT, Array, find_last, NIL, "value", varray());
- ADDFUNC1R(ARRAY, INT, Array, count, NIL, "value", varray());
- ADDFUNC1R(ARRAY, BOOL, Array, has, NIL, "value", varray());
- ADDFUNC0RNC(ARRAY, NIL, Array, pop_back, varray());
- ADDFUNC0RNC(ARRAY, NIL, Array, pop_front, varray());
- ADDFUNC0NC(ARRAY, NIL, Array, sort, varray());
- ADDFUNC2NC(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray());
- ADDFUNC0NC(ARRAY, NIL, Array, shuffle, varray());
- ADDFUNC2R(ARRAY, INT, Array, bsearch, NIL, "value", BOOL, "before", varray(true));
- ADDFUNC4R(ARRAY, INT, Array, bsearch_custom, NIL, "value", OBJECT, "obj", STRING, "func", BOOL, "before", varray(true));
- ADDFUNC0NC(ARRAY, NIL, Array, invert, varray());
- ADDFUNC1R(ARRAY, ARRAY, Array, duplicate, BOOL, "deep", varray(false));
- ADDFUNC4R(ARRAY, ARRAY, Array, slice, INT, "begin", INT, "end", INT, "step", BOOL, "deep", varray(1, false));
- ADDFUNC0R(ARRAY, NIL, Array, max, varray());
- ADDFUNC0R(ARRAY, NIL, Array, min, varray());
-
- ADDFUNC0R(PACKED_BYTE_ARRAY, INT, PackedByteArray, size, varray());
- ADDFUNC0R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, empty, varray());
- ADDFUNC2(PACKED_BYTE_ARRAY, NIL, PackedByteArray, set, INT, "idx", INT, "byte", varray());
- ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, push_back, INT, "byte", varray());
- ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, append, INT, "byte", varray());
- ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, append_array, PACKED_BYTE_ARRAY, "array", varray());
- ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_BYTE_ARRAY, INT, PackedByteArray, insert, INT, "idx", INT, "byte", varray());
- ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, has, INT, "value", varray());
- ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, sort, varray());
- ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, invert, varray());
- ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, subarray, INT, "from", INT, "to", varray());
-
- ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_ascii, varray());
- ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf8, varray());
- ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf16, varray());
- ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf32, varray());
- ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, hex_encode, varray());
- ADDFUNC1R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, compress, INT, "compression_mode", varray(0));
- ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0));
- ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, decompress_dynamic, INT, "max_output_size", INT, "compression_mode", varray(0));
-
- ADDFUNC0R(PACKED_INT32_ARRAY, INT, PackedInt32Array, size, varray());
- ADDFUNC0R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, empty, varray());
- ADDFUNC2(PACKED_INT32_ARRAY, NIL, PackedInt32Array, set, INT, "idx", INT, "integer", varray());
- ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, push_back, INT, "integer", varray());
- ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, append, INT, "integer", varray());
- ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, append_array, PACKED_INT32_ARRAY, "array", varray());
- ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_INT32_ARRAY, INT, PackedInt32Array, insert, INT, "idx", INT, "integer", varray());
- ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, has, INT, "value", varray());
- ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, sort, varray());
- ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, invert, varray());
-
- ADDFUNC0R(PACKED_INT64_ARRAY, INT, PackedInt64Array, size, varray());
- ADDFUNC0R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, empty, varray());
- ADDFUNC2(PACKED_INT64_ARRAY, NIL, PackedInt64Array, set, INT, "idx", INT, "integer", varray());
- ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, push_back, INT, "integer", varray());
- ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, append, INT, "integer", varray());
- ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, append_array, PACKED_INT64_ARRAY, "array", varray());
- ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_INT64_ARRAY, INT, PackedInt64Array, insert, INT, "idx", INT, "integer", varray());
- ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, has, INT, "value", varray());
- ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, sort, varray());
- ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, invert, varray());
-
- ADDFUNC0R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, size, varray());
- ADDFUNC0R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, empty, varray());
- ADDFUNC2(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, set, INT, "idx", FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, push_back, FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, append, FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, append_array, PACKED_FLOAT32_ARRAY, "array", varray());
- ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, insert, INT, "idx", FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, has, FLOAT, "value", varray());
- ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, sort, varray());
- ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, invert, varray());
-
- ADDFUNC0R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, size, varray());
- ADDFUNC0R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, empty, varray());
- ADDFUNC2(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, set, INT, "idx", FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, push_back, FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, append, FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, append_array, PACKED_FLOAT64_ARRAY, "array", varray());
- ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, insert, INT, "idx", FLOAT, "value", varray());
- ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, has, FLOAT, "value", varray());
- ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, sort, varray());
- ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, invert, varray());
-
- ADDFUNC0R(PACKED_STRING_ARRAY, INT, PackedStringArray, size, varray());
- ADDFUNC0R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, empty, varray());
- ADDFUNC2(PACKED_STRING_ARRAY, NIL, PackedStringArray, set, INT, "idx", STRING, "string", varray());
- ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, push_back, STRING, "string", varray());
- ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, append, STRING, "string", varray());
- ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, append_array, PACKED_STRING_ARRAY, "array", varray());
- ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_STRING_ARRAY, INT, PackedStringArray, insert, INT, "idx", STRING, "string", varray());
- ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, has, STRING, "value", varray());
- ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, sort, varray());
- ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, invert, varray());
-
- ADDFUNC0R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, size, varray());
- ADDFUNC0R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, empty, varray());
- ADDFUNC2(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, set, INT, "idx", VECTOR2, "vector2", varray());
- ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, push_back, VECTOR2, "vector2", varray());
- ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, append, VECTOR2, "vector2", varray());
- ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, append_array, PACKED_VECTOR2_ARRAY, "array", varray());
- ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, insert, INT, "idx", VECTOR2, "vector2", varray());
- ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, has, VECTOR2, "value", varray());
- ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, sort, varray());
- ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, invert, varray());
-
- ADDFUNC0R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, size, varray());
- ADDFUNC0R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, empty, varray());
- ADDFUNC2(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, set, INT, "idx", VECTOR3, "vector3", varray());
- ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, push_back, VECTOR3, "vector3", varray());
- ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, append, VECTOR3, "vector3", varray());
- ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, append_array, PACKED_VECTOR3_ARRAY, "array", varray());
- ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, insert, INT, "idx", VECTOR3, "vector3", varray());
- ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, has, VECTOR3, "value", varray());
- ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, sort, varray());
- ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, invert, varray());
-
- ADDFUNC0R(PACKED_COLOR_ARRAY, INT, PackedColorArray, size, varray());
- ADDFUNC0R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, empty, varray());
- ADDFUNC2(PACKED_COLOR_ARRAY, NIL, PackedColorArray, set, INT, "idx", COLOR, "color", varray());
- ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, push_back, COLOR, "color", varray());
- ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, append, COLOR, "color", varray());
- ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, append_array, PACKED_COLOR_ARRAY, "array", varray());
- ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, remove, INT, "idx", varray());
- ADDFUNC2R(PACKED_COLOR_ARRAY, INT, PackedColorArray, insert, INT, "idx", COLOR, "color", varray());
- ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, resize, INT, "idx", varray());
- ADDFUNC1R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, has, COLOR, "value", varray());
- ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, sort, varray());
- ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, invert, varray());
-
- //pointerbased
-
- ADDFUNC0R(AABB, AABB, AABB, abs, varray());
- ADDFUNC0R(AABB, FLOAT, AABB, get_area, varray());
- ADDFUNC0R(AABB, BOOL, AABB, has_no_area, varray());
- ADDFUNC0R(AABB, BOOL, AABB, has_no_surface, varray());
- ADDFUNC1R(AABB, BOOL, AABB, has_point, VECTOR3, "point", varray());
- ADDFUNC1R(AABB, BOOL, AABB, is_equal_approx, AABB, "aabb", varray());
- ADDFUNC1R(AABB, BOOL, AABB, intersects, AABB, "with", varray());
- ADDFUNC1R(AABB, BOOL, AABB, encloses, AABB, "with", varray());
- ADDFUNC1R(AABB, BOOL, AABB, intersects_plane, PLANE, "plane", varray());
- ADDFUNC2R(AABB, BOOL, AABB, intersects_segment, VECTOR3, "from", VECTOR3, "to", varray());
- ADDFUNC1R(AABB, AABB, AABB, intersection, AABB, "with", varray());
- ADDFUNC1R(AABB, AABB, AABB, merge, AABB, "with", varray());
- ADDFUNC1R(AABB, AABB, AABB, expand, VECTOR3, "to_point", varray());
- ADDFUNC1R(AABB, AABB, AABB, grow, FLOAT, "by", varray());
- ADDFUNC1R(AABB, VECTOR3, AABB, get_support, VECTOR3, "dir", varray());
- ADDFUNC0R(AABB, VECTOR3, AABB, get_longest_axis, varray());
- ADDFUNC0R(AABB, INT, AABB, get_longest_axis_index, varray());
- ADDFUNC0R(AABB, FLOAT, AABB, get_longest_axis_size, varray());
- ADDFUNC0R(AABB, VECTOR3, AABB, get_shortest_axis, varray());
- ADDFUNC0R(AABB, INT, AABB, get_shortest_axis_index, varray());
- ADDFUNC0R(AABB, FLOAT, AABB, get_shortest_axis_size, varray());
- ADDFUNC1R(AABB, VECTOR3, AABB, get_endpoint, INT, "idx", varray());
-
- ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, inverse, varray());
- ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, affine_inverse, varray());
- ADDFUNC0R(TRANSFORM2D, FLOAT, Transform2D, get_rotation, varray());
- ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_origin, varray());
- ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_scale, varray());
- ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, orthonormalized, varray());
- ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, rotated, FLOAT, "phi", varray());
- ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, scaled, VECTOR2, "scale", varray());
- ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray());
- ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray());
- ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray());
- ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray());
- ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform_inv, VECTOR2, "v", varray());
- ADDFUNC2R(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", FLOAT, "weight", varray());
- ADDFUNC1R(TRANSFORM2D, BOOL, Transform2D, is_equal_approx, TRANSFORM2D, "transform", varray());
-
- ADDFUNC0R(BASIS, BASIS, Basis, inverse, varray());
- ADDFUNC0R(BASIS, BASIS, Basis, transposed, varray());
- ADDFUNC0R(BASIS, BASIS, Basis, orthonormalized, varray());
- ADDFUNC0R(BASIS, FLOAT, Basis, determinant, varray());
- ADDFUNC2R(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", FLOAT, "phi", varray());
- ADDFUNC1R(BASIS, BASIS, Basis, scaled, VECTOR3, "scale", varray());
- ADDFUNC0R(BASIS, VECTOR3, Basis, get_scale, varray());
- ADDFUNC0R(BASIS, VECTOR3, Basis, get_euler, varray());
- ADDFUNC1R(BASIS, FLOAT, Basis, tdotx, VECTOR3, "with", varray());
- ADDFUNC1R(BASIS, FLOAT, Basis, tdoty, VECTOR3, "with", varray());
- ADDFUNC1R(BASIS, FLOAT, Basis, tdotz, VECTOR3, "with", varray());
- ADDFUNC1R(BASIS, VECTOR3, Basis, xform, VECTOR3, "v", varray());
- ADDFUNC1R(BASIS, VECTOR3, Basis, xform_inv, VECTOR3, "v", varray());
- ADDFUNC0R(BASIS, INT, Basis, get_orthogonal_index, varray());
- ADDFUNC2R(BASIS, BASIS, Basis, slerp, BASIS, "b", FLOAT, "t", varray());
- ADDFUNC1R(BASIS, BOOL, Basis, is_equal_approx, BASIS, "b", varray());
- ADDFUNC0R(BASIS, QUAT, Basis, get_rotation_quat, varray());
-
- ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, inverse, varray());
- ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, affine_inverse, varray());
- ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, orthonormalized, varray());
- ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, rotated, VECTOR3, "axis", FLOAT, "phi", varray());
- ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, scaled, VECTOR3, "scale", varray());
- ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, translated, VECTOR3, "offset", varray());
- ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, looking_at, VECTOR3, "target", VECTOR3, "up", varray());
- ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, interpolate_with, TRANSFORM, "transform", FLOAT, "weight", varray());
- ADDFUNC1R(TRANSFORM, BOOL, Transform, is_equal_approx, TRANSFORM, "transform", varray());
- ADDFUNC1R(TRANSFORM, NIL, Transform, xform, NIL, "v", varray());
- ADDFUNC1R(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray());
+
+ bind_method(String, casecmp_to, sarray("to"), varray());
+ bind_method(String, nocasecmp_to, sarray("to"), varray());
+ bind_method(String, naturalnocasecmp_to, sarray("to"), varray());
+ bind_method(String, length, sarray(), varray());
+ bind_method(String, substr, sarray("from", "len"), varray(-1));
+ bind_methodv("find", static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0));
+ bind_method(String, count, sarray("what", "from", "to"), varray(0, 0));
+ bind_method(String, countn, sarray("what", "from", "to"), varray(0, 0));
+ bind_method(String, findn, sarray("what", "from"), varray(0));
+ bind_method(String, rfind, sarray("what", "from"), varray(-1));
+ bind_method(String, rfindn, sarray("what", "from"), varray(-1));
+ bind_method(String, match, sarray("expr"), varray());
+ bind_method(String, matchn, sarray("expr"), varray());
+ bind_methodv("begins_with", static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray());
+ bind_method(String, ends_with, sarray("text"), varray());
+ bind_method(String, is_subsequence_of, sarray("text"), varray());
+ bind_method(String, is_subsequence_ofi, sarray("text"), varray());
+ bind_method(String, bigrams, sarray(), varray());
+ bind_method(String, similarity, sarray("text"), varray());
+
+ bind_method(String, format, sarray("values", "placeholder"), varray("{_}"));
+ bind_methodv("replace", static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray());
+ bind_method(String, replacen, sarray("what", "forwhat"), varray());
+ bind_method(String, repeat, sarray("count"), varray());
+ bind_method(String, insert, sarray("position", "what"), varray());
+ bind_method(String, capitalize, sarray(), varray());
+ bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0));
+ bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0));
+ bind_method(String, split_floats, sarray("delimiter", "allow_empty"), varray(true));
+ bind_method(String, join, sarray("parts"), varray());
+
+ bind_method(String, to_upper, sarray(), varray());
+ bind_method(String, to_lower, sarray(), varray());
+
+ bind_method(String, left, sarray("position"), varray());
+ bind_method(String, right, sarray("position"), varray());
+
+ bind_method(String, strip_edges, sarray("left", "right"), varray(true, true));
+ bind_method(String, strip_escapes, sarray(), varray());
+ bind_method(String, lstrip, sarray("chars"), varray());
+ bind_method(String, rstrip, sarray("chars"), varray());
+ bind_method(String, get_extension, sarray(), varray());
+ bind_method(String, get_basename, sarray(), varray());
+ bind_method(String, plus_file, sarray("file"), varray());
+ bind_method(String, ord_at, sarray("at"), varray());
+ bind_method(String, dedent, sarray(), varray());
+ //string needs to be immutable when binding
+ //bind_method(String, erase, sarray("position", "chars"), varray());
+ bind_method(String, hash, sarray(), varray());
+ bind_method(String, md5_text, sarray(), varray());
+ bind_method(String, sha1_text, sarray(), varray());
+ bind_method(String, sha256_text, sarray(), varray());
+ bind_method(String, md5_buffer, sarray(), varray());
+ bind_method(String, sha1_buffer, sarray(), varray());
+ bind_method(String, sha256_buffer, sarray(), varray());
+ bind_method(String, empty, sarray(), varray());
+ //static function, not sure how to bind
+ //bind_method(String, humanize_size, sarray("size"), varray());
+
+ bind_method(String, is_abs_path, sarray(), varray());
+ bind_method(String, is_rel_path, sarray(), varray());
+ bind_method(String, get_base_dir, sarray(), varray());
+ bind_method(String, get_file, sarray(), varray());
+ bind_method(String, xml_escape, sarray("escape_quotes"), varray(false));
+ bind_method(String, xml_unescape, sarray(), varray());
+ bind_method(String, http_escape, sarray(), varray());
+ bind_method(String, http_unescape, sarray(), varray());
+ bind_method(String, c_escape, sarray(), varray());
+ bind_method(String, c_unescape, sarray(), varray());
+ bind_method(String, json_escape, sarray(), varray());
+ bind_method(String, percent_encode, sarray(), varray());
+ bind_method(String, percent_decode, sarray(), varray());
+
+ bind_method(String, is_valid_identifier, sarray(), varray());
+ bind_method(String, is_valid_integer, sarray(), varray());
+ bind_method(String, is_valid_float, sarray(), varray());
+ bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false));
+ bind_method(String, is_valid_html_color, sarray(), varray());
+ bind_method(String, is_valid_ip_address, sarray(), varray());
+ bind_method(String, is_valid_filename, sarray(), varray());
+
+ bind_method(String, to_int, sarray(), varray());
+ bind_method(String, to_float, sarray(), varray());
+ bind_method(String, hex_to_int, sarray("with_prefix"), varray(true));
+ bind_method(String, bin_to_int, sarray("with_prefix"), varray(true));
+
+ bind_method(String, lpad, sarray("min_length", "character"), varray(" "));
+ bind_method(String, rpad, sarray("min_length", "character"), varray(" "));
+ bind_method(String, pad_decimals, sarray("digits"), varray());
+ bind_method(String, pad_zeros, sarray("digits"), varray());
+ bind_method(String, trim_prefix, sarray("prefix"), varray());
+ bind_method(String, trim_suffix, sarray("suffix"), varray());
+
+ bind_method(String, to_ascii_buffer, sarray(), varray());
+ bind_method(String, to_utf8_buffer, sarray(), varray());
+ bind_method(String, to_utf16_buffer, sarray(), varray());
+ bind_method(String, to_utf32_buffer, sarray(), varray());
+
+ /* VECTOR2 */
+
+ bind_method(Vector2, angle, sarray(), varray());
+ bind_method(Vector2, angle_to, sarray("to"), varray());
+ bind_method(Vector2, angle_to_point, sarray("to"), varray());
+ bind_method(Vector2, direction_to, sarray("b"), varray());
+ bind_method(Vector2, distance_to, sarray("to"), varray());
+ bind_method(Vector2, distance_squared_to, sarray("to"), varray());
+ bind_method(Vector2, length, sarray(), varray());
+ bind_method(Vector2, length_squared, sarray(), varray());
+ bind_method(Vector2, normalized, sarray(), varray());
+ bind_method(Vector2, is_normalized, sarray(), varray());
+ bind_method(Vector2, is_equal_approx, sarray("to"), varray());
+ bind_method(Vector2, posmod, sarray("mod"), varray());
+ bind_method(Vector2, posmodv, sarray("modv"), varray());
+ bind_method(Vector2, project, sarray("b"), varray());
+ bind_method(Vector2, lerp, sarray("with", "t"), varray());
+ bind_method(Vector2, slerp, sarray("with", "t"), varray());
+ bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Vector2, move_toward, sarray("to", "delta"), varray());
+ bind_method(Vector2, rotated, sarray("phi"), varray());
+ bind_method(Vector2, tangent, sarray(), varray());
+ bind_method(Vector2, floor, sarray(), varray());
+ bind_method(Vector2, ceil, sarray(), varray());
+ bind_method(Vector2, round, sarray(), varray());
+ bind_method(Vector2, aspect, sarray(), varray());
+ bind_method(Vector2, dot, sarray("with"), varray());
+ bind_method(Vector2, slide, sarray("n"), varray());
+ bind_method(Vector2, bounce, sarray("n"), varray());
+ bind_method(Vector2, reflect, sarray("n"), varray());
+ bind_method(Vector2, cross, sarray("with"), varray());
+ bind_method(Vector2, abs, sarray(), varray());
+ bind_method(Vector2, sign, sarray(), varray());
+ bind_method(Vector2, clamped, sarray("length"), varray());
+
+ /* VECTOR2I */
+
+ bind_method(Vector2i, aspect, sarray(), varray());
+ bind_method(Vector2i, sign, sarray(), varray());
+ bind_method(Vector2i, abs, sarray(), varray());
+
+ /* RECT2 */
+
+ bind_method(Rect2, get_area, sarray(), varray());
+ bind_method(Rect2, has_no_area, sarray(), varray());
+ bind_method(Rect2, has_point, sarray("point"), varray());
+ bind_method(Rect2, is_equal_approx, sarray("rect"), varray());
+ bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false));
+ bind_method(Rect2, encloses, sarray("b"), varray());
+ bind_method(Rect2, clip, sarray("b"), varray());
+ bind_method(Rect2, merge, sarray("b"), varray());
+ bind_method(Rect2, expand, sarray("to"), varray());
+ bind_method(Rect2, grow, sarray("by"), varray());
+ bind_methodv("grow_margin", &Rect2::grow_margin_bind, sarray("margin", "by"), varray());
+ bind_method(Rect2, grow_individual, sarray("left", "top", "right", "bottom"), varray());
+ bind_method(Rect2, abs, sarray(), varray());
+
+ /* Rect2i */
+
+ bind_method(Rect2i, get_area, sarray(), varray());
+ bind_method(Rect2i, has_no_area, sarray(), varray());
+ bind_method(Rect2i, has_point, sarray("point"), varray());
+ bind_method(Rect2i, intersects, sarray("b"), varray());
+ bind_method(Rect2i, encloses, sarray("b"), varray());
+ bind_method(Rect2i, clip, sarray("b"), varray());
+ bind_method(Rect2i, merge, sarray("b"), varray());
+ bind_method(Rect2i, expand, sarray("to"), varray());
+ bind_method(Rect2i, grow, sarray("by"), varray());
+ bind_methodv("grow_margin", &Rect2i::grow_margin_bind, sarray("margin", "by"), varray());
+ bind_method(Rect2i, grow_individual, sarray("left", "top", "right", "bottom"), varray());
+ bind_method(Rect2i, abs, sarray(), varray());
+
+ /* Vector3 */
+
+ bind_method(Vector3, min_axis, sarray(), varray());
+ bind_method(Vector3, max_axis, sarray(), varray());
+ bind_method(Vector3, angle_to, sarray("to"), varray());
+ bind_method(Vector3, direction_to, sarray("b"), varray());
+ bind_method(Vector3, distance_to, sarray("b"), varray());
+ bind_method(Vector3, distance_squared_to, sarray("b"), varray());
+ bind_method(Vector3, length, sarray(), varray());
+ bind_method(Vector3, length_squared, sarray(), varray());
+ bind_method(Vector3, normalized, sarray(), varray());
+ bind_method(Vector3, is_normalized, sarray(), varray());
+ bind_method(Vector3, is_equal_approx, sarray("to"), varray());
+ bind_method(Vector3, inverse, sarray(), varray());
+ bind_method(Vector3, snapped, sarray("by"), varray());
+ bind_method(Vector3, rotated, sarray("by_axis", "phi"), varray());
+ bind_method(Vector3, lerp, sarray("b", "t"), varray());
+ bind_method(Vector3, slerp, sarray("b", "t"), varray());
+ bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Vector3, move_toward, sarray("to", "delta"), varray());
+ bind_method(Vector3, dot, sarray("with"), varray());
+ bind_method(Vector3, cross, sarray("with"), varray());
+ bind_method(Vector3, outer, sarray("with"), varray());
+ bind_method(Vector3, to_diagonal_matrix, sarray(), varray());
+ bind_method(Vector3, abs, sarray(), varray());
+ bind_method(Vector3, floor, sarray(), varray());
+ bind_method(Vector3, ceil, sarray(), varray());
+ bind_method(Vector3, round, sarray(), varray());
+ bind_method(Vector3, posmod, sarray("mod"), varray());
+ bind_method(Vector3, posmodv, sarray("modv"), varray());
+ bind_method(Vector3, project, sarray("b"), varray());
+ bind_method(Vector3, slide, sarray("n"), varray());
+ bind_method(Vector3, bounce, sarray("n"), varray());
+ bind_method(Vector3, reflect, sarray("n"), varray());
+ bind_method(Vector3, sign, sarray(), varray());
+
+ /* Vector3i */
+
+ bind_method(Vector3i, min_axis, sarray(), varray());
+ bind_method(Vector3i, max_axis, sarray(), varray());
+ bind_method(Vector3i, sign, sarray(), varray());
+ bind_method(Vector3i, abs, sarray(), varray());
+
+ /* Plane */
+
+ bind_method(Plane, normalized, sarray(), varray());
+ bind_method(Plane, center, sarray(), varray());
+ bind_method(Plane, is_equal_approx, sarray("to_plane"), varray());
+ bind_method(Plane, is_point_over, sarray("plane"), varray());
+ bind_method(Plane, distance_to, sarray("point"), varray());
+ bind_method(Plane, has_point, sarray("point", "epsilon"), varray(CMP_EPSILON));
+ bind_method(Plane, project, sarray("point"), varray());
+ bind_methodv("intersect_3", &Plane::intersect_3_bind, sarray("b", "c"), varray());
+ bind_methodv("intersects_ray", &Plane::intersects_ray_bind, sarray("from", "dir"), varray());
+ bind_methodv("intersects_segment", &Plane::intersects_segment_bind, sarray("from", "to"), varray());
+
+ /* Quaternion */
+
+ bind_method(Quat, length, sarray(), varray());
+ bind_method(Quat, length_squared, sarray(), varray());
+ bind_method(Quat, normalized, sarray(), varray());
+ bind_method(Quat, is_normalized, sarray(), varray());
+ bind_method(Quat, is_equal_approx, sarray("to"), varray());
+ bind_method(Quat, inverse, sarray(), varray());
+ bind_method(Quat, dot, sarray("with"), varray());
+ bind_method(Quat, xform, sarray("v3"), varray());
+ bind_method(Quat, slerp, sarray("b", "t"), varray());
+ bind_method(Quat, slerpni, sarray("b", "t"), varray());
+ bind_method(Quat, cubic_slerp, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Quat, get_euler, sarray(), varray());
+
+ //Quat is atomic, this should be done via construcror
+ //ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray());
+ //ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", FLOAT, "angle", varray());
+
+ /* Color */
+
+ bind_method(Color, to_argb32, sarray(), varray());
+ bind_method(Color, to_abgr32, sarray(), varray());
+ bind_method(Color, to_rgba32, sarray(), varray());
+ bind_method(Color, to_argb64, sarray(), varray());
+ bind_method(Color, to_abgr64, sarray(), varray());
+ bind_method(Color, to_rgba64, sarray(), varray());
+
+ bind_method(Color, inverted, sarray(), varray());
+ bind_method(Color, contrasted, sarray(), varray());
+ bind_method(Color, lerp, sarray("b", "t"), varray());
+ bind_method(Color, lightened, sarray("amount"), varray());
+ bind_method(Color, darkened, sarray("amount"), varray());
+ bind_method(Color, to_html, sarray("with_alpha"), varray(true));
+
+ //Color is immutable, need to probably find a way to do this via constructor
+ //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0));
+ bind_method(Color, is_equal_approx, sarray("to"), varray());
+
+ /* RID */
+
+ bind_method(RID, get_id, sarray(), varray());
+
+ /* NodePath */
+
+ bind_method(NodePath, is_absolute, sarray(), varray());
+ bind_method(NodePath, get_name_count, sarray(), varray());
+ bind_method(NodePath, get_name, sarray("idx"), varray());
+ bind_method(NodePath, get_subname_count, sarray(), varray());
+ bind_method(NodePath, get_subname, sarray("idx"), varray());
+ bind_method(NodePath, get_concatenated_subnames, sarray(), varray());
+ bind_method(NodePath, get_as_property_path, sarray(), varray());
+ bind_method(NodePath, is_empty, sarray(), varray());
+
+ /* Callable */
+
+ bind_method(Callable, is_null, sarray(), varray());
+ bind_method(Callable, is_custom, sarray(), varray());
+ bind_method(Callable, is_standard, sarray(), varray());
+ bind_method(Callable, get_object, sarray(), varray());
+ bind_method(Callable, get_object_id, sarray(), varray());
+ bind_method(Callable, get_method, sarray(), varray());
+ bind_method(Callable, hash, sarray(), varray());
+ bind_method(Callable, unbind, sarray("argcount"), varray());
+
+ //#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type)
+
+ bind_custom(Variant::CALLABLE, "call", _VariantCall::func_Callable_call, Variant::InternalMethod::FLAG_VARARGS | Variant::InternalMethod::FLAG_RETURNS_VARIANT, Vector<Variant::Type>(), Variant::NIL, sarray());
+ bind_custom(Variant::CALLABLE, "call_deferred", _VariantCall::func_Callable_call_deferred, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray());
+ bind_custom(Variant::CALLABLE, "bind", _VariantCall::func_Callable_bind, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::CALLABLE, sarray());
+
+ /* Signal */
+
+ bind_method(Signal, is_null, sarray(), varray());
+ bind_method(Signal, get_object, sarray(), varray());
+ bind_method(Signal, get_object_id, sarray(), varray());
+ bind_method(Signal, get_name, sarray(), varray());
+
+ bind_method(Signal, connect, sarray("callable", "binds", "flags"), varray(Array(), 0));
+ bind_method(Signal, disconnect, sarray("callable"), varray());
+ bind_method(Signal, is_connected, sarray("callable"), varray());
+ bind_method(Signal, get_connections, sarray(), varray());
+
+ bind_custom(Variant::SIGNAL, "emit", _VariantCall::func_Signal_emit, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray());
+
+ /* Transform2D */
+
+ bind_method(Transform2D, inverse, sarray(), varray());
+ bind_method(Transform2D, affine_inverse, sarray(), varray());
+ bind_method(Transform2D, get_rotation, sarray(), varray());
+ bind_method(Transform2D, get_origin, sarray(), varray());
+ bind_method(Transform2D, get_scale, sarray(), varray());
+ bind_method(Transform2D, orthonormalized, sarray(), varray());
+ bind_method(Transform2D, rotated, sarray("phi"), varray());
+ bind_method(Transform2D, scaled, sarray("scale"), varray());
+ bind_method(Transform2D, translated, sarray("offset"), varray());
+ //too complex to bind this, operator * should be used instead
+ //ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray());
+ //ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray());
+ bind_method(Transform2D, basis_xform, sarray("v"), varray());
+ bind_method(Transform2D, basis_xform_inv, sarray("v"), varray());
+ bind_method(Transform2D, interpolate_with, sarray("xform", "t"), varray());
+ bind_method(Transform2D, is_equal_approx, sarray("xform"), varray());
+
+ /* Basis */
+
+ bind_method(Basis, inverse, sarray(), varray());
+ bind_method(Basis, transposed, sarray(), varray());
+ bind_method(Basis, orthonormalized, sarray(), varray());
+ bind_method(Basis, determinant, sarray(), varray());
+ bind_methodv("rotated", static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray());
+ bind_method(Basis, scaled, sarray("scale"), varray());
+ bind_method(Basis, get_scale, sarray(), varray());
+ bind_method(Basis, get_euler, sarray(), varray());
+ bind_method(Basis, tdotx, sarray("with"), varray());
+ bind_method(Basis, tdoty, sarray("with"), varray());
+ bind_method(Basis, tdotz, sarray("with"), varray());
+ //use the operators instead
+ //ADDFUNC1R(BASIS, VECTOR3, Basis, xform, VECTOR3, "v", varray());
+ //ADDFUNC1R(BASIS, VECTOR3, Basis, xform_inv, VECTOR3, "v", varray());
+ bind_method(Basis, get_orthogonal_index, sarray(), varray());
+ bind_method(Basis, slerp, sarray("b", "t"), varray());
+ bind_method(Basis, is_equal_approx, sarray("b"), varray());
+ bind_method(Basis, get_rotation_quat, sarray(), varray());
+
+ /* AABB */
+
+ bind_method(::AABB, abs, sarray(), varray());
+ bind_method(::AABB, get_area, sarray(), varray());
+ bind_method(::AABB, has_no_area, sarray(), varray());
+ bind_method(::AABB, has_no_surface, sarray(), varray());
+ bind_method(::AABB, has_point, sarray("point"), varray());
+ bind_method(::AABB, is_equal_approx, sarray("aabb"), varray());
+ bind_method(::AABB, intersects, sarray("with"), varray());
+ bind_method(::AABB, encloses, sarray("with"), varray());
+ bind_method(::AABB, intersects_plane, sarray("plane"), varray());
+ bind_method(::AABB, intersection, sarray("with"), varray());
+ bind_method(::AABB, merge, sarray("with"), varray());
+ bind_method(::AABB, expand, sarray("to_point"), varray());
+ bind_method(::AABB, grow, sarray("by"), varray());
+ bind_method(::AABB, get_support, sarray("dir"), varray());
+ bind_method(::AABB, get_longest_axis, sarray(), varray());
+ bind_method(::AABB, get_longest_axis_index, sarray(), varray());
+ bind_method(::AABB, get_longest_axis_size, sarray(), varray());
+ bind_method(::AABB, get_shortest_axis, sarray(), varray());
+ bind_method(::AABB, get_shortest_axis_index, sarray(), varray());
+ bind_method(::AABB, get_shortest_axis_size, sarray(), varray());
+ bind_method(::AABB, get_endpoint, sarray("idx"), varray());
+ bind_methodv("intersects_segment", &AABB::intersects_segment_bind, sarray("from", "to"), varray());
+ bind_methodv("intersects_ray", &AABB::intersects_ray_bind, sarray("from", "dir"), varray());
+
+ /* Transform */
+
+ bind_method(Transform, inverse, sarray(), varray());
+ bind_method(Transform, affine_inverse, sarray(), varray());
+ bind_method(Transform, orthonormalized, sarray(), varray());
+ bind_method(Transform, rotated, sarray("axis", "phi"), varray());
+ bind_method(Transform, scaled, sarray("scale"), varray());
+ bind_method(Transform, translated, sarray("offset"), varray());
+ bind_method(Transform, looking_at, sarray("target", "up"), varray());
+ bind_method(Transform, interpolate_with, sarray("xform", "weight"), varray());
+ bind_method(Transform, is_equal_approx, sarray("xform"), varray());
+ //use the operators instead
+ //ADDFUNC1R(TRANSFORM, NIL, Transform, xform, NIL, "v", varray());
+ //ADDFUNC1R(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray());
+
+ /* Dictionary */
+
+ bind_method(Dictionary, size, sarray(), varray());
+ bind_method(Dictionary, empty, sarray(), varray());
+ bind_method(Dictionary, clear, sarray(), varray());
+ bind_method(Dictionary, has, sarray("key"), varray());
+ bind_method(Dictionary, has_all, sarray("keys"), varray());
+ bind_method(Dictionary, erase, sarray("key"), varray());
+ bind_method(Dictionary, hash, sarray(), varray());
+ bind_method(Dictionary, keys, sarray(), varray());
+ bind_method(Dictionary, values, sarray(), varray());
+ bind_method(Dictionary, duplicate, sarray("deep"), varray("true"));
+ bind_method(Dictionary, get, sarray("key", "default"), varray(Variant()));
+
+ /* Array */
+
+ bind_method(Array, size, sarray(), varray());
+ bind_method(Array, empty, sarray(), varray());
+ bind_method(Array, clear, sarray(), varray());
+ bind_method(Array, hash, sarray(), varray());
+ bind_method(Array, push_back, sarray("value"), varray());
+ bind_method(Array, push_front, sarray("value"), varray());
+ bind_method(Array, append, sarray("value"), varray());
+ bind_method(Array, resize, sarray("size"), varray());
+ bind_method(Array, insert, sarray("position", "value"), varray());
+ bind_method(Array, remove, sarray("position"), varray());
+ bind_method(Array, erase, sarray("value"), varray());
+ bind_method(Array, front, sarray(), varray());
+ bind_method(Array, back, sarray(), varray());
+ bind_method(Array, find, sarray("what", "from"), varray(0));
+ bind_method(Array, rfind, sarray("what", "from"), varray(-1));
+ bind_method(Array, find_last, sarray("value"), varray());
+ bind_method(Array, count, sarray("value"), varray());
+ bind_method(Array, has, sarray("value"), varray());
+ bind_method(Array, pop_back, sarray(), varray());
+ bind_method(Array, pop_front, sarray(), varray());
+ bind_method(Array, sort, sarray(), varray());
+ bind_method(Array, sort_custom, sarray("obj", "func"), varray());
+ bind_method(Array, shuffle, sarray(), varray());
+ bind_method(Array, bsearch, sarray("value", "before"), varray(true));
+ bind_method(Array, bsearch_custom, sarray("value", "obj", "func", "before"), varray(true));
+ bind_method(Array, invert, sarray(), varray());
+ bind_method(Array, duplicate, sarray("deep"), varray(true));
+ bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false));
+ bind_method(Array, max, sarray(), varray());
+ bind_method(Array, min, sarray(), varray());
+
+ /* Byte Array */
+ bind_method(PackedByteArray, size, sarray(), varray());
+ bind_method(PackedByteArray, empty, sarray(), varray());
+ bind_method(PackedByteArray, set, sarray("index", "value"), varray());
+ bind_method(PackedByteArray, push_back, sarray("value"), varray());
+ bind_method(PackedByteArray, append, sarray("value"), varray());
+ bind_method(PackedByteArray, append_array, sarray("array"), varray());
+ bind_method(PackedByteArray, remove, sarray("index"), varray());
+ bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedByteArray, resize, sarray("new_size"), varray());
+ bind_method(PackedByteArray, has, sarray("value"), varray());
+ bind_method(PackedByteArray, invert, sarray(), varray());
+ bind_method(PackedByteArray, subarray, sarray("from", "to"), varray());
+ bind_method(PackedByteArray, sort, sarray(), varray());
+
+ bind_function("get_string_from_ascii", _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
+ bind_function("get_string_from_utf8", _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
+ bind_function("get_string_from_utf16", _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray());
+ bind_function("get_string_from_utf32", _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray());
+ bind_function("hex_encode", _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray());
+ bind_function("compress", _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray());
+ bind_function("decompress", _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray());
+ bind_function("decompress_dynamic", _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray());
+
+ /* Int32 Array */
+
+ bind_method(PackedInt32Array, size, sarray(), varray());
+ bind_method(PackedInt32Array, empty, sarray(), varray());
+ bind_method(PackedInt32Array, set, sarray("index", "value"), varray());
+ bind_method(PackedInt32Array, push_back, sarray("value"), varray());
+ bind_method(PackedInt32Array, append, sarray("value"), varray());
+ bind_method(PackedInt32Array, append_array, sarray("array"), varray());
+ bind_method(PackedInt32Array, remove, sarray("index"), varray());
+ bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedInt32Array, resize, sarray("new_size"), varray());
+ bind_method(PackedInt32Array, has, sarray("value"), varray());
+ bind_method(PackedInt32Array, invert, sarray(), varray());
+ bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedInt32Array, to_byte_array, sarray(), varray());
+ bind_method(PackedInt32Array, sort, sarray(), varray());
+
+ /* Int64 Array */
+
+ bind_method(PackedInt64Array, size, sarray(), varray());
+ bind_method(PackedInt64Array, empty, sarray(), varray());
+ bind_method(PackedInt64Array, set, sarray("index", "value"), varray());
+ bind_method(PackedInt64Array, push_back, sarray("value"), varray());
+ bind_method(PackedInt64Array, append, sarray("value"), varray());
+ bind_method(PackedInt64Array, append_array, sarray("array"), varray());
+ bind_method(PackedInt64Array, remove, sarray("index"), varray());
+ bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedInt64Array, resize, sarray("new_size"), varray());
+ bind_method(PackedInt64Array, has, sarray("value"), varray());
+ bind_method(PackedInt64Array, invert, sarray(), varray());
+ bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedInt64Array, to_byte_array, sarray(), varray());
+ bind_method(PackedInt64Array, sort, sarray(), varray());
+
+ /* Float32 Array */
+
+ bind_method(PackedFloat32Array, size, sarray(), varray());
+ bind_method(PackedFloat32Array, empty, sarray(), varray());
+ bind_method(PackedFloat32Array, set, sarray("index", "value"), varray());
+ bind_method(PackedFloat32Array, push_back, sarray("value"), varray());
+ bind_method(PackedFloat32Array, append, sarray("value"), varray());
+ bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
+ bind_method(PackedFloat32Array, remove, sarray("index"), varray());
+ bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedFloat32Array, resize, sarray("new_size"), varray());
+ bind_method(PackedFloat32Array, has, sarray("value"), varray());
+ bind_method(PackedFloat32Array, invert, sarray(), varray());
+ bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedFloat32Array, to_byte_array, sarray(), varray());
+ bind_method(PackedFloat32Array, sort, sarray(), varray());
+
+ /* Float64 Array */
+
+ bind_method(PackedFloat64Array, size, sarray(), varray());
+ bind_method(PackedFloat64Array, empty, sarray(), varray());
+ bind_method(PackedFloat64Array, set, sarray("index", "value"), varray());
+ bind_method(PackedFloat64Array, push_back, sarray("value"), varray());
+ bind_method(PackedFloat64Array, append, sarray("value"), varray());
+ bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
+ bind_method(PackedFloat64Array, remove, sarray("index"), varray());
+ bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedFloat64Array, resize, sarray("new_size"), varray());
+ bind_method(PackedFloat64Array, has, sarray("value"), varray());
+ bind_method(PackedFloat64Array, invert, sarray(), varray());
+ bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedFloat64Array, to_byte_array, sarray(), varray());
+ bind_method(PackedFloat64Array, sort, sarray(), varray());
+
+ /* String Array */
+
+ bind_method(PackedStringArray, size, sarray(), varray());
+ bind_method(PackedStringArray, empty, sarray(), varray());
+ bind_method(PackedStringArray, set, sarray("index", "value"), varray());
+ bind_method(PackedStringArray, push_back, sarray("value"), varray());
+ bind_method(PackedStringArray, append, sarray("value"), varray());
+ bind_method(PackedStringArray, append_array, sarray("array"), varray());
+ bind_method(PackedStringArray, remove, sarray("index"), varray());
+ bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedStringArray, resize, sarray("new_size"), varray());
+ bind_method(PackedStringArray, has, sarray("value"), varray());
+ bind_method(PackedStringArray, invert, sarray(), varray());
+ bind_method(PackedStringArray, subarray, sarray("from", "to"), varray());
+ bind_method(PackedStringArray, to_byte_array, sarray(), varray());
+ bind_method(PackedStringArray, sort, sarray(), varray());
+
+ /* Vector2 Array */
+
+ bind_method(PackedVector2Array, size, sarray(), varray());
+ bind_method(PackedVector2Array, empty, sarray(), varray());
+ bind_method(PackedVector2Array, set, sarray("index", "value"), varray());
+ bind_method(PackedVector2Array, push_back, sarray("value"), varray());
+ bind_method(PackedVector2Array, append, sarray("value"), varray());
+ bind_method(PackedVector2Array, append_array, sarray("array"), varray());
+ bind_method(PackedVector2Array, remove, sarray("index"), varray());
+ bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
+ bind_method(PackedVector2Array, has, sarray("value"), varray());
+ bind_method(PackedVector2Array, invert, sarray(), varray());
+ bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedVector2Array, to_byte_array, sarray(), varray());
+
+ /* Vector3 Array */
+
+ bind_method(PackedVector3Array, size, sarray(), varray());
+ bind_method(PackedVector3Array, empty, sarray(), varray());
+ bind_method(PackedVector3Array, set, sarray("index", "value"), varray());
+ bind_method(PackedVector3Array, push_back, sarray("value"), varray());
+ bind_method(PackedVector3Array, append, sarray("value"), varray());
+ bind_method(PackedVector3Array, append_array, sarray("array"), varray());
+ bind_method(PackedVector3Array, remove, sarray("index"), varray());
+ bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
+ bind_method(PackedVector3Array, has, sarray("value"), varray());
+ bind_method(PackedVector3Array, invert, sarray(), varray());
+ bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray());
+ bind_method(PackedVector3Array, to_byte_array, sarray(), varray());
+
+ /* Color Array */
+
+ bind_method(PackedColorArray, size, sarray(), varray());
+ bind_method(PackedColorArray, empty, sarray(), varray());
+ bind_method(PackedColorArray, set, sarray("index", "value"), varray());
+ bind_method(PackedColorArray, push_back, sarray("value"), varray());
+ bind_method(PackedColorArray, append, sarray("value"), varray());
+ bind_method(PackedColorArray, append_array, sarray("array"), varray());
+ bind_method(PackedColorArray, remove, sarray("index"), varray());
+ bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedColorArray, resize, sarray("new_size"), varray());
+ bind_method(PackedColorArray, has, sarray("value"), varray());
+ bind_method(PackedColorArray, invert, sarray(), varray());
+ bind_method(PackedColorArray, subarray, sarray("from", "to"), varray());
+ bind_method(PackedColorArray, to_byte_array, sarray(), varray());
/* REGISTER CONSTRUCTORS */
@@ -2497,7 +2207,18 @@ void register_variant_methods() {
}
void unregister_variant_methods() {
- memdelete_arr(_VariantCall::type_funcs);
+ //clear methods
+ for (int i = 0; i < Variant::VARIANT_MAX; i++) {
+ for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[i].front(); E; E = E->next()) {
+ Variant::InternalMethod **m = _VariantCall::type_internal_methods[i].lookup_ptr(E->get());
+ if (*m) {
+ memdelete(*m);
+ }
+ }
+ }
+
+ memdelete_arr(_VariantCall::type_internal_methods);
+ memdelete_arr(_VariantCall::type_internal_method_names);
memdelete_arr(_VariantCall::construct_funcs);
memdelete_arr(_VariantCall::constant_data);
}
diff --git a/core/variant_internal.h b/core/variant_internal.h
index 0e0a1e398f..7893c6d382 100644
--- a/core/variant_internal.h
+++ b/core/variant_internal.h
@@ -113,6 +113,540 @@ public:
_FORCE_INLINE_ static const PackedVector3Array *get_vector3_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector3> *>(v->_data.packed_array)->array; }
_FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
_FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
+
+ _FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; }
+ _FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; }
+};
+
+template <class T>
+struct VariantGetInternalPtr {
+};
+
+template <>
+struct VariantGetInternalPtr<bool> {
+ static bool *get_ptr(Variant *v) { return VariantInternal::get_bool(v); }
+ static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<int8_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<uint8_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<int16_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<uint16_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<int32_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<uint32_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<int64_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<uint64_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<char32_t> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<ObjectID> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Error> {
+ static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
+ static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<float> {
+ static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); }
+ static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<double> {
+ static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); }
+ static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<String> {
+ static String *get_ptr(Variant *v) { return VariantInternal::get_string(v); }
+ static const String *get_ptr(const Variant *v) { return VariantInternal::get_string(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Vector2> {
+ static Vector2 *get_ptr(Variant *v) { return VariantInternal::get_vector2(v); }
+ static const Vector2 *get_ptr(const Variant *v) { return VariantInternal::get_vector2(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Vector2i> {
+ static Vector2i *get_ptr(Variant *v) { return VariantInternal::get_vector2i(v); }
+ static const Vector2i *get_ptr(const Variant *v) { return VariantInternal::get_vector2i(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Rect2> {
+ static Rect2 *get_ptr(Variant *v) { return VariantInternal::get_rect2(v); }
+ static const Rect2 *get_ptr(const Variant *v) { return VariantInternal::get_rect2(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Rect2i> {
+ static Rect2i *get_ptr(Variant *v) { return VariantInternal::get_rect2i(v); }
+ static const Rect2i *get_ptr(const Variant *v) { return VariantInternal::get_rect2i(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Vector3> {
+ static Vector3 *get_ptr(Variant *v) { return VariantInternal::get_vector3(v); }
+ static const Vector3 *get_ptr(const Variant *v) { return VariantInternal::get_vector3(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Vector3i> {
+ static Vector3i *get_ptr(Variant *v) { return VariantInternal::get_vector3i(v); }
+ static const Vector3i *get_ptr(const Variant *v) { return VariantInternal::get_vector3i(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Transform2D> {
+ static Transform2D *get_ptr(Variant *v) { return VariantInternal::get_transform2d(v); }
+ static const Transform2D *get_ptr(const Variant *v) { return VariantInternal::get_transform2d(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Transform> {
+ static Transform *get_ptr(Variant *v) { return VariantInternal::get_transform(v); }
+ static const Transform *get_ptr(const Variant *v) { return VariantInternal::get_transform(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Plane> {
+ static Plane *get_ptr(Variant *v) { return VariantInternal::get_plane(v); }
+ static const Plane *get_ptr(const Variant *v) { return VariantInternal::get_plane(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Quat> {
+ static Quat *get_ptr(Variant *v) { return VariantInternal::get_quat(v); }
+ static const Quat *get_ptr(const Variant *v) { return VariantInternal::get_quat(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<::AABB> {
+ static ::AABB *get_ptr(Variant *v) { return VariantInternal::get_aabb(v); }
+ static const ::AABB *get_ptr(const Variant *v) { return VariantInternal::get_aabb(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Basis> {
+ static Basis *get_ptr(Variant *v) { return VariantInternal::get_basis(v); }
+ static const Basis *get_ptr(const Variant *v) { return VariantInternal::get_basis(v); }
+};
+
+//
+
+template <>
+struct VariantGetInternalPtr<Color> {
+ static Color *get_ptr(Variant *v) { return VariantInternal::get_color(v); }
+ static const Color *get_ptr(const Variant *v) { return VariantInternal::get_color(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<StringName> {
+ static StringName *get_ptr(Variant *v) { return VariantInternal::get_string_name(v); }
+ static const StringName *get_ptr(const Variant *v) { return VariantInternal::get_string_name(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<NodePath> {
+ static NodePath *get_ptr(Variant *v) { return VariantInternal::get_node_path(v); }
+ static const NodePath *get_ptr(const Variant *v) { return VariantInternal::get_node_path(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<RID> {
+ static RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); }
+ static const RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Callable> {
+ static Callable *get_ptr(Variant *v) { return VariantInternal::get_callable(v); }
+ static const Callable *get_ptr(const Variant *v) { return VariantInternal::get_callable(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Signal> {
+ static Signal *get_ptr(Variant *v) { return VariantInternal::get_signal(v); }
+ static const Signal *get_ptr(const Variant *v) { return VariantInternal::get_signal(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Dictionary> {
+ static Dictionary *get_ptr(Variant *v) { return VariantInternal::get_dictionary(v); }
+ static const Dictionary *get_ptr(const Variant *v) { return VariantInternal::get_dictionary(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Array> {
+ static Array *get_ptr(Variant *v) { return VariantInternal::get_array(v); }
+ static const Array *get_ptr(const Variant *v) { return VariantInternal::get_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedByteArray> {
+ static PackedByteArray *get_ptr(Variant *v) { return VariantInternal::get_byte_array(v); }
+ static const PackedByteArray *get_ptr(const Variant *v) { return VariantInternal::get_byte_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedInt32Array> {
+ static PackedInt32Array *get_ptr(Variant *v) { return VariantInternal::get_int32_array(v); }
+ static const PackedInt32Array *get_ptr(const Variant *v) { return VariantInternal::get_int32_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedInt64Array> {
+ static PackedInt64Array *get_ptr(Variant *v) { return VariantInternal::get_int64_array(v); }
+ static const PackedInt64Array *get_ptr(const Variant *v) { return VariantInternal::get_int64_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedFloat32Array> {
+ static PackedFloat32Array *get_ptr(Variant *v) { return VariantInternal::get_float32_array(v); }
+ static const PackedFloat32Array *get_ptr(const Variant *v) { return VariantInternal::get_float32_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedFloat64Array> {
+ static PackedFloat64Array *get_ptr(Variant *v) { return VariantInternal::get_float64_array(v); }
+ static const PackedFloat64Array *get_ptr(const Variant *v) { return VariantInternal::get_float64_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedStringArray> {
+ static PackedStringArray *get_ptr(Variant *v) { return VariantInternal::get_string_array(v); }
+ static const PackedStringArray *get_ptr(const Variant *v) { return VariantInternal::get_string_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedVector2Array> {
+ static PackedVector2Array *get_ptr(Variant *v) { return VariantInternal::get_vector2_array(v); }
+ static const PackedVector2Array *get_ptr(const Variant *v) { return VariantInternal::get_vector2_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedVector3Array> {
+ static PackedVector3Array *get_ptr(Variant *v) { return VariantInternal::get_vector3_array(v); }
+ static const PackedVector3Array *get_ptr(const Variant *v) { return VariantInternal::get_vector3_array(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<PackedColorArray> {
+ static PackedColorArray *get_ptr(Variant *v) { return VariantInternal::get_color_array(v); }
+ static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); }
+};
+
+template <class T>
+struct VariantInternalAccessor {
+};
+
+template <>
+struct VariantInternalAccessor<bool> {
+ static _FORCE_INLINE_ bool get(const Variant *v) { return *VariantInternal::get_bool(v); }
+ static _FORCE_INLINE_ void set(Variant *v, bool p_value) { *VariantInternal::get_bool(v) = p_value; }
+};
+
+#define VARIANT_ACCESSOR_NUMBER(m_type) \
+ template <> \
+ struct VariantInternalAccessor<m_type> { \
+ static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type)*VariantInternal::get_int(v); } \
+ static _FORCE_INLINE_ void set(Variant *v, m_type p_value) { *VariantInternal::get_int(v) = p_value; } \
+ };
+
+VARIANT_ACCESSOR_NUMBER(int8_t)
+VARIANT_ACCESSOR_NUMBER(uint8_t)
+VARIANT_ACCESSOR_NUMBER(int16_t)
+VARIANT_ACCESSOR_NUMBER(uint16_t)
+VARIANT_ACCESSOR_NUMBER(int32_t)
+VARIANT_ACCESSOR_NUMBER(uint32_t)
+VARIANT_ACCESSOR_NUMBER(int64_t)
+VARIANT_ACCESSOR_NUMBER(uint64_t)
+VARIANT_ACCESSOR_NUMBER(char32_t)
+VARIANT_ACCESSOR_NUMBER(Error)
+VARIANT_ACCESSOR_NUMBER(Margin)
+
+template <>
+struct VariantInternalAccessor<ObjectID> {
+ static _FORCE_INLINE_ ObjectID get(const Variant *v) { return ObjectID(*VariantInternal::get_int(v)); }
+ static _FORCE_INLINE_ void set(Variant *v, ObjectID p_value) { *VariantInternal::get_int(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<float> {
+ static _FORCE_INLINE_ float get(const Variant *v) { return *VariantInternal::get_float(v); }
+ static _FORCE_INLINE_ void set(Variant *v, float p_value) { *VariantInternal::get_float(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<double> {
+ static _FORCE_INLINE_ double get(const Variant *v) { return *VariantInternal::get_float(v); }
+ static _FORCE_INLINE_ void set(Variant *v, double p_value) { *VariantInternal::get_float(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<String> {
+ static _FORCE_INLINE_ const String &get(const Variant *v) { return *VariantInternal::get_string(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const String &p_value) { *VariantInternal::get_string(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector2> {
+ static _FORCE_INLINE_ const Vector2 &get(const Variant *v) { return *VariantInternal::get_vector2(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector2 &p_value) { *VariantInternal::get_vector2(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector2i> {
+ static _FORCE_INLINE_ const Vector2i &get(const Variant *v) { return *VariantInternal::get_vector2i(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector2i &p_value) { *VariantInternal::get_vector2i(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Rect2> {
+ static _FORCE_INLINE_ const Rect2 &get(const Variant *v) { return *VariantInternal::get_rect2(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Rect2 &p_value) { *VariantInternal::get_rect2(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Rect2i> {
+ static _FORCE_INLINE_ const Rect2i &get(const Variant *v) { return *VariantInternal::get_rect2i(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Rect2i &p_value) { *VariantInternal::get_rect2i(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector3> {
+ static _FORCE_INLINE_ const Vector3 &get(const Variant *v) { return *VariantInternal::get_vector3(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector3 &p_value) { *VariantInternal::get_vector3(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector3i> {
+ static _FORCE_INLINE_ const Vector3i &get(const Variant *v) { return *VariantInternal::get_vector3i(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector3i &p_value) { *VariantInternal::get_vector3i(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Transform2D> {
+ static _FORCE_INLINE_ const Transform2D &get(const Variant *v) { return *VariantInternal::get_transform2d(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Transform2D &p_value) { *VariantInternal::get_transform2d(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Transform> {
+ static _FORCE_INLINE_ const Transform &get(const Variant *v) { return *VariantInternal::get_transform(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Transform &p_value) { *VariantInternal::get_transform(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Plane> {
+ static _FORCE_INLINE_ const Plane &get(const Variant *v) { return *VariantInternal::get_plane(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Plane &p_value) { *VariantInternal::get_plane(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Quat> {
+ static _FORCE_INLINE_ const Quat &get(const Variant *v) { return *VariantInternal::get_quat(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Quat &p_value) { *VariantInternal::get_quat(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<AABB> {
+ static _FORCE_INLINE_ const AABB &get(const Variant *v) { return *VariantInternal::get_aabb(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const AABB &p_value) { *VariantInternal::get_aabb(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Basis> {
+ static _FORCE_INLINE_ const Basis &get(const Variant *v) { return *VariantInternal::get_basis(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Basis &p_value) { *VariantInternal::get_basis(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Color> {
+ static _FORCE_INLINE_ const Color &get(const Variant *v) { return *VariantInternal::get_color(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Color &p_value) { *VariantInternal::get_color(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<StringName> {
+ static _FORCE_INLINE_ const StringName &get(const Variant *v) { return *VariantInternal::get_string_name(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const StringName &p_value) { *VariantInternal::get_string_name(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<NodePath> {
+ static _FORCE_INLINE_ const NodePath &get(const Variant *v) { return *VariantInternal::get_node_path(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const NodePath &p_value) { *VariantInternal::get_node_path(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<RID> {
+ static _FORCE_INLINE_ const RID &get(const Variant *v) { return *VariantInternal::get_rid(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const RID &p_value) { *VariantInternal::get_rid(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Callable> {
+ static _FORCE_INLINE_ const Callable &get(const Variant *v) { return *VariantInternal::get_callable(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Callable &p_value) { *VariantInternal::get_callable(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Signal> {
+ static _FORCE_INLINE_ const Signal &get(const Variant *v) { return *VariantInternal::get_signal(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Signal &p_value) { *VariantInternal::get_signal(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Dictionary> {
+ static _FORCE_INLINE_ const Dictionary &get(const Variant *v) { return *VariantInternal::get_dictionary(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Dictionary &p_value) { *VariantInternal::get_dictionary(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Array> {
+ static _FORCE_INLINE_ const Array &get(const Variant *v) { return *VariantInternal::get_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Array &p_value) { *VariantInternal::get_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedByteArray> {
+ static _FORCE_INLINE_ const PackedByteArray &get(const Variant *v) { return *VariantInternal::get_byte_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedByteArray &p_value) { *VariantInternal::get_byte_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedInt32Array> {
+ static _FORCE_INLINE_ const PackedInt32Array &get(const Variant *v) { return *VariantInternal::get_int32_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedInt32Array &p_value) { *VariantInternal::get_int32_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedInt64Array> {
+ static _FORCE_INLINE_ const PackedInt64Array &get(const Variant *v) { return *VariantInternal::get_int64_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedInt64Array &p_value) { *VariantInternal::get_int64_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedFloat32Array> {
+ static _FORCE_INLINE_ const PackedFloat32Array &get(const Variant *v) { return *VariantInternal::get_float32_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedFloat32Array &p_value) { *VariantInternal::get_float32_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedFloat64Array> {
+ static _FORCE_INLINE_ const PackedFloat64Array &get(const Variant *v) { return *VariantInternal::get_float64_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedFloat64Array &p_value) { *VariantInternal::get_float64_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedStringArray> {
+ static _FORCE_INLINE_ const PackedStringArray &get(const Variant *v) { return *VariantInternal::get_string_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedStringArray &p_value) { *VariantInternal::get_string_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedVector2Array> {
+ static _FORCE_INLINE_ const PackedVector2Array &get(const Variant *v) { return *VariantInternal::get_vector2_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedVector2Array &p_value) { *VariantInternal::get_vector2_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedVector3Array> {
+ static _FORCE_INLINE_ const PackedVector3Array &get(const Variant *v) { return *VariantInternal::get_vector3_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedVector3Array &p_value) { *VariantInternal::get_vector3_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<PackedColorArray> {
+ static _FORCE_INLINE_ const PackedColorArray &get(const Variant *v) { return *VariantInternal::get_color_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedColorArray &p_value) { *VariantInternal::get_color_array(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Object *> {
+ static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); }
+ static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { *VariantInternal::get_object(v) = const_cast<Object *>(p_value); }
+};
+
+template <>
+struct VariantInternalAccessor<Variant> {
+ static _FORCE_INLINE_ Variant &get(Variant *v) { return *v; }
+ static _FORCE_INLINE_ const Variant &get(const Variant *v) { return *v; }
+ static _FORCE_INLINE_ void set(Variant *v, const Variant &p_value) { *v = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector<Variant>> {
+ static _FORCE_INLINE_ Vector<Variant> get(const Variant *v) {
+ Vector<Variant> ret;
+ int s = VariantInternal::get_array(v)->size();
+ ret.resize(s);
+ for (int i = 0; i < s; i++) {
+ ret.write[i] = VariantInternal::get_array(v)->get(i);
+ }
+
+ return ret;
+ }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector<Variant> &p_value) {
+ int s = p_value.size();
+ VariantInternal::get_array(v)->resize(s);
+ for (int i = 0; i < s; i++) {
+ VariantInternal::get_array(v)->set(i, p_value[i]);
+ }
+ }
};
#endif // VARIANT_INTERNAL_H
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml
index ceef16f158..d34308501c 100644
--- a/doc/classes/Animation.xml
+++ b/doc/classes/Animation.xml
@@ -681,26 +681,26 @@
Returns the update mode of a value track.
</description>
</method>
- <method name="value_track_set_update_mode">
- <return type="void">
+ <method name="value_track_interpolate" qualifiers="const">
+ <return type="Variant">
</return>
<argument index="0" name="track_idx" type="int">
</argument>
- <argument index="1" name="mode" type="int" enum="Animation.UpdateMode">
+ <argument index="1" name="time_sec" type="float">
</argument>
<description>
- Sets the update mode (see [enum UpdateMode]) of a value track.
+ Returns the interpolated value at the given time (in seconds). The [code]track_idx[/code] must be the index of a value track.
</description>
</method>
- <method name="value_track_interpolate" qualifiers="const">
- <return type="float">
+ <method name="value_track_set_update_mode">
+ <return type="void">
</return>
<argument index="0" name="track_idx" type="int">
</argument>
- <argument index="1" name="time_sec" type="float">
+ <argument index="1" name="mode" type="int" enum="Animation.UpdateMode">
</argument>
<description>
- Returns the interpolated value at the given time (in seconds). The [code]track_idx[/code] must be the index of a value track.
+ Sets the update mode (see [enum UpdateMode]) of a value track.
</description>
</method>
</methods>
diff --git a/doc/classes/Area2D.xml b/doc/classes/Area2D.xml
index 4f8d102393..72c40478bb 100644
--- a/doc/classes/Area2D.xml
+++ b/doc/classes/Area2D.xml
@@ -91,7 +91,8 @@
</methods>
<members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="1.0">
- The rate at which objects stop spinning in this area. Represents the angular velocity lost per second. Values range from [code]0[/code] (no damping) to [code]1[/code] (full damping).
+ The rate at which objects stop spinning in this area. Represents the angular velocity lost per second.
+ See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping.
</member>
<member name="audio_bus_name" type="StringName" setter="set_audio_bus_name" getter="get_audio_bus_name" default="@&quot;Master&quot;">
The name of the area's audio bus.
@@ -118,7 +119,8 @@
The area's gravity vector (not normalized). If gravity is a point (see [member gravity_point]), this will be the point of attraction.
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.1">
- The rate at which objects stop moving in this area. Represents the linear velocity lost per second. Values range from [code]0[/code] (no damping) to [code]1[/code] (full damping).
+ The rate at which objects stop moving in this area. Represents the linear velocity lost per second.
+ See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping.
</member>
<member name="monitorable" type="bool" setter="set_monitorable" getter="is_monitorable" default="true">
If [code]true[/code], other monitoring areas can detect this area.
diff --git a/doc/classes/Area3D.xml b/doc/classes/Area3D.xml
index db1c96c8cb..92a8465762 100644
--- a/doc/classes/Area3D.xml
+++ b/doc/classes/Area3D.xml
@@ -89,7 +89,8 @@
</methods>
<members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="0.1">
- The rate at which objects stop spinning in this area. Represents the angular velocity lost per second. Values range from [code]0[/code] (no damping) to [code]1[/code] (full damping).
+ The rate at which objects stop spinning in this area. Represents the angular velocity lost per second.
+ See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping.
</member>
<member name="audio_bus_name" type="StringName" setter="set_audio_bus" getter="get_audio_bus" default="@&quot;Master&quot;">
The name of the area's audio bus.
@@ -116,7 +117,8 @@
The area's gravity vector (not normalized). If gravity is a point (see [member gravity_point]), this will be the point of attraction.
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.1">
- The rate at which objects stop moving in this area. Represents the linear velocity lost per second. Values range from [code]0[/code] (no damping) to [code]1[/code] (full damping).
+ The rate at which objects stop moving in this area. Represents the linear velocity lost per second.
+ See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping.
</member>
<member name="monitorable" type="bool" setter="set_monitorable" getter="is_monitorable" default="true">
If [code]true[/code], other monitoring areas can detect this area.
diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml
index 4edf69ccb2..dc834474ad 100644
--- a/doc/classes/ArrayMesh.xml
+++ b/doc/classes/ArrayMesh.xml
@@ -69,7 +69,6 @@
<argument index="2" name="blend_shapes" type="Array" default="[ ]">
</argument>
<argument index="3" name="lods" type="Dictionary" default="{
-
}">
</argument>
<argument index="4" name="compress_flags" type="int" default="31744">
diff --git a/doc/classes/BaseButton.xml b/doc/classes/BaseButton.xml
index bf4d9383ac..e3045f9611 100644
--- a/doc/classes/BaseButton.xml
+++ b/doc/classes/BaseButton.xml
@@ -51,9 +51,6 @@
<member name="disabled" type="bool" setter="set_disabled" getter="is_disabled" default="false">
If [code]true[/code], the button is in disabled state and can't be clicked or toggled.
</member>
- <member name="enabled_focus_mode" type="int" setter="set_enabled_focus_mode" getter="get_enabled_focus_mode" enum="Control.FocusMode" default="2">
- Focus access mode to use when switching between enabled/disabled (see [member Control.focus_mode] and [member disabled]).
- </member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="2" />
<member name="group" type="ButtonGroup" setter="set_button_group" getter="get_button_group">
[ButtonGroup] associated to the button.
diff --git a/doc/classes/Basis.xml b/doc/classes/Basis.xml
index faea2f78b8..42ca3ad24b 100644
--- a/doc/classes/Basis.xml
+++ b/doc/classes/Basis.xml
@@ -111,8 +111,6 @@
</return>
<argument index="0" name="b" type="Basis">
</argument>
- <argument index="1" name="epsilon" type="float" default="1e-05">
- </argument>
<description>
Returns [code]true[/code] if this basis and [code]b[/code] are approximately equal, by calling [code]is_equal_approx[/code] on each component.
</description>
diff --git a/doc/classes/Callable.xml b/doc/classes/Callable.xml
index 3bbee993ac..ad5c549fee 100644
--- a/doc/classes/Callable.xml
+++ b/doc/classes/Callable.xml
@@ -47,6 +47,12 @@
Creates a new [Callable] for the method called [code]method_name[/code] in the specified [code]object[/code].
</description>
</method>
+ <method name="bind" qualifiers="vararg">
+ <return type="void">
+ </return>
+ <description>
+ </description>
+ </method>
<method name="call" qualifiers="vararg">
<return type="Variant">
</return>
@@ -106,6 +112,14 @@
<description>
</description>
</method>
+ <method name="unbind">
+ <return type="Callable">
+ </return>
+ <argument index="0" name="argcount" type="int">
+ </argument>
+ <description>
+ </description>
+ </method>
</methods>
<constants>
</constants>
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index d36a997330..11000ce8d5 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -607,9 +607,6 @@
<member name="show_behind_parent" type="bool" setter="set_draw_behind_parent" getter="is_draw_behind_parent_enabled" default="false">
If [code]true[/code], the object draws behind its parent.
</member>
- <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level">
- If [code]true[/code], the node will not inherit its transform from parent [CanvasItem]s.
- </member>
<member name="show_on_top" type="bool" setter="_set_on_top" getter="_is_on_top">
If [code]true[/code], the object draws on top of its parent.
</member>
@@ -619,6 +616,9 @@
<member name="texture_repeat" type="int" setter="set_texture_repeat" getter="get_texture_repeat" enum="CanvasItem.TextureRepeat" default="0">
The texture repeating mode to use on this [CanvasItem].
</member>
+ <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level" default="false">
+ If [code]true[/code], the node will not inherit its transform from parent [CanvasItem]s.
+ </member>
<member name="use_parent_material" type="bool" setter="set_use_parent_material" getter="get_use_parent_material" default="false">
If [code]true[/code], the parent [CanvasItem]'s [member material] property is used as this one's material.
</member>
diff --git a/doc/classes/FuncRef.xml b/doc/classes/FuncRef.xml
index 7c01397c24..dc9246ad35 100644
--- a/doc/classes/FuncRef.xml
+++ b/doc/classes/FuncRef.xml
@@ -26,6 +26,13 @@
Calls the referenced function previously set in [member function] or [method @GDScript.funcref]. Contrarily to [method call_func], this method does not support a variable number of arguments but expects all parameters to be passed via a single [Array].
</description>
</method>
+ <method name="is_valid" qualifiers="const">
+ <return type="bool">
+ </return>
+ <description>
+ Returns whether the object still exists and has the function assigned.
+ </description>
+ </method>
<method name="set_instance">
<return type="void">
</return>
@@ -35,16 +42,9 @@
The object containing the referenced function. This object must be of a type actually inheriting from [Object], not a built-in type such as [int], [Vector2] or [Dictionary].
</description>
</method>
- <method name="is_valid" qualifiers="const">
- <return type="bool">
- </return>
- <description>
- Returns whether the object still exists and has the function assigned.
- </description>
- </method>
</methods>
<members>
- <member name="function" type="StringName" setter="set_function" getter="get_function">
+ <member name="function" type="StringName" setter="set_function" getter="get_function" default="@&quot;&quot;">
The name of the referenced function.
</member>
</members>
diff --git a/doc/classes/GPUParticles3D.xml b/doc/classes/GPUParticles3D.xml
index e840e457bf..d1296c3418 100644
--- a/doc/classes/GPUParticles3D.xml
+++ b/doc/classes/GPUParticles3D.xml
@@ -67,6 +67,8 @@
<member name="amount" type="int" setter="set_amount" getter="get_amount" default="8">
Number of particles to emit.
</member>
+ <member name="collision_base_size" type="float" setter="set_collision_base_size" getter="get_collision_base_size" default="0.01">
+ </member>
<member name="draw_order" type="int" setter="set_draw_order" getter="get_draw_order" enum="GPUParticles3D.DrawOrder" default="0">
Particle draw order. Uses [enum DrawOrder] values.
</member>
diff --git a/doc/classes/GPUParticlesAttractor3D.xml b/doc/classes/GPUParticlesAttractor3D.xml
new file mode 100644
index 0000000000..111827d294
--- /dev/null
+++ b/doc/classes/GPUParticlesAttractor3D.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesAttractor3D" inherits="VisualInstance3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="attenuation" type="float" setter="set_attenuation" getter="get_attenuation" default="1.0">
+ </member>
+ <member name="cull_mask" type="int" setter="set_cull_mask" getter="get_cull_mask" default="4294967295">
+ </member>
+ <member name="directionality" type="float" setter="set_directionality" getter="get_directionality" default="0.0">
+ </member>
+ <member name="strength" type="float" setter="set_strength" getter="get_strength" default="1.0">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesAttractorBox.xml b/doc/classes/GPUParticlesAttractorBox.xml
new file mode 100644
index 0000000000..68616f9bbd
--- /dev/null
+++ b/doc/classes/GPUParticlesAttractorBox.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesAttractorBox" inherits="GPUParticlesAttractor3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesAttractorSphere.xml b/doc/classes/GPUParticlesAttractorSphere.xml
new file mode 100644
index 0000000000..6984427a96
--- /dev/null
+++ b/doc/classes/GPUParticlesAttractorSphere.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesAttractorSphere" inherits="GPUParticlesAttractor3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesAttractorVectorField.xml b/doc/classes/GPUParticlesAttractorVectorField.xml
new file mode 100644
index 0000000000..cf5e375ea3
--- /dev/null
+++ b/doc/classes/GPUParticlesAttractorVectorField.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesAttractorVectorField" inherits="GPUParticlesAttractor3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
+ </member>
+ <member name="texture" type="Texture3D" setter="set_texture" getter="get_texture">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesCollision3D.xml b/doc/classes/GPUParticlesCollision3D.xml
new file mode 100644
index 0000000000..dce9a32fc4
--- /dev/null
+++ b/doc/classes/GPUParticlesCollision3D.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesCollision3D" inherits="VisualInstance3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="cull_mask" type="int" setter="set_cull_mask" getter="get_cull_mask" default="4294967295">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesCollisionBox.xml b/doc/classes/GPUParticlesCollisionBox.xml
new file mode 100644
index 0000000000..17fc124c41
--- /dev/null
+++ b/doc/classes/GPUParticlesCollisionBox.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesCollisionBox" inherits="GPUParticlesCollision3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesCollisionHeightField.xml b/doc/classes/GPUParticlesCollisionHeightField.xml
new file mode 100644
index 0000000000..c6987515a9
--- /dev/null
+++ b/doc/classes/GPUParticlesCollisionHeightField.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesCollisionHeightField" inherits="GPUParticlesCollision3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
+ </member>
+ <member name="follow_camera_enabled" type="bool" setter="set_follow_camera_mode" getter="is_follow_camera_mode_enabled" default="false">
+ </member>
+ <member name="follow_camera_push_ratio" type="float" setter="set_follow_camera_push_ratio" getter="get_follow_camera_push_ratio" default="0.1">
+ </member>
+ <member name="resolution" type="int" setter="set_resolution" getter="get_resolution" enum="GPUParticlesCollisionHeightField.Resolution" default="2">
+ </member>
+ <member name="update_mode" type="int" setter="set_update_mode" getter="get_update_mode" enum="GPUParticlesCollisionHeightField.UpdateMode" default="0">
+ </member>
+ </members>
+ <constants>
+ <constant name="RESOLUTION_256" value="0" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_512" value="1" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_1024" value="2" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_2048" value="3" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_4096" value="4" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_8192" value="5" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_MAX" value="6" enum="Resolution">
+ </constant>
+ <constant name="UPDATE_MODE_WHEN_MOVED" value="0" enum="UpdateMode">
+ </constant>
+ <constant name="UPDATE_MODE_ALWAYS" value="1" enum="UpdateMode">
+ </constant>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesCollisionSDF.xml b/doc/classes/GPUParticlesCollisionSDF.xml
new file mode 100644
index 0000000000..c3cbe4b1c6
--- /dev/null
+++ b/doc/classes/GPUParticlesCollisionSDF.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesCollisionSDF" inherits="GPUParticlesCollision3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 1, 1, 1 )">
+ </member>
+ <member name="resolution" type="int" setter="set_resolution" getter="get_resolution" enum="GPUParticlesCollisionSDF.Resolution" default="2">
+ </member>
+ <member name="texture" type="Texture3D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="thickness" type="float" setter="set_thickness" getter="get_thickness" default="1.0">
+ </member>
+ </members>
+ <constants>
+ <constant name="RESOLUTION_16" value="0" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_32" value="1" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_64" value="2" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_128" value="3" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_256" value="4" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_512" value="5" enum="Resolution">
+ </constant>
+ <constant name="RESOLUTION_MAX" value="6" enum="Resolution">
+ </constant>
+ </constants>
+</class>
diff --git a/doc/classes/GPUParticlesCollisionSphere.xml b/doc/classes/GPUParticlesCollisionSphere.xml
new file mode 100644
index 0000000000..41150960d2
--- /dev/null
+++ b/doc/classes/GPUParticlesCollisionSphere.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="GPUParticlesCollisionSphere" inherits="GPUParticlesCollision3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/Geometry3D.xml b/doc/classes/Geometry3D.xml
index ec685a5ce7..d0b930defb 100644
--- a/doc/classes/Geometry3D.xml
+++ b/doc/classes/Geometry3D.xml
@@ -102,15 +102,6 @@
Given the two 3D segments ([code]p1[/code], [code]p2[/code]) and ([code]q1[/code], [code]q2[/code]), finds those two points on the two segments that are closest to each other. Returns a [PackedVector3Array] that contains this point on ([code]p1[/code], [code]p2[/code]) as well the accompanying point on ([code]q1[/code], [code]q2[/code]).
</description>
</method>
- <method name="get_uv84_normal_bit">
- <return type="int">
- </return>
- <argument index="0" name="normal" type="Vector3">
- </argument>
- <description>
- Used internally by the engine.
- </description>
- </method>
<method name="ray_intersects_triangle">
<return type="Variant">
</return>
diff --git a/doc/classes/KinematicBody2D.xml b/doc/classes/KinematicBody2D.xml
index 17c4b85346..425df00b6f 100644
--- a/doc/classes/KinematicBody2D.xml
+++ b/doc/classes/KinematicBody2D.xml
@@ -55,21 +55,21 @@
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on the ceiling. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with the ceiling on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="is_on_floor" qualifiers="const">
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on the floor. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with the floor on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="is_on_wall" qualifiers="const">
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on a wall. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with a wall on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="move_and_collide">
diff --git a/doc/classes/KinematicBody3D.xml b/doc/classes/KinematicBody3D.xml
index 17a6034e9a..a21496de54 100644
--- a/doc/classes/KinematicBody3D.xml
+++ b/doc/classes/KinematicBody3D.xml
@@ -59,21 +59,21 @@
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on the ceiling. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with the ceiling on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="is_on_floor" qualifiers="const">
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on the floor. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with the floor on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="is_on_wall" qualifiers="const">
<return type="bool">
</return>
<description>
- Returns [code]true[/code] if the body is on a wall. Only updates when calling [method move_and_slide] or [method move_and_slide_with_snap].
+ Returns [code]true[/code] if the body collided with a wall on the last call of [method move_and_slide] or [method move_and_slide_with_snap]. Otherwise, returns [code]false[/code].
</description>
</method>
<method name="move_and_collide">
diff --git a/doc/classes/LinkButton.xml b/doc/classes/LinkButton.xml
index fed936cc2f..2d475fc449 100644
--- a/doc/classes/LinkButton.xml
+++ b/doc/classes/LinkButton.xml
@@ -12,7 +12,6 @@
<methods>
</methods>
<members>
- <member name="enabled_focus_mode" type="int" setter="set_enabled_focus_mode" getter="get_enabled_focus_mode" override="true" enum="Control.FocusMode" default="0" />
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="0" />
<member name="mouse_default_cursor_shape" type="int" setter="set_default_cursor_shape" getter="get_default_cursor_shape" override="true" enum="Control.CursorShape" default="2" />
<member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
diff --git a/doc/classes/MenuButton.xml b/doc/classes/MenuButton.xml
index cf1fdb5ba6..d97e0f0f21 100644
--- a/doc/classes/MenuButton.xml
+++ b/doc/classes/MenuButton.xml
@@ -30,7 +30,6 @@
</methods>
<members>
<member name="action_mode" type="int" setter="set_action_mode" getter="get_action_mode" override="true" enum="BaseButton.ActionMode" default="0" />
- <member name="enabled_focus_mode" type="int" setter="set_enabled_focus_mode" getter="get_enabled_focus_mode" override="true" enum="Control.FocusMode" default="0" />
<member name="flat" type="bool" setter="set_flat" getter="is_flat" override="true" default="true" />
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="0" />
<member name="switch_on_hover" type="bool" setter="set_switch_on_hover" getter="is_switch_on_hover" default="false">
diff --git a/doc/classes/MultiMesh.xml b/doc/classes/MultiMesh.xml
index e1b3ffa2e4..6ebfc946dc 100644
--- a/doc/classes/MultiMesh.xml
+++ b/doc/classes/MultiMesh.xml
@@ -65,7 +65,7 @@
<argument index="1" name="color" type="Color">
</argument>
<description>
- Sets the color of a specific instance.
+ Sets the color of a specific instance by [i]multiplying[/i] the mesh's existing vertex colors.
For the color to take effect, ensure that [member use_colors] is [code]true[/code] on the [MultiMesh] and [member BaseMaterial3D.vertex_color_use_as_albedo] is [code]true[/code] on the material.
</description>
</method>
diff --git a/doc/classes/Node3D.xml b/doc/classes/Node3D.xml
index af4f18c5f7..f6ff514474 100644
--- a/doc/classes/Node3D.xml
+++ b/doc/classes/Node3D.xml
@@ -301,7 +301,7 @@
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3( 1, 1, 1 )">
Scale part of the local transformation.
</member>
- <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level">
+ <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level" default="false">
If [code]true[/code], the node will not inherit its transformations from its parent. Node transformations are only in global space.
</member>
<member name="transform" type="Transform" setter="set_transform" getter="get_transform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
diff --git a/doc/classes/ParticlesMaterial.xml b/doc/classes/ParticlesMaterial.xml
index f6fa3cf38b..77df6245e9 100644
--- a/doc/classes/ParticlesMaterial.xml
+++ b/doc/classes/ParticlesMaterial.xml
@@ -131,6 +131,16 @@
<member name="anim_speed_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
Animation speed randomness ratio.
</member>
+ <member name="attractor_interaction_enabled" type="bool" setter="set_attractor_interaction_enabled" getter="is_attractor_interaction_enabled" default="true">
+ </member>
+ <member name="collision_bounce" type="float" setter="set_collision_bounce" getter="get_collision_bounce" default="0.0">
+ </member>
+ <member name="collision_enabled" type="bool" setter="set_collision_enabled" getter="is_collision_enabled" default="true">
+ </member>
+ <member name="collision_friction" type="float" setter="set_collision_friction" getter="get_collision_friction" default="0.0">
+ </member>
+ <member name="collision_use_scale" type="bool" setter="set_collision_use_scale" getter="is_collision_using_scale" default="false">
+ </member>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
Each particle's initial color. If the [GPUParticles2D]'s [code]texture[/code] is defined, it will be multiplied by this color. To have particle display color in a [BaseMaterial3D] make sure to set [member BaseMaterial3D.vertex_color_use_as_albedo] to [code]true[/code].
</member>
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 54c337faf9..91998ead34 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -469,7 +469,7 @@
[b]Note:[/b] This option is experimental and meant to alleviate stutter experienced by some users. However, some users have experienced a Vsync framerate halving (e.g. from 60 FPS to 30 FPS) when using it.
</member>
<member name="editor/script_templates_search_path" type="String" setter="" getter="" default="&quot;res://script_templates&quot;">
- Search path for project-specific script templates. Script templates will be search both in the editor-specific path and in this project-specific path.
+ Search path for project-specific script templates. Godot will search for script templates both in the editor-specific path and in this project-specific path.
</member>
<member name="editor/search_in_file_extensions" type="PackedStringArray" setter="" getter="" default="PackedStringArray( &quot;gd&quot;, &quot;shader&quot; )">
Text-based file extensions to include in the script editor's "Find in Files" feature. You can add e.g. [code]tscn[/code] if you wish to also parse your scene files, especially if you use built-in scripts which are serialized in the scene files.
@@ -558,7 +558,7 @@
<member name="input_devices/pointing/emulate_touch_from_mouse" type="bool" setter="" getter="" default="false">
If [code]true[/code], sends touch input events when clicking or dragging the mouse.
</member>
- <member name="input_devices/pointing/ios/touch_delay" type="float" setter="" getter="" default="0.150">
+ <member name="input_devices/pointing/ios/touch_delay" type="float" setter="" getter="" default="0.15">
Default delay for touch events. This only affects iOS devices.
</member>
<member name="layer_names/2d_physics/layer_1" type="String" setter="" getter="" default="&quot;&quot;">
@@ -818,7 +818,7 @@
<member name="logging/file_logging/max_log_files" type="int" setter="" getter="" default="5">
Specifies the maximum amount of log files allowed (used for rotation).
</member>
- <member name="memory/limits/message_queue/max_size_kb" type="int" setter="" getter="" default="1024">
+ <member name="memory/limits/message_queue/max_size_kb" type="int" setter="" getter="" default="4096">
Godot uses a message queue to defer some function calls. If you run out of space on it (you will see an error), you can increase the size here.
</member>
<member name="memory/limits/multithreaded_server/rid_pool_prealloc" type="int" setter="" getter="" default="60">
@@ -883,6 +883,7 @@
</member>
<member name="physics/2d/default_angular_damp" type="float" setter="" getter="" default="1.0">
The default angular damp in 2D.
+ [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_fps], [code]60[/code] by default) will bring the object to a stop in one iteration.
</member>
<member name="physics/2d/default_gravity" type="int" setter="" getter="" default="98">
The default gravity strength in 2D.
@@ -902,6 +903,7 @@
</member>
<member name="physics/2d/default_linear_damp" type="float" setter="" getter="" default="0.1">
The default linear damp in 2D.
+ [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_fps], [code]60[/code] by default) will bring the object to a stop in one iteration.
</member>
<member name="physics/2d/large_object_surface_threshold_in_cells" type="int" setter="" getter="" default="512">
Threshold defining the surface size that constitutes a large object with regard to cells in the broad-phase 2D hash grid algorithm.
@@ -928,6 +930,7 @@
</member>
<member name="physics/3d/default_angular_damp" type="float" setter="" getter="" default="0.1">
The default angular damp in 3D.
+ [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_fps], [code]60[/code] by default) will bring the object to a stop in one iteration.
</member>
<member name="physics/3d/default_gravity" type="float" setter="" getter="" default="9.8">
The default gravity strength in 3D.
@@ -947,6 +950,7 @@
</member>
<member name="physics/3d/default_linear_damp" type="float" setter="" getter="" default="0.1">
The default linear damp in 3D.
+ [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_fps], [code]60[/code] by default) will bring the object to a stop in one iteration.
</member>
<member name="physics/3d/physics_engine" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
Sets which physics engine to use for 3D physics.
diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml
index ec0f1a96b2..d4f9517dd1 100644
--- a/doc/classes/RandomNumberGenerator.xml
+++ b/doc/classes/RandomNumberGenerator.xml
@@ -15,6 +15,7 @@
[/codeblock]
</description>
<tutorials>
+ <link title="Random number generation">https://docs.godotengine.org/en/latest/tutorials/math/random_number_generation.html</link>
</tutorials>
<methods>
<method name="randf">
diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml
index 9c8c964967..456022a626 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -583,6 +583,12 @@
Modulates all colors in the given canvas.
</description>
</method>
+ <method name="create_local_rendering_device" qualifiers="const">
+ <return type="RenderingDevice">
+ </return>
+ <description>
+ </description>
+ </method>
<method name="directional_light_create">
<return type="RID">
</return>
@@ -1627,7 +1633,6 @@
<argument index="3" name="blend_shapes" type="Array" default="[ ]">
</argument>
<argument index="4" name="lods" type="Dictionary" default="{
-
}">
</argument>
<argument index="5" name="compress_format" type="int" default="31744">
@@ -3574,22 +3579,24 @@
<constant name="INSTANCE_PARTICLES" value="4" enum="InstanceType">
The instance is a particle emitter.
</constant>
- <constant name="INSTANCE_LIGHT" value="5" enum="InstanceType">
+ <constant name="INSTANCE_PARTICLES_COLLISION" value="5" enum="InstanceType">
+ </constant>
+ <constant name="INSTANCE_LIGHT" value="6" enum="InstanceType">
The instance is a light.
</constant>
- <constant name="INSTANCE_REFLECTION_PROBE" value="6" enum="InstanceType">
+ <constant name="INSTANCE_REFLECTION_PROBE" value="7" enum="InstanceType">
The instance is a reflection probe.
</constant>
- <constant name="INSTANCE_DECAL" value="7" enum="InstanceType">
+ <constant name="INSTANCE_DECAL" value="8" enum="InstanceType">
The instance is a decal.
</constant>
- <constant name="INSTANCE_GI_PROBE" value="8" enum="InstanceType">
+ <constant name="INSTANCE_GI_PROBE" value="9" enum="InstanceType">
The instance is a GI probe.
</constant>
- <constant name="INSTANCE_LIGHTMAP" value="9" enum="InstanceType">
+ <constant name="INSTANCE_LIGHTMAP" value="10" enum="InstanceType">
The instance is a lightmap.
</constant>
- <constant name="INSTANCE_MAX" value="10" enum="InstanceType">
+ <constant name="INSTANCE_MAX" value="11" enum="InstanceType">
Represents the size of the [enum InstanceType] enum.
</constant>
<constant name="INSTANCE_GEOMETRY_MASK" value="30" enum="InstanceType">
diff --git a/doc/classes/RigidBody2D.xml b/doc/classes/RigidBody2D.xml
index eca5b8054d..6f41d5ba27 100644
--- a/doc/classes/RigidBody2D.xml
+++ b/doc/classes/RigidBody2D.xml
@@ -119,6 +119,7 @@
<members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0">
Damps the body's [member angular_velocity]. If [code]-1[/code], the body will use the [b]Default Angular Damp[/b] defined in [b]Project &gt; Project Settings &gt; Physics &gt; 2d[/b].
+ See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping.
</member>
<member name="angular_velocity" type="float" setter="set_angular_velocity" getter="get_angular_velocity" default="0.0">
The body's rotational velocity.
@@ -155,6 +156,7 @@
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0">
Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 2d[/b].
+ See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping.
</member>
<member name="linear_velocity" type="Vector2" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector2( 0, 0 )">
The body's linear velocity.
diff --git a/doc/classes/RigidBody3D.xml b/doc/classes/RigidBody3D.xml
index 8d92c8b066..f8dc9887a9 100644
--- a/doc/classes/RigidBody3D.xml
+++ b/doc/classes/RigidBody3D.xml
@@ -134,6 +134,7 @@
<members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0">
Damps RigidBody3D's rotational forces.
+ See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping.
</member>
<member name="angular_velocity" type="Vector3" setter="set_angular_velocity" getter="get_angular_velocity" default="Vector3( 0, 0, 0 )">
RigidBody3D's rotational velocity.
@@ -179,6 +180,7 @@
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0">
The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0, any linear damp derived from the world or areas will be overridden.
+ See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping.
</member>
<member name="linear_velocity" type="Vector3" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector3( 0, 0, 0 )">
The body's linear velocity. Can be used sporadically, but [b]don't set this every frame[/b], because physics may run in another thread and runs at a different granularity. Use [method _integrate_forces] as your process loop for precise control of the body state.
diff --git a/doc/classes/VisualShaderNode.xml b/doc/classes/VisualShaderNode.xml
index 3bb527f3d4..6327ab534f 100644
--- a/doc/classes/VisualShaderNode.xml
+++ b/doc/classes/VisualShaderNode.xml
@@ -57,12 +57,6 @@
Emitted when the node requests an editor refresh. Currently called only in setter of [member VisualShaderNodeTexture.source], [VisualShaderNodeTexture], and [VisualShaderNodeCubemap] (and their derivatives).
</description>
</signal>
- <signal name="show_port_preview">
- <argument index="0" name="port_id" type="int">
- </argument>
- <description>
- </description>
- </signal>
</signals>
<constants>
<constant name="PORT_TYPE_SCALAR" value="0" enum="PortType">
diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h
index bdb51b1573..1df26756c2 100644
--- a/drivers/dummy/rasterizer_dummy.h
+++ b/drivers/dummy/rasterizer_dummy.h
@@ -154,6 +154,7 @@ public:
void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) override {}
void render_sdfgi(RID p_render_buffers, int p_region, InstanceBase **p_cull_result, int p_cull_count) override {}
void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const RID **p_positional_light_cull_result, const uint32_t *p_positional_light_cull_count) override {}
+ void render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, InstanceBase **p_cull_result, int p_cull_count) override {}
void set_scene_pass(uint64_t p_pass) override {}
void set_time(double p_time, double p_step) override {}
@@ -802,6 +803,7 @@ public:
void particles_set_fractional_delta(RID p_particles, bool p_enable) override {}
void particles_set_subemitter(RID p_particles, RID p_subemitter_particles) override {}
void particles_set_view_axis(RID p_particles, const Vector3 &p_axis) override {}
+ void particles_set_collision_base_size(RID p_particles, float p_size) override {}
void particles_restart(RID p_particles) override {}
void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) override {}
@@ -819,6 +821,28 @@ public:
int particles_get_draw_passes(RID p_particles) const override { return 0; }
RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const override { return RID(); }
+ void particles_add_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) override {}
+ void particles_remove_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) override {}
+
+ void update_particles() override {}
+
+ /* PARTICLES COLLISION */
+
+ RID particles_collision_create() override { return RID(); }
+ void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) override {}
+ void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) override {}
+ void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius) override {}
+ void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) override {}
+ void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength) override {}
+ void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality) override {}
+ void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve) override {}
+ void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) override {}
+ void particles_collision_height_field_update(RID p_particles_collision) override {}
+ void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) override {}
+ AABB particles_collision_get_aabb(RID p_particles_collision) const override { return AABB(); }
+ bool particles_collision_is_heightfield(RID p_particles_collision) const override { return false; }
+ RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const override { return RID(); }
+
/* GLOBAL VARIABLES */
void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) override {}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 8edda3123b..a6321ce058 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -128,6 +128,7 @@
#include "editor/plugins/gi_probe_editor_plugin.h"
#include "editor/plugins/gpu_particles_2d_editor_plugin.h"
#include "editor/plugins/gpu_particles_3d_editor_plugin.h"
+#include "editor/plugins/gpu_particles_collision_sdf_editor_plugin.h"
#include "editor/plugins/gradient_editor_plugin.h"
#include "editor/plugins/item_list_editor_plugin.h"
#include "editor/plugins/light_occluder_2d_editor_plugin.h"
@@ -5121,7 +5122,6 @@ void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) {
void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, String to_path) {
DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- Vector<String> just_copy = String("ttf,otf").split(",");
for (int i = 0; i < p_files.size(); i++) {
String from = p_files[i];
@@ -5152,9 +5152,6 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str
continue;
}
- if (!ResourceFormatImporter::get_singleton()->can_be_imported(from) && (just_copy.find(from.get_extension().to_lower()) == -1)) {
- continue;
- }
dir->copy(from, to);
}
}
@@ -6635,6 +6632,7 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(PhysicalBone3DEditorPlugin(this)));
add_editor_plugin(memnew(MeshEditorPlugin(this)));
add_editor_plugin(memnew(MaterialEditorPlugin(this)));
+ add_editor_plugin(memnew(GPUParticlesCollisionSDFEditorPlugin(this)));
for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) {
add_editor_plugin(EditorPlugins::create(i, this));
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 4c8af615b4..9e68ef2f35 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -614,7 +614,7 @@ public:
const Ref<InputEventMouseButton> mb = p_ev;
- if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed() && hovered_index > 0) {
// Toggle the flag.
// We base our choice on the hovered flag, so that it always matches the hovered flag.
if (value & (1 << hovered_index)) {
diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp
index 422534a2e1..639da371bd 100644
--- a/editor/editor_run_native.cpp
+++ b/editor/editor_run_native.cpp
@@ -76,8 +76,10 @@ void EditorRunNative::_notification(int p_what) {
} else {
mb->get_popup()->clear();
mb->show();
- mb->set_tooltip(eep->get_options_tooltip());
- if (dc > 1) {
+ if (dc == 1) {
+ mb->set_tooltip(eep->get_option_tooltip(0));
+ } else {
+ mb->set_tooltip(eep->get_options_tooltip());
for (int i = 0; i < dc; i++) {
mb->get_popup()->add_icon_item(eep->get_option_icon(i), eep->get_option_label(i));
mb->get_popup()->set_item_tooltip(mb->get_popup()->get_item_count() - 1, eep->get_option_tooltip(i));
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index bbf62596d0..ac068c05cf 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -51,7 +51,7 @@ String ResourceImporterLayeredTexture::get_importer_name() const {
return "cubemap_array_texture";
} break;
case MODE_3D: {
- return "cubemap_3d_texture";
+ return "3d_texture";
} break;
}
diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp
index 6764f70d9b..e4562c57af 100644
--- a/editor/localization_editor.cpp
+++ b/editor/localization_editor.cpp
@@ -319,7 +319,7 @@ void LocalizationEditor::_translation_filter_option_changed() {
}
}
- f_locales = f_locales.sort();
+ f_locales.sort();
undo_redo->create_action(TTR("Changed Locale Filter"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/locale_filter", f_locales_all);
diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp
index 6e5fb6389d..397a958d8f 100644
--- a/editor/node_3d_editor_gizmos.cpp
+++ b/editor/node_3d_editor_gizmos.cpp
@@ -41,6 +41,7 @@
#include "scene/3d/decal.h"
#include "scene/3d/gi_probe.h"
#include "scene/3d/gpu_particles_3d.h"
+#include "scene/3d/gpu_particles_collision_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/lightmap_probe.h"
#include "scene/3d/listener_3d.h"
@@ -2455,6 +2456,266 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
////
+////
+
+GPUParticlesCollision3DGizmoPlugin::GPUParticlesCollision3DGizmoPlugin() {
+ Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1));
+ create_material("shape_material", gizmo_color);
+ gizmo_color.a = 0.15;
+ create_material("shape_material_internal", gizmo_color);
+
+ create_handle_material("handles");
+}
+
+bool GPUParticlesCollision3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
+ return (Object::cast_to<GPUParticlesCollision3D>(p_spatial) != nullptr) || (Object::cast_to<GPUParticlesAttractor3D>(p_spatial) != nullptr);
+}
+
+String GPUParticlesCollision3DGizmoPlugin::get_name() const {
+ return "GPUParticlesCollision3D";
+}
+
+int GPUParticlesCollision3DGizmoPlugin::get_priority() const {
+ return -1;
+}
+
+String GPUParticlesCollision3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
+ const Node3D *cs = p_gizmo->get_spatial_node();
+
+ if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
+ return "Radius";
+ }
+
+ if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
+ return "Extents";
+ }
+
+ return "";
+}
+
+Variant GPUParticlesCollision3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
+ const Node3D *cs = p_gizmo->get_spatial_node();
+
+ if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
+ return p_gizmo->get_spatial_node()->call("get_radius");
+ }
+
+ if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
+ return Vector3(p_gizmo->get_spatial_node()->call("get_extents"));
+ }
+
+ return Variant();
+}
+
+void GPUParticlesCollision3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
+ Node3D *sn = p_gizmo->get_spatial_node();
+
+ Transform gt = sn->get_global_transform();
+ Transform gi = gt.affine_inverse();
+
+ Vector3 ray_from = p_camera->project_ray_origin(p_point);
+ Vector3 ray_dir = p_camera->project_ray_normal(p_point);
+
+ Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
+
+ if (Object::cast_to<GPUParticlesCollisionSphere>(sn) || Object::cast_to<GPUParticlesAttractorSphere>(sn)) {
+ Vector3 ra, rb;
+ Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
+ float d = ra.x;
+ if (Node3DEditor::get_singleton()->is_snap_enabled()) {
+ d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
+ }
+
+ if (d < 0.001) {
+ d = 0.001;
+ }
+
+ sn->call("set_radius", d);
+ }
+
+ if (Object::cast_to<GPUParticlesCollisionBox>(sn) || Object::cast_to<GPUParticlesAttractorBox>(sn) || Object::cast_to<GPUParticlesAttractorVectorField>(sn) || Object::cast_to<GPUParticlesCollisionSDF>(sn) || Object::cast_to<GPUParticlesCollisionHeightField>(sn)) {
+ Vector3 axis;
+ axis[p_idx] = 1.0;
+ Vector3 ra, rb;
+ Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
+ float d = ra[p_idx];
+ if (Node3DEditor::get_singleton()->is_snap_enabled()) {
+ d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
+ }
+
+ if (d < 0.001) {
+ d = 0.001;
+ }
+
+ Vector3 he = sn->call("get_extents");
+ he[p_idx] = d;
+ sn->call("set_extents", he);
+ }
+}
+
+void GPUParticlesCollision3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
+ Node3D *sn = p_gizmo->get_spatial_node();
+
+ if (Object::cast_to<GPUParticlesCollisionSphere>(sn) || Object::cast_to<GPUParticlesAttractorSphere>(sn)) {
+ if (p_cancel) {
+ sn->call("set_radius", p_restore);
+ return;
+ }
+
+ UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Change Radius"));
+ ur->add_do_method(sn, "set_radius", sn->call("get_radius"));
+ ur->add_undo_method(sn, "set_radius", p_restore);
+ ur->commit_action();
+ }
+
+ if (Object::cast_to<GPUParticlesCollisionBox>(sn) || Object::cast_to<GPUParticlesAttractorBox>(sn) || Object::cast_to<GPUParticlesAttractorVectorField>(sn) || Object::cast_to<GPUParticlesCollisionSDF>(sn) || Object::cast_to<GPUParticlesCollisionHeightField>(sn)) {
+ if (p_cancel) {
+ sn->call("set_extents", p_restore);
+ return;
+ }
+
+ UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Change Box Shape Extents"));
+ ur->add_do_method(sn, "set_extents", sn->call("get_extents"));
+ ur->add_undo_method(sn, "set_extents", p_restore);
+ ur->commit_action();
+ }
+}
+
+void GPUParticlesCollision3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
+ Node3D *cs = p_gizmo->get_spatial_node();
+
+ print_line("redraw request " + itos(cs != nullptr));
+ p_gizmo->clear();
+
+ const Ref<Material> material =
+ get_material("shape_material", p_gizmo);
+ const Ref<Material> material_internal =
+ get_material("shape_material_internal", p_gizmo);
+
+ Ref<Material> handles_material = get_material("handles");
+
+ if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
+ float r = cs->call("get_radius");
+
+ Vector<Vector3> points;
+
+ for (int i = 0; i <= 360; i++) {
+ float ra = Math::deg2rad((float)i);
+ float rb = Math::deg2rad((float)i + 1);
+ Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
+ Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
+
+ points.push_back(Vector3(a.x, 0, a.y));
+ points.push_back(Vector3(b.x, 0, b.y));
+ points.push_back(Vector3(0, a.x, a.y));
+ points.push_back(Vector3(0, b.x, b.y));
+ points.push_back(Vector3(a.x, a.y, 0));
+ points.push_back(Vector3(b.x, b.y, 0));
+ }
+
+ Vector<Vector3> collision_segments;
+
+ for (int i = 0; i < 64; i++) {
+ float ra = i * Math_PI * 2.0 / 64.0;
+ float rb = (i + 1) * Math_PI * 2.0 / 64.0;
+ Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
+ Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
+
+ collision_segments.push_back(Vector3(a.x, 0, a.y));
+ collision_segments.push_back(Vector3(b.x, 0, b.y));
+ collision_segments.push_back(Vector3(0, a.x, a.y));
+ collision_segments.push_back(Vector3(0, b.x, b.y));
+ collision_segments.push_back(Vector3(a.x, a.y, 0));
+ collision_segments.push_back(Vector3(b.x, b.y, 0));
+ }
+
+ p_gizmo->add_lines(points, material);
+ p_gizmo->add_collision_segments(collision_segments);
+ Vector<Vector3> handles;
+ handles.push_back(Vector3(r, 0, 0));
+ p_gizmo->add_handles(handles, handles_material);
+ }
+
+ if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
+ Vector<Vector3> lines;
+ AABB aabb;
+ aabb.position = -cs->call("get_extents").operator Vector3();
+ aabb.size = aabb.position * -2;
+
+ for (int i = 0; i < 12; i++) {
+ Vector3 a, b;
+ aabb.get_edge(i, a, b);
+ lines.push_back(a);
+ lines.push_back(b);
+ }
+
+ Vector<Vector3> handles;
+
+ for (int i = 0; i < 3; i++) {
+ Vector3 ax;
+ ax[i] = cs->call("get_extents").operator Vector3()[i];
+ handles.push_back(ax);
+ }
+
+ p_gizmo->add_lines(lines, material);
+ p_gizmo->add_collision_segments(lines);
+ p_gizmo->add_handles(handles, handles_material);
+
+ GPUParticlesCollisionSDF *col_sdf = Object::cast_to<GPUParticlesCollisionSDF>(cs);
+ if (col_sdf) {
+ static const int subdivs[GPUParticlesCollisionSDF::RESOLUTION_MAX] = { 16, 32, 64, 128, 256, 512 };
+ int subdiv = subdivs[col_sdf->get_resolution()];
+ float cell_size = aabb.get_longest_axis_size() / subdiv;
+
+ lines.clear();
+
+ for (int i = 1; i < subdiv; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (cell_size * i > aabb.size[j]) {
+ continue;
+ }
+
+ Vector2 dir;
+ dir[j] = 1.0;
+ Vector2 ta, tb;
+ int j_n1 = (j + 1) % 3;
+ int j_n2 = (j + 2) % 3;
+ ta[j_n1] = 1.0;
+ tb[j_n2] = 1.0;
+
+ for (int k = 0; k < 4; k++) {
+ Vector3 from = aabb.position, to = aabb.position;
+ from[j] += cell_size * i;
+ to[j] += cell_size * i;
+
+ if (k & 1) {
+ to[j_n1] += aabb.size[j_n1];
+ } else {
+ to[j_n2] += aabb.size[j_n2];
+ }
+
+ if (k & 2) {
+ from[j_n1] += aabb.size[j_n1];
+ from[j_n2] += aabb.size[j_n2];
+ }
+
+ lines.push_back(from);
+ lines.push_back(to);
+ }
+ }
+ }
+
+ p_gizmo->add_lines(lines, material_internal);
+ }
+ }
+}
+
+/////
+
+////
+
ReflectionProbeGizmoPlugin::ReflectionProbeGizmoPlugin() {
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5));
diff --git a/editor/node_3d_editor_gizmos.h b/editor/node_3d_editor_gizmos.h
index c7aae39a45..4826054643 100644
--- a/editor/node_3d_editor_gizmos.h
+++ b/editor/node_3d_editor_gizmos.h
@@ -253,6 +253,23 @@ public:
GPUParticles3DGizmoPlugin();
};
+class GPUParticlesCollision3DGizmoPlugin : public EditorNode3DGizmoPlugin {
+ GDCLASS(GPUParticlesCollision3DGizmoPlugin, EditorNode3DGizmoPlugin);
+
+public:
+ bool has_gizmo(Node3D *p_spatial) override;
+ String get_name() const override;
+ int get_priority() const override;
+ void redraw(EditorNode3DGizmo *p_gizmo) override;
+
+ String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override;
+ Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override;
+ void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override;
+ void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override;
+
+ GPUParticlesCollision3DGizmoPlugin();
+};
+
class ReflectionProbeGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(ReflectionProbeGizmoPlugin, EditorNode3DGizmoPlugin);
diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp
index 26006d85c9..885ec17cb3 100644
--- a/editor/plugins/animation_state_machine_editor.cpp
+++ b/editor/plugins/animation_state_machine_editor.cpp
@@ -386,6 +386,12 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
over_text = over_text_now;
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) {
diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp
new file mode 100644
index 0000000000..0288645f91
--- /dev/null
+++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp
@@ -0,0 +1,201 @@
+/*************************************************************************/
+/* gpu_particles_collision_sdf_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "gpu_particles_collision_sdf_editor_plugin.h"
+
+void GPUParticlesCollisionSDFEditorPlugin::_bake() {
+ if (col_sdf) {
+ if (col_sdf->get_texture().is_null() || !col_sdf->get_texture()->get_path().is_resource_file()) {
+ String path = get_tree()->get_edited_scene_root()->get_filename();
+ if (path == String()) {
+ path = "res://" + col_sdf->get_name() + "_data.exr";
+ } else {
+ String ext = path.get_extension();
+ path = path.get_basename() + "." + col_sdf->get_name() + "_data.exr";
+ }
+ probe_file->set_current_path(path);
+ probe_file->popup_file_dialog();
+ return;
+ }
+
+ _sdf_save_path_and_bake(col_sdf->get_texture()->get_path());
+ }
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::edit(Object *p_object) {
+ GPUParticlesCollisionSDF *s = Object::cast_to<GPUParticlesCollisionSDF>(p_object);
+ if (!s) {
+ return;
+ }
+
+ col_sdf = s;
+}
+
+bool GPUParticlesCollisionSDFEditorPlugin::handles(Object *p_object) const {
+ return p_object->is_class("GPUParticlesCollisionSDF");
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::_notification(int p_what) {
+ if (p_what == NOTIFICATION_PROCESS) {
+ if (!col_sdf) {
+ return;
+ }
+
+ const Vector3i size = col_sdf->get_estimated_cell_size();
+ String text = vformat(String::utf8("%d × %d × %d"), size.x, size.y, size.z);
+ int data_size = 2;
+
+ const double size_mb = size.x * size.y * size.z * data_size / (1024.0 * 1024.0);
+ text += " - " + vformat(TTR("VRAM Size: %s MB"), String::num(size_mb, 2));
+
+ if (bake_info->get_text() == text) {
+ return;
+ }
+
+ // Color the label depending on the estimated performance level.
+ Color color;
+ if (size_mb <= 16.0 + CMP_EPSILON) {
+ // Fast.
+ color = bake_info->get_theme_color("success_color", "Editor");
+ } else if (size_mb <= 64.0 + CMP_EPSILON) {
+ // Medium.
+ color = bake_info->get_theme_color("warning_color", "Editor");
+ } else {
+ // Slow.
+ color = bake_info->get_theme_color("error_color", "Editor");
+ }
+ bake_info->add_theme_color_override("font_color", color);
+
+ bake_info->set_text(text);
+ }
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::make_visible(bool p_visible) {
+ if (p_visible) {
+ bake_hb->show();
+ set_process(true);
+ } else {
+ bake_hb->hide();
+ set_process(false);
+ }
+}
+
+EditorProgress *GPUParticlesCollisionSDFEditorPlugin::tmp_progress = nullptr;
+
+void GPUParticlesCollisionSDFEditorPlugin::bake_func_begin(int p_steps) {
+ ERR_FAIL_COND(tmp_progress != nullptr);
+
+ tmp_progress = memnew(EditorProgress("bake_sdf", TTR("Bake SDF"), p_steps));
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::bake_func_step(int p_step, const String &p_description) {
+ ERR_FAIL_COND(tmp_progress == nullptr);
+ tmp_progress->step(p_description, p_step, false);
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::bake_func_end() {
+ ERR_FAIL_COND(tmp_progress == nullptr);
+ memdelete(tmp_progress);
+ tmp_progress = nullptr;
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::_sdf_save_path_and_bake(const String &p_path) {
+ probe_file->hide();
+ if (col_sdf) {
+ Ref<Image> bake_img = col_sdf->bake();
+ if (bake_img.is_null()) {
+ EditorNode::get_singleton()->show_warning("Bake Error.");
+ return;
+ }
+
+ Ref<ConfigFile> config;
+
+ config.instance();
+ if (FileAccess::exists(p_path + ".import")) {
+ config->load(p_path + ".import");
+ }
+
+ config->set_value("remap", "importer", "3d_texture");
+ config->set_value("remap", "type", "StreamTexture3D");
+ if (!config->has_section_key("params", "compress/mode")) {
+ config->set_value("params", "compress/mode", 3); //user may want another compression, so leave it be
+ }
+ config->set_value("params", "compress/channel_pack", 1);
+ config->set_value("params", "mipmaps/generate", false);
+ config->set_value("params", "slices/horizontal", 1);
+ config->set_value("params", "slices/vertical", bake_img->get_meta("depth"));
+
+ config->save(p_path + ".import");
+
+ Error err = bake_img->save_exr(p_path, false);
+ ERR_FAIL_COND(err);
+ ResourceLoader::import(p_path);
+ Ref<Texture> t = ResourceLoader::load(p_path); //if already loaded, it will be updated on refocus?
+ ERR_FAIL_COND(t.is_null());
+
+ col_sdf->set_texture(t);
+ }
+}
+
+void GPUParticlesCollisionSDFEditorPlugin::_bind_methods() {
+}
+
+GPUParticlesCollisionSDFEditorPlugin::GPUParticlesCollisionSDFEditorPlugin(EditorNode *p_node) {
+ editor = p_node;
+ bake_hb = memnew(HBoxContainer);
+ bake_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ bake_hb->hide();
+ bake = memnew(Button);
+ bake->set_flat(true);
+ bake->set_icon(editor->get_gui_base()->get_theme_icon("Bake", "EditorIcons"));
+ bake->set_text(TTR("Bake SDF"));
+ bake->connect("pressed", callable_mp(this, &GPUParticlesCollisionSDFEditorPlugin::_bake));
+ bake_hb->add_child(bake);
+ bake_info = memnew(Label);
+ bake_info->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ bake_info->set_clip_text(true);
+ bake_hb->add_child(bake_info);
+
+ add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake_hb);
+ col_sdf = nullptr;
+ probe_file = memnew(EditorFileDialog);
+ probe_file->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
+ probe_file->add_filter("*.exr");
+ probe_file->connect("file_selected", callable_mp(this, &GPUParticlesCollisionSDFEditorPlugin::_sdf_save_path_and_bake));
+ get_editor_interface()->get_base_control()->add_child(probe_file);
+ probe_file->set_title(TTR("Select path for SDF Texture"));
+
+ GPUParticlesCollisionSDF::bake_begin_function = bake_func_begin;
+ GPUParticlesCollisionSDF::bake_step_function = bake_func_step;
+ GPUParticlesCollisionSDF::bake_end_function = bake_func_end;
+}
+
+GPUParticlesCollisionSDFEditorPlugin::~GPUParticlesCollisionSDFEditorPlugin() {
+}
diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.h b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.h
new file mode 100644
index 0000000000..0cdc70a62b
--- /dev/null
+++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.h
@@ -0,0 +1,74 @@
+/*************************************************************************/
+/* gpu_particles_collision_sdf_editor_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GPU_PARTICLES_COLLISION_SDF_EDITOR_PLUGIN_H
+#define GPU_PARTICLES_COLLISION_SDF_EDITOR_PLUGIN_H
+
+#include "editor/editor_node.h"
+#include "editor/editor_plugin.h"
+#include "scene/3d/gpu_particles_collision_3d.h"
+#include "scene/resources/material.h"
+
+class GPUParticlesCollisionSDFEditorPlugin : public EditorPlugin {
+ GDCLASS(GPUParticlesCollisionSDFEditorPlugin, EditorPlugin);
+
+ GPUParticlesCollisionSDF *col_sdf;
+
+ HBoxContainer *bake_hb;
+ Label *bake_info;
+ Button *bake;
+ EditorNode *editor;
+
+ EditorFileDialog *probe_file;
+
+ static EditorProgress *tmp_progress;
+ static void bake_func_begin(int p_steps);
+ static void bake_func_step(int p_step, const String &p_description);
+ static void bake_func_end();
+
+ void _bake();
+ void _sdf_save_path_and_bake(const String &p_path);
+
+protected:
+ static void _bind_methods();
+ void _notification(int p_what);
+
+public:
+ virtual String get_name() const override { return "GPUParticlesCollisionSDF"; }
+ bool has_main_screen() const override { return false; }
+ virtual void edit(Object *p_object) override;
+ virtual bool handles(Object *p_object) const override;
+ virtual void make_visible(bool p_visible) override;
+
+ GPUParticlesCollisionSDFEditorPlugin(EditorNode *p_node);
+ ~GPUParticlesCollisionSDFEditorPlugin();
+};
+
+#endif // GPU_PARTICLES_COLLISION_SDF_EDITOR_PLUGIN_H
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index b2fd855834..aecbf817c4 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -2405,18 +2405,18 @@ void Node3DEditorViewport::_notification(int p_what) {
}
Transform t = sp->get_global_gizmo_transform();
+ VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(sp);
+ AABB new_aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp);
exist = true;
- if (se->last_xform == t && !se->last_xform_dirty) {
+ if (se->last_xform == t && se->aabb == new_aabb && !se->last_xform_dirty) {
continue;
}
changed = true;
se->last_xform_dirty = false;
se->last_xform = t;
- VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(sp);
-
- se->aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp);
+ se->aabb = new_aabb;
t.translate(se->aabb.position);
@@ -6092,6 +6092,7 @@ void Node3DEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<VehicleWheel3DGizmoPlugin>(memnew(VehicleWheel3DGizmoPlugin)));
add_gizmo_plugin(Ref<VisibilityNotifier3DGizmoPlugin>(memnew(VisibilityNotifier3DGizmoPlugin)));
add_gizmo_plugin(Ref<GPUParticles3DGizmoPlugin>(memnew(GPUParticles3DGizmoPlugin)));
+ add_gizmo_plugin(Ref<GPUParticlesCollision3DGizmoPlugin>(memnew(GPUParticlesCollision3DGizmoPlugin)));
add_gizmo_plugin(Ref<CPUParticles3DGizmoPlugin>(memnew(CPUParticles3DGizmoPlugin)));
add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin)));
add_gizmo_plugin(Ref<DecalGizmoPlugin>(memnew(DecalGizmoPlugin)));
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 8cd8aaf277..9261113706 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -89,6 +89,25 @@ void TileMapEditor::_notification(int p_what) {
case NOTIFICATION_EXIT_TREE: {
get_tree()->disconnect("node_removed", callable_mp(this, &TileMapEditor::_node_removed));
} break;
+
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
+ if (tool == TOOL_PAINTING) {
+ Vector<int> ids = get_selected_tiles();
+
+ if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) {
+ _set_cell(over_tile, ids, flip_h, flip_v, transpose);
+ _finish_undo();
+
+ paint_undo.clear();
+ }
+
+ tool = TOOL_NONE;
+ _update_button_tool();
+ }
+
+ // set flag to ignore over_tile on refocus
+ refocus_over_tile = true;
+ } break;
}
}
@@ -1299,6 +1318,12 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport();
}
+ if (refocus_over_tile) {
+ // editor lost focus; forget last tile position
+ old_over_tile = new_over_tile;
+ refocus_over_tile = false;
+ }
+
int tile_under = node->get_cell(over_tile.x, over_tile.y);
String tile_name = "none";
diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h
index 996e904853..f57616db1f 100644
--- a/editor/plugins/tile_map_editor_plugin.h
+++ b/editor/plugins/tile_map_editor_plugin.h
@@ -119,6 +119,7 @@ class TileMapEditor : public VBoxContainer {
Rect2i rectangle;
Point2i over_tile;
+ bool refocus_over_tile = false;
bool *bucket_cache_visited;
Rect2i bucket_cache_rect;
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 1651de4048..61fb0f4700 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -107,6 +107,7 @@ void VisualShaderGraphPlugin::_bind_methods() {
ClassDB::bind_method("update_node_deferred", &VisualShaderGraphPlugin::update_node_deferred);
ClassDB::bind_method("set_input_port_default_value", &VisualShaderGraphPlugin::set_input_port_default_value);
ClassDB::bind_method("set_uniform_name", &VisualShaderGraphPlugin::set_uniform_name);
+ ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant);
}
@@ -226,6 +227,13 @@ void VisualShaderGraphPlugin::update_constant(VisualShader::Type p_type, int p_n
links[p_node_id].graph_node->set_size(Size2(-1, -1));
}
+void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
+ if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
+ return;
+ }
+ links[p_node_id].expression_edit->set_text(p_expression);
+}
+
void VisualShaderGraphPlugin::update_node_size(int p_node_id) {
if (!links.has(p_node_id)) {
return;
@@ -241,6 +249,10 @@ void VisualShaderGraphPlugin::register_constant_option_btn(int p_node_id, Option
links[p_node_id].const_op = p_button;
}
+void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
+ links[p_node_id].expression_edit = p_expression_edit;
+}
+
void VisualShaderGraphPlugin::update_uniform_refs() {
for (Map<int, Link>::Element *E = links.front(); E; E = E->next()) {
VisualShaderNodeUniformRef *ref = Object::cast_to<VisualShaderNodeUniformRef>(E->get().visual_node);
@@ -284,7 +296,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) {
}
void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
- links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr });
+ links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr });
}
void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
@@ -342,7 +354,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
if (p_id >= 2) {
node->set_show_close_button(true);
- node->connect("close_request", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_delete_request), varray(p_id), CONNECT_DEFERRED);
+ node->connect("close_request", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_delete_node_request), varray(p_type, p_id), CONNECT_DEFERRED);
}
node->connect("dragged", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_node_dragged), varray(p_id));
@@ -623,6 +635,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
expression_syntax_highlighter.instance();
expression_node->set_control(expression_box, 0);
node->add_child(expression_box);
+ register_expression_edit(p_id, expression_box);
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
@@ -1210,7 +1223,7 @@ void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type
return;
}
- undo_redo->create_action(TTR("Add input port"));
+ undo_redo->create_action(TTR("Add Input Port"));
undo_redo->add_do_method(node.ptr(), "add_input_port", p_port, p_port_type, p_name);
undo_redo->add_undo_method(node.ptr(), "remove_input_port", p_port);
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
@@ -1225,7 +1238,7 @@ void VisualShaderEditor::_add_output_port(int p_node, int p_port, int p_port_typ
return;
}
- undo_redo->create_action(TTR("Add output port"));
+ undo_redo->create_action(TTR("Add Output Port"));
undo_redo->add_do_method(node.ptr(), "add_output_port", p_port, p_port_type, p_name);
undo_redo->add_undo_method(node.ptr(), "remove_output_port", p_port);
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
@@ -1240,7 +1253,7 @@ void VisualShaderEditor::_change_input_port_type(int p_type, int p_node, int p_p
return;
}
- undo_redo->create_action(TTR("Change input port type"));
+ undo_redo->create_action(TTR("Change Input Port Type"));
undo_redo->add_do_method(node.ptr(), "set_input_port_type", p_port, p_type);
undo_redo->add_undo_method(node.ptr(), "set_input_port_type", p_port, node->get_input_port_type(p_port));
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
@@ -1255,7 +1268,7 @@ void VisualShaderEditor::_change_output_port_type(int p_type, int p_node, int p_
return;
}
- undo_redo->create_action(TTR("Change output port type"));
+ undo_redo->create_action(TTR("Change Output Port Type"));
undo_redo->add_do_method(node.ptr(), "set_output_port_type", p_port, p_type);
undo_redo->add_undo_method(node.ptr(), "set_output_port_type", p_port, node->get_output_port_type(p_port));
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node);
@@ -1269,7 +1282,7 @@ void VisualShaderEditor::_change_input_port_name(const String &p_text, Object *l
Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
ERR_FAIL_COND(!node.is_valid());
- undo_redo->create_action(TTR("Change input port name"));
+ undo_redo->create_action(TTR("Change Input Port Name"));
undo_redo->add_do_method(node.ptr(), "set_input_port_name", p_port_id, p_text);
undo_redo->add_undo_method(node.ptr(), "set_input_port_name", p_port_id, node->get_input_port_name(p_port_id));
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node_id);
@@ -1283,7 +1296,7 @@ void VisualShaderEditor::_change_output_port_name(const String &p_text, Object *
Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node_id);
ERR_FAIL_COND(!node.is_valid());
- undo_redo->create_action(TTR("Change output port name"));
+ undo_redo->create_action(TTR("Change Output Port Name"));
undo_redo->add_do_method(node.ptr(), "set_output_port_name", p_port_id, p_text);
undo_redo->add_undo_method(node.ptr(), "set_output_port_name", p_port_id, node->get_output_port_name(p_port_id));
undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, p_node_id);
@@ -1298,7 +1311,7 @@ void VisualShaderEditor::_remove_input_port(int p_node, int p_port) {
return;
}
- undo_redo->create_action(TTR("Remove input port"));
+ undo_redo->create_action(TTR("Remove Input Port"));
List<VisualShader::Connection> conns;
visual_shader->get_node_connections(type, &conns);
@@ -1347,7 +1360,7 @@ void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
return;
}
- undo_redo->create_action(TTR("Remove output port"));
+ undo_redo->create_action(TTR("Remove Output Port"));
List<VisualShader::Connection> conns;
visual_shader->get_node_connections(type, &conns);
@@ -1402,67 +1415,72 @@ void VisualShaderEditor::_expression_focus_out(Object *code_edit, int p_node) {
return;
}
- undo_redo->create_action(TTR("Set expression"));
+ undo_redo->create_action(TTR("Set VisualShader Expression"));
undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
undo_redo->add_undo_method(node.ptr(), "set_expression", node->get_expression());
+ undo_redo->add_do_method(graph_plugin.ptr(), "set_expression", type, p_node, expression_box->get_text());
+ undo_redo->add_undo_method(graph_plugin.ptr(), "set_expression", type, p_node, node->get_expression());
undo_redo->commit_action();
}
void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) {
- VisualShader::Type type = get_current_shader_type();
+ VisualShader::Type type = VisualShader::Type(p_type);
Ref<VisualShaderNode> node = visual_shader->get_node(type, p_node);
if (node.is_null()) {
return;
}
Ref<VisualShaderNodeGroupBase> group_node = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
-
if (group_node.is_null()) {
return;
}
- Vector2 size = p_size;
+ group_node->set_size(p_size);
- group_node->set_size(size);
+ if (get_current_shader_type() == type) {
+ Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
+ Control *text_box = nullptr;
+ if (!expression_node.is_null()) {
+ text_box = expression_node->get_control(0);
+ if (text_box) {
+ text_box->set_custom_minimum_size(Size2(0, 0));
+ }
+ }
- GraphNode *gn = nullptr;
- if (edit_type->get_selected() == p_type) { // check - otherwise the error will be emitted
+ GraphNode *gn = nullptr;
Node *node2 = graph->get_node(itos(p_node));
gn = Object::cast_to<GraphNode>(node2);
if (!gn) {
return;
}
- gn->set_custom_minimum_size(size);
+ gn->set_custom_minimum_size(p_size);
gn->set_size(Size2(1, 1));
- }
- Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
- if (!expression_node.is_null()) {
- Control *text_box = expression_node->get_control(0);
- Size2 box_size = size;
- if (gn != nullptr) {
- if (box_size.x < 150 * EDSCALE || box_size.y < 0) {
- box_size.x = gn->get_size().x;
+ if (!expression_node.is_null() && text_box) {
+ Size2 box_size = p_size;
+ if (gn != nullptr) {
+ if (box_size.x < 150 * EDSCALE || box_size.y < 0) {
+ box_size.x = gn->get_size().x;
+ }
}
+ box_size.x -= text_box->get_margin(MARGIN_LEFT);
+ box_size.x -= 28 * EDSCALE;
+ box_size.y -= text_box->get_margin(MARGIN_TOP);
+ box_size.y -= 28 * EDSCALE;
+ text_box->set_custom_minimum_size(Size2(box_size.x, box_size.y));
+ text_box->set_size(Size2(1, 1));
}
- box_size.x -= text_box->get_margin(MARGIN_LEFT);
- box_size.x -= 28 * EDSCALE;
- box_size.y -= text_box->get_margin(MARGIN_TOP);
- box_size.y -= 28 * EDSCALE;
- text_box->set_custom_minimum_size(Size2(box_size.x, box_size.y));
- text_box->set_size(Size2(1, 1));
}
}
void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, int p_node) {
- VisualShader::Type type = get_current_shader_type();
- Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(type, p_node);
+ Ref<VisualShaderNodeGroupBase> node = visual_shader->get_node(VisualShader::Type(p_type), p_node);
if (node.is_null()) {
return;
}
- undo_redo->create_action(TTR("Resize VisualShader node"), UndoRedo::MERGE_ENDS);
+ undo_redo->create_action(TTR("Resize VisualShader Node"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, p_new_size);
undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size());
undo_redo->commit_action();
@@ -1903,61 +1921,112 @@ void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slo
_show_members_dialog(true);
}
-void VisualShaderEditor::_delete_request(int which) {
- VisualShader::Type type = get_current_shader_type();
- Ref<VisualShaderNode> node = Ref<VisualShaderNode>(visual_shader->get_node(type, which));
-
- undo_redo->create_action(TTR("Delete Node"));
-
+void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) {
+ VisualShader::Type type = VisualShader::Type(p_type);
List<VisualShader::Connection> conns;
visual_shader->get_node_connections(type, &conns);
- for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
- if (E->get().from_node == which || E->get().to_node == which) {
- undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+
+ for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) {
+ for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
+ if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
+ undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ }
}
}
- undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, which);
- undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, which), which);
- undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, which);
+ Set<String> uniform_names;
- undo_redo->add_do_method(this, "_clear_buffer");
- undo_redo->add_undo_method(this, "_clear_buffer");
+ for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) {
+ Ref<VisualShaderNode> node = visual_shader->get_node(type, F->get());
- // restore size, inputs and outputs if node is group
- VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
- if (group) {
- undo_redo->add_undo_method(group, "set_size", group->get_size());
- undo_redo->add_undo_method(group, "set_inputs", group->get_inputs());
- undo_redo->add_undo_method(group, "set_outputs", group->get_outputs());
- }
+ undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get());
+ undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F->get()), F->get());
+ undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F->get());
+
+ undo_redo->add_do_method(this, "_clear_buffer");
+ undo_redo->add_undo_method(this, "_clear_buffer");
+
+ // restore size, inputs and outputs if node is group
+ VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
+ if (group) {
+ undo_redo->add_undo_method(group, "set_size", group->get_size());
+ undo_redo->add_undo_method(group, "set_inputs", group->get_inputs());
+ undo_redo->add_undo_method(group, "set_outputs", group->get_outputs());
+ }
+
+ // restore expression text if node is expression
+ VisualShaderNodeExpression *expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
+ if (expression) {
+ undo_redo->add_undo_method(expression, "set_expression", expression->get_expression());
+ }
- // restore expression text if node is expression
- VisualShaderNodeExpression *expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
- if (expression) {
- undo_redo->add_undo_method(expression, "set_expression", expression->get_expression());
+ VisualShaderNodeUniform *uniform = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
+ if (uniform) {
+ uniform_names.insert(uniform->get_uniform_name());
+ }
}
- for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
- if (E->get().from_node == which || E->get().to_node == which) {
- undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
- undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ List<VisualShader::Connection> used_conns;
+ for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) {
+ for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
+ if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
+ bool cancel = false;
+ for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
+ if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) {
+ cancel = true; // to avoid ERR_ALREADY_EXISTS warning
+ break;
+ }
+ }
+ if (!cancel) {
+ undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ used_conns.push_back(E->get());
+ }
+ }
}
}
- // delete a node from the graph
- undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, which);
- VisualShaderNodeUniform *uniform = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
- if (uniform) {
+ // delete nodes from the graph
+ for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) {
+ undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F->get());
+ }
+
+ // update uniform refs if any uniform has been deleted
+ if (uniform_names.size() > 0) {
undo_redo->add_do_method(this, "_update_uniforms", true);
undo_redo->add_undo_method(this, "_update_uniforms", true);
- Set<String> uniform_names;
- uniform_names.insert(uniform->get_uniform_name());
-
_update_uniform_refs(uniform_names);
}
+}
+void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
+ List<int> to_erase;
+ to_erase.push_back(p_node);
+
+ undo_redo->create_action(TTR("Delete VisualShader Node"));
+ _delete_nodes(p_type, to_erase);
+ undo_redo->commit_action();
+}
+
+void VisualShaderEditor::_delete_nodes_request() {
+ List<int> to_erase;
+
+ for (int i = 0; i < graph->get_child_count(); i++) {
+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
+ if (gn) {
+ if (gn->is_selected() && gn->is_close_button_visible()) {
+ to_erase.push_back(gn->get_name().operator String().to_int());
+ }
+ }
+ }
+
+ if (to_erase.empty()) {
+ return;
+ }
+
+ undo_redo->create_action(TTR("Delete VisualShader Node(s)"));
+ _delete_nodes(get_current_shader_type(), to_erase);
undo_redo->commit_action();
}
@@ -2280,7 +2349,7 @@ void VisualShaderEditor::_clear_buffer() {
}
void VisualShaderEditor::_duplicate_nodes() {
- int type = edit_type->get_selected();
+ int type = get_current_shader_type();
List<int> nodes;
Set<int> excluded;
@@ -2291,13 +2360,13 @@ void VisualShaderEditor::_duplicate_nodes() {
return;
}
- undo_redo->create_action(TTR("Duplicate Nodes"));
+ undo_redo->create_action(TTR("Duplicate VisualShader Node(s)"));
_dup_paste_nodes(type, type, nodes, excluded, Vector2(10, 10) * EDSCALE, true);
}
void VisualShaderEditor::_copy_nodes() {
- copy_type = edit_type->get_selected();
+ copy_type = get_current_shader_type();
_clear_buffer();
@@ -2309,9 +2378,7 @@ void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2
return;
}
- int type = edit_type->get_selected();
-
- undo_redo->create_action(TTR("Paste Nodes"));
+ int type = get_current_shader_type();
float scale = graph->get_zoom();
@@ -2322,109 +2389,13 @@ void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2
mpos = graph->get_local_mouse_position();
}
+ undo_redo->create_action(TTR("Paste VisualShader Node(s)"));
+
_dup_paste_nodes(type, copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer, (graph->get_scroll_ofs() / scale + mpos / scale - selection_center), false);
_dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste
}
-void VisualShaderEditor::_delete_nodes() {
- VisualShader::Type type = get_current_shader_type();
- List<int> to_erase;
-
- for (int i = 0; i < graph->get_child_count(); i++) {
- GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
- if (gn) {
- if (gn->is_selected() && gn->is_close_button_visible()) {
- to_erase.push_back(gn->get_name().operator String().to_int());
- }
- }
- }
-
- if (to_erase.empty()) {
- return;
- }
-
- undo_redo->create_action(TTR("Delete Nodes"));
-
- List<VisualShader::Connection> conns;
- visual_shader->get_node_connections(type, &conns);
-
- for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
- for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
- if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
- undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
- }
- }
- }
-
- Set<String> uniform_names;
-
- for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
- Ref<VisualShaderNode> node = visual_shader->get_node(type, F->get());
-
- undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get());
- undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F->get()), F->get());
- undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F->get());
-
- undo_redo->add_do_method(this, "_clear_buffer");
- undo_redo->add_undo_method(this, "_clear_buffer");
-
- // restore size, inputs and outputs if node is group
- VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr());
- if (group) {
- undo_redo->add_undo_method(group, "set_size", group->get_size());
- undo_redo->add_undo_method(group, "set_inputs", group->get_inputs());
- undo_redo->add_undo_method(group, "set_outputs", group->get_outputs());
- }
-
- // restore expression text if node is expression
- VisualShaderNodeExpression *expression = Object::cast_to<VisualShaderNodeExpression>(node.ptr());
- if (expression) {
- undo_redo->add_undo_method(expression, "set_expression", expression->get_expression());
- }
-
- VisualShaderNodeUniform *uniform = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
- if (uniform) {
- uniform_names.insert(uniform->get_uniform_name());
- }
- }
-
- List<VisualShader::Connection> used_conns;
- for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
- for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
- if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
- bool cancel = false;
- for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) {
- if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) {
- cancel = true; // to avoid ERR_ALREADY_EXISTS warning
- break;
- }
- }
- if (!cancel) {
- undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
- undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
- used_conns.push_back(E->get());
- }
- }
- }
- }
-
- // delete nodes from the graph
- for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
- undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F->get());
- }
-
- // update uniform refs if any uniform has been deleted
- if (uniform_names.size() > 0) {
- undo_redo->add_do_method(this, "_update_uniforms", true);
- undo_redo->add_undo_method(this, "_update_uniforms", true);
-
- _update_uniform_refs(uniform_names);
- }
-
- undo_redo->commit_action();
-}
-
void VisualShaderEditor::_mode_selected(int p_id) {
visual_shader->set_shader_type(particles_mode ? VisualShader::Type(p_id + 3) : VisualShader::Type(p_id));
_update_options_menu();
@@ -2630,7 +2601,7 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
_paste_nodes(true, menu_point);
break;
case NodeMenuOptions::DELETE:
- _delete_nodes();
+ _delete_nodes_request();
break;
case NodeMenuOptions::DUPLICATE:
_duplicate_nodes();
@@ -2842,8 +2813,8 @@ VisualShaderEditor::VisualShaderEditor() {
graph->connect("scroll_offset_changed", callable_mp(this, &VisualShaderEditor::_scroll_changed));
graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes));
- graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes));
- graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes));
+ graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes), varray(false, Point2()));
+ graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
@@ -3127,6 +3098,7 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("FragCoord", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("Light", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light"), "light", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("LightColor", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "light_color"), "light_color", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
+ add_options.push_back(AddOption("Metallic", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "metallic"), "metallic", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("Roughness", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "roughness"), "roughness", VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("Specular", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "specular"), "specular", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("Transmission", "Input", "Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "transmission"), "transmission", VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index d43af82238..cecee70ca9 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -73,6 +73,7 @@ private:
VBoxContainer *preview_box;
LineEdit *uniform_name;
OptionButton *const_op;
+ CodeEdit *expression_edit;
};
Ref<VisualShader> visual_shader;
@@ -91,6 +92,7 @@ public:
void register_uniform_name(int p_id, LineEdit *p_uniform_name);
void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
void register_constant_option_btn(int p_node_id, OptionButton *p_button);
+ void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);
void clear_links();
void set_shader_type(VisualShader::Type p_type);
bool is_preview_visible(int p_id) const;
@@ -110,6 +112,7 @@ public:
void update_uniform_refs();
void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name);
void update_constant(VisualShader::Type p_type, int p_node_id);
+ void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);
int get_constant_index(float p_constant) const;
void update_node_size(int p_node_id);
VisualShader::Type get_shader_type() const;
@@ -290,8 +293,9 @@ class VisualShaderEditor : public VBoxContainer {
void _scroll_changed(const Vector2 &p_scroll);
void _node_selected(Object *p_node);
- void _delete_request(int);
- void _delete_nodes();
+ void _delete_nodes(int p_type, const List<int> &p_nodes);
+ void _delete_node_request(int p_type, int p_node);
+ void _delete_nodes_request();
void _removed_from_graph();
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 75dc840738..fa2270dcd6 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -1141,7 +1141,7 @@ void SceneTreeDock::_notification(int p_what) {
node_shortcuts->add_child(button_custom);
button_custom->set_text(TTR("Other Node"));
button_custom->set_icon(get_theme_icon("Add", "EditorIcons"));
- button_custom->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_NEW, false));
+ button_custom->connect("pressed", callable_bind(callable_mp(this, &SceneTreeDock::_tool_selected), TOOL_NEW, false));
node_shortcuts->add_spacer();
create_root_dialog->add_child(node_shortcuts);
diff --git a/editor/shader_globals_editor.cpp b/editor/shader_globals_editor.cpp
index aa88b0ef39..04fbac3463 100644
--- a/editor/shader_globals_editor.cpp
+++ b/editor/shader_globals_editor.cpp
@@ -437,6 +437,9 @@ void ShaderGlobalsEditor::_notification(int p_what) {
inspector->edit(interface);
}
}
+ if (p_what == NOTIFICATION_PREDELETE) {
+ inspector->edit(nullptr);
+ }
}
ShaderGlobalsEditor::ShaderGlobalsEditor() {
@@ -474,6 +477,5 @@ ShaderGlobalsEditor::ShaderGlobalsEditor() {
}
ShaderGlobalsEditor::~ShaderGlobalsEditor() {
- inspector->edit(nullptr);
memdelete(interface);
}
diff --git a/misc/dist/html/editor.html b/misc/dist/html/editor.html
new file mode 100644
index 0000000000..5b6ad2df65
--- /dev/null
+++ b/misc/dist/html/editor.html
@@ -0,0 +1,475 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='' xml:lang=''>
+<head>
+ <meta charset='utf-8' />
+ <meta name='viewport' content='width=device-width, user-scalable=no' />
+ <link id='-gd-engine-icon' rel='icon' type='image/png' href='favicon.png' />
+ <title></title>
+ <style type='text/css'>
+
+ body {
+ touch-action: none;
+ margin: 0;
+ border: 0 none;
+ padding: 0;
+ text-align: center;
+ background-color: black;
+ overflow: hidden;
+ }
+
+ #canvas, #gameCanvas {
+ display: block;
+ margin: 0;
+ color: white;
+ }
+
+ #canvas:focus, #gameCanvas:focus {
+ outline: none;
+ }
+
+ .godot {
+ font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
+ color: #e0e0e0;
+ background-color: #3b3943;
+ background-image: linear-gradient(to bottom, #403e48, #35333c);
+ border: 1px solid #45434e;
+ box-shadow: 0 0 1px 1px #2f2d35;
+ }
+
+
+ /* Status display
+ * ============== */
+
+ #status {
+ position: absolute;
+ left: 0;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ /* don't consume click events - make children visible explicitly */
+ visibility: hidden;
+ }
+
+ #status-progress {
+ width: 366px;
+ height: 7px;
+ background-color: #38363A;
+ border: 1px solid #444246;
+ padding: 1px;
+ box-shadow: 0 0 2px 1px #1B1C22;
+ border-radius: 2px;
+ visibility: visible;
+ }
+
+ @media only screen and (orientation:portrait) {
+ #status-progress {
+ width: 61.8%;
+ }
+ }
+
+ #status-progress-inner {
+ height: 100%;
+ width: 0;
+ box-sizing: border-box;
+ transition: width 0.5s linear;
+ background-color: #202020;
+ border: 1px solid #222223;
+ box-shadow: 0 0 1px 1px #27282E;
+ border-radius: 3px;
+ }
+
+ #status-indeterminate {
+ visibility: visible;
+ position: relative;
+ }
+
+ #status-indeterminate > div {
+ width: 4.5px;
+ height: 0;
+ border-style: solid;
+ border-width: 9px 3px 0 3px;
+ border-color: #2b2b2b transparent transparent transparent;
+ transform-origin: center 21px;
+ position: absolute;
+ }
+
+ #status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
+ #status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
+ #status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
+ #status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
+ #status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
+ #status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
+ #status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
+ #status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
+
+ #status-notice {
+ margin: 0 100px;
+ line-height: 1.3;
+ visibility: visible;
+ padding: 4px 6px;
+ visibility: visible;
+ }
+ </style>
+</head>
+<body>
+ <div id="tabs-buttons">
+ <button id="btn-tab-loader" class="tab-btn" onclick="showTab('loader')">Loader</button>
+ <button id="btn-tab-editor" class="tab-btn" disabled="disabled" onclick="showTab('editor')">Editor</button>
+ <button id="btn-close-editor" class="close-btn" disabled="disabled" onclick="closeEditor()">X</button>
+ <button id="btn-tab-game" class="tab-btn" disabled="disabled" onclick="showTab('game')">Game</button>
+ <button id="btn-close-game" class="close-btn" disabled="disabled" onclick="closeGame()">X</button>
+ </div>
+ <div id='tabs'>
+ <div id='tab-loader'>
+ <div style="color: white;" id="persistence">
+ <label for="videoMode" style="display: none;">Select video driver:</label><br />
+ <select id="videoMode" style="display: none;">
+ <option value="GLES2" selected="selected">WebGL</option>
+ <option value="GLES3">WebGL 2</option>
+ </select>
+ <br />
+ <label for="zip-file">Preload project zip: </label><input id="zip-file" type="file" id="files" name="files"/>
+ <br />
+ <button id="startButton">Start Godot Editor</button>
+ <br />
+ <br />
+ <button onclick="clearPersistence()">Clear persistent data</button>
+ </div>
+ </div>
+ <div id='tab-editor' style="display: none;">
+ <canvas id='editor-canvas' tabindex="1">
+ HTML5 canvas appears to be unsupported in the current browser.<br />
+ Please try updating or use a different browser.
+ </canvas>
+ </div>
+ <div id='tab-game' style="display: none;">
+ <canvas id='game-canvas' tabindex="2">
+ HTML5 canvas appears to be unsupported in the current browser.<br />
+ Please try updating or use a different browser.
+ </canvas>
+ </div>
+ <div id='tab-status' style="display: none;">
+ <div id='status-progress' style='display: none;' oncontextmenu='event.preventDefault();'><div id ='status-progress-inner'></div></div>
+ <div id='status-indeterminate' style='display: none;' oncontextmenu='event.preventDefault();'>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ </div>
+ <div id='status-notice' class='godot' style='display: none;'></div>
+ </div>
+ </div>
+
+ <script type='text/javascript' src='godot.tools.js'></script>
+ <script type='text/javascript'>//<![CDATA[
+
+ var engine = new Engine;
+ var game = null;
+ var setStatusMode;
+ var setStatusNotice;
+ var video_driver = "GLES2";
+
+ function clearPersistence() {
+ function deleteDB(path) {
+ return new Promise(function(resolve, reject) {
+ var req = indexedDB.deleteDatabase(path);
+ req.onsuccess = function() {
+ resolve();
+ };
+ req.onerror = function(err) {
+ reject(err);
+ };
+ req.onblocked = function(err) {
+ reject(err);
+ }
+
+ });
+ }
+ if (!window.confirm("Are you sure you want to delete all the locally stored files?")) {
+ return;
+ }
+ Promise.all([
+ deleteDB("/home/web_user/projects"),
+ deleteDB("/home/web_user/.config")
+ ]).then(function(results) {
+ alert("Done.");
+ }).catch(function (err) {
+ alert("Error deleting local files. Please retry after reloading the page.");
+ });
+ }
+
+ function selectVideoMode() {
+ var select = document.getElementById('videoMode');
+ video_driver = select.selectedOptions[0].value;
+ }
+
+ var tabs = [
+ document.getElementById('tab-loader'),
+ document.getElementById('tab-editor'),
+ document.getElementById('tab-game')
+ ]
+ function showTab(name) {
+ tabs.forEach(function (elem) {
+ if (elem.id == 'tab-' + name) {
+ elem.style.display = 'block';
+ } else {
+ elem.style.display = 'none';
+ }
+ });
+ }
+
+ function setButtonEnabled(id, enabled) {
+ if (enabled) {
+ document.getElementById(id).disabled = "";
+ } else {
+ document.getElementById(id).disabled = "disabled";
+ }
+ }
+
+ function setLoaderEnabled(enabled) {
+ setButtonEnabled('btn-tab-loader', enabled);
+ setButtonEnabled('btn-tab-editor', !enabled);
+ setButtonEnabled('btn-close-editor', !enabled);
+ }
+
+ function setGameTabEnabled(enabled) {
+ setButtonEnabled('btn-tab-game', enabled);
+ setButtonEnabled('btn-close-game', enabled);
+ }
+
+ function closeGame() {
+ if (game) {
+ game.requestQuit();
+ }
+ }
+
+ function closeEditor() {
+ closeGame();
+ if (engine) {
+ engine.requestQuit();
+ }
+ }
+
+ function startEditor(zip) {
+
+ const INDETERMINATE_STATUS_STEP_MS = 100;
+ const persistentPaths = ['/home/web_user/.config', '/home/web_user/projects'];
+
+ var editorCanvas = document.getElementById('editor-canvas');
+ var gameCanvas = document.getElementById('game-canvas');
+ var statusProgress = document.getElementById('status-progress');
+ var statusProgressInner = document.getElementById('status-progress-inner');
+ var statusIndeterminate = document.getElementById('status-indeterminate');
+ var statusNotice = document.getElementById('status-notice');
+
+ var initializing = true;
+ var statusMode = 'hidden';
+
+ showTab('status');
+
+ var animationCallbacks = [];
+ function animate(time) {
+ animationCallbacks.forEach(callback => callback(time));
+ requestAnimationFrame(animate);
+ }
+ requestAnimationFrame(animate);
+
+ function adjustCanvasDimensions() {
+ var scale = window.devicePixelRatio || 1;
+ var header = document.getElementById('tabs-buttons');
+ var headerHeight = header.offsetHeight + 1;
+ var width = window.innerWidth;
+ var height = window.innerHeight - headerHeight;
+ editorCanvas.width = width * scale;
+ editorCanvas.height = height * scale;
+ editorCanvas.style.width = width + "px";
+ editorCanvas.style.height = height + "px";
+ }
+ animationCallbacks.push(adjustCanvasDimensions);
+ adjustCanvasDimensions();
+
+ setStatusMode = function setStatusMode(mode) {
+
+ if (statusMode === mode || !initializing)
+ return;
+ [statusProgress, statusIndeterminate, statusNotice].forEach(elem => {
+ elem.style.display = 'none';
+ });
+ animationCallbacks = animationCallbacks.filter(function(value) {
+ return (value != animateStatusIndeterminate);
+ });
+ switch (mode) {
+ case 'progress':
+ statusProgress.style.display = 'block';
+ break;
+ case 'indeterminate':
+ statusIndeterminate.style.display = 'block';
+ animationCallbacks.push(animateStatusIndeterminate);
+ break;
+ case 'notice':
+ statusNotice.style.display = 'block';
+ break;
+ case 'hidden':
+ break;
+ default:
+ throw new Error('Invalid status mode');
+ }
+ statusMode = mode;
+ }
+
+ function animateStatusIndeterminate(ms) {
+
+ var i = Math.floor(ms / INDETERMINATE_STATUS_STEP_MS % 8);
+ if (statusIndeterminate.children[i].style.borderTopColor == '') {
+ Array.prototype.slice.call(statusIndeterminate.children).forEach(child => {
+ child.style.borderTopColor = '';
+ });
+ statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
+ }
+ }
+
+ setStatusNotice = function setStatusNotice(text) {
+
+ while (statusNotice.lastChild) {
+ statusNotice.removeChild(statusNotice.lastChild);
+ }
+ var lines = text.split('\n');
+ lines.forEach((line) => {
+ statusNotice.appendChild(document.createTextNode(line));
+ statusNotice.appendChild(document.createElement('br'));
+ });
+ };
+
+ engine.setProgressFunc((current, total) => {
+
+ if (total > 0) {
+ statusProgressInner.style.width = current/total * 100 + '%';
+ setStatusMode('progress');
+ if (current === total) {
+ // wait for progress bar animation
+ setTimeout(() => {
+ setStatusMode('indeterminate');
+ }, 100);
+ }
+ } else {
+ setStatusMode('indeterminate');
+ }
+ });
+
+ engine.setPersistentPaths(persistentPaths);
+
+ engine.setOnExecute(function(args) {
+ const is_editor = args.filter(function(v) { return v == '--editor' || v == '-e' }).length != 0;
+ const is_project_manager = args.filter(function(v) { return v == '--project-manager' }).length != 0;
+ const is_game = !is_editor && !is_project_manager;
+ if (is_project_manager) {
+ args.push('--video-driver', video_driver);
+ }
+ if (is_game) {
+ if (game) {
+ console.error("A game is already running. Close it first");
+ return;
+ }
+ setGameTabEnabled(true);
+ game = new Engine();
+ game.setPersistentPaths(persistentPaths);
+ game.setUnloadAfterInit(false);
+ game.setOnExecute(engine.onExecute);
+ game.setCanvas(gameCanvas);
+ game.setCanvasResizedOnStart(true);
+ game.setOnExit(function() {
+ setGameTabEnabled(false);
+ showTab('editor');
+ game = null;
+ });
+ showTab('game');
+ game.init().then(function() {
+ requestAnimationFrame(function() {
+ game.start.apply(game, args).then(function() {
+ gameCanvas.focus();
+ });
+ });
+ });
+ } else { // New editor instances will be run in the same canvas. We want to wait for it to exit.
+ engine.setOnExit(function(code) {
+ setLoaderEnabled(true);
+ setTimeout(function() {
+ engine.init().then(function() {
+ setLoaderEnabled(false);
+ engine.setOnExit(function() {
+ showTab('loader');
+ setLoaderEnabled(true);
+ });
+ engine.start.apply(engine, args);
+ });
+ }, 0);
+ engine.setOnExit(null);
+ });
+ }
+ });
+
+ function displayFailureNotice(err) {
+ var msg = err.message || err;
+ console.error(msg);
+ setStatusNotice(msg);
+ setStatusMode('notice');
+ initializing = false;
+ };
+
+ if (!Engine.isWebGLAvailable()) {
+ displayFailureNotice('WebGL not available');
+ } else {
+ setStatusMode('indeterminate');
+ engine.setCanvas(editorCanvas);
+ engine.setUnloadAfterInit(false); // Don't want to reload when starting game.
+ engine.init('godot.tools').then(function() {
+ if (zip) {
+ engine.copyToFS("/home/web_user/preload.zip", zip);
+ }
+ try {
+ // Avoid user creating project in the persistent root folder.
+ engine.copyToFS("/home/web_user/projects/keep", new Uint8Array());
+ } catch(e) {
+ // File exists
+ }
+ //selectVideoMode();
+ showTab('editor');
+ setLoaderEnabled(false);
+ engine.setOnExit(function() {
+ showTab('loader');
+ setLoaderEnabled(true);
+ });
+ engine.start('--video-driver', video_driver).then(function() {
+ setStatusMode('hidden');
+ initializing = false;
+ });
+ }).catch(displayFailureNotice);
+ }
+ };
+ document.getElementById("startButton").onclick = function() {
+ preloadZip(document.getElementById('zip-file')).then(function(zip) {
+ startEditor(zip);
+ });
+ }
+
+ function preloadZip(target) {
+ return new Promise(function(resolve, reject) {
+ if (target.files.length > 0) {
+ target.files[0].arrayBuffer().then(function(data) {
+ resolve(data);
+ });
+ } else {
+ resolve();
+ }
+ });
+ }
+ //]]></script>
+</body>
+</html>
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp
index 76c0e0e607..eb599df74c 100644
--- a/modules/bullet/rigid_body_bullet.cpp
+++ b/modules/bullet/rigid_body_bullet.cpp
@@ -264,6 +264,7 @@ RigidBodyBullet::RigidBodyBullet() :
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, godotMotionState, nullptr, localInertia);
btBody = bulletnew(btRigidBody(cInfo));
+ btBody->setFriction(1.0);
reload_shapes();
setupBulletCollisionObject(btBody);
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index fc27892099..e170667a30 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -7,6 +7,7 @@
List of core built-in GDScript functions. Math functions and other utilities. Everything else is provided by objects. (Keywords: builtin, built in, global functions.)
</description>
<tutorials>
+ <link title="Random number generation">https://docs.godotengine.org/en/latest/tutorials/math/random_number_generation.html</link>
</tutorials>
<methods>
<method name="Color8">
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index 8f0ce99de6..eabf53581d 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -529,6 +529,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
append(p_arguments[i]);
}
append(p_target);
+ alloc_call(p_arguments.size());
}
void GDScriptByteCodeGenerator::write_construct_array(const Address &p_target, const Vector<Address> &p_arguments) {
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index a05b38b8bf..70b731d611 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -975,7 +975,6 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
script->signals_invalidated = true;
script->reload(p_soft_reload);
- script->update_exports();
if (!script->valid) {
script->pending_reload_instances.clear();
@@ -2955,13 +2954,24 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon
CRASH_COND(p_script->native == nullptr);
+ p_script->valid = true;
+
+ update_script_class_info(p_script);
+
+#ifdef TOOLS_ENABLED
+ p_script->_update_member_info_no_exports();
+#endif
+}
+
+// Extract information about the script using the mono class.
+void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) {
GDMonoClass *base = p_script->script_class->get_parent_class();
+ // `base` should only be set if the script is a user defined type.
if (base != p_script->native) {
p_script->base = base;
}
- p_script->valid = true;
p_script->tool = p_script->script_class->has_attribute(CACHED_CLASS(ToolAttribute));
if (!p_script->tool) {
@@ -2996,17 +3006,74 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon
p_script->script_class->fetch_methods_with_godot_api_checks(p_script->native);
- // Need to fetch method from base classes as well
+ p_script->rpc_functions.clear();
+ p_script->rpc_variables.clear();
+
GDMonoClass *top = p_script->script_class;
while (top && top != p_script->native) {
+ // Fetch methods from base classes as well
top->fetch_methods_with_godot_api_checks(p_script->native);
+
+ // Update RPC info
+ {
+ Vector<GDMonoMethod *> methods = top->get_all_methods();
+ for (int i = 0; i < methods.size(); i++) {
+ if (!methods[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = p_script->_member_get_rpc_mode(methods[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = methods[i]->get_name();
+ nd.mode = mode;
+ if (-1 == p_script->rpc_functions.find(nd)) {
+ p_script->rpc_functions.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ {
+ Vector<GDMonoField *> fields = top->get_all_fields();
+ for (int i = 0; i < fields.size(); i++) {
+ if (!fields[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = p_script->_member_get_rpc_mode(fields[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = fields[i]->get_name();
+ nd.mode = mode;
+ if (-1 == p_script->rpc_variables.find(nd)) {
+ p_script->rpc_variables.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ {
+ Vector<GDMonoProperty *> properties = top->get_all_properties();
+ for (int i = 0; i < properties.size(); i++) {
+ if (!properties[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = p_script->_member_get_rpc_mode(properties[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = properties[i]->get_name();
+ nd.mode = mode;
+ if (-1 == p_script->rpc_variables.find(nd)) {
+ p_script->rpc_variables.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
top = top->get_parent_class();
}
+ // Sort so we are 100% that they are always the same.
+ p_script->rpc_functions.sort_custom<SortNetData>();
+ p_script->rpc_variables.sort_custom<SortNetData>();
+
p_script->load_script_signals(p_script->script_class, p_script->native);
-#ifdef TOOLS_ENABLED
- p_script->_update_member_info_no_exports();
-#endif
}
bool CSharpScript::can_instance() const {
@@ -3305,124 +3372,15 @@ Error CSharpScript::reload(bool p_keep_state) {
print_verbose("Found class " + script_class->get_full_name() + " for script " + get_path());
#endif
- tool = script_class->has_attribute(CACHED_CLASS(ToolAttribute));
-
- if (!tool) {
- GDMonoClass *nesting_class = script_class->get_nesting_class();
- tool = nesting_class && nesting_class->has_attribute(CACHED_CLASS(ToolAttribute));
- }
-
-#if TOOLS_ENABLED
- if (!tool) {
- tool = script_class->get_assembly() == GDMono::get_singleton()->get_tools_assembly();
- }
-#endif
-
native = GDMonoUtils::get_class_native_base(script_class);
CRASH_COND(native == nullptr);
- GDMonoClass *base_class = script_class->get_parent_class();
-
- if (base_class != native) {
- base = base_class;
- }
-
-#ifdef DEBUG_ENABLED
- // For debug builds, we must fetch from all native base methods as well.
- // Native base methods must be fetched before the current class.
- // Not needed if the script class itself is a native class.
+ update_script_class_info(this);
- if (script_class != native) {
- GDMonoClass *native_top = native;
- while (native_top) {
- native_top->fetch_methods_with_godot_api_checks(native);
-
- if (native_top == CACHED_CLASS(GodotObject)) {
- break;
- }
-
- native_top = native_top->get_parent_class();
- }
- }
-#endif
-
- script_class->fetch_methods_with_godot_api_checks(native);
-
- // Need to fetch method from base classes as well
- GDMonoClass *top = script_class;
- while (top && top != native) {
- top->fetch_methods_with_godot_api_checks(native);
- top = top->get_parent_class();
- }
-
- load_script_signals(script_class, native);
_update_exports();
}
- rpc_functions.clear();
- rpc_variables.clear();
-
- GDMonoClass *top = script_class;
- while (top && top != native) {
- {
- Vector<GDMonoMethod *> methods = top->get_all_methods();
- for (int i = 0; i < methods.size(); i++) {
- if (!methods[i]->is_static()) {
- MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(methods[i]);
- if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
- ScriptNetData nd;
- nd.name = methods[i]->get_name();
- nd.mode = mode;
- if (-1 == rpc_functions.find(nd)) {
- rpc_functions.push_back(nd);
- }
- }
- }
- }
- }
-
- {
- Vector<GDMonoField *> fields = top->get_all_fields();
- for (int i = 0; i < fields.size(); i++) {
- if (!fields[i]->is_static()) {
- MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(fields[i]);
- if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
- ScriptNetData nd;
- nd.name = fields[i]->get_name();
- nd.mode = mode;
- if (-1 == rpc_variables.find(nd)) {
- rpc_variables.push_back(nd);
- }
- }
- }
- }
- }
-
- {
- Vector<GDMonoProperty *> properties = top->get_all_properties();
- for (int i = 0; i < properties.size(); i++) {
- if (!properties[i]->is_static()) {
- MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(properties[i]);
- if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
- ScriptNetData nd;
- nd.name = properties[i]->get_name();
- nd.mode = mode;
- if (-1 == rpc_variables.find(nd)) {
- rpc_variables.push_back(nd);
- }
- }
- }
- }
- }
-
- top = top->get_parent_class();
- }
-
- // Sort so we are 100% that they are always the same.
- rpc_functions.sort_custom<SortNetData>();
- rpc_variables.sort_custom<SortNetData>();
-
return OK;
}
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index f0b43a40f9..cfe070a371 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -164,6 +164,7 @@ private:
// Do not use unless you know what you are doing
friend void GDMonoInternals::tie_managed_to_unmanaged(MonoObject *, Object *);
static Ref<CSharpScript> create_for_managed_type(GDMonoClass *p_class, GDMonoClass *p_native);
+ static void update_script_class_info(Ref<CSharpScript> p_script);
static void initialize_for_managed_type(Ref<CSharpScript> p_script, GDMonoClass *p_class, GDMonoClass *p_native);
MultiplayerAPI::RPCMode _member_get_rpc_mode(IMonoClassMember *p_member) const;
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.nuspec b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.nuspec
index 5b5cefe80e..ba68a4da43 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.nuspec
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.nuspec
@@ -17,6 +17,6 @@
<repository url="$projecturl$" />
</metadata>
<files>
- <file src="Sdk\**" target="Sdk" />\
+ <file src="Sdk\**" target="Sdk" />
</files>
</package>
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
index 7bfba779fb..93aae2e03e 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
@@ -119,7 +119,7 @@ namespace GodotTools.Build
{
var result = new List<string>();
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
result.Add("/Library/Frameworks/Mono.framework/Versions/Current/bin/");
result.Add("/usr/local/var/homebrew/linked/mono/bin/");
diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs b/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs
index 42ede3f3f3..5bb8d444c2 100755
--- a/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs
@@ -120,7 +120,7 @@ namespace GodotTools.Export
string assemblyPath = assembly.Value;
string outputFileExtension = platform == OS.Platforms.Windows ? ".dll" :
- platform == OS.Platforms.OSX ? ".dylib" :
+ platform == OS.Platforms.MacOS ? ".dylib" :
".so";
string outputFileName = assemblyName + ".dll" + outputFileExtension;
@@ -132,7 +132,7 @@ namespace GodotTools.Export
ExecuteCompiler(FindCrossCompiler(compilerDirPath), compilerArgs, bclDir);
- if (platform == OS.Platforms.OSX)
+ if (platform == OS.Platforms.MacOS)
{
exporter.AddSharedObject(tempOutputFilePath, tags: null);
}
@@ -581,7 +581,7 @@ MONO_AOT_MODE_LAST = 1000,
string arch = bits == "64" ? "x86_64" : "i686";
return $"windows-{arch}";
}
- case OS.Platforms.OSX:
+ case OS.Platforms.MacOS:
{
Debug.Assert(bits == null || bits == "64");
string arch = "x86_64";
diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
index 599ca94699..cd188509b4 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
@@ -340,7 +340,7 @@ namespace GodotTools.Export
private static bool PlatformHasTemplateDir(string platform)
{
// OSX export templates are contained in a zip, so we place our custom template inside it and let Godot do the rest.
- return !new[] {OS.Platforms.OSX, OS.Platforms.Android, OS.Platforms.iOS, OS.Platforms.HTML5}.Contains(platform);
+ return !new[] {OS.Platforms.MacOS, OS.Platforms.Android, OS.Platforms.iOS, OS.Platforms.HTML5}.Contains(platform);
}
private static bool DeterminePlatformFromFeatures(IEnumerable<string> features, out string platform)
@@ -411,7 +411,7 @@ namespace GodotTools.Export
case OS.Platforms.Windows:
case OS.Platforms.UWP:
return "net_4_x_win";
- case OS.Platforms.OSX:
+ case OS.Platforms.MacOS:
case OS.Platforms.LinuxBSD:
case OS.Platforms.Server:
case OS.Platforms.Haiku:
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
index 2a450c5b87..57d334b93e 100644
--- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
@@ -272,7 +272,7 @@ namespace GodotTools
bool osxAppBundleInstalled = false;
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
// The package path is '/Applications/Visual Studio Code.app'
const string vscodeBundleId = "com.microsoft.VSCode";
@@ -312,7 +312,7 @@ namespace GodotTools
string command;
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
if (!osxAppBundleInstalled && string.IsNullOrEmpty(_vsCodePath))
{
@@ -504,7 +504,7 @@ namespace GodotTools
$",Visual Studio Code:{(int)ExternalEditorId.VsCode}" +
$",JetBrains Rider:{(int)ExternalEditorId.Rider}";
}
- else if (OS.IsOSX)
+ else if (OS.IsMacOS)
{
settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" +
$",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
index e4932ca217..451ce39f5c 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
@@ -111,7 +111,7 @@ namespace GodotTools.Ides
{
MonoDevelop.Instance GetMonoDevelopInstance(string solutionPath)
{
- if (Utils.OS.IsOSX && editorId == ExternalEditorId.VisualStudioForMac)
+ if (Utils.OS.IsMacOS && editorId == ExternalEditorId.VisualStudioForMac)
{
vsForMacInstance = (vsForMacInstance?.IsDisposed ?? true ? null : vsForMacInstance) ??
new MonoDevelop.Instance(solutionPath, MonoDevelop.EditorId.VisualStudioForMac);
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
index d6fa2eeba7..fd7bbd5578 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
@@ -26,7 +26,7 @@ namespace GodotTools.Ides.MonoDevelop
string command;
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
string bundleId = BundleIds[editorId];
@@ -85,7 +85,7 @@ namespace GodotTools.Ides.MonoDevelop
public Instance(string solutionFile, EditorId editorId)
{
- if (editorId == EditorId.VisualStudioForMac && !OS.IsOSX)
+ if (editorId == EditorId.VisualStudioForMac && !OS.IsMacOS)
throw new InvalidOperationException($"{nameof(EditorId.VisualStudioForMac)} not supported on this platform");
this.solutionFile = solutionFile;
@@ -103,7 +103,7 @@ namespace GodotTools.Ides.MonoDevelop
static Instance()
{
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
ExecutableNames = new Dictionary<EditorId, string>
{
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
index e22e9af919..94fc5da425 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
@@ -32,7 +32,7 @@ namespace GodotTools.Ides.Rider
{
return CollectRiderInfosWindows();
}
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
return CollectRiderInfosMac();
}
@@ -138,7 +138,7 @@ namespace GodotTools.Ides.Rider
return GetToolboxRiderRootPath(localAppData);
}
- if (OS.IsOSX)
+ if (OS.IsMacOS)
{
var home = Environment.GetEnvironmentVariable("HOME");
if (string.IsNullOrEmpty(home))
@@ -211,7 +211,7 @@ namespace GodotTools.Ides.Rider
{
if (OS.IsWindows || OS.IsUnixLike)
return "../../build.txt";
- if (OS.IsOSX)
+ if (OS.IsMacOS)
return "Contents/Resources/build.txt";
throw new Exception("Unknown OS.");
}
diff --git a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
index 6c05891f2c..e745966435 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
@@ -21,7 +21,7 @@ namespace GodotTools.Utils
public static class Names
{
public const string Windows = "Windows";
- public const string OSX = "OSX";
+ public const string MacOS = "macOS";
public const string Linux = "Linux";
public const string FreeBSD = "FreeBSD";
public const string NetBSD = "NetBSD";
@@ -37,7 +37,7 @@ namespace GodotTools.Utils
public static class Platforms
{
public const string Windows = "windows";
- public const string OSX = "osx";
+ public const string MacOS = "osx";
public const string LinuxBSD = "linuxbsd";
public const string Server = "server";
public const string UWP = "uwp";
@@ -50,7 +50,7 @@ namespace GodotTools.Utils
public static readonly Dictionary<string, string> PlatformNameMap = new Dictionary<string, string>
{
[Names.Windows] = Platforms.Windows,
- [Names.OSX] = Platforms.OSX,
+ [Names.MacOS] = Platforms.MacOS,
[Names.Linux] = Platforms.LinuxBSD,
[Names.FreeBSD] = Platforms.LinuxBSD,
[Names.NetBSD] = Platforms.LinuxBSD,
@@ -77,11 +77,11 @@ namespace GodotTools.Utils
new[] {Names.Linux, Names.FreeBSD, Names.NetBSD, Names.BSD};
private static readonly IEnumerable<string> UnixLikePlatforms =
- new[] {Names.OSX, Names.Server, Names.Haiku, Names.Android, Names.iOS}
+ new[] {Names.MacOS, Names.Server, Names.Haiku, Names.Android, Names.iOS}
.Concat(LinuxBSDPlatforms).ToArray();
private static readonly Lazy<bool> _isWindows = new Lazy<bool>(() => IsOS(Names.Windows));
- private static readonly Lazy<bool> _isOSX = new Lazy<bool>(() => IsOS(Names.OSX));
+ private static readonly Lazy<bool> _isMacOS = new Lazy<bool>(() => IsOS(Names.MacOS));
private static readonly Lazy<bool> _isLinuxBSD = new Lazy<bool>(() => IsAnyOS(LinuxBSDPlatforms));
private static readonly Lazy<bool> _isServer = new Lazy<bool>(() => IsOS(Names.Server));
private static readonly Lazy<bool> _isUWP = new Lazy<bool>(() => IsOS(Names.UWP));
@@ -92,7 +92,7 @@ namespace GodotTools.Utils
private static readonly Lazy<bool> _isUnixLike = new Lazy<bool>(() => IsAnyOS(UnixLikePlatforms));
public static bool IsWindows => _isWindows.Value || IsUWP;
- public static bool IsOSX => _isOSX.Value;
+ public static bool IsMacOS => _isMacOS.Value;
public static bool IsLinuxBSD => _isLinuxBSD.Value;
public static bool IsServer => _isServer.Value;
public static bool IsUWP => _isUWP.Value;
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index f13377f3c8..68de686272 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -2088,6 +2088,7 @@ void VisualScriptPropertyGet::_bind_methods() {
BIND_ENUM_CONSTANT(CALL_MODE_SELF);
BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH);
BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE);
+ BIND_ENUM_CONSTANT(CALL_MODE_BASIC_TYPE);
}
class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml
index c80b903e39..e21dee8eff 100644
--- a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml
+++ b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml
@@ -40,7 +40,6 @@
<argument index="0" name="label" type="String">
</argument>
<argument index="1" name="options" type="Dictionary" default="{
-
}">
</argument>
<description>
@@ -82,7 +81,6 @@
<return type="int" enum="Error">
</return>
<argument index="0" name="configuration" type="Dictionary" default="{
-
}">
</argument>
<description>
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index a8861124b9..7381ea13b7 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -9,6 +9,7 @@ javascript_files = [
"javascript_eval.cpp",
"javascript_main.cpp",
"os_javascript.cpp",
+ "api/javascript_tools_editor_plugin.cpp",
]
build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
@@ -55,7 +56,7 @@ out_files = [
zip_dir.File(binary_name + ".wasm"),
zip_dir.File(binary_name + ".html"),
]
-html_file = "#misc/dist/html/full-size.html"
+html_file = "#misc/dist/html/editor.html" if env["tools"] else "#misc/dist/html/full-size.html"
in_files = [js_wrapped, build[1], html_file]
if env["threads_enabled"]:
in_files.append(build[2])
diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp
index 9c73e5c4c4..aa0206d144 100644
--- a/platform/javascript/api/api.cpp
+++ b/platform/javascript/api/api.cpp
@@ -31,10 +31,12 @@
#include "api.h"
#include "core/engine.h"
#include "javascript_eval.h"
+#include "javascript_tools_editor_plugin.h"
static JavaScript *javascript_eval;
void register_javascript_api() {
+ JavaScriptToolsEditorPlugin::initialize();
ClassDB::register_virtual_class<JavaScript>();
javascript_eval = memnew(JavaScript);
Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_eval));
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp
new file mode 100644
index 0000000000..e487bf23b7
--- /dev/null
+++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp
@@ -0,0 +1,153 @@
+/*************************************************************************/
+/* javascript_tools_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED)
+#include "javascript_tools_editor_plugin.h"
+
+#include "core/engine.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/project_settings.h"
+#include "editor/editor_node.h"
+
+#include <emscripten/emscripten.h>
+
+static void _javascript_editor_init_callback() {
+ EditorNode::get_singleton()->add_editor_plugin(memnew(JavaScriptToolsEditorPlugin(EditorNode::get_singleton())));
+}
+
+void JavaScriptToolsEditorPlugin::initialize() {
+ EditorNode::add_init_callback(_javascript_editor_init_callback);
+}
+
+JavaScriptToolsEditorPlugin::JavaScriptToolsEditorPlugin(EditorNode *p_editor) {
+ Variant v;
+ add_tool_menu_item("Download Project Source", this, "_download_zip", v);
+}
+
+void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
+ if (!Engine::get_singleton() || !Engine::get_singleton()->is_editor_hint()) {
+ WARN_PRINT("Project download is only available in Editor mode");
+ return;
+ }
+ String resource_path = ProjectSettings::get_singleton()->get_resource_path();
+
+ FileAccess *src_f;
+ zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
+ zipFile zip = zipOpen2("/tmp/project.zip", APPEND_STATUS_CREATE, NULL, &io);
+ String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
+ _zip_recursive(resource_path, base_path, zip);
+ zipClose(zip, NULL);
+ EM_ASM({
+ const path = "/tmp/project.zip";
+ const size = FS.stat(path)["size"];
+ const buf = new Uint8Array(size);
+ const fd = FS.open(path, "r");
+ FS.read(fd, buf, 0, size);
+ FS.close(fd);
+ FS.unlink(path);
+ const blob = new Blob([buf], { type: "application/zip" });
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = "project.zip";
+ a.style.display = "none";
+ document.body.appendChild(a);
+ a.click();
+ a.remove();
+ window.URL.revokeObjectURL(url);
+ });
+}
+
+void JavaScriptToolsEditorPlugin::_bind_methods() {
+ ClassDB::bind_method("_download_zip", &JavaScriptToolsEditorPlugin::_download_zip);
+}
+
+void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) {
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
+ if (!f) {
+ WARN_PRINT("Unable to open file for zipping: " + p_path);
+ return;
+ }
+ Vector<uint8_t> data;
+ int len = f->get_len();
+ data.resize(len);
+ f->get_buffer(data.ptrw(), len);
+ f->close();
+ memdelete(f);
+
+ String path = p_path.replace_first(p_base_path, "");
+ zipOpenNewFileInZip(p_zip,
+ path.utf8().get_data(),
+ NULL,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION);
+ zipWriteInFileInZip(p_zip, data.ptr(), data.size());
+ zipCloseFileInZip(p_zip);
+}
+
+void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) {
+ DirAccess *dir = DirAccess::open(p_path);
+ if (!dir) {
+ WARN_PRINT("Unable to open dir for zipping: " + p_path);
+ return;
+ }
+ dir->list_dir_begin();
+ String cur = dir->get_next();
+ while (!cur.empty()) {
+ String cs = p_path.plus_file(cur);
+ if (cur == "." || cur == ".." || cur == ".import") {
+ // Skip
+ } else if (dir->current_is_dir()) {
+ String path = cs.replace_first(p_base_path, "") + "/";
+ zipOpenNewFileInZip(p_zip,
+ path.utf8().get_data(),
+ NULL,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION);
+ zipCloseFileInZip(p_zip);
+ _zip_recursive(cs, p_base_path, p_zip);
+ } else {
+ _zip_file(cs, p_base_path, p_zip);
+ }
+ cur = dir->get_next();
+ }
+}
+#endif
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.h b/platform/javascript/api/javascript_tools_editor_plugin.h
new file mode 100644
index 0000000000..cc09fa4cd3
--- /dev/null
+++ b/platform/javascript/api/javascript_tools_editor_plugin.h
@@ -0,0 +1,62 @@
+/*************************************************************************/
+/* javascript_tools_editor_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
+#define JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
+
+#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED)
+#include "core/io/zip_io.h"
+#include "editor/editor_plugin.h"
+
+class JavaScriptToolsEditorPlugin : public EditorPlugin {
+ GDCLASS(JavaScriptToolsEditorPlugin, EditorPlugin);
+
+private:
+ void _zip_file(String p_path, String p_base_path, zipFile p_zip);
+ void _zip_recursive(String p_path, String p_base_path, zipFile p_zip);
+
+protected:
+ static void _bind_methods();
+
+ void _download_zip(Variant p_v);
+
+public:
+ static void initialize();
+
+ JavaScriptToolsEditorPlugin(EditorNode *p_editor);
+};
+#else
+class JavaScriptToolsEditorPlugin {
+public:
+ static void initialize() {}
+};
+#endif
+
+#endif // JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 4b5890545f..8f2961b33d 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -135,7 +135,7 @@ def configure(env):
env.Append(CPPDEFINES=["PTHREAD_NO_RENAME"])
env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"])
env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"])
- env.Append(LINKFLAGS=["-s", "PTHREAD_POOL_SIZE=4"])
+ env.Append(LINKFLAGS=["-s", "PTHREAD_POOL_SIZE=8"])
env.Append(LINKFLAGS=["-s", "WASM_MEM_MAX=2048MB"])
env.extra_suffix = ".threads" + env.extra_suffix
else:
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js
index adcd919a6b..05a11701c0 100644
--- a/platform/javascript/engine/engine.js
+++ b/platform/javascript/engine/engine.js
@@ -121,6 +121,7 @@ Function('return this')()['Engine'] = (function() {
me.rtenv['noExitRuntime'] = true;
me.rtenv['onExecute'] = me.onExecute;
me.rtenv['onExit'] = function(code) {
+ me.rtenv['deinitFS']();
if (me.onExit)
me.onExit(code);
me.rtenv = null;
@@ -227,6 +228,12 @@ Function('return this')()['Engine'] = (function() {
this.persistentPaths = persistentPaths;
};
+ Engine.prototype.requestQuit = function() {
+ if (this.rtenv) {
+ this.rtenv['request_quit']();
+ }
+ };
+
// Closure compiler exported engine methods.
/** @export */
Engine['isWebGLAvailable'] = Utils.isWebGLAvailable;
@@ -249,5 +256,6 @@ Function('return this')()['Engine'] = (function() {
Engine.prototype['setOnExit'] = Engine.prototype.setOnExit;
Engine.prototype['copyToFS'] = Engine.prototype.copyToFS;
Engine.prototype['setPersistentPaths'] = Engine.prototype.setPersistentPaths;
+ Engine.prototype['requestQuit'] = Engine.prototype.requestQuit;
return Engine;
})();
diff --git a/platform/javascript/native/utils.js b/platform/javascript/native/utils.js
index 0b3698fd86..8d0beba454 100644
--- a/platform/javascript/native/utils.js
+++ b/platform/javascript/native/utils.js
@@ -29,8 +29,7 @@
/*************************************************************************/
Module['initFS'] = function(persistentPaths) {
- FS.mkdir('/userfs');
- FS.mount(IDBFS, {}, '/userfs');
+ Module.mount_points = ['/userfs'].concat(persistentPaths);
function createRecursive(dir) {
try {
@@ -43,13 +42,14 @@ Module['initFS'] = function(persistentPaths) {
}
}
- persistentPaths.forEach(function(path) {
+ Module.mount_points.forEach(function(path) {
createRecursive(path);
FS.mount(IDBFS, {}, path);
});
return new Promise(function(resolve, reject) {
FS.syncfs(true, function(err) {
if (err) {
+ Module.mount_points = [];
Module.idbfs = false;
console.log("IndexedDB not available: " + err.message);
} else {
@@ -60,6 +60,21 @@ Module['initFS'] = function(persistentPaths) {
});
};
+Module['deinitFS'] = function() {
+ Module.mount_points.forEach(function(path) {
+ try {
+ FS.unmount(path);
+ } catch (e) {
+ console.log("Already unmounted", e);
+ }
+ if (Module.idbfs && IDBFS.dbs[path]) {
+ IDBFS.dbs[path].close();
+ delete IDBFS.dbs[path];
+ }
+ });
+ Module.mount_points = [];
+};
+
Module['copyToFS'] = function(path, buffer) {
var p = path.lastIndexOf("/");
var dir = "/";
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp
index 8b0d08d1cb..176878bc12 100644
--- a/platform/linuxbsd/display_server_x11.cpp
+++ b/platform/linuxbsd/display_server_x11.cpp
@@ -737,6 +737,7 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) {
XDestroyWindow(x11_display, wd.x11_window);
if (wd.xic) {
XDestroyIC(wd.xic);
+ wd.xic = nullptr;
}
windows.erase(p_id);
@@ -2784,6 +2785,13 @@ void DisplayServerX11::process_events() {
wd.focused = true;
+ if (wd.xic) {
+ // Block events polling while changing input focus
+ // because it triggers some event polling internally.
+ MutexLock mutex_lock(events_mutex);
+ XSetICFocus(wd.xic);
+ }
+
// Keep track of focus order for overlapping windows.
static unsigned int focus_order = 0;
wd.focus_order = ++focus_order;
@@ -2812,12 +2820,6 @@ void DisplayServerX11::process_events() {
XIGrabDevice(x11_display, xi.touch_devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &xi.touch_event_mask);
}*/
#endif
- if (wd.xic) {
- // Block events polling while changing input focus
- // because it triggers some event polling internally.
- MutexLock mutex_lock(events_mutex);
- XSetICFocus(wd.xic);
- }
if (!app_focused) {
if (OS::get_singleton()->get_main_loop()) {
@@ -2834,6 +2836,13 @@ void DisplayServerX11::process_events() {
wd.focused = false;
+ if (wd.xic) {
+ // Block events polling while changing input focus
+ // because it triggers some event polling internally.
+ MutexLock mutex_lock(events_mutex);
+ XUnsetICFocus(wd.xic);
+ }
+
Input::get_singleton()->release_pressed_events();
_send_window_event(wd, WINDOW_EVENT_FOCUS_OUT);
@@ -2864,12 +2873,6 @@ void DisplayServerX11::process_events() {
}
xi.state.clear();
#endif
- if (wd.xic) {
- // Block events polling while changing input focus
- // because it triggers some event polling internally.
- MutexLock mutex_lock(events_mutex);
- XUnsetICFocus(wd.xic);
- }
} break;
case ConfigureNotify: {
@@ -4044,11 +4047,13 @@ DisplayServerX11::~DisplayServerX11() {
}
#endif
- if (E->get().xic) {
- XDestroyIC(E->get().xic);
+ WindowData &wd = E->get();
+ if (wd.xic) {
+ XDestroyIC(wd.xic);
+ wd.xic = nullptr;
}
- XUnmapWindow(x11_display, E->get().x11_window);
- XDestroyWindow(x11_display, E->get().x11_window);
+ XUnmapWindow(x11_display, wd.x11_window);
+ XDestroyWindow(x11_display, wd.x11_window);
}
//destroy drivers
diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py
index 6e57dbbf64..2af7803749 100644
--- a/platform/uwp/detect.py
+++ b/platform/uwp/detect.py
@@ -81,7 +81,7 @@ def configure(env):
vc_base_path = os.environ["VCTOOLSINSTALLDIR"] if "VCTOOLSINSTALLDIR" in os.environ else os.environ["VCINSTALLDIR"]
# Force to use Unicode encoding
- env.Append(MSVC_FLAGS=["/utf-8"])
+ env.AppendUnique(CCFLAGS=["/utf-8"])
# ANGLE
angle_root = os.getenv("ANGLE_SRC_PATH")
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 5679ec3eac..219174b509 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -249,7 +249,7 @@ void AppxPackager::make_content_types(const String &p_path) {
Map<String, String> types;
for (int i = 0; i < file_metadata.size(); i++) {
- String ext = file_metadata[i].name.get_extension();
+ String ext = file_metadata[i].name.get_extension().to_lower();
if (types.has(ext)) {
continue;
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index d5474ace9c..489e45404f 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -223,7 +223,7 @@ def configure_msvc(env, manual_msvc_config):
env.AppendUnique(CCFLAGS=["/MT", "/Gd", "/GR", "/nologo"])
# Force to use Unicode encoding
- env.Append(MSVC_FLAGS=["/utf-8"])
+ env.AppendUnique(CCFLAGS=["/utf-8"])
env.AppendUnique(CXXFLAGS=["/TP"]) # assume all sources are C++
if manual_msvc_config: # should be automatic if SCons found it
if os.getenv("WindowsSdkDir") is not None:
diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp
index da5c99a873..ec33d7bcab 100644
--- a/scene/3d/gpu_particles_3d.cpp
+++ b/scene/3d/gpu_particles_3d.cpp
@@ -124,6 +124,11 @@ void GPUParticles3D::set_speed_scale(float p_scale) {
RS::get_singleton()->particles_set_speed_scale(particles, p_scale);
}
+void GPUParticles3D::set_collision_base_size(float p_size) {
+ collision_base_size = p_size;
+ RS::get_singleton()->particles_set_collision_base_size(particles, p_size);
+}
+
bool GPUParticles3D::is_emitting() const {
return RS::get_singleton()->particles_get_emitting(particles);
}
@@ -168,6 +173,10 @@ float GPUParticles3D::get_speed_scale() const {
return speed_scale;
}
+float GPUParticles3D::get_collision_base_size() const {
+ return collision_base_size;
+}
+
void GPUParticles3D::set_draw_order(DrawOrder p_order) {
draw_order = p_order;
RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order));
@@ -381,6 +390,7 @@ void GPUParticles3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta);
ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material);
ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale);
+ ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles3D::set_collision_base_size);
ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting);
ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount);
@@ -395,6 +405,7 @@ void GPUParticles3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta);
ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material);
ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale);
+ ClassDB::bind_method(D_METHOD("get_collision_base_size"), &GPUParticles3D::get_collision_base_size);
ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order);
@@ -426,6 +437,8 @@ void GPUParticles3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_base_size", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater"), "set_collision_base_size", "get_collision_base_size");
ADD_GROUP("Drawing", "");
ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb"), "set_visibility_aabb", "get_visibility_aabb");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
@@ -469,6 +482,7 @@ GPUParticles3D::GPUParticles3D() {
set_draw_passes(1);
set_draw_order(DRAW_ORDER_INDEX);
set_speed_scale(1);
+ set_collision_base_size(0.01);
}
GPUParticles3D::~GPUParticles3D() {
diff --git a/scene/3d/gpu_particles_3d.h b/scene/3d/gpu_particles_3d.h
index 0d8dadd31d..b68acef21c 100644
--- a/scene/3d/gpu_particles_3d.h
+++ b/scene/3d/gpu_particles_3d.h
@@ -65,6 +65,7 @@ private:
int fixed_fps;
bool fractional_delta;
NodePath sub_emitter;
+ float collision_base_size;
Ref<Material> process_material;
@@ -94,6 +95,7 @@ public:
void set_use_local_coordinates(bool p_enable);
void set_process_material(const Ref<Material> &p_material);
void set_speed_scale(float p_scale);
+ void set_collision_base_size(float p_ratio);
bool is_emitting() const;
int get_amount() const;
@@ -106,6 +108,7 @@ public:
bool get_use_local_coordinates() const;
Ref<Material> get_process_material() const;
float get_speed_scale() const;
+ float get_collision_base_size() const;
void set_fixed_fps(int p_count);
int get_fixed_fps() const;
diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp
new file mode 100644
index 0000000000..baaaa23185
--- /dev/null
+++ b/scene/3d/gpu_particles_collision_3d.cpp
@@ -0,0 +1,901 @@
+/*************************************************************************/
+/* gpu_particles_collision_3d.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "gpu_particles_collision_3d.h"
+
+#include "core/thread_work_pool.h"
+#include "mesh_instance_3d.h"
+#include "scene/3d/camera_3d.h"
+#include "scene/main/viewport.h"
+
+void GPUParticlesCollision3D::set_cull_mask(uint32_t p_cull_mask) {
+ cull_mask = p_cull_mask;
+ RS::get_singleton()->particles_collision_set_cull_mask(collision, p_cull_mask);
+}
+
+uint32_t GPUParticlesCollision3D::get_cull_mask() const {
+ return cull_mask;
+}
+
+void GPUParticlesCollision3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &GPUParticlesCollision3D::set_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_cull_mask"), &GPUParticlesCollision3D::get_cull_mask);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
+}
+
+GPUParticlesCollision3D::GPUParticlesCollision3D(RS::ParticlesCollisionType p_type) {
+ collision = RS::get_singleton()->particles_collision_create();
+ RS::get_singleton()->particles_collision_set_collision_type(collision, p_type);
+ set_base(collision);
+}
+
+GPUParticlesCollision3D::~GPUParticlesCollision3D() {
+ RS::get_singleton()->free(collision);
+}
+
+/////////////////////////////////
+
+void GPUParticlesCollisionSphere::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_radius", "radius"), &GPUParticlesCollisionSphere::set_radius);
+ ClassDB::bind_method(D_METHOD("get_radius"), &GPUParticlesCollisionSphere::get_radius);
+
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_radius", "get_radius");
+}
+
+void GPUParticlesCollisionSphere::set_radius(float p_radius) {
+ radius = p_radius;
+ RS::get_singleton()->particles_collision_set_sphere_radius(_get_collision(), radius);
+ update_gizmo();
+}
+
+float GPUParticlesCollisionSphere::get_radius() const {
+ return radius;
+}
+
+AABB GPUParticlesCollisionSphere::get_aabb() const {
+ return AABB(Vector3(-radius, -radius, -radius), Vector3(radius * 2, radius * 2, radius * 2));
+}
+
+GPUParticlesCollisionSphere::GPUParticlesCollisionSphere() :
+ GPUParticlesCollision3D(RS::PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE) {
+}
+
+GPUParticlesCollisionSphere::~GPUParticlesCollisionSphere() {
+}
+
+///////////////////////////
+
+void GPUParticlesCollisionBox::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GPUParticlesCollisionBox::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GPUParticlesCollisionBox::get_extents);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_extents", "get_extents");
+}
+
+void GPUParticlesCollisionBox::set_extents(const Vector3 &p_extents) {
+ extents = p_extents;
+ RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
+ update_gizmo();
+}
+
+Vector3 GPUParticlesCollisionBox::get_extents() const {
+ return extents;
+}
+
+AABB GPUParticlesCollisionBox::get_aabb() const {
+ return AABB(-extents, extents * 2);
+}
+
+GPUParticlesCollisionBox::GPUParticlesCollisionBox() :
+ GPUParticlesCollision3D(RS::PARTICLES_COLLISION_TYPE_BOX_COLLIDE) {
+}
+
+GPUParticlesCollisionBox::~GPUParticlesCollisionBox() {
+}
+
+///////////////////////////////
+///////////////////////////
+
+void GPUParticlesCollisionSDF::_find_meshes(const AABB &p_aabb, Node *p_at_node, List<PlotMesh> &plot_meshes) {
+ MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
+ if (mi && mi->is_visible_in_tree()) {
+ Ref<Mesh> mesh = mi->get_mesh();
+ if (mesh.is_valid()) {
+ AABB aabb = mesh->get_aabb();
+
+ Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
+
+ if (p_aabb.intersects(xf.xform(aabb))) {
+ PlotMesh pm;
+ pm.local_xform = xf;
+ pm.mesh = mesh;
+ plot_meshes.push_back(pm);
+ }
+ }
+ }
+
+ Node3D *s = Object::cast_to<Node3D>(p_at_node);
+ if (s) {
+ if (s->is_visible_in_tree()) {
+ Array meshes = p_at_node->call("get_meshes");
+ for (int i = 0; i < meshes.size(); i += 2) {
+ Transform mxf = meshes[i];
+ Ref<Mesh> mesh = meshes[i + 1];
+ if (!mesh.is_valid()) {
+ continue;
+ }
+
+ AABB aabb = mesh->get_aabb();
+
+ Transform xf = get_global_transform().affine_inverse() * (s->get_global_transform() * mxf);
+
+ if (p_aabb.intersects(xf.xform(aabb))) {
+ PlotMesh pm;
+ pm.local_xform = xf;
+ pm.mesh = mesh;
+ plot_meshes.push_back(pm);
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < p_at_node->get_child_count(); i++) {
+ Node *child = p_at_node->get_child(i);
+ _find_meshes(p_aabb, child, plot_meshes);
+ }
+}
+
+uint32_t GPUParticlesCollisionSDF::_create_bvh(LocalVector<BVH> &bvh_tree, FacePos *p_faces, uint32_t p_face_count, const Face3 *p_triangles, float p_thickness) {
+ if (p_face_count == 1) {
+ return BVH::LEAF_BIT | p_faces[0].index;
+ }
+
+ uint32_t index = bvh_tree.size();
+ {
+ BVH bvh;
+
+ for (uint32_t i = 0; i < p_face_count; i++) {
+ const Face3 &f = p_triangles[p_faces[i].index];
+ AABB aabb(f.vertex[0], Vector3());
+ aabb.expand_to(f.vertex[1]);
+ aabb.expand_to(f.vertex[2]);
+ if (p_thickness > 0.0) {
+ Vector3 normal = p_triangles[p_faces[i].index].get_plane().normal;
+ aabb.expand_to(f.vertex[0] - normal * p_thickness);
+ aabb.expand_to(f.vertex[1] - normal * p_thickness);
+ aabb.expand_to(f.vertex[2] - normal * p_thickness);
+ }
+ if (i == 0) {
+ bvh.bounds = aabb;
+ } else {
+ bvh.bounds.merge_with(aabb);
+ }
+ }
+ bvh_tree.push_back(bvh);
+ }
+
+ uint32_t middle = p_face_count / 2;
+
+ SortArray<FacePos, FaceSort> s;
+ s.compare.axis = bvh_tree[index].bounds.get_longest_axis_index();
+ s.sort(p_faces, p_face_count);
+
+ uint32_t left = _create_bvh(bvh_tree, p_faces, middle, p_triangles, p_thickness);
+ uint32_t right = _create_bvh(bvh_tree, p_faces + middle, p_face_count - middle, p_triangles, p_thickness);
+
+ bvh_tree[index].children[0] = left;
+ bvh_tree[index].children[1] = right;
+
+ return index;
+}
+
+static _FORCE_INLINE_ float Vector3_dot2(const Vector3 &p_vec3) {
+ return p_vec3.dot(p_vec3);
+}
+
+void GPUParticlesCollisionSDF::_find_closest_distance(const Vector3 &p_pos, const BVH *bvh, uint32_t p_bvh_cell, const Face3 *triangles, float thickness, float &closest_distance) {
+ if (p_bvh_cell & BVH::LEAF_BIT) {
+ p_bvh_cell &= BVH::LEAF_MASK; //remove bit
+
+ Vector3 point = p_pos;
+ Plane p = triangles[p_bvh_cell].get_plane();
+ float d = p.distance_to(point);
+ float inside_d = 1e20;
+ if (d < 0 && d > -thickness) {
+ //inside planes, do this in 2D
+
+ Vector3 x_axis = (triangles[p_bvh_cell].vertex[0] - triangles[p_bvh_cell].vertex[1]).normalized();
+ Vector3 y_axis = p.normal.cross(x_axis).normalized();
+
+ Vector2 points[3];
+ for (int i = 0; i < 3; i++) {
+ points[i] = Vector2(x_axis.dot(triangles[p_bvh_cell].vertex[i]), y_axis.dot(triangles[p_bvh_cell].vertex[i]));
+ }
+
+ Vector2 p2d = Vector2(x_axis.dot(point), y_axis.dot(point));
+
+ {
+ // https://www.shadertoy.com/view/XsXSz4
+
+ Vector2 e0 = points[1] - points[0];
+ Vector2 e1 = points[2] - points[1];
+ Vector2 e2 = points[0] - points[2];
+
+ Vector2 v0 = p2d - points[0];
+ Vector2 v1 = p2d - points[1];
+ Vector2 v2 = p2d - points[2];
+
+ Vector2 pq0 = v0 - e0 * CLAMP(v0.dot(e0) / e0.dot(e0), 0.0, 1.0);
+ Vector2 pq1 = v1 - e1 * CLAMP(v1.dot(e1) / e1.dot(e1), 0.0, 1.0);
+ Vector2 pq2 = v2 - e2 * CLAMP(v2.dot(e2) / e2.dot(e2), 0.0, 1.0);
+
+ float s = SGN(e0.x * e2.y - e0.y * e2.x);
+ Vector2 d2 = Vector2(pq0.dot(pq0), s * (v0.x * e0.y - v0.y * e0.x)).min(Vector2(pq1.dot(pq1), s * (v1.x * e1.y - v1.y * e1.x))).min(Vector2(pq2.dot(pq2), s * (v2.x * e2.y - v2.y * e2.x)));
+
+ inside_d = -Math::sqrt(d2.x) * SGN(d2.y);
+ }
+
+ //make sure distance to planes is not shorter if inside
+ if (inside_d < 0) {
+ inside_d = MAX(inside_d, d);
+ inside_d = MAX(inside_d, -(thickness + d));
+ }
+
+ closest_distance = MIN(closest_distance, inside_d);
+ } else {
+ if (d < 0) {
+ point -= p.normal * thickness; //flatten
+ }
+
+ // https://iquilezles.org/www/articles/distfunctions/distfunctions.htm
+ Vector3 a = triangles[p_bvh_cell].vertex[0];
+ Vector3 b = triangles[p_bvh_cell].vertex[1];
+ Vector3 c = triangles[p_bvh_cell].vertex[2];
+
+ Vector3 ba = b - a;
+ Vector3 pa = point - a;
+ Vector3 cb = c - b;
+ Vector3 pb = point - b;
+ Vector3 ac = a - c;
+ Vector3 pc = point - c;
+ Vector3 nor = ba.cross(ac);
+
+ inside_d = Math::sqrt(
+ (SGN(ba.cross(nor).dot(pa)) +
+ SGN(cb.cross(nor).dot(pb)) +
+ SGN(ac.cross(nor).dot(pc)) <
+ 2.0) ?
+ MIN(MIN(
+ Vector3_dot2(ba * CLAMP(ba.dot(pa) / Vector3_dot2(ba), 0.0, 1.0) - pa),
+ Vector3_dot2(cb * CLAMP(cb.dot(pb) / Vector3_dot2(cb), 0.0, 1.0) - pb)),
+ Vector3_dot2(ac * CLAMP(ac.dot(pc) / Vector3_dot2(ac), 0.0, 1.0) - pc)) :
+ nor.dot(pa) * nor.dot(pa) / Vector3_dot2(nor));
+
+ closest_distance = MIN(closest_distance, inside_d);
+ }
+
+ } else {
+ bool pass = true;
+ if (!bvh[p_bvh_cell].bounds.has_point(p_pos)) {
+ //outside, find closest point
+ Vector3 he = bvh[p_bvh_cell].bounds.size * 0.5;
+ Vector3 center = bvh[p_bvh_cell].bounds.position + he;
+
+ Vector3 rel = (p_pos - center).abs();
+ Vector3 closest(MIN(rel.x, he.x), MIN(rel.y, he.y), MIN(rel.z, he.z));
+ float d = rel.distance_to(closest);
+
+ if (d >= closest_distance) {
+ pass = false; //already closer than this aabb, discard
+ }
+ }
+
+ if (pass) {
+ _find_closest_distance(p_pos, bvh, bvh[p_bvh_cell].children[0], triangles, thickness, closest_distance);
+ _find_closest_distance(p_pos, bvh, bvh[p_bvh_cell].children[1], triangles, thickness, closest_distance);
+ }
+ }
+}
+
+void GPUParticlesCollisionSDF::_compute_sdf_z(uint32_t p_z, ComputeSDFParams *params) {
+ int32_t z_ofs = p_z * params->size.y * params->size.x;
+ for (int32_t y = 0; y < params->size.y; y++) {
+ int32_t y_ofs = z_ofs + y * params->size.x;
+ for (int32_t x = 0; x < params->size.x; x++) {
+ int32_t x_ofs = y_ofs + x;
+ float &cell = params->cells[x_ofs];
+
+ Vector3 pos = params->cell_offset + Vector3(x, y, p_z) * params->cell_size;
+
+ cell = 1e20;
+
+ _find_closest_distance(pos, params->bvh, 0, params->triangles, params->thickness, cell);
+ }
+ }
+}
+
+void GPUParticlesCollisionSDF::_compute_sdf(ComputeSDFParams *params) {
+ ThreadWorkPool work_pool;
+ work_pool.init();
+ work_pool.begin_work(params->size.z, this, &GPUParticlesCollisionSDF::_compute_sdf_z, params);
+ while (work_pool.get_work_index() < (uint32_t)params->size.z) {
+ OS::get_singleton()->delay_usec(10000);
+ bake_step_function(work_pool.get_work_index() * 100 / params->size.z, "Baking SDF");
+ }
+ work_pool.end_work();
+ work_pool.finish();
+}
+
+Vector3i GPUParticlesCollisionSDF::get_estimated_cell_size() const {
+ static const int subdivs[RESOLUTION_MAX] = { 16, 32, 64, 128, 256, 512 };
+ int subdiv = subdivs[get_resolution()];
+
+ AABB aabb(-extents, extents * 2);
+
+ float cell_size = aabb.get_longest_axis_size() / float(subdiv);
+
+ Vector3i sdf_size = Vector3i(aabb.size / cell_size);
+ sdf_size.x = MAX(1, sdf_size.x);
+ sdf_size.y = MAX(1, sdf_size.y);
+ sdf_size.z = MAX(1, sdf_size.z);
+ return sdf_size;
+}
+
+Ref<Image> GPUParticlesCollisionSDF::bake() {
+ static const int subdivs[RESOLUTION_MAX] = { 16, 32, 64, 128, 256, 512 };
+ int subdiv = subdivs[get_resolution()];
+
+ AABB aabb(-extents, extents * 2);
+
+ float cell_size = aabb.get_longest_axis_size() / float(subdiv);
+
+ Vector3i sdf_size = Vector3i(aabb.size / cell_size);
+ sdf_size.x = MAX(1, sdf_size.x);
+ sdf_size.y = MAX(1, sdf_size.y);
+ sdf_size.z = MAX(1, sdf_size.z);
+
+ if (bake_begin_function) {
+ bake_begin_function(100);
+ }
+
+ aabb.size = Vector3(sdf_size) * cell_size;
+
+ List<PlotMesh> plot_meshes;
+ _find_meshes(aabb, get_parent(), plot_meshes);
+
+ LocalVector<Face3> faces;
+
+ if (bake_step_function) {
+ bake_step_function(0, "Finding Meshes");
+ }
+
+ for (List<PlotMesh>::Element *E = plot_meshes.front(); E; E = E->next()) {
+ const PlotMesh &pm = E->get();
+
+ for (int i = 0; i < pm.mesh->get_surface_count(); i++) {
+ if (pm.mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
+ continue; //only triangles
+ }
+
+ Array a = pm.mesh->surface_get_arrays(i);
+
+ Vector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
+ const Vector3 *vr = vertices.ptr();
+ Vector<int> index = a[Mesh::ARRAY_INDEX];
+
+ if (index.size()) {
+ int facecount = index.size() / 3;
+ const int *ir = index.ptr();
+
+ for (int j = 0; j < facecount; j++) {
+ Face3 face;
+
+ for (int k = 0; k < 3; k++) {
+ face.vertex[k] = pm.local_xform.xform(vr[ir[j * 3 + k]]);
+ }
+
+ //test against original bounds
+ if (!Geometry3D::triangle_box_overlap(aabb.position + aabb.size * 0.5, aabb.size * 0.5, face.vertex)) {
+ continue;
+ }
+
+ faces.push_back(face);
+ }
+
+ } else {
+ int facecount = vertices.size() / 3;
+
+ for (int j = 0; j < facecount; j++) {
+ Face3 face;
+
+ for (int k = 0; k < 3; k++) {
+ face.vertex[k] = pm.local_xform.xform(vr[j * 3 + k]);
+ }
+
+ //test against original bounds
+ if (!Geometry3D::triangle_box_overlap(aabb.position + aabb.size * 0.5, aabb.size * 0.5, face.vertex)) {
+ continue;
+ }
+
+ faces.push_back(face);
+ }
+ }
+ }
+ }
+
+ //compute bvh
+
+ ERR_FAIL_COND_V(faces.size() <= 1, Ref<Image>());
+
+ LocalVector<FacePos> face_pos;
+
+ face_pos.resize(faces.size());
+
+ float th = cell_size * thickness;
+
+ for (uint32_t i = 0; i < faces.size(); i++) {
+ face_pos[i].index = i;
+ face_pos[i].center = (faces[i].vertex[0] + faces[i].vertex[1] + faces[i].vertex[2]) / 2;
+ if (th > 0.0) {
+ face_pos[i].center -= faces[i].get_plane().normal * th * 0.5;
+ }
+ }
+
+ if (bake_step_function) {
+ bake_step_function(0, "Creating BVH");
+ }
+
+ LocalVector<BVH> bvh;
+
+ _create_bvh(bvh, face_pos.ptr(), face_pos.size(), faces.ptr(), th);
+
+ Vector<uint8_t> data;
+ data.resize(sdf_size.z * sdf_size.y * sdf_size.x * sizeof(float));
+
+ if (bake_step_function) {
+ bake_step_function(0, "Baking SDF");
+ }
+
+ ComputeSDFParams params;
+ params.cells = (float *)data.ptrw();
+ params.size = sdf_size;
+ params.cell_size = cell_size;
+ params.cell_offset = aabb.position + Vector3(cell_size * 0.5, cell_size * 0.5, cell_size * 0.5);
+ params.bvh = bvh.ptr();
+ params.triangles = faces.ptr();
+ params.thickness = th;
+ _compute_sdf(&params);
+
+ Ref<Image> ret;
+ ret.instance();
+ ret->create(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, data);
+ ret->convert(Image::FORMAT_RH); //convert to half, save space
+ ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function
+
+ if (bake_end_function) {
+ bake_end_function();
+ }
+
+ return ret;
+}
+
+void GPUParticlesCollisionSDF::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GPUParticlesCollisionSDF::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GPUParticlesCollisionSDF::get_extents);
+
+ ClassDB::bind_method(D_METHOD("set_resolution", "resolution"), &GPUParticlesCollisionSDF::set_resolution);
+ ClassDB::bind_method(D_METHOD("get_resolution"), &GPUParticlesCollisionSDF::get_resolution);
+
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &GPUParticlesCollisionSDF::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &GPUParticlesCollisionSDF::get_texture);
+
+ ClassDB::bind_method(D_METHOD("set_thickness", "thickness"), &GPUParticlesCollisionSDF::set_thickness);
+ ClassDB::bind_method(D_METHOD("get_thickness"), &GPUParticlesCollisionSDF::get_thickness);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_extents", "get_extents");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "resolution", PROPERTY_HINT_ENUM, "16,32,64,128,256,512"), "set_resolution", "get_resolution");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "thickness", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_thickness", "get_thickness");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture3D"), "set_texture", "get_texture");
+
+ BIND_ENUM_CONSTANT(RESOLUTION_16);
+ BIND_ENUM_CONSTANT(RESOLUTION_32);
+ BIND_ENUM_CONSTANT(RESOLUTION_64);
+ BIND_ENUM_CONSTANT(RESOLUTION_128);
+ BIND_ENUM_CONSTANT(RESOLUTION_256);
+ BIND_ENUM_CONSTANT(RESOLUTION_512);
+ BIND_ENUM_CONSTANT(RESOLUTION_MAX);
+}
+
+void GPUParticlesCollisionSDF::set_thickness(float p_thickness) {
+ thickness = p_thickness;
+}
+
+float GPUParticlesCollisionSDF::get_thickness() const {
+ return thickness;
+}
+
+void GPUParticlesCollisionSDF::set_extents(const Vector3 &p_extents) {
+ extents = p_extents;
+ RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
+ update_gizmo();
+}
+
+Vector3 GPUParticlesCollisionSDF::get_extents() const {
+ return extents;
+}
+
+void GPUParticlesCollisionSDF::set_resolution(Resolution p_resolution) {
+ resolution = p_resolution;
+ update_gizmo();
+}
+
+GPUParticlesCollisionSDF::Resolution GPUParticlesCollisionSDF::get_resolution() const {
+ return resolution;
+}
+
+void GPUParticlesCollisionSDF::set_texture(const Ref<Texture3D> &p_texture) {
+ texture = p_texture;
+ RID tex = texture.is_valid() ? texture->get_rid() : RID();
+ RS::get_singleton()->particles_collision_set_field_texture(_get_collision(), tex);
+}
+
+Ref<Texture3D> GPUParticlesCollisionSDF::get_texture() const {
+ return texture;
+}
+
+AABB GPUParticlesCollisionSDF::get_aabb() const {
+ return AABB(-extents, extents * 2);
+}
+
+GPUParticlesCollisionSDF::BakeBeginFunc GPUParticlesCollisionSDF::bake_begin_function = nullptr;
+GPUParticlesCollisionSDF::BakeStepFunc GPUParticlesCollisionSDF::bake_step_function = nullptr;
+GPUParticlesCollisionSDF::BakeEndFunc GPUParticlesCollisionSDF::bake_end_function = nullptr;
+
+GPUParticlesCollisionSDF::GPUParticlesCollisionSDF() :
+ GPUParticlesCollision3D(RS::PARTICLES_COLLISION_TYPE_SDF_COLLIDE) {
+}
+
+GPUParticlesCollisionSDF::~GPUParticlesCollisionSDF() {
+}
+
+////////////////////////////
+////////////////////////////
+
+void GPUParticlesCollisionHeightField::_notification(int p_what) {
+ if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
+ if (update_mode == UPDATE_MODE_ALWAYS) {
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ }
+
+ if (follow_camera_mode && get_viewport()) {
+ Camera3D *cam = get_viewport()->get_camera();
+ if (cam) {
+ Transform xform = get_global_transform();
+ Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
+ Vector3 z_axis = xform.basis.get_axis(Vector3::AXIS_Z).normalized();
+ float x_len = xform.basis.get_scale().x;
+ float z_len = xform.basis.get_scale().z;
+
+ Vector3 cam_pos = cam->get_global_transform().origin;
+ Transform new_xform = xform;
+
+ while (x_axis.dot(cam_pos - new_xform.origin) > x_len) {
+ new_xform.origin += x_axis * x_len;
+ }
+ while (x_axis.dot(cam_pos - new_xform.origin) < -x_len) {
+ new_xform.origin -= x_axis * x_len;
+ }
+
+ while (z_axis.dot(cam_pos - new_xform.origin) > z_len) {
+ new_xform.origin += z_axis * z_len;
+ }
+ while (z_axis.dot(cam_pos - new_xform.origin) < -z_len) {
+ new_xform.origin -= z_axis * z_len;
+ }
+
+ if (new_xform != xform) {
+ set_global_transform(new_xform);
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ }
+ }
+ }
+ }
+
+ if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ }
+}
+
+void GPUParticlesCollisionHeightField::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GPUParticlesCollisionHeightField::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GPUParticlesCollisionHeightField::get_extents);
+
+ ClassDB::bind_method(D_METHOD("set_resolution", "resolution"), &GPUParticlesCollisionHeightField::set_resolution);
+ ClassDB::bind_method(D_METHOD("get_resolution"), &GPUParticlesCollisionHeightField::get_resolution);
+
+ ClassDB::bind_method(D_METHOD("set_update_mode", "update_mode"), &GPUParticlesCollisionHeightField::set_update_mode);
+ ClassDB::bind_method(D_METHOD("get_update_mode"), &GPUParticlesCollisionHeightField::get_update_mode);
+
+ ClassDB::bind_method(D_METHOD("set_follow_camera_mode", "enabled"), &GPUParticlesCollisionHeightField::set_follow_camera_mode);
+ ClassDB::bind_method(D_METHOD("is_follow_camera_mode_enabled"), &GPUParticlesCollisionHeightField::is_follow_camera_mode_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_follow_camera_push_ratio", "ratio"), &GPUParticlesCollisionHeightField::set_follow_camera_push_ratio);
+ ClassDB::bind_method(D_METHOD("get_follow_camera_push_ratio"), &GPUParticlesCollisionHeightField::get_follow_camera_push_ratio);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_extents", "get_extents");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "resolution", PROPERTY_HINT_ENUM, "256,512,1024,2048,4096,8192"), "set_resolution", "get_resolution");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "WhenMoved,Always"), "set_update_mode", "get_update_mode");
+ ADD_GROUP("Folow Camera", "follow_camera_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_camera_enabled"), "set_follow_camera_mode", "is_follow_camera_mode_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "follow_camera_push_ratio", PROPERTY_HINT_RANGE, "0.01,1,0.01"), "set_follow_camera_push_ratio", "get_follow_camera_push_ratio");
+
+ BIND_ENUM_CONSTANT(RESOLUTION_256);
+ BIND_ENUM_CONSTANT(RESOLUTION_512);
+ BIND_ENUM_CONSTANT(RESOLUTION_1024);
+ BIND_ENUM_CONSTANT(RESOLUTION_2048);
+ BIND_ENUM_CONSTANT(RESOLUTION_4096);
+ BIND_ENUM_CONSTANT(RESOLUTION_8192);
+ BIND_ENUM_CONSTANT(RESOLUTION_MAX);
+
+ BIND_ENUM_CONSTANT(UPDATE_MODE_WHEN_MOVED);
+ BIND_ENUM_CONSTANT(UPDATE_MODE_ALWAYS);
+}
+
+void GPUParticlesCollisionHeightField::set_follow_camera_push_ratio(float p_follow_camera_push_ratio) {
+ follow_camera_push_ratio = p_follow_camera_push_ratio;
+}
+
+float GPUParticlesCollisionHeightField::get_follow_camera_push_ratio() const {
+ return follow_camera_push_ratio;
+}
+
+void GPUParticlesCollisionHeightField::set_extents(const Vector3 &p_extents) {
+ extents = p_extents;
+ RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
+ update_gizmo();
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+}
+
+Vector3 GPUParticlesCollisionHeightField::get_extents() const {
+ return extents;
+}
+
+void GPUParticlesCollisionHeightField::set_resolution(Resolution p_resolution) {
+ resolution = p_resolution;
+ RS::get_singleton()->particles_collision_set_height_field_resolution(_get_collision(), RS::ParticlesCollisionHeightfieldResolution(resolution));
+ update_gizmo();
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+}
+
+GPUParticlesCollisionHeightField::Resolution GPUParticlesCollisionHeightField::get_resolution() const {
+ return resolution;
+}
+
+void GPUParticlesCollisionHeightField::set_update_mode(UpdateMode p_update_mode) {
+ update_mode = p_update_mode;
+ set_process_internal(follow_camera_mode || update_mode == UPDATE_MODE_ALWAYS);
+}
+
+GPUParticlesCollisionHeightField::UpdateMode GPUParticlesCollisionHeightField::get_update_mode() const {
+ return update_mode;
+}
+
+void GPUParticlesCollisionHeightField::set_follow_camera_mode(bool p_enabled) {
+ follow_camera_mode = p_enabled;
+ set_process_internal(follow_camera_mode || update_mode == UPDATE_MODE_ALWAYS);
+}
+
+bool GPUParticlesCollisionHeightField::is_follow_camera_mode_enabled() const {
+ return follow_camera_mode;
+}
+
+AABB GPUParticlesCollisionHeightField::get_aabb() const {
+ return AABB(-extents, extents * 2);
+}
+
+GPUParticlesCollisionHeightField::GPUParticlesCollisionHeightField() :
+ GPUParticlesCollision3D(RS::PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE) {
+}
+
+GPUParticlesCollisionHeightField::~GPUParticlesCollisionHeightField() {
+}
+
+////////////////////////////
+////////////////////////////
+
+void GPUParticlesAttractor3D::set_cull_mask(uint32_t p_cull_mask) {
+ cull_mask = p_cull_mask;
+ RS::get_singleton()->particles_collision_set_cull_mask(collision, p_cull_mask);
+}
+
+uint32_t GPUParticlesAttractor3D::get_cull_mask() const {
+ return cull_mask;
+}
+
+void GPUParticlesAttractor3D::set_strength(float p_strength) {
+ strength = p_strength;
+ RS::get_singleton()->particles_collision_set_attractor_strength(collision, p_strength);
+}
+
+float GPUParticlesAttractor3D::get_strength() const {
+ return strength;
+}
+
+void GPUParticlesAttractor3D::set_attenuation(float p_attenuation) {
+ attenuation = p_attenuation;
+ RS::get_singleton()->particles_collision_set_attractor_attenuation(collision, p_attenuation);
+}
+
+float GPUParticlesAttractor3D::get_attenuation() const {
+ return attenuation;
+}
+
+void GPUParticlesAttractor3D::set_directionality(float p_directionality) {
+ directionality = p_directionality;
+ RS::get_singleton()->particles_collision_set_attractor_directionality(collision, p_directionality);
+ update_gizmo();
+}
+
+float GPUParticlesAttractor3D::get_directionality() const {
+ return directionality;
+}
+
+void GPUParticlesAttractor3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &GPUParticlesAttractor3D::set_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_cull_mask"), &GPUParticlesAttractor3D::get_cull_mask);
+
+ ClassDB::bind_method(D_METHOD("set_strength", "strength"), &GPUParticlesAttractor3D::set_strength);
+ ClassDB::bind_method(D_METHOD("get_strength"), &GPUParticlesAttractor3D::get_strength);
+
+ ClassDB::bind_method(D_METHOD("set_attenuation", "attenuation"), &GPUParticlesAttractor3D::set_attenuation);
+ ClassDB::bind_method(D_METHOD("get_attenuation"), &GPUParticlesAttractor3D::get_attenuation);
+
+ ClassDB::bind_method(D_METHOD("set_directionality", "amount"), &GPUParticlesAttractor3D::set_directionality);
+ ClassDB::bind_method(D_METHOD("get_directionality"), &GPUParticlesAttractor3D::get_directionality);
+
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "-128,128,0.01,or_greater,or_lesser"), "set_strength", "get_strength");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "attenuation", PROPERTY_HINT_EXP_EASING, "0,8,0.01"), "set_attenuation", "get_attenuation");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "directionality", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_directionality", "get_directionality");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
+}
+
+GPUParticlesAttractor3D::GPUParticlesAttractor3D(RS::ParticlesCollisionType p_type) {
+ collision = RS::get_singleton()->particles_collision_create();
+ RS::get_singleton()->particles_collision_set_collision_type(collision, p_type);
+ set_base(collision);
+}
+GPUParticlesAttractor3D::~GPUParticlesAttractor3D() {
+ RS::get_singleton()->free(collision);
+}
+
+/////////////////////////////////
+
+void GPUParticlesAttractorSphere::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_radius", "radius"), &GPUParticlesAttractorSphere::set_radius);
+ ClassDB::bind_method(D_METHOD("get_radius"), &GPUParticlesAttractorSphere::get_radius);
+
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_radius", "get_radius");
+}
+
+void GPUParticlesAttractorSphere::set_radius(float p_radius) {
+ radius = p_radius;
+ RS::get_singleton()->particles_collision_set_sphere_radius(_get_collision(), radius);
+ update_gizmo();
+}
+
+float GPUParticlesAttractorSphere::get_radius() const {
+ return radius;
+}
+
+AABB GPUParticlesAttractorSphere::get_aabb() const {
+ return AABB(Vector3(-radius, -radius, -radius), Vector3(radius * 2, radius * 2, radius * 2));
+}
+
+GPUParticlesAttractorSphere::GPUParticlesAttractorSphere() :
+ GPUParticlesAttractor3D(RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT) {
+}
+
+GPUParticlesAttractorSphere::~GPUParticlesAttractorSphere() {
+}
+
+///////////////////////////
+
+void GPUParticlesAttractorBox::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GPUParticlesAttractorBox::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GPUParticlesAttractorBox::get_extents);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_extents", "get_extents");
+}
+
+void GPUParticlesAttractorBox::set_extents(const Vector3 &p_extents) {
+ extents = p_extents;
+ RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
+ update_gizmo();
+}
+
+Vector3 GPUParticlesAttractorBox::get_extents() const {
+ return extents;
+}
+
+AABB GPUParticlesAttractorBox::get_aabb() const {
+ return AABB(-extents, extents * 2);
+}
+
+GPUParticlesAttractorBox::GPUParticlesAttractorBox() :
+ GPUParticlesAttractor3D(RS::PARTICLES_COLLISION_TYPE_BOX_ATTRACT) {
+}
+
+GPUParticlesAttractorBox::~GPUParticlesAttractorBox() {
+}
+
+///////////////////////////
+
+void GPUParticlesAttractorVectorField::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GPUParticlesAttractorVectorField::set_extents);
+ ClassDB::bind_method(D_METHOD("get_extents"), &GPUParticlesAttractorVectorField::get_extents);
+
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &GPUParticlesAttractorVectorField::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &GPUParticlesAttractorVectorField::get_texture);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater"), "set_extents", "get_extents");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture3D"), "set_texture", "get_texture");
+}
+
+void GPUParticlesAttractorVectorField::set_extents(const Vector3 &p_extents) {
+ extents = p_extents;
+ RS::get_singleton()->particles_collision_set_box_extents(_get_collision(), extents);
+ update_gizmo();
+}
+
+Vector3 GPUParticlesAttractorVectorField::get_extents() const {
+ return extents;
+}
+
+void GPUParticlesAttractorVectorField::set_texture(const Ref<Texture3D> &p_texture) {
+ texture = p_texture;
+ RID tex = texture.is_valid() ? texture->get_rid() : RID();
+ RS::get_singleton()->particles_collision_set_field_texture(_get_collision(), tex);
+}
+
+Ref<Texture3D> GPUParticlesAttractorVectorField::get_texture() const {
+ return texture;
+}
+
+AABB GPUParticlesAttractorVectorField::get_aabb() const {
+ return AABB(-extents, extents * 2);
+}
+
+GPUParticlesAttractorVectorField::GPUParticlesAttractorVectorField() :
+ GPUParticlesAttractor3D(RS::PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT) {
+}
+
+GPUParticlesAttractorVectorField::~GPUParticlesAttractorVectorField() {
+}
diff --git a/scene/3d/gpu_particles_collision_3d.h b/scene/3d/gpu_particles_collision_3d.h
new file mode 100644
index 0000000000..4c73c7bcb2
--- /dev/null
+++ b/scene/3d/gpu_particles_collision_3d.h
@@ -0,0 +1,342 @@
+/*************************************************************************/
+/* gpu_particles_collision_3d.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GPU_PARTICLES_COLLISION_3D_H
+#define GPU_PARTICLES_COLLISION_3D_H
+
+#include "core/local_vector.h"
+#include "core/rid.h"
+#include "scene/3d/visual_instance_3d.h"
+#include "scene/resources/material.h"
+
+class GPUParticlesCollision3D : public VisualInstance3D {
+ GDCLASS(GPUParticlesCollision3D, VisualInstance3D);
+
+ uint32_t cull_mask = 0xFFFFFFFF;
+ RID collision;
+
+protected:
+ _FORCE_INLINE_ RID _get_collision() { return collision; }
+ static void _bind_methods();
+
+ GPUParticlesCollision3D(RS::ParticlesCollisionType p_type);
+
+public:
+ void set_cull_mask(uint32_t p_cull_mask);
+ uint32_t get_cull_mask() const;
+
+ virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const override { return Vector<Face3>(); }
+
+ ~GPUParticlesCollision3D();
+};
+
+class GPUParticlesCollisionSphere : public GPUParticlesCollision3D {
+ GDCLASS(GPUParticlesCollisionSphere, GPUParticlesCollision3D);
+
+ float radius = 1.0;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_radius(float p_radius);
+ float get_radius() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesCollisionSphere();
+ ~GPUParticlesCollisionSphere();
+};
+
+class GPUParticlesCollisionBox : public GPUParticlesCollision3D {
+ GDCLASS(GPUParticlesCollisionBox, GPUParticlesCollision3D);
+
+ Vector3 extents = Vector3(1, 1, 1);
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_extents(const Vector3 &p_extents);
+ Vector3 get_extents() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesCollisionBox();
+ ~GPUParticlesCollisionBox();
+};
+
+class GPUParticlesCollisionSDF : public GPUParticlesCollision3D {
+ GDCLASS(GPUParticlesCollisionSDF, GPUParticlesCollision3D);
+
+public:
+ enum Resolution {
+ RESOLUTION_16,
+ RESOLUTION_32,
+ RESOLUTION_64,
+ RESOLUTION_128,
+ RESOLUTION_256,
+ RESOLUTION_512,
+ RESOLUTION_MAX,
+ };
+
+ typedef void (*BakeBeginFunc)(int);
+ typedef void (*BakeStepFunc)(int, const String &);
+ typedef void (*BakeEndFunc)();
+
+private:
+ Vector3 extents = Vector3(1, 1, 1);
+ Resolution resolution = RESOLUTION_64;
+ Ref<Texture3D> texture;
+ float thickness = 1.0;
+
+ struct PlotMesh {
+ Ref<Mesh> mesh;
+ Transform local_xform;
+ };
+
+ void _find_meshes(const AABB &p_aabb, Node *p_at_node, List<PlotMesh> &plot_meshes);
+
+ struct BVH {
+ enum {
+ LEAF_BIT = 1 << 30,
+ LEAF_MASK = LEAF_BIT - 1
+ };
+ AABB bounds;
+ uint32_t children[2];
+ };
+
+ struct FacePos {
+ Vector3 center;
+ uint32_t index;
+ };
+
+ struct FaceSort {
+ uint32_t axis;
+ bool operator()(const FacePos &p_left, const FacePos &p_right) const {
+ return p_left.center[axis] < p_right.center[axis];
+ }
+ };
+
+ uint32_t _create_bvh(LocalVector<BVH> &bvh_tree, FacePos *p_faces, uint32_t p_face_count, const Face3 *p_triangles, float p_thickness);
+
+ struct ComputeSDFParams {
+ float *cells;
+ Vector3i size;
+ float cell_size;
+ Vector3 cell_offset;
+ const BVH *bvh;
+ const Face3 *triangles;
+ float thickness;
+ };
+
+ void _find_closest_distance(const Vector3 &p_pos, const BVH *bvh, uint32_t p_bvh_cell, const Face3 *triangles, float thickness, float &closest_distance);
+ void _compute_sdf_z(uint32_t p_z, ComputeSDFParams *params);
+ void _compute_sdf(ComputeSDFParams *params);
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_thickness(float p_thickness);
+ float get_thickness() const;
+
+ void set_extents(const Vector3 &p_extents);
+ Vector3 get_extents() const;
+
+ void set_resolution(Resolution p_resolution);
+ Resolution get_resolution() const;
+
+ void set_texture(const Ref<Texture3D> &p_texture);
+ Ref<Texture3D> get_texture() const;
+
+ Vector3i get_estimated_cell_size() const;
+ Ref<Image> bake();
+
+ virtual AABB get_aabb() const override;
+
+ static BakeBeginFunc bake_begin_function;
+ static BakeStepFunc bake_step_function;
+ static BakeEndFunc bake_end_function;
+
+ GPUParticlesCollisionSDF();
+ ~GPUParticlesCollisionSDF();
+};
+
+VARIANT_ENUM_CAST(GPUParticlesCollisionSDF::Resolution)
+
+class GPUParticlesCollisionHeightField : public GPUParticlesCollision3D {
+ GDCLASS(GPUParticlesCollisionHeightField, GPUParticlesCollision3D);
+
+public:
+ enum Resolution {
+ RESOLUTION_256,
+ RESOLUTION_512,
+ RESOLUTION_1024,
+ RESOLUTION_2048,
+ RESOLUTION_4096,
+ RESOLUTION_8192,
+ RESOLUTION_MAX,
+ };
+
+ enum UpdateMode {
+ UPDATE_MODE_WHEN_MOVED,
+ UPDATE_MODE_ALWAYS,
+ };
+
+private:
+ Vector3 extents = Vector3(1, 1, 1);
+ Resolution resolution = RESOLUTION_1024;
+ bool follow_camera_mode = false;
+ float follow_camera_push_ratio = 0.1;
+
+ UpdateMode update_mode = UPDATE_MODE_WHEN_MOVED;
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void set_extents(const Vector3 &p_extents);
+ Vector3 get_extents() const;
+
+ void set_resolution(Resolution p_resolution);
+ Resolution get_resolution() const;
+
+ void set_update_mode(UpdateMode p_update_mode);
+ UpdateMode get_update_mode() const;
+
+ void set_follow_camera_mode(bool p_enabled);
+ bool is_follow_camera_mode_enabled() const;
+
+ void set_follow_camera_push_ratio(float p_ratio);
+ float get_follow_camera_push_ratio() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesCollisionHeightField();
+ ~GPUParticlesCollisionHeightField();
+};
+
+VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField::Resolution)
+VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField::UpdateMode)
+
+class GPUParticlesAttractor3D : public VisualInstance3D {
+ GDCLASS(GPUParticlesAttractor3D, VisualInstance3D);
+
+ uint32_t cull_mask = 0xFFFFFFFF;
+ RID collision;
+ float strength = 1.0;
+ float attenuation = 1.0;
+ float directionality = 0.0;
+
+protected:
+ _FORCE_INLINE_ RID _get_collision() { return collision; }
+ static void _bind_methods();
+
+ GPUParticlesAttractor3D(RS::ParticlesCollisionType p_type);
+
+public:
+ void set_cull_mask(uint32_t p_cull_mask);
+ uint32_t get_cull_mask() const;
+
+ void set_strength(float p_strength);
+ float get_strength() const;
+
+ void set_attenuation(float p_attenuation);
+ float get_attenuation() const;
+
+ void set_directionality(float p_directionality);
+ float get_directionality() const;
+
+ virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const override { return Vector<Face3>(); }
+
+ ~GPUParticlesAttractor3D();
+};
+
+class GPUParticlesAttractorSphere : public GPUParticlesAttractor3D {
+ GDCLASS(GPUParticlesAttractorSphere, GPUParticlesAttractor3D);
+
+ float radius = 1.0;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_radius(float p_radius);
+ float get_radius() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesAttractorSphere();
+ ~GPUParticlesAttractorSphere();
+};
+
+class GPUParticlesAttractorBox : public GPUParticlesAttractor3D {
+ GDCLASS(GPUParticlesAttractorBox, GPUParticlesAttractor3D);
+
+ Vector3 extents = Vector3(1, 1, 1);
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_extents(const Vector3 &p_extents);
+ Vector3 get_extents() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesAttractorBox();
+ ~GPUParticlesAttractorBox();
+};
+
+class GPUParticlesAttractorVectorField : public GPUParticlesAttractor3D {
+ GDCLASS(GPUParticlesAttractorVectorField, GPUParticlesAttractor3D);
+
+ Vector3 extents = Vector3(1, 1, 1);
+ Ref<Texture3D> texture;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_extents(const Vector3 &p_extents);
+ Vector3 get_extents() const;
+
+ void set_texture(const Ref<Texture3D> &p_texture);
+ Ref<Texture3D> get_texture() const;
+
+ virtual AABB get_aabb() const override;
+
+ GPUParticlesAttractorVectorField();
+ ~GPUParticlesAttractorVectorField();
+};
+
+#endif // GPU_PARTICLES_COLLISION_3D_H
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 2e77d20d4e..a759e329da 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -307,17 +307,6 @@ int BaseButton::get_button_mask() const {
return button_mask;
}
-void BaseButton::set_enabled_focus_mode(FocusMode p_mode) {
- enabled_focus_mode = p_mode;
- if (!status.disabled) {
- set_focus_mode(p_mode);
- }
-}
-
-Control::FocusMode BaseButton::get_enabled_focus_mode() const {
- return enabled_focus_mode;
-}
-
void BaseButton::set_keep_pressed_outside(bool p_on) {
keep_pressed_outside = p_on;
}
@@ -388,8 +377,6 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_mask", "mask"), &BaseButton::set_button_mask);
ClassDB::bind_method(D_METHOD("get_button_mask"), &BaseButton::get_button_mask);
ClassDB::bind_method(D_METHOD("get_draw_mode"), &BaseButton::get_draw_mode);
- ClassDB::bind_method(D_METHOD("set_enabled_focus_mode", "mode"), &BaseButton::set_enabled_focus_mode);
- ClassDB::bind_method(D_METHOD("get_enabled_focus_mode"), &BaseButton::get_enabled_focus_mode);
ClassDB::bind_method(D_METHOD("set_keep_pressed_outside", "enabled"), &BaseButton::set_keep_pressed_outside);
ClassDB::bind_method(D_METHOD("is_keep_pressed_outside"), &BaseButton::is_keep_pressed_outside);
@@ -412,7 +399,6 @@ void BaseButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "action_mode", PROPERTY_HINT_ENUM, "Button Press,Button Release"), "set_action_mode", "get_action_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask", PROPERTY_HINT_FLAGS, "Mouse Left, Mouse Right, Mouse Middle"), "set_button_mask", "get_button_mask");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_enabled_focus_mode", "get_enabled_focus_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_pressed_outside"), "set_keep_pressed_outside", "is_keep_pressed_outside");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "Shortcut"), "set_shortcut", "get_shortcut");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "group", PROPERTY_HINT_RESOURCE_TYPE, "ButtonGroup"), "set_button_group", "get_button_group");
@@ -437,7 +423,6 @@ BaseButton::BaseButton() {
status.pressing_inside = false;
status.disabled = false;
set_focus_mode(FOCUS_ALL);
- enabled_focus_mode = FOCUS_ALL;
action_mode = ACTION_MODE_BUTTON_RELEASE;
button_mask = BUTTON_MASK_LEFT;
}
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 8e71931f8b..33f19949cd 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -49,7 +49,6 @@ private:
bool toggle_mode;
bool shortcut_in_tooltip;
bool keep_pressed_outside;
- FocusMode enabled_focus_mode;
Ref<Shortcut> shortcut;
ActionMode action_mode;
@@ -115,9 +114,6 @@ public:
void set_button_mask(int p_mask);
int get_button_mask() const;
- void set_enabled_focus_mode(FocusMode p_mode);
- FocusMode get_enabled_focus_mode() const;
-
void set_shortcut(const Ref<Shortcut> &p_shortcut);
Ref<Shortcut> get_shortcut() const;
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 56cf432b38..1eb45d7fc6 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -132,6 +132,7 @@ void CodeEdit::set_line_as_breakpoint(int p_line, bool p_breakpointed) {
breakpointed_lines.erase(p_line);
}
emit_signal("breakpoint_toggled", p_line);
+ update();
}
bool CodeEdit::is_line_breakpointed(int p_line) const {
@@ -160,6 +161,7 @@ Array CodeEdit::get_breakpointed_lines() const {
void CodeEdit::set_line_as_bookmarked(int p_line, bool p_bookmarked) {
int mask = get_line_gutter_metadata(p_line, main_gutter);
set_line_gutter_metadata(p_line, main_gutter, p_bookmarked ? mask | MAIN_GUTTER_BOOKMARK : mask & ~MAIN_GUTTER_BOOKMARK);
+ update();
}
bool CodeEdit::is_line_bookmarked(int p_line) const {
@@ -188,6 +190,7 @@ Array CodeEdit::get_bookmarked_lines() const {
void CodeEdit::set_line_as_executing(int p_line, bool p_executing) {
int mask = get_line_gutter_metadata(p_line, main_gutter);
set_line_gutter_metadata(p_line, main_gutter, p_executing ? mask | MAIN_GUTTER_EXECUTING : mask & ~MAIN_GUTTER_EXECUTING);
+ update();
}
bool CodeEdit::is_line_executing(int p_line) const {
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index f8c8bd4caf..27a60945c8 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -127,6 +127,5 @@ void LinkButton::_bind_methods() {
LinkButton::LinkButton() {
underline_mode = UNDERLINE_MODE_ALWAYS;
- set_enabled_focus_mode(FOCUS_NONE);
set_default_cursor_shape(CURSOR_POINTING_HAND);
}
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index aa69fb39e7..9b1738ec79 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -130,7 +130,6 @@ MenuButton::MenuButton() {
set_flat(true);
set_toggle_mode(true);
set_disable_shortcuts(false);
- set_enabled_focus_mode(FOCUS_NONE);
set_process_unhandled_key_input(true);
set_action_mode(ACTION_MODE_BUTTON_PRESS);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 2f5ee20373..318496df70 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1173,6 +1173,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (p_item->cells[i].text.size() > 0) {
float icon_width = p_item->cells[i].get_icon_size().width;
+ if (p_item->get_icon_max_width(i) > 0) {
+ icon_width = p_item->get_icon_max_width(i);
+ }
r.position.x += icon_width;
r.size.x -= icon_width;
}
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 7c2350d1c0..9f014e8175 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -895,11 +895,11 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
if (exclusive_child != nullptr) {
Window *focus_target = exclusive_child;
+ focus_target->grab_focus();
while (focus_target->exclusive_child != nullptr) {
- focus_target->grab_focus();
focus_target = focus_target->exclusive_child;
+ focus_target->grab_focus();
}
- focus_target->grab_focus();
if (!is_embedding_subwindows()) { //not embedding, no need for event
return;
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 820513c53d..6b602ae6e5 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -194,6 +194,7 @@
#include "scene/3d/decal.h"
#include "scene/3d/gi_probe.h"
#include "scene/3d/gpu_particles_3d.h"
+#include "scene/3d/gpu_particles_collision_3d.h"
#include "scene/3d/immediate_geometry_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/lightmap_probe.h"
@@ -450,6 +451,15 @@ void register_scene_types() {
ClassDB::register_class<LightmapProbe>();
ClassDB::register_virtual_class<Lightmapper>();
ClassDB::register_class<GPUParticles3D>();
+ ClassDB::register_virtual_class<GPUParticlesCollision3D>();
+ ClassDB::register_class<GPUParticlesCollisionBox>();
+ ClassDB::register_class<GPUParticlesCollisionSphere>();
+ ClassDB::register_class<GPUParticlesCollisionSDF>();
+ ClassDB::register_class<GPUParticlesCollisionHeightField>();
+ ClassDB::register_virtual_class<GPUParticlesAttractor3D>();
+ ClassDB::register_class<GPUParticlesAttractorBox>();
+ ClassDB::register_class<GPUParticlesAttractorSphere>();
+ ClassDB::register_class<GPUParticlesAttractorVectorField>();
ClassDB::register_class<CPUParticles3D>();
ClassDB::register_class<Position3D>();
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 4bbfa8965a..a286184aee 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -98,6 +98,9 @@ void ParticlesMaterial::init_shaders() {
shader_names->sub_emitter_frequency = "sub_emitter_frequency";
shader_names->sub_emitter_amount_at_end = "sub_emitter_amount_at_end";
shader_names->sub_emitter_keep_velocity = "sub_emitter_keep_velocity";
+
+ shader_names->collision_friction = "collision_friction";
+ shader_names->collision_bounce = "collision_bounce";
}
void ParticlesMaterial::finish_shaders() {
@@ -136,6 +139,10 @@ void ParticlesMaterial::_update_shader() {
String code = "shader_type particles;\n";
+ if (collision_scale) {
+ code += "render_mode collision_use_scale;\n";
+ }
+
code += "uniform vec3 direction;\n";
code += "uniform float spread;\n";
code += "uniform float flatness;\n";
@@ -247,6 +254,11 @@ void ParticlesMaterial::_update_shader() {
code += "uniform sampler2D anim_offset_texture;\n";
}
+ if (collision_enabled) {
+ code += "uniform float collision_friction;\n";
+ code += "uniform float collision_bounce;\n";
+ }
+
//need a random function
code += "\n\n";
code += "float rand_from_seed(inout uint seed) {\n";
@@ -476,6 +488,10 @@ void ParticlesMaterial::_update_shader() {
code += " vec3 crossDiff = cross(normalize(diff), normalize(gravity));\n";
code += " force += length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel + tex_tangent_accel) * mix(1.0, rand_from_seed(alt_seed), tangent_accel_random)) : vec3(0.0);\n";
}
+ if (attractor_interaction_enabled) {
+ code += " force += ATTRACTOR_FORCE;\n\n";
+ }
+
code += " // apply attractor forces\n";
code += " VELOCITY += force * DELTA;\n";
code += " // orbit velocity\n";
@@ -599,6 +615,13 @@ void ParticlesMaterial::_update_shader() {
code += " VELOCITY.z = 0.0;\n";
code += " TRANSFORM[3].z = 0.0;\n";
}
+ if (collision_enabled) {
+ code += " if (COLLIDED) {\n";
+ code += " TRANSFORM[3].xyz+=COLLISION_NORMAL * COLLISION_DEPTH;\n";
+ code += " VELOCITY -= COLLISION_NORMAL * dot(COLLISION_NORMAL, VELOCITY) * (1.0 + collision_bounce);\n";
+ code += " VELOCITY = mix(VELOCITY,vec3(0.0),collision_friction * DELTA * 100.0);\n";
+ code += " }\n";
+ }
if (sub_emitter_mode != SUB_EMITTER_DISABLED) {
code += " int emit_count = 0;\n";
switch (sub_emitter_mode) {
@@ -609,6 +632,7 @@ void ParticlesMaterial::_update_shader() {
} break;
case SUB_EMITTER_AT_COLLISION: {
//not implemented yet
+ code += " if (COLLIDED) emit_count = 1;\n";
} break;
case SUB_EMITTER_AT_END: {
//not implemented yet
@@ -1072,6 +1096,51 @@ bool ParticlesMaterial::get_sub_emitter_keep_velocity() const {
return sub_emitter_keep_velocity;
}
+void ParticlesMaterial::set_attractor_interaction_enabled(bool p_enable) {
+ attractor_interaction_enabled = p_enable;
+ _queue_shader_change();
+}
+
+bool ParticlesMaterial::is_attractor_interaction_enabled() const {
+ return attractor_interaction_enabled;
+}
+
+void ParticlesMaterial::set_collision_enabled(bool p_enabled) {
+ collision_enabled = p_enabled;
+ _queue_shader_change();
+}
+
+bool ParticlesMaterial::is_collision_enabled() const {
+ return collision_enabled;
+}
+
+void ParticlesMaterial::set_collision_use_scale(bool p_scale) {
+ collision_scale = p_scale;
+ _queue_shader_change();
+}
+
+bool ParticlesMaterial::is_collision_using_scale() const {
+ return collision_scale;
+}
+
+void ParticlesMaterial::set_collision_friction(float p_friction) {
+ collision_friction = p_friction;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->collision_friction, p_friction);
+}
+
+float ParticlesMaterial::get_collision_friction() const {
+ return collision_friction;
+}
+
+void ParticlesMaterial::set_collision_bounce(float p_bounce) {
+ collision_bounce = p_bounce;
+ RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->collision_bounce, p_bounce);
+}
+
+float ParticlesMaterial::get_collision_bounce() const {
+ return collision_bounce;
+}
+
Shader::Mode ParticlesMaterial::get_shader_mode() const {
return Shader::MODE_PARTICLES;
}
@@ -1143,6 +1212,21 @@ void ParticlesMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_sub_emitter_keep_velocity"), &ParticlesMaterial::get_sub_emitter_keep_velocity);
ClassDB::bind_method(D_METHOD("set_sub_emitter_keep_velocity", "enable"), &ParticlesMaterial::set_sub_emitter_keep_velocity);
+ ClassDB::bind_method(D_METHOD("set_attractor_interaction_enabled", "enabled"), &ParticlesMaterial::set_attractor_interaction_enabled);
+ ClassDB::bind_method(D_METHOD("is_attractor_interaction_enabled"), &ParticlesMaterial::is_attractor_interaction_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_collision_enabled", "enabled"), &ParticlesMaterial::set_collision_enabled);
+ ClassDB::bind_method(D_METHOD("is_collision_enabled"), &ParticlesMaterial::is_collision_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_collision_use_scale", "radius"), &ParticlesMaterial::set_collision_use_scale);
+ ClassDB::bind_method(D_METHOD("is_collision_using_scale"), &ParticlesMaterial::is_collision_using_scale);
+
+ ClassDB::bind_method(D_METHOD("set_collision_friction", "friction"), &ParticlesMaterial::set_collision_friction);
+ ClassDB::bind_method(D_METHOD("get_collision_friction"), &ParticlesMaterial::get_collision_friction);
+
+ ClassDB::bind_method(D_METHOD("set_collision_bounce", "bounce"), &ParticlesMaterial::set_collision_bounce);
+ ClassDB::bind_method(D_METHOD("get_collision_bounce"), &ParticlesMaterial::get_collision_bounce);
+
ADD_GROUP("Time", "");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
@@ -1221,6 +1305,14 @@ void ParticlesMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_amount_at_end", PROPERTY_HINT_RANGE, "1,32,1"), "set_sub_emitter_amount_at_end", "get_sub_emitter_amount_at_end");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sub_emitter_keep_velocity"), "set_sub_emitter_keep_velocity", "get_sub_emitter_keep_velocity");
+ ADD_GROUP("Attractor Interaction", "attractor_interaction_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "attractor_interaction_enabled"), "set_attractor_interaction_enabled", "is_attractor_interaction_enabled");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_enabled"), "set_collision_enabled", "is_collision_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_friction", "get_collision_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_bounce", "get_collision_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_scale"), "set_collision_use_scale", "is_collision_using_scale");
+
BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
@@ -1283,6 +1375,12 @@ ParticlesMaterial::ParticlesMaterial() :
set_sub_emitter_amount_at_end(1);
set_sub_emitter_keep_velocity(false);
+ set_attractor_interaction_enabled(true);
+ set_collision_enabled(true);
+ set_collision_bounce(0.0);
+ set_collision_friction(0.0);
+ set_collision_use_scale(false);
+
for (int i = 0; i < PARAM_MAX; i++) {
set_param_randomness(Parameter(i), 0);
}
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index fa8858f67f..7aca708889 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -37,11 +37,7 @@
/*
TODO:
-Path following
-*Manual emission
--Sub Emitters
--Attractors
-Emitter positions deformable by bones
--Collision
-Proper trails
*/
@@ -99,6 +95,9 @@ private:
uint32_t invalid_key : 1;
uint32_t has_emission_color : 1;
uint32_t sub_emitter : 2;
+ uint32_t attractor_enabled : 1;
+ uint32_t collision_enabled : 1;
+ uint32_t collision_scale : 1;
};
uint32_t key;
@@ -135,6 +134,9 @@ private:
mk.emission_shape = emission_shape;
mk.has_emission_color = emission_shape >= EMISSION_SHAPE_POINTS && emission_color_texture.is_valid();
mk.sub_emitter = sub_emitter_mode;
+ mk.collision_enabled = collision_enabled;
+ mk.attractor_enabled = attractor_interaction_enabled;
+ mk.collision_scale = collision_scale;
return mk;
}
@@ -201,6 +203,9 @@ private:
StringName sub_emitter_frequency;
StringName sub_emitter_amount_at_end;
StringName sub_emitter_keep_velocity;
+
+ StringName collision_friction;
+ StringName collision_bounce;
};
static ShaderNames *shader_names;
@@ -244,6 +249,12 @@ private:
bool sub_emitter_keep_velocity;
//do not save emission points here
+ bool attractor_interaction_enabled;
+ bool collision_enabled;
+ bool collision_scale;
+ float collision_friction;
+ float collision_bounce;
+
protected:
static void _bind_methods();
virtual void _validate_property(PropertyInfo &property) const override;
@@ -298,6 +309,21 @@ public:
void set_lifetime_randomness(float p_lifetime);
float get_lifetime_randomness() const;
+ void set_attractor_interaction_enabled(bool p_enable);
+ bool is_attractor_interaction_enabled() const;
+
+ void set_collision_enabled(bool p_enabled);
+ bool is_collision_enabled() const;
+
+ void set_collision_use_scale(bool p_scale);
+ bool is_collision_using_scale() const;
+
+ void set_collision_friction(float p_friction);
+ float get_collision_friction() const;
+
+ void set_collision_bounce(float p_bounce);
+ float get_collision_bounce() const;
+
static void init_shaders();
static void finish_shaders();
static void flush_changes();
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 84437faca0..1afc4e114e 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -1712,6 +1712,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "diffuse", "DIFFUSE_LIGHT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "specular", "SPECULAR_LIGHT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "roughness", "ROUGHNESS" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "metallic", "METALLIC" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_TRANSFORM, "world", "WORLD_MATRIX" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_TRANSFORM, "inv_camera", "INV_CAMERA_MATRIX" },
diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
index e744dbf9b0..3f4f11ee8d 100644
--- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
+++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
@@ -113,15 +113,15 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames
float *fftw = temporal_fft.ptrw();
for (int i = 0; i < to_fill; i++) { //left and right buffers
- float window = -0.5 * Math::cos(2.0 * Math_PI * (double)i / (double)to_fill) + 0.5;
- fftw[(i + temporal_fft_pos) * 2] = window * p_src_frames[i].l;
- fftw[(i + temporal_fft_pos) * 2 + 1] = 0;
- fftw[(i + temporal_fft_pos + fft_size * 2) * 2] = window * p_src_frames[i].r;
- fftw[(i + temporal_fft_pos + fft_size * 2) * 2 + 1] = 0;
+ float window = -0.5 * Math::cos(2.0 * Math_PI * (double)temporal_fft_pos / (double)fft_size) + 0.5;
+ fftw[temporal_fft_pos * 2] = window * p_src_frames->l;
+ fftw[temporal_fft_pos * 2 + 1] = 0;
+ fftw[(temporal_fft_pos + fft_size * 2) * 2] = window * p_src_frames->r;
+ fftw[(temporal_fft_pos + fft_size * 2) * 2 + 1] = 0;
+ ++p_src_frames;
+ ++temporal_fft_pos;
}
- p_src_frames += to_fill;
- temporal_fft_pos += to_fill;
p_frame_count -= to_fill;
if (temporal_fft_pos == fft_size * 2) {
@@ -134,9 +134,8 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames
for (int i = 0; i < fft_size; i++) {
//abs(vec)/fft_size normalizes each frequency
- float window = 1.0; //-.5 * Math::cos(2. * Math_PI * (double)i / (double)fft_size) + .5;
- hw[i].l = window * Vector2(fftw[i * 2], fftw[i * 2 + 1]).length() / float(fft_size);
- hw[i].r = window * Vector2(fftw[fft_size * 4 + i * 2], fftw[fft_size * 4 + i * 2 + 1]).length() / float(fft_size);
+ hw[i].l = Vector2(fftw[i * 2], fftw[i * 2 + 1]).length() / float(fft_size);
+ hw[i].r = Vector2(fftw[fft_size * 4 + i * 2], fftw[fft_size * 4 + i * 2 + 1]).length() / float(fft_size);
}
fft_pos = next; //swap
diff --git a/servers/rendering/rasterizer.h b/servers/rendering/rasterizer.h
index a24189bdd7..84c04f34b6 100644
--- a/servers/rendering/rasterizer.h
+++ b/servers/rendering/rasterizer.h
@@ -299,6 +299,7 @@ public:
virtual void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) = 0;
virtual void render_sdfgi(RID p_render_buffers, int p_region, InstanceBase **p_cull_result, int p_cull_count) = 0;
virtual void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const RID **p_positional_light_cull_result, const uint32_t *p_positional_light_cull_count) = 0;
+ virtual void render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, InstanceBase **p_cull_result, int p_cull_count) = 0;
virtual void set_scene_pass(uint64_t p_pass) = 0;
virtual void set_time(double p_time, double p_step) = 0;
@@ -660,6 +661,7 @@ public:
virtual void particles_set_process_material(RID p_particles, RID p_material) = 0;
virtual void particles_set_fixed_fps(RID p_particles, int p_fps) = 0;
virtual void particles_set_fractional_delta(RID p_particles, bool p_enable) = 0;
+ virtual void particles_set_collision_base_size(RID p_particles, float p_size) = 0;
virtual void particles_restart(RID p_particles) = 0;
virtual void particles_emit(RID p_particles, const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) = 0;
virtual void particles_set_subemitter(RID p_particles, RID p_subemitter_particles) = 0;
@@ -682,6 +684,28 @@ public:
virtual void particles_set_view_axis(RID p_particles, const Vector3 &p_axis) = 0;
+ virtual void particles_add_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) = 0;
+ virtual void particles_remove_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) = 0;
+
+ virtual void update_particles() = 0;
+
+ /* PARTICLES COLLISION */
+
+ virtual RID particles_collision_create() = 0;
+ virtual void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) = 0;
+ virtual void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) = 0;
+ virtual void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius) = 0; //for spheres
+ virtual void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) = 0; //for non-spheres
+ virtual void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength) = 0;
+ virtual void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality) = 0;
+ virtual void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve) = 0;
+ virtual void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) = 0; //for SDF and vector field, heightfield is dynamic
+ virtual void particles_collision_height_field_update(RID p_particles_collision) = 0; //for SDF and vector field
+ virtual void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) = 0; //for SDF and vector field
+ virtual AABB particles_collision_get_aabb(RID p_particles_collision) const = 0;
+ virtual bool particles_collision_is_heightfield(RID p_particles_collision) const = 0;
+ virtual RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const = 0;
+
/* GLOBAL VARIABLES */
virtual void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) = 0;
diff --git a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp
index 527ed09584..71acd4ceb6 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_effects_rd.cpp
@@ -1758,6 +1758,7 @@ RasterizerEffectsRD::~RasterizerEffectsRD() {
resolve.shader.version_free(resolve.shader_version);
roughness.shader.version_free(roughness.shader_version);
roughness_limiter.shader.version_free(roughness_limiter.shader_version);
+ sort.shader.version_free(sort.shader_version);
specular_merge.shader.version_free(specular_merge.shader_version);
ssao.blur_shader.version_free(ssao.blur_shader_version);
ssao.gather_shader.version_free(ssao.gather_shader_version);
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
index c56c208098..ac028e93f1 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
@@ -2018,6 +2018,39 @@ void RasterizerSceneHighEndRD::_render_shadow(RID p_framebuffer, InstanceBase **
}
}
+void RasterizerSceneHighEndRD::_render_particle_collider_heightfield(RID p_fb, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, InstanceBase **p_cull_result, int p_cull_count) {
+ RENDER_TIMESTAMP("Setup Render Collider Heightfield");
+
+ _update_render_base_uniform_set();
+
+ render_pass++;
+
+ scene_state.ubo.dual_paraboloid_side = 0;
+
+ _setup_environment(RID(), RID(), p_cam_projection, p_cam_transform, RID(), true, Vector2(1, 1), RID(), true, Color(), 0, p_cam_projection.get_z_far(), false, false);
+
+ render_list.clear();
+
+ PassMode pass_mode = PASS_MODE_SHADOW;
+
+ _fill_render_list(p_cull_result, p_cull_count, pass_mode);
+
+ _setup_view_dependant_uniform_set(RID(), RID(), nullptr, 0);
+
+ RENDER_TIMESTAMP("Render Collider Heightield");
+
+ render_list.sort_by_key(false);
+
+ _fill_instances(render_list.elements, render_list.element_count, true);
+
+ {
+ //regular forward for now
+ RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_fb, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ);
+ _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_fb), render_list.elements, render_list.element_count, false, pass_mode, true, RID(), RID());
+ RD::get_singleton()->draw_list_end();
+ }
+}
+
void RasterizerSceneHighEndRD::_render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) {
RENDER_TIMESTAMP("Setup Rendering Material");
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
index 1aad9039ff..4c89928c95 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
@@ -581,6 +581,7 @@ protected:
virtual void _render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region);
virtual void _render_uv2(InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region);
virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, InstanceBase **p_cull_result, int p_cull_count, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture);
+ virtual void _render_particle_collider_heightfield(RID p_fb, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, InstanceBase **p_cull_result, int p_cull_count);
public:
virtual void set_time(double p_time, double p_step);
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
index 958d8eac1f..934330cc9b 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
@@ -7511,6 +7511,23 @@ void RasterizerSceneRD::render_sdfgi(RID p_render_buffers, int p_region, Instanc
}
}
+void RasterizerSceneRD::render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, InstanceBase **p_cull_result, int p_cull_count) {
+ ERR_FAIL_COND(!storage->particles_collision_is_heightfield(p_collider));
+ Vector3 extents = storage->particles_collision_get_extents(p_collider) * p_transform.basis.get_scale();
+ CameraMatrix cm;
+ cm.set_orthogonal(-extents.x, extents.x, -extents.z, extents.z, 0, extents.y * 2.0);
+
+ Vector3 cam_pos = p_transform.origin;
+ cam_pos.y += extents.y;
+
+ Transform cam_xform;
+ cam_xform.set_look_at(cam_pos, cam_pos - p_transform.basis.get_axis(Vector3::AXIS_Y), -p_transform.basis.get_axis(Vector3::AXIS_Z).normalized());
+
+ RID fb = storage->particles_collision_get_heightfield_framebuffer(p_collider);
+
+ _render_particle_collider_heightfield(fb, cam_xform, cm, p_cull_result, p_cull_count);
+}
+
void RasterizerSceneRD::render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const RID **p_positional_light_cull_result, const uint32_t *p_positional_light_cull_count) {
RenderBuffers *rb = render_buffers_owner.getornull(p_render_buffers);
ERR_FAIL_COND(!rb);
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h
index fe31d2f76b..0e7e56716b 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.h
@@ -112,6 +112,7 @@ protected:
virtual void _render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) = 0;
virtual void _render_uv2(InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) = 0;
virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, InstanceBase **p_cull_result, int p_cull_count, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) = 0;
+ virtual void _render_particle_collider_heightfield(RID p_fb, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, InstanceBase **p_cull_result, int p_cull_count) = 0;
virtual void _debug_giprobe(RID p_gi_probe, RenderingDevice::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
void _debug_sdfgi_probes(RID p_render_buffers, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform);
@@ -1876,6 +1877,8 @@ public:
void render_sdfgi(RID p_render_buffers, int p_region, InstanceBase **p_cull_result, int p_cull_count);
void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const RID **p_positional_light_cull_result, const uint32_t *p_positional_light_cull_count);
+ void render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, InstanceBase **p_cull_result, int p_cull_count);
+
virtual void set_scene_pass(uint64_t p_pass) {
scene_pass = p_pass;
}
diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
index db2c707984..90dd6af319 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
@@ -3333,6 +3333,10 @@ void RasterizerStorageRD::_particles_free_data(Particles *particles) {
particles->particles_transforms_buffer_uniform_set = RID();
particles->particle_buffer = RID();
+ if (RD::get_singleton()->uniform_set_is_valid(particles->collision_textures_uniform_set)) {
+ RD::get_singleton()->free(particles->collision_textures_uniform_set);
+ }
+
if (particles->particles_sort_buffer.is_valid()) {
RD::get_singleton()->free(particles->particles_sort_buffer);
particles->particles_sort_buffer = RID();
@@ -3454,6 +3458,13 @@ void RasterizerStorageRD::particles_set_fractional_delta(RID p_particles, bool p
particles->fractional_delta = p_enable;
}
+void RasterizerStorageRD::particles_set_collision_base_size(RID p_particles, float p_size) {
+ Particles *particles = particles_owner.getornull(p_particles);
+ ERR_FAIL_COND(!particles);
+
+ particles->collision_base_size = p_size;
+}
+
void RasterizerStorageRD::particles_set_process_material(RID p_particles, RID p_material) {
Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND(!particles);
@@ -3646,6 +3657,22 @@ RID RasterizerStorageRD::particles_get_draw_pass_mesh(RID p_particles, int p_pas
return particles->draw_passes[p_pass];
}
+void RasterizerStorageRD::particles_add_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) {
+ Particles *particles = particles_owner.getornull(p_particles);
+ ERR_FAIL_COND(!particles);
+
+ ERR_FAIL_COND(p_instance->base_type != RS::INSTANCE_PARTICLES_COLLISION);
+
+ particles->collisions.insert(p_instance);
+}
+
+void RasterizerStorageRD::particles_remove_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance) {
+ Particles *particles = particles_owner.getornull(p_particles);
+ ERR_FAIL_COND(!particles);
+
+ particles->collisions.erase(p_instance);
+}
+
void RasterizerStorageRD::_particles_process(Particles *p_particles, float p_delta) {
if (p_particles->particles_material_uniform_set.is_null() || !RD::get_singleton()->uniform_set_is_valid(p_particles->particles_material_uniform_set)) {
Vector<RD::Uniform> uniforms;
@@ -3729,6 +3756,195 @@ void RasterizerStorageRD::_particles_process(Particles *p_particles, float p_del
frame_params.cycle = p_particles->cycle_number;
+ { //collision and attractors
+
+ frame_params.collider_count = 0;
+ frame_params.attractor_count = 0;
+ frame_params.particle_size = p_particles->collision_base_size;
+
+ RID collision_3d_textures[ParticlesFrameParams::MAX_3D_TEXTURES];
+ RID collision_heightmap_texture;
+
+ Transform to_particles;
+ if (p_particles->use_local_coords) {
+ to_particles = p_particles->emission_transform.affine_inverse();
+ }
+ uint32_t collision_3d_textures_used = 0;
+ for (const Set<RasterizerScene::InstanceBase *>::Element *E = p_particles->collisions.front(); E; E = E->next()) {
+ ParticlesCollision *pc = particles_collision_owner.getornull(E->get()->base);
+ Transform to_collider = E->get()->transform;
+ if (p_particles->use_local_coords) {
+ to_collider = to_particles * to_collider;
+ }
+ Vector3 scale = to_collider.basis.get_scale();
+ to_collider.basis.orthonormalize();
+
+ if (pc->type <= RS::PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT) {
+ //attractor
+ if (frame_params.attractor_count >= ParticlesFrameParams::MAX_ATTRACTORS) {
+ continue;
+ }
+
+ ParticlesFrameParams::Attractor &attr = frame_params.attractors[frame_params.attractor_count];
+
+ store_transform(to_collider, attr.transform);
+ attr.strength = pc->attractor_strength;
+ attr.attenuation = pc->attractor_attenuation;
+ attr.directionality = pc->attractor_directionality;
+
+ switch (pc->type) {
+ case RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT: {
+ attr.type = ParticlesFrameParams::ATTRACTOR_TYPE_SPHERE;
+ float radius = pc->radius;
+ radius *= (scale.x + scale.y + scale.z) / 3.0;
+ attr.extents[0] = radius;
+ attr.extents[1] = radius;
+ attr.extents[2] = radius;
+ } break;
+ case RS::PARTICLES_COLLISION_TYPE_BOX_ATTRACT: {
+ attr.type = ParticlesFrameParams::ATTRACTOR_TYPE_BOX;
+ Vector3 extents = pc->extents * scale;
+ attr.extents[0] = extents.x;
+ attr.extents[1] = extents.y;
+ attr.extents[2] = extents.z;
+ } break;
+ case RS::PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT: {
+ if (collision_3d_textures_used >= ParticlesFrameParams::MAX_3D_TEXTURES) {
+ continue;
+ }
+ attr.type = ParticlesFrameParams::ATTRACTOR_TYPE_VECTOR_FIELD;
+ Vector3 extents = pc->extents * scale;
+ attr.extents[0] = extents.x;
+ attr.extents[1] = extents.y;
+ attr.extents[2] = extents.z;
+ attr.texture_index = collision_3d_textures_used;
+
+ collision_3d_textures[collision_3d_textures_used] = pc->field_texture;
+ collision_3d_textures_used++;
+ } break;
+ default: {
+ }
+ }
+
+ frame_params.attractor_count++;
+ } else {
+ //collider
+ if (frame_params.collider_count >= ParticlesFrameParams::MAX_COLLIDERS) {
+ continue;
+ }
+
+ ParticlesFrameParams::Collider &col = frame_params.colliders[frame_params.collider_count];
+
+ store_transform(to_collider, col.transform);
+ switch (pc->type) {
+ case RS::PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE: {
+ col.type = ParticlesFrameParams::COLLISION_TYPE_SPHERE;
+ float radius = pc->radius;
+ radius *= (scale.x + scale.y + scale.z) / 3.0;
+ col.extents[0] = radius;
+ col.extents[1] = radius;
+ col.extents[2] = radius;
+ } break;
+ case RS::PARTICLES_COLLISION_TYPE_BOX_COLLIDE: {
+ col.type = ParticlesFrameParams::COLLISION_TYPE_BOX;
+ Vector3 extents = pc->extents * scale;
+ col.extents[0] = extents.x;
+ col.extents[1] = extents.y;
+ col.extents[2] = extents.z;
+ } break;
+ case RS::PARTICLES_COLLISION_TYPE_SDF_COLLIDE: {
+ if (collision_3d_textures_used >= ParticlesFrameParams::MAX_3D_TEXTURES) {
+ continue;
+ }
+ col.type = ParticlesFrameParams::COLLISION_TYPE_SDF;
+ Vector3 extents = pc->extents * scale;
+ col.extents[0] = extents.x;
+ col.extents[1] = extents.y;
+ col.extents[2] = extents.z;
+ col.texture_index = collision_3d_textures_used;
+ col.scale = (scale.x + scale.y + scale.z) * 0.333333333333; //non uniform scale non supported
+
+ collision_3d_textures[collision_3d_textures_used] = pc->field_texture;
+ collision_3d_textures_used++;
+ } break;
+ case RS::PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE: {
+ if (collision_heightmap_texture != RID()) { //already taken
+ continue;
+ }
+
+ col.type = ParticlesFrameParams::COLLISION_TYPE_HEIGHT_FIELD;
+ Vector3 extents = pc->extents * scale;
+ col.extents[0] = extents.x;
+ col.extents[1] = extents.y;
+ col.extents[2] = extents.z;
+ collision_heightmap_texture = pc->heightfield_texture;
+ } break;
+ default: {
+ }
+ }
+
+ frame_params.collider_count++;
+ }
+ }
+
+ bool different = false;
+ if (collision_3d_textures_used == p_particles->collision_3d_textures_used) {
+ for (int i = 0; i < ParticlesFrameParams::MAX_3D_TEXTURES; i++) {
+ if (p_particles->collision_3d_textures[i] != collision_3d_textures[i]) {
+ different = true;
+ break;
+ }
+ }
+ }
+
+ if (collision_heightmap_texture != p_particles->collision_heightmap_texture) {
+ different = true;
+ }
+
+ bool uniform_set_valid = RD::get_singleton()->uniform_set_is_valid(p_particles->collision_textures_uniform_set);
+
+ if (different || !uniform_set_valid) {
+ if (uniform_set_valid) {
+ RD::get_singleton()->free(p_particles->collision_textures_uniform_set);
+ }
+
+ Vector<RD::Uniform> uniforms;
+
+ {
+ RD::Uniform u;
+ u.type = RD::UNIFORM_TYPE_TEXTURE;
+ u.binding = 0;
+ for (uint32_t i = 0; i < ParticlesFrameParams::MAX_3D_TEXTURES; i++) {
+ RID rd_tex;
+ if (i < collision_3d_textures_used) {
+ Texture *t = texture_owner.getornull(collision_3d_textures[i]);
+ if (t && t->type == Texture::TYPE_3D) {
+ rd_tex = t->rd_texture;
+ }
+ }
+
+ if (rd_tex == RID()) {
+ rd_tex = default_rd_textures[DEFAULT_RD_TEXTURE_3D_WHITE];
+ }
+ u.ids.push_back(rd_tex);
+ }
+ uniforms.push_back(u);
+ }
+ {
+ RD::Uniform u;
+ u.type = RD::UNIFORM_TYPE_TEXTURE;
+ u.binding = 1;
+ if (collision_heightmap_texture.is_valid()) {
+ u.ids.push_back(collision_heightmap_texture);
+ } else {
+ u.ids.push_back(default_rd_textures[DEFAULT_RD_TEXTURE_BLACK]);
+ }
+ uniforms.push_back(u);
+ }
+ p_particles->collision_textures_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, particles_shader.default_shader_rd, 2);
+ }
+ }
+
ParticlesShader::PushConstant push_constant;
push_constant.clear = p_particles->clear;
@@ -3783,8 +3999,10 @@ void RasterizerStorageRD::_particles_process(Particles *p_particles, float p_del
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, m->shader_data->pipeline);
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, particles_shader.base_uniform_set, 0);
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, p_particles->particles_material_uniform_set, 1);
+ RD::get_singleton()->compute_list_bind_uniform_set(compute_list, p_particles->collision_textures_uniform_set, 2);
+
if (m->uniform_set.is_valid()) {
- RD::get_singleton()->compute_list_bind_uniform_set(compute_list, m->uniform_set, 2);
+ RD::get_singleton()->compute_list_bind_uniform_set(compute_list, m->uniform_set, 3);
}
RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ParticlesShader::PushConstant));
@@ -4190,7 +4408,7 @@ void RasterizerStorageRD::ParticlesMaterialData::update_parameters(const Map<Str
}
}
- uniform_set = RD::get_singleton()->uniform_set_create(uniforms, base_singleton->particles_shader.shader.version_get_shader(shader_data->version, 0), 2);
+ uniform_set = RD::get_singleton()->uniform_set_create(uniforms, base_singleton->particles_shader.shader.version_get_shader(shader_data->version, 0), 3);
}
RasterizerStorageRD::ParticlesMaterialData::~ParticlesMaterialData() {
@@ -4211,6 +4429,171 @@ RasterizerStorageRD::MaterialData *RasterizerStorageRD::_create_particles_materi
return material_data;
}
////////
+
+/* PARTICLES COLLISION API */
+
+RID RasterizerStorageRD::particles_collision_create() {
+ return particles_collision_owner.make_rid(ParticlesCollision());
+}
+
+RID RasterizerStorageRD::particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND_V(!particles_collision, RID());
+ ERR_FAIL_COND_V(particles_collision->type != RS::PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE, RID());
+
+ if (particles_collision->heightfield_texture == RID()) {
+ //create
+ int resolutions[RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX] = { 256, 512, 1024, 2048, 4096, 8192 };
+ Size2i size;
+ if (particles_collision->extents.x > particles_collision->extents.z) {
+ size.x = resolutions[particles_collision->heightfield_resolution];
+ size.y = int32_t(particles_collision->extents.z / particles_collision->extents.x * size.x);
+ } else {
+ size.y = resolutions[particles_collision->heightfield_resolution];
+ size.x = int32_t(particles_collision->extents.x / particles_collision->extents.z * size.y);
+ }
+
+ RD::TextureFormat tf;
+ tf.format = RD::DATA_FORMAT_D32_SFLOAT;
+ tf.width = size.x;
+ tf.height = size.y;
+ tf.type = RD::TEXTURE_TYPE_2D;
+ tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
+
+ particles_collision->heightfield_texture = RD::get_singleton()->texture_create(tf, RD::TextureView());
+
+ Vector<RID> fb_tex;
+ fb_tex.push_back(particles_collision->heightfield_texture);
+ particles_collision->heightfield_fb = RD::get_singleton()->framebuffer_create(fb_tex);
+ particles_collision->heightfield_fb_size = size;
+ }
+
+ return particles_collision->heightfield_fb;
+}
+
+void RasterizerStorageRD::particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ if (p_type == particles_collision->type) {
+ return;
+ }
+
+ if (particles_collision->heightfield_texture.is_valid()) {
+ RD::get_singleton()->free(particles_collision->heightfield_texture);
+ particles_collision->heightfield_texture = RID();
+ }
+ particles_collision->type = p_type;
+ particles_collision->instance_dependency.instance_notify_changed(true, false);
+}
+
+void RasterizerStorageRD::particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+ particles_collision->cull_mask = p_cull_mask;
+}
+
+void RasterizerStorageRD::particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->radius = p_radius;
+ particles_collision->instance_dependency.instance_notify_changed(true, false);
+}
+
+void RasterizerStorageRD::particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->extents = p_extents;
+ particles_collision->instance_dependency.instance_notify_changed(true, false);
+}
+
+void RasterizerStorageRD::particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->attractor_strength = p_strength;
+}
+
+void RasterizerStorageRD::particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->attractor_directionality = p_directionality;
+}
+
+void RasterizerStorageRD::particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->attractor_attenuation = p_curve;
+}
+
+void RasterizerStorageRD::particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ particles_collision->field_texture = p_texture;
+}
+
+void RasterizerStorageRD::particles_collision_height_field_update(RID p_particles_collision) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+ particles_collision->instance_dependency.instance_notify_changed(true, false);
+}
+
+void RasterizerStorageRD::particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND(!particles_collision);
+
+ if (particles_collision->heightfield_resolution == p_resolution) {
+ return;
+ }
+
+ particles_collision->heightfield_resolution = p_resolution;
+
+ if (particles_collision->heightfield_texture.is_valid()) {
+ RD::get_singleton()->free(particles_collision->heightfield_texture);
+ particles_collision->heightfield_texture = RID();
+ }
+}
+
+AABB RasterizerStorageRD::particles_collision_get_aabb(RID p_particles_collision) const {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND_V(!particles_collision, AABB());
+
+ switch (particles_collision->type) {
+ case RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT:
+ case RS::PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE: {
+ AABB aabb;
+ aabb.position = -Vector3(1, 1, 1) * particles_collision->radius;
+ aabb.size = Vector3(2, 2, 2) * particles_collision->radius;
+ return aabb;
+ }
+ default: {
+ AABB aabb;
+ aabb.position = -particles_collision->extents;
+ aabb.size = particles_collision->extents * 2;
+ return aabb;
+ }
+ }
+
+ return AABB();
+}
+
+Vector3 RasterizerStorageRD::particles_collision_get_extents(RID p_particles_collision) const {
+ const ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND_V(!particles_collision, Vector3());
+ return particles_collision->extents;
+}
+
+bool RasterizerStorageRD::particles_collision_is_heightfield(RID p_particles_collision) const {
+ const ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_particles_collision);
+ ERR_FAIL_COND_V(!particles_collision, false);
+ return particles_collision->type == RS::PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE;
+}
+
/* SKELETON API */
RID RasterizerStorageRD::skeleton_create() {
@@ -4680,6 +5063,9 @@ void RasterizerStorageRD::reflection_probe_set_extents(RID p_probe, const Vector
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
+ if (reflection_probe->extents == p_extents) {
+ return;
+ }
reflection_probe->extents = p_extents;
reflection_probe->instance_dependency.instance_notify_changed(true, false);
}
@@ -5797,6 +6183,9 @@ void RasterizerStorageRD::base_update_dependency(RID p_base, RasterizerScene::In
} else if (particles_owner.owns(p_base)) {
Particles *p = particles_owner.getornull(p_base);
p_instance->update_dependency(&p->instance_dependency);
+ } else if (particles_collision_owner.owns(p_base)) {
+ ParticlesCollision *pc = particles_collision_owner.getornull(p_base);
+ p_instance->update_dependency(&pc->instance_dependency);
}
}
@@ -5832,6 +6221,9 @@ RS::InstanceType RasterizerStorageRD::get_base_type(RID p_rid) const {
if (particles_owner.owns(p_rid)) {
return RS::INSTANCE_PARTICLES;
}
+ if (particles_collision_owner.owns(p_rid)) {
+ return RS::INSTANCE_PARTICLES_COLLISION;
+ }
return RS::INSTANCE_NONE;
}
@@ -6735,8 +7127,6 @@ void RasterizerStorageRD::update_dirty_resources() {
_update_dirty_multimeshes();
_update_dirty_skeletons();
_update_decal_atlas();
-
- update_particles();
}
bool RasterizerStorageRD::has_os_feature(const String &p_feature) const {
@@ -6871,6 +7261,14 @@ bool RasterizerStorageRD::free(RID p_rid) {
_particles_free_data(particles);
particles->instance_dependency.instance_notify_deleted(p_rid);
particles_owner.free(p_rid);
+ } else if (particles_collision_owner.owns(p_rid)) {
+ ParticlesCollision *particles_collision = particles_collision_owner.getornull(p_rid);
+
+ if (particles_collision->heightfield_texture.is_valid()) {
+ RD::get_singleton()->free(particles_collision->heightfield_texture);
+ }
+ particles_collision->instance_dependency.instance_notify_deleted(p_rid);
+ particles_collision_owner.free(p_rid);
} else if (render_target_owner.owns(p_rid)) {
RenderTarget *rt = render_target_owner.getornull(p_rid);
@@ -7379,14 +7777,19 @@ RasterizerStorageRD::RasterizerStorageRD() {
actions.renames["RESTART_COLOR"] = "restart_color";
actions.renames["RESTART_CUSTOM"] = "restart_custom";
actions.renames["emit_particle"] = "emit_particle";
+ actions.renames["COLLIDED"] = "collided";
+ actions.renames["COLLISION_NORMAL"] = "collision_normal";
+ actions.renames["COLLISION_DEPTH"] = "collision_depth";
+ actions.renames["ATTRACTOR_FORCE"] = "attractor_force";
actions.render_mode_defines["disable_force"] = "#define DISABLE_FORCE\n";
actions.render_mode_defines["disable_velocity"] = "#define DISABLE_VELOCITY\n";
actions.render_mode_defines["keep_data"] = "#define ENABLE_KEEP_DATA\n";
+ actions.render_mode_defines["collision_use_scale"] = "#define USE_COLLISON_SCALE\n";
actions.sampler_array_name = "material_samplers";
actions.base_texture_binding_index = 1;
- actions.texture_layout_set = 2;
+ actions.texture_layout_set = 3;
actions.base_uniform_string = "material.";
actions.base_varying_index = 10;
@@ -7481,7 +7884,12 @@ RasterizerStorageRD::~RasterizerStorageRD() {
for (int i = 0; i < DEFAULT_RD_BUFFER_MAX; i++) {
RD::get_singleton()->free(mesh_default_rd_buffers[i]);
}
+
giprobe_sdf_shader.version_free(giprobe_sdf_shader_version);
+ particles_shader.copy_shader.version_free(particles_shader.copy_shader_version);
+
+ RenderingServer::get_singleton()->free(particles_shader.default_material);
+ RenderingServer::get_singleton()->free(particles_shader.default_shader);
RD::get_singleton()->free(default_rd_storage_buffer);
diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h
index e14b9528cf..b03a26e200 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h
+++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h
@@ -475,6 +475,46 @@ private:
};
struct ParticlesFrameParams {
+ enum {
+ MAX_ATTRACTORS = 32,
+ MAX_COLLIDERS = 32,
+ MAX_3D_TEXTURES = 7
+ };
+
+ enum AttractorType {
+ ATTRACTOR_TYPE_SPHERE,
+ ATTRACTOR_TYPE_BOX,
+ ATTRACTOR_TYPE_VECTOR_FIELD,
+ };
+
+ struct Attractor {
+ float transform[16];
+ float extents[3]; //exents or radius
+ uint32_t type;
+
+ uint32_t texture_index; //texture index for vector field
+ float strength;
+ float attenuation;
+ float directionality;
+ };
+
+ enum CollisionType {
+ COLLISION_TYPE_SPHERE,
+ COLLISION_TYPE_BOX,
+ COLLISION_TYPE_SDF,
+ COLLISION_TYPE_HEIGHT_FIELD
+ };
+
+ struct Collider {
+ float transform[16];
+ float extents[3]; //exents or radius
+ uint32_t type;
+
+ uint32_t texture_index; //texture index for vector field
+ float scale;
+ uint32_t pad[2];
+ };
+
uint32_t emitting;
float system_phase;
float prev_system_phase;
@@ -486,9 +526,14 @@ private:
float delta;
uint32_t random_seed;
- uint32_t pad[3];
+ uint32_t attractor_count;
+ uint32_t collider_count;
+ float particle_size;
float emission_transform[16];
+
+ Attractor attractors[MAX_ATTRACTORS];
+ Collider colliders[MAX_COLLIDERS];
};
struct ParticleEmissionBufferData {
@@ -536,6 +581,11 @@ private:
RID particles_material_uniform_set;
RID particles_copy_uniform_set;
RID particles_transforms_buffer_uniform_set;
+ RID collision_textures_uniform_set;
+
+ RID collision_3d_textures[ParticlesFrameParams::MAX_3D_TEXTURES];
+ uint32_t collision_3d_textures_used = 0;
+ RID collision_heightmap_texture;
RID particles_sort_buffer;
RID particles_sort_uniform_set;
@@ -557,6 +607,7 @@ private:
int fixed_fps;
bool fractional_delta;
float frame_remainder;
+ float collision_base_size;
bool clear;
@@ -569,6 +620,8 @@ private:
ParticleEmissionBuffer *emission_buffer = nullptr;
RID emission_storage_buffer;
+ Set<RasterizerScene::InstanceBase *> collisions;
+
Particles() :
inactive(true),
inactive_time(0.0),
@@ -590,6 +643,7 @@ private:
fixed_fps(0),
fractional_delta(false),
frame_remainder(0),
+ collision_base_size(0.01),
clear(true) {
}
@@ -704,6 +758,28 @@ private:
mutable RID_Owner<Particles> particles_owner;
+ /* Particles Collision */
+
+ struct ParticlesCollision {
+ RS::ParticlesCollisionType type = RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT;
+ uint32_t cull_mask = 0xFFFFFFFF;
+ float radius = 1.0;
+ Vector3 extents = Vector3(1, 1, 1);
+ float attractor_strength = 1.0;
+ float attractor_attenuation = 1.0;
+ float attractor_directionality = 0.0;
+ RID field_texture;
+ RID heightfield_texture;
+ RID heightfield_fb;
+ Size2i heightfield_fb_size;
+
+ RS::ParticlesCollisionHeightfieldResolution heightfield_resolution = RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024;
+
+ RasterizerScene::InstanceDependency instance_dependency;
+ };
+
+ mutable RID_Owner<ParticlesCollision> particles_collision_owner;
+
/* Skeleton */
struct Skeleton {
@@ -1691,6 +1767,7 @@ public:
void particles_set_process_material(RID p_particles, RID p_material);
void particles_set_fixed_fps(RID p_particles, int p_fps);
void particles_set_fractional_delta(RID p_particles, bool p_enable);
+ void particles_set_collision_base_size(RID p_particles, float p_size);
void particles_restart(RID p_particles);
void particles_emit(RID p_particles, const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
void particles_set_subemitter(RID p_particles, RID p_subemitter_particles);
@@ -1748,6 +1825,27 @@ public:
return particles->particles_transforms_buffer_uniform_set;
}
+ virtual void particles_add_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance);
+ virtual void particles_remove_collision(RID p_particles, RasterizerScene::InstanceBase *p_instance);
+
+ /* PARTICLES COLLISION */
+
+ virtual RID particles_collision_create();
+ virtual void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type);
+ virtual void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask);
+ virtual void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius); //for spheres
+ virtual void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents); //for non-spheres
+ virtual void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength);
+ virtual void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality);
+ virtual void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve);
+ virtual void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture); //for SDF and vector field, heightfield is dynamic
+ virtual void particles_collision_height_field_update(RID p_particles_collision); //for SDF and vector field
+ virtual void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution); //for SDF and vector field
+ virtual AABB particles_collision_get_aabb(RID p_particles_collision) const;
+ virtual Vector3 particles_collision_get_extents(RID p_particles_collision) const;
+ virtual bool particles_collision_is_heightfield(RID p_particles_collision) const;
+ RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const;
+
/* GLOBAL VARIABLES API */
virtual void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value);
diff --git a/servers/rendering/rasterizer_rd/shaders/particles.glsl b/servers/rendering/rasterizer_rd/shaders/particles.glsl
index a924509771..926c7ef9fc 100644
--- a/servers/rendering/rasterizer_rd/shaders/particles.glsl
+++ b/servers/rendering/rasterizer_rd/shaders/particles.glsl
@@ -31,6 +31,40 @@ global_variables;
/* Set 1: FRAME AND PARTICLE DATA */
// a frame history is kept for trail deterministic behavior
+
+#define MAX_ATTRACTORS 32
+
+#define ATTRACTOR_TYPE_SPHERE 0
+#define ATTRACTOR_TYPE_BOX 1
+#define ATTRACTOR_TYPE_VECTOR_FIELD 2
+
+struct Attractor {
+ mat4 transform;
+ vec3 extents; //exents or radius
+ uint type;
+ uint texture_index; //texture index for vector field
+ float strength;
+ float attenuation;
+ float directionality;
+};
+
+#define MAX_COLLIDERS 32
+
+#define COLLIDER_TYPE_SPHERE 0
+#define COLLIDER_TYPE_BOX 1
+#define COLLIDER_TYPE_SDF 2
+#define COLLIDER_TYPE_HEIGHT_FIELD 3
+
+struct Collider {
+ mat4 transform;
+ vec3 extents; //exents or radius
+ uint type;
+
+ uint texture_index; //texture index for vector field
+ float scale;
+ uint pad[2];
+};
+
struct FrameParams {
bool emitting;
float system_phase;
@@ -43,9 +77,14 @@ struct FrameParams {
float delta;
uint random_seed;
- uint pad[3];
+ uint attractor_count;
+ uint collider_count;
+ float particle_size;
mat4 emission_transform;
+
+ Attractor attractors[MAX_ATTRACTORS];
+ Collider colliders[MAX_COLLIDERS];
};
layout(set = 1, binding = 0, std430) restrict buffer FrameHistory {
@@ -80,7 +119,7 @@ struct ParticleEmission {
vec4 custom;
};
-layout(set = 1, binding = 2, std430) restrict volatile coherent buffer SourceEmission {
+layout(set = 1, binding = 2, std430) restrict buffer SourceEmission {
int particle_count;
uint pad0;
uint pad1;
@@ -89,7 +128,7 @@ layout(set = 1, binding = 2, std430) restrict volatile coherent buffer SourceEmi
}
src_particles;
-layout(set = 1, binding = 3, std430) restrict volatile coherent buffer DestEmission {
+layout(set = 1, binding = 3, std430) restrict buffer DestEmission {
int particle_count;
int particle_max;
uint pad1;
@@ -98,10 +137,17 @@ layout(set = 1, binding = 3, std430) restrict volatile coherent buffer DestEmiss
}
dst_particles;
-/* SET 2: MATERIAL */
+/* SET 2: COLLIDER/ATTRACTOR TEXTURES */
+
+#define MAX_3D_TEXTURES 7
+
+layout(set = 2, binding = 0) uniform texture3D sdf_vec_textures[MAX_3D_TEXTURES];
+layout(set = 2, binding = 1) uniform texture2D height_field_texture;
+
+/* SET 3: MATERIAL */
#ifdef USE_MATERIAL_UNIFORMS
-layout(set = 2, binding = 0, std140) uniform MaterialUniforms{
+layout(set = 3, binding = 0, std140) uniform MaterialUniforms{
/* clang-format off */
MATERIAL_UNIFORMS
/* clang-format on */
@@ -140,29 +186,7 @@ bool emit_particle(mat4 p_xform, vec3 p_velocity, vec4 p_color, vec4 p_custom, u
atomicAdd(dst_particles.particle_count, -1);
return false;
}
- /*
- valid = true;
-
- int attempts = 256; // never trust compute
- while(attempts-- > 0) {
- dst_index = dst_particles.particle_count;
- if (dst_index == dst_particles.particle_max) {
- return false; //can't emit anymore
- }
-
- if (atomicCompSwap(dst_particles.particle_count, dst_index, dst_index +1 ) != dst_index) {
- continue;
- }
- valid=true;
- break;
- }
- barrier();
-
- if (!valid) {
- return false; //gave up (attempts exhausted)
- }
-*/
dst_particles.data[dst_index].xform = p_xform;
dst_particles.data[dst_index].velocity = p_velocity;
dst_particles.data[dst_index].color = p_color;
@@ -217,6 +241,199 @@ void main() {
vec4(0.0, 0.0, 0.0, 1.0));
}
+ bool collided = false;
+ vec3 collision_normal = vec3(0.0);
+ float collision_depth = 0.0;
+
+ vec3 attractor_force = vec3(0.0);
+
+#if !defined(DISABLE_VELOCITY)
+
+ if (PARTICLE.is_active) {
+ PARTICLE.xform[3].xyz += PARTICLE.velocity * local_delta;
+ }
+#endif
+
+ /* Process physics if active */
+
+ if (PARTICLE.is_active) {
+ for (uint i = 0; i < FRAME.attractor_count; i++) {
+ vec3 dir;
+ float amount;
+ vec3 rel_vec = PARTICLE.xform[3].xyz - FRAME.attractors[i].transform[3].xyz;
+ vec3 local_pos = rel_vec * mat3(FRAME.attractors[i].transform);
+
+ switch (FRAME.attractors[i].type) {
+ case ATTRACTOR_TYPE_SPHERE: {
+ dir = normalize(rel_vec);
+ float d = length(local_pos) / FRAME.attractors[i].extents.x;
+ if (d > 1.0) {
+ continue;
+ }
+ amount = max(0.0, 1.0 - d);
+ } break;
+ case ATTRACTOR_TYPE_BOX: {
+ dir = normalize(rel_vec);
+
+ vec3 abs_pos = abs(local_pos / FRAME.attractors[i].extents);
+ float d = max(abs_pos.x, max(abs_pos.y, abs_pos.z));
+ if (d > 1.0) {
+ continue;
+ }
+ amount = max(0.0, 1.0 - d);
+
+ } break;
+ case ATTRACTOR_TYPE_VECTOR_FIELD: {
+ vec3 uvw_pos = (local_pos / FRAME.attractors[i].extents) * 2.0 - 1.0;
+ if (any(lessThan(uvw_pos, vec3(0.0))) || any(greaterThan(uvw_pos, vec3(1.0)))) {
+ continue;
+ }
+ vec3 s = texture(sampler3D(sdf_vec_textures[FRAME.attractors[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos).xyz;
+ dir = mat3(FRAME.attractors[i].transform) * normalize(s); //revert direction
+ amount = length(s);
+
+ } break;
+ }
+ amount = pow(amount, FRAME.attractors[i].attenuation);
+ dir = normalize(mix(dir, FRAME.attractors[i].transform[2].xyz, FRAME.attractors[i].directionality));
+ attractor_force -= amount * dir * FRAME.attractors[i].strength;
+ }
+
+ float particle_size = FRAME.particle_size;
+
+#ifdef USE_COLLISON_SCALE
+
+ particle_size *= dot(vec3(length(PARTICLE.xform[0].xyz), length(PARTICLE.xform[1].xyz), length(PARTICLE.xform[2].xyz)), vec3(0.33333333333));
+
+#endif
+
+ for (uint i = 0; i < FRAME.collider_count; i++) {
+ vec3 normal;
+ float depth;
+ bool col = false;
+
+ vec3 rel_vec = PARTICLE.xform[3].xyz - FRAME.colliders[i].transform[3].xyz;
+ vec3 local_pos = rel_vec * mat3(FRAME.colliders[i].transform);
+
+ switch (FRAME.colliders[i].type) {
+ case COLLIDER_TYPE_SPHERE: {
+ float d = length(rel_vec) - (particle_size + FRAME.colliders[i].extents.x);
+
+ if (d < 0.0) {
+ col = true;
+ depth = -d;
+ normal = normalize(rel_vec);
+ }
+
+ } break;
+ case COLLIDER_TYPE_BOX: {
+ vec3 abs_pos = abs(local_pos);
+ vec3 sgn_pos = sign(local_pos);
+
+ if (any(greaterThan(abs_pos, FRAME.colliders[i].extents))) {
+ //point outside box
+
+ vec3 closest = min(abs_pos, FRAME.colliders[i].extents);
+ vec3 rel = abs_pos - closest;
+ depth = length(rel) - particle_size;
+ if (depth < 0.0) {
+ col = true;
+ normal = mat3(FRAME.colliders[i].transform) * (normalize(rel) * sgn_pos);
+ depth = -depth;
+ }
+ } else {
+ //point inside box
+ vec3 axis_len = FRAME.colliders[i].extents - abs_pos;
+ // there has to be a faster way to do this?
+ if (all(lessThan(axis_len.xx, axis_len.yz))) {
+ normal = vec3(1, 0, 0);
+ } else if (all(lessThan(axis_len.yy, axis_len.xz))) {
+ normal = vec3(0, 1, 0);
+ } else {
+ normal = vec3(0, 0, 1);
+ }
+
+ col = true;
+ depth = dot(normal * axis_len, vec3(1)) + particle_size;
+ normal = mat3(FRAME.colliders[i].transform) * (normal * sgn_pos);
+ }
+
+ } break;
+ case COLLIDER_TYPE_SDF: {
+ vec3 apos = abs(local_pos);
+ float extra_dist = 0.0;
+ if (any(greaterThan(apos, FRAME.colliders[i].extents))) { //outside
+ vec3 mpos = min(apos, FRAME.colliders[i].extents);
+ extra_dist = distance(mpos, apos);
+ }
+
+ if (extra_dist > particle_size) {
+ continue;
+ }
+
+ vec3 uvw_pos = (local_pos / FRAME.colliders[i].extents) * 0.5 + 0.5;
+ float s = texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos).r;
+ s *= FRAME.colliders[i].scale;
+ s += extra_dist;
+ if (s < particle_size) {
+ col = true;
+ depth = particle_size - s;
+ const float EPSILON = 0.001;
+ normal = mat3(FRAME.colliders[i].transform) *
+ normalize(
+ vec3(
+ texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos + vec3(EPSILON, 0.0, 0.0)).r - texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos - vec3(EPSILON, 0.0, 0.0)).r,
+ texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos + vec3(0.0, EPSILON, 0.0)).r - texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos - vec3(0.0, EPSILON, 0.0)).r,
+ texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos + vec3(0.0, 0.0, EPSILON)).r - texture(sampler3D(sdf_vec_textures[FRAME.colliders[i].texture_index], material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos - vec3(0.0, 0.0, EPSILON)).r));
+ }
+
+ } break;
+ case COLLIDER_TYPE_HEIGHT_FIELD: {
+ vec3 local_pos_bottom = local_pos;
+ local_pos_bottom.y -= particle_size;
+
+ if (any(greaterThan(abs(local_pos_bottom), FRAME.colliders[i].extents))) {
+ continue;
+ }
+
+ const float DELTA = 1.0 / 8192.0;
+
+ vec3 uvw_pos = vec3(local_pos_bottom / FRAME.colliders[i].extents) * 0.5 + 0.5;
+
+ float y = 1.0 - texture(sampler2D(height_field_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos.xz).r;
+
+ if (y > uvw_pos.y) {
+ //inside heightfield
+
+ vec3 pos1 = (vec3(uvw_pos.x, y, uvw_pos.z) * 2.0 - 1.0) * FRAME.colliders[i].extents;
+ vec3 pos2 = (vec3(uvw_pos.x + DELTA, 1.0 - texture(sampler2D(height_field_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos.xz + vec2(DELTA, 0)).r, uvw_pos.z) * 2.0 - 1.0) * FRAME.colliders[i].extents;
+ vec3 pos3 = (vec3(uvw_pos.x, 1.0 - texture(sampler2D(height_field_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uvw_pos.xz + vec2(0, DELTA)).r, uvw_pos.z + DELTA) * 2.0 - 1.0) * FRAME.colliders[i].extents;
+
+ normal = normalize(cross(pos1 - pos2, pos1 - pos3));
+ float local_y = (vec3(local_pos / FRAME.colliders[i].extents) * 0.5 + 0.5).y;
+
+ col = true;
+ depth = dot(normal, pos1) - dot(normal, local_pos_bottom);
+ }
+
+ } break;
+ }
+
+ if (col) {
+ if (!collided) {
+ collided = true;
+ collision_normal = normal;
+ collision_depth = depth;
+ } else {
+ vec3 c = collision_normal * collision_depth;
+ c += normal * max(0.0, depth - dot(normal, c));
+ collision_normal = normalize(c);
+ collision_depth = length(c);
+ }
+ }
+ }
+ }
+
if (params.sub_emitter_mode) {
if (!PARTICLE.is_active) {
int src_index = atomicAdd(src_particles.particle_count, -1) - 1;
@@ -329,66 +546,4 @@ COMPUTE_SHADER_CODE
/* clang-format on */
}
-
-#if !defined(DISABLE_VELOCITY)
-
- if (PARTICLE.is_active) {
- PARTICLE.xform[3].xyz += PARTICLE.velocity * local_delta;
- }
-#endif
-
-#if 0
- if (PARTICLE.is_active) {
- //execute shader
-
-
-
-
- //!defined(DISABLE_FORCE)
-
- if (false) {
- vec3 force = vec3(0.0);
- for (int i = 0; i < attractor_count; i++) {
- vec3 rel_vec = xform[3].xyz - attractors[i].pos;
- float dist = length(rel_vec);
- if (attractors[i].radius < dist)
- continue;
- if (attractors[i].eat_radius > 0.0 && attractors[i].eat_radius > dist) {
- out_velocity_active.a = 0.0;
- }
-
- rel_vec = normalize(rel_vec);
-
- float attenuation = pow(dist / attractors[i].radius, attractors[i].attenuation);
-
- if (attractors[i].dir == vec3(0.0)) {
- //towards center
- force += attractors[i].strength * rel_vec * attenuation * mass;
- } else {
- force += attractors[i].strength * attractors[i].dir * attenuation * mass;
- }
- }
-
- out_velocity_active.xyz += force * local_delta;
- }
-
-#if !defined(DISABLE_VELOCITY)
-
- if (true) {
- xform[3].xyz += out_velocity_active.xyz * local_delta;
- }
-#endif
- } else {
- xform = mat4(0.0);
- }
-
-
- xform = transpose(xform);
-
- out_velocity_active.a = mix(0.0, 1.0, shader_active);
-
- out_xform_1 = xform[0];
- out_xform_2 = xform[1];
- out_xform_3 = xform[2];
-#endif
}
diff --git a/servers/rendering/rendering_server_raster.cpp b/servers/rendering/rendering_server_raster.cpp
index b12e2ff3c1..cbc91497ba 100644
--- a/servers/rendering/rendering_server_raster.cpp
+++ b/servers/rendering/rendering_server_raster.cpp
@@ -108,6 +108,9 @@ void RenderingServerRaster::draw(bool p_swap_buffers, double frame_step) {
RSG::scene->update_dirty_instances(); //update scene stuff
+ RSG::scene->render_particle_colliders();
+ RSG::storage->update_particles(); //need to be done after instances are updated (colliders and particle transforms), and colliders are rendered
+
RSG::scene->render_probes();
RSG::viewport->draw_viewports();
RSG::canvas_render->update();
diff --git a/servers/rendering/rendering_server_raster.h b/servers/rendering/rendering_server_raster.h
index b554425bef..afb3d6f46f 100644
--- a/servers/rendering/rendering_server_raster.h
+++ b/servers/rendering/rendering_server_raster.h
@@ -452,6 +452,7 @@ public:
BIND1(particles_restart, RID)
BIND6(particles_emit, RID, const Transform &, const Vector3 &, const Color &, const Color &, uint32_t)
BIND2(particles_set_subemitter, RID, RID)
+ BIND2(particles_set_collision_base_size, RID, float)
BIND2(particles_set_draw_order, RID, RS::ParticlesDrawOrder)
@@ -461,6 +462,21 @@ public:
BIND1R(AABB, particles_get_current_aabb, RID)
BIND2(particles_set_emission_transform, RID, const Transform &)
+ /* PARTICLES COLLISION */
+
+ BIND0R(RID, particles_collision_create)
+
+ BIND2(particles_collision_set_collision_type, RID, ParticlesCollisionType)
+ BIND2(particles_collision_set_cull_mask, RID, uint32_t)
+ BIND2(particles_collision_set_sphere_radius, RID, float)
+ BIND2(particles_collision_set_box_extents, RID, const Vector3 &)
+ BIND2(particles_collision_set_attractor_strength, RID, float)
+ BIND2(particles_collision_set_attractor_directionality, RID, float)
+ BIND2(particles_collision_set_attractor_attenuation, RID, float)
+ BIND2(particles_collision_set_field_texture, RID, RID)
+ BIND1(particles_collision_height_field_update, RID)
+ BIND2(particles_collision_set_height_field_resolution, RID, ParticlesCollisionHeightfieldResolution)
+
#undef BINDBASE
//from now on, calls forwarded to this singleton
#define BINDBASE RSG::scene
diff --git a/servers/rendering/rendering_server_scene.cpp b/servers/rendering/rendering_server_scene.cpp
index d8e52a5aae..ae6786090a 100644
--- a/servers/rendering/rendering_server_scene.cpp
+++ b/servers/rendering/rendering_server_scene.cpp
@@ -193,6 +193,8 @@ void *RenderingServerScene::_instance_pair(void *p_self, OctreeElementID, Instan
} else if (B->base_type == RS::INSTANCE_GI_PROBE && A->base_type == RS::INSTANCE_LIGHT) {
InstanceGIProbeData *gi_probe = static_cast<InstanceGIProbeData *>(B->base_data);
return gi_probe->lights.insert(A);
+ } else if (B->base_type == RS::INSTANCE_PARTICLES_COLLISION && A->base_type == RS::INSTANCE_PARTICLES) {
+ RSG::storage->particles_add_collision(A->base, B);
}
return nullptr;
@@ -274,6 +276,8 @@ void RenderingServerScene::_instance_unpair(void *p_self, OctreeElementID, Insta
Set<Instance *>::Element *E = reinterpret_cast<Set<Instance *>::Element *>(udata);
gi_probe->lights.erase(E);
+ } else if (B->base_type == RS::INSTANCE_PARTICLES_COLLISION && A->base_type == RS::INSTANCE_PARTICLES) {
+ RSG::storage->particles_remove_collision(A->base, B);
}
}
@@ -539,6 +543,9 @@ void RenderingServerScene::instance_set_scenario(RID p_instance, RID p_scenario)
RSG::scene_render->reflection_probe_release_atlas_index(reflection_probe->instance);
} break;
+ case RS::INSTANCE_PARTICLES_COLLISION: {
+ heightfield_particle_colliders_update_list.erase(instance);
+ } break;
case RS::INSTANCE_GI_PROBE: {
InstanceGIProbeData *gi_probe = static_cast<InstanceGIProbeData *>(instance->base_data);
@@ -702,6 +709,12 @@ void RenderingServerScene::instance_set_visible(RID p_instance, bool p_visible)
}
} break;
+ case RS::INSTANCE_PARTICLES_COLLISION: {
+ if (instance->octree_id && instance->scenario) {
+ instance->scenario->octree.set_pairable(instance->octree_id, p_visible, 1 << RS::INSTANCE_PARTICLES_COLLISION, p_visible ? (1 << RS::INSTANCE_PARTICLES) : 0);
+ }
+
+ } break;
default: {
}
}
@@ -1026,6 +1039,13 @@ void RenderingServerScene::_update_instance(Instance *p_instance) {
RSG::storage->particles_set_emission_transform(p_instance->base, p_instance->transform);
}
+ if (p_instance->base_type == RS::INSTANCE_PARTICLES_COLLISION) {
+ //remove materials no longer used and un-own them
+ if (RSG::storage->particles_collision_is_heightfield(p_instance->base)) {
+ heightfield_particle_colliders_update_list.insert(p_instance);
+ }
+ }
+
if (p_instance->aabb.has_no_surface()) {
return;
}
@@ -1085,6 +1105,11 @@ void RenderingServerScene::_update_instance(Instance *p_instance) {
pairable = true;
}
+ if (p_instance->base_type == RS::INSTANCE_PARTICLES_COLLISION) {
+ pairable_mask = p_instance->visible ? (1 << RS::INSTANCE_PARTICLES) : 0;
+ pairable = true;
+ }
+
if (p_instance->base_type == RS::INSTANCE_GI_PROBE) {
//lights and geometries
pairable_mask = p_instance->visible ? RS::INSTANCE_GEOMETRY_MASK | (1 << RS::INSTANCE_LIGHT) : 0;
@@ -1146,6 +1171,10 @@ void RenderingServerScene::_update_instance_aabb(Instance *p_instance) {
}
} break;
+ case RenderingServer::INSTANCE_PARTICLES_COLLISION: {
+ new_aabb = RSG::storage->particles_collision_get_aabb(p_instance->base);
+
+ } break;
case RenderingServer::INSTANCE_LIGHT: {
new_aabb = RSG::storage->light_get_aabb(p_instance->base);
@@ -2679,6 +2708,27 @@ void RenderingServerScene::render_probes() {
}
}
+void RenderingServerScene::render_particle_colliders() {
+ while (heightfield_particle_colliders_update_list.front()) {
+ Instance *hfpc = heightfield_particle_colliders_update_list.front()->get();
+
+ if (hfpc->scenario && hfpc->base_type == RS::INSTANCE_PARTICLES_COLLISION && RSG::storage->particles_collision_is_heightfield(hfpc->base)) {
+ //update heightfield
+ int cull_count = hfpc->scenario->octree.cull_aabb(hfpc->transformed_aabb, instance_cull_result, MAX_INSTANCE_CULL); //@TODO: cull mask missing
+ for (int i = 0; i < cull_count; i++) {
+ Instance *instance = instance_cull_result[i];
+ if (!instance->visible || !((1 << instance->base_type) & (RS::INSTANCE_GEOMETRY_MASK & (~(1 << RS::INSTANCE_PARTICLES))))) { //all but particles to avoid self collision
+ cull_count--;
+ SWAP(instance_cull_result[i], instance_cull_result[cull_count]);
+ }
+ }
+
+ RSG::scene_render->render_particle_collider_heightfield(hfpc->base, hfpc->transform, (RasterizerScene::InstanceBase **)instance_cull_result, cull_count);
+ }
+ heightfield_particle_colliders_update_list.erase(heightfield_particle_colliders_update_list.front());
+ }
+}
+
void RenderingServerScene::_update_instance_shader_parameters_from_material(Map<StringName, RasterizerScene::InstanceBase::InstanceShaderParameter> &isparams, const Map<StringName, RasterizerScene::InstanceBase::InstanceShaderParameter> &existing_isparams, RID p_material) {
List<RasterizerStorage::InstanceShaderParam> plist;
RSG::storage->material_get_instance_shader_parameters(p_material, &plist);
diff --git a/servers/rendering/rendering_server_scene.h b/servers/rendering/rendering_server_scene.h
index 165c3784c1..1b0a617627 100644
--- a/servers/rendering/rendering_server_scene.h
+++ b/servers/rendering/rendering_server_scene.h
@@ -385,6 +385,8 @@ public:
}
};
+ Set<Instance *> heightfield_particle_colliders_update_list;
+
int instance_cull_count;
Instance *instance_cull_result[MAX_INSTANCE_CULL];
Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps
@@ -461,6 +463,7 @@ public:
void render_camera(RID p_render_buffers, Ref<XRInterface> &p_interface, XRInterface::Eyes p_eye, RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
void update_dirty_instances();
+ void render_particle_colliders();
void render_probes();
TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size);
diff --git a/servers/rendering/rendering_server_wrap_mt.cpp b/servers/rendering/rendering_server_wrap_mt.cpp
index 9aa6593cbe..ab9856e06e 100644
--- a/servers/rendering/rendering_server_wrap_mt.cpp
+++ b/servers/rendering/rendering_server_wrap_mt.cpp
@@ -124,6 +124,7 @@ void RenderingServerWrapMT::finish() {
gi_probe_free_cached_ids();
lightmap_free_cached_ids();
particles_free_cached_ids();
+ particles_collision_free_cached_ids();
camera_free_cached_ids();
viewport_free_cached_ids();
environment_free_cached_ids();
diff --git a/servers/rendering/rendering_server_wrap_mt.h b/servers/rendering/rendering_server_wrap_mt.h
index 372a7269dc..910acd74cb 100644
--- a/servers/rendering/rendering_server_wrap_mt.h
+++ b/servers/rendering/rendering_server_wrap_mt.h
@@ -356,6 +356,8 @@ public:
FUNC2(particles_set_process_material, RID, RID)
FUNC2(particles_set_fixed_fps, RID, int)
FUNC2(particles_set_fractional_delta, RID, bool)
+ FUNC2(particles_set_collision_base_size, RID, float)
+
FUNC1R(bool, particles_is_inactive, RID)
FUNC1(particles_request_process, RID)
FUNC1(particles_restart, RID)
@@ -371,6 +373,21 @@ public:
FUNC1R(AABB, particles_get_current_aabb, RID)
+ /* PARTICLES COLLISION */
+
+ FUNCRID(particles_collision)
+
+ FUNC2(particles_collision_set_collision_type, RID, ParticlesCollisionType)
+ FUNC2(particles_collision_set_cull_mask, RID, uint32_t)
+ FUNC2(particles_collision_set_sphere_radius, RID, float)
+ FUNC2(particles_collision_set_box_extents, RID, const Vector3 &)
+ FUNC2(particles_collision_set_attractor_strength, RID, float)
+ FUNC2(particles_collision_set_attractor_directionality, RID, float)
+ FUNC2(particles_collision_set_attractor_attenuation, RID, float)
+ FUNC2(particles_collision_set_field_texture, RID, RID)
+ FUNC1(particles_collision_height_field_update, RID)
+ FUNC2(particles_collision_set_height_field_resolution, RID, ParticlesCollisionHeightfieldResolution)
+
/* CAMERA API */
FUNCRID(camera)
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index 6c835fcadf..1883b6b338 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -5912,6 +5912,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
int instance_index = 0;
ShaderNode::Uniform::Scope uniform_scope = ShaderNode::Uniform::SCOPE_LOCAL;
+ stages = &p_functions;
+
while (tk.type != TK_EOF) {
switch (tk.type) {
case TK_RENDER_MODE: {
@@ -7326,6 +7328,12 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
int idx = 0;
bool low_end = RenderingServer::get_singleton()->is_low_end();
+ if (stages && stages->has(skip_function)) {
+ for (const Map<StringName, StageFunctionInfo>::Element *E = (*stages)[skip_function].stage_functions.front(); E; E = E->next()) {
+ matches.insert(String(E->key()), ScriptCodeCompletionOption::KIND_FUNCTION);
+ }
+ }
+
while (builtin_func_defs[idx].name) {
if (low_end && builtin_func_defs[idx].high_end) {
idx++;
@@ -7362,6 +7370,16 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
return OK;
} break;
case COMPLETION_CALL_ARGUMENTS: {
+ StringName block_function;
+ BlockNode *block = completion_block;
+
+ while (block) {
+ if (block->parent_function) {
+ block_function = block->parent_function->name;
+ }
+ block = block->parent_block;
+ }
+
for (int i = 0; i < shader->functions.size(); i++) {
if (!shader->functions[i].callable) {
continue;
@@ -7421,6 +7439,45 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
String calltip;
bool low_end = RenderingServer::get_singleton()->is_low_end();
+ if (stages && stages->has(block_function)) {
+ for (const Map<StringName, StageFunctionInfo>::Element *E = (*stages)[block_function].stage_functions.front(); E; E = E->next()) {
+ if (completion_function == E->key()) {
+ calltip += get_datatype_name(E->get().return_type);
+ calltip += " ";
+ calltip += E->key();
+ calltip += "(";
+
+ for (int i = 0; i < E->get().arguments.size(); i++) {
+ if (i > 0) {
+ calltip += ", ";
+ } else {
+ calltip += " ";
+ }
+
+ if (i == completion_argument) {
+ calltip += char32_t(0xFFFF);
+ }
+
+ calltip += get_datatype_name(E->get().arguments[i].type);
+ calltip += " ";
+ calltip += E->get().arguments[i].name;
+
+ if (i == completion_argument) {
+ calltip += char32_t(0xFFFF);
+ }
+ }
+
+ if (E->get().arguments.size()) {
+ calltip += " ";
+ }
+ calltip += ")";
+
+ r_call_hint = calltip;
+ return OK;
+ }
+ }
+ }
+
while (builtin_func_defs[idx].name) {
if (low_end && builtin_func_defs[idx].high_end) {
idx++;
@@ -7453,7 +7510,7 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
calltip += "(";
bool found_arg = false;
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < BuiltinFuncDef::MAX_ARGS - 1; i++) {
if (builtin_func_defs[idx].args[i] == TYPE_VOID) {
break;
}
diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h
index 0d044a21c7..3c0a10809b 100644
--- a/servers/rendering/shader_language.h
+++ b/servers/rendering/shader_language.h
@@ -846,6 +846,7 @@ private:
StringName completion_function;
StringName completion_struct;
int completion_argument;
+ const Map<StringName, FunctionInfo> *stages = nullptr;
bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier);
static const BuiltinFuncDef builtin_func_defs[];
diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp
index ad5cbc9e51..f1209d9d6d 100644
--- a/servers/rendering/shader_types.cpp
+++ b/servers/rendering/shader_types.cpp
@@ -149,6 +149,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["SHADOW_ATTENUATION"] = constt(ShaderLanguage::TYPE_VEC3);
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["ALBEDO"] = constt(ShaderLanguage::TYPE_VEC3);
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["BACKLIGHT"] = constt(ShaderLanguage::TYPE_VEC3);
+ shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["METALLIC"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["ROUGHNESS"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["DIFFUSE_LIGHT"] = ShaderLanguage::TYPE_VEC3;
shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["SPECULAR_LIGHT"] = ShaderLanguage::TYPE_VEC3;
@@ -294,6 +295,10 @@ ShaderTypes::ShaderTypes() {
shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["RESTART_VELOCITY"] = constt(ShaderLanguage::TYPE_BOOL);
shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["RESTART_COLOR"] = constt(ShaderLanguage::TYPE_BOOL);
shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["RESTART_CUSTOM"] = constt(ShaderLanguage::TYPE_BOOL);
+ shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["COLLIDED"] = constt(ShaderLanguage::TYPE_BOOL);
+ shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["COLLISION_NORMAL"] = constt(ShaderLanguage::TYPE_VEC3);
+ shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["COLLISION_DEPTH"] = constt(ShaderLanguage::TYPE_FLOAT);
+ shader_modes[RS::SHADER_PARTICLES].functions["compute"].built_ins["ATTRACTOR_FORCE"] = constt(ShaderLanguage::TYPE_VEC3);
shader_modes[RS::SHADER_PARTICLES].functions["compute"].can_discard = false;
{
@@ -307,6 +312,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[RS::SHADER_PARTICLES].functions["compute"].stage_functions["emit_particle"] = emit_vertex_func;
}
+ shader_modes[RS::SHADER_PARTICLES].modes.push_back("collision_use_scale");
shader_modes[RS::SHADER_PARTICLES].modes.push_back("disable_force");
shader_modes[RS::SHADER_PARTICLES].modes.push_back("disable_velocity");
shader_modes[RS::SHADER_PARTICLES].modes.push_back("keep_data");
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index 9ad19e4b38..9434e377f8 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -2152,6 +2152,7 @@ void RenderingServer::_bind_methods() {
BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH);
BIND_ENUM_CONSTANT(INSTANCE_IMMEDIATE);
BIND_ENUM_CONSTANT(INSTANCE_PARTICLES);
+ BIND_ENUM_CONSTANT(INSTANCE_PARTICLES_COLLISION);
BIND_ENUM_CONSTANT(INSTANCE_LIGHT);
BIND_ENUM_CONSTANT(INSTANCE_REFLECTION_PROBE);
BIND_ENUM_CONSTANT(INSTANCE_DECAL);
@@ -2327,11 +2328,11 @@ RenderingServer::RenderingServer() {
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/directional_shadow/size", PropertyInfo(Variant::INT, "rendering/quality/directional_shadow/size", PROPERTY_HINT_RANGE, "256,16384"));
GLOBAL_DEF("rendering/quality/directional_shadow/soft_shadow_quality", 2);
GLOBAL_DEF("rendering/quality/directional_shadow/soft_shadow_quality.mobile", 0);
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/directional_shadow/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/quality/directional_shadow/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard(Fastest), Soft Low (Fast), Soft Medium (Average), Soft High (Slow), Soft Ultra (Slowest)"));
+ ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/directional_shadow/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/quality/directional_shadow/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)"));
GLOBAL_DEF("rendering/quality/shadows/soft_shadow_quality", 2);
GLOBAL_DEF("rendering/quality/shadows/soft_shadow_quality.mobile", 0);
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadows/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/quality/shadows/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard(Fastest), Soft Low (Fast), Soft Medium (Average), Soft High (Slow), Soft Ultra (Slowest)"));
+ ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadows/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/quality/shadows/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)"));
GLOBAL_DEF("rendering/quality/shadow_atlas/size", 4096);
GLOBAL_DEF("rendering/quality/shadow_atlas/size.mobile", 2048);
diff --git a/servers/rendering_server.h b/servers/rendering_server.h
index 7dae45f126..7680dc1390 100644
--- a/servers/rendering_server.h
+++ b/servers/rendering_server.h
@@ -578,6 +578,7 @@ public:
virtual void particles_set_process_material(RID p_particles, RID p_material) = 0;
virtual void particles_set_fixed_fps(RID p_particles, int p_fps) = 0;
virtual void particles_set_fractional_delta(RID p_particles, bool p_enable) = 0;
+ virtual void particles_set_collision_base_size(RID p_particles, float p_size) = 0;
virtual bool particles_is_inactive(RID p_particles) = 0;
virtual void particles_request_process(RID p_particles) = 0;
virtual void particles_restart(RID p_particles) = 0;
@@ -609,6 +610,43 @@ public:
virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform) = 0; //this is only used for 2D, in 3D it's automatic
+ /* PARTICLES COLLISION API */
+
+ virtual RID particles_collision_create() = 0;
+
+ enum ParticlesCollisionType {
+ PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT,
+ PARTICLES_COLLISION_TYPE_BOX_ATTRACT,
+ PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT,
+ PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE,
+ PARTICLES_COLLISION_TYPE_BOX_COLLIDE,
+ PARTICLES_COLLISION_TYPE_SDF_COLLIDE,
+ PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE,
+ };
+
+ virtual void particles_collision_set_collision_type(RID p_particles_collision, ParticlesCollisionType p_type) = 0;
+ virtual void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) = 0;
+ virtual void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius) = 0; //for spheres
+ virtual void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) = 0; //for non-spheres
+ virtual void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength) = 0;
+ virtual void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality) = 0;
+ virtual void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve) = 0;
+ virtual void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) = 0; //for SDF and vector field, heightfield is dynamic
+
+ virtual void particles_collision_height_field_update(RID p_particles_collision) = 0; //for SDF and vector field
+
+ enum ParticlesCollisionHeightfieldResolution { //longest axis resolution
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_256,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_512,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_2048,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_4096,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_8192,
+ PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX,
+ };
+
+ virtual void particles_collision_set_height_field_resolution(RID p_particles_collision, ParticlesCollisionHeightfieldResolution p_resolution) = 0; //for SDF and vector field
+
/* CAMERA API */
virtual RID camera_create() = 0;
@@ -965,6 +1003,7 @@ public:
INSTANCE_MULTIMESH,
INSTANCE_IMMEDIATE,
INSTANCE_PARTICLES,
+ INSTANCE_PARTICLES_COLLISION,
INSTANCE_LIGHT,
INSTANCE_REFLECTION_PROBE,
INSTANCE_DECAL,