diff options
31 files changed, 595 insertions, 21 deletions
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/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/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/variant_call.cpp b/core/variant_call.cpp index 5fd970c8e1..6ee63e1610 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -586,6 +586,7 @@ struct _VariantCall { VCALL_LOCALMEM0(Callable, get_object_id); VCALL_LOCALMEM0(Callable, get_method); VCALL_LOCALMEM0(Callable, hash); + VCALL_LOCALMEM1R(Callable, unbind); VCALL_LOCALMEM0R(Signal, is_null); VCALL_LOCALMEM0R(Signal, get_object); @@ -1347,11 +1348,14 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p 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) { + } else if (p_method == CoreStringNames::get_singleton()->call_deferred) { reinterpret_cast<const Callable *>(_data._mem)->call_deferred(p_args, p_argcount); valid = true; + } else if (p_method == CoreStringNames::get_singleton()->bind) { + ret = reinterpret_cast<const Callable *>(_data._mem)->bind(p_args, p_argcount); + valid = true; } + } else if (type == SIGNAL) { if (p_method == CoreStringNames::get_singleton()->emit) { if (r_ret) { @@ -1696,9 +1700,13 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const { if (type == CALLABLE) { MethodInfo mi; + + mi.name = "bind"; + mi.flags |= METHOD_FLAG_VARARG; + p_list->push_back(mi); + mi.name = "call"; mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; - mi.flags |= METHOD_FLAG_VARARG; p_list->push_back(mi); @@ -2130,6 +2138,7 @@ void register_variant_methods() { ADDFUNC0R(CALLABLE, INT, Callable, get_object_id, varray()); ADDFUNC0R(CALLABLE, STRING_NAME, Callable, get_method, varray()); ADDFUNC0R(CALLABLE, INT, Callable, hash, varray()); + ADDFUNC1R(CALLABLE, CALLABLE, Callable, unbind, INT, "argcount", varray()); ADDFUNC0R(SIGNAL, BOOL, Signal, is_null, varray()); ADDFUNC0R(SIGNAL, OBJECT, Signal, get_object, varray()); 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/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/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/RenderingServer.xml b/doc/classes/RenderingServer.xml index 9ca699501f..456022a626 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3579,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/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/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 8bd6e39252..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); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 1651de4048..2d0f4a19e7 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -3127,6 +3127,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/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/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp index af737b058c..baaaa23185 100644 --- a/scene/3d/gpu_particles_collision_3d.cpp +++ b/scene/3d/gpu_particles_collision_3d.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "gpu_particles_collision_3d.h" + #include "core/thread_work_pool.h" #include "mesh_instance_3d.h" #include "scene/3d/camera_3d.h" @@ -663,6 +664,9 @@ void GPUParticlesCollisionHeightField::_bind_methods() { 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) { 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/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_storage_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp index 6448872610..1a1490816c 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp @@ -7884,7 +7884,9 @@ 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); RD::get_singleton()->free(default_rd_storage_buffer); diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 9ad19e4b38..f4b3634d99 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); |