Browse Source

Define global hashed values for known resource types

Daniele Bartolini 12 năm trước cách đây
mục cha
commit
66da099221
4 tập tin đã thay đổi với 18 bổ sung24 xóa
  1. 1 1
      src/Device.cpp
  2. 7 0
      src/Resource.h
  3. 9 14
      src/ResourceManager.cpp
  4. 1 9
      src/ResourceManager.h

+ 1 - 1
src/Device.cpp

@@ -325,7 +325,7 @@ void Device::reload(ResourceId name)
 
 	const void* new_resource = m_resource_manager->data(name);
 
-	if (name.type == m_resource_manager->m_texture_hash)
+	if (name.type == TEXTURE_TYPE)
 	{
 		m_renderer->reload_texture((TextureResource*)old_resource, (TextureResource*)new_resource);
 	}

+ 7 - 0
src/Resource.h

@@ -26,10 +26,17 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
+#include "Hash.h"
 
 namespace crown
 {
 
+/// Hashed values for supported resource types
+const uint32_t TEXTURE_TYPE	= hash::murmur2_32("tga", 3, 0);
+const uint32_t MESH_TYPE	= hash::murmur2_32("dae", 3, 0);
+const uint32_t SCRIPT_TYPE	= hash::murmur2_32("lua", 3, 0);
+const uint32_t TEXT_TYPE	= hash::murmur2_32("txt", 3, 0);
+
 /// Enumerates the loading states of a resource
 enum ResourceState
 {

+ 9 - 14
src/ResourceManager.cpp

@@ -47,11 +47,6 @@ ResourceManager::ResourceManager(ResourceArchive& archive, Allocator& allocator)
 	m_loaded_queue(m_allocator),
 	m_thread(ResourceManager::background_thread, (void*)this, "resource-loader-thread")
 {
-	// FIXME hardcoded seed
-	m_texture_hash = hash::murmur2_32("tga", 3, 0);
-	m_mesh_hash = hash::murmur2_32("mesh", 4, 0);
-	m_txt_hash = hash::murmur2_32("txt", 3, 0);
-	m_script_hash = hash::murmur2_32("lua", 3, 0);
 }
 
 //-----------------------------------------------------------------------------
@@ -322,15 +317,15 @@ void ResourceManager::background_load()
 //-----------------------------------------------------------------------------
 void* ResourceManager::load_by_type(ResourceId name) const
 {
-	if (name.type == m_texture_hash)
+	if (name.type == TEXTURE_TYPE)
 	{
 		return TextureResource::load(m_resource_allocator, m_resource_archive, name);
 	}
-	else if (name.type == m_txt_hash)
+	else if (name.type == TEXT_TYPE)
 	{
 		return TextResource::load(m_resource_allocator, m_resource_archive, name);
 	}
-	else if (name.type == m_script_hash)
+	else if (name.type == SCRIPT_TYPE)
 	{
 		return ScriptResource::load(m_resource_allocator, m_resource_archive, name);
 	}
@@ -341,15 +336,15 @@ void* ResourceManager::load_by_type(ResourceId name) const
 //-----------------------------------------------------------------------------
 void ResourceManager::unload_by_type(ResourceId name, void* resource) const
 {
-	if (name.type == m_texture_hash)
+	if (name.type == TEXTURE_TYPE)
 	{
 		TextureResource::unload(m_resource_allocator, (TextureResource*)resource);
 	}
-	else if (name.type == m_txt_hash)
+	else if (name.type == TEXT_TYPE)
 	{
 		TextResource::unload(m_resource_allocator, (TextResource*)resource);
 	}
-	else if (name.type == m_script_hash)
+	else if (name.type == SCRIPT_TYPE)
 	{
 		ScriptResource::unload(m_resource_allocator, (ScriptResource*)resource);
 	}
@@ -360,15 +355,15 @@ void ResourceManager::unload_by_type(ResourceId name, void* resource) const
 //-----------------------------------------------------------------------------
 void ResourceManager::online(ResourceId name, void* resource)
 {
-	if (name.type == m_texture_hash)
+	if (name.type == TEXTURE_TYPE)
 	{
 		TextureResource::online((TextureResource*)resource);
 	}
-	else if (name.type == m_txt_hash)
+	else if (name.type == TEXT_TYPE)
 	{
 		TextResource::unload(m_resource_allocator, (TextResource*)resource);
 	}
-	else if (name.type == m_script_hash)
+	else if (name.type == SCRIPT_TYPE)
 	{
 		ScriptResource::online((ScriptResource*)resource);
 	}

+ 1 - 9
src/ResourceManager.h

@@ -167,15 +167,7 @@ private:
 	Mutex					m_loaded_mutex;
 	mutable Mutex			m_resources_mutex;
 
-private:
-
-	// Hashes of resource types (FIXME)
-	uint32_t			m_texture_hash;
-	uint32_t			m_mesh_hash;
-	uint32_t			m_txt_hash;
-	uint32_t			m_script_hash;
-
-	friend class		Device;
+	friend class			Device;
 };
 
 } // namespace crown