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

Method get_shallow_script

modules/gdscript/gdscript_cache.cpp:306–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_error, const String &p_owner) {
307 MutexLock lock(singleton->mutex);
308
309 if (!p_owner.is_empty()) {
310 singleton->dependencies[p_owner].insert(p_path);
311 }
312 if (singleton->full_gdscript_cache.has(p_path)) {
313 return singleton->full_gdscript_cache[p_path];
314 }
315 if (singleton->shallow_gdscript_cache.has(p_path)) {
316 return singleton->shallow_gdscript_cache[p_path];
317 }
318
319 const String remapped_path = ResourceLoader::path_remap(p_path);
320
321 Ref<GDScript> script;
322 script.instantiate();
323 script->set_path(p_path, true);
324 if (remapped_path.get_extension().to_lower() == "gdc") {
325 Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
326 if (buffer.is_empty()) {
327 r_error = ERR_FILE_CANT_READ;
328 }
329 script->set_binary_tokens_source(buffer);
330 } else {
331 r_error = script->load_source_code(remapped_path);
332 }
333
334 if (r_error) {
335 return Ref<GDScript>(); // Returns null and does not cache when the script fails to load.
336 }
337
338 Ref<GDScriptParserRef> parser_ref = get_parser(p_path, GDScriptParserRef::PARSED, r_error);
339 if (r_error == OK) {
340 GDScriptCompiler::make_scripts(script.ptr(), parser_ref->get_parser()->get_tree(), true);
341 }
342
343 singleton->shallow_gdscript_cache[p_path] = script;
344
345 return script;
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);

Callers

nothing calls this directly

Calls 12

to_lowerMethod · 0.80
is_emptyMethod · 0.45
insertMethod · 0.45
hasMethod · 0.45
instantiateMethod · 0.45
set_pathMethod · 0.45
get_extensionMethod · 0.45
load_source_codeMethod · 0.45
ptrMethod · 0.45
get_treeMethod · 0.45
get_parserMethod · 0.45

Tested by

no test coverage detected