mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 22:21:18 +00:00
Fix editor needs restart after adding GDExtensions
This commit is contained in:
parent
fd7239cfab
commit
ef6f873938
10 changed files with 196 additions and 65 deletions
|
|
@ -57,6 +57,7 @@
|
|||
#include "scene/scene_string_names.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "core/extension/gdextension_manager.h"
|
||||
#include "editor/editor_paths.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -2177,9 +2178,26 @@ void GDScriptLanguage::_add_global(const StringName &p_name, const Variant &p_va
|
|||
global_array.write[globals[p_name]] = p_value;
|
||||
return;
|
||||
}
|
||||
globals[p_name] = global_array.size();
|
||||
global_array.push_back(p_value);
|
||||
_global_array = global_array.ptrw();
|
||||
|
||||
if (global_array_empty_indexes.size()) {
|
||||
int index = global_array_empty_indexes[global_array_empty_indexes.size() - 1];
|
||||
globals[p_name] = index;
|
||||
global_array.write[index] = p_value;
|
||||
global_array_empty_indexes.resize(global_array_empty_indexes.size() - 1);
|
||||
} else {
|
||||
globals[p_name] = global_array.size();
|
||||
global_array.push_back(p_value);
|
||||
_global_array = global_array.ptrw();
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptLanguage::_remove_global(const StringName &p_name) {
|
||||
if (!globals.has(p_name)) {
|
||||
return;
|
||||
}
|
||||
global_array_empty_indexes.push_back(globals[p_name]);
|
||||
global_array.write[globals[p_name]] = Variant::NIL;
|
||||
globals.erase(p_name);
|
||||
}
|
||||
|
||||
void GDScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) {
|
||||
|
|
@ -2237,11 +2255,40 @@ void GDScriptLanguage::init() {
|
|||
_add_global(E.name, E.ptr);
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
GDExtensionManager::get_singleton()->connect("extension_loaded", callable_mp(this, &GDScriptLanguage::_extension_loaded));
|
||||
GDExtensionManager::get_singleton()->connect("extension_unloading", callable_mp(this, &GDScriptLanguage::_extension_unloading));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TESTS_ENABLED
|
||||
GDScriptTests::GDScriptTestRunner::handle_cmdline();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
void GDScriptLanguage::_extension_loaded(const Ref<GDExtension> &p_extension) {
|
||||
List<StringName> class_list;
|
||||
ClassDB::get_extension_class_list(p_extension, &class_list);
|
||||
for (const StringName &n : class_list) {
|
||||
if (globals.has(n)) {
|
||||
continue;
|
||||
}
|
||||
Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(n));
|
||||
_add_global(n, nc);
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptLanguage::_extension_unloading(const Ref<GDExtension> &p_extension) {
|
||||
List<StringName> class_list;
|
||||
ClassDB::get_extension_class_list(p_extension, &class_list);
|
||||
for (const StringName &n : class_list) {
|
||||
_remove_global(n);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
String GDScriptLanguage::get_type() const {
|
||||
return "GDScript";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue