diff options
author | David Snopek <dsnopek@gmail.com> | 2023-10-16 10:47:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 10:47:06 -0500 |
commit | 64eac01d04cd6ced10ad72dece92fdc971161d89 (patch) | |
tree | cca8ce7e3e4192b61427c21c81dccdcd08e064f9 /src/classes/wrapped.cpp | |
parent | 4320c62c76879ae9ab3e5ff198d82896d9985af3 (diff) | |
parent | b507b3e5913344a97e90ba27b221e28924f555ab (diff) | |
download | redot-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 'src/classes/wrapped.cpp')
-rw-r--r-- | src/classes/wrapped.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index 5b425c7..37fcf65 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -28,12 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +#include <vector> + #include <godot_cpp/classes/wrapped.hpp> #include <godot_cpp/variant/builtin_types.hpp> #include <godot_cpp/classes/object.hpp> +#include <godot_cpp/core/class_db.hpp> + namespace godot { const StringName *Wrapped::_get_extension_class_name() const { @@ -81,6 +85,11 @@ void postinitialize_handler(Wrapped *p_wrapped) { namespace internal { +std::vector<EngineClassRegistrationCallback> &get_engine_class_registration_callbacks() { + static std::vector<EngineClassRegistrationCallback> engine_class_registration_callbacks; + return engine_class_registration_callbacks; +} + GDExtensionPropertyInfo *create_c_property_list(const ::godot::List<::godot::PropertyInfo> &plist_cpp, uint32_t *r_size) { GDExtensionPropertyInfo *plist = nullptr; // Linked list size can be expensive to get so we cache it @@ -106,6 +115,22 @@ void free_c_property_list(GDExtensionPropertyInfo *plist) { memfree(plist); } +void add_engine_class_registration_callback(EngineClassRegistrationCallback p_callback) { + get_engine_class_registration_callbacks().push_back(p_callback); +} + +void register_engine_class(const StringName &p_name, const GDExtensionInstanceBindingCallbacks *p_callbacks) { + ClassDB::_register_engine_class(p_name, p_callbacks); +} + +void register_engine_classes() { + std::vector<EngineClassRegistrationCallback> &engine_class_registration_callbacks = get_engine_class_registration_callbacks(); + for (EngineClassRegistrationCallback cb : engine_class_registration_callbacks) { + cb(); + } + engine_class_registration_callbacks.clear(); +} + } // namespace internal } // namespace godot |