From 9d62cf70aa01bca726fbd675a2ee61c8b10eecca Mon Sep 17 00:00:00 2001 From: Malkierian Date: Sun, 8 Dec 2024 18:34:30 -0700 Subject: [PATCH] Address review comments, add rando MQ handling. --- soh/soh/OTRGlobals.cpp | 1 - soh/soh/ResourceManagerHelpers.cpp | 52 +++++++++++++----------------- soh/soh/ResourceManagerHelpers.h | 1 - 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 2e37a0f027..a317464669 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1202,7 +1202,6 @@ extern "C" void InitOTR() { #endif ResourceMgr_LoadPersistentAltAssets(); - ResourceMgr_RegisterHooks(); } extern "C" void SaveManager_ThreadPoolWait() { diff --git a/soh/soh/ResourceManagerHelpers.cpp b/soh/soh/ResourceManagerHelpers.cpp index afeda7b688..777421b8a5 100644 --- a/soh/soh/ResourceManagerHelpers.cpp +++ b/soh/soh/ResourceManagerHelpers.cpp @@ -19,9 +19,8 @@ #include #include -bool delayedAltAssetLoad = false; s16 unloadScene = -1; -std::shared_ptr rmhThreadPool = std::make_shared(1); +std::shared_ptr helperThreads = std::make_shared(1); extern "C" PlayState* gPlayState; @@ -400,10 +399,6 @@ extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { auto res = std::static_pointer_cast(ResourceMgr_GetResourceByNameHandlingMQ(path)); - // if (res->CachedGameAsset != nullptr) - // return (char*)res->CachedGameAsset; - // else - // { Vec3s* data = (Vec3s*)malloc(sizeof(Vec3s) * res->Scalars.size()); for (size_t i = 0; i < res->Scalars.size(); i += 3) { @@ -412,10 +407,7 @@ extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { data[(i / 3)].z = res->Scalars[i + 2].s16; } - // res->CachedGameAsset = data; - return (char*)data; - // } } extern "C" CollisionHeader* ResourceMgr_LoadColByName(const char* path) { @@ -514,21 +506,30 @@ extern "C" s32* ResourceMgr_LoadCSByName(const char* path) { } bool IsSharedScene(int16_t sceneNum) { - return sceneNum > SCENE_INSIDE_GANONS_CASTLE || sceneNum == SCENE_GANONS_TOWER || sceneNum == SCENE_THIEVES_HIDEOUT; + return sceneNum != SCENE_DEKU_TREE && + sceneNum != SCENE_DODONGOS_CAVERN && + sceneNum != SCENE_JABU_JABU && + sceneNum != SCENE_FOREST_TEMPLE && + sceneNum != SCENE_FIRE_TEMPLE && + sceneNum != SCENE_WATER_TEMPLE && + sceneNum != SCENE_SPIRIT_TEMPLE && + sceneNum != SCENE_SHADOW_TEMPLE && + sceneNum != SCENE_BOTTOM_OF_THE_WELL && + sceneNum != SCENE_ICE_CAVERN && + sceneNum != SCENE_GERUDO_TRAINING_GROUND && + sceneNum != SCENE_INSIDE_GANONS_CASTLE; } std::string GetScenePath(int16_t sceneNum) { std::string sceneName = gSceneTable[sceneNum].sceneFile.fileName; std::string path = "alt/scenes/shared/" + sceneName + "/*"; if (!IsSharedScene(sceneNum)) { - size_t pos = 0; - if ((pos = path.find("/shared/", 0)) != std::string::npos) { - if (ResourceMgr_IsGameMasterQuest()) { - path.replace(pos, 8, "/mq/"); - } - else { - path.replace(pos, 8, "/nonmq/"); - } + size_t pos = path.find("/shared/", 0); + if (IS_MASTER_QUEST || (IS_RANDO && OTRGlobals::Instance->gRandoContext->GetDungeons()->GetDungeonFromScene(sceneNum)->IsMQ())) { + path.replace(pos, 8, "/mq/"); + } + else { + path.replace(pos, 8, "/nonmq/"); } } return path; @@ -579,7 +580,7 @@ extern "C" void ResourceMgr_LoadAllSceneResources(int16_t sceneNum, bool now) { } } } - rmhThreadPool->submit_task(std::bind(LoadSceneResourcesProcess, sceneNum)); + helperThreads->submit_task(std::bind(LoadSceneResourcesProcess, sceneNum)); } extern "C" void ResourceMgr_RegisterUnloadSceneAssets(s16 prevScene) { @@ -599,7 +600,7 @@ void UnloadSceneAssetsProcess() { extern "C" void ResourceMgr_UnloadSceneAssets() { if (unloadScene != -1) { - rmhThreadPool->submit_task(UnloadSceneAssetsProcess); + helperThreads->submit_task(UnloadSceneAssetsProcess); } } @@ -641,14 +642,5 @@ extern "C" void ResourceMgr_LoadPersistentAltAssets() { ResourceLoadDirectoryAsync("alt/textures/parameter_Static/*"); ResourceLoadDirectoryAsync("alt/objects/gameplay_*"); } - rmhThreadPool->submit_task(ResourceMgr_LoadDelayedPersistentAltAssets); -} - -extern "C" void ResourceMgr_RegisterHooks() { - GameInteractor::Instance->RegisterGameHook([](int32_t sceneNum) { - if (delayedAltAssetLoad) { - delayedAltAssetLoad = false; - rmhThreadPool->submit_task(ResourceMgr_LoadDelayedPersistentAltAssets); - } - }); + helperThreads->submit_task(ResourceMgr_LoadDelayedPersistentAltAssets); } diff --git a/soh/soh/ResourceManagerHelpers.h b/soh/soh/ResourceManagerHelpers.h index 2627d33bb7..39045ac22d 100644 --- a/soh/soh/ResourceManagerHelpers.h +++ b/soh/soh/ResourceManagerHelpers.h @@ -65,7 +65,6 @@ extern "C" { void ResourceMgr_UnloadSceneAssets(); void ResourceMgr_LoadDelayedPersistentAltAssets(); void ResourceMgr_LoadPersistentAltAssets(); - void ResourceMgr_RegisterHooks(); void ResourceMgr_RegisterUnloadSceneAssets(s16 prevScene); #ifdef __cplusplus }