Răsfoiți Sursa

Add lookup to fetch a resource instance given resource type and name

Daniele Bartolini 12 ani în urmă
părinte
comite
be25777427
2 a modificat fișierele cu 14 adăugiri și 0 ștergeri
  1. 11 0
      engine/resource/ResourceManager.cpp
  2. 3 0
      engine/resource/ResourceManager.h

+ 11 - 0
engine/resource/ResourceManager.cpp

@@ -80,6 +80,17 @@ void ResourceManager::unload(ResourceId name)
 	}
 }
 
+//-----------------------------------------------------------------------------
+void* ResourceManager::lookup(const char* type, const char* name)
+{
+	ResourceId id = resource_id(type, name);
+	ResourceEntry* entry = find(id);
+
+	CE_ASSERT_NOT_NULL(entry);
+
+	return entry->resource;
+}
+
 //-----------------------------------------------------------------------------
 bool ResourceManager::has(ResourceId name) const
 {

+ 3 - 0
engine/resource/ResourceManager.h

@@ -73,6 +73,9 @@ public:
 	/// and eventually any global object associated with it.
 	void					unload(ResourceId name);
 
+	/// Returns the resource instance associated to the given @a type and @a name.
+	void*					lookup(const char* type, const char* name);
+
 	/// Returns whether the manager has the @a name resource into
 	/// its list of resources.
 	/// @warning