Skip to content

Commit

Permalink
Add UnloadResourcesAsync to handle threaded unloading.
Browse files Browse the repository at this point in the history
Make `UnloadResources` non-async.
Add common `UnloadResourcesProcess` to handle the actual unloading.
  • Loading branch information
Malkierian committed Dec 18, 2024
1 parent b7e715e commit e713983
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,36 @@ void ResourceManager::DirtyResources(const ResourceFilter& filter) {
});
}

void ResourceManager::UnloadResources(const ResourceFilter& filter) {
mThreadPool->submit_task([this, filter]() -> void {
auto list = GetArchiveManager()->ListFiles(filter.IncludeMasks, filter.ExcludeMasks);
void ResourceManager::DirtyResources(const std::string& searchMask) {
DirtyResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive });
}

for (const auto& key : *list.get()) {
UnloadResource({ key, mDefaultCacheOwner, mDefaultCacheArchive });
}
});
void ResourceManager::UnloadResourcesAsync(const std::string& searchMask) {
UnloadResourcesAsync({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive });
}

void ResourceManager::DirtyResources(const std::string& searchMask) {
DirtyResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive });
void ResourceManager::UnloadResourcesAsync(const ResourceFilter& filter) {
mThreadPool->submit_task([this, filter]() -> void {
UnloadResourcesProcess(filter);
});
}

void ResourceManager::UnloadResources(const std::string& searchMask) {
UnloadResources({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive });
}

void ResourceManager::UnloadResources(const ResourceFilter& filter) {
UnloadResourcesProcess(filter);
}

void ResourceManager::UnloadResourcesProcess(const ResourceFilter& filter) {
auto list = GetArchiveManager()->ListFiles(filter.IncludeMasks, filter.ExcludeMasks);

for (const auto& key : *list.get()) {
UnloadResource({ key, mDefaultCacheOwner, mDefaultCacheArchive });
}
}

std::shared_ptr<ArchiveManager> ResourceManager::GetArchiveManager() {
return mArchiveManager;
}
Expand Down
3 changes: 3 additions & 0 deletions src/resource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ class ResourceManager {
void DirtyResources(const ResourceFilter& filter);
void UnloadResources(const std::string& searchMask);
void UnloadResources(const ResourceFilter& filter);
void UnloadResourcesAsync(const std::string& searchMask);
void UnloadResourcesAsync(const ResourceFilter& filter);

bool OtrSignatureCheck(const char* fileName);
bool IsAltAssetsEnabled();
void SetAltAssetsEnabled(bool isEnabled);

protected:
std::shared_ptr<std::vector<std::shared_ptr<IResource>>> LoadResourcesProcess(const ResourceFilter& filter);
void UnloadResourcesProcess(const ResourceFilter& filter);
std::variant<ResourceLoadError, std::shared_ptr<IResource>> CheckCache(const ResourceIdentifier& identifier,
bool loadExact = false);
std::shared_ptr<File> LoadFileProcess(const ResourceIdentifier& identifier,
Expand Down

0 comments on commit e713983

Please sign in to comment.