mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-26 11:22:17 -05:00
ResourceMgr now decreases priority of load messages to trace.
This commit is contained in:
parent
3792b03a7d
commit
b774252f0c
@ -14,8 +14,9 @@ namespace Ship {
|
||||
|
||||
gameVersion = OOT_UNKNOWN;
|
||||
|
||||
if (OTR->IsMainMPQValid())
|
||||
if (OTR->IsMainMPQValid()) {
|
||||
Start();
|
||||
}
|
||||
}
|
||||
|
||||
ResourceMgr::~ResourceMgr() {
|
||||
@ -87,10 +88,11 @@ namespace Ship {
|
||||
|
||||
OTR->LoadFile(ToLoad->path, true, ToLoad);
|
||||
|
||||
if (!ToLoad->bHasLoadError)
|
||||
if (!ToLoad->bHasLoadError) {
|
||||
FileCache[ToLoad->path] = ToLoad->bIsLoaded && !ToLoad->bHasLoadError ? ToLoad : nullptr;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Loaded File {} on ResourceMgr thread", ToLoad->path);
|
||||
SPDLOG_TRACE("Loaded File {} on ResourceMgr thread", ToLoad->path);
|
||||
|
||||
ToLoad->FileLoadNotifier.notify_all();
|
||||
}
|
||||
@ -123,12 +125,10 @@ namespace Ship {
|
||||
}
|
||||
}
|
||||
|
||||
if (!ToLoad->file->bHasLoadError)
|
||||
{
|
||||
if (!ToLoad->file->bHasLoadError) {
|
||||
auto UnmanagedRes = ResourceLoader::LoadResource(ToLoad->file);
|
||||
|
||||
if (UnmanagedRes != nullptr)
|
||||
{
|
||||
if (UnmanagedRes != nullptr) {
|
||||
UnmanagedRes->resMgr = this;
|
||||
auto Res = std::shared_ptr<Resource>(UnmanagedRes);
|
||||
|
||||
@ -142,17 +142,14 @@ namespace Ship {
|
||||
SPDLOG_DEBUG("Loaded Resource {} on ResourceMgr thread", ToLoad->file->path);
|
||||
|
||||
Res->file = nullptr;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ToLoad->bHasResourceLoaded = false;
|
||||
ToLoad->resource = nullptr;
|
||||
|
||||
SPDLOG_ERROR("Resource load FAILED {} on ResourceMgr thread", ToLoad->file->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ToLoad->bHasResourceLoaded = false;
|
||||
ToLoad->resource = nullptr;
|
||||
}
|
||||
@ -163,13 +160,11 @@ namespace Ship {
|
||||
SPDLOG_INFO("Resource Manager LoadResourceThread ended");
|
||||
}
|
||||
|
||||
uint32_t ResourceMgr::GetGameVersion()
|
||||
{
|
||||
uint32_t ResourceMgr::GetGameVersion() {
|
||||
return gameVersion;
|
||||
}
|
||||
|
||||
void ResourceMgr::SetGameVersion(uint32_t newGameVersion)
|
||||
{
|
||||
void ResourceMgr::SetGameVersion(uint32_t newGameVersion) {
|
||||
gameVersion = newGameVersion;
|
||||
}
|
||||
|
||||
@ -206,24 +201,23 @@ namespace Ship {
|
||||
auto resCacheFind = ResourceCache.find(FilePath);
|
||||
|
||||
if (resCacheFind != ResourceCache.end() &&
|
||||
resCacheFind->second.use_count() > 0)
|
||||
{
|
||||
resCacheFind->second.use_count() > 0) {
|
||||
return resCacheFind->second;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Resource> ResourceMgr::LoadResource(const char* FilePath) {
|
||||
auto Res = LoadResourceAsync(FilePath);
|
||||
|
||||
if (std::holds_alternative<std::shared_ptr<Resource>>(Res))
|
||||
if (std::holds_alternative<std::shared_ptr<Resource>>(Res)) {
|
||||
return std::get<std::shared_ptr<Resource>>(Res);
|
||||
}
|
||||
|
||||
auto& Promise = std::get<std::shared_ptr<ResourcePromise>>(Res);
|
||||
|
||||
if (!Promise->bHasResourceLoaded)
|
||||
{
|
||||
if (!Promise->bHasResourceLoaded) {
|
||||
std::unique_lock<std::mutex> Lock(Promise->resourceLoadMutex);
|
||||
while (!Promise->bHasResourceLoaded) {
|
||||
Promise->resourceLoadNotifier.wait(Lock);
|
||||
@ -234,8 +228,9 @@ namespace Ship {
|
||||
}
|
||||
|
||||
std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> ResourceMgr::LoadResourceAsync(const char* FilePath) {
|
||||
if (FilePath[0] == '_' && FilePath[1] == '_' && FilePath[2] == 'O' && FilePath[3] == 'T' && FilePath[4] == 'R' && FilePath[5] == '_' && FilePath[6] == '_')
|
||||
if (FilePath[0] == '_' && FilePath[1] == '_' && FilePath[2] == 'O' && FilePath[3] == 'T' && FilePath[4] == 'R' && FilePath[5] == '_' && FilePath[6] == '_') {
|
||||
FilePath += 7;
|
||||
}
|
||||
|
||||
const std::lock_guard<std::mutex> ResLock(ResourceLoadMutex);
|
||||
auto resCacheFind = ResourceCache.find(FilePath);
|
||||
@ -248,21 +243,16 @@ namespace Ship {
|
||||
std::shared_ptr<File> FileData = LoadFile(FilePath);
|
||||
Promise->file = FileData;
|
||||
|
||||
if (Promise->file->bHasLoadError)
|
||||
{
|
||||
if (Promise->file->bHasLoadError) {
|
||||
Promise->bHasResourceLoaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Promise->bHasResourceLoaded = false;
|
||||
ResourceLoadQueue.push(Promise);
|
||||
ResourceLoadNotifier.notify_all();
|
||||
}
|
||||
|
||||
return Promise;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return resCacheFind->second;
|
||||
}
|
||||
}
|
||||
@ -273,8 +263,7 @@ namespace Ship {
|
||||
|
||||
for (DWORD i = 0; i < fileList.size(); i++) {
|
||||
auto resource = LoadResourceAsync(fileList.operator[](i).cFileName);
|
||||
if (std::holds_alternative<std::shared_ptr<Resource>>(resource))
|
||||
{
|
||||
if (std::holds_alternative<std::shared_ptr<Resource>>(resource)) {
|
||||
auto promise = std::make_shared<ResourcePromise>();
|
||||
promise->bHasResourceLoaded = true;
|
||||
promise->resource = std::get<std::shared_ptr<Resource>>(resource);
|
||||
@ -304,8 +293,7 @@ namespace Ship {
|
||||
return LoadedList;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> ResourceMgr::DirtyDirectory(std::string SearchMask)
|
||||
{
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> ResourceMgr::DirtyDirectory(std::string& SearchMask) {
|
||||
auto PromiseList = CacheDirectoryAsync(SearchMask);
|
||||
auto LoadedList = std::make_shared<std::vector<std::shared_ptr<Resource>>>();
|
||||
|
||||
@ -317,8 +305,9 @@ namespace Ship {
|
||||
Promise->resourceLoadNotifier.wait(Lock);
|
||||
}
|
||||
|
||||
if (Promise->resource != nullptr)
|
||||
if (Promise->resource != nullptr) {
|
||||
Promise->resource->isDirty = true;
|
||||
}
|
||||
|
||||
LoadedList->push_back(Promise->resource);
|
||||
}
|
||||
@ -326,8 +315,7 @@ namespace Ship {
|
||||
return LoadedList;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<std::string>> ResourceMgr::ListFiles(std::string SearchMask)
|
||||
{
|
||||
std::shared_ptr<std::vector<std::string>> ResourceMgr::ListFiles(std::string SearchMask) {
|
||||
auto result = std::make_shared<std::vector<std::string>>();
|
||||
auto fileList = OTR->ListFiles(SearchMask);
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace Ship {
|
||||
std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> LoadResourceAsync(const char* FilePath);
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(const std::string& SearchMask);
|
||||
std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> CacheDirectoryAsync(const std::string& SearchMask);
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> DirtyDirectory(std::string SearchMask);
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> DirtyDirectory(std::string& SearchMask);
|
||||
std::shared_ptr<std::vector<std::string>> ListFiles(std::string SearchMask);
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user