ソースを参照

Put compiled resources into data folder

Daniele Bartolini 11 年 前
コミット
b23832f330
2 ファイル変更31 行追加12 行削除
  1. 22 9
      engine/compilers/bundle_compiler.cpp
  2. 9 3
      engine/resource/resource_loader.cpp

+ 22 - 9
engine/compilers/bundle_compiler.cpp

@@ -15,7 +15,7 @@
 #include "compile_options.h"
 #include "resource_registry.h"
 #include "resource_id.h"
-#include <inttypes.h>
+#include "temp_allocator.h"
 
 namespace crown
 {
@@ -30,17 +30,27 @@ BundleCompiler::BundleCompiler(const char* source_dir, const char* bundle_dir)
 
 bool BundleCompiler::compile(const char* type, const char* name, Platform::Enum platform)
 {
-	const ResourceId id(type, name);
-	char out_name[512];
-	snprintf(out_name, 512, "%.16"PRIx64"-%.16"PRIx64, id.type, id.name);
-	char path[512];
-	snprintf(path, 512, "%s.%s", name, type);
+	ResourceId id(type, name);
 
-	CE_LOGI("%s <= %s.%s", out_name, name, type);
+	TempAllocator512 alloc;
+	DynamicString path(alloc);
+	TempAllocator512 alloc2;
+	DynamicString src_path(alloc2);
 
-	File* outf = _bundle_fs.open(out_name, FOM_WRITE);
+	src_path += name;
+	src_path += ".";
+	src_path += type;
+
+	char res_name[64];
+	id.to_string(res_name);
+
+	path::join("data", res_name, path);
+
+	CE_LOGI("%s <= %s.%s", res_name, name, type);
+
+	File* outf = _bundle_fs.open(path.c_str(), FOM_WRITE);
 	CompileOptions opts(_source_fs, outf, platform);
-	resource_on_compile(id.type, path, opts);
+	resource_on_compile(id.type, src_path.c_str(), opts);
 	_bundle_fs.close(outf);
 	return true;
 }
@@ -62,6 +72,9 @@ bool BundleCompiler::compile_all(Platform::Enum platform)
 	_source_fs.close(src);
 	_bundle_fs.close(dst);
 
+	if (!_bundle_fs.exists("data"))
+		_bundle_fs.create_directory("data");
+
 	// Compile all resources
 	for (uint32_t i = 0; i < vector::size(files); i++)
 	{

+ 9 - 3
engine/resource/resource_loader.cpp

@@ -9,6 +9,8 @@
 #include "log.h"
 #include "queue.h"
 #include "filesystem.h"
+#include "temp_allocator.h"
+#include "path.h"
 
 namespace crown
 {
@@ -84,10 +86,14 @@ int32_t ResourceLoader::run()
 		ResourceData rd;
 		rd.id = id;
 
-		char path[64];
-		id.to_string(path);
+		char name[64];
+		id.to_string(name);
 
-		File* file = _fs.open(path, FOM_READ);
+		TempAllocator256 alloc;
+		DynamicString path(alloc);
+		path::join("data", name, path);
+
+		File* file = _fs.open(path.c_str(), FOM_READ);
 		rd.data = resource_on_load(id.type, *file, _resource_heap);
 		_fs.close(file);