summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp/classes
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2023-10-16 10:47:06 -0500
committerGitHub <noreply@github.com>2023-10-16 10:47:06 -0500
commit64eac01d04cd6ced10ad72dece92fdc971161d89 (patch)
treecca8ce7e3e4192b61427c21c81dccdcd08e064f9 /include/godot_cpp/classes
parent4320c62c76879ae9ab3e5ff198d82896d9985af3 (diff)
parentb507b3e5913344a97e90ba27b221e28924f555ab (diff)
downloadredot-cpp-64eac01d04cd6ced10ad72dece92fdc971161d89.tar.gz
Merge pull request #1266 from dsnopek/automatic-engine-class-registration
Automatically register only engine classes whose header has been included
Diffstat (limited to 'include/godot_cpp/classes')
-rw-r--r--include/godot_cpp/classes/editor_plugin_registration.hpp62
-rw-r--r--include/godot_cpp/classes/wrapped.hpp17
2 files changed, 79 insertions, 0 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 879346b..2bbffc0 100644
--- a/include/godot_cpp/classes/wrapped.hpp
+++ b/include/godot_cpp/classes/wrapped.hpp
@@ -111,6 +111,22 @@ 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
@@ -352,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: \