This commit is contained in:
louist103 2022-06-04 22:10:55 -04:00 committed by louist103
parent ac2127094b
commit cf872d1e0d
2 changed files with 11 additions and 11 deletions

View File

@ -9,7 +9,7 @@
namespace Ship { namespace Ship {
ResourceMgr::ResourceMgr(std::shared_ptr<GlobalCtx2> Context, std::string MainPath, std::string PatchesPath) : Context(Context), bIsRunning(false), FileLoadThread(nullptr) { ResourceMgr::ResourceMgr(std::shared_ptr<GlobalCtx2> Context, const std::string& MainPath, const std::string& PatchesPath) : Context(Context), bIsRunning(false), FileLoadThread(nullptr) {
OTR = std::make_shared<Archive>(MainPath, PatchesPath, false); OTR = std::make_shared<Archive>(MainPath, PatchesPath, false);
gameVersion = OOT_UNKNOWN; gameVersion = OOT_UNKNOWN;
@ -95,7 +95,7 @@ namespace Ship {
//Lock.unlock(); //Lock.unlock();
SPDLOG_DEBUG("Loaded File {} on ResourceMgr thread", ToLoad->path); SPDLOG_DEBUG("Loaded File {} on ResourceMgr thread", ToLoad->path.c_str());
ToLoad->FileLoadNotifier.notify_all(); ToLoad->FileLoadNotifier.notify_all();
} }
@ -186,7 +186,7 @@ namespace Ship {
gameVersion = newGameVersion; gameVersion = newGameVersion;
} }
std::shared_ptr<File> ResourceMgr::LoadFileAsync(std::string FilePath) { std::shared_ptr<File> ResourceMgr::LoadFileAsync(const std::string& FilePath) {
const std::lock_guard<std::mutex> Lock(FileLoadMutex); const std::lock_guard<std::mutex> Lock(FileLoadMutex);
// File NOT already loaded...? // File NOT already loaded...?
auto fileCacheFind = FileCache.find(FilePath); auto fileCacheFind = FileCache.find(FilePath);
@ -204,7 +204,7 @@ namespace Ship {
return fileCacheFind->second; return fileCacheFind->second;
} }
std::shared_ptr<File> ResourceMgr::LoadFile(std::string FilePath) { std::shared_ptr<File> ResourceMgr::LoadFile(const std::string& FilePath) {
auto ToLoad = LoadFileAsync(FilePath); auto ToLoad = LoadFileAsync(FilePath);
// Wait for the File to actually be loaded if we are told to block. // Wait for the File to actually be loaded if we are told to block.
std::unique_lock<std::mutex> Lock(ToLoad->FileLoadMutex); std::unique_lock<std::mutex> Lock(ToLoad->FileLoadMutex);
@ -280,7 +280,7 @@ namespace Ship {
} }
} }
std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> ResourceMgr::CacheDirectoryAsync(std::string SearchMask) { std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> ResourceMgr::CacheDirectoryAsync(const std::string& SearchMask) {
auto loadedList = std::make_shared<std::vector<std::shared_ptr<ResourcePromise>>>(); auto loadedList = std::make_shared<std::vector<std::shared_ptr<ResourcePromise>>>();
auto fileList = OTR->ListFiles(SearchMask); auto fileList = OTR->ListFiles(SearchMask);
@ -299,7 +299,7 @@ namespace Ship {
return loadedList; return loadedList;
} }
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> ResourceMgr::CacheDirectory(std::string SearchMask) { std::shared_ptr<std::vector<std::shared_ptr<Resource>>> ResourceMgr::CacheDirectory(const std::string& SearchMask) {
auto PromiseList = CacheDirectoryAsync(SearchMask); auto PromiseList = CacheDirectoryAsync(SearchMask);
auto LoadedList = std::make_shared<std::vector<std::shared_ptr<Resource>>>(); auto LoadedList = std::make_shared<std::vector<std::shared_ptr<Resource>>>();

View File

@ -17,7 +17,7 @@ namespace Ship
// It works with the original game's assets because the entire ROM is 64MB and fits into RAM of any semi-modern PC. // It works with the original game's assets because the entire ROM is 64MB and fits into RAM of any semi-modern PC.
class ResourceMgr { class ResourceMgr {
public: public:
ResourceMgr(std::shared_ptr<GlobalCtx2> Context, std::string MainPath, std::string PatchesPath); ResourceMgr(std::shared_ptr<GlobalCtx2> Context, const std::string& MainPath, const std::string& PatchesPath);
~ResourceMgr(); ~ResourceMgr();
bool IsRunning(); bool IsRunning();
@ -32,14 +32,14 @@ namespace Ship
uint32_t GetGameVersion(); uint32_t GetGameVersion();
void SetGameVersion(uint32_t newGameVersion); void SetGameVersion(uint32_t newGameVersion);
std::shared_ptr<File> LoadFileAsync(std::string FilePath); std::shared_ptr<File> LoadFileAsync(const std::string& FilePath);
std::shared_ptr<File> LoadFile(std::string FilePath); std::shared_ptr<File> LoadFile(const std::string& FilePath);
std::shared_ptr<Ship::Resource> GetCachedFile(const char* FilePath) const; std::shared_ptr<Ship::Resource> GetCachedFile(const char* FilePath) const;
std::shared_ptr<Resource> LoadResource(const char* FilePath); std::shared_ptr<Resource> LoadResource(const char* FilePath);
std::shared_ptr<Resource> LoadResource(const std::string& FilePath) { return LoadResource(FilePath.c_str()); } std::shared_ptr<Resource> LoadResource(const std::string& FilePath) { return LoadResource(FilePath.c_str()); }
std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> LoadResourceAsync(const char* FilePath); std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourcePromise>> LoadResourceAsync(const char* FilePath);
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(std::string SearchMask); std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(const std::string& SearchMask);
std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> CacheDirectoryAsync(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);
protected: protected: