1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Added a simpler/faster way to bind script languages instance wrappers to Godot

This commit is contained in:
Juan Linietsky
2017-07-16 12:39:23 -03:00
parent 40ab9adec3
commit 4366b7c8b0
4 changed files with 37 additions and 6 deletions

View File

@@ -1817,6 +1817,23 @@ uint32_t Object::get_edited_version() const {
}
#endif
void *Object::get_script_instance_binding(int p_script_language_index) {
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(p_script_language_index, MAX_SCRIPT_INSTANCE_BINDINGS, NULL);
#endif
//it's up to the script language to make this thread safe, if the function is called twice due to threads being out of syncro
//just return the same pointer.
//if you want to put a big lock in the entire function and keep allocated pointers in a map or something, feel free to do it
//as it should not really affect performance much (won't be called too often), as in far most caes the condition below will be false afterwards
if (!_script_instance_bindings[p_script_language_index]) {
_script_instance_bindings[p_script_language_index] = ScriptServer::get_language(p_script_language_index)->alloc_instance_binding_data(this);
}
return _script_instance_bindings[p_script_language_index];
}
Object::Object() {
_class_ptr = NULL;
@@ -1826,6 +1843,7 @@ Object::Object() {
_instance_ID = ObjectDB::add_instance(this);
_can_translate = true;
_is_queued_for_deletion = false;
memset(_script_instance_bindings, 0, sizeof(void *) * MAX_SCRIPT_INSTANCE_BINDINGS);
script_instance = NULL;
#ifdef TOOLS_ENABLED
@@ -1877,6 +1895,12 @@ Object::~Object() {
ObjectDB::remove_instance(this);
_instance_ID = 0;
_predelete_ok = 2;
for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) {
if (_script_instance_bindings[i]) {
ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]);
}
}
}
bool predelete_handler(Object *p_object) {