Просмотр исходного кода

Generate 64-bit hash for resource names

Daniele Bartolini 12 лет назад
Родитель
Сommit
cf4a751f3f
1 измененных файлов с 10 добавлено и 12 удалено
  1. 10 12
      engine/compilers/BundleCompiler.cpp

+ 10 - 12
engine/compilers/BundleCompiler.cpp

@@ -59,28 +59,26 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir)
 	// Compile all resources
 	for (uint32_t i = 0; i < files.size(); i++)
 	{
-		DynamicString& filename = files[i];
+		const char* filename = files[i].c_str();
+		uint64_t filename_hash = hash::murmur2_64(filename, string::strlen(filename), 0);
 
-		char resource_name[1024];
-		char resource_type[1024];
-		path::filename_without_extension(filename.c_str(), resource_name, 1024);
-		path::extension(filename.c_str(), resource_type, 1024);
+		char filename_extension[32];
+		path::extension(filename, filename_extension, 32);
+		uint32_t resource_type_hash = hash::murmur2_32(filename_extension, string::strlen(filename_extension), 0);
 
-		uint32_t resource_name_hash = hash::murmur2_32(resource_name, string::strlen(resource_name), 0);
-		uint32_t resource_type_hash = hash::murmur2_32(resource_type, string::strlen(resource_type), 0);
+		char out_name[65];
+		snprintf(out_name, 65, "%.16llx", filename_hash);
 
-		char out_name[1024];
-		snprintf(out_name, 1024, "%.8X%.8X", resource_name_hash, resource_type_hash);
-		Log::i("%s <= %s", out_name, filename.c_str());
+		Log::i("%s <= %s", out_name, filename);
 
 		bool result = false;
 		if (resource_type_hash == TEXTURE_TYPE)
 		{
-			result = m_tga.compile(source_dir, bundle_dir, filename.c_str(), out_name);
+			result = m_tga.compile(source_dir, bundle_dir, filename, out_name);
 		}
 		else if (resource_type_hash == LUA_TYPE)
 		{
-			result = m_lua.compile(source_dir, bundle_dir, filename.c_str(), out_name);
+			result = m_lua.compile(source_dir, bundle_dir, filename, out_name);
 		}
 		else
 		{