Parcourir la source

GDScript: Add script to cache on reload

This ensures that scripts created without a resource loader are properly
included in the cache (such as builtin scripts) and are not tried to be
loaded from the disk.
George Marques il y a 5 ans
Parent
commit
8088e9e6ac
1 fichiers modifiés avec 15 ajouts et 0 suppressions
  1. 15 0
      modules/gdscript/gdscript.cpp

+ 15 - 0
modules/gdscript/gdscript.cpp

@@ -596,6 +596,21 @@ Error GDScript::reload(bool p_keep_state) {
 		return OK;
 		return OK;
 	}
 	}
 
 
+	{
+		String source_path = path;
+		if (source_path.empty()) {
+			source_path = get_path();
+		}
+		if (!source_path.empty()) {
+			MutexLock lock(GDScriptCache::singleton->lock);
+			Ref<GDScript> self(this);
+			if (!GDScriptCache::singleton->shallow_gdscript_cache.has(source_path)) {
+				GDScriptCache::singleton->shallow_gdscript_cache[source_path] = self;
+				self->unreference();
+			}
+		}
+	}
+
 	valid = false;
 	valid = false;
 	GDScriptParser parser;
 	GDScriptParser parser;
 	Error err = parser.parse(source, path, false);
 	Error err = parser.parse(source, path, false);