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

Remove common header from compiled resources

Daniele Bartolini 12 лет назад
Родитель
Сommit
79af738239

+ 2 - 14
engine/compilers/Compiler.cpp

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Compiler.h"
 #include "Filesystem.h"
 #include "DiskFilesystem.h"
-#include "ResourceFormat.h"
 #include "File.h"
 #include "Log.h"
 
@@ -48,25 +47,14 @@ bool Compiler::compile(const char* root_path, const char* dest_path, const char*
 		return false;
 	}
 
-	// Setup resource header
-	ResourceHeader resource_header;
-	resource_header.magic = RESOURCE_MAGIC_NUMBER;
-	resource_header.version = RESOURCE_VERSION;
-	resource_header.size = resource_size;
-
-	// Open destination file and write the header
+	// Open destination file
 	File* out_file = dest_fs.open(name_out, FOM_WRITE);
 
 	if (out_file)
 	{
-		// Write header
-		out_file->write((char*)&resource_header, sizeof(ResourceHeader));
-
-		// Write resource-specific data
+		// Write data
 		write_impl(out_file);
-
 		dest_fs.close(out_file);
-
 		cleanup();
 		return true;
 	}

+ 0 - 24
engine/resource/FileBundle.cpp

@@ -38,19 +38,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-const uint32_t	RESOURCE_MAGIC_NUMBER		= 0xCE010101;
-const uint32_t	RESOURCE_VERSION			= 2;
-
-/// Contains the header data common to all
-/// types of resources passing through the
-/// standard Compiler mechanics.
-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	size;		// Size of the resource data _not_ including this header in bytes
-};
-
 class FileBundle : public Bundle
 {
 public:
@@ -65,22 +52,11 @@ public:
 		// Convert name/type into strings
 		char resource_name[512];
 		snprintf(resource_name, 512, "%.16"PRIx64"", name.id);
-		
-		// Search the resource in the filesystem
-		// bool exists = m_filesystem.exists(resource_name);
-		// CE_ASSERT(exists == true, "Resource does not exist: %s", resource_name);
 
 		// Open the resource and check magic number/version
 		File* file = m_filesystem.open(resource_name, FOM_READ);
 
 		CE_ASSERT(file != NULL, "Resource %s does not exist", resource_name);
-
-		ResourceHeader header;
-		file->read(&header, sizeof(ResourceHeader));
-
-		CE_ASSERT(header.magic == RESOURCE_MAGIC_NUMBER, "Resource is not valid: %s", resource_name);
-		CE_ASSERT(header.version == RESOURCE_VERSION, "Resource version mismatch: %s", resource_name);
-
 		return file;
 	}
 

+ 1 - 1
engine/resource/LuaResource.h

@@ -50,7 +50,7 @@ struct LuaResource
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 1 - 1
engine/resource/MeshResource.h

@@ -78,7 +78,7 @@ public:
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 1 - 1
engine/resource/PackageResource.h

@@ -58,7 +58,7 @@ struct PackageResource
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 0 - 53
engine/resource/ResourceFormat.h

@@ -1,53 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Types.h"
-
-namespace crown
-{
-
-const uint32_t	RESOURCE_MAGIC_NUMBER		= 0xCE010101;
-const uint32_t	RESOURCE_VERSION			= 2;
-
-/// Contains the header data common to all
-/// types of resources passing through the
-/// standard Compiler mechanics.
-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	size;		// Size of the resource data _not_ including this header in bytes
-};
-
-// Resource format:
-//
-// [ResourceHeader]
-// [ResourceData]
-//
-// The ResourceHeader is common to all resource types.
-// Every resource appends its data after the resource header.
-
-} // namespace crown

+ 1 - 1
engine/resource/SoundResource.h

@@ -71,7 +71,7 @@ public:
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 1 - 1
engine/resource/SpriteResource.h

@@ -69,7 +69,7 @@ struct SpriteResource
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 1 - 1
engine/resource/TextureResource.h

@@ -56,7 +56,7 @@ struct TextureResource
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);

+ 1 - 1
engine/resource/UnitResource.h

@@ -79,7 +79,7 @@ struct UnitResource
 	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
 	{
 		File* file = bundle.open(id);
-		const size_t file_size = file->size() - 12;
+		const size_t file_size = file->size();
 
 		void* res = allocator.allocate(file_size);
 		file->read(res, file_size);