[NativeScript] implement refcount instance binding funcs
This commit is contained in:
parent
a1019c2c82
commit
917bd5b2c2
|
@ -229,6 +229,8 @@ const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
|
GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
|
||||||
GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
|
GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
|
||||||
|
GDCALLINGCONV void (*refcount_incremented_instance_binding)(void *, godot_object *);
|
||||||
|
GDCALLINGCONV bool (*refcount_decremented_instance_binding)(void *, godot_object *);
|
||||||
void *data;
|
void *data;
|
||||||
GDCALLINGCONV void (*free_func)(void *);
|
GDCALLINGCONV void (*free_func)(void *);
|
||||||
} godot_instance_binding_functions;
|
} godot_instance_binding_functions;
|
||||||
|
|
|
@ -1370,6 +1370,54 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
|
||||||
delete &binding_data;
|
delete &binding_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) {
|
||||||
|
|
||||||
|
void *data = p_object->get_script_instance_binding(lang_idx);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Vector<void *> &binding_data = *(Vector<void *> *)data;
|
||||||
|
|
||||||
|
for (int i = 0; i < binding_data.size(); i++) {
|
||||||
|
if (!binding_data[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!binding_functions[i].first)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (binding_functions[i].second.refcount_incremented_instance_binding) {
|
||||||
|
binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) {
|
||||||
|
|
||||||
|
void *data = p_object->get_script_instance_binding(lang_idx);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Vector<void *> &binding_data = *(Vector<void *> *)data;
|
||||||
|
|
||||||
|
bool can_die = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < binding_data.size(); i++) {
|
||||||
|
if (!binding_data[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!binding_functions[i].first)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (binding_functions[i].second.refcount_decremented_instance_binding) {
|
||||||
|
can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return can_die;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) {
|
void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) {
|
||||||
if (!global_type_tags.has(p_idx)) {
|
if (!global_type_tags.has(p_idx)) {
|
||||||
global_type_tags.insert(p_idx, HashMap<StringName, const void *>());
|
global_type_tags.insert(p_idx, HashMap<StringName, const void *>());
|
||||||
|
|
|
@ -353,6 +353,8 @@ public:
|
||||||
|
|
||||||
virtual void *alloc_instance_binding_data(Object *p_object);
|
virtual void *alloc_instance_binding_data(Object *p_object);
|
||||||
virtual void free_instance_binding_data(void *p_data);
|
virtual void free_instance_binding_data(void *p_data);
|
||||||
|
virtual void refcount_incremented_instance_binding(Object *p_object);
|
||||||
|
virtual bool refcount_decremented_instance_binding(Object *p_object);
|
||||||
|
|
||||||
void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag);
|
void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag);
|
||||||
const void *get_global_type_tag(int p_idx, StringName p_class_name) const;
|
const void *get_global_type_tag(int p_idx, StringName p_class_name) const;
|
||||||
|
|
Loading…
Reference in New Issue