MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / get_full_script

Method get_full_script

modules/gdscript/gdscript_cache.cpp:348–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346}
347
348Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner, bool p_update_from_disk) {
349 MutexLock lock(singleton->mutex);
350
351 if (!p_owner.is_empty()) {
352 singleton->dependencies[p_owner].insert(p_path);
353 }
354
355 Ref<GDScript> script;
356 r_error = OK;
357 if (singleton->full_gdscript_cache.has(p_path)) {
358 script = singleton->full_gdscript_cache[p_path];
359 if (!p_update_from_disk) {
360 return script;
361 }
362 }
363
364 if (script.is_null()) {
365 script = get_shallow_script(p_path, r_error);
366 // Only exit early if script failed to load, otherwise let reload report errors.
367 if (script.is_null()) {
368 return script;
369 }
370 }
371
372 const String remapped_path = ResourceLoader::path_remap(p_path);
373
374 if (p_update_from_disk) {
375 if (remapped_path.get_extension().to_lower() == "gdc") {
376 Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
377 if (buffer.is_empty()) {
378 r_error = ERR_FILE_CANT_READ;
379 return script;
380 }
381 script->set_binary_tokens_source(buffer);
382 } else {
383 r_error = script->load_source_code(remapped_path);
384 if (r_error) {
385 return script;
386 }
387 }
388 }
389
390 // Allowing lifting the lock might cause a script to be reloaded multiple times,
391 // which, as a last resort deadlock prevention strategy, is a good tradeoff.
392 uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone(singleton->mutex);
393 r_error = script->reload(true);
394 WorkerThreadPool::thread_exit_unlock_allowance_zone(allowance_id);
395 if (r_error) {
396 return script;
397 }
398
399 singleton->full_gdscript_cache[p_path] = script;
400 singleton->shallow_gdscript_cache.erase(p_path);
401
402 return script;
403}
404
405Ref<GDScript> GDScriptCache::get_cached_script(const String &p_path) {

Callers

nothing calls this directly

Calls 10

to_lowerMethod · 0.80
is_emptyMethod · 0.45
insertMethod · 0.45
hasMethod · 0.45
is_nullMethod · 0.45
get_extensionMethod · 0.45
load_source_codeMethod · 0.45
reloadMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected