32
32
33
33
#include " core/extension/gdextension_compat_hashes.h"
34
34
#include " core/extension/gdextension_library_loader.h"
35
- #include " core/io/dir_access.h"
36
35
#include " core/io/file_access.h"
37
36
#include " core/object/script_language.h"
38
37
39
- GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal (const Ref<GDExtension> &p_extension, bool p_first_load ) {
38
+ GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal (const Ref<GDExtension> &p_extension) {
40
39
if (level >= 0 ) { // Already initialized up to some level.
41
- int32_t minimum_level = 0 ;
42
- if (!p_first_load) {
43
- minimum_level = p_extension->get_minimum_library_initialization_level ();
44
- if (minimum_level < MIN (level, GDExtension::INITIALIZATION_LEVEL_SCENE)) {
45
- return LOAD_STATUS_NEEDS_RESTART;
46
- }
40
+ int32_t minimum_level = p_extension->get_minimum_library_initialization_level ();
41
+ if (minimum_level < MIN (level, GDExtension::INITIALIZATION_LEVEL_SCENE)) {
42
+ return LOAD_STATUS_NEEDS_RESTART;
47
43
}
48
44
// Initialize up to current level.
49
45
for (int32_t i = minimum_level; i <= level; i++) {
@@ -55,20 +51,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(cons
55
51
gdextension_class_icon_paths[kv.key ] = kv.value ;
56
52
}
57
53
58
- #ifdef TOOLS_ENABLED
59
- // Signals that a new extension is loaded so GDScript can register new class names.
60
- emit_signal (" extension_loaded" , p_extension);
61
- #endif
62
-
63
54
return LOAD_STATUS_OK;
64
55
}
65
56
66
57
GDExtensionManager::LoadStatus GDExtensionManager::_unload_extension_internal (const Ref<GDExtension> &p_extension) {
67
- #ifdef TOOLS_ENABLED
68
- // Signals that a new extension is unloading so GDScript can unregister class names.
69
- emit_signal (" extension_unloading" , p_extension);
70
- #endif
71
-
72
58
if (level >= 0 ) { // Already initialized up to some level.
73
59
// Deinitialize down from current level.
74
60
for (int32_t i = level; i >= GDExtension::INITIALIZATION_LEVEL_CORE; i--) {
@@ -103,7 +89,7 @@ GDExtensionManager::LoadStatus GDExtensionManager::load_extension_with_loader(co
103
89
return LOAD_STATUS_FAILED;
104
90
}
105
91
106
- LoadStatus status = _load_extension_internal (extension, true );
92
+ LoadStatus status = _load_extension_internal (extension);
107
93
if (status != LOAD_STATUS_OK) {
108
94
return status;
109
95
}
@@ -149,7 +135,7 @@ GDExtensionManager::LoadStatus GDExtensionManager::reload_extension(const String
149
135
return LOAD_STATUS_FAILED;
150
136
}
151
137
152
- status = _load_extension_internal (extension, false );
138
+ status = _load_extension_internal (extension);
153
139
if (status != LOAD_STATUS_OK) {
154
140
return status;
155
141
}
@@ -288,72 +274,6 @@ void GDExtensionManager::reload_extensions() {
288
274
#endif
289
275
}
290
276
291
- bool GDExtensionManager::ensure_extensions_loaded (const HashSet<String> &p_extensions) {
292
- Vector<String> extensions_added;
293
- Vector<String> extensions_removed;
294
-
295
- for (const String &E : p_extensions) {
296
- if (!is_extension_loaded (E)) {
297
- extensions_added.push_back (E);
298
- }
299
- }
300
-
301
- Vector<String> loaded_extensions = get_loaded_extensions ();
302
- for (const String &loaded_extension : loaded_extensions) {
303
- if (!p_extensions.has (loaded_extension)) {
304
- // The extension may not have a .gdextension file.
305
- const Ref<GDExtension> extension = GDExtensionManager::get_singleton ()->get_extension (loaded_extension);
306
- if (!extension->get_loader ()->library_exists ()) {
307
- extensions_removed.push_back (loaded_extension);
308
- }
309
- }
310
- }
311
-
312
- String extension_list_config_file = GDExtension::get_extension_list_config_file ();
313
- if (p_extensions.size ()) {
314
- if (extensions_added.size () || extensions_removed.size ()) {
315
- // Extensions were added or removed.
316
- Ref<FileAccess> f = FileAccess::open (extension_list_config_file, FileAccess::WRITE);
317
- for (const String &E : p_extensions) {
318
- f->store_line (E);
319
- }
320
- }
321
- } else {
322
- if (loaded_extensions.size () || FileAccess::exists (extension_list_config_file)) {
323
- // Extensions were removed.
324
- Ref<DirAccess> da = DirAccess::create (DirAccess::ACCESS_RESOURCES);
325
- da->remove (extension_list_config_file);
326
- }
327
- }
328
-
329
- bool needs_restart = false ;
330
- for (const String &extension : extensions_added) {
331
- GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton ()->load_extension (extension);
332
- if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
333
- needs_restart = true ;
334
- }
335
- }
336
-
337
- for (const String &extension : extensions_removed) {
338
- GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton ()->unload_extension (extension);
339
- if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
340
- needs_restart = true ;
341
- }
342
- }
343
-
344
- #ifdef TOOLS_ENABLED
345
- if (extensions_added.size () || extensions_removed.size ()) {
346
- // Emitting extensions_reloaded so EditorNode can reload Inspector and regenerate documentation.
347
- emit_signal (" extensions_reloaded" );
348
-
349
- // Reload all scripts to clear out old references.
350
- callable_mp_static (&GDExtensionManager::_reload_all_scripts).call_deferred ();
351
- }
352
- #endif
353
-
354
- return needs_restart;
355
- }
356
-
357
277
GDExtensionManager *GDExtensionManager::get_singleton () {
358
278
return singleton;
359
279
}
@@ -374,8 +294,6 @@ void GDExtensionManager::_bind_methods() {
374
294
BIND_ENUM_CONSTANT (LOAD_STATUS_NEEDS_RESTART);
375
295
376
296
ADD_SIGNAL (MethodInfo (" extensions_reloaded" ));
377
- ADD_SIGNAL (MethodInfo (" extension_loaded" , PropertyInfo (Variant::OBJECT, " extension" , PROPERTY_HINT_RESOURCE_TYPE, " GDExtension" )));
378
- ADD_SIGNAL (MethodInfo (" extension_unloading" , PropertyInfo (Variant::OBJECT, " extension" , PROPERTY_HINT_RESOURCE_TYPE, " GDExtension" )));
379
297
}
380
298
381
299
GDExtensionManager *GDExtensionManager::singleton = nullptr ;
0 commit comments