Răsfoiți Sursa

Fix TGA resource compilation

Daniele Bartolini 12 ani în urmă
părinte
comite
e78e25f5df
3 a modificat fișierele cu 24 adăugiri și 6 ștergeri
  1. 18 1
      tools/cli/resource-compiler.cpp
  2. 5 4
      tools/compilers/Compiler.cpp
  3. 1 1
      tools/compilers/Compiler.h

+ 18 - 1
tools/cli/resource-compiler.cpp

@@ -62,12 +62,29 @@ int main(int argc, char** argv)
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
 	}
 	}
 
 
+
 	TGACompiler tga;
 	TGACompiler tga;
 	// TXTCompiler txt(root_path, dest_path);
 	// TXTCompiler txt(root_path, dest_path);
 	// VSCompiler vs(root_path, dest_path);
 	// VSCompiler vs(root_path, dest_path);
 	// PSCompiler ps(root_path, dest_path);
 	// PSCompiler ps(root_path, dest_path);
 
 
-	tga.compile(root_path, dest_path, argv[first_resource]);
+	char out_name[1024];
+	char resource_name[1024];
+	char resource_type[1024];
+
+	for (int32_t i = 0; i < argc - first_resource; i++)
+	{
+		path::filename_without_extension(argv[first_resource + i], resource_name, 1024);
+		path::extension(argv[first_resource + i], resource_type, 1024);
+
+		snprintf(out_name, 1024, "%.8X%.8X",
+			hash::murmur2_32(resource_name, string::strlen(resource_name), hash_seed),
+			hash::murmur2_32(resource_type, string::strlen(resource_type), 0));
+
+		printf("%s <= %s\n", out_name, argv[first_resource + i]);
+
+		tga.compile(root_path, dest_path, argv[first_resource + i], out_name);
+	}
 
 
 	return 0;
 	return 0;
 }
 }

+ 5 - 4
tools/compilers/Compiler.cpp

@@ -35,13 +35,14 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-size_t Compiler::compile(const char* root_path, const char* dest_path, const char* resource)
+size_t Compiler::compile(const char* root_path, const char* dest_path, const char* name_in, const char* name_out)
 {
 {
-	std::string resource_path = std::string(root_path) + "/" + std::string(resource);
+	std::string path_in = std::string(root_path) + "/" + std::string(name_in);
+	std::string path_out = std::string(dest_path) + "/" + std::string(name_out);
 
 
 	// The compilation fails when returned size is zero
 	// The compilation fails when returned size is zero
 	size_t resource_size = 0;
 	size_t resource_size = 0;
-	if ((resource_size = compile_impl(resource_path.c_str())) == 0)
+	if ((resource_size = compile_impl(path_in.c_str())) == 0)
 	{
 	{
 		std::cout << "Compilation failed." << std::endl;
 		std::cout << "Compilation failed." << std::endl;
 		return 0;
 		return 0;
@@ -55,7 +56,7 @@ size_t Compiler::compile(const char* root_path, const char* dest_path, const cha
 
 
 	// Open destination file and write the header
 	// Open destination file and write the header
 	std::fstream out_file;
 	std::fstream out_file;
-	out_file.open("out.raw", std::fstream::out | std::fstream::binary);
+	out_file.open(path_out.c_str(), std::fstream::out | std::fstream::binary);
 
 
 	if (!out_file.is_open())
 	if (!out_file.is_open())
 	{
 	{

+ 1 - 1
tools/compilers/Compiler.h

@@ -42,7 +42,7 @@ public:
 
 
 	virtual					~Compiler() {}
 	virtual					~Compiler() {}
 
 
-	size_t					compile(const char* root_path, const char* dest_path, const char* resource);
+	size_t					compile(const char* root_path, const char* dest_path, const char* name_in, const char* name_out);
 	void					cleanup();
 	void					cleanup();
 
 
 protected:
 protected: