Merge pull request #17980 from karroffel/nativescript-1.1-global-type-tags
[NativeScript] added global type tag system
This commit is contained in:
commit
eaa5dfbdbd
5 changed files with 64 additions and 24 deletions
|
@ -5821,6 +5821,23 @@
|
|||
["godot_string", "p_documentation"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "godot_nativescript_set_global_type_tag",
|
||||
"return_type": "void",
|
||||
"arguments": [
|
||||
["int", "p_idx"],
|
||||
["const char *", "p_name"],
|
||||
["const void *", "p_type_tag"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "godot_nativescript_get_global_type_tag",
|
||||
"return_type": "const void *",
|
||||
"arguments": [
|
||||
["int", "p_idx"],
|
||||
["const char *", "p_name"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "godot_nativescript_set_type_tag",
|
||||
"return_type": "void",
|
||||
|
|
|
@ -214,13 +214,16 @@ void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle,
|
|||
|
||||
// type tag API
|
||||
|
||||
void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag);
|
||||
const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name);
|
||||
|
||||
void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
|
||||
const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
|
||||
|
||||
// instance binding API
|
||||
|
||||
typedef struct {
|
||||
GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, godot_object *);
|
||||
GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
|
||||
GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
|
||||
void *data;
|
||||
GDCALLINGCONV void (*free_func)(void *);
|
||||
|
|
|
@ -313,6 +313,14 @@ void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle,
|
|||
signal->get().documentation = *(String *)&p_documentation;
|
||||
}
|
||||
|
||||
void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag) {
|
||||
NativeScriptLanguage::get_singleton()->set_global_type_tag(p_idx, StringName(p_name), p_type_tag);
|
||||
}
|
||||
|
||||
const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name) {
|
||||
return NativeScriptLanguage::get_singleton()->get_global_type_tag(p_idx, StringName(p_name));
|
||||
}
|
||||
|
||||
void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag) {
|
||||
String *s = (String *)p_gdnative_handle;
|
||||
|
||||
|
@ -347,10 +355,6 @@ const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions) {
|
||||
return NativeScriptLanguage::get_singleton()->register_binding_functions(p_binding_functions);
|
||||
}
|
||||
|
@ -362,3 +366,7 @@ void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_i
|
|||
void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object) {
|
||||
return NativeScriptLanguage::get_singleton()->get_instance_binding_data(p_idx, (Object *)p_object);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -55,12 +55,6 @@
|
|||
#include "editor/editor_node.h"
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
// Script stuff
|
||||
//
|
||||
//
|
||||
|
||||
void NativeScript::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_class_name", "class_name"), &NativeScript::set_class_name);
|
||||
ClassDB::bind_method(D_METHOD("get_class_name"), &NativeScript::get_class_name);
|
||||
|
@ -528,12 +522,6 @@ NativeScript::~NativeScript() {
|
|||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// ScriptInstance stuff
|
||||
//
|
||||
//
|
||||
|
||||
#define GET_SCRIPT_DESC() script->get_script_desc()
|
||||
|
||||
void NativeScriptInstance::_ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount) {
|
||||
|
@ -872,12 +860,6 @@ NativeScriptInstance::~NativeScriptInstance() {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// ScriptingLanguage stuff
|
||||
//
|
||||
//
|
||||
|
||||
NativeScriptLanguage *NativeScriptLanguage::singleton;
|
||||
|
||||
void NativeScriptLanguage::_unload_stuff(bool p_reload) {
|
||||
|
@ -1195,8 +1177,11 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
|
|||
}
|
||||
|
||||
if (!(*binding_data)[p_idx]) {
|
||||
|
||||
const void *global_type_tag = global_type_tags[p_idx].get(p_object->get_class_name());
|
||||
|
||||
// no binding data yet, soooooo alloc new one \o/
|
||||
(*binding_data)[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, (godot_object *)p_object);
|
||||
(*binding_data)[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
|
||||
}
|
||||
|
||||
return (*binding_data)[p_idx];
|
||||
|
@ -1238,6 +1223,27 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
|
|||
delete &binding_data;
|
||||
}
|
||||
|
||||
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)) {
|
||||
global_type_tags.insert(p_idx, HashMap<StringName, const void *>());
|
||||
}
|
||||
|
||||
HashMap<StringName, const void *> &tags = global_type_tags[p_idx];
|
||||
|
||||
tags.set(p_class_name, p_type_tag);
|
||||
}
|
||||
|
||||
const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const {
|
||||
if (!global_type_tags.has(p_idx))
|
||||
return NULL;
|
||||
|
||||
const HashMap<StringName, const void *> &tags = global_type_tags[p_idx];
|
||||
|
||||
const void *tag = tags.get(p_class_name);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
#ifndef NO_THREADS
|
||||
void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script) {
|
||||
MutexLock lock(mutex);
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "core/self_list.h"
|
||||
#include "io/resource_loader.h"
|
||||
#include "io/resource_saver.h"
|
||||
#include "oa_hash_map.h"
|
||||
#include "ordered_hash_map.h"
|
||||
#include "os/thread_safe.h"
|
||||
#include "scene/main/node.h"
|
||||
|
@ -240,6 +241,8 @@ private:
|
|||
Vector<Pair<bool, godot_instance_binding_functions> > binding_functions;
|
||||
Set<Vector<void *> *> binding_instances;
|
||||
|
||||
Map<int, HashMap<StringName, const void *> > global_type_tags;
|
||||
|
||||
public:
|
||||
// These two maps must only be touched on the main thread
|
||||
Map<String, Map<StringName, NativeScriptDesc> > library_classes;
|
||||
|
@ -323,6 +326,9 @@ public:
|
|||
|
||||
virtual void *alloc_instance_binding_data(Object *p_object);
|
||||
virtual void free_instance_binding_data(void *p_data);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
inline NativeScriptDesc *NativeScript::get_script_desc() const {
|
||||
|
|
Loading…
Reference in a new issue