Răsfoiți Sursa

Add magic number and version number to compiled resource files

Daniele Bartolini 12 ani în urmă
părinte
comite
13271b2fd4

+ 1 - 2
src/FileResourceArchive.cpp

@@ -62,8 +62,7 @@ FileStream* FileResourceArchive::find(ResourceId name)
 
 	FileStream* file = (FileStream*)m_filesystem.open(resource_name, SOM_READ);
 
-	/// FIXME harcoded!!!
-	file->skip(sizeof(uint32_t) * 3);
+	file->skip(sizeof(ResourceHeader));
 
 	return file;
 

+ 11 - 0
src/FileResourceArchive.h

@@ -34,6 +34,17 @@ namespace crown
 class Filesystem;
 class FileStream;
 
+// The header of every compiled resource file.
+// KEEP IN SYNC WITH CompiledResource struct in Compiler.h!
+struct ResourceHeader
+{
+	uint32_t	magic;		// Magic number used to identify the file
+	uint32_t	version;	// Version of the compiler used to compile the resource
+	uint32_t	name;		// Name of the resource (murmur2_32 hash)
+	uint32_t	type;		// Type of the resource (murmur2_32 hash)
+	uint32_t	size;		// Size of the resource data _not_ including header (in bytes)
+};
+
 /// Source of resources
 class FileResourceArchive : public ResourceArchive
 {

+ 2 - 0
tools/compilers/Compiler.cpp

@@ -171,6 +171,8 @@ FileStream* Compiler::destination_file()
 //-----------------------------------------------------------------------------
 void Compiler::prepare_header(uint32_t size)
 {
+	m_compiled_header.magic = COMPILED_HEADER_MAGIC_NUMBER;
+	m_compiled_header.version = COMPILER_VERSION;
 	m_compiled_header.name = m_name_hash;
 	m_compiled_header.type = m_type_hash;
 	m_compiled_header.size = size;

+ 11 - 6
tools/compilers/Compiler.h

@@ -31,18 +31,23 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-const size_t MAX_RESOURCE_NAME_LENGTH = 1024;
-const size_t MAX_RESOURCE_TYPE_LENGTH = 64;
-const size_t MAX_RESOURCE_PATH_LENGTH = 1024;
+const size_t	MAX_RESOURCE_NAME_LENGTH			= 1024;
+const size_t	MAX_RESOURCE_TYPE_LENGTH			= 64;
+const size_t	MAX_RESOURCE_PATH_LENGTH			= 1024;
+
+const uint32_t	COMPILED_HEADER_MAGIC_NUMBER		= 0xCE010101;
+const uint32_t	COMPILER_VERSION					= 1;
 
 /// Contains the header data common to all
 /// types of resources passing through the
 /// standard Compiler mechanics.
 struct CompiledHeader
 {
-	uint32_t	name;	// Name of the resource (murmur2_32 hash)
-	uint32_t	type;	// Type of the resource (murmur2_32 hash)
-	uint32_t	size;	// Size of the resource data _not_ including header (in bytes)
+	uint32_t	magic;		// Magic number used to identify the file
+	uint32_t	version;	// Version of the compiler used to compile the resource
+	uint32_t	name;		// Name of the resource (murmur2_32 hash)
+	uint32_t	type;		// Type of the resource (murmur2_32 hash)
+	uint32_t	size;		// Size of the resource data _not_ including header (in bytes)
 };
 
 class FileStream;

+ 4 - 0
tools/compilers/resource-linker.cpp

@@ -13,6 +13,10 @@ using namespace crown;
 
 /// Resource linker links together individual compiled resources into a
 /// single binary blob ready to be loaded by Crown Engine.
+/// Usage: resource-linker <root-path> [resource1, resource2, ..., resourceN]
+/// The resources are put into the archive in the order they appear in the command line.
+/// This allows to simplify the code and to decouple the linking process from the
+/// placement optimization of the resources in the final archive.
 int main(int argc, char** argv)
 {
 	//-------------------------------------------------------------------------

+ 1 - 1
tools/compilers/tga/TGACompiler.cpp

@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "TGACompiler.h"
 #include "FileStream.h"
-#include "Pixel.h"
+#include "PixelFormat.h"
 #include "Resource.h"
 
 namespace crown

+ 1 - 1
tools/compilers/tga/TGACompiler.h

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Compiler.h"
 #include "FileStream.h"
-#include "Pixel.h"
+#include "PixelFormat.h"
 
 namespace crown
 {