Browse Source

Rework resource callbacks a bit

Daniele Bartolini 12 năm trước cách đây
mục cha
commit
cbec56057d

+ 3 - 3
src/MaterialResource.cpp

@@ -30,7 +30,7 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-MaterialResource* MaterialResource::load(Allocator& allocator, ResourceArchive* archive, ResourceId id)
+void* MaterialResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
 {
 {
 	(void)allocator;
 	(void)allocator;
 	(void)archive;
 	(void)archive;
@@ -41,14 +41,14 @@ MaterialResource* MaterialResource::load(Allocator& allocator, ResourceArchive*
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void MaterialResource::online(MaterialResource* material)
+void MaterialResource::online(void* material)
 {
 {
 	(void)material;
 	(void)material;
 	// TODO
 	// TODO
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void MaterialResource::unload(Allocator& allocator, MaterialResource* material)
+void MaterialResource::unload(Allocator& allocator, void* material)
 {
 {
 	(void)allocator;
 	(void)allocator;
 	(void)material;
 	(void)material;

+ 4 - 4
src/MaterialResource.h

@@ -50,10 +50,10 @@ class MaterialResource
 {
 {
 public:
 public:
 
 
-	static MaterialResource*	load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
-	static void					online(MaterialResource* texture);
-	static void					unload(Allocator& allocator, MaterialResource* texture);
-	static void					offline();
+	static void*	load(Allocator& allocator, ResourceArchive& archive, ResourceId id);
+	static void		online(void* resource);
+	static void		unload(Allocator& allocator, void* texture);
+	static void		offline();
 
 
 private:
 private:
 
 

+ 2 - 2
src/ResourceLoader.cpp

@@ -114,11 +114,11 @@ void* ResourceLoader::load_by_type(ResourceId name) const
 	}
 	}
 	else if (name.type == m_texture_hash)
 	else if (name.type == m_texture_hash)
 	{
 	{
-		return TextureResource::load(m_resource_allocator, &m_resource_archive, name);
+		return TextureResource::load(m_resource_allocator, m_resource_archive, name);
 	}
 	}
 	else if (name.type == m_txt_hash)
 	else if (name.type == m_txt_hash)
 	{
 	{
-		return TextResource::load(m_resource_allocator, &m_resource_archive, name);
+		return TextResource::load(m_resource_allocator, m_resource_archive, name);
 	}
 	}
 
 
 	return NULL;
 	return NULL;

+ 7 - 9
src/TextResource.cpp

@@ -8,11 +8,9 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-TextResource* TextResource::load(Allocator& allocator, ResourceArchive* archive, ResourceId id)
+void* TextResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
 {
 {
-	assert(archive != NULL);
-	
-	FileStream* stream = archive->find(id);
+	FileStream* stream = archive.find(id);
 
 
 	if (stream != NULL)
 	if (stream != NULL)
 	{
 	{
@@ -33,14 +31,14 @@ TextResource* TextResource::load(Allocator& allocator, ResourceArchive* archive,
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void TextResource::unload(Allocator& allocator, TextResource* text)
+void TextResource::unload(Allocator& allocator, void* resource)
 {
 {
-	assert(text != NULL);
+	assert(resource != NULL);
 
 
-	text->length = 0;
+	((TextResource*)resource)->length = 0;
 
 
-	allocator.deallocate(text->data);
-	allocator.deallocate(text);
+	allocator.deallocate(((TextResource*)resource)->data);
+	allocator.deallocate(resource);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 4 - 4
src/TextResource.h

@@ -13,11 +13,11 @@ class TextResource
 {
 {
 public:
 public:
 
 
-	static TextResource*		load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
-	static void					unload(Allocator& allocator, TextResource* text);
+	static void*		load(Allocator& allocator, ResourceArchive& archive, ResourceId id);
+	static void			unload(Allocator& allocator, void* resource);
 
 
-	uint32_t					length;
-	char*						data;
+	uint32_t			length;
+	char*				data;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 7 - 9
src/TextureResource.cpp

@@ -11,11 +11,9 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-TextureResource* TextureResource::load(Allocator& allocator, ResourceArchive* archive, ResourceId id)
+void* TextureResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
 {
 {
-	assert(archive != NULL);
-	
-	FileStream* stream = archive->find(id);
+	FileStream* stream = archive.find(id);
 
 
 	if (stream != NULL)
 	if (stream != NULL)
 	{
 	{
@@ -38,19 +36,19 @@ TextureResource* TextureResource::load(Allocator& allocator, ResourceArchive* ar
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void TextureResource::online(TextureResource* texture)
+void TextureResource::online(void* resource)
 {
 {
-	assert(texture != NULL);
+	assert(resource != NULL);
 
 
-	texture->m_render_texture = device()->renderer()->load_texture(texture);
+	((TextureResource*)resource)->m_render_texture = device()->renderer()->load_texture((TextureResource*)resource);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void TextureResource::unload(Allocator& allocator, TextureResource* resource)
+void TextureResource::unload(Allocator& allocator, void* resource)
 {
 {
 	assert(resource != NULL);
 	assert(resource != NULL);
 
 
-	allocator.deallocate(resource->m_data);
+	allocator.deallocate(((TextureResource*)resource)->m_data);
 	allocator.deallocate(resource);
 	allocator.deallocate(resource);
 }
 }
 
 

+ 13 - 13
src/TextureResource.h

@@ -40,28 +40,28 @@ class TextureResource
 {
 {
 public:
 public:
 
 
-	static TextureResource*		load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
-	static void					online(TextureResource* texture);
-	static void					unload(Allocator& allocator, TextureResource* texture);
-	static void					offline();
+	static void*		load(Allocator& allocator, ResourceArchive& archive, ResourceId id);
+	static void			online(void* texture);
+	static void			unload(Allocator& allocator, void* resource);
+	static void			offline();
 
 
 public:
 public:
 
 
-	PixelFormat					format() const { return m_format; }
-	uint16_t					width() const { return m_width; }
-	uint16_t					height() const { return m_height; }
-	const uint8_t*				data() const { return m_data; }
+	PixelFormat			format() const { return m_format; }
+	uint16_t			width() const { return m_width; }
+	uint16_t			height() const { return m_height; }
+	const uint8_t*		data() const { return m_data; }
 
 
 private:
 private:
 
 
-	PixelFormat					m_format;
-	uint16_t					m_width;
-	uint16_t					m_height;
-	uint8_t*					m_data;
+	PixelFormat			m_format;
+	uint16_t			m_width;
+	uint16_t			m_height;
+	uint8_t*			m_data;
 
 
 public:
 public:
 
 
-	TextureId					m_render_texture;
+	TextureId			m_render_texture;
 };
 };
 
 
 } // namespace crown
 } // namespace crown