summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/godot_cpp')
-rw-r--r--include/godot_cpp/classes/editor_plugin_registration.hpp62
-rw-r--r--include/godot_cpp/classes/wrapped.hpp41
-rw-r--r--include/godot_cpp/core/class_db.hpp12
-rw-r--r--include/godot_cpp/godot.hpp4
-rw-r--r--include/godot_cpp/variant/callable_method_pointer.hpp1
-rw-r--r--include/godot_cpp/variant/char_string.hpp12
6 files changed, 122 insertions, 10 deletions
diff --git a/include/godot_cpp/classes/editor_plugin_registration.hpp b/include/godot_cpp/classes/editor_plugin_registration.hpp
new file mode 100644
index 0000000..1ccde31
--- /dev/null
+++ b/include/godot_cpp/classes/editor_plugin_registration.hpp
@@ -0,0 +1,62 @@
+/**************************************************************************/
+/* editor_plugin_registration.hpp */
+/**************************************************************************/
+/* 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. */
+/**************************************************************************/
+
+#ifndef GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
+#define GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
+
+#include <godot_cpp/templates/vector.hpp>
+
+namespace godot {
+
+class EditorPlugin;
+class StringName;
+
+class EditorPlugins {
+private:
+ static Vector<StringName> plugin_classes;
+
+public:
+ static void add_plugin_class(const StringName &p_class_name);
+ static void remove_plugin_class(const StringName &p_class_name);
+ static void deinitialize(GDExtensionInitializationLevel p_level);
+
+ template <class T>
+ static void add_by_type() {
+ add_plugin_class(T::get_class_static());
+ }
+ template <class T>
+ static void remove_by_type() {
+ remove_plugin_class(T::get_class_static());
+ }
+};
+
+} // namespace godot
+
+#endif // GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp
index 91e29eb..2bbffc0 100644
--- a/include/godot_cpp/classes/wrapped.hpp
+++ b/include/godot_cpp/classes/wrapped.hpp
@@ -51,6 +51,15 @@ class Wrapped {
friend void postinitialize_handler(Wrapped *);
protected:
+#ifdef HOT_RELOAD_ENABLED
+ struct RecreateInstance {
+ GDExtensionClassInstancePtr wrapper;
+ GDExtensionObjectPtr owner;
+ RecreateInstance *next;
+ };
+ inline static RecreateInstance *recreate_instance = nullptr;
+#endif
+
virtual const StringName *_get_extension_class_name() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks() const = 0;
@@ -102,10 +111,37 @@ namespace internal {
GDExtensionPropertyInfo *create_c_property_list(const ::godot::List<::godot::PropertyInfo> &plist_cpp, uint32_t *r_size);
void free_c_property_list(GDExtensionPropertyInfo *plist);
+typedef void (*EngineClassRegistrationCallback)();
+void add_engine_class_registration_callback(EngineClassRegistrationCallback p_callback);
+void register_engine_class(const StringName &p_name, const GDExtensionInstanceBindingCallbacks *p_callbacks);
+void register_engine_classes();
+
+template <class T>
+struct EngineClassRegistration {
+ EngineClassRegistration() {
+ add_engine_class_registration_callback(&EngineClassRegistration<T>::callback);
+ }
+
+ static void callback() {
+ register_engine_class(T::get_class_static(), &T::_gde_binding_callbacks);
+ }
+};
+
} // namespace internal
} // namespace godot
+#ifdef HOT_RELOAD_ENABLED
+#define _GDCLASS_RECREATE(m_class, m_inherits) \
+ m_class *new_instance = (m_class *)memalloc(sizeof(m_class)); \
+ Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; \
+ Wrapped::recreate_instance = &recreate_data; \
+ memnew_placement(new_instance, m_class); \
+ return new_instance;
+#else
+#define _GDCLASS_RECREATE(m_class, m_inherits) return nullptr;
+#endif
+
// Use this on top of your own classes.
// Note: the trail of `***` is to keep sane diffs in PRs, because clang-format otherwise moves every `\` which makes
// every line of the macro different
@@ -193,6 +229,10 @@ public:
return new_object->_owner; \
} \
\
+ static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \
+ _GDCLASS_RECREATE(m_class, m_inherits); \
+ } \
+ \
static void notification_bind(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) { \
if (p_instance && m_class::_get_notification()) { \
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
@@ -328,6 +368,7 @@ public:
// Don't use this for your classes, use GDCLASS() instead.
#define GDEXTENSION_CLASS_ALIAS(m_class, m_alias_for, m_inherits) \
private: \
+ inline static ::godot::internal::EngineClassRegistration<m_class> _gde_engine_class_registration_helper; \
void operator=(const m_class &p_rval) {} \
\
protected: \
diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp
index c974fa4..17e093a 100644
--- a/include/godot_cpp/core/class_db.hpp
+++ b/include/godot_cpp/core/class_db.hpp
@@ -119,8 +119,10 @@ public:
static void register_abstract_class();
template <class T>
static void register_internal_class();
- template <class T>
- static void register_engine_class();
+
+ _FORCE_INLINE_ static void _register_engine_class(const StringName &p_name, const GDExtensionInstanceBindingCallbacks *p_callbacks) {
+ instance_binding_callbacks[p_name] = p_callbacks;
+ }
template <class N, class M, typename... VarArgs>
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args);
@@ -201,6 +203,7 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed) {
nullptr, // GDExtensionClassUnreference unreference_func;
T::create, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */
T::free, // GDExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
+ T::recreate, // GDExtensionClassRecreateInstance recreate_instance_func;
&ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func;
nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func;
@@ -232,11 +235,6 @@ void ClassDB::register_internal_class() {
ClassDB::_register_class<T, false>(false, false);
}
-template <class T>
-void ClassDB::register_engine_class() {
- instance_binding_callbacks[T::get_class_static()] = &T::_gde_binding_callbacks;
-}
-
template <class N, class M, typename... VarArgs>
MethodBind *ClassDB::bind_method(N p_method_name, M p_method, VarArgs... p_args) {
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
diff --git a/include/godot_cpp/godot.hpp b/include/godot_cpp/godot.hpp
index 4561a75..46911dc 100644
--- a/include/godot_cpp/godot.hpp
+++ b/include/godot_cpp/godot.hpp
@@ -124,6 +124,7 @@ extern "C" GDExtensionInterfaceStringOperatorPlusEqCstr gdextension_interface_st
extern "C" GDExtensionInterfaceStringOperatorPlusEqWcstr gdextension_interface_string_operator_plus_eq_wcstr;
extern "C" GDExtensionInterfaceStringOperatorPlusEqC32str gdextension_interface_string_operator_plus_eq_c32str;
extern "C" GDExtensionInterfaceStringResize gdextension_interface_string_resize;
+extern "C" GDExtensionInterfaceStringNameNewWithLatin1Chars gdextension_interface_string_name_new_with_latin1_chars;
extern "C" GDExtensionInterfaceXmlParserOpenBuffer gdextension_interface_xml_parser_open_buffer;
extern "C" GDExtensionInterfaceFileAccessStoreBuffer gdextension_interface_file_access_store_buffer;
extern "C" GDExtensionInterfaceFileAccessGetBuffer gdextension_interface_file_access_get_buffer;
@@ -196,9 +197,6 @@ enum ModuleInitializationLevel {
};
class GDExtensionBinding {
-private:
- static void register_engine_classes();
-
public:
using Callback = void (*)(ModuleInitializationLevel p_level);
diff --git a/include/godot_cpp/variant/callable_method_pointer.hpp b/include/godot_cpp/variant/callable_method_pointer.hpp
index bd31ea1..d83bcba 100644
--- a/include/godot_cpp/variant/callable_method_pointer.hpp
+++ b/include/godot_cpp/variant/callable_method_pointer.hpp
@@ -40,6 +40,7 @@ class CallableCustomMethodPointerBase {
public:
virtual Object *get_object() const = 0;
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, GDExtensionCallError &r_call_error) const = 0;
+ virtual ~CallableCustomMethodPointerBase() {}
};
namespace internal {
diff --git a/include/godot_cpp/variant/char_string.hpp b/include/godot_cpp/variant/char_string.hpp
index f8f5169..fef6a71 100644
--- a/include/godot_cpp/variant/char_string.hpp
+++ b/include/godot_cpp/variant/char_string.hpp
@@ -120,6 +120,18 @@ protected:
void copy_from(const T *p_cstr);
};
+template <>
+const char *CharStringT<char>::get_data() const;
+
+template <>
+const char16_t *CharStringT<char16_t>::get_data() const;
+
+template <>
+const char32_t *CharStringT<char32_t>::get_data() const;
+
+template <>
+const wchar_t *CharStringT<wchar_t>::get_data() const;
+
typedef CharStringT<char> CharString;
typedef CharStringT<char16_t> Char16String;
typedef CharStringT<char32_t> Char32String;