Browse Source

GDScript files are converted to binary on export now.

Juan Linietsky 7 years ago
parent
commit
93a63a5e1a
5 changed files with 102 additions and 20 deletions
  1. 48 20
      core/io/resource_loader.cpp
  2. 4 0
      core/io/resource_loader.h
  3. 1 0
      editor/editor_node.cpp
  4. 5 0
      main/main.cpp
  5. 44 0
      modules/gdscript/register_types.cpp

+ 48 - 20
core/io/resource_loader.cpp

@@ -196,19 +196,19 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
 	else
 		local_path = ProjectSettings::get_singleton()->localize_path(p_path);
 
-	bool xl_remapped = false;
-	String path = _path_remap(local_path, &xl_remapped);
-
-	ERR_FAIL_COND_V(path == "", RES());
-
-	if (!p_no_cache && ResourceCache::has(path)) {
+	if (!p_no_cache && ResourceCache::has(local_path)) {
 
 		if (OS::get_singleton()->is_stdout_verbose())
-			print_line("load resource: " + path + " (cached)");
+			print_line("load resource: " + local_path + " (cached)");
 
-		return RES(ResourceCache::get(path));
+		return RES(ResourceCache::get(local_path));
 	}
 
+	bool xl_remapped = false;
+	String path = _path_remap(local_path, &xl_remapped);
+
+	ERR_FAIL_COND_V(path == "", RES());
+
 	if (OS::get_singleton()->is_stdout_verbose())
 		print_line("load resource: " + path);
 
@@ -247,23 +247,23 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
 	else
 		local_path = ProjectSettings::get_singleton()->localize_path(p_path);
 
-	bool xl_remapped = false;
-	String path = _path_remap(local_path, &xl_remapped);
-
-	ERR_FAIL_COND_V(path == "", Ref<ResourceInteractiveLoader>());
-
-	if (!p_no_cache && ResourceCache::has(path)) {
+	if (!p_no_cache && ResourceCache::has(local_path)) {
 
 		if (OS::get_singleton()->is_stdout_verbose())
-			print_line("load resource: " + path + " (cached)");
+			print_line("load resource: " + local_path + " (cached)");
 
-		Ref<Resource> res_cached = ResourceCache::get(path);
+		Ref<Resource> res_cached = ResourceCache::get(local_path);
 		Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault));
 
 		ril->resource = res_cached;
 		return ril;
 	}
 
+	bool xl_remapped = false;
+	String path = _path_remap(local_path, &xl_remapped);
+
+	ERR_FAIL_COND_V(path == "", Ref<ResourceInteractiveLoader>());
+
 	if (OS::get_singleton()->is_stdout_verbose())
 		print_line("load resource: ");
 
@@ -426,9 +426,11 @@ String ResourceLoader::get_resource_type(const String &p_path) {
 
 String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {
 
-	if (translation_remaps.has(p_path)) {
+	String new_path = p_path;
 
-		Vector<String> &v = *translation_remaps.getptr(p_path);
+	if (translation_remaps.has(new_path)) {
+
+		Vector<String> &v = *translation_remaps.getptr(new_path);
 		String locale = TranslationServer::get_singleton()->get_locale();
 		if (r_translation_remapped) {
 			*r_translation_remapped = true;
@@ -443,12 +445,16 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
 				continue;
 
 			if (l.begins_with(locale)) {
-				return v[i].left(split);
+				new_path = v[i].left(split);
+				break;
 			}
 		}
 	}
 
-	return p_path;
+	if (path_remaps.has(new_path)) {
+		new_path = path_remaps[new_path];
+	}
+	return new_path;
 }
 
 String ResourceLoader::import_remap(const String &p_path) {
@@ -515,6 +521,27 @@ void ResourceLoader::clear_translation_remaps() {
 	translation_remaps.clear();
 }
 
+void ResourceLoader::load_path_remaps() {
+
+	if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths"))
+		return;
+
+	PoolVector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths");
+	int rc = remaps.size();
+	ERR_FAIL_COND(rc & 1); //must be even
+	PoolVector<String>::Read r = remaps.read();
+
+	for (int i = 0; i < rc; i += 2) {
+
+		path_remaps[r[i]] = r[i + 1];
+	}
+}
+
+void ResourceLoader::clear_path_remaps() {
+
+	path_remaps.clear();
+}
+
 ResourceLoadErrorNotify ResourceLoader::err_notify = NULL;
 void *ResourceLoader::err_notify_ud = NULL;
 
@@ -526,3 +553,4 @@ bool ResourceLoader::timestamp_on_load = false;
 
 SelfList<Resource>::List ResourceLoader::remapped_list;
 HashMap<String, Vector<String> > ResourceLoader::translation_remaps;
+HashMap<String, String> ResourceLoader::path_remaps;

+ 4 - 0
core/io/resource_loader.h

@@ -91,6 +91,7 @@ class ResourceLoader {
 	static DependencyErrorNotify dep_err_notify;
 	static bool abort_on_missing_resource;
 	static HashMap<String, Vector<String> > translation_remaps;
+	static HashMap<String, String> path_remaps;
 
 	static String _path_remap(const String &p_path, bool *r_translation_remapped = NULL);
 	friend class Resource;
@@ -137,6 +138,9 @@ public:
 	static String path_remap(const String &p_path);
 	static String import_remap(const String &p_path);
 
+	static void load_path_remaps();
+	static void clear_path_remaps();
+
 	static void reload_translation_remaps();
 	static void load_translation_remaps();
 	static void clear_translation_remaps();

+ 1 - 0
editor/editor_node.cpp

@@ -4708,6 +4708,7 @@ EditorNode::EditorNode() {
 	EditorHelp::generate_doc(); //before any editor classes are crated
 	SceneState::set_disable_placeholders(true);
 	ResourceLoader::clear_translation_remaps(); //no remaps using during editor
+	ResourceLoader::clear_path_remaps();
 	editor_initialize_certificates(); //for asset sharing
 
 	InputDefault *id = Object::cast_to<InputDefault>(Input::get_singleton());

+ 5 - 0
main/main.cpp

@@ -1136,6 +1136,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
 	translation_server->load_translations();
 	ResourceLoader::load_translation_remaps(); //load remaps for resources
 
+	ResourceLoader::load_path_remaps();
+
 	audio_server->load_default_bus_layout();
 
 	if (use_debug_profiler && script_debugger) {
@@ -1816,6 +1818,9 @@ void Main::cleanup() {
 	OS::get_singleton()->_execpath = "";
 	OS::get_singleton()->_local_clipboard = "";
 
+	ResourceLoader::clear_translation_remaps();
+	ResourceLoader::clear_path_remaps();
+
 	ScriptServer::finish_languages();
 
 #ifdef TOOLS_ENABLED

+ 44 - 0
modules/gdscript/register_types.cpp

@@ -30,6 +30,7 @@
 #include "register_types.h"
 
 #include "gdscript.h"
+#include "gdscript_tokenizer.h"
 #include "io/file_access_encrypted.h"
 #include "io/resource_loader.h"
 #include "os/file_access.h"
@@ -38,6 +39,45 @@ GDScriptLanguage *script_language_gd = NULL;
 ResourceFormatLoaderGDScript *resource_loader_gd = NULL;
 ResourceFormatSaverGDScript *resource_saver_gd = NULL;
 
+#ifdef TOOLS_ENABLED
+
+#include "editor/editor_export.h"
+#include "editor/editor_node.h"
+#include "editor/editor_settings.h"
+
+class EditorExportGDScript : public EditorExportPlugin {
+
+	GDCLASS(EditorExportGDScript, EditorExportPlugin);
+
+public:
+	virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
+
+		if (!p_path.ends_with(".gd"))
+			return;
+
+		Vector<uint8_t> file = FileAccess::get_file_as_array(p_path);
+		if (file.empty())
+			return;
+		String txt;
+		txt.parse_utf8((const char *)file.ptr(), file.size());
+		file = GDScriptTokenizerBuffer::parse_code_string(txt);
+
+		if (file.empty())
+			return;
+
+		add_file(p_path.get_basename() + ".gdc", file, true);
+	}
+};
+
+static void _editor_init() {
+
+	Ref<EditorExportGDScript> gd_export;
+	gd_export.instance();
+	EditorExport::get_singleton()->add_export_plugin(gd_export);
+}
+
+#endif
+
 void register_gdscript_types() {
 
 	ClassDB::register_class<GDScript>();
@@ -49,6 +89,10 @@ void register_gdscript_types() {
 	ResourceLoader::add_resource_format_loader(resource_loader_gd);
 	resource_saver_gd = memnew(ResourceFormatSaverGDScript);
 	ResourceSaver::add_resource_format_saver(resource_saver_gd);
+
+#ifdef TOOLS_ENABLED
+	EditorNode::add_init_callback(_editor_init);
+#endif
 }
 
 void unregister_gdscript_types() {