Parcourir la source

Simplify resource folder

Daniele Bartolini il y a 12 ans
Parent
commit
d2e831c7f7

+ 0 - 5
engine/Android.mk

@@ -86,14 +86,9 @@ LOCAL_SRC_FILES :=\
 \
 	resource/ArchiveBundle.cpp\
 	resource/FileBundle.cpp\
-	resource/FontResource.cpp\
-	resource/MaterialResource.cpp\
-	resource/MeshResource.cpp\
 	resource/ResourceLoader.cpp\
 	resource/ResourceManager.cpp\
 	resource/ResourceRegistry.cpp\
-	resource/TextureResource.cpp\
-	resource/SoundResource.cpp\
 \
 	lua/LuaStack.cpp\
 	lua/LuaEnvironment.cpp\

+ 0 - 5
engine/CMakeLists.txt

@@ -271,14 +271,9 @@ set (RENDERERS_HEADERS
 )
 
 set (RESOURCE_SRC
-	resource/MaterialResource.cpp
 	resource/ResourceLoader.cpp
 	resource/ResourceManager.cpp
 	resource/ResourceRegistry.cpp
-	resource/TextureResource.cpp
-	resource/MeshResource.cpp
-	resource/FontResource.cpp
-	resource/SoundResource.cpp
 	resource/ArchiveBundle.cpp
 	resource/FileBundle.cpp
 )

+ 4 - 4
engine/resource/ArchiveBundle.cpp

@@ -42,7 +42,7 @@ ArchiveBundle::ArchiveBundle(Filesystem& fs) :
 	m_entries(NULL)
 {
 	// FIXME Default archive name
-	m_archive_file = (DiskFile*)m_filesystem.open("disk", "archive.bin", FOM_READ);
+	m_archive_file = m_filesystem.open("disk", "archive.bin", FOM_READ);
 	
 	ArchiveHeader header;
 	
@@ -80,7 +80,7 @@ ArchiveBundle::~ArchiveBundle()
 }
 
 //-----------------------------------------------------------------------------
-DiskFile* ArchiveBundle::open(ResourceId name)
+File* ArchiveBundle::open(ResourceId name)
 {
 	// Search the resource in the archive
 	for (uint32_t i = 0; i < m_entries_count; i++)
@@ -90,7 +90,7 @@ DiskFile* ArchiveBundle::open(ResourceId name)
 			// If found, seek to the first byte of the resource data
 			m_archive_file->seek(m_entries[i].offset);
 
-			return (DiskFile*)m_archive_file;
+			return m_archive_file;
 		}
 	}
 
@@ -98,7 +98,7 @@ DiskFile* ArchiveBundle::open(ResourceId name)
 }
 
 //-----------------------------------------------------------------------------
-void ArchiveBundle::close(DiskFile* resource)
+void ArchiveBundle::close(File* resource)
 {
 	// Does nothing, the stream is automatically closed at exit.
 	(void)resource;

+ 3 - 6
engine/resource/ArchiveBundle.h

@@ -64,19 +64,16 @@ public:
 					~ArchiveBundle();
 
 	/// @copydoc Bundle::open()
-	DiskFile*		open(ResourceId name);
+	File*			open(ResourceId name);
 
 	/// @copydoc Bundle::close()
-	void			close(DiskFile* resource);
+	void			close(File* resource);
 
 private:
 
 	HeapAllocator	m_allocator;
-
 	Filesystem&		m_filesystem;
-
-	DiskFile*		m_archive_file;
-
+	File*			m_archive_file;
 	uint32_t		m_entries_count;
 	ArchiveEntry*	m_entries;
 };

+ 3 - 3
engine/resource/Bundle.h

@@ -50,7 +50,7 @@ struct ArchiveEntry
 };
 
 class Filesystem;
-class DiskFile;
+class File;
 
 class Bundle
 {
@@ -64,10 +64,10 @@ public:
 	/// The resource stream points exactly at the start
 	/// of the useful resource data, so you do not have to
 	/// care about skipping headers, metadatas and so on.
-	virtual DiskFile*		open(ResourceId name) = 0;
+	virtual File*		open(ResourceId name) = 0;
 
 	/// Closes the resource file.
-	virtual void			close(DiskFile* resource) = 0;
+	virtual void		close(File* resource) = 0;
 };
 
 } // namespace crown

+ 3 - 3
engine/resource/FileBundle.cpp

@@ -51,7 +51,7 @@ FileBundle::~FileBundle()
 }
 
 //-----------------------------------------------------------------------------
-DiskFile* FileBundle::open(ResourceId name)
+File* FileBundle::open(ResourceId name)
 {
 	// Convert name/type into strings
 	char resource_name[512];
@@ -62,7 +62,7 @@ DiskFile* FileBundle::open(ResourceId name)
 	CE_ASSERT(exists == true, "Resource does not exist: %s", resource_name);
 
 	// Open the resource and check magic number/version
-	DiskFile* file = (DiskFile*)m_filesystem.open(g_default_mountpoint.value(), resource_name, FOM_READ);
+	File* file = m_filesystem.open(g_default_mountpoint.value(), resource_name, FOM_READ);
 
 	ResourceHeader header;
 	file->read(&header, sizeof(ResourceHeader));
@@ -74,7 +74,7 @@ DiskFile* FileBundle::open(ResourceId name)
 }
 
 //-----------------------------------------------------------------------------
-void FileBundle::close(DiskFile* resource)
+void FileBundle::close(File* resource)
 {
 	m_filesystem.close(resource);
 }

+ 2 - 2
engine/resource/FileBundle.h

@@ -57,10 +57,10 @@ public:
 					~FileBundle();
 
 	/// @copydoc Bundle::open()
-	DiskFile*		open(ResourceId name);
+	File*			open(ResourceId name);
 
 	/// @copydoc Bundle::close()
-	void			close(DiskFile* resource);
+	void			close(File* resource);
 
 
 private:

+ 0 - 57
engine/resource/FontResource.cpp

@@ -1,57 +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"
-#include "FontResource.h"
-#include "Bundle.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* FontResource::load(Allocator& /*allocator*/, Bundle& /*bundle*/, ResourceId /*id*/)
-{
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-void FontResource::online(void* resource)
-{
-	(void)resource;
-}
-
-//-----------------------------------------------------------------------------
-void FontResource::unload(Allocator& /*allocator*/, void* /*resource*/)
-{
-}
-
-//-----------------------------------------------------------------------------
-void FontResource::offline(void* /*resource*/)
-{
-}
-
-} // namespace crown
-

+ 23 - 7
engine/resource/FontResource.h

@@ -28,21 +28,37 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Resource.h"
+#include "Bundle.h"
+#include "Allocator.h"
 
 namespace crown
 {
 
-class Allocator;
-class Bundle;
-
 class FontResource
 {
 public:
 
-	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			online(void* resource);
-	static void			offline(void* resource);
+	//-----------------------------------------------------------------------------
+	static void* load(Allocator& /*allocator*/, Bundle& /*bundle*/, ResourceId /*id*/)
+	{
+		return NULL;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void online(void* resource)
+	{
+		(void)resource;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void unload(Allocator& /*allocator*/, void* /*resource*/)
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	static void offline(void* /*resource*/)
+	{
+	}
 
 public:
 

+ 0 - 60
engine/resource/MaterialResource.cpp

@@ -1,60 +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"
-#include "MaterialResource.h"
-#include "Bundle.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* MaterialResource::load(Allocator& /*allocator*/, Bundle& /*bundle*/, ResourceId /*id*/)
-{
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-void MaterialResource::online(void* material)
-{
-	(void)material;
-	// TODO
-}
-
-//-----------------------------------------------------------------------------
-void MaterialResource::unload(Allocator& /*allocator*/, void* /*material*/)
-{
-	// TODO
-}
-
-//-----------------------------------------------------------------------------
-void MaterialResource::offline(void* /*resource*/)
-{
-	// TODO
-}
-
-} // namespace crown
-

+ 26 - 6
engine/resource/MaterialResource.h

@@ -33,6 +33,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Color4.h"
 #include "Material.h"
 #include "Texture.h"
+#include "Bundle.h"
+#include "Allocator.h"
 
 namespace crown
 {
@@ -41,8 +43,6 @@ namespace crown
 /// @note The maximum number of usable layers depends on the graphic card/Renderer config.
 const uint32_t MAX_TEXTURE_LAYERS = 8;
 
-class Bundle;
-class Allocator;
 
 /// A material describes the visual properties of a surface.
 /// It is primarly intended for rendering purposes but can
@@ -51,10 +51,30 @@ class MaterialResource
 {
 public:
 
-	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			online(void* resource);
-	static void			offline(void* resource);
+	//-----------------------------------------------------------------------------
+	static void* load(Allocator& /*allocator*/, Bundle& /*bundle*/, ResourceId /*id*/)
+	{
+		return NULL;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void online(void* material)
+	{
+		(void)material;
+		// TODO
+	}
+
+	//-----------------------------------------------------------------------------
+	static void unload(Allocator& /*allocator*/, void* /*material*/)
+	{
+		// TODO
+	}
+
+	//-----------------------------------------------------------------------------
+	static void offline(void* /*resource*/)
+	{
+		// TODO
+	}
 
 private:
 

+ 0 - 80
engine/resource/MeshResource.cpp

@@ -1,80 +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 "MeshResource.h"
-#include "Bundle.h"
-#include "Log.h"
-#include "DiskFile.h"
-#include "Assert.h"
-#include "Allocator.h"
-#include "Device.h"
-#include "Renderer.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* MeshResource::load(Allocator& allocator, Bundle& bundle, ResourceId id)
-{
-	DiskFile* file = bundle.open(id);
-
-	CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
-
-	MeshResource* resource = (MeshResource*)allocator.allocate(sizeof(MeshResource));
-	file->read(&resource->m_header, sizeof(MeshHeader));
-
-	// Read vertices
-	file->read(&resource->m_vertex_count, sizeof(uint32_t));
-	resource->m_vertices = (float*) allocator.allocate(sizeof(float) * resource->m_vertex_count);
-	file->read(resource->m_vertices, sizeof(float) * resource->m_vertex_count);
-
-	// Read triangles
-	file->read(&resource->m_index_count, sizeof(uint32_t));
-	resource->m_indices = (uint16_t*) allocator.allocate(sizeof(uint16_t) * resource->m_index_count);
-	file->read(resource->m_indices, sizeof(uint16_t) * resource->m_index_count);
-
-	bundle.close(file);
-
-	return resource;
-}
-
-//-----------------------------------------------------------------------------
-void MeshResource::online(void* )
-{
-}
-
-//-----------------------------------------------------------------------------
-void MeshResource::unload(Allocator& , void* )
-{
-}
-
-//-----------------------------------------------------------------------------
-void MeshResource::offline(void* /*resource*/)
-{
-
-}
-
-} // namespace crown

+ 42 - 7
engine/resource/MeshResource.h

@@ -30,6 +30,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Resource.h"
 #include "PixelFormat.h"
 #include "Texture.h"
+#include "Allocator.h"
+#include "Bundle.h"
 
 namespace crown
 {
@@ -45,17 +47,50 @@ struct MeshHeader
 	uint32_t	padding[16];
 };
 
-class Bundle;
-class Allocator;
-
 class MeshResource
 {
 public:
 
-	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			online(void* resource);
-	static void			offline(void* resource);
+	//-----------------------------------------------------------------------------
+	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
+	{
+		File* file = bundle.open(id);
+
+		CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
+
+		MeshResource* resource = (MeshResource*)allocator.allocate(sizeof(MeshResource));
+		file->read(&resource->m_header, sizeof(MeshHeader));
+
+		// Read vertices
+		file->read(&resource->m_vertex_count, sizeof(uint32_t));
+		resource->m_vertices = (float*) allocator.allocate(sizeof(float) * resource->m_vertex_count);
+		file->read(resource->m_vertices, sizeof(float) * resource->m_vertex_count);
+
+		// Read triangles
+		file->read(&resource->m_index_count, sizeof(uint32_t));
+		resource->m_indices = (uint16_t*) allocator.allocate(sizeof(uint16_t) * resource->m_index_count);
+		file->read(resource->m_indices, sizeof(uint16_t) * resource->m_index_count);
+
+		bundle.close(file);
+
+		return resource;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void online(void* )
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	static void unload(Allocator& , void* )
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	static void offline(void* /*resource*/)
+	{
+
+	}
 
 public:
 

+ 0 - 81
engine/resource/SoundResource.cpp

@@ -1,81 +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 "SoundResource.h"
-#include "Bundle.h"
-#include "Log.h"
-#include "DiskFile.h"
-#include "Assert.h"
-#include "Allocator.h"
-#include "Device.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* SoundResource::load(Allocator& allocator, Bundle& bundle, ResourceId id)
-{
-	DiskFile* file = bundle.open(id);
-
-	CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
-
-	SoundResource* resource = (SoundResource*)allocator.allocate(sizeof(SoundResource));
-
-	file->read(&resource->m_header, sizeof(SoundHeader));
-
-	size_t size = resource->size();
-
-	resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
-
-	file->read(resource->m_data, size);
-
-	bundle.close(file);
-
-	return resource;
-}
-
-//-----------------------------------------------------------------------------
-void SoundResource::online(void* resource)
-{
-	CE_ASSERT(resource != NULL, "Resource not loaded");
-}
-
-//-----------------------------------------------------------------------------
-void SoundResource::unload(Allocator& allocator, void* resource)
-{
-	CE_ASSERT(resource != NULL, "Resource not loaded");
-
-	allocator.deallocate(((SoundResource*)resource)->m_data);
-	allocator.deallocate(resource);
-}
-
-//-----------------------------------------------------------------------------
-void SoundResource::offline(void* /*resource*/)
-{
-
-}
-
-} // namespace crown

+ 44 - 7
engine/resource/SoundResource.h

@@ -28,6 +28,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Resource.h"
+#include "Bundle.h"
+#include "Allocator.h"
 
 namespace crown
 {
@@ -42,17 +44,52 @@ struct SoundHeader
 	uint32_t 	bits_per_sample;
 };
 
-class Bundle;
-class Allocator;
-
 class SoundResource
 {
 public:
 
-	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			online(void* resource);
-	static void			offline(void* resource);
+	//-----------------------------------------------------------------------------
+	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
+	{
+		File* file = bundle.open(id);
+
+		CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
+
+		SoundResource* resource = (SoundResource*)allocator.allocate(sizeof(SoundResource));
+
+		file->read(&resource->m_header, sizeof(SoundHeader));
+
+		size_t size = resource->size();
+
+		resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
+
+		file->read(resource->m_data, size);
+
+		bundle.close(file);
+
+		return resource;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void online(void* resource)
+	{
+		CE_ASSERT(resource != NULL, "Resource not loaded");
+	}
+
+	//-----------------------------------------------------------------------------
+	static void unload(Allocator& allocator, void* resource)
+	{
+		CE_ASSERT(resource != NULL, "Resource not loaded");
+
+		allocator.deallocate(((SoundResource*)resource)->m_data);
+		allocator.deallocate(resource);
+	}
+
+	//-----------------------------------------------------------------------------
+	static void offline(void* /*resource*/)
+	{
+
+	}
 
 public:
 

+ 0 - 82
engine/resource/TextureResource.cpp

@@ -1,82 +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 "TextureResource.h"
-#include "Bundle.h"
-#include "Log.h"
-#include "DiskFile.h"
-#include "Assert.h"
-#include "Allocator.h"
-#include "Device.h"
-#include "Renderer.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* TextureResource::load(Allocator& allocator, Bundle& bundle, ResourceId id)
-{
-	DiskFile* file = bundle.open(id);
-
-	CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
-
-	TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
-
-	file->read(&resource->m_header, sizeof(TextureHeader));
-
-	size_t size = resource->width() * resource->height() * Pixel::bytes_per_pixel(resource->format());
-
-	resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
-
-	file->read(resource->m_data, size);
-
-	bundle.close(file);
-
-	return resource;
-}
-
-//-----------------------------------------------------------------------------
-void TextureResource::online(void* resource)
-{
-	CE_ASSERT(resource != NULL, "Resource not loaded");
-}
-
-//-----------------------------------------------------------------------------
-void TextureResource::unload(Allocator& allocator, void* resource)
-{
-	CE_ASSERT(resource != NULL, "Resource not loaded");
-
-	allocator.deallocate(((TextureResource*)resource)->m_data);
-	allocator.deallocate(resource);
-}
-
-//-----------------------------------------------------------------------------
-void TextureResource::offline(void* /*resource*/)
-{
-
-}
-
-} // namespace crown

+ 64 - 11
engine/resource/TextureResource.h

@@ -30,6 +30,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Resource.h"
 #include "PixelFormat.h"
 #include "Texture.h"
+#include "Bundle.h"
+#include "Allocator.h"
+#include "File.h"
 
 namespace crown
 {
@@ -45,24 +48,74 @@ struct TextureHeader
 	uint32_t	height;		// Height in pixels
 };
 
-class Bundle;
-class Allocator;
-
 class TextureResource
 {
 public:
 
-	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			online(void* resource);
-	static void			offline(void* resource);
+	//-----------------------------------------------------------------------------
+	static void* load(Allocator& allocator, Bundle& bundle, ResourceId id)
+	{
+		File* file = bundle.open(id);
+
+		CE_ASSERT(file != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
+
+		TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
+
+		file->read(&resource->m_header, sizeof(TextureHeader));
+
+		size_t size = resource->width() * resource->height() * Pixel::bytes_per_pixel(resource->format());
+
+		resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
+
+		file->read(resource->m_data, size);
+
+		bundle.close(file);
+
+		return resource;
+	}
+
+	//-----------------------------------------------------------------------------
+	static void online(void* resource)
+	{
+		CE_ASSERT(resource != NULL, "Resource not loaded");
+	}
+
+	//-----------------------------------------------------------------------------
+	static void unload(Allocator& allocator, void* resource)
+	{
+		CE_ASSERT(resource != NULL, "Resource not loaded");
+
+		allocator.deallocate(((TextureResource*)resource)->m_data);
+		allocator.deallocate(resource);
+	}
+
+	//-----------------------------------------------------------------------------
+	static void offline(void* /*resource*/)
+	{
+
+	}
 
 public:
 
-	PixelFormat			format() const { return (PixelFormat) m_header.format; }
-	uint32_t			width() const { return m_header.width; }
-	uint32_t			height() const { return m_header.height; }
-	const uint8_t*		data() const { return m_data; }
+	PixelFormat format() const
+	{
+		return (PixelFormat) m_header.format;
+	}
+
+	uint32_t width() const
+	{
+		return m_header.width;
+	}
+
+	uint32_t height() const
+	{
+		return m_header.height;
+	}
+
+	const uint8_t* data() const
+	{
+		return m_data;
+	}
 
 private: