summaryrefslogtreecommitdiffstats
path: root/src/classes/wrapped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/wrapped.cpp')
-rw-r--r--src/classes/wrapped.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp
index 1e9239c..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 {
@@ -49,6 +53,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()));
}
@@ -62,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
@@ -87,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