Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnloadResourceAsync #766

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,34 @@ 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, BS::priority_t priority) {
UnloadResourcesAsync({ { searchMask }, {}, mDefaultCacheOwner, mDefaultCacheArchive }, priority);
}

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

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, BS::priority_t priority = BS::pr::normal);
void UnloadResourcesAsync(const ResourceFilter& filter, BS::priority_t priority = BS::pr::normal);

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
Loading