diff options
Diffstat (limited to 'include/godot_cpp')
-rw-r--r-- | include/godot_cpp/core/class_db.hpp | 18 | ||||
-rw-r--r-- | include/godot_cpp/godot.hpp | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index ca5a326..8ef7f8e 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -45,6 +45,7 @@ #include <godot_cpp/variant/callable_method_pointer.hpp> #include <list> +#include <mutex> #include <set> #include <string> #include <unordered_map> @@ -104,6 +105,8 @@ private: static std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks; // Used to remember the custom class registration order. static std::vector<StringName> class_register_order; + static std::unordered_map<StringName, Object *> engine_singletons; + static std::mutex engine_singletons_mutex; static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount); static void initialize_class(const ClassInfo &cl); @@ -153,6 +156,21 @@ public: instance_binding_callbacks[p_name] = p_callbacks; } + static void _register_engine_singleton(const StringName &p_class_name, Object *p_singleton) { + std::lock_guard<std::mutex> lock(engine_singletons_mutex); + std::unordered_map<StringName, Object *>::const_iterator i = engine_singletons.find(p_class_name); + if (i != engine_singletons.end()) { + ERR_FAIL_COND((*i).second != p_singleton); + return; + } + engine_singletons[p_class_name] = p_singleton; + } + + static void _unregister_engine_singleton(const StringName &p_class_name) { + std::lock_guard<std::mutex> lock(engine_singletons_mutex); + engine_singletons.erase(p_class_name); + } + template <typename N, typename M, typename... VarArgs> static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args); diff --git a/include/godot_cpp/godot.hpp b/include/godot_cpp/godot.hpp index 95a0387..822363d 100644 --- a/include/godot_cpp/godot.hpp +++ b/include/godot_cpp/godot.hpp @@ -162,6 +162,7 @@ extern "C" GDExtensionInterfaceObjectDestroy gdextension_interface_object_destro extern "C" GDExtensionInterfaceGlobalGetSingleton gdextension_interface_global_get_singleton; extern "C" GDExtensionInterfaceObjectGetInstanceBinding gdextension_interface_object_get_instance_binding; extern "C" GDExtensionInterfaceObjectSetInstanceBinding gdextension_interface_object_set_instance_binding; +extern "C" GDExtensionInterfaceObjectFreeInstanceBinding gdextension_interface_object_free_instance_binding; extern "C" GDExtensionInterfaceObjectSetInstance gdextension_interface_object_set_instance; extern "C" GDExtensionInterfaceObjectGetClassName gdextension_interface_object_get_class_name; extern "C" GDExtensionInterfaceObjectCastTo gdextension_interface_object_cast_to; |