Explorar o código

Rework ResourceManger a bit

Daniele Bartolini %!s(int64=13) %!d(string=hai) anos
pai
achega
aed0967949
Modificáronse 2 ficheiros con 66 adicións e 3 borrados
  1. 36 2
      src/ResourceLoader.cpp
  2. 30 1
      src/ResourceLoader.h

+ 36 - 2
src/ResourceLoader.cpp

@@ -1,3 +1,28 @@
+/*
+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 "ResourceLoader.h"
 #include "ResourceManager.h"
 #include "String.h"
@@ -9,8 +34,10 @@
 namespace crown
 {
 
-ResourceLoader::ResourceLoader(ResourceManager* resource_manager) :
+//-----------------------------------------------------------------------------
+ResourceLoader::ResourceLoader(ResourceManager* resource_manager, Filesystem* filesystem) :
 	m_resource_manager(resource_manager),
+	m_filesystem(filesystem),
 	m_resources(m_allocator)
 {
 	m_config_hash = hash::fnv1a_32("config", string::strlen("config"));
@@ -18,10 +45,12 @@ ResourceLoader::ResourceLoader(ResourceManager* resource_manager) :
 	m_mesh_hash = hash::fnv1a_32("mesh", string::strlen("mesh"));
 }
 
+//-----------------------------------------------------------------------------
 ResourceLoader::~ResourceLoader()
 {
 }
 
+//-----------------------------------------------------------------------------
 void ResourceLoader::load(ResourceId name)
 {
 	m_resources.push_back(name);
@@ -30,11 +59,13 @@ void ResourceLoader::load(ResourceId name)
 	m_resource_manager->loading(name);
 }
 
+//-----------------------------------------------------------------------------
 void ResourceLoader::unload(ResourceId name)
 {
 	// do something
 }
 
+//-----------------------------------------------------------------------------
 void ResourceLoader::flush()
 {
 	while (m_resources.size() > 0)
@@ -49,6 +80,7 @@ void ResourceLoader::flush()
 	}
 }
 
+//-----------------------------------------------------------------------------
 void* ResourceLoader::load_by_type(ResourceId name)
 {
 	if (name.name == m_config_hash)
@@ -58,8 +90,10 @@ void* ResourceLoader::load_by_type(ResourceId name)
 
 	if (name.name == m_texture_hash)
 	{
-		return TextureResource::load(NULL);
+		return TextureResource::load(&m_resource_archive, name.name);
 	}
+	
+	return NULL;
 }
 
 } // namespace crown

+ 30 - 1
src/ResourceLoader.h

@@ -1,3 +1,28 @@
+/*
+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.
+*/
+
 #pragma once
 
 #include "Queue.h"
@@ -9,12 +34,13 @@ namespace crown
 {
 
 class ResourceManager;
+class Filesystem;
 
 class ResourceLoader
 {
 public:
 
-						ResourceLoader(ResourceManager* resource_manager);
+						ResourceLoader(ResourceManager* resource_manager, Filesystem* filesystem);
 						~ResourceLoader();
 
 	void				load(ResourceId name);
@@ -29,8 +55,11 @@ private:
 private:
 
 	ResourceManager*	m_resource_manager;
+	Filesystem*			m_filesystem;
+
 	ResourceArchive		m_resource_archive;
 	MallocAllocator		m_allocator;
+
 	Queue<ResourceId>	m_resources;
 	
 	uint32_t			m_config_hash;