Explorar el Código

Delete ResourceLoader

Daniele Bartolini hace 13 años
padre
commit
d69999a8e8
Se han modificado 2 ficheros con 0 adiciones y 246 borrados
  1. 0 156
      src/ResourceLoader.cpp
  2. 0 90
      src/ResourceLoader.h

+ 0 - 156
src/ResourceLoader.cpp

@@ -1,156 +0,0 @@
-/*
-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 "ResourceArchive.h"
-#include "String.h"
-#include "Hash.h"
-#include "TextureResource.h"
-#include "TextResource.h"
-#include "Log.h"
-#include <stdio.h>
-#include <unistd.h>
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-ResourceLoader::ResourceLoader(Allocator& resource_allocator, ResourceArchive& archive) :
-	m_resource_allocator(resource_allocator),
-	m_resource_archive(archive),
-	m_waiting_resources(m_allocator),
-	m_loaded_resources(m_allocator),
-	m_thread(ResourceLoader::background_thread, (void*)this, "resource-loader-thread")
-{
-	// FIXME hardcoded seed
-	m_config_hash = hash::murmur2_32("config", string::strlen("config"), 0);
-	m_texture_hash = hash::murmur2_32("tga", string::strlen("tga"), 0);
-	m_mesh_hash = hash::murmur2_32("mesh", string::strlen("mesh"), 0);
-	m_txt_hash = hash::murmur2_32("txt", 3, 0);
-}
-
-//-----------------------------------------------------------------------------
-ResourceLoader::~ResourceLoader()
-{
-}
-
-//-----------------------------------------------------------------------------
-void ResourceLoader::load(ResourceId name)
-{
-	m_waiting_mutex.lock();
-
-	m_waiting_resources.push_back(name);
-
-	m_waiting_mutex.unlock();
-}
-
-//-----------------------------------------------------------------------------
-void ResourceLoader::unload(ResourceId name, void* resource)
-{
-	unload_by_type(name, resource);
-}
-
-//-----------------------------------------------------------------------------
-void ResourceLoader::background_load()
-{
-	// FIXME: Maybe epic crash because of concurrent access to the same allocator?
-	while (true)
-	{
-		if (m_waiting_resources.size() > 0)
-		{
-			m_waiting_mutex.lock();
-
-			ResourceId resource = m_waiting_resources.front();
-			m_waiting_resources.pop_front();
-
-			m_waiting_mutex.unlock();
-
-			void* data = load_by_type(resource);
-
-			LoadedResource lr;
-			lr.resource = resource;
-			lr.data = data;
-
-			m_loaded_mutex.lock();
-
-			m_loaded_resources.push_back(lr);
-
-			m_loaded_mutex.unlock();
-			
-			m_waiting_mutex.unlock();
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-void* ResourceLoader::load_by_type(ResourceId name) const
-{
-	if (name.type == m_config_hash)
-	{
-		return NULL;
-	}
-	else if (name.type == m_texture_hash)
-	{
-		return TextureResource::load(m_resource_allocator, &m_resource_archive, name);
-	}
-	else if (name.type == m_txt_hash)
-	{
-		return TextResource::load(m_resource_allocator, &m_resource_archive, name);
-	}
-
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-void ResourceLoader::unload_by_type(ResourceId name, void* resource) const
-{
-	if (name.type == m_config_hash)
-	{
-		return;
-	}
-
-	if (name.type == m_texture_hash)
-	{
-		TextureResource::unload(m_resource_allocator, (TextureResource*)resource);
-	}
-
-	if (name.type == m_txt_hash)
-	{
-		TextResource::unload(m_resource_allocator, (TextResource*)resource);
-	}
-
-	return;
-}
-
-//-----------------------------------------------------------------------------
-void* ResourceLoader::background_thread(void* thiz)
-{
-	ResourceLoader* loader = (ResourceLoader*)thiz;
-
-	loader->background_load();
-}
-
-} // namespace crown

+ 0 - 90
src/ResourceLoader.h

@@ -1,90 +0,0 @@
-/*
-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"
-#include "Resource.h"
-#include "MallocAllocator.h"
-#include "ResourceManager.h"
-#include "OS.h"
-#include "Thread.h"
-#include "Mutex.h"
-
-namespace crown
-{
-
-class Allocator;
-class ResourceArchive;
-
-struct LoadedResource
-{
-	ResourceId	resource;
-	void*		data;
-};
-
-class ResourceLoader
-{
-public:
-
-						ResourceLoader(Allocator& resource_allocator, ResourceArchive& archive);
-						~ResourceLoader();
-
-	void				load(ResourceId name);
-	void				unload(ResourceId name, void* resource);
-
-private:
-
-	void				background_load();
-	void*				load_by_type(ResourceId name) const;
-	void				unload_by_type(ResourceId name, void* resource) const;
-
-private:
-
-	static void*		background_thread(void* thiz);
-
-private:
-
-	Allocator&			m_resource_allocator;
-	ResourceArchive&	m_resource_archive;
-
-	MallocAllocator		m_allocator;
-
-	Mutex				m_waiting_mutex;
-	Queue<ResourceId>	m_waiting_resources;
-	Mutex				m_loaded_mutex;
-	Queue<LoadedResource>	m_loaded_resources;
-
-	Thread				m_thread;
-
-	uint32_t			m_config_hash;
-	uint32_t			m_texture_hash;
-	uint32_t			m_mesh_hash;
-	uint32_t			m_txt_hash;
-
-	friend class		ResourceManager;
-};
-
-} // namespace crown