From 582f084973b9c5cc4c5c49831fb44a957d5161d6 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Mon, 1 Aug 2022 03:32:40 +0200 Subject: [PATCH] Use tex sizes from texture rather than hardcoded values (#610) * Use tex sizes from texture rather than hardcoded values * Dynamic do action tex sizes * Remove unused minimap texture keys * Restore MESSAGE_STATIC_TEX_SIZE * Use dynamic offsets * MACRO it up * Enable SPDLOG in Xcode * Handle non-existent texture --- libultraship/libultraship/Window.cpp | 36 ++++++++- soh/include/z64.h | 2 - soh/soh.xcodeproj/project.pbxproj | 6 +- .../xcshareddata/xcschemes/soh.xcscheme | 78 +++++++++++++++++++ soh/soh/GbiWrap.cpp | 3 + soh/soh/OTRGlobals.cpp | 6 ++ soh/soh/OTRGlobals.h | 3 + soh/src/code/z_construct.c | 28 +------ soh/src/code/z_map_data.c | 29 +++---- soh/src/code/z_map_exp.c | 9 ++- soh/src/code/z_message_PAL.c | 11 +-- soh/src/code/z_parameter.c | 62 ++++++++++----- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 23 ++++-- 13 files changed, 209 insertions(+), 87 deletions(-) create mode 100644 soh/soh.xcodeproj/xcshareddata/xcschemes/soh.xcscheme diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 9957ebc48..39d4aad06 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -32,6 +32,8 @@ #include +#define LOAD_TEX(texPath) static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); + extern "C" { struct OSMesgQueue; @@ -123,8 +125,7 @@ extern "C" { const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); if (hashStr != nullptr) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str()).get()); - + const auto res = LOAD_TEX(hashStr->c_str()); ModInternal::ExecuteHooks(hashStr->c_str(), &res->imageData); return reinterpret_cast(res->imageData); @@ -151,13 +152,40 @@ extern "C" { } char* ResourceMgr_LoadTexByName(char* texPath) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); + const auto res = LOAD_TEX(texPath); ModInternal::ExecuteHooks(texPath, &res->imageData); return (char*)res->imageData; } + uint16_t ResourceMgr_LoadTexWidthByName(char* texPath) { + const auto res = LOAD_TEX(texPath); + if (res != nullptr) + return res->width; + + SPDLOG_ERROR("Given texture path is a non-existent resource"); + return -1; + } + + uint16_t ResourceMgr_LoadTexHeightByName(char* texPath) { + const auto res = LOAD_TEX(texPath); + if (res != nullptr) + return res->height; + + SPDLOG_ERROR("Given texture path is a non-existent resource"); + return -1; + } + + uint32_t ResourceMgr_LoadTexSizeByName(char* texPath) { + const auto res = LOAD_TEX(texPath); + if (res != nullptr) + return res->imageDataSize; + + SPDLOG_ERROR("Given texture path is a non-existent resource"); + return -1; + } + void ResourceMgr_WriteTexS16ByName(char* texPath, size_t index, s16 value) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); + const auto res = LOAD_TEX(texPath); if (res != nullptr) { diff --git a/soh/include/z64.h b/soh/include/z64.h index fdc634e58..94d8b280e 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -1458,8 +1458,6 @@ typedef struct { /* 0x18 */ s16 (*roomCompassOffsetY)[44]; // dungeon compass icon Y offset by room /* 0x1C */ u8* dgnMinimapCount; // number of room minimaps /* 0x20 */ u16* dgnMinimapTexIndexOffset; // dungeon minimap texture index offset - /* 0x24 */ u16* owMinimapTexSize; - /* 0x28 */ u16* owMinimapTexOffset; /* 0x2C */ s16* owMinimapPosX; /* 0x30 */ s16* owMinimapPosY; /* 0x34 */ s16 (*owCompassInfo)[4]; // [X scale, Y scale, X offset, Y offset] diff --git a/soh/soh.xcodeproj/project.pbxproj b/soh/soh.xcodeproj/project.pbxproj index e5b56cb72..a20ba8db4 100644 --- a/soh/soh.xcodeproj/project.pbxproj +++ b/soh/soh.xcodeproj/project.pbxproj @@ -6668,10 +6668,12 @@ "$(inherited)", "-DENABLE_OPENGL", "-DNDEBUG", + "-DSPDLOG_ACTIVE_LEVEL=0", ); OTHER_CPLUSPLUSFLAGS = ( "-DENABLE_OPENGL", "-DNDEBUG", + "-DSPDLOG_ACTIVE_LEVEL=0", ); OTHER_LIBTOOLFLAGS = ""; OTHER_REZFLAGS = ""; @@ -6728,10 +6730,12 @@ "$(inherited)", "-DENABLE_OPENGL", "-D_DEBUG", + "-DSPDLOG_ACTIVE_LEVEL=0", ); OTHER_CPLUSPLUSFLAGS = ( "-DENABLE_OPENGL", "-D_DEBUG", + "-DSPDLOG_ACTIVE_LEVEL=0", ); OTHER_LIBTOOLFLAGS = ""; OTHER_REZFLAGS = ""; @@ -6842,7 +6846,6 @@ "-DENABLE_OPENGL", "-D_CRT_SECURE_NO_WARNINGS", "-D_CONSOLE", - "-DSPDLOG_ACTIVE_LEVEL=0", "-DNDEBUG", ); OTHER_LDFLAGS = ( @@ -7031,7 +7034,6 @@ "-DENABLE_OPENGL", "-D_CRT_SECURE_NO_WARNINGS", "-D_CONSOLE", - "-DSPDLOG_ACTIVE_LEVEL=0", "-D_DEBUG", ); OTHER_LDFLAGS = ( diff --git a/soh/soh.xcodeproj/xcshareddata/xcschemes/soh.xcscheme b/soh/soh.xcodeproj/xcshareddata/xcschemes/soh.xcscheme new file mode 100644 index 000000000..86e5eaeeb --- /dev/null +++ b/soh/soh.xcodeproj/xcshareddata/xcschemes/soh.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/soh/soh/GbiWrap.cpp b/soh/soh/GbiWrap.cpp index 9f71f1717..cf33ed547 100644 --- a/soh/soh/GbiWrap.cpp +++ b/soh/soh/GbiWrap.cpp @@ -17,6 +17,9 @@ void ResourceMgr_CacheDirectory(const char* resName); void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); char* ResourceMgr_LoadTexByName(char* texPath); +uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); +uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); +uint32_t ResourceMgr_LoadTexSizeByName(char* texPath); char* ResourceMgr_LoadTexOrDListByName(char* filePath); char* ResourceMgr_LoadPlayerAnimByName(char* animPath); char* ResourceMgr_GetNameByCRC(uint64_t crc, char* alloc); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 053d2d801..f611909b1 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -452,6 +452,12 @@ extern "C" char* ResourceMgr_LoadJPEG(char* data, int dataSize) extern "C" char* ResourceMgr_LoadTexByName(const char* texPath); +extern "C" uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); + +extern "C" uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); + +extern "C" uint32_t ResourceMgr_LoadTexSizeByName(const char* texPath); + extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) { auto res = OTRGlobals::Instance->context->GetResourceManager()->LoadResource(filePath); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 2bee6819d..d03c913e1 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -44,6 +44,9 @@ void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); char* ResourceMgr_LoadJPEG(char* data, int dataSize); char* ResourceMgr_LoadTexByName(const char* texPath); +uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); +uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); +uint32_t ResourceMgr_LoadTexSizeByName(char* texPath); char* ResourceMgr_LoadTexOrDListByName(const char* filePath); char* ResourceMgr_LoadPlayerAnimByName(const char* animPath); AnimationHeaderCommon* ResourceMgr_LoadAnimByName(const char* path); diff --git a/soh/src/code/z_construct.c b/soh/src/code/z_construct.c index 96915d919..08497fe1c 100644 --- a/soh/src/code/z_construct.c +++ b/soh/src/code/z_construct.c @@ -8,7 +8,6 @@ void func_80110990(GlobalContext* globalCtx) { void func_801109B0(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; u32 parameterSize; - u16 doActionOffset; u8 temp; gSaveContext.sunsSongState = SUNSSONG_INACTIVE; @@ -49,30 +48,11 @@ void func_801109B0(GlobalContext* globalCtx) { ASSERT(interfaceCtx->doActionSegment != NULL); - if (gSaveContext.language == LANGUAGE_ENG) { - doActionOffset = 0; - } else if (gSaveContext.language == LANGUAGE_GER) { - doActionOffset = 0x2B80; - } else { - doActionOffset = 0x5700; - } + uint32_t attackDoActionTexSize = ResourceMgr_LoadTexSizeByName(gAttackDoActionENGTex); + memcpy(interfaceCtx->doActionSegment, ResourceMgr_LoadTexByName(gAttackDoActionENGTex), attackDoActionTexSize); + memcpy(interfaceCtx->doActionSegment + (attackDoActionTexSize / 2), ResourceMgr_LoadTexByName(gCheckDoActionENGTex), attackDoActionTexSize); - memcpy(interfaceCtx->doActionSegment, ResourceMgr_LoadTexByName(gAttackDoActionENGTex), 0x180); - memcpy(interfaceCtx->doActionSegment + 0x180, ResourceMgr_LoadTexByName(gCheckDoActionENGTex), 0x180); - //DmaMgr_SendRequest1(interfaceCtx->doActionSegment, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset, 0x300, - //__FILE__, __LINE__); - - if (gSaveContext.language == LANGUAGE_ENG) { - doActionOffset = 0x480; - } else if (gSaveContext.language == LANGUAGE_GER) { - doActionOffset = 0x3000; - } else { - doActionOffset = 0x5B80; - } - - memcpy(interfaceCtx->doActionSegment + 0x300, ResourceMgr_LoadTexByName(gReturnDoActionENGTex), 0x180); - //DmaMgr_SendRequest1(interfaceCtx->doActionSegment + 0x300, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset, - //0x180); + memcpy(interfaceCtx->doActionSegment + attackDoActionTexSize, ResourceMgr_LoadTexByName(gReturnDoActionENGTex), ResourceMgr_LoadTexSizeByName(gReturnDoActionENGTex)); interfaceCtx->iconItemSegment = GAMESTATE_ALLOC_MC( &globalCtx->state, 0x1000 * ARRAY_COUNT(gSaveContext.equips.buttonItems)); diff --git a/soh/src/code/z_map_data.c b/soh/src/code/z_map_data.c index f518a124c..f76a3b4ce 100644 --- a/soh/src/code/z_map_data.c +++ b/soh/src/code/z_map_data.c @@ -184,16 +184,6 @@ static u16 sDgnMinimapTexIndexOffset[10] = { 0, 13, 32, 49, 76, 114, 158, 190, 217, 227, }; -static u16 sOwMinimapTexSize[24] = { - 2920, 2560, 1560, 2784, 2976, 2040, 3240, 2336, 2080, 2600, 1792, 1888, - 3400, 1792, 1888, 2040, 3120, 2304, 2176, 1888, 1560, 3240, 2600, 3400, -}; - -static u16 sOwMinimapTexOffset[24] = { - 0x0000, 0x0B68, 0x1568, 0x1B80, 0x2660, 0x3200, 0x39F8, 0x46A0, 0x4FC0, 0x57E0, 0x6208, 0x6908, - 0x7068, 0x7DB0, 0x84B0, 0x8C10, 0x9408, 0xA038, 0xA938, 0xB1B8, 0xB918, 0xBF30, 0xCBD8, 0xD600, -}; - static s16 sOwMinimapPosX[24] = { 216, 216, 218, 202, 202, 250, 216, 234, 234, 216, 234, 234, 216, 234, 234, 250, 216, 234, 234, 234, 218, 80, 80, 216, @@ -319,14 +309,13 @@ static u8 sFloorID[10][8] = { static s16 sSkullFloorIconY[10] = { -47, -47, -33, -47, -47, -5, -19, -47, -99, -99 }; MapData gMapDataTable = { - sFloorTexIndexOffset, sBossFloor, sRoomPalette, - sMaxPaletteCount, sPaletteRoom, sRoomCompassOffsetX, - sRoomCompassOffsetY, sDgnMinimapCount, sDgnMinimapTexIndexOffset, - sOwMinimapTexSize, sOwMinimapTexOffset, sOwMinimapPosX, - sOwMinimapPosY, sOwCompassInfo, sDgnMinimapTexIndexBase, - sDgnCompassInfo, sOwMinimapWidth, sOwMinimapHeight, - sOwEntranceIconPosX, sOwEntranceIconPosY, sOwEntranceFlag, - sFloorCoordY, sSwitchEntryCount, sSwitchFromRoom, - sSwitchFromFloor, sSwitchToRoom, sFloorID, - sSkullFloorIconY, + sFloorTexIndexOffset, sBossFloor, sRoomPalette, + sMaxPaletteCount, sPaletteRoom, sRoomCompassOffsetX, + sRoomCompassOffsetY, sDgnMinimapCount, sDgnMinimapTexIndexOffset, + sOwMinimapPosX, sOwMinimapPosY, sOwCompassInfo, + sDgnMinimapTexIndexBase, sDgnCompassInfo, sOwMinimapWidth, + sOwMinimapHeight, sOwEntranceIconPosX, sOwEntranceIconPosY, + sOwEntranceFlag, sFloorCoordY, sSwitchEntryCount, + sSwitchFromRoom, sSwitchFromFloor, sSwitchToRoom, + sFloorID, sSkullFloorIconY, }; diff --git a/soh/src/code/z_map_exp.c b/soh/src/code/z_map_exp.c index 6572f6fc1..c9b927730 100644 --- a/soh/src/code/z_map_exp.c +++ b/soh/src/code/z_map_exp.c @@ -412,8 +412,10 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) { //(uintptr_t)_map_grand_staticSegmentRomStart + gMapData->owMinimapTexOffset[extendedMapIndex], //gMapData->owMinimapTexSize[mapIndex], __FILE__, __LINE__); - if (sEntranceIconMapIndex < 24) - memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableOW[sEntranceIconMapIndex]), gMapData->owMinimapTexSize[mapIndex]); + if (sEntranceIconMapIndex < 24) { + const char* textureName = minimapTableOW[sEntranceIconMapIndex]; + memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); + } interfaceCtx->unk_258 = mapIndex; break; @@ -445,7 +447,8 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) { //((gMapData->dgnMinimapTexIndexOffset[mapIndex] + room) * 0xFF0), //0xFF0, __FILE__, __LINE__); - memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]), 0xFF0); + const char* textureName = minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]; + memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); R_COMPASS_OFFSET_X = gMapData->roomCompassOffsetX[mapIndex][room]; R_COMPASS_OFFSET_Y = gMapData->roomCompassOffsetY[mapIndex][room]; diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index a91dd5e41..afc69e814 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1196,7 +1196,7 @@ void Message_LoadItemIcon(GlobalContext* globalCtx, u16 itemId, s16 y) { R_TEXTBOX_ICON_YPOS = y + 6; R_TEXTBOX_ICON_SIZE = 32; memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, - ResourceMgr_LoadTexByName(gItemIcons[itemId]), 0x1000); + ResourceMgr_LoadTexByName(gItemIcons[itemId]), ResourceMgr_LoadTexSizeByName(gItemIcons[itemId])); // "Item 32-0" osSyncPrintf("アイテム32-0\n"); } else { @@ -1204,7 +1204,7 @@ void Message_LoadItemIcon(GlobalContext* globalCtx, u16 itemId, s16 y) { R_TEXTBOX_ICON_YPOS = y + 10; R_TEXTBOX_ICON_SIZE = 24; memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, - ResourceMgr_LoadTexByName(gItemIcons[itemId]), 0x900); + ResourceMgr_LoadTexByName(gItemIcons[itemId]), ResourceMgr_LoadTexSizeByName(gItemIcons[itemId])); // "Item 24" osSyncPrintf("アイテム24=%d (%d) {%d}\n", itemId, itemId - ITEM_KOKIRI_EMERALD, 84); } @@ -1565,9 +1565,9 @@ void Message_Decode(GlobalContext* globalCtx) { msgCtx->textboxBackgroundUnkArg = font->msgBuf[msgCtx->msgBufPos + 3] & 0xF; memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, - ResourceMgr_LoadTexByName(gRedMessageXLeftTex), 0x900); + ResourceMgr_LoadTexByName(gRedMessageXLeftTex), ResourceMgr_LoadTexSizeByName(gRedMessageXLeftTex)); memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, - ResourceMgr_LoadTexByName(gRedMessageXRightTex), 0x900); + ResourceMgr_LoadTexByName(gRedMessageXRightTex), ResourceMgr_LoadTexSizeByName(gRedMessageXRightTex)); msgCtx->msgBufPos += 3; R_TEXTBOX_BG_YPOS = R_TEXTBOX_Y + 8; @@ -1750,7 +1750,8 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { // "Text Box Type" osSyncPrintf("吹き出し種類=%d\n", msgCtx->textBoxType); if (textBoxType < TEXTBOX_TYPE_NONE_BOTTOM) { - memcpy(msgCtx->textboxSegment, ResourceMgr_LoadTexByName(msgStaticTbl[messageStaticIndices[textBoxType]]), MESSAGE_STATIC_TEX_SIZE); + const char* textureName = msgStaticTbl[messageStaticIndices[textBoxType]]; + memcpy(msgCtx->textboxSegment, ResourceMgr_LoadTexByName(textureName), MESSAGE_STATIC_TEX_SIZE); if (textBoxType == TEXTBOX_TYPE_BLACK) { msgCtx->textboxColorRed = 0; msgCtx->textboxColorGreen = 0; diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index 2a4921d7f..40f2c2678 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -10,10 +10,31 @@ #include #endif -// TODO extract this information from the texture definitions themselves -#define DO_ACTION_TEX_WIDTH 48 -#define DO_ACTION_TEX_HEIGHT 16 -#define DO_ACTION_TEX_SIZE ((DO_ACTION_TEX_WIDTH * DO_ACTION_TEX_HEIGHT) / 2) // (sizeof(gCheckDoActionENGTex)) + +static uint16_t _doActionTexWidth, _doActionTexHeight = -1; +static uint16_t DO_ACTION_TEX_WIDTH() { + return 48; + + // TODO: Figure out why Ship::Texture is not returning a valid width + if (_doActionTexWidth == -1) + _doActionTexWidth = ResourceMgr_LoadTexWidthByName(gCheckDoActionENGTex); + return _doActionTexWidth; +} +static uint16_t DO_ACTION_TEX_HEIGHT() { + return 16; + + // TODO: Figure out why Ship::Texture is not returning a valid height + if (_doActionTexHeight == -1) + _doActionTexHeight = ResourceMgr_LoadTexHeightByName(gCheckDoActionENGTex); + return _doActionTexHeight; +} + +static uint32_t _doActionTexSize = -1; +static uint32_t DO_ACTION_TEX_SIZE() { + if (_doActionTexSize == -1) + _doActionTexSize = ResourceMgr_LoadTexSizeByName(gCheckDoActionENGTex); + return _doActionTexSize; +} // The button statuses include the A button when most things are only the equip item buttons // So, when indexing into it with a item button index, we need to adjust @@ -2457,8 +2478,8 @@ void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 l if (action != DO_ACTION_NONE) { //osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), ResourceMgr_LoadTexByName(doAction), - DO_ACTION_TEX_SIZE); + memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE()), ResourceMgr_LoadTexByName(doAction), + DO_ACTION_TEX_SIZE()); //DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, //interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), //(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, @@ -2467,7 +2488,7 @@ void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 l } else { gSegments[7] = VIRTUAL_TO_PHYSICAL(interfaceCtx->doActionSegment); //func_80086D5C(SEGMENTED_TO_VIRTUAL(sDoActionTextures[loadOffset]), DO_ACTION_TEX_SIZE / 4); - func_80086D5C(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE / 4); + func_80086D5C(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE()), DO_ACTION_TEX_SIZE() / 4); } } @@ -2545,7 +2566,7 @@ void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) { // OTRTODO osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE); + memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE(), ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE()); //DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, //(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, 0, //&interfaceCtx->loadQueue, NULL, __FILE__, __LINE__); @@ -3181,7 +3202,7 @@ void func_80088B34(s16 arg0) { void Interface_DrawActionLabel(GraphicsContext* gfxCtx, void* texture) { OPEN_DISPS(gfxCtx); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, texture, G_IM_FMT_IA, DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, + gDPLoadTextureBlock_4b(OVERLAY_DISP++, texture, G_IM_FMT_IA, DO_ACTION_TEX_WIDTH(), DO_ACTION_TEX_HEIGHT(), 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -3254,8 +3275,8 @@ void Interface_DrawItemButtons(GlobalContext* globalCtx) { const s16 rStartLabelY_ori = R_START_LABEL_Y(gSaveContext.language)+Y_Margins_StartBtn; const s16 PosX_StartBtn_ori = OTRGetRectDimensionFromRightEdge(startButtonLeftPos[gSaveContext.language]+X_Margins_StartBtn); const s16 PosY_StartBtn_ori = 16+Y_Margins_StartBtn; - s16 StartBTN_Label_W = DO_ACTION_TEX_WIDTH; - s16 StartBTN_Label_H = DO_ACTION_TEX_HEIGHT; + s16 StartBTN_Label_W = DO_ACTION_TEX_WIDTH(); + s16 StartBTN_Label_H = DO_ACTION_TEX_HEIGHT(); int StartBTN_Label_H_Scaled = StartBTN_Label_H * 1.0f; int StartBTN_Label_W_Scaled = StartBTN_Label_W * 1.0f; int StartBTN_Label_W_factor = (1 << 10) * StartBTN_Label_W / StartBTN_Label_W_Scaled; @@ -3511,10 +3532,11 @@ void Interface_DrawItemButtons(GlobalContext* globalCtx) { } doAction = newName; } - memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE * 2, ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE * 2, G_IM_FMT_IA, - DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, + memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE() * 2, ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE()); + + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE() * 2, G_IM_FMT_IA, + DO_ACTION_TEX_WIDTH(), DO_ACTION_TEX_HEIGHT(), 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); //const s16 rStartLabelX = OTRGetRectDimensionFromRightEdge(R_START_LABEL_X(gSaveContext.language)+Right_HUD_Margin); @@ -4330,7 +4352,7 @@ void Interface_Draw(GlobalContext* globalCtx) { // Invalidate Do Action textures as they may have changed gSPInvalidateTexCache(OVERLAY_DISP++, interfaceCtx->doActionSegment); - gSPInvalidateTexCache(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE); + gSPInvalidateTexCache(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE()); gSPSegment(OVERLAY_DISP++, 0x02, interfaceCtx->parameterSegment); gSPSegment(OVERLAY_DISP++, 0x07, interfaceCtx->doActionSegment); @@ -4630,14 +4652,14 @@ void Interface_Draw(GlobalContext* globalCtx) { PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->bAlpha); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, G_IM_FMT_IA, - DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE(), G_IM_FMT_IA, + DO_ACTION_TEX_WIDTH(), DO_ACTION_TEX_HEIGHT(), 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); R_B_LABEL_DD = (1 << 10) / (WREG(37 + gSaveContext.language) / 100.0f); gSPWideTextureRectangle(OVERLAY_DISP++, BbtnPosX << 2, BbtnPosY << 2, - (BbtnPosX + DO_ACTION_TEX_WIDTH) << 2, - (BbtnPosY + DO_ACTION_TEX_HEIGHT) << 2, G_TX_RENDERTILE, 0, 0, + (BbtnPosX + DO_ACTION_TEX_WIDTH()) << 2, + (BbtnPosY + DO_ACTION_TEX_HEIGHT()) << 2, G_TX_RENDERTILE, 0, 0, R_B_LABEL_DD, R_B_LABEL_DD); } @@ -4846,7 +4868,7 @@ void Interface_Draw(GlobalContext* globalCtx) { if ((interfaceCtx->unk_1EC < 2) || (interfaceCtx->unk_1EC == 3)) { Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment); } else { - Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE); + Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE()); } gDPPipeSync(OVERLAY_DISP++); diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 9071e7a0f..2735ed9b4 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -2110,7 +2110,8 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) { sp2A += 12; } - memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(mapNameTextures[sp2A]), 0x400); + const char* textureName = mapNameTextures[sp2A]; + memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); } else { osSyncPrintf("zoom_name=%d\n", pauseCtx->namedItem); @@ -2123,7 +2124,8 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) { osSyncPrintf("J_N=%d point=%d\n", gSaveContext.language, sp2A); - memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(iconNameTextures[sp2A]), 0x400); + const char* textureName = iconNameTextures[sp2A]; + memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); } pauseCtx->nameDisplayTimer = 0; @@ -3224,8 +3226,12 @@ void KaleidoScope_UpdateCursorSize(PauseContext* pauseCtx) { void KaleidoScope_LoadDungeonMap(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; - memcpy(interfaceCtx->mapSegment, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX]), 0x800); - memcpy(interfaceCtx->mapSegment + 0x800, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX + 1]), 0x800); + char* firstTextureName = sDungeonMapTexs[R_MAP_TEX_INDEX]; + char* secondTextureName = sDungeonMapTexs[R_MAP_TEX_INDEX + 1]; + uint32_t firstTextureSize = ResourceMgr_LoadTexSizeByName(firstTextureName); + + memcpy(interfaceCtx->mapSegment, ResourceMgr_LoadTexByName(firstTextureName), ResourceMgr_LoadTexSizeByName(firstTextureName)); + memcpy(interfaceCtx->mapSegment + (firstTextureSize / 2), ResourceMgr_LoadTexByName(secondTextureName), ResourceMgr_LoadTexSizeByName(secondTextureName)); } void KaleidoScope_UpdateDungeonMap(GlobalContext* globalCtx) { @@ -3403,11 +3409,14 @@ void KaleidoScope_Update(GlobalContext* globalCtx) if (((void)0, gSaveContext.worldMapArea) < 22) { if (gSaveContext.language == LANGUAGE_ENG) { - memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[36 + gSaveContext.worldMapArea]), 0xA00); + const char* textureName = mapNameTextures[36 + gSaveContext.worldMapArea]; + memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); } else if (gSaveContext.language == LANGUAGE_GER) { - memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[58 + gSaveContext.worldMapArea]), 0xA00); + const char* textureName = mapNameTextures[58 + gSaveContext.worldMapArea]; + memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); } else { - memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[80 + gSaveContext.worldMapArea]), 0xA00); + const char* textureName = mapNameTextures[80 + gSaveContext.worldMapArea]; + memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(textureName), ResourceMgr_LoadTexSizeByName(textureName)); } } // OTRTODO - player on pause