From f1df164eca77215f4788e3210536f6807938da6f Mon Sep 17 00:00:00 2001 From: Malkierian Date: Thu, 31 Oct 2024 13:58:48 -0700 Subject: [PATCH] Beginning steps for loading scene objects. --- soh/soh/z_play_otr.cpp | 45 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/soh/soh/z_play_otr.cpp b/soh/soh/z_play_otr.cpp index 754831617a..48da9f8a81 100644 --- a/soh/soh/z_play_otr.cpp +++ b/soh/soh/z_play_otr.cpp @@ -19,14 +19,42 @@ std::vector> persistentAssets; std::vector>> persistentAssetsAsync; std::map>> sceneAssets; std::map>>> sceneAssetsAsync; +std::map> sceneHeaders; -//LUS::OTRResource* OTRPlay_LoadFile(PlayState* play, RomFile* file) { +//Ship::IResource* OTRPlay_LoadFile(RomFile* file) { Ship::IResource* OTRPlay_LoadFile(const char* fileName) { auto res = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fileName); return res.get(); } +bool OTRPlay_IsSharedScene(s32 sceneId) { + return !((sceneId >= SCENE_DEKU_TREE && sceneId <= SCENE_ICE_CAVERN) || + sceneId == SCENE_GERUDO_TRAINING_GROUND || sceneId == SCENE_INSIDE_GANONS_CASTLE); +} + +extern "C" void OTRPlay_LoadSceneHeaders() { + sceneHeaders.insert("shared", {}); + sceneHeaders.insert("mq", {}); + sceneHeaders.insert("nonmq", {}); + + for (s32 i = 0; i < SCENE_ID_MAX; i++) { + // Scenes considered "dungeon" with a MQ variant + + SceneTableEntry* scene = &gSceneTable[i]; + if (OTRPlay_IsSharedScene(i)) { + std::string scenePath = StringHelper::Sprintf("scenes/shared/%s/%s", scene->sceneFile.fileName, scene->sceneFile.fileName); + sceneHeaders.at("shared")[i] = OTRPlay_LoadFile(scenePath.c_str()); + } else { + std::string scenePath = StringHelper::Sprintf("scenes/mq/%s/%s", scene->sceneFile.fileName, scene->sceneFile.fileName); + sceneHeaders.at("mq")[i] = OTRPlay_LoadFile(scenePath.c_str()); + auto pos = scenePath.find("/mq/"); + scenePath.replace(pos, pos + 3, "/nonmq/"); + sceneHeaders.at("nonmq")[i] = OTRPlay_LoadFile(scenePath.c_str()); + } + } +} + extern "C" void OTRPlay_InitSceneResourceMaps() { for (u32 i = 0; i < SCENE_ID_MAX; i++) { sceneAssets.insert(i, {}); @@ -149,23 +177,20 @@ extern "C" void OTRPlay_SpawnScene(PlayState* play, s32 sceneNum, s32 spawn) { //osSyncPrintf("\nSCENE SIZE %fK\n", (scene->sceneFile.vromEnd - scene->sceneFile.vromStart) / 1024.0f); - // Scenes considered "dungeon" with a MQ variant - int16_t inNonSharedScene = (sceneNum >= SCENE_DEKU_TREE && sceneNum <= SCENE_ICE_CAVERN) || - sceneNum == SCENE_GERUDO_TRAINING_GROUND || sceneNum == SCENE_INSIDE_GANONS_CASTLE; - std::string sceneVersion = "shared"; - if (inNonSharedScene) { + if (!OTRPlay_IsSharedScene(sceneNum)) { sceneVersion = IsGameMasterQuest() ? "mq" : "nonmq"; } - std::string scenePath = StringHelper::Sprintf("scenes/%s/%s/%s", sceneVersion.c_str(), scene->sceneFile.fileName, scene->sceneFile.fileName); - - play->sceneSegment = OTRPlay_LoadFile(scenePath.c_str()); + play->sceneSegment = nullptr; + if (sceneHeaders.at(sceneVersion).contains(sceneNum)) { + play->sceneSegment = sceneHeaders.at(sceneVersion).at(sceneNum); + } // Failed to load scene... default to doodongs cavern if (play->sceneSegment == nullptr) { lusprintf(__FILE__, __LINE__, 2, "Unable to load scene %s... Defaulting to Doodong's Cavern!\n", - scenePath.c_str()); + scene->sceneFile); OTRPlay_SpawnScene(play, 0x01, 0); return; }