fix: no longer leak memory, invalidate textures properly (#2223)

* Revert "Fix Ganondorf boss battle ending (MQ only) (#2072)"

This reverts commit 52b896271c.

* yolo this should work

* finish comment

* see if this doesn't lag switches!

* formatting

* formatting

Co-authored-by: briaguya <briaguya@alice>
This commit is contained in:
briaguya 2022-12-21 01:26:13 -05:00 committed by GitHub
parent e03ef85f3b
commit 73873a6dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 32 deletions

View File

@ -84,8 +84,11 @@ extern "C" void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr)
{
char* imgData = (char*)texAddr;
if (texAddr != 0 && ResourceMgr_OTRSigCheck(imgData))
texAddr = (uintptr_t)ResourceMgr_LoadTexByName(imgData);
if (texAddr != 0 && ResourceMgr_OTRSigCheck(imgData)) {
// Temporary solution to the mq/nonmq issue, this will be
// handled better with LUS 1.0
texAddr = (uintptr_t)ResourceMgr_LoadTexOrDListByName(imgData);
}
__gSPInvalidateTexCache(pkt, texAddr);
}

View File

@ -724,29 +724,19 @@ extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize)
return result;
}
std::string GetName(const char* path) {
std::string Path = path;
if (IsGameMasterQuest()) {
size_t pos = 0;
if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) {
Path.replace(pos, 7, "/mq/");
}
}
return Path;
}
extern "C" const char* ResourceMgr_GetName(const char* path) {
auto s = new std::string(GetName(path));
const char* name = s->c_str();
return name;
}
extern "C" void ResourceMgr_LoadFile(const char* resName) {
OTRGlobals::Instance->context->GetResourceManager()->LoadResource(resName);
}
std::shared_ptr<Ship::Resource> ResourceMgr_LoadResource(const char* path) {
return OTRGlobals::Instance->context->GetResourceManager()->LoadResource(ResourceMgr_GetName(path));
std::string Path = path;
if (ResourceMgr_IsGameMasterQuest()) {
size_t pos = 0;
if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) {
Path.replace(pos, 7, "/mq/");
}
}
return OTRGlobals::Instance->context->GetResourceManager()->LoadResource(Path.c_str());
}
extern "C" char* ResourceMgr_LoadFileRaw(const char* resName) {
@ -821,7 +811,14 @@ extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) {
else if (res->ResType == Ship::ResourceType::Array)
return (char*)(std::static_pointer_cast<Ship::Array>(res))->vertices.data();
else {
return ResourceMgr_LoadTexByName(ResourceMgr_GetName(filePath));
std::string Path = filePath;
if (ResourceMgr_IsGameMasterQuest()) {
size_t pos = 0;
if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) {
Path.replace(pos, 7, "/mq/");
}
}
return ResourceMgr_LoadTexByName(Path.c_str());
}
}

View File

@ -37,7 +37,6 @@ private:
};
uint32_t IsGameMasterQuest();
std::string GetName(const char* path);
#endif
#ifndef __cplusplus
@ -60,7 +59,6 @@ uint32_t ResourceMgr_GetNumGameVersions();
uint32_t ResourceMgr_GetGameVersion(int index);
void ResourceMgr_CacheDirectory(const char* resName);
char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize);
const char* ResourceMgr_GetName(const char* path);
void ResourceMgr_LoadFile(const char* resName);
char* ResourceMgr_LoadFileFromDisk(const char* filePath);
char* ResourceMgr_LoadJPEG(char* data, int dataSize);

View File

@ -1703,10 +1703,7 @@ void BossDodongo_DrawEffects(PlayState* play) {
Gfx_SetupDL_25Xlu(play->state.gfxCtx);
unkMtx = &play->billboardMtxF;
// OTRTODO: This call causes the whole texture cache to be cleaned up, which causes an important slowdown on switch so we need to find a way to avoid it.
#if !defined(__SWITCH__) && !defined(__WIIU__)
gSPInvalidateTexCache(POLY_XLU_DISP++, 0);
#endif
gSPInvalidateTexCache(POLY_XLU_DISP++, gDodongosCavernBossLavaFloorTex);
for (i = 0; i < 80; i++, eff++) {
FrameInterpolation_RecordOpenChild(eff, eff->epoch);

View File

@ -1197,8 +1197,10 @@ void BossGanon_SetupTowerCutscene(BossGanon* this, PlayState* play) {
void BossGanon_ShatterWindows(u8 windowShatterState) {
s16 i;
u8* tex1 = ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(ResourceMgr_GetName(ganon_boss_sceneTex_006C18)));
u8* tex2 = ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(ResourceMgr_GetName(ganon_boss_sceneTex_007418)));
// Temporary solution: using LoadTexOrDList to ensure we actually have the texture available
// based on mq/nonmq. This will be handled properly with LUS 1.0
u8* tex1 = ResourceMgr_LoadTexOrDListByName(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_006C18));
u8* tex2 = ResourceMgr_LoadTexOrDListByName(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_007418));
u8* templateTex = ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(gGanondorfWindowShatterTemplateTex));
for (i = 0; i < 2048; i++) {
@ -3820,8 +3822,8 @@ void BossGanon_Draw(Actor* thisx, PlayState* play) {
// Invalidate textures if they have changed
if (this->windowShatterState != GDF_WINDOW_SHATTER_OFF) {
gSPInvalidateTexCache(POLY_OPA_DISP++, ResourceMgr_GetName(ganon_boss_sceneTex_006C18));
gSPInvalidateTexCache(POLY_OPA_DISP++, ResourceMgr_GetName(ganon_boss_sceneTex_007418));
gSPInvalidateTexCache(POLY_OPA_DISP++, ganon_boss_sceneTex_006C18);
gSPInvalidateTexCache(POLY_OPA_DISP++, ganon_boss_sceneTex_007418);
}
Gfx_SetupDL_25Opa(play->state.gfxCtx);