From ed967484e31166706a69c142027bc2e7fef1cc48 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sat, 6 Apr 2024 04:25:11 -0600 Subject: [PATCH] First ingame boot --- CMakeLists.txt | 5 +- include/gfx.h | 13 ++++ include/macros.h | 6 ++ src/engine/fox_game.c | 13 +--- src/engine/fox_hud.c | 72 +++++-------------- src/engine/fox_message.c | 14 ++-- src/engine/fox_radio.c | 20 ++---- src/engine/fox_std_lib.c | 63 +++++++++------- src/overlays/ovl_menu/fox_i_menu.c | 7 ++ src/overlays/ovl_menu/fox_map.c | 53 ++++++-------- src/overlays/ovl_menu/fox_title.c | 62 +++++----------- src/port/Engine.cpp | 26 ++++--- src/port/Engine.h | 3 + src/port/Game.cpp | 1 + src/port/resource/importers/AnimFactory.cpp | 44 ++++++++++++ src/port/resource/importers/AnimFactory.h | 11 +++ src/port/resource/importers/LimbFactory.cpp | 32 +++++++++ src/port/resource/importers/LimbFactory.h | 11 +++ .../resource/importers/MessageFactory.cpp | 22 ++++++ src/port/resource/importers/MessageFactory.h | 11 +++ .../importers/MessageLookupFactory.cpp | 26 +++++++ .../resource/importers/MessageLookupFactory.h | 11 +++ src/port/resource/importers/ResourceUtil.h | 15 ++++ .../resource/importers/SkeletonFactory.cpp | 24 +++++++ src/port/resource/importers/SkeletonFactory.h | 11 +++ src/port/resource/type/Animation.cpp | 11 +++ src/port/resource/type/Animation.h | 38 ++++++++++ src/port/resource/type/Limb.cpp | 11 +++ src/port/resource/type/Limb.h | 37 ++++++++++ src/port/resource/type/Message.cpp | 19 +++++ src/port/resource/type/Message.h | 32 +++++++++ src/port/resource/type/ResourceType.h | 18 +++++ src/port/resource/type/Skeleton.cpp | 11 +++ src/port/resource/type/Skeleton.h | 19 +++++ 34 files changed, 577 insertions(+), 195 deletions(-) create mode 100644 src/port/resource/importers/AnimFactory.cpp create mode 100644 src/port/resource/importers/AnimFactory.h create mode 100644 src/port/resource/importers/LimbFactory.cpp create mode 100644 src/port/resource/importers/LimbFactory.h create mode 100644 src/port/resource/importers/MessageFactory.cpp create mode 100644 src/port/resource/importers/MessageFactory.h create mode 100644 src/port/resource/importers/MessageLookupFactory.cpp create mode 100644 src/port/resource/importers/MessageLookupFactory.h create mode 100644 src/port/resource/importers/ResourceUtil.h create mode 100644 src/port/resource/importers/SkeletonFactory.cpp create mode 100644 src/port/resource/importers/SkeletonFactory.h create mode 100644 src/port/resource/type/Animation.cpp create mode 100644 src/port/resource/type/Animation.h create mode 100644 src/port/resource/type/Limb.cpp create mode 100644 src/port/resource/type/Limb.h create mode 100644 src/port/resource/type/Message.cpp create mode 100644 src/port/resource/type/Message.h create mode 100644 src/port/resource/type/ResourceType.h create mode 100644 src/port/resource/type/Skeleton.cpp create mode 100644 src/port/resource/type/Skeleton.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 307c6965..aadeaf23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ include_directories( # Collect source files to build the executable file(GLOB_RECURSE ALL_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - "src/assets/*.c" + # "src/assets/*.c" "src/audio/*.c" "src/audio/*.h" "src/engine/*.c" @@ -107,7 +107,8 @@ list(FILTER ALL_FILES EXCLUDE REGEX "src/overlays/ovl_ending/fox_end2_data.c") list(FILTER ALL_FILES EXCLUDE REGEX "src/sys/sys_timer.c") list(FILTER ALL_FILES EXCLUDE REGEX "src/sys/sys_fault.c") -add_executable(${PROJECT_NAME} ${ALL_FILES} ${GENERATED_SOURCES}) +add_executable(${PROJECT_NAME} ${ALL_FILES} ${GENERATED_SOURCES} + src/port/resource/importers/ResourceUtil.h) ################################################################################ # MSVC runtime library diff --git a/include/gfx.h b/include/gfx.h index 301d4ff1..d34ac252 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -13,6 +13,19 @@ #define RGBA16_GRN(color16) (((color16) >> 6) & 0x1F) #define RGBA16_BLU(color16) (((color16) >> 1) & 0x1F) +#define gDPSetTileCustom(pkt, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + do { \ + gDPPipeSync(pkt); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + } while (0) + #define gDPSetupTile(pkt, fmt, siz, width, height, dw, dh, \ cms, cmt, masks, maskt, shifts, shiftt) \ { \ diff --git a/include/macros.h b/include/macros.h index 0c1c39a8..870be9f3 100644 --- a/include/macros.h +++ b/include/macros.h @@ -65,4 +65,10 @@ extern f32 COS_DEG(f32 angle); #define __attribute__(x) #endif +#if defined(_WIN32) + #define ALIGN_ASSET(x) __declspec(align(x)) +#else + #define ALIGN_ASSET(x) __attribute__((aligned (x))) +#endif + #endif // MACROS_H diff --git a/src/engine/fox_game.c b/src/engine/fox_game.c index a02b7da9..6a32f54d 100644 --- a/src/engine/fox_game.c +++ b/src/engine/fox_game.c @@ -333,6 +333,7 @@ void Game_Update(void) { if (D_Timer_8017783C != 0) { D_Timer_8017783C--; } + switch (gGameState) { case GSTATE_BOOT: D_Timer_8017783C = 2; @@ -346,11 +347,7 @@ void Game_Update(void) { case GSTATE_SHOW_LOGO: RCP_SetupDL(&gMasterDisp, 0x4C); gDPSetPrimColor(gMasterDisp++, 0x00, 0x00, 255, 255, 255, 255); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 0], 128, 16, 100.0f, 86.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 1], 128, 16, 100.0f, 102.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 2], 128, 16, 100.0f, 118.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 3], 128, 16, 100.0f, 134.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 4], 128, 10, 100.0f, 150.0f, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gNintendoLogo, 128, 74, 100.0f, 86.0f, 1.0f, 1.0f); gGameState++; break; case GSTATE_CHECK_SAVE: @@ -364,11 +361,7 @@ void Game_Update(void) { case GSTATE_LOGO_WAIT: RCP_SetupDL(&gMasterDisp, 0x4C); gDPSetPrimColor(gMasterDisp++, 0x00, 0x00, 255, 255, 255, 255); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 0], 128, 16, 100.0f, 86.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 1], 128, 16, 100.0f, 102.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 2], 128, 16, 100.0f, 118.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 3], 128, 16, 100.0f, 134.0f, 1.0f, 1.0f); - TextureRect_8bIA(&gMasterDisp, &gNintendoLogo[128 * 16 * 4], 128, 10, 100.0f, 150.0f, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gNintendoLogo, 128, 74, 100.0f, 86.0f, 1.0f, 1.0f); break; case GSTATE_START: gGameState = GSTATE_INIT; diff --git a/src/engine/fox_hud.c b/src/engine/fox_hud.c index 2db59f19..3688dea6 100644 --- a/src/engine/fox_hud.c +++ b/src/engine/fox_hud.c @@ -274,7 +274,7 @@ void func_hud_8008566C(f32 x, f32 y, f32 arg2, f32 arg3) { } void func_hud_800856C0(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4) { - func_hud_80084E78(&gMasterDisp, &D_1013580, &D_1013700, 48, 12, arg0, arg1, arg2, arg3, 48.0f * arg4, 8.0f); + func_hud_80084E78(&gMasterDisp, D_1013580, D_1013700, 48, 12, arg0, arg1, arg2, arg3, 48.0f * arg4, 8.0f); } void func_hud_80085740(f32 arg0, f32 arg1, f32 arg2, f32 arg3) { @@ -583,10 +583,7 @@ void func_hud_80086444(void) { RCP_SetupDL(&gMasterDisp, 0x4C); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - for (j = 0; j < 19; j++) { - TextureRect_8bIA(&gMasterDisp, D_800D1C9C[i] + (D_800D1CA4[i] * j), D_800D1CA4[i], 1, D_800D1CB4[i], - D_800D1CBC[i] + j - 28.0f, 1.0f, 1.0f); - } + TextureRect_8bIA(&gMasterDisp, D_800D1C9C[i], D_800D1CA4[i], 19, D_800D1CB4[i], D_800D1CBC[i] - 28.0f, 1.0f, 1.0f); } } @@ -664,10 +661,7 @@ void func_hud_80086664(f32 x, f32 y) { func_hud_80086444(); } - for (i = 0; i < D_800D1AEC[j].unk_14; i++) { - TextureRect_8bIA(&gMasterDisp, D_800D1AEC[j].unk_0C + (D_800D1AEC[j].unk_10 * i), D_800D1AEC[j].unk_10, 1, x2, - y2 + i, 1.0f, 1.0f); - } + TextureRect_8bIA(&gMasterDisp, D_800D1AEC[j].unk_0C, D_800D1AEC[j].unk_10, D_800D1AEC[j].unk_14, x2, y2, 1.0f, 1.0f); if ((D_ctx_80177CA0 == 0) && (D_360_8015F924 == 0) && (gCurrentLevel != LEVEL_VENOM_ANDROSS) && (gCurrentLevel != LEVEL_TRAINING)) { @@ -861,36 +855,16 @@ void func_hud_80086DCC(void) { switch (temp) { case 1: if (boolTemp) { - for (i = 0; i < 11; i++) { - TextureRect_8bIA(&gMasterDisp, D_5002DC0 + (136 * 2 * i), 136, 2, x + 50.0f, y + 50.0f + (2 * i), - 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, D_5002DC0 + (136 * 2 * i), 136, 1, x + 50.0f, y + 50.0f + (2 * i), 1.0f, - 1.0f); + TextureRect_8bIA(&gMasterDisp, D_5002DC0, 136, 23, x + 50.0f, y + 50.0f, 1.0f, 1.0f); } else { - for (i = 0; i < 10; i++) { - TextureRect_8bIA(&gMasterDisp, D_5004E20 + (80 * 2 * i), 80, 2, x + 66.0f, y + 50.0f + (2 * i), - 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, D_5004E20 + (80 * 2 * i), 80, 1, x + 66.0f, y + 50.0f + (2 * i), 1.0f, - 1.0f); + TextureRect_8bIA(&gMasterDisp, D_5004E20, 80, 21, x + 66.0f, y + 50.0f, 1.0f, 1.0f); } case 2: if (boolTemp) { - for (i = 0; i < 11; i++) { - TextureRect_8bIA(&gMasterDisp, D_50022F0 + (120 * 2 * i), 120, 2, x - 62.0f, y + 50.0f + (2 * i), - 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, D_50022F0 + (120 * 2 * i), 120, 1, x - 62.0f, y + 50.0f + (2 * i), 1.0f, - 1.0f); + TextureRect_8bIA(&gMasterDisp, D_50022F0, 120, 23, x - 62.0f, y + 50.0f, 1.0f, 1.0f); } else { - for (i = 0; i < 11; i++) { - TextureRect_8bIA(&gMasterDisp, D_5004580 + (96 * 2 * i), 96, 2, x - 22.0f, y + 50.0f + (2 * i), - 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, D_5004580 + (96 * 2 * i), 96, 1, x - 22.0f, y + 50.0f + (2 * i), 1.0f, - 1.0f); + TextureRect_8bIA(&gMasterDisp, D_5004580, 96, 23, x - 22.0f, y + 50.0f, 1.0f, 1.0f); } case 3: @@ -1021,11 +995,7 @@ void func_hud_80087788(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); } - for (i = 0; i < 2; i++) { - TextureRect_16bRGBA(&gMasterDisp, D_800D1D18[j + 1] + (44 * 20 * i), 44, 20, x[j][0], - y[j][0] + (f32) (20 * i), 1.0f, 1.0f); - } - TextureRect_16bRGBA(&gMasterDisp, D_800D1D18[j + 1] + (44 * 40), 44, 4, x[j][0], y[j][0] + 40.0f, 1.0f, 1.0f); + TextureRect_16bRGBA(&gMasterDisp, D_800D1D18[j + 1], 44, 44, x[j][0], y[j][0], 1.0f, 1.0f); func_hud_80086110(x[j][2], y[j][2], shield); } @@ -1637,10 +1607,7 @@ void func_hud_80088970(void) { RCP_SetupDL(&gMasterDisp, 0x4C); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - for (i = 0; i < D_800D1AEC[j].unk_14; i++) { - TextureRect_8bIA(&gMasterDisp, D_800D1AEC[j].unk_0C + (D_800D1AEC[j].unk_10 * i), - D_800D1AEC[j].unk_10, 1, x2, y2 + i, 1.0f, 1.0f); - } + TextureRect_8bIA(&gMasterDisp, D_800D1AEC[j].unk_0C, D_800D1AEC[j].unk_10, D_800D1AEC[j].unk_14, x2, y2 + i, 1.0f, 1.0f); func_hud_80086C08(x1 - 10.0f, y0 - 4.0f, 4.7f, 2.8f); @@ -2592,7 +2559,7 @@ s32 func_hud_8008BCBC(s32 arg0) { } void func_hud_8008BD00(u8* texturePtr, s32 xPos, s32 yPos, u8 arg3) { - u8* texture = SEGMENTED_TO_VIRTUAL(texturePtr); + u8* texture = LOAD_ASSET(texturePtr); u8 temp; s32 x; s32 y; @@ -2655,8 +2622,8 @@ void func_hud_8008C104(u16* texture, u16* arg1) { s32 temp3; s32 temp2; - temp = SEGMENTED_TO_VIRTUAL(texture); - dst = SEGMENTED_TO_VIRTUAL(arg1); + temp = LOAD_ASSET(texture); + dst = LOAD_ASSET(arg1); Texture_Scroll(texture, width, height, 1); @@ -2718,11 +2685,7 @@ void func_hud_8008C5C8(f32 arg0, f32 arg1, f32 arg2, s32 arg3) { }; s32 i; - for (i = 0; i < 2; i++) { - TextureRect_16bRGBA(&gMasterDisp, D_800D1EE8[arg3] + (880 * i), 44, 20, arg0, (20 * i * arg2) + arg1, arg2, - arg2); - } - TextureRect_16bRGBA(&gMasterDisp, D_800D1EE8[arg3] + 1760, 44, 4, arg0, (40.0f * arg2) + arg1, arg2, arg2); + TextureRect_16bRGBA(&gMasterDisp, D_800D1EE8[arg3], 44, 44, arg0, arg1, arg2, arg2); } void func_hud_8008C6F4(s32 idx, s32 arg1) { @@ -2870,12 +2833,9 @@ void func_hud_8008CBE4(void) { void func_hud_8008CFB8(f32 arg0, f32 arg1, f32 arg2, f32 arg3) { s32 i; - for (i = 0; i < 3; i++) { - TextureRect_8bIA(&gMasterDisp, D_versus_3000BC0 + 2 * ((640 * i) / 2), 80, 8, arg0, (8 * i * arg3) + arg1, arg2, - arg3); - } - TextureRect_8bIA(&gMasterDisp, D_versus_3000BC0 + 2 * ((640 * i) / 2), 80, 2, arg0, (8 * i * arg3) + arg1, arg2, - arg3); + // LTodo: [HD-Texture] Is broken + u8* texture = (u8*) LOAD_ASSET(D_versus_3000BC0); + TextureRect_8bIA(&gMasterDisp, texture + 2 * ((640 * i) / 2), 80, 8, arg0, (8 * i * arg3) + arg1, arg2, arg3); } void func_hud_8008D0DC(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4) { diff --git a/src/engine/fox_message.c b/src/engine/fox_message.c index 2c2051de..874169ed 100644 --- a/src/engine/fox_message.c +++ b/src/engine/fox_message.c @@ -3,7 +3,7 @@ u16* Message_PtrFromId(u16 msgId) { s32 i; - MsgLookup* lookup = gMsgLookup; + MsgLookup* lookup = (MsgLookup*) LOAD_ASSET(gMsgLookup); while (lookup->msgId != -1) { if (lookup->msgId == msgId) { @@ -16,7 +16,7 @@ u16* Message_PtrFromId(u16 msgId) { u16 Message_IdFromPtr(u16* msgPtr) { s32 i; - MsgLookup* lookup = gMsgLookup; + MsgLookup* lookup = (MsgLookup*) LOAD_ASSET(gMsgLookup); while (lookup->msgPtr != NULL) { if (lookup->msgPtr == msgPtr) { @@ -29,7 +29,7 @@ u16 Message_IdFromPtr(u16* msgPtr) { s32 Message_GetWidth(u16* msgPtr) { s32 width = 0; - u16* msgChar = msgPtr; + u16* msgChar = LOAD_ASSET(msgPtr); while (*msgChar != MSGCHAR_END) { if (*msgChar > 15 || *msgChar == 12) { @@ -42,7 +42,7 @@ s32 Message_GetWidth(u16* msgPtr) { s32 Message_GetCharCount(u16* msgPtr) { s32 count = 0; - u16* msgChar = msgPtr; + u16* msgChar = LOAD_ASSET(msgPtr); #if MODS_LEVEL_SELECT == 1 if (gCurrentPlanet == 6) { @@ -58,7 +58,8 @@ s32 Message_GetCharCount(u16* msgPtr) { } void Message_DisplayChar(Gfx** gfxPtr, u16 msgChar, s32 xpos, s32 ypos) { - gDPLoadTextureBlock_4b((*gfxPtr)++, gTextCharTextures[msgChar >> 2], G_IM_FMT_CI, 16, 13, msgChar & 3, + const char* mChar = gTextCharTextures[msgChar >> 2]; + gDPLoadTextureBlock_4b((*gfxPtr)++, mChar, G_IM_FMT_CI, 16, 13, msgChar & 3, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPTextureRectangle((*gfxPtr)++, xpos << 2, ypos << 2, (xpos + 13) << 2, (ypos + 13) << 2, G_TX_RENDERTILE, 64, 0, @@ -70,6 +71,7 @@ bool Message_DisplayText(Gfx** gfxPtr, u16* msgPtr, s32 xPos, s32 yPos, s32 len) s32 yChar = yPos; s32 i; s32 print = false; + msgPtr = LOAD_ASSET(msgPtr); gDPSetPrimColor((*gfxPtr)++, 0x00, 0x00, 255, 255, 255, 255); gDPSetTextureLUT((*gfxPtr)++, G_TT_RGBA16); @@ -121,6 +123,7 @@ void Message_DisplayScrollingText(Gfx** gfxPtr, u16* msgPtr, s32 xPos, s32 yPos, s32 var_s2 = xPos; s32 var_s4 = yPos; s32 i; + msgPtr = LOAD_ASSET(msgPtr); gDPSetTextureLUT((*gfxPtr)++, G_TT_RGBA16); gDPLoadTLUT((*gfxPtr)++, 64, 256, gTextCharPalettes); @@ -165,6 +168,7 @@ void Message_DisplayScrollingText(Gfx** gfxPtr, u16* msgPtr, s32 xPos, s32 yPos, bool Message_IsPrintingChar(u16* msgPtr, s32 charPos) { s32 i; s32 print; + msgPtr = LOAD_ASSET(msgPtr); // bug: if the for loop is skipped, print is never initialized for (i = 0; msgPtr[i] != 0 && i < charPos; i++) { diff --git a/src/engine/fox_radio.c b/src/engine/fox_radio.c index de4b97ae..db4795b1 100644 --- a/src/engine/fox_radio.c +++ b/src/engine/fox_radio.c @@ -56,6 +56,7 @@ void Radio_PlayMessage(u16* msg, RadioCharacterId character) { s32 var_v1; s32 temp_v0; s32 priority; + msg = LOAD_ASSET(msg); switch (msg[0]) { default: @@ -156,7 +157,6 @@ void func_radio_800BAAE8(void) { s32 i; f32 sp38; f32 temp_fa0; - s32 j; D_radio_80178744 = 0; @@ -425,21 +425,13 @@ void func_radio_800BAAE8(void) { gDPSetPrimColor(gMasterDisp++, 0x00, 0x00, 255, 255, 255, 255); if (mirror) { - for (i = 0, j = 0; i < 2; i++, j += 880) { - TextureRect_16bRGBA_MirX(&gMasterDisp, &sp44[j], 44, 20, D_radio_8017873C, - D_radio_80178740 + 20.0f + sp38 + (i * 20.0f * D_ctx_80177D38), 1.0f, + TextureRect_16bRGBA_MirX(&gMasterDisp, sp44, 44, 44, D_radio_8017873C, + D_radio_80178740 + 20.0f + sp38 + D_ctx_80177D38, 1.0f, D_ctx_80177D38); - } - TextureRect_16bRGBA_MirX(&gMasterDisp, &sp44[2 * 880], 44, 4, D_radio_8017873C, - D_radio_80178740 + 20.0f + sp38 + (40.0f * D_ctx_80177D38), 1.0f, D_ctx_80177D38); } else { - for (i = 0, j = 0; i < 2; i++, j += 880) { - TextureRect_16bRGBA(&gMasterDisp, &sp44[j], 44, 20, D_radio_8017873C, - D_radio_80178740 + 20.0f + sp38 + (i * 20.0f * D_ctx_80177D38), 1.0f, - D_ctx_80177D38); - } - TextureRect_16bRGBA(&gMasterDisp, &sp44[2 * 880], 44, 4, D_radio_8017873C, - D_radio_80178740 + 20.0f + sp38 + (40.0f * D_ctx_80177D38), 1.0f, D_ctx_80177D38); + TextureRect_16bRGBA(&gMasterDisp, sp44, 44, 44, D_radio_8017873C, + D_radio_80178740 + 20.0f + sp38 + D_ctx_80177D38, 1.0f, + D_ctx_80177D38); } } } diff --git a/src/engine/fox_std_lib.c b/src/engine/fox_std_lib.c index 5390c969..f3f4fcc8 100644 --- a/src/engine/fox_std_lib.c +++ b/src/engine/fox_std_lib.c @@ -26,7 +26,7 @@ s32 Graphics_Printf(const char* fmt, ...) { } void Texture_Scroll(u16* texture, s32 width, s32 height, u8 mode) { - u16* temp_t0 = SEGMENTED_TO_VIRTUAL(texture); + u16* temp_t0 = LOAD_ASSET(texture); u16 temp_a3; s32 var_a0; s32 var_t4; @@ -81,8 +81,8 @@ void Texture_Mottle(u16* dst, u16* src, u8 mode) { u8* var_s4_2; s32 temp_ft3; - dst = SEGMENTED_TO_VIRTUAL(dst); - src = SEGMENTED_TO_VIRTUAL(src); + dst = LOAD_ASSET(dst); + src = LOAD_ASSET(src); switch (mode) { case 2: for (var_s3 = 0; var_s3 < 32 * 32; var_s3 += 32) { @@ -154,6 +154,7 @@ void Animation_DrawLimb(s32 mode, Limb* limb, Limb** skeleton, Vec3f* jointTable Matrix_Push(&gCalcMatrix); + skeleton = LOAD_ASSET(skeleton); limbIndex = Animation_GetLimbIndex(limb, skeleton); limb = SEGMENTED_TO_VIRTUAL(limb); rot = jointTable[limbIndex]; @@ -211,7 +212,7 @@ void Animation_DrawSkeleton(s32 mode, Limb** skeletonSegment, Vec3f* jointTable, Matrix_Push(&gCalcMatrix); Matrix_Copy(gCalcMatrix, transform); - skeleton = SEGMENTED_TO_VIRTUAL(skeletonSegment); + skeleton = LOAD_ASSET(skeletonSegment); rootLimb = SEGMENTED_TO_VIRTUAL(skeleton[0]); rootIndex = Animation_GetLimbIndex(skeleton[0], skeleton); baseRot = jointTable[rootIndex]; @@ -255,8 +256,8 @@ void Animation_DrawSkeleton(s32 mode, Limb** skeletonSegment, Vec3f* jointTable, } } -s16 Animation_GetFrameData(Animation* animationSegmemt, s32 frame, Vec3f* frameTable) { - Animation* animation = SEGMENTED_TO_VIRTUAL(animationSegmemt); +s16 Animation_GetFrameData(Animation* anim, s32 frame, Vec3f* frameTable) { + Animation* animation = LOAD_ASSET(anim); u16 var4 = animation->limbCount; JointKey* key = SEGMENTED_TO_VIRTUAL(animation->jointKey); u16* frameData = SEGMENTED_TO_VIRTUAL(animation->frameData); @@ -282,8 +283,8 @@ s16 Animation_GetFrameData(Animation* animationSegmemt, s32 frame, Vec3f* frameT return var4 + 1; } -s32 Animation_GetFrameCount(Animation* animationSegment) { - Animation* animation = SEGMENTED_TO_VIRTUAL(animationSegment); +s32 Animation_GetFrameCount(Animation* anim) { + Animation* animation = LOAD_ASSET(anim); return animation->frameCount; } @@ -355,12 +356,12 @@ void Animation_GetSkeletonBoundingBox(Limb** skeletonSegment, Animation* animati Vec3f boundBox[8]; Vec3f boundBoxRot[8]; s32 i; - Limb** skeleton = (Limb**) SEGMENTED_TO_VIRTUAL(skeletonSegment); + Limb** skeleton = LOAD_ASSET(skeletonSegment); - limb = (Limb*) SEGMENTED_TO_VIRTUAL(skeleton[0]); - animation = (Animation*) SEGMENTED_TO_VIRTUAL(animationSegment); - key = (JointKey*) SEGMENTED_TO_VIRTUAL(animation->jointKey); - frameData = (u16*) SEGMENTED_TO_VIRTUAL(animation->frameData); + limb = SEGMENTED_TO_VIRTUAL(skeleton[0]); + animation = LOAD_ASSET(animationSegment); + key = SEGMENTED_TO_VIRTUAL(animation->jointKey); + frameData = SEGMENTED_TO_VIRTUAL(animation->frameData); if (frame < (s16) key[1].zLen) { var_t6 = frameData[(s16) key[1].z + frame]; @@ -589,10 +590,14 @@ void TextureRect_8bCI(Gfx** gfxPtr, void* texture, void* palette, u32 width, u32 (s32) (1.0f / yScale * 1024.0f)); } -void TextureRect_16bRGBA(Gfx** gfxPtr, void* texture, u32 width, u32 height, f32 xPos, f32 yPos, f32 xScale, - f32 yScale) { - gDPLoadTextureBlock((*gfxPtr)++, texture, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 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); +void TextureRect_16bRGBA(Gfx** gfxPtr, void* texture, u32 width, u32 height, f32 xPos, f32 yPos, f32 xScale, f32 yScale) { + gDPSetTileCustom((*gfxPtr)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + + gDPSetTextureImage((*gfxPtr)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, texture); + gDPLoadSync((*gfxPtr)++); + gDPLoadTile((*gfxPtr)++, G_TX_LOADTILE, 0, 0, width - 1 << 2, height - 1 << 2); + gSPTextureRectangle((*gfxPtr)++, (s32) (xPos * 4.0f), (s32) (yPos * 4.0f), (s32) ((xPos + width * xScale) * 4.0f), (s32) ((yPos + height * yScale) * 4.0f), 0, 0, 0, (s32) (1.0f / xScale * 1024.0f), (s32) (1.0f / yScale * 1024.0f)); @@ -600,16 +605,26 @@ void TextureRect_16bRGBA(Gfx** gfxPtr, void* texture, u32 width, u32 height, f32 void TextureRect_16bRGBA_MirX(Gfx** gfxPtr, void* texture, u32 width, u32 height, f32 xPos, f32 yPos, f32 xScale, f32 yScale) { - gDPLoadTextureBlock((*gfxPtr)++, texture, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 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); + gDPSetTileCustom((*gfxPtr)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + + gDPSetTextureImage((*gfxPtr)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, texture); + gDPLoadSync((*gfxPtr)++); + gDPLoadTile((*gfxPtr)++, G_TX_LOADTILE, 0, 0, width - 1 << 2, height - 1 << 2); + gSPTextureRectangle((*gfxPtr)++, (s32) (xPos * 4.0f), (s32) (yPos * 4.0f), (s32) ((xPos + width * xScale) * 4.0f), (s32) ((yPos + height * yScale) * 4.0f), G_TX_RENDERTILE, (width - 1) * 32, 0, (u16) (s32) (-1.0f / xScale * 1024.0f), (s32) (1.0f / yScale * 1024.0f)); } void TextureRect_8bIA(Gfx** gfxPtr, void* texture, u32 width, u32 height, f32 xPos, f32 yPos, f32 xScale, f32 yScale) { - gDPLoadTextureBlock((*gfxPtr)++, texture, G_IM_FMT_IA, G_IM_SIZ_8b, width, 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); + gDPSetTileCustom((*gfxPtr)++, G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + + gDPSetTextureImage((*gfxPtr)++, G_IM_FMT_IA, G_IM_SIZ_8b, width, texture); + gDPLoadSync((*gfxPtr)++); + gDPLoadTile((*gfxPtr)++, G_TX_LOADTILE, 0, 0, width - 1 << 2, height - 1 << 2); + gSPTextureRectangle((*gfxPtr)++, (s32) (xPos * 4.0f), (s32) (yPos * 4.0f), (s32) ((xPos + width * xScale) * 4.0f), (s32) ((yPos + height * yScale) * 4.0f), 0, 0, 0, (s32) (1.0f / xScale * 1024.0f), (s32) (1.0f / yScale * 1024.0f)); @@ -1187,9 +1202,9 @@ void func_stdlib_800A1540(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { // 20 kinds of fake. Try to improve it here: https://decomp.me/scratch/NMQZB void Texture_BlendRGBA16(f32 weight, u16 size, u16* src1, u16* src2, u16* dst) { s32 i; - u16* var_a1 = SEGMENTED_TO_VIRTUAL(src1); - u16* var_a2 = SEGMENTED_TO_VIRTUAL(src2); - u16* var_a3 = SEGMENTED_TO_VIRTUAL(dst); + u16* var_a1 = LOAD_ASSET(src1); + u16* var_a2 = LOAD_ASSET(src2); + u16* var_a3 = LOAD_ASSET(dst); u16 temp1; u16 temp2; u16 temp3; diff --git a/src/overlays/ovl_menu/fox_i_menu.c b/src/overlays/ovl_menu/fox_i_menu.c index 4f1b3ba3..dcc5dd54 100644 --- a/src/overlays/ovl_menu/fox_i_menu.c +++ b/src/overlays/ovl_menu/fox_i_menu.c @@ -12,6 +12,8 @@ void Map_801A01A8(void); s32 D_menu_801B7BA0; s32 D_menu_801AD9F0 = 0; +extern void Title_8018F77C(void); + void OvlMenu_CallFunction(u32 mode, void* ptr) { switch (mode) { case 103: @@ -44,6 +46,11 @@ void OvlMenu_CallFunction(u32 mode, void* ptr) { case 110: Map_8019E8C8(); + break; + + case 999: + Title_8018F77C(); + break; default: break; diff --git a/src/overlays/ovl_menu/fox_map.c b/src/overlays/ovl_menu/fox_map.c index 13a47e95..a02579e7 100644 --- a/src/overlays/ovl_menu/fox_map.c +++ b/src/overlays/ovl_menu/fox_map.c @@ -2022,12 +2022,16 @@ void Map_801A0788(void) { } void Map_801A07E8(u8* arg0, u8* arg1, f32* arg2) { + return; s32* var_v0 = D_menu_801B0004; s32 temp; s32 i; s32 j; s32 k; + arg0 = LOAD_ASSET(arg0); + arg1 = LOAD_ASSET(arg1); + for (i = 1; i < 48; i++, var_v0++) { for (k = 0, j = *var_v0; j < (95 - *var_v0); j++, k++) { temp = D_menu_801B00C0[i - 1][k] + (s32) *arg2; @@ -2156,13 +2160,14 @@ void Map_801A0954(void) { } } +static const char* D_menu_801B6954[] = { + D_MAP_6041A80, D_MAP_6035780, D_MAP_6033080, D_MAP_603A580, D_MAP_603F380, D_MAP_6037E80, D_MAP_603CC80, +}; + void Map_801A0D14(void) { s32 i; static f32 D_menu_801B694C = 71.0f; static f32 D_menu_801B6950 = 205.0f; - static u16* D_menu_801B6954[] = { - D_MAP_6041A80, D_MAP_6035780, D_MAP_6033080, D_MAP_603A580, D_MAP_603F380, D_MAP_6037E80, D_MAP_603CC80, - }; Map_801A116C(); @@ -2187,18 +2192,12 @@ void Map_801A0D14(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, D_menu_801CD9E8); - for (i = 0; i < 13; i++) { - TextureRect_16bRGBA(&gMasterDisp, D_menu_801B6954[D_menu_801CD9F0] + (96 * 4 * i), 96, 4, 109.0f, - 24.0f + (4.0f * i), 1.0f, 1.0f); - } + TextureRect_16bRGBA(&gMasterDisp, D_menu_801B6954[D_menu_801CD9F0], 96, 52, 109.0f, 24.0f, 1.0f, 1.0f); if ((D_menu_801CD9E4 != 0) && (D_menu_801CD9F0 + 1 < 7)) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, D_menu_801CD9E4); - for (i = 0; i < 13; i++) { - TextureRect_16bRGBA(&gMasterDisp, D_menu_801B6954[D_menu_801CD9F0 + 1] + (i * 96 * 4), 96, 4, 109.0f, - 24.0f + (i * 4.0f), 1.0f, 1.0f); - } + TextureRect_16bRGBA(&gMasterDisp, D_menu_801B6954[D_menu_801CD9F0 + 1], 96, 52, 109.0f, 24.0f, 1.0f, 1.0f); if (D_menu_801CD9E4 == 255) { D_menu_801CD9E4 = 0; @@ -2378,10 +2377,7 @@ void Map_801A19A8(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, (s32) D_menu_801CEA9C); - for (i = 0; i < 4; i++) { - TextureRect_8bIA(&gMasterDisp, D_MAP_600D590 + (i * 168 * 4), 168, 4, 72.0f, 104.0f + (4.0f * i), 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, D_MAP_600D590 + (168 * 16), 168, 3, 72.0f, 104.0f + 16.0f, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, D_MAP_600D590, 168, 19, 72.0f, 104.0f, 1.0f, 1.0f); } void Map_801A1AE8(void) { @@ -5306,11 +5302,8 @@ void Map_801A9910(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, (s32) D_menu_801CEA6C); - for (i = 0; i < D_menu_801AF834[var_s0].height; i++) { - TextureRect_8bIA(&gMasterDisp, D_menu_801AF834[var_s0].texture + (D_menu_801AF834[var_s0].width * i), - D_menu_801AF834[var_s0].width, 1, D_menu_801AF834[var_s0].xPos, 20.0f + (1.0f * i), 1.0f, - 1.0f); - } + TextureRect_8bIA(&gMasterDisp, D_menu_801AF834[var_s0].texture, + D_menu_801AF834[var_s0].width, D_menu_801AF834[var_s0].height, D_menu_801AF834[var_s0].xPos, 20.0f, 1.0f, 1.0f); Math_SmoothStepToF(&D_menu_801CEA6C, 255.0f, D_menu_801CEA70, 10.0f, 1.0f); @@ -5411,18 +5404,18 @@ void Map_801A9A8C(void) { } #endif - TextureRect_8bIA(&gMasterDisp, &D_5000500, 112, 19, D_menu_801B6AC0[0], D_menu_801B6AC8[0], 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, D_5000500, 112, 19, D_menu_801B6AC0[0], D_menu_801B6AC8[0], 1.0f, 1.0f); TextureRect_8bIA(&gMasterDisp, sp54, 16, 15, D_menu_801B6AC0[1], D_menu_801B6AC8[1], 1.0f, 1.0f); for (i = 0; i < D_menu_801AF834[sp58].height; i++) { - TextureRect_8bIA(&gMasterDisp, D_menu_801AF834[sp58].texture + (D_menu_801AF834[sp58].width * i), - D_menu_801AF834[sp58].width, 1, D_menu_801AF834[sp58].xPos, 94.0f + (1.0f * i), 1.0f, 1.0f); + } - for (i = 0; i < D_menu_801AF914[sp58].height; i++) { - TextureRect_8bIA(&gMasterDisp, D_menu_801AF914[sp58].texture + (D_menu_801AF914[sp58].width * i), - D_menu_801AF914[sp58].width, 1, D_menu_801AF914[sp58].xPos, 140.0f + (1.0f * i), 1.0f, 1.0f); - } + TextureRect_8bIA(&gMasterDisp, D_menu_801AF834[sp58].texture, D_menu_801AF834[sp58].width, D_menu_801AF834[sp58].height, + D_menu_801AF834[sp58].xPos, 94.0f, 1.0f, 1.0f); + + TextureRect_8bIA(&gMasterDisp, D_menu_801AF914[sp58].texture, D_menu_801AF914[sp58].width, D_menu_801AF914[sp58].height, + D_menu_801AF914[sp58].xPos, 140.0f, 1.0f, 1.0f); } void Map_801A9DE8(void) { @@ -5975,11 +5968,7 @@ void Map_801AB978(s32 arg0) { xPos = 205.0f; yPos = 77.0f; - for (i = 0; i < 12; i++) { - TextureRect_16bRGBA(&gMasterDisp, D_MAP_6044820 + (i * 92 * 4), 92, 4, xPos, yPos + (i * 4.0f), - 1.0f, 1.0f); - } - TextureRect_16bRGBA(&gMasterDisp, D_MAP_6044820 + (92 * 12 * 4), 92, 3, xPos, yPos + 48.0f, 1.0f, 1.0f); + TextureRect_16bRGBA(&gMasterDisp, D_MAP_6044820, 92, 51, xPos, yPos, 1.0f, 1.0f); if (arg0 == 21) { TextureRect_16bRGBA(&gMasterDisp, D_MAP_6046CD0, 32, 34, xPos + 47.0, yPos, 1.0f, 1.0f); diff --git a/src/overlays/ovl_menu/fox_title.c b/src/overlays/ovl_menu/fox_title.c index 156708de..10155bd4 100644 --- a/src/overlays/ovl_menu/fox_title.c +++ b/src/overlays/ovl_menu/fox_title.c @@ -396,6 +396,9 @@ void Title_80187B00(void) { void Title_80187CA8(void) { static char D_menu_801ADA44[] = "S T A R F O X R A N K I N G"; + + // LTodo: [HD-Texture] Is Broken + uint8_t* D_5007690_Data = LOAD_ASSET_RAW(D_5007690); s32 temp = 20; s32 temp2 = 36; @@ -414,7 +417,7 @@ void Title_80187CA8(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - TextureRect_8bIA(&gMasterDisp, &D_5007690[48 * 6], 16, 2, 36, 32, 15.2f, 1.0f); + TextureRect_8bIA(&gMasterDisp, &D_5007690_Data[48 * 6], 16, 2, 36, 32, 15.2f, 1.0f); Title_80187E28(); } @@ -2813,15 +2816,11 @@ void Title_8018F438(void) { } void Title_8018F680(void) { - s32 i; - RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - for (i = 0; i < 30; i++) { - TextureRect_16bRGBA(&gMasterDisp, gTitleStarfoxLogo + (i * 472), 236, 2, D_menu_801B9054, - D_menu_801B9058 + (i * 2.0f), 1.0f, 1.0f); - } + // LTodo: Validate this + TextureRect_16bRGBA(&gMasterDisp, gTitleStarfoxLogo, 236, 60, D_menu_801B9054, D_menu_801B9058, 1.0f, 1.0f); } void Title_8018F77C(void) { @@ -2867,25 +2866,19 @@ void Title_8018F8E4(void) { gDPSetPrimColor(gMasterDisp++, 0, 0, 60, 60, 255, 200); - TextureRect_8bCI(&gMasterDisp, &D_TITLE_601D750, &D_TITLE_601DB50, 32, 32, D_menu_801AE464, D_menu_801AE468, + TextureRect_8bCI(&gMasterDisp, D_TITLE_601D750, D_TITLE_601DB50, 32, 32, D_menu_801AE464, D_menu_801AE468, D_menu_801AE46C, D_menu_801AE470); RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, (s32) D_menu_801B7BC8, (s32) D_menu_801B7BC8, 255); - for (i = 0; i < 6; i++) { - TextureRect_8bIA(&gMasterDisp, gTitleNoController + (704 * i), 176, 4, D_menu_801AE474, - D_menu_801AE478 + (i * 4.0f), 1.0f, 1.0f); - } + TextureRect_8bIA(&gMasterDisp, gTitleNoController, 176, 24, D_menu_801AE474, + D_menu_801AE478, 1.0f, 1.0f); } else { RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, (s32) D_menu_801B7BC8, (s32) D_menu_801B7BC8, 255); - for (i = 0; i < 2; i++) { - TextureRect_8bIA(&gMasterDisp, gTitlePressStart + (i * 720), 120, 6, 101.0f, temp2 + (i * 6.0f), 1.0f, - 1.0f); - } - TextureRect_8bIA(&gMasterDisp, gTitlePressStart + 1440, 120, 1, 101.0f, temp2 + 12, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gTitlePressStart, 120, 13, 101.0f, temp2, 1.0f, 1.0f); } } } @@ -2896,10 +2889,7 @@ void Title_8018FC14(void) { RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - for (i = 0; i < 2; i++) { - TextureRect_8bIA(&gMasterDisp, gTitleNintendoCopyright + (i * 720), 120, 6, 102.0f, 209.0f + (i * 6.0f), 1.0f, - 1.0f); - } + TextureRect_8bIA(&gMasterDisp, gTitleNintendoCopyright, 120, 12, 102.0f, 209.0f, 1.0f, 1.0f); } void Title_8018FD08(void) { @@ -2928,18 +2918,11 @@ void Title_8018FD08(void) { break; case 2: - for (i = 0; i < 3; i++) { - TextureRect_8bIA(&gMasterDisp, gTitleFalcoCard + (704 * i), 176, 4, temp_fs2, temp + (i * 4), 1.0f, - 1.0f); - } - TextureRect_8bIA(&gMasterDisp, gTitleFalcoCard + 2112, 176, 1, temp_fs2, temp + 12.0f, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gTitleFalcoCard, 176, 13, temp_fs2, temp, 1.0f, 1.0f); break; case 3: - for (i = 0; i < 3; i++) { - TextureRect_8bIA(&gMasterDisp, gTitleFoxCard + (i * 704), 176, 4, temp_fs2, temp + (i * 4), 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, gTitleFoxCard + 2112, 176, 1, temp_fs2, temp + 12, 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gTitleFoxCard, 176, 13, temp_fs2, temp, 1.0f, 1.0f); break; } } @@ -2981,7 +2964,7 @@ void Title_8018FF74(void) { gDPSetColorDither(gMasterDisp++, G_CD_NOISE); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, D_menu_801B7BD0); - TextureRect_16bRGBA(&gMasterDisp, &gTitleSunBeam, 32, 32, D_menu_801B9080, D_menu_801B9084, D_menu_801B7BB0, + TextureRect_16bRGBA(&gMasterDisp, gTitleSunBeam, 32, 32, D_menu_801B9080, D_menu_801B9084, D_menu_801B7BB0, D_menu_801B7BB4); D_menu_801B9080 += 1.66f; } @@ -3105,13 +3088,8 @@ void Title_801906A0(void) { case 1: RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, (s32) D_menu_801B7BDC); - - for (i = 0; i < 5; i++) { - TextureRect_16bRGBA(&gMasterDisp, gTitleNintendo64Logo + (2048 * i), 128, 16, D_menu_801B9070, - D_menu_801B9074 + (16 * i * D_menu_801B907C), D_menu_801B9078, D_menu_801B907C); - } - TextureRect_16bRGBA(&gMasterDisp, gTitleNintendo64Logo + (2048 * 5), 128, 8, D_menu_801B9070, - (80.0f * D_menu_801B907C) + D_menu_801B9074, D_menu_801B9078, D_menu_801B907C); + TextureRect_16bRGBA(&gMasterDisp, gTitleNintendo64Logo, 128, 88, D_menu_801B9070, + D_menu_801B9074, D_menu_801B9078, D_menu_801B907C); case -1: break; @@ -3180,12 +3158,8 @@ void Title_80190C9C(void) { RCP_SetupDL(&gMasterDisp, 0x53); gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255); - for (i = 0; i < 4; i++) { - TextureRect_8bIA(&gMasterDisp, gTitleArwingCard + (672 * i), 112, 6, D_menu_801AE564, - D_menu_801AE568 + (6.0f * i), 1.0f, 1.0f); - } - TextureRect_8bIA(&gMasterDisp, gTitleArwingCard + (112 * 24), 112, 2, D_menu_801AE564, - D_menu_801AE568 + (6.0f * 4), 1.0f, 1.0f); + TextureRect_8bIA(&gMasterDisp, gTitleArwingCard, 112, 26, D_menu_801AE564, + D_menu_801AE568, 1.0f, 1.0f); } } diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index ae656728..04601922 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -2,6 +2,12 @@ #include "ui/ImguiUI.h" #include "ZAPDUtils/Utils/StringHelper.h" #include "libultraship/src/Context.h" +#include "resource/type/ResourceType.h" +#include "resource/importers/AnimFactory.h" +#include "resource/importers/LimbFactory.h" +#include "resource/importers/MessageFactory.h" +#include "resource/importers/MessageLookupFactory.h" +#include "resource/importers/SkeletonFactory.h" #include #include @@ -16,13 +22,12 @@ float gInterpolationStep = 0.0f; } GameEngine* GameEngine::Instance; -// TimerTask sTimerTasks[0x10]; GameEngine::GameEngine() { std::vector OTRFiles; - // if (const std::string cube_path = LUS::Context::GetPathRelativeToAppDirectory("lylat.otr"); std::filesystem::exists(cube_path)) { - // OTRFiles.push_back(cube_path); - // } + if (const std::string cube_path = LUS::Context::GetPathRelativeToAppDirectory("lylat.otr"); std::filesystem::exists(cube_path)) { + OTRFiles.push_back(cube_path); + } if (const std::string sm64_otr_path = LUS::Context::GetPathRelativeToAppBundle("sm64.otr"); std::filesystem::exists(sm64_otr_path)) { OTRFiles.push_back(sm64_otr_path); } @@ -35,10 +40,15 @@ GameEngine::GameEngine() { } } } - this->context = LUS::Context::CreateInstance("Lylat64", "sf64", "lylat.cfg.json", OTRFiles, - {}, 3); - // this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - // LUS::ResourceType::SAnim, "Animation", std::make_shared()); + + this->context = LUS::Context::CreateInstance("Lylat64", "sf64", "lylat.cfg.json", OTRFiles, {}, 3); + + auto loader = context->GetResourceManager()->GetResourceLoader(); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Animation", static_cast(SF64::ResourceType::AnimData), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Skeleton", static_cast(SF64::ResourceType::Skeleton), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Limb", static_cast(SF64::ResourceType::Limb), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Message", static_cast(SF64::ResourceType::Message), 0); + loader->RegisterResourceFactory( std::make_shared(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast(SF64::ResourceType::MessageTable), 0); } void GameEngine::Create(){ diff --git a/src/port/Engine.h b/src/port/Engine.h index 9af6483e..fc531d4b 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -1,5 +1,8 @@ #pragma once +#define LOAD_ASSET(path) (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path) +#define LOAD_ASSET_RAW(path) ResourceGetDataByName((const char*) path) + #ifdef __cplusplus #include #include diff --git a/src/port/Game.cpp b/src/port/Game.cpp index 37abe9c3..ffa9bbc7 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -4,6 +4,7 @@ #include "Engine.h" extern "C" { +#include void Main_SetVIMode(void); void Main_Initialize(void); void Main_ThreadEntry(void* arg); diff --git a/src/port/resource/importers/AnimFactory.cpp b/src/port/resource/importers/AnimFactory.cpp new file mode 100644 index 00000000..0f4eecdc --- /dev/null +++ b/src/port/resource/importers/AnimFactory.cpp @@ -0,0 +1,44 @@ +#include "AnimFactory.h" +#include "../type/Animation.h" +#include "spdlog/spdlog.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryAnimV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto anim = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + int16_t frameCount = reader->ReadInt16(); + int16_t limbCount = reader->ReadInt16(); + + auto jointSize = reader->ReadUInt32(); + + SPDLOG_INFO("JointSize: {}", jointSize); + + for (uint32_t i = 0; i < jointSize; i++) { + uint16_t xLen = reader->ReadUInt16(); + uint16_t x = reader->ReadUInt16(); + uint16_t yLen = reader->ReadUInt16(); + uint16_t y = reader->ReadUInt16(); + uint16_t zLen = reader->ReadUInt16(); + uint16_t z = reader->ReadUInt16(); + anim->jointKey.push_back({xLen, x, yLen, y, zLen, z}); + } + + auto frameSize = reader->ReadUInt32(); + + for (uint32_t i = 0; i < frameSize; i++) { + anim->frameData.push_back(reader->ReadInt16()); + } + + anim->mData.frameCount = frameCount; + anim->mData.limbCount = limbCount; + anim->mData.jointKey = anim->jointKey.data(); + anim->mData.frameData = anim->frameData.data(); + + return anim; +} +} // namespace LUS diff --git a/src/port/resource/importers/AnimFactory.h b/src/port/resource/importers/AnimFactory.h new file mode 100644 index 00000000..c94d8f53 --- /dev/null +++ b/src/port/resource/importers/AnimFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryAnimV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/LimbFactory.cpp b/src/port/resource/importers/LimbFactory.cpp new file mode 100644 index 00000000..72e698ae --- /dev/null +++ b/src/port/resource/importers/LimbFactory.cpp @@ -0,0 +1,32 @@ +#include "LimbFactory.h" + +#include "Context.h" +#include "resourcebridge.h" +#include "../type/Limb.h" +#include "ResourceUtil.h" + +namespace SF64 { + +std::shared_ptr ResourceFactoryBinaryLimbV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto limb = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + limb->mData.dList = LoadChild(reader->ReadUInt64()); + limb->mData.trans.x = reader->ReadFloat(); + limb->mData.trans.y = reader->ReadFloat(); + limb->mData.trans.z = reader->ReadFloat(); + + limb->mData.rot.x = reader->ReadInt16(); + limb->mData.rot.y = reader->ReadInt16(); + limb->mData.rot.z = reader->ReadInt16(); + + limb->mData.sibling = LoadChild(reader->ReadUInt64()); + limb->mData.child = LoadChild(reader->ReadUInt64()); + + return limb; +} +} // namespace LUS diff --git a/src/port/resource/importers/LimbFactory.h b/src/port/resource/importers/LimbFactory.h new file mode 100644 index 00000000..6b2593dc --- /dev/null +++ b/src/port/resource/importers/LimbFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryLimbV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/MessageFactory.cpp b/src/port/resource/importers/MessageFactory.cpp new file mode 100644 index 00000000..64716da8 --- /dev/null +++ b/src/port/resource/importers/MessageFactory.cpp @@ -0,0 +1,22 @@ +#include "MessageFactory.h" +#include "../type/Message.h" +#include "spdlog/spdlog.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryMessageV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto msg = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + auto size = reader->ReadUInt32(); + + for (uint32_t i = 0; i < size; i++) { + msg->mMessage.push_back(reader->ReadUInt16()); + } + + return msg; +} +} // namespace LUS diff --git a/src/port/resource/importers/MessageFactory.h b/src/port/resource/importers/MessageFactory.h new file mode 100644 index 00000000..38c6e42c --- /dev/null +++ b/src/port/resource/importers/MessageFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryMessageV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/MessageLookupFactory.cpp b/src/port/resource/importers/MessageLookupFactory.cpp new file mode 100644 index 00000000..8cda5527 --- /dev/null +++ b/src/port/resource/importers/MessageLookupFactory.cpp @@ -0,0 +1,26 @@ +#include "MessageLookupFactory.h" +#include "../type/Message.h" +#include "spdlog/spdlog.h" + +#include "resourcebridge.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryMessageLookupV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto table = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + auto count = reader->ReadUInt32(); + + for (uint32_t i = 0; i < count; i++) { + SPDLOG_INFO("Reading message lookup table entry {}", i); + auto id = reader->ReadInt32(); + uint16_t* ptr = static_cast(ResourceGetDataByCrc(reader->ReadUInt64())); + table->mLookupTable.push_back({ id, ptr }); + } + + return table; +} +} // namespace LUS diff --git a/src/port/resource/importers/MessageLookupFactory.h b/src/port/resource/importers/MessageLookupFactory.h new file mode 100644 index 00000000..b93953f8 --- /dev/null +++ b/src/port/resource/importers/MessageLookupFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryMessageLookupV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/ResourceUtil.h b/src/port/resource/importers/ResourceUtil.h new file mode 100644 index 00000000..4872ad64 --- /dev/null +++ b/src/port/resource/importers/ResourceUtil.h @@ -0,0 +1,15 @@ +#pragma once + +#include "resourcebridge.h" +#include "Context.h" + +namespace SF64 { +template T LoadChild(uint64_t crc) { + auto path = ResourceGetNameByCrc(crc); + if (path == nullptr) { + return nullptr; + } + auto asset = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(path); + return asset ? static_cast(asset->GetRawPointer()) : nullptr; +} +} \ No newline at end of file diff --git a/src/port/resource/importers/SkeletonFactory.cpp b/src/port/resource/importers/SkeletonFactory.cpp new file mode 100644 index 00000000..1893a53a --- /dev/null +++ b/src/port/resource/importers/SkeletonFactory.cpp @@ -0,0 +1,24 @@ +#include "SkeletonFactory.h" + +#include "../type/Skeleton.h" +#include "spdlog/spdlog.h" +#include "ResourceUtil.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinarySkeletonV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto skel = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + auto count = reader->ReadUInt32(); + for(size_t i = 0; i < count; i++) { + skel->mLimbs.push_back(LoadChild(reader->ReadUInt64())); + } + skel->mLimbs.push_back(nullptr); + + return skel; +} +} // namespace LUS diff --git a/src/port/resource/importers/SkeletonFactory.h b/src/port/resource/importers/SkeletonFactory.h new file mode 100644 index 00000000..fa9fda61 --- /dev/null +++ b/src/port/resource/importers/SkeletonFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinarySkeletonV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/type/Animation.cpp b/src/port/resource/type/Animation.cpp new file mode 100644 index 00000000..7cb2c900 --- /dev/null +++ b/src/port/resource/type/Animation.cpp @@ -0,0 +1,11 @@ +#include "Animation.h" + +namespace SF64 { +AnimationData* Animation::GetPointer() { + return &mData; +} + +size_t Animation::GetPointerSize() { + return sizeof(mData); +} +} \ No newline at end of file diff --git a/src/port/resource/type/Animation.h b/src/port/resource/type/Animation.h new file mode 100644 index 00000000..868aa5d2 --- /dev/null +++ b/src/port/resource/type/Animation.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace SF64 { +struct JointKey { + /* 0x0 */ uint16_t xLen; + /* 0x2 */ uint16_t x; + /* 0x4 */ uint16_t yLen; + /* 0x6 */ uint16_t y; + /* 0x8 */ uint16_t zLen; + /* 0xA */ uint16_t z; +}; // size = 0xC + +struct AnimationData { + /* 0x00 */ int16_t frameCount; + /* 0x02 */ int16_t limbCount; + /* 0x04 */ uint16_t* frameData; + /* 0x08 */ JointKey* jointKey; +}; // size = 0xC + +class Animation : public LUS::Resource { + public: + using Resource::Resource; + + Animation() : Resource(std::shared_ptr()) {} + + AnimationData* GetPointer(); + size_t GetPointerSize(); + + AnimationData mData; + + std::vector frameData; + std::vector jointKey; +}; +} \ No newline at end of file diff --git a/src/port/resource/type/Limb.cpp b/src/port/resource/type/Limb.cpp new file mode 100644 index 00000000..a2030c32 --- /dev/null +++ b/src/port/resource/type/Limb.cpp @@ -0,0 +1,11 @@ +#include "Limb.h" + +namespace SF64 { +LimbData* Limb::GetPointer() { + return &mData; +} + +size_t Limb::GetPointerSize() { + return sizeof(mData); +} +} \ No newline at end of file diff --git a/src/port/resource/type/Limb.h b/src/port/resource/type/Limb.h new file mode 100644 index 00000000..eb12e2e3 --- /dev/null +++ b/src/port/resource/type/Limb.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +namespace SF64 { + +struct Vec3f { + float x, y, z; +}; + +struct Vec3s { + int16_t x, y, z; +}; + +struct Gfx; + +struct LimbData { + /* 0x000 */ Gfx* dList; + /* 0x004 */ Vec3f trans; + /* 0x010 */ Vec3s rot; + /* 0x018 */ LimbData* sibling; + /* 0x01C */ LimbData* child; +}; // size = 0x20 + +class Limb : public LUS::Resource { + public: + using Resource::Resource; + + Limb() : Resource(std::shared_ptr()) {} + + LimbData* GetPointer(); + size_t GetPointerSize(); + + LimbData mData{}; +}; +} \ No newline at end of file diff --git a/src/port/resource/type/Message.cpp b/src/port/resource/type/Message.cpp new file mode 100644 index 00000000..a0708f60 --- /dev/null +++ b/src/port/resource/type/Message.cpp @@ -0,0 +1,19 @@ +#include "Message.h" + +namespace SF64 { +void* Message::GetPointer() { + return mMessage.data(); +} + +size_t Message::GetPointerSize() { + return mMessage.size() * sizeof(uint16_t); +} + +MsgLookup* MessageLookup::GetPointer() { + return mLookupTable.data(); +} + +size_t MessageLookup::GetPointerSize() { + return mLookupTable.size() * sizeof(MsgLookup); +} +} \ No newline at end of file diff --git a/src/port/resource/type/Message.h b/src/port/resource/type/Message.h new file mode 100644 index 00000000..ac074862 --- /dev/null +++ b/src/port/resource/type/Message.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +namespace SF64 { +typedef struct { + s32 msgId; + u16* msgPtr; +} MsgLookup; + +class Message : public LUS::Resource { + public: + using Resource::Resource; + + void* GetPointer() override; + size_t GetPointerSize() override; + + std::vector mMessage; +}; + +class MessageLookup : public LUS::Resource { + public: + using Resource::Resource; + + MsgLookup* GetPointer() override; + size_t GetPointerSize() override; + + std::vector mLookupTable; +}; +} \ No newline at end of file diff --git a/src/port/resource/type/ResourceType.h b/src/port/resource/type/ResourceType.h new file mode 100644 index 00000000..9ff6d2cd --- /dev/null +++ b/src/port/resource/type/ResourceType.h @@ -0,0 +1,18 @@ +#pragma once + +namespace SF64 { +enum class ResourceType { + // SF64 + AnimData = 0x414E494D, // ANIM + ColPoly = 0x43504C59, // CPLY + EnvSettings = 0x454E5653, // ENVS + Limb = 0x4C494D42, // LIMB + Message = 0x4D534720, // MSG + MessageTable = 0x4D534754, // MSGT + Skeleton = 0x534B454C, // SKEL + Script = 0x53435250, // SCRP + ScriptCmd = 0x53434D44, // SCMD + Hitbox = 0x48544258, // HTBX + ObjectInit = 0x4F42494E, // OBIN +}; +} // namespace SOH diff --git a/src/port/resource/type/Skeleton.cpp b/src/port/resource/type/Skeleton.cpp new file mode 100644 index 00000000..49e9a59a --- /dev/null +++ b/src/port/resource/type/Skeleton.cpp @@ -0,0 +1,11 @@ +#include "Skeleton.h" + +namespace SF64 { +LimbData** Skeleton::GetPointer() { + return mLimbs.data(); +} + +size_t Skeleton::GetPointerSize() { + return mLimbs.size() * sizeof(LimbData*); +} +} \ No newline at end of file diff --git a/src/port/resource/type/Skeleton.h b/src/port/resource/type/Skeleton.h new file mode 100644 index 00000000..3332abf7 --- /dev/null +++ b/src/port/resource/type/Skeleton.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Limb.h" + +#include + +namespace SF64 { +class Skeleton : public LUS::Resource { + public: + using Resource::Resource; + + Skeleton() : Resource(std::shared_ptr()) {} + + LimbData** GetPointer(); + size_t GetPointerSize(); + + std::vector mLimbs; +}; +} \ No newline at end of file