Преглед изворни кода

Add ResourceManager::reload()

Daniele Bartolini пре 11 година
родитељ
комит
98e968d44b
2 измењених фајлова са 18 додато и 0 уклоњено
  1. 14 0
      engine/resource/resource_manager.cpp
  2. 4 0
      engine/resource/resource_manager.h

+ 14 - 0
engine/resource/resource_manager.cpp

@@ -98,6 +98,20 @@ void ResourceManager::unload(StringId64 type, StringId64 name)
 	}
 }
 
+void ResourceManager::reload(StringId64 type, StringId64 name)
+{
+	const ResourceId id(type, name);
+	const ResourceEntry& entry = sort_map::get(_rm, id, NOT_FOUND);
+	const uint32_t old_refs = entry.references;
+
+	unload(type, name);
+	load(type, name);
+	flush();
+
+	ResourceEntry& new_entry = sort_map::get(_rm, id, NOT_FOUND);
+	new_entry.references = old_refs;
+}
+
 bool ResourceManager::can_get(const char* type, const char* name)
 {
 	ResourceId id(type, name);

+ 4 - 0
engine/resource/resource_manager.h

@@ -57,6 +57,10 @@ public:
 	/// Unloads the resource @a type @a name.
 	void unload(StringId64 type, StringId64 name);
 
+	/// Reloads the resource (@a type, @a name).
+	/// @note The user has to manually update all the references to the old resource.
+	void reload(StringId64 type, StringId64 name);
+
 	/// Returns whether the manager has the resource (@a type, @a name).
 	bool can_get(const char* type, const char* name);