Skip to content

Commit

Permalink
Beginning steps for loading scene objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian committed Oct 31, 2024
1 parent b3046c6 commit f1df164
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions soh/soh/z_play_otr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,42 @@ std::vector<std::shared_ptr<Ship::IResource>> persistentAssets;
std::vector<std::shared_future<std::shared_ptr<Ship::IResource>>> persistentAssetsAsync;
std::map<u32, std::vector<std::shared_ptr<Ship::IResource>>> sceneAssets;
std::map<u32, std::vector<std::shared_future<std::shared_ptr<Ship::IResource>>>> sceneAssetsAsync;
std::map<std::string, std::map<int32_t, Ship::IResource*>> 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, {});
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f1df164

Please sign in to comment.