Daniele Bartolini 9 лет назад
Родитель
Сommit
ada50871cf
3 измененных файлов с 60 добавлено и 37 удалено
  1. 17 11
      src/resource/bundle_compiler.cpp
  2. 24 14
      src/resource/resource_loader.cpp
  3. 19 12
      src/resource/resource_manager.cpp

+ 17 - 11
src/resource/bundle_compiler.cpp

@@ -157,23 +157,29 @@ bool BundleCompiler::compile(const char* type, const char* name, const char* pla
 	StringId64 _type(type);
 	StringId64 _name(name);
 
-	TempAllocator512 alloc;
-	DynamicString path(alloc);
-	TempAllocator512 alloc2;
-	DynamicString src_path(alloc2);
+	TempAllocator1024 ta;
+	DynamicString path(ta);
+	DynamicString src_path(ta);
 
+	// Build source file path
 	src_path += name;
-	src_path += ".";
+	src_path += '.';
 	src_path += type;
 
-	char res_name[1 + 2*StringId64::STRING_LENGTH];
-	_type.to_string(res_name);
-	res_name[16] = '-';
-	_name.to_string(res_name + 17);
+	// Build compiled file path
+	DynamicString type_str(ta);
+	DynamicString name_str(ta);
+	_type.to_string(type_str);
+	_name.to_string(name_str);
 
-	path::join(CROWN_DATA_DIRECTORY, res_name, path);
+	DynamicString dst_path(ta);
+	dst_path += type_str;
+	dst_path += '-';
+	dst_path += name_str;
 
-	CE_LOGI("%s <= %s.%s", res_name, name, type);
+	path::join(CROWN_DATA_DIRECTORY, dst_path.c_str(), path);
+
+	CE_LOGI("%s <= %s", dst_path.c_str(), src_path.c_str());
 
 	bool success = true;
 	jmp_buf buf;

+ 24 - 14
src/resource/resource_loader.cpp

@@ -31,14 +31,19 @@ ResourceLoader::~ResourceLoader()
 
 bool ResourceLoader::can_load(StringId64 type, StringId64 name)
 {
-	char buf[1 + 2*StringId64::STRING_LENGTH];
-	type.to_string(buf);
-	buf[16] = '-';
-	name.to_string(buf + 17);
+	TempAllocator128 ta;
+	DynamicString type_str(ta);
+	DynamicString name_str(ta);
+	type.to_string(type_str);
+	name.to_string(name_str);
 
-	TempAllocator256 alloc;
-	DynamicString path(alloc);
-	path::join(CROWN_DATA_DIRECTORY, buf, path);
+	DynamicString res_path(ta);
+	res_path += type_str;
+	res_path += '-';
+	res_path += name_str;
+
+	DynamicString path(ta);
+	path::join(CROWN_DATA_DIRECTORY, res_path.c_str(), path);
 
 	return _fs.exists(path.c_str());
 }
@@ -93,14 +98,19 @@ s32 ResourceLoader::run()
 		ResourceRequest rr = queue::front(_requests);
 		_mutex.unlock();
 
-		char name[1 + 2*StringId64::STRING_LENGTH];
-		rr.type.to_string(name);
-		name[16] = '-';
-		rr.name.to_string(name + 17);
+		TempAllocator128 ta;
+		DynamicString type_str(ta);
+		DynamicString name_str(ta);
+		rr.type.to_string(type_str);
+		rr.name.to_string(name_str);
+
+		DynamicString res_path(ta);
+		res_path += type_str;
+		res_path += '-';
+		res_path += name_str;
 
-		TempAllocator256 alloc;
-		DynamicString path(alloc);
-		path::join(CROWN_DATA_DIRECTORY, name, path);
+		DynamicString path(ta);
+		path::join(CROWN_DATA_DIRECTORY, res_path.c_str(), path);
 
 		File* file = _fs.open(path.c_str(), FileOpenMode::READ);
 		rr.data = rr.load_function(*file, *rr.allocator);

+ 19 - 12
src/resource/resource_manager.cpp

@@ -5,6 +5,7 @@
 
 #include "array.h"
 #include "config_resource.h"
+#include "dynamic_string.h"
 #include "font_resource.h"
 #include "level_resource.h"
 #include "lua_resource.h"
@@ -87,16 +88,19 @@ void ResourceManager::load(StringId64 type, StringId64 name)
 
 	if (entry == ResourceEntry::NOT_FOUND)
 	{
-		char type_buf[StringId64::STRING_LENGTH];
-		char name_buf[StringId64::STRING_LENGTH];
+		TempAllocator64 ta;
+		DynamicString type_str(ta);
+		DynamicString name_str(ta);
+		type.to_string(type_str);
+		name.to_string(name_str);
 
 		CE_ASSERT(_loader->can_load(type, name)
 			, "Can't load resource #ID(%s-%s)"
-			, type.to_string(type_buf)
-			, name.to_string(name_buf)
+			, type_str.c_str()
+			, name_str.c_str()
 			);
-		CE_UNUSED(type_buf);
-		CE_UNUSED(name_buf);
+		CE_UNUSED(type_str);
+		CE_UNUSED(name_str);
 
 		ResourceRequest rr;
 		rr.type = type;
@@ -152,16 +156,19 @@ bool ResourceManager::can_get(StringId64 type, StringId64 name)
 const void* ResourceManager::get(StringId64 type, StringId64 name)
 {
 	const ResourcePair id = { type, name };
-	char type_buf[StringId64::STRING_LENGTH];
-	char name_buf[StringId64::STRING_LENGTH];
+	TempAllocator128 ta;
+	DynamicString type_str(ta);
+	DynamicString name_str(ta);
+	type.to_string(type_str);
+	name.to_string(name_str);
 
 	CE_ASSERT(can_get(type, name)
 		, "Resource not loaded #ID(%s-%s)"
-		, type.to_string(type_buf)
-		, name.to_string(name_buf)
+		, type_str.c_str()
+		, name_str.c_str()
 		);
-	CE_UNUSED(type_buf);
-	CE_UNUSED(name_buf);
+	CE_UNUSED(type_str);
+	CE_UNUSED(name_str);
 
 	if (_autoload && !sort_map::has(_rm, id))
 	{