summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/classes/wrapped.cpp19
-rw-r--r--src/core/class_db.cpp20
-rw-r--r--src/core/memory.cpp4
-rw-r--r--src/godot.cpp4
-rw-r--r--src/variant/callable_method_pointer.cpp66
-rw-r--r--src/variant/variant.cpp4
6 files changed, 109 insertions, 8 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp
index 1e9239c..5b425c7 100644
--- a/src/classes/wrapped.cpp
+++ b/src/classes/wrapped.cpp
@@ -49,6 +49,25 @@ void Wrapped::_postinitialize() {
}
Wrapped::Wrapped(const StringName p_godot_class) {
+#ifdef HOT_RELOAD_ENABLED
+ if (unlikely(Wrapped::recreate_instance)) {
+ RecreateInstance *recreate_data = Wrapped::recreate_instance;
+ RecreateInstance *previous = nullptr;
+ while (recreate_data) {
+ if (recreate_data->wrapper == this) {
+ _owner = recreate_data->owner;
+ if (previous) {
+ previous->next = recreate_data->next;
+ } else {
+ Wrapped::recreate_instance = recreate_data->next;
+ }
+ return;
+ }
+ previous = recreate_data;
+ recreate_data = recreate_data->next;
+ }
+ }
+#endif
_owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
}
diff --git a/src/core/class_db.cpp b/src/core/class_db.cpp
index 159c031..7219a79 100644
--- a/src/core/class_db.cpp
+++ b/src/core/class_db.cpp
@@ -77,7 +77,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
if (p_setter != String("")) {
setter = get_method(p_class, p_setter);
- ERR_FAIL_COND_MSG(!setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
+ ERR_FAIL_NULL_MSG(setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
size_t exp_args = 1 + (p_index >= 0 ? 1 : 0);
ERR_FAIL_COND_MSG((int)exp_args != setter->get_argument_count(), String("Setter method '{0}::{1}()' must take a single argument.").format(Array::make(p_class, p_setter)));
@@ -86,7 +86,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
ERR_FAIL_COND_MSG(p_getter == String(""), String("Getter method must be specified for '{0}::{1}'.").format(Array::make(p_class, p_pinfo.name)));
MethodBind *getter = get_method(p_class, p_getter);
- ERR_FAIL_COND_MSG(!getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
+ ERR_FAIL_NULL_MSG(getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
{
size_t exp_args = 0 + (p_index >= 0 ? 1 : 0);
ERR_FAIL_COND_MSG((int)exp_args != getter->get_argument_count(), String("Getter method '{0}::{1}()' must not take any argument.").format(Array::make(p_class, p_getter)));
@@ -310,7 +310,18 @@ GDExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, GDExtens
const GDExtensionInstanceBindingCallbacks *ClassDB::get_instance_binding_callbacks(const StringName &p_class) {
std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *>::iterator callbacks_it = instance_binding_callbacks.find(p_class);
- ERR_FAIL_COND_V_MSG(callbacks_it == instance_binding_callbacks.end(), nullptr, String("Cannot find instance binding callbacks for class '{0}'.").format(Array::make(p_class)));
+ if (likely(callbacks_it != instance_binding_callbacks.end())) {
+ return callbacks_it->second;
+ }
+
+ // If we don't have an instance binding callback for the given class, find the closest parent where we do.
+ StringName class_name = p_class;
+ do {
+ class_name = get_parent_class(class_name);
+ ERR_FAIL_COND_V_MSG(class_name == StringName(), nullptr, String("Cannot find instance binding callbacks for class '{0}'.").format(Array::make(p_class)));
+ callbacks_it = instance_binding_callbacks.find(class_name);
+ } while (callbacks_it == instance_binding_callbacks.end());
+
return callbacks_it->second;
}
@@ -354,6 +365,9 @@ void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
for (auto method : cl.method_map) {
memdelete(method.second);
}
+
+ classes.erase(*i);
+ class_register_order.erase((i + 1).base());
}
}
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 17b0696..80e71ec 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -42,7 +42,7 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
#endif
void *mem = internal::gdextension_interface_mem_alloc(p_bytes + (prepad ? PAD_ALIGN : 0));
- ERR_FAIL_COND_V(!mem, nullptr);
+ ERR_FAIL_NULL_V(mem, nullptr);
if (prepad) {
uint8_t *s8 = (uint8_t *)mem;
@@ -71,7 +71,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
if (prepad) {
mem -= PAD_ALIGN;
mem = (uint8_t *)internal::gdextension_interface_mem_realloc(mem, p_bytes + PAD_ALIGN);
- ERR_FAIL_COND_V(!mem, nullptr);
+ ERR_FAIL_NULL_V(mem, nullptr);
return mem + PAD_ALIGN;
} else {
return (uint8_t *)internal::gdextension_interface_mem_realloc(mem, p_bytes);
diff --git a/src/godot.cpp b/src/godot.cpp
index 69d471b..05413ff 100644
--- a/src/godot.cpp
+++ b/src/godot.cpp
@@ -170,6 +170,7 @@ GDExtensionInterfaceObjectGetClassName gdextension_interface_object_get_class_na
GDExtensionInterfaceObjectCastTo gdextension_interface_object_cast_to = nullptr;
GDExtensionInterfaceObjectGetInstanceFromId gdextension_interface_object_get_instance_from_id = nullptr;
GDExtensionInterfaceObjectGetInstanceId gdextension_interface_object_get_instance_id = nullptr;
+GDExtensionInterfaceCallableCustomCreate gdextension_interface_callable_custom_create = nullptr;
GDExtensionInterfaceRefGetObject gdextension_interface_ref_get_object = nullptr;
GDExtensionInterfaceRefSetObject gdextension_interface_ref_set_object = nullptr;
GDExtensionInterfaceScriptInstanceCreate2 gdextension_interface_script_instance_create2 = nullptr;
@@ -386,6 +387,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
LOAD_PROC_ADDRESS(object_cast_to, GDExtensionInterfaceObjectCastTo);
LOAD_PROC_ADDRESS(object_get_instance_from_id, GDExtensionInterfaceObjectGetInstanceFromId);
LOAD_PROC_ADDRESS(object_get_instance_id, GDExtensionInterfaceObjectGetInstanceId);
+ LOAD_PROC_ADDRESS(callable_custom_create, GDExtensionInterfaceCallableCustomCreate);
LOAD_PROC_ADDRESS(ref_get_object, GDExtensionInterfaceRefGetObject);
LOAD_PROC_ADDRESS(ref_set_object, GDExtensionInterfaceRefSetObject);
LOAD_PROC_ADDRESS(script_instance_create2, GDExtensionInterfaceScriptInstanceCreate2);
@@ -411,7 +413,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
r_initialization->deinitialize = deinitialize_level;
r_initialization->minimum_initialization_level = minimum_initialization_level;
- ERR_FAIL_COND_V_MSG(init_callback == nullptr, false, "Initialization callback must be defined.");
+ ERR_FAIL_NULL_V_MSG(init_callback, false, "Initialization callback must be defined.");
Variant::init_bindings();
register_engine_classes();
diff --git a/src/variant/callable_method_pointer.cpp b/src/variant/callable_method_pointer.cpp
new file mode 100644
index 0000000..7934c73
--- /dev/null
+++ b/src/variant/callable_method_pointer.cpp
@@ -0,0 +1,66 @@
+/**************************************************************************/
+/* callable_method_pointer.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* 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 <godot_cpp/variant/callable_method_pointer.hpp>
+
+//#include <godot_cpp/godot.hpp>
+
+namespace godot {
+
+static void call_custom_callable(void *userdata, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error) {
+ CallableCustomMethodPointerBase *callable_method_pointer = (CallableCustomMethodPointerBase *)userdata;
+ callable_method_pointer->call((const Variant **)p_args, p_argument_count, *(Variant *)r_return, *r_error);
+}
+
+static void free_custom_callable(void *userdata) {
+ CallableCustomMethodPointerBase *callable_method_pointer = (CallableCustomMethodPointerBase *)userdata;
+ memdelete(callable_method_pointer);
+}
+
+namespace internal {
+
+Callable create_custom_callable(CallableCustomMethodPointerBase *p_callable_method_pointer) {
+ Object *object = p_callable_method_pointer->get_object();
+
+ GDExtensionCallableCustomInfo info = {};
+ info.callable_userdata = p_callable_method_pointer;
+ info.token = internal::token;
+ info.object = object != nullptr ? object->_owner : nullptr;
+ info.call_func = &call_custom_callable;
+ info.free_func = &free_custom_callable;
+
+ Callable callable;
+ ::godot::internal::gdextension_interface_callable_custom_create(callable._native_ptr(), &info);
+ return callable;
+}
+
+} // namespace internal
+
+} // namespace godot
diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp
index a73db74..641f59c 100644
--- a/src/variant/variant.cpp
+++ b/src/variant/variant.cpp
@@ -549,11 +549,11 @@ bool Variant::operator<(const Variant &other) const {
return result.operator bool();
}
-void Variant::call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
+void Variant::callp(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
internal::gdextension_interface_variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
}
-void Variant::call_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
+void Variant::callp_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
internal::gdextension_interface_variant_call_static(static_cast<GDExtensionVariantType>(type), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
}