From 38345c16725a0e9c29dc40dc3735144d13ee53d1 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 22 Aug 2023 08:03:17 +1000 Subject: [PATCH 1/6] Set names for menumodel symbols --- src/game/credits.c | 50 +- src/game/endscreen.c | 28 +- src/game/mainmenu.c | 85 ++-- src/game/menu.c | 785 +++++++++++++++---------------- src/game/menugfx.c | 18 +- src/game/menuitem.c | 4 +- src/game/menutick.c | 4 +- src/game/mplayer/setup.c | 124 ++--- src/game/savebuffer.c | 8 +- src/game/trainingmenus.c | 170 +++---- src/include/bss.h | 4 +- src/include/constants.h | 19 + src/include/game/endscreen.h | 2 +- src/include/game/menu.h | 8 +- src/include/game/mplayer/setup.h | 2 +- src/include/types.h | 123 +++-- 16 files changed, 719 insertions(+), 715 deletions(-) diff --git a/src/game/credits.c b/src/game/credits.c index 6063c6dde..6226594c2 100644 --- a/src/game/credits.c +++ b/src/game/credits.c @@ -122,7 +122,7 @@ struct creditsdata { /*0x0008*/ u32 unk0008; /*0x000c*/ struct particle particles[500]; /*0x2eec*/ u8 unk2eec; - /*0x2ef0*/ struct menu840 unk2ef0; + /*0x2ef0*/ struct menumodel menumodel; /*0x34a8*/ u8 unk34a8[0xcac]; /** @@ -1796,7 +1796,7 @@ Gfx *creditsDraw(Gfx *gdl) g_CreditsScrollStarted = true; scrolltimer240 = 0; - func0f0f37a4(&g_CreditsData->unk2ef0); + menuUnsetModel(&g_CreditsData->menumodel); } scrolltimer240 += g_Vars.diffframe240; @@ -1805,19 +1805,22 @@ Gfx *creditsDraw(Gfx *gdl) scrolltimer240 = 0; } - g_CreditsData->unk2ef0.unk54c = 0; - g_CreditsData->unk2ef0.unk524 = 0; - g_CreditsData->unk2ef0.unk520 = g_CreditsData->unk2ef0.unk548 = -0.26175770163536; - g_CreditsData->unk2ef0.unk528 = g_CreditsData->unk2ef0.unk550 = 0; - g_CreditsData->unk2ef0.unk538 = 833.0f - (scrolltimer240 / TICKS(14400.0f)) * 2413.0f; - g_CreditsData->unk2ef0.unk53c = VERSION == VERSION_PAL_FINAL ? 65.86 : 70.86; - g_CreditsData->unk2ef0.unk540 = -2050; - g_CreditsData->unk2ef0.unk544 = 1.467; - g_CreditsData->unk2ef0.unk00c = 1200; - g_CreditsData->unk2ef0.unk5b1_07 = true; - g_CreditsData->unk2ef0.partvisibility = NULL; + g_CreditsData->menumodel.newroty = 0; + g_CreditsData->menumodel.curroty = 0; - gdl = menuRenderModels(gdl, &g_CreditsData->unk2ef0, 4); + g_CreditsData->menumodel.currotx = g_CreditsData->menumodel.newrotx = -0.26175770163536; + g_CreditsData->menumodel.currotz = g_CreditsData->menumodel.newrotz = 0; + + g_CreditsData->menumodel.newposx = 833.0f - (scrolltimer240 / TICKS(14400.0f)) * 2413.0f; + g_CreditsData->menumodel.newposy = VERSION == VERSION_PAL_FINAL ? 65.86 : 70.86; + g_CreditsData->menumodel.newposz = -2050; + + g_CreditsData->menumodel.newscale = 1.467; + g_CreditsData->menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(FILE_PPDMENU); + g_CreditsData->menumodel.drawbehinddialog = true; + g_CreditsData->menumodel.partvisibility = NULL; + + gdl = menuRenderModel(gdl, &g_CreditsData->menumodel, MENUMODELTYPE_CREDITSLOGO); gSPMatrix(gdl++, osVirtualToPhysical(matrix), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); @@ -1912,19 +1915,18 @@ void creditsReset(void) creditsResetParticles(); creditsResetSlides(); - func0f0f8bb4(&g_CreditsData->unk2ef0, 0x25800, 1); + menuResetModel(&g_CreditsData->menumodel, 0x25800, true); - g_CreditsData->unk2ef0.unk580 = 0; + g_CreditsData->menumodel.removingpiece = false; - func0f0f372c(&g_CreditsData->unk2ef0, 0, 0, 0, 0, 0, 0, 1, 5); + menuConfigureModel(&g_CreditsData->menumodel, 0, 0, 0, 0, 0, 0, 1, MENUMODELFLAG_HASSCALE | MENUMODELFLAG_HASROTATION); - g_CreditsData->unk2ef0.unk53c = 90; - g_CreditsData->unk2ef0.unk510 = 8.2; - g_CreditsData->unk2ef0.unk514 = -4.1; - g_CreditsData->unk2ef0.unk51c = 0.00393; - g_CreditsData->unk2ef0.unk54c = 0; - g_CreditsData->unk2ef0.unk524 = g_CreditsData->unk2ef0.unk54c; - g_CreditsData->unk2ef0.unk578 = 60; + g_CreditsData->menumodel.newposy = 90; + g_CreditsData->menumodel.curposx = 8.2; + g_CreditsData->menumodel.curposy = -4.1; + g_CreditsData->menumodel.curscale = 0.00393; + g_CreditsData->menumodel.curroty = g_CreditsData->menumodel.newroty = 0; + g_CreditsData->menumodel.rottimer60 = 60; g_CreditsUsingAltTitle = g_CreditsAltTitleRequested; diff --git a/src/game/endscreen.c b/src/game/endscreen.c index b4bf2cee1..add6d4949 100644 --- a/src/game/endscreen.c +++ b/src/game/endscreen.c @@ -432,19 +432,19 @@ struct menudialogdef *endscreenAdvance(void) return &g_NextMissionMenuDialog; } -void endscreen0f10d770(void) +void endscreenResetModels(void) { - func0f0f8bb4(&g_Menus[0].unk840, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), 0); - g_Menus[0].unk840.unk004 = bgunGetGunMem() + menugfxGetParticleArraySize(); + menuResetModel(&g_Menus[0].menumodel, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), false); + g_Menus[0].menumodel.allocstart = bgunGetGunMem() + menugfxGetParticleArraySize(); - func0f0f8bb4(&g_Menus[1].unk840, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), 0); - g_Menus[1].unk840.unk004 = bgunGetGunMem() + menugfxGetParticleArraySize(); + menuResetModel(&g_Menus[1].menumodel, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), false); + g_Menus[1].menumodel.allocstart = bgunGetGunMem() + menugfxGetParticleArraySize(); - func0f0f8bb4(&g_Menus[2].unk840, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), 0); - g_Menus[2].unk840.unk004 = bgunGetGunMem() + menugfxGetParticleArraySize(); + menuResetModel(&g_Menus[2].menumodel, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), false); + g_Menus[2].menumodel.allocstart = bgunGetGunMem() + menugfxGetParticleArraySize(); - func0f0f8bb4(&g_Menus[3].unk840, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), 0); - g_Menus[3].unk840.unk004 = bgunGetGunMem() + menugfxGetParticleArraySize(); + menuResetModel(&g_Menus[3].menumodel, bgunCalculateGunMemCapacity() - menugfxGetParticleArraySize(), false); + g_Menus[3].menumodel.allocstart = bgunGetGunMem() + menugfxGetParticleArraySize(); } #if VERSION >= VERSION_NTSC_1_0 @@ -687,7 +687,7 @@ void endscreenContinue(s32 context) menuPushDialog(&g_MissionContinueOrReplyMenuDialog); } } else { - endscreen0f10d770(); + endscreenResetModels(); if (context == 1) { menuPushRootDialog(endscreenAdvance(), MENUROOT_COOPCONTINUE); @@ -746,7 +746,7 @@ MenuDialogHandlerResult endscreenHandle2PCompleted(s32 operation, struct menudia && !isStageDifficultyUnlocked(g_MissionConfig.stageindex + 1, g_MissionConfig.difficulty)))) { menuPopDialog(); } else { - endscreen0f10d770(); + endscreenResetModels(); menuPushDialog(endscreenAdvance()); } #endif @@ -789,7 +789,7 @@ MenuDialogHandlerResult endscreenHandle2PFailed(s32 operation, struct menudialog || g_Vars.stagenum == STAGE_CITRAINING) { menuPopDialog(); } else { - endscreen0f10d770(); + endscreenResetModels(); menuPushDialog(&g_RetryMissionMenuDialog); } } @@ -1750,7 +1750,7 @@ void endscreenPushSolo(void) #endif { // Failed or aborted - endscreen0f10d770(); + endscreenResetModels(); menuPushRootDialog(&g_RetryMissionMenuDialog, MENUROOT_COOPCONTINUE); } else { // Completed @@ -1760,7 +1760,7 @@ void endscreenPushSolo(void) struct menudialogdef *definition = endscreenAdvance(); if (definition) { - endscreen0f10d770(); + endscreenResetModels(); menuPushRootDialog(definition, MENUROOT_COOPCONTINUE); } #endif diff --git a/src/game/mainmenu.c b/src/game/mainmenu.c index f4e60cfaa..1595df7fc 100644 --- a/src/game/mainmenu.c +++ b/src/game/mainmenu.c @@ -772,11 +772,11 @@ MenuDialogHandlerResult menudialog00103608(s32 operation, struct menudialogdef * { switch (operation) { case MENUOP_OPEN: - g_Menus[g_MpPlayerNum].unk840.unk010 = 0; + g_Menus[g_MpPlayerNum].menumodel.curparams = 0; setupLoadBriefing(g_MissionConfig.stagenum, - g_Menus[g_MpPlayerNum].unk840.unk004, - g_Menus[g_MpPlayerNum].unk840.unk008, &g_Briefing); + g_Menus[g_MpPlayerNum].menumodel.allocstart, + g_Menus[g_MpPlayerNum].menumodel.alloclen, &g_Briefing); break; case MENUOP_CLOSE: langClearBank(g_Briefing.langbank); @@ -3779,51 +3779,50 @@ void func0f105948(s32 weaponnum) if (weaponHasFlag(weaponnum, WEAPONFLAG_HIDEMENUMODEL) == false && (u32)wantindex >= 0 && useindex >= 0) { weapon = weaponFindById(weaponnum); - g_Menus[g_MpPlayerNum].unk840.unk000 = 8; - g_Menus[g_MpPlayerNum].unk840.unk010 = 0; - g_Menus[g_MpPlayerNum].unk840.unk00c = weaponGetFileNum(weaponnum); - g_Menus[g_MpPlayerNum].unk840.unk538 = 0; - g_Menus[g_MpPlayerNum].unk840.unk510 = 0; - g_Menus[g_MpPlayerNum].unk840.unk53c = 0; - g_Menus[g_MpPlayerNum].unk840.unk514 = 0; - g_Menus[g_MpPlayerNum].unk840.unk540 = 0; - g_Menus[g_MpPlayerNum].unk840.unk518 = 0; - g_Menus[g_MpPlayerNum].unk840.unk550 = 0; - g_Menus[g_MpPlayerNum].unk840.unk528 = 0; - g_Menus[g_MpPlayerNum].unk840.unk52c = gunconfig[useindex][0]; - g_Menus[g_MpPlayerNum].unk840.unk530 = gunconfig[useindex][1]; - g_Menus[g_MpPlayerNum].unk840.unk534 = gunconfig[useindex][2]; - g_Menus[g_MpPlayerNum].unk840.unk548 = gunconfig[useindex][3]; - g_Menus[g_MpPlayerNum].unk840.unk520 = gunconfig[useindex][3]; // @bug? Wrong index? + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 8; + g_Menus[g_MpPlayerNum].menumodel.curparams = 0; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(weaponGetFileNum(weaponnum)); - func0f0f372c(&g_Menus[g_MpPlayerNum].unk840, 0, 0, 0, 0, 0, 0, gunconfig[useindex][4], 1); + g_Menus[g_MpPlayerNum].menumodel.curposx = g_Menus[g_MpPlayerNum].menumodel.newposx = 0; + g_Menus[g_MpPlayerNum].menumodel.curposy = g_Menus[g_MpPlayerNum].menumodel.newposy = 0; + g_Menus[g_MpPlayerNum].menumodel.curposz = g_Menus[g_MpPlayerNum].menumodel.newposz = 0; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0; - g_Menus[g_MpPlayerNum].unk840.partvisibility = weapon->partvisibility; - g_Menus[g_MpPlayerNum].unk840.unk554 = -1; + g_Menus[g_MpPlayerNum].menumodel.currotz = g_Menus[g_MpPlayerNum].menumodel.newrotz = 0; + + g_Menus[g_MpPlayerNum].menumodel.displacex = gunconfig[useindex][0]; + g_Menus[g_MpPlayerNum].menumodel.displacey = gunconfig[useindex][1]; + g_Menus[g_MpPlayerNum].menumodel.displacez = gunconfig[useindex][2]; + + g_Menus[g_MpPlayerNum].menumodel.newrotx = gunconfig[useindex][3]; + g_Menus[g_MpPlayerNum].menumodel.currotx = gunconfig[useindex][3]; + + menuConfigureModel(&g_Menus[g_MpPlayerNum].menumodel, 0, 0, 0, 0, 0, 0, gunconfig[useindex][4], MENUMODELFLAG_HASSCALE); + + g_Menus[g_MpPlayerNum].menumodel.curscale = 0; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = weapon->partvisibility; + g_Menus[g_MpPlayerNum].menumodel.zoom = -1; // These indexes correspond to WEAPON_DISGUISE40 and WEAPON_DISGUISE41 if (wantindex == 0x3e || wantindex == 0x3f) { if ((u32)wantindex == 0x3e) { - g_Menus[g_MpPlayerNum].unk840.unk00c = 0x0a01ffff; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_MP_HEADBODY(MPHEAD_DARK_FROCK, MPBODY_DARKLAB); } else { - g_Menus[g_MpPlayerNum].unk840.unk00c = 0x0400ffff; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_MP_HEADBODY(MPHEAD_DARK_COMBAT, MPBODY_DARK_AF1); } - g_Menus[g_MpPlayerNum].unk840.partvisibility = NULL; - g_Menus[g_MpPlayerNum].unk840.unk580 = 0; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = NULL; + g_Menus[g_MpPlayerNum].menumodel.removingpiece = false; - func0f0f372c(&g_Menus[g_MpPlayerNum].unk840, 0, 0, 0, 0, 0, 0, 1, 1); + menuConfigureModel(&g_Menus[g_MpPlayerNum].menumodel, 0, 0, 0, 0, 0, 0, 1, MENUMODELFLAG_HASSCALE); - g_Menus[g_MpPlayerNum].unk840.unk578 = TICKS(60); - g_Menus[g_MpPlayerNum].unk840.unk574 = TICKS(120); - g_Menus[g_MpPlayerNum].unk840.unk54c = -0.2f; - g_Menus[g_MpPlayerNum].unk840.unk524 = -0.2f; + g_Menus[g_MpPlayerNum].menumodel.rottimer60 = TICKS(60); + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120); + g_Menus[g_MpPlayerNum].menumodel.curroty = g_Menus[g_MpPlayerNum].menumodel.newroty = -0.2f; } } else { - g_Menus[g_MpPlayerNum].unk840.bodymodeldef = NULL; - g_Menus[g_MpPlayerNum].unk840.unk010 = 0; - g_Menus[g_MpPlayerNum].unk840.unk00c = 0; + g_Menus[g_MpPlayerNum].menumodel.bodymodeldef = NULL; + g_Menus[g_MpPlayerNum].menumodel.curparams = 0; + g_Menus[g_MpPlayerNum].menumodel.newparams = 0; } } @@ -3831,11 +3830,11 @@ MenuDialogHandlerResult inventoryMenuDialog(s32 operation, struct menudialogdef { if (operation == MENUOP_TICK) { if (g_Menus[g_MpPlayerNum].curdialog && g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef) { - g_Menus[g_MpPlayerNum].unk840.unk574 -= g_Vars.diffframe60; - g_Menus[g_MpPlayerNum].unk840.unk54c = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk524 = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk528 = 0; - g_Menus[g_MpPlayerNum].unk840.unk550 = 0; + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 -= g_Vars.diffframe60; + g_Menus[g_MpPlayerNum].menumodel.newroty = 18.849555969238f * g_20SecIntervalFrac; + g_Menus[g_MpPlayerNum].menumodel.curroty = 18.849555969238f * g_20SecIntervalFrac; + g_Menus[g_MpPlayerNum].menumodel.currotz = 0; + g_Menus[g_MpPlayerNum].menumodel.newrotz = 0; if (var80072d88 != g_InventoryWeapon) { func0f105948(g_InventoryWeapon); @@ -3843,9 +3842,9 @@ MenuDialogHandlerResult inventoryMenuDialog(s32 operation, struct menudialogdef } if (g_InventoryWeapon == WEAPON_DISGUISE40 || g_InventoryWeapon == WEAPON_DISGUISE41) { - g_Menus[g_MpPlayerNum].unk840.unk05c = ANIM_006A; - g_Menus[g_MpPlayerNum].unk840.unk578 = TICKS(60); - g_Menus[g_MpPlayerNum].unk840.unk574 = TICKS(120); + g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_006A; + g_Menus[g_MpPlayerNum].menumodel.rottimer60 = TICKS(60); + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120); } } else { var80072d88 = 255; diff --git a/src/game/menu.c b/src/game/menu.c index 7840aabb9..898962604 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -1424,7 +1424,7 @@ void menuOpenDialog(struct menudialogdef *dialogdef, struct menudialog *dialog, void menuPushDialog(struct menudialogdef *dialogdef) { if (dialogdef) { - func0f0f37a4(&g_Menus[g_MpPlayerNum].unk840); + menuUnsetModel(&g_Menus[g_MpPlayerNum].menumodel); if (g_Menus[g_MpPlayerNum].depth < 6 && g_Menus[g_MpPlayerNum].numdialogs < ARRAYCOUNT(g_Menus[0].dialogs)) { struct menulayer *layer = &g_Menus[g_MpPlayerNum].layers[g_Menus[g_MpPlayerNum].depth]; @@ -1646,75 +1646,65 @@ void func0f0f3704(struct menudialogdef *dialogdef) menuPushDialog(dialogdef); } -void func0f0f372c(struct menu840 *arg0, f32 x, f32 y, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32 arg7, u8 flags) +void menuConfigureModel(struct menumodel *menumodel, f32 x, f32 y, f32 z, f32 rotx, f32 roty, f32 rotz, f32 scale, u8 flags) { - arg0->unk5b1_05 = true; + menumodel->configuring = true; - if (flags & 2) { - arg0->unk538 = x; - arg0->unk53c = y; - arg0->unk540 = arg3; + if (flags & MENUMODELFLAG_HASPOSITION) { + menumodel->newposx = x; + menumodel->newposy = y; + menumodel->newposz = z; } - if (flags & 4) { - arg0->unk548 = arg4; - arg0->unk54c = arg5; - arg0->unk550 = arg6; + if (flags & MENUMODELFLAG_HASROTATION) { + menumodel->newrotx = rotx; + menumodel->newroty = roty; + menumodel->newrotz = rotz; } - if (flags & 1) { - arg0->unk544 = arg7; + if (flags & MENUMODELFLAG_HASSCALE) { + menumodel->newscale = scale; } - arg0->unk568 = flags; - arg0->unk564 = 0.0f; + menumodel->flags = flags; + menumodel->configurefrac = 0.0f; } -void func0f0f37a4(struct menu840 *arg0) +void menuUnsetModel(struct menumodel *menumodel) { - if (arg0->unk010 == 0x4fac5ace) { + if (menumodel->curparams == 0x4fac5ace) { challengeUnsetCurrent(); } - arg0->unk000 = 0; - arg0->unk00c = 0; - arg0->unk010 = 0; - arg0->bodymodeldef = 0; - arg0->headmodeldef = 0; - arg0->unk05c = 0; - arg0->unk05e = 0; - arg0->unk5b0 = 0; - arg0->unk5b1_01 = false; - arg0->unk5b1_02 = false; - arg0->unk5b1_03 = false; - arg0->unk5b1_04 = false; - arg0->unk5b1_05 = false; - arg0->unk5b1_06 = false; - arg0->unk5b1_07 = false; - arg0->partvisibility = NULL; - arg0->unk560 = -1; - arg0->headnum = -1; - arg0->bodynum = -1; - arg0->unk550 = 0.0f; - arg0->unk54c = 0.0f; - arg0->unk548 = 0.0f; - arg0->unk540 = 0.0f; - arg0->unk53c = 0.0f; - arg0->unk538 = 0.0f; - arg0->unk534 = 0.0f; - arg0->unk530 = 0.0f; - arg0->unk52c = 0.0f; - arg0->unk528 = 0.0f; - arg0->unk524 = 0.0f; - arg0->unk520 = 0.0f; - arg0->unk518 = 0.0f; - arg0->unk514 = 0.0f; - arg0->unk510 = 0.0f; - arg0->unk558 = 0.0f; - arg0->unk55c = 1.0f; - arg0->unk51c = 1.0f; - arg0->unk544 = 1.0f; - arg0->unk554 = -1.0f; + menumodel->loaddelay = 0; + menumodel->newparams = 0; + menumodel->curparams = 0; + menumodel->bodymodeldef = NULL; + menumodel->headmodeldef = NULL; + menumodel->newanimnum = 0; + menumodel->curanimnum = 0; + menumodel->perfectheadnum = 0; + menumodel->isperfecthead = false; + menumodel->unk5b1_02 = false; + menumodel->unk5b1_03 = false; + menumodel->reverseanim = false; + menumodel->configuring = false; + menumodel->unk5b1_06 = false; + menumodel->drawbehinddialog = false; + menumodel->partvisibility = NULL; + menumodel->unk560 = -1; + menumodel->headnum = -1; + menumodel->bodynum = -1; + menumodel->newrotx = menumodel->newroty = menumodel->newrotz = 0.0f; + menumodel->newposx = menumodel->newposy = menumodel->newposz = 0.0f; + menumodel->displacex = menumodel->displacey = menumodel->displacez = 0.0f; + menumodel->currotx = menumodel->curroty = menumodel->currotz = 0.0f; + menumodel->curposx = menumodel->curposy = menumodel->curposz = 0.0f; + menumodel->unk558 = 0.0f; + menumodel->unk55c = 1.0f; + menumodel->curscale = 1.0f; + menumodel->newscale = 1.0f; + menumodel->zoom = -1.0f; } Lights1 var80071468 = gdSPDefLights1(0x96, 0x96, 0x96, 0xff, 0xff, 0xff, 0xb2, 0x4d, 0x2e); @@ -1722,15 +1712,15 @@ Lights1 var80071468 = gdSPDefLights1(0x96, 0x96, 0x96, 0xff, 0xff, 0xff, 0xb2, 0 /** * Render the hudpiece as well as any models within dialogs. */ -Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) +Gfx *menuRenderModel(Gfx *gdl, struct menumodel *menumodel, s32 modeltype) { - f32 a; - f32 b; - f32 c; - f32 sp430; - f32 sp42c; - f32 sp428; - f32 sp424; + f32 rotx; + f32 roty; + f32 rotz; + f32 posx; + f32 posy; + f32 posz; + f32 scale; s32 totalfilelen; struct texpool texpool; s32 bodyfilelen2; @@ -1740,48 +1730,49 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) s32 headnum; if (g_Vars.stagenum != STAGE_CITRAINING && g_Vars.stagenum != STAGE_CREDITS) { - if (g_MenuData.unk5d5_01 && arg2 != 1 && arg2 < 3) { + if (g_MenuData.unk5d5_01 && modeltype != MENUMODELTYPE_HUDPIECE && modeltype < MENUMODELTYPE_3) { return gdl; } - if (thing->unk004 == NULL) { + if (menumodel->allocstart == NULL) { if (bgunChangeGunMem(GUNMEMOWNER_INVMENU)) { - thing->unk004 = bgunGetGunMem(); - thing->unk008 = bgunCalculateGunMemCapacity(); + menumodel->allocstart = bgunGetGunMem(); + menumodel->alloclen = bgunCalculateGunMemCapacity(); } else { return gdl; } } } - if (thing->unk004 == NULL) { + if (menumodel->allocstart == NULL) { return gdl; } - if (thing->unk00c != 0) { - if (thing->unk00c == thing->unk010) { - thing->unk00c = 0; - thing->unk000 = 0; + // If the caller has asked for a new model to be loaded, do it + if (menumodel->newparams != 0) { + if (menumodel->newparams == menumodel->curparams) { + menumodel->newparams = 0; + menumodel->loaddelay = 0; } else { - if (thing->unk010 == 0x4fac5ace) { + if (menumodel->curparams == 0x4fac5ace) { challengeUnsetCurrent(); } - if (thing->unk000 == 0) { - thing->unk000 = 1; + if (menumodel->loaddelay == 0) { + menumodel->loaddelay = 1; return gdl; } - thing->unk000--; + menumodel->loaddelay--; - if (thing->unk000 == 0) { - if ((thing->unk00c & 0xffff) == 0xffff || (thing->unk00c & 0x80000000)) { - if (thing->unk00c & 0x80000000) { - headnum = thing->unk00c & 0x3ff; - bodynum = (thing->unk00c & 0xffc00) >> 10; + if (menumodel->loaddelay == 0) { + if (MENUMODELPARAMS_GET_FILENUM(menumodel->newparams) == 0xffff || MENUMODELPARAMS_HAS_MASTER_HEADBODY(menumodel->newparams)) { + if (MENUMODELPARAMS_HAS_MASTER_HEADBODY(menumodel->newparams)) { + headnum = MENUMODELPARAMS_GET_MASTER_HEADNUM(menumodel->newparams); + bodynum = MENUMODELPARAMS_GET_MASTER_BODYNUM(menumodel->newparams); } else { - s32 mpheadnum = (thing->unk00c >> 16) & 0xff; - s32 mpbodynum = (thing->unk00c >> 24) & 0xff; + s32 mpheadnum = MENUMODELPARAMS_GET_MP_HEADNUM(menumodel->newparams); + s32 mpbodynum = MENUMODELPARAMS_GET_MP_BODYNUM(menumodel->newparams); bodynum = mpGetBodyId(mpbodynum); if (mpheadnum < mpGetNumHeads2()) { @@ -1789,7 +1780,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) } else { headnum = func0f14a9f8(mpheadnum - mpGetNumHeads2()); headnum = mpGetBeauHeadId(headnum); - thing->unk5b0 = (mpheadnum - mpGetNumHeads2()) & 0xff; + menumodel->perfectheadnum = (mpheadnum - mpGetNumHeads2()) & 0xff; } } @@ -1808,80 +1799,82 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) totalfilelen += 0x4000; - texInitPool(&texpool, thing->unk004 + totalfilelen, thing->unk008 - totalfilelen); + texInitPool(&texpool, menumodel->allocstart + totalfilelen, menumodel->alloclen - totalfilelen); - thing->headnum = headnum; - thing->bodynum = bodynum; - thing->bodymodeldef = modeldefLoad(bodyfilenum, thing->unk004, totalfilelen, &texpool); + menumodel->headnum = headnum; + menumodel->bodynum = bodynum; + menumodel->bodymodeldef = modeldefLoad(bodyfilenum, menumodel->allocstart, totalfilelen, &texpool); bodyfilelen2 = ALIGN64(fileGetLoadedSize(bodyfilenum)); - modelAllocateRwData(thing->bodymodeldef); + modelAllocateRwData(menumodel->bodymodeldef); if (headnum < 0) { - thing->headmodeldef = NULL; + menumodel->headmodeldef = NULL; } else { - thing->headmodeldef = modeldefLoad(headfilenum, thing->unk004 + bodyfilelen2, totalfilelen - bodyfilelen2, &texpool); + menumodel->headmodeldef = modeldefLoad(headfilenum, menumodel->allocstart + bodyfilelen2, totalfilelen - bodyfilelen2, &texpool); fileGetLoadedSize(headfilenum); - bodyCalculateHeadOffset(thing->headmodeldef, headnum, bodynum); - modelAllocateRwData(thing->headmodeldef); + bodyCalculateHeadOffset(menumodel->headmodeldef, headnum, bodynum); + modelAllocateRwData(menumodel->headmodeldef); } - modelInit(&thing->bodymodel, thing->bodymodeldef, thing->unk110, true); - animInit(&thing->bodyanim); + modelInit(&menumodel->bodymodel, menumodel->bodymodeldef, menumodel->rwdata, true); + animInit(&menumodel->bodyanim); - thing->bodymodel.rwdatalen = 256; - thing->bodymodel.anim = &thing->bodyanim; + menumodel->bodymodel.rwdatalen = 256; + menumodel->bodymodel.anim = &menumodel->bodyanim; - body0f02ce8c(bodynum, headnum, thing->bodymodeldef, thing->headmodeldef, totalfilelen * 0, &thing->bodymodel, false, 1); + body0f02ce8c(bodynum, headnum, menumodel->bodymodeldef, menumodel->headmodeldef, totalfilelen * 0, &menumodel->bodymodel, false, 1); } else { - totalfilelen = ALIGN64(fileGetInflatedSize(thing->unk00c)) + 0x4000; + totalfilelen = ALIGN64(fileGetInflatedSize(menumodel->newparams)) + 0x4000; if (1); - texInitPool(&texpool, &thing->unk004[(u32)totalfilelen], thing->unk008 - totalfilelen); + texInitPool(&texpool, &menumodel->allocstart[(u32)totalfilelen], menumodel->alloclen - totalfilelen); - thing->headnum = -1; - thing->bodynum = -1; - thing->bodymodeldef = modeldefLoad(thing->unk00c, thing->unk004, totalfilelen, &texpool); + menumodel->headnum = -1; + menumodel->bodynum = -1; + menumodel->bodymodeldef = modeldefLoad(menumodel->newparams, menumodel->allocstart, totalfilelen, &texpool); - fileGetLoadedSize(thing->unk00c); - modelAllocateRwData(thing->bodymodeldef); - modelInit(&thing->bodymodel, thing->bodymodeldef, thing->unk110, true); - animInit(&thing->bodyanim); + fileGetLoadedSize(menumodel->newparams); + modelAllocateRwData(menumodel->bodymodeldef); + modelInit(&menumodel->bodymodel, menumodel->bodymodeldef, menumodel->rwdata, true); + animInit(&menumodel->bodyanim); - thing->bodymodel.rwdatalen = 256; - thing->bodymodel.anim = &thing->bodyanim; + menumodel->bodymodel.rwdatalen = 256; + menumodel->bodymodel.anim = &menumodel->bodyanim; } - thing->unk010 = thing->unk00c; - thing->unk05e = 0; - thing->unk00c = 0; + menumodel->curparams = menumodel->newparams; + menumodel->curanimnum = 0; + menumodel->newparams = 0; } else { return gdl; } } } - if (thing->bodymodeldef != NULL) { + if (menumodel->bodymodeldef != NULL) { struct modelrenderdata renderdata = {NULL, true, 3}; - Mtxf *sp3b4; + Mtxf *matrices; s32 i; u32 stack[3]; - struct coord sp398; - f32 sp390[2]; - Mtxf sp350; - Mtxf sp310; - f32 sp30c[1]; - bool sp308; - struct coord sp2fc; - f32 sp2f8; - bool sp2f4; + struct coord tmpcoord; + f32 screenpos[2]; + Mtxf rotmtx; + Mtxf posmtx; + f32 screenz[1]; + bool haszoom; + struct coord zoompos; + f32 zoomy; + bool dodefaultzoom; - if (arg2 < 3 && g_MenuData.unk5d5_03) { + // Most models use the z-buffer and a scissor. + // Types 2 and 3 are unused. Type 4 is the credits scrolling logo. + if (modeltype < MENUMODELTYPE_3 && g_MenuData.usezbuf) { gdl = viPrepareZbuf(gdl); gdl = vi0000b1d0(gdl); - g_MenuData.unk5d5_03 = false; + g_MenuData.usezbuf = false; - if (arg2 != 2) { + if (modeltype != MENUMODELTYPE_2) { gdl = menuApplyScissor(gdl); } @@ -1891,221 +1884,217 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) gSPDisplayList(gdl++, var80061380); gSPDisplayList(gdl++, var800613a0); - sp308 = false; + haszoom = false; - if (thing->unk554 > 0.0f) { - sp2f4 = true; + // Handle updating the camera zoom in/out (eg. character selection dialog) + if (menumodel->zoom > 0.0f) { + dodefaultzoom = true; - if (thing->bodymodeldef->skel == &g_SkelChr) { - struct modelnode *node = modelGetPart(thing->bodymodeldef, MODELPART_CHR_0006); + if (menumodel->bodymodeldef->skel == &g_SkelChr) { + struct modelnode *node = modelGetPart(menumodel->bodymodeldef, MODELPART_CHR_0006); if (node) { struct modelrodata_position *rodata = &node->rodata->position; - f32 f0 = menuGetLinearOscPauseFrac(thing->unk574 / TICKS(480.0f)); + f32 frac = menuGetLinearOscPauseFrac(menumodel->zoomtimer60 / TICKS(480.0f)); - sp2fc.f[0] = 0.0f; - sp2fc.f[1] = 0.0f - (rodata->pos.f[1] / 7.6f * (1.0f - f0 * f0)); - sp2fc.f[2] = 0.0f; + zoompos.f[0] = 0.0f; + zoompos.f[1] = 0.0f - (rodata->pos.f[1] / 7.6f * (1.0f - frac * frac)); + zoompos.f[2] = 0.0f; - sp308 = true; + haszoom = true; - thing->unk554 = 100.0f + (1.0f - f0) * 270.0f; - sp2f8 = thing->unk554 / (rodata->pos.f[1] / 2.0f); + menumodel->zoom = 100.0f + (1.0f - frac) * 270.0f; + zoomy = menumodel->zoom / (rodata->pos.f[1] / 2.0f); - sp2f4 = false; + dodefaultzoom = false; - modelFindBboxRodata(&thing->bodymodel); + modelFindBboxRodata(&menumodel->bodymodel); } if (1); } - if (sp2f4) { - struct modelrodata_bbox *bbox = modelFindBboxRodata(&thing->bodymodel); + if (dodefaultzoom) { + struct modelrodata_bbox *bbox = modelFindBboxRodata(&menumodel->bodymodel); if (bbox) { - sp2fc.x = -(bbox->xmax - ((bbox->xmax - bbox->xmin) * 0.5f)); - sp2fc.y = -(bbox->ymax - ((bbox->ymax - bbox->ymin) * 0.5f)); - sp2fc.z = -(bbox->zmax - ((bbox->zmax - bbox->zmin) * 0.5f)); - sp308 = true; - sp2f8 = thing->unk554 / ((bbox->ymax - bbox->ymin) * 0.5f); + zoompos.x = -(bbox->xmax - ((bbox->xmax - bbox->xmin) * 0.5f)); + zoompos.y = -(bbox->ymax - ((bbox->ymax - bbox->ymin) * 0.5f)); + zoompos.z = -(bbox->zmax - ((bbox->zmax - bbox->zmin) * 0.5f)); + haszoom = true; + zoomy = menumodel->zoom / ((bbox->ymax - bbox->ymin) * 0.5f); } } } - mtx4LoadIdentity(&sp350); + mtx4LoadIdentity(&rotmtx); - if (arg2 == 1) { + // For the hudpiece, tween the position and scale to the new values and apply rotation. + if (modeltype == MENUMODELTYPE_HUDPIECE) { if (IS8MB()) { s32 i; - if (thing->unk510 != thing->unk538) { + if (menumodel->curposx != menumodel->newposx) { for (i = 0; i < g_Vars.diffframe60; i++) { - thing->unk510 = (thing->unk538 * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * thing->unk510); + menumodel->curposx = (menumodel->newposx * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * menumodel->curposx); } } - if (thing->unk514 != thing->unk53c) { + if (menumodel->curposy != menumodel->newposy) { for (i = 0; i < g_Vars.diffframe60; i++) { - thing->unk514 = (thing->unk53c * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * thing->unk514); + menumodel->curposy = (menumodel->newposy * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * menumodel->curposy); } } - if (thing->unk518 != thing->unk540) { + if (menumodel->curposz != menumodel->newposz) { for (i = 0; i < g_Vars.diffframe60; i++) { - thing->unk518 = (thing->unk540 * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * thing->unk518); + menumodel->curposz = (menumodel->newposz * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * menumodel->curposz); } } - if (thing->unk51c != thing->unk544) { + if (menumodel->curscale != menumodel->newscale) { for (i = 0; i < g_Vars.diffframe60; i++) { - thing->unk51c = (thing->unk544 * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * thing->unk51c); + menumodel->curscale = (menumodel->newscale * PALUPF(0.002f)) + ((1.0f - PALUPF(0.002f)) * menumodel->curscale); } } - sp430 = thing->unk510; + posx = menumodel->curposx; #if !PAL if (g_ViRes == VIRES_HI) { - sp430 *= 2.0f; + posx *= 2.0f; } #endif - sp42c = thing->unk514; - sp428 = thing->unk518; - sp424 = thing->unk51c; + posy = menumodel->curposy; + posz = menumodel->curposz; - a = thing->unk548; - b = thing->unk54c; - c = thing->unk550; + scale = menumodel->curscale; - thing->unk520 = a; - thing->unk524 = b; - thing->unk528 = c; + menumodel->currotx = rotx = menumodel->newrotx; + menumodel->curroty = roty = menumodel->newroty; + menumodel->currotz = rotz = menumodel->newrotz; - sp398.x = a; - sp398.y = b; - sp398.z = c; + tmpcoord.x = rotx; + tmpcoord.y = roty; + tmpcoord.z = rotz; - mtx4LoadRotation(&sp398, &sp350); + mtx4LoadRotation(&tmpcoord, &rotmtx); } } else { - if (thing->unk5b1_05) { + // If the caller is reconfiguring the model's position, rotation or scale, tween towards the new values. + if (menumodel->configuring) { #if VERSION >= VERSION_PAL_BETA - thing->unk564 += g_Vars.diffframe60freal / 40.0f; + menumodel->configurefrac += g_Vars.diffframe60freal / 40.0f; #else - thing->unk564 += g_Vars.diffframe60f / 40.0f; + menumodel->configurefrac += g_Vars.diffframe60f / 40.0f; #endif - if (thing->unk564 > 1.0f) { - thing->unk5b1_05 = false; - thing->unk510 = thing->unk538; - thing->unk514 = thing->unk53c; - thing->unk518 = thing->unk540; - thing->unk51c = thing->unk544; + if (menumodel->configurefrac > 1.0f) { + menumodel->configuring = false; + menumodel->curposx = menumodel->newposx; + menumodel->curposy = menumodel->newposy; + menumodel->curposz = menumodel->newposz; + menumodel->curscale = menumodel->newscale; } else { - f32 sp2d0 = (-cosf(thing->unk564 * M_PI) * 0.5f) + 0.5f; - f32 sp2cc = 1.0f - sp2d0; + f32 fracnew = (-cosf(menumodel->configurefrac * M_PI) * 0.5f) + 0.5f; + f32 fraccur = 1.0f - fracnew; - if (thing->unk568 & 2) { - sp430 = (thing->unk510 * sp2cc) + (sp2d0 * thing->unk538); - sp42c = (thing->unk514 * sp2cc) + (sp2d0 * thing->unk53c); - sp428 = (thing->unk518 * sp2cc) + (sp2d0 * thing->unk540); + if (menumodel->flags & MENUMODELFLAG_HASPOSITION) { + posx = (menumodel->curposx * fraccur) + (fracnew * menumodel->newposx); + posy = (menumodel->curposy * fraccur) + (fracnew * menumodel->newposy); + posz = (menumodel->curposz * fraccur) + (fracnew * menumodel->newposz); } else { - sp430 = thing->unk510 = thing->unk538; - sp42c = thing->unk514 = thing->unk53c; - sp428 = thing->unk518 = thing->unk540; + posx = menumodel->curposx = menumodel->newposx; + posy = menumodel->curposy = menumodel->newposy; + posz = menumodel->curposz = menumodel->newposz; } - if (thing->unk568 & 1) { - sp424 = (thing->unk51c * sp2cc) + (sp2d0 * thing->unk544); + if (menumodel->flags & MENUMODELFLAG_HASSCALE) { + scale = (menumodel->curscale * fraccur) + (fracnew * menumodel->newscale); } else { - sp424 = thing->unk51c = thing->unk544; + scale = menumodel->curscale = menumodel->newscale; } - if (thing->unk568 & 4) { + if (menumodel->flags & MENUMODELFLAG_HASROTATION) { f32 sp2bc[4]; f32 sp2ac[4]; f32 sp29c[4]; - struct coord sp290; + struct coord tmprot; - sp290.x = thing->unk520; - sp290.y = thing->unk524; - sp290.z = thing->unk528; + tmprot.x = menumodel->currotx; + tmprot.y = menumodel->curroty; + tmprot.z = menumodel->currotz; - quaternion0f096ca0(&sp290, sp2bc); + quaternion0f096ca0(&tmprot, sp2bc); - sp290.x = thing->unk548; - sp290.y = thing->unk54c; - sp290.z = thing->unk550; + tmprot.x = menumodel->newrotx; + tmprot.y = menumodel->newroty; + tmprot.z = menumodel->newrotz; - quaternion0f096ca0(&sp290, sp2ac); - quaternionSlerp(sp2bc, sp2ac, sp2d0, sp29c); - quaternionToMtx(sp29c, &sp350); + quaternion0f096ca0(&tmprot, sp2ac); + quaternionSlerp(sp2bc, sp2ac, fracnew, sp29c); + quaternionToMtx(sp29c, &rotmtx); } else { - a = thing->unk548; - b = thing->unk54c; - c = thing->unk550; + menumodel->currotx = rotx = menumodel->newrotx; + menumodel->curroty = roty = menumodel->newroty; + menumodel->currotz = rotz = menumodel->newrotz; - thing->unk520 = a; - thing->unk524 = b; - thing->unk528 = c; + tmpcoord.x = rotx; + tmpcoord.y = roty; + tmpcoord.z = rotz; - sp398.x = a; - sp398.y = b; - sp398.z = c; - - mtx4LoadRotation(&sp398, &sp350); + mtx4LoadRotation(&tmpcoord, &rotmtx); } } } - if (!thing->unk5b1_05) { - sp430 = thing->unk510 = thing->unk538; - sp42c = thing->unk514 = thing->unk53c; - sp428 = thing->unk518 = thing->unk540; - sp424 = thing->unk51c = thing->unk544; + if (!menumodel->configuring) { + posx = menumodel->curposx = menumodel->newposx; + posy = menumodel->curposy = menumodel->newposy; + posz = menumodel->curposz = menumodel->newposz; + + scale = menumodel->curscale = menumodel->newscale; if (1); - a = thing->unk548; - b = thing->unk54c; - c = thing->unk550; - thing->unk520 = a; - thing->unk524 = b; - thing->unk528 = c; + menumodel->currotx = rotx = menumodel->newrotx; + menumodel->curroty = roty = menumodel->newroty; + menumodel->currotz = rotz = menumodel->newrotz; - sp398.x = a; - sp398.y = b; - sp398.z = c; + tmpcoord.x = rotx; + tmpcoord.y = roty; + tmpcoord.z = rotz; - mtx4LoadRotation(&sp398, &sp350); + mtx4LoadRotation(&tmpcoord, &rotmtx); } } - sp30c[0] = -100.0f + sp428; + screenz[0] = -100.0f + posz; - if (arg2 == 1) { + if (modeltype == MENUMODELTYPE_HUDPIECE) { if (IS8MB()) { - sp390[0] = thing->unk510 * g_ScaleX; - sp390[1] = thing->unk514; + screenpos[0] = menumodel->curposx * g_ScaleX; + screenpos[1] = menumodel->curposy; } } else { - sp390[0] = sp430 * g_ScaleX + viGetViewLeft() + viGetViewWidth() * 0.5f; - sp390[1] = sp42c + viGetViewTop() + viGetViewHeight() * 0.5f; + screenpos[0] = posx * g_ScaleX + viGetViewLeft() + viGetViewWidth() * 0.5f; + screenpos[1] = posy + viGetViewTop() + viGetViewHeight() * 0.5f; } - cam0f0b4c3c(sp390, &sp398, 1.0f); - mtx4LoadIdentity(&sp310); + cam0f0b4c3c(screenpos, &tmpcoord, 1.0f); - if (thing->partvisibility != NULL) { - struct modelpartvisibility *ptr = thing->partvisibility; + mtx4LoadIdentity(&posmtx); + + // Show or hide model parts according to the visibility list + if (menumodel->partvisibility != NULL) { + struct modelpartvisibility *ptr = menumodel->partvisibility; while (ptr->part != 255) { - struct modelnode *node = modelGetPart(thing->bodymodeldef, ptr->part); + struct modelnode *node = modelGetPart(menumodel->bodymodeldef, ptr->part); if (node) { - union modelrwdata *rwdata = modelGetNodeRwData(&thing->bodymodel, node); + union modelrwdata *rwdata = modelGetNodeRwData(&menumodel->bodymodel, node); if (rwdata) { if (ptr->visible) { @@ -2120,39 +2109,40 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) } } - if (arg2 == 3) { - sp398.x = thing->unk510; - sp398.y = thing->unk514; - sp398.z = thing->unk518; + if (modeltype == MENUMODELTYPE_3) { + tmpcoord.x = menumodel->curposx; + tmpcoord.y = menumodel->curposy; + tmpcoord.z = menumodel->curposz; } else { - c = sp30c[0] / sp398.z; - sp398.x = c * sp398.x; - sp398.y = c * sp398.y; - sp398.z = c * sp398.z; + // Reusing rotz + rotz = screenz[0] / tmpcoord.z; + tmpcoord.x = rotz * tmpcoord.x; + tmpcoord.y = rotz * tmpcoord.y; + tmpcoord.z = rotz * tmpcoord.z; } #if VERSION < VERSION_NTSC_1_0 - if ((thing->unk010 & 0x80000000) != 0) { + if (MENUMODELPARAMS_HAS_MASTER_HEADBODY(menumodel->curparams)) { struct coord oldpos; struct coord newpos = {0, 0, 0}; u32 stack[3]; - modelUpdateInfo(&thing->bodymodel); + modelUpdateInfo(&menumodel->bodymodel); - modelGetRootPosition(&thing->bodymodel, &oldpos); + modelGetRootPosition(&menumodel->bodymodel, &oldpos); if (joyGetButtons(0, L_TRIG)) { - modelSetRootPosition(&thing->bodymodel, &newpos); + modelSetRootPosition(&menumodel->bodymodel, &newpos); } } #endif - mtx4LoadTranslation(&sp398, &sp310); + mtx4LoadTranslation(&tmpcoord, &posmtx); - if (sp308) { - mtx00015f04(sp424 * sp2f8, &sp310); + if (haszoom) { + mtx00015f04(scale * zoomy, &posmtx); } else { - mtx00015f04(sp424, &sp310); + mtx00015f04(scale, &posmtx); } { @@ -2161,30 +2151,31 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) Mtxf sp1c4; Mtxf sp184; - if (sp308) { - mtx4LoadTranslation(&sp2fc, &sp204); + if (haszoom) { + mtx4LoadTranslation(&zoompos, &sp204); } else { - sp398.x = thing->unk52c; - sp398.y = thing->unk530; - sp398.z = thing->unk534; - mtx4LoadTranslation(&sp398, &sp204); + tmpcoord.x = menumodel->displacex; + tmpcoord.y = menumodel->displacey; + tmpcoord.z = menumodel->displacez; + + mtx4LoadTranslation(&tmpcoord, &sp204); } - mtx4MultMtx4(&sp310, &sp350, &sp244); + mtx4MultMtx4(&posmtx, &rotmtx, &sp244); - if (arg2 == 3) { + if (modeltype == MENUMODELTYPE_3) { credits0f13ae04(&sp1c4); mtx4MultMtx4(&sp1c4, &sp244, &sp184); - mtx4MultMtx4(&sp184, &sp204, &thing->unk014); + mtx4MultMtx4(&sp184, &sp204, &menumodel->mtx); } else { - mtx4MultMtx4(&sp244, &sp204, &thing->unk014); + mtx4MultMtx4(&sp244, &sp204, &menumodel->mtx); } } gdl = menugfx0f0e2348(gdl); - if (arg2 < 3) { - if (arg2 != 0) { + if (modeltype < MENUMODELTYPE_3) { + if (modeltype != MENUMODELTYPE_DEFAULT) { gdl = func0f0d49c8(gdl); gSPMatrix(gdl++, osVirtualToPhysical(camGetPerspectiveMtxL()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); } else { @@ -2205,52 +2196,57 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) } } - sp3b4 = gfxAllocate(thing->bodymodeldef->nummatrices * sizeof(Mtxf)); + // Allocate model matrices + matrices = gfxAllocate(menumodel->bodymodeldef->nummatrices * sizeof(Mtxf)); - for (i = 0; i < thing->bodymodeldef->nummatrices; i++) { - mtx4LoadIdentity(&sp3b4[i]); + for (i = 0; i < menumodel->bodymodeldef->nummatrices; i++) { + mtx4LoadIdentity(&matrices[i]); } - thing->bodymodel.matrices = sp3b4; + menumodel->bodymodel.matrices = matrices; - if (thing->unk05c && thing->unk05e != thing->unk05c) { - if (thing->unk5b1_04) { - modelSetAnimation(&thing->bodymodel, thing->unk05c, false, 0, PALUPF(-0.5f), 0.0f); - modelSetAnimFrame(&thing->bodymodel, modelGetNumAnimFrames(&thing->bodymodel)); + // Set new animation if requested + if (menumodel->newanimnum && menumodel->curanimnum != menumodel->newanimnum) { + if (menumodel->reverseanim) { + modelSetAnimation(&menumodel->bodymodel, menumodel->newanimnum, false, 0, PALUPF(-0.5f), 0.0f); + modelSetAnimFrame(&menumodel->bodymodel, modelGetNumAnimFrames(&menumodel->bodymodel)); } else { - modelSetAnimation(&thing->bodymodel, thing->unk05c, false, 0, PALUPF(0.5f), 0.0f); + modelSetAnimation(&menumodel->bodymodel, menumodel->newanimnum, false, 0, PALUPF(0.5f), 0.0f); } - thing->unk05e = thing->unk05c; + menumodel->curanimnum = menumodel->newanimnum; } - thing->unk05c = 0; + menumodel->newanimnum = 0; - if (thing->unk05e != 0) { - f32 sp178; + // Tick the animation, if any + if (menumodel->curanimnum != 0) { + f32 frame; u32 stack; - modelTickAnimQuarterSpeed(&thing->bodymodel, g_Vars.diffframe240, true); + modelTickAnimQuarterSpeed(&menumodel->bodymodel, g_Vars.diffframe240, true); - if (thing->unk5b1_04) { - sp178 = modelGetNumAnimFrames(&thing->bodymodel) - modelGetCurAnimFrame(&thing->bodymodel); + if (menumodel->reverseanim) { + frame = modelGetNumAnimFrames(&menumodel->bodymodel) - modelGetCurAnimFrame(&menumodel->bodymodel); } else { - sp178 = modelGetCurAnimFrame(&thing->bodymodel); + frame = modelGetCurAnimFrame(&menumodel->bodymodel); } - if (sp178 >= modelGetNumAnimFrames(&thing->bodymodel) - 1) { - thing->unk05e = 0; + if (frame >= modelGetNumAnimFrames(&menumodel->bodymodel) - 1) { + menumodel->curanimnum = 0; } } - mtx4Copy(&thing->unk014, sp3b4); + mtx4Copy(&menumodel->mtx, matrices); - renderdata.unk00 = &thing->unk014; - renderdata.unk10 = thing->bodymodel.matrices; - modelSetMatricesWithAnim(&renderdata, &thing->bodymodel); + renderdata.unk00 = &menumodel->mtx; + renderdata.unk10 = menumodel->bodymodel.matrices; - if (thing->bodymodeldef->skel == &g_SkelHudPiece) { - struct modelnode *node = modelGetPart(thing->bodymodeldef, MODELPART_HUDPIECE_0000); + modelSetMatricesWithAnim(&renderdata, &menumodel->bodymodel); + + if (menumodel->bodymodeldef->skel == &g_SkelHudPiece) { + // Update the hudpiece's liquid texture + struct modelnode *node = modelGetPart(menumodel->bodymodeldef, MODELPART_HUDPIECE_0000); if (node) { struct modelrodata_gundl *rodata = &node->rodata->gundl; @@ -2272,44 +2268,46 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) } } - node = modelGetPart(thing->bodymodeldef, MODELPART_HUDPIECE_0002); + // Rotate the hudpiece's rotor thing + node = modelGetPart(menumodel->bodymodeldef, MODELPART_HUDPIECE_0002); if (node) { - s32 sp160; + s32 mtxindex = modelFindNodeMtxIndex(node, 0); Mtxf sp120; Mtxf spe0; - sp160 = modelFindNodeMtxIndex(node, 0); + mtx4LoadIdentity(&sp120); mtx4LoadXRotation(menuGetCosOscFrac(4), &sp120); - mtx4MultMtx4((Mtxf *)((uintptr_t)sp3b4 + sp160 * sizeof(Mtxf)), &sp120, &spe0); - mtx4Copy(&spe0, (Mtxf *)((uintptr_t)sp3b4 + sp160 * sizeof(Mtxf))); + mtx4MultMtx4((Mtxf *)((uintptr_t)matrices + mtxindex * sizeof(Mtxf)), &sp120, &spe0); + mtx4Copy(&spe0, (Mtxf *)((uintptr_t)matrices + mtxindex * sizeof(Mtxf))); } - node = modelGetPart(thing->bodymodeldef, MODELPART_HUDPIECE_0001); + // Make the menu projection lines come from the hudpiece eye + node = modelGetPart(menumodel->bodymodeldef, MODELPART_HUDPIECE_0001); if (node) { if (g_MenuData.root == MENUROOT_MAINMENU || g_MenuData.root == MENUROOT_FILEMGR || g_MenuData.root == MENUROOT_MPSETUP || g_MenuData.root == MENUROOT_TRAINING) { - s32 index = modelFindNodeMtxIndex(node, 0); - struct coord spd0; - f32 spc8[2]; + s32 mtxindex = modelFindNodeMtxIndex(node, 0); + struct coord pos; + f32 screenpos[2]; - spd0.x = sp3b4[index].m[3][0]; - spd0.y = sp3b4[index].m[3][1]; - spd0.z = sp3b4[index].m[3][2]; + pos.x = matrices[mtxindex].m[3][0]; + pos.y = matrices[mtxindex].m[3][1]; + pos.z = matrices[mtxindex].m[3][2]; - cam0f0b4d04(&spd0, spc8); - var8009de98 = ((s32)spc8[0] - viGetWidth() / 2) / g_ScaleX; - var8009de9c = (s32)spc8[1] - viGetHeight() / 2; + cam0f0b4d04(&pos, screenpos); + + g_MenuProjectFromX = ((s32)screenpos[0] - viGetWidth() / 2) / g_ScaleX; + g_MenuProjectFromY = (s32)screenpos[1] - viGetHeight() / 2; } } } gSPSetLights1(gdl++, var80071468); - gSPLookAtX(gdl++, &camGetLookAt()->l[0]); - gSPLookAtY(gdl++, &camGetLookAt()->l[1]); + gSPLookAt(gdl++, camGetLookAt()); renderdata.unk30 = 1; renderdata.envcolour = 0xffffffff; @@ -2319,21 +2317,22 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) renderdata.gdl = gdl; renderdata.zbufferenabled = true; - modelRender(&renderdata, &thing->bodymodel); + + modelRender(&renderdata, &menumodel->bodymodel); gdl = renderdata.gdl; mtx00016760(); - for (i = 0; i < thing->bodymodeldef->nummatrices; i++) { + for (i = 0; i < menumodel->bodymodeldef->nummatrices; i++) { Mtxf sp70; - mtx4Copy((Mtxf *)((uintptr_t)thing->bodymodel.matrices + i * sizeof(Mtxf)), &sp70); - mtxF2L(&sp70, &thing->bodymodel.matrices[i]); + mtx4Copy((Mtxf *)((uintptr_t)menumodel->bodymodel.matrices + i * sizeof(Mtxf)), &sp70); + mtxF2L(&sp70, &menumodel->bodymodel.matrices[i]); } mtx00016784(); - if (arg2 < 3) { + if (modeltype < MENUMODELTYPE_3) { gdl = func0f0d479c(gdl); } @@ -2491,9 +2490,9 @@ Gfx *dialogRender(Gfx *gdl, struct menudialog *dialog, struct menu *menu, bool l if (g_Menus[g_MpPlayerNum].curdialog == dialog && (dialog->definition->flags & MENUDIALOGFLAG_0002) && !lightweight - && g_Menus[g_MpPlayerNum].unk840.unk5b1_07 == 1) { + && g_Menus[g_MpPlayerNum].menumodel.drawbehinddialog == true) { gSPSetGeometryMode(gdl++, G_ZBUFFER); - gdl = menuRenderModels(gdl, &g_Menus[g_MpPlayerNum].unk840, 2); + gdl = menuRenderModel(gdl, &g_Menus[g_MpPlayerNum].menumodel, MENUMODELTYPE_2); gSPClearGeometryMode(gdl++, G_ZBUFFER); } @@ -2729,10 +2728,10 @@ Gfx *dialogRender(Gfx *gdl, struct menudialog *dialog, struct menu *menu, bool l if (g_Menus[g_MpPlayerNum].curdialog == dialog && (dialog->definition->flags & MENUDIALOGFLAG_0002) && !lightweight - && !g_Menus[g_MpPlayerNum].unk840.unk5b1_07) { + && !g_Menus[g_MpPlayerNum].menumodel.drawbehinddialog) { gSPSetGeometryMode(gdl++, G_ZBUFFER); - gdl = menuRenderModels(gdl, &g_Menus[g_MpPlayerNum].unk840, 0); + gdl = menuRenderModel(gdl, &g_Menus[g_MpPlayerNum].menumodel, MENUMODELTYPE_DEFAULT); gSPClearGeometryMode(gdl++, G_ZBUFFER); @@ -3509,7 +3508,7 @@ void menuPushRootDialog(struct menudialogdef *dialogdef, s32 root) || root == MENUROOT_MPSETUP || root == MENUROOT_TRAINING || root == MENUROOT_FILEMGR) { - if (IS8MB() && (g_MenuData.unk5d4 == 0 || g_MenuData.unk01c.unk5b1_04)) { + if (IS8MB() && (g_MenuData.unk5d4 == 0 || g_MenuData.hudpiece.reverseanim)) { if (!g_MenuData.unk5d5_04) { g_MenuData.unk5d5_05 = true; } @@ -3599,8 +3598,8 @@ Gfx *menuRenderDialogs(Gfx *gdl) if (g_MenuData.root == MENUROOT_MPPAUSE || g_MenuData.root == MENUROOT_PICKTARGET || g_MenuData.root == MENUROOT_MPENDSCREEN) { - var8009de98 = g_Menus[g_MpPlayerNum].curdialog->x + g_Menus[g_MpPlayerNum].curdialog->width / 2 - viGetWidth() / (g_ScaleX * 2); - var8009de9c = g_Menus[g_MpPlayerNum].curdialog->y + g_Menus[g_MpPlayerNum].curdialog->height / 2 - viGetHeight() / 2; + g_MenuProjectFromX = g_Menus[g_MpPlayerNum].curdialog->x + g_Menus[g_MpPlayerNum].curdialog->width / 2 - viGetWidth() / (g_ScaleX * 2); + g_MenuProjectFromY = g_Menus[g_MpPlayerNum].curdialog->y + g_Menus[g_MpPlayerNum].curdialog->height / 2 - viGetHeight() / 2; gdl = menuRenderDialog(gdl, g_Menus[g_MpPlayerNum].curdialog, &g_Menus[g_MpPlayerNum], 0); } else { @@ -3686,40 +3685,36 @@ Gfx *menuRenderDialogs(Gfx *gdl) u32 var800714e8 = 0; -void func0f0f8bb4(struct menu840 *arg0, u32 arg1, u32 arg2) +void menuResetModel(struct menumodel *menumodel, u32 allocationlen, bool allocate) { - arg0->unk008 = arg1; - arg0->unk004 = arg2 ? mempAlloc(arg1, MEMPOOL_STAGE) : NULL; - arg0->unk54c = 0.0f; - arg0->unk000 = 0; - arg0->unk00c = 0xffff; - arg0->bodymodeldef = NULL; - arg0->unk010 = 0; - arg0->unk56c = 0; - arg0->unk570 = 0; - arg0->partvisibility = NULL; - arg0->unk5b1_01 = false; - arg0->unk5b1_02 = false; - arg0->unk5b1_04 = false; - arg0->unk5b1_06 = false; - arg0->headnum = -1; - arg0->bodynum = -1; - arg0->unk538 = 0.0f; - arg0->unk510 = 0.0f; - arg0->unk53c = 0.0f; - arg0->unk514 = 0.0f; - arg0->unk540 = 0.0f; - arg0->unk518 = 0.0f; - arg0->unk544 = 0.0f; - arg0->unk51c = 0.0f; - arg0->unk548 = 0.0f; - arg0->unk520 = 0.0f; - arg0->unk550 = 0.0f; - arg0->unk528 = 0.0f; - arg0->unk534 = 0.0f; - arg0->unk530 = 0.0f; - arg0->unk52c = 0.0f; - arg0->unk524 = arg0->unk54c; + menumodel->alloclen = allocationlen; + menumodel->allocstart = allocate ? mempAlloc(allocationlen, MEMPOOL_STAGE) : NULL; + menumodel->loaddelay = 0; + menumodel->newparams = MENUMODELPARAMS_SET_FILENUM(0xffff); + menumodel->bodymodeldef = NULL; + menumodel->curparams = 0; + + menumodel->curposx = menumodel->newposx = 0.0f; + menumodel->curposy = menumodel->newposy = 0.0f; + menumodel->curposz = menumodel->newposz = 0.0f; + + menumodel->curscale = menumodel->newscale = 0.0f; + + menumodel->currotx = menumodel->newrotx = 0.0f; + menumodel->curroty = menumodel->newroty = 0.0f; + menumodel->currotz = menumodel->newrotz = 0.0f; + + menumodel->displacex = menumodel->displacey = menumodel->displacez = 0.0f; + + menumodel->unk56c = 0; + menumodel->unk570 = 0; + menumodel->partvisibility = NULL; + menumodel->isperfecthead = false; + menumodel->unk5b1_02 = false; + menumodel->reverseanim = false; + menumodel->unk5b1_06 = false; + menumodel->headnum = -1; + menumodel->bodynum = -1; } void menuReset(void) @@ -3759,10 +3754,10 @@ void menuReset(void) } for (i = 0; i < ARRAYCOUNT(g_Menus); i++) { - g_Menus[i].unk840.unk004 = NULL; + g_Menus[i].menumodel.allocstart = NULL; } - g_MenuData.unk01c.unk004 = NULL; + g_MenuData.hudpiece.allocstart = NULL; if (g_Vars.stagenum == STAGE_CITRAINING) { g_MissionConfig.iscoop = false; @@ -3782,24 +3777,24 @@ void menuReset(void) } for (i = 0; i < max; i++) { - func0f0f8bb4(&g_Menus[i].unk840, IS4MB() ? 0xb400 : 0x25800, 1); + menuResetModel(&g_Menus[i].menumodel, IS4MB() ? 0xb400 : 0x25800, true); } if (IS8MB()) { - func0f0f8bb4(&g_MenuData.unk01c, 0xc800, 1); + menuResetModel(&g_MenuData.hudpiece, 0xc800, true); } - g_MenuData.unk01c.unk00c = FILE_GHUDPIECE; - g_MenuData.unk01c.unk524 = g_MenuData.unk01c.unk54c = -M_PI; - g_MenuData.unk01c.unk520 = g_MenuData.unk01c.unk548 = 0; - g_MenuData.unk01c.unk528 = g_MenuData.unk01c.unk550 = 0; - g_MenuData.unk01c.unk510 = g_MenuData.unk01c.unk538 = -205.5f; - g_MenuData.unk01c.unk514 = g_MenuData.unk01c.unk53c = 244.7f; - g_MenuData.unk01c.unk518 = g_MenuData.unk01c.unk540 = 68.3f; - g_MenuData.unk01c.unk51c = g_MenuData.unk01c.unk544 = 0.12209f; - g_MenuData.unk01c.unk5b1_01 = false; - g_MenuData.unk01c.unk574 = 0; - g_MenuData.unk01c.unk580 = 0; + g_MenuData.hudpiece.newparams = MENUMODELPARAMS_SET_FILENUM(FILE_GHUDPIECE); + g_MenuData.hudpiece.curroty = g_MenuData.hudpiece.newroty = -M_PI; + g_MenuData.hudpiece.currotx = g_MenuData.hudpiece.newrotx = 0; + g_MenuData.hudpiece.currotz = g_MenuData.hudpiece.newrotz = 0; + g_MenuData.hudpiece.curposx = g_MenuData.hudpiece.newposx = -205.5f; + g_MenuData.hudpiece.curposy = g_MenuData.hudpiece.newposy = 244.7f; + g_MenuData.hudpiece.curposz = g_MenuData.hudpiece.newposz = 68.3f; + g_MenuData.hudpiece.curscale = g_MenuData.hudpiece.newscale = 0.12209f; + g_MenuData.hudpiece.isperfecthead = false; + g_MenuData.hudpiece.zoomtimer60 = 0; + g_MenuData.hudpiece.removingpiece = false; } g_MenuData.unk5d4 = 0; @@ -3894,7 +3889,7 @@ void menuSwipe(s32 direction) g_Menus[g_MpPlayerNum].curdialog->state = MENUDIALOGSTATE_PREOPEN; g_Menus[g_MpPlayerNum].curdialog->statefrac = 0.0f; - func0f0f37a4(&g_Menus[g_MpPlayerNum].unk840); + menuUnsetModel(&g_Menus[g_MpPlayerNum].menumodel); menuPlaySound(MENUSOUND_SWIPE); } @@ -5186,10 +5181,10 @@ Gfx *menuRender(Gfx *gdl) // Calculate hudpiece things then render it if (g_MenuData.unk5d5_05) { - g_MenuData.unk01c.unk05e = 0; - g_MenuData.unk01c.unk05c = 0x40d; - g_MenuData.unk01c.unk580 = 0; - g_MenuData.unk01c.unk5b1_04 = false; + g_MenuData.hudpiece.curanimnum = 0; + g_MenuData.hudpiece.newanimnum = ANIM_040D; + g_MenuData.hudpiece.removingpiece = false; + g_MenuData.hudpiece.reverseanim = false; g_MenuData.unk5d4 = 1; g_MenuData.unk5d5_05 = false; } @@ -5202,11 +5197,11 @@ Gfx *menuRender(Gfx *gdl) // Everyone 1 in 100 frames on average, calculate a new X/Y for the hudpiece // Note: unintentional 64-bit float comparison done here if (RANDOMFRAC() < 0.01) { - g_MenuData.unk01c.unk538 = RANDOMFRAC() * 80.0f + -205.5f - 40.0f; - g_MenuData.unk01c.unk53c = RANDOMFRAC() * 80.0f + 244.7f - 40.0f; + g_MenuData.hudpiece.newposx = RANDOMFRAC() * 80.0f + -205.5f - 40.0f; + g_MenuData.hudpiece.newposy = RANDOMFRAC() * 80.0f + 244.7f - 40.0f; } - var8009de98 = var8009de9c = 0; + g_MenuProjectFromX = g_MenuProjectFromY = 0; if (g_MenuData.root == MENUROOT_MPSETUP) { if (g_MenuData.count <= 0) { @@ -5234,13 +5229,13 @@ Gfx *menuRender(Gfx *gdl) } if (removepiece) { - if (g_MenuData.unk01c.unk580 == 0) { - g_MenuData.unk01c.unk5b1_04 = true; - g_MenuData.unk01c.unk05e = 0; - g_MenuData.unk01c.unk05c = 0x40d; - g_MenuData.unk01c.unk580 = 1; - } else if (g_MenuData.unk01c.unk05e == 0) { - g_MenuData.unk01c.unk580 = 0; + if (!g_MenuData.hudpiece.removingpiece) { + g_MenuData.hudpiece.reverseanim = true; + g_MenuData.hudpiece.curanimnum = 0; + g_MenuData.hudpiece.newanimnum = ANIM_040D; + g_MenuData.hudpiece.removingpiece = true; + } else if (g_MenuData.hudpiece.curanimnum == 0) { + g_MenuData.hudpiece.removingpiece = false; g_MenuData.unk5d4 = 0; } } @@ -5248,20 +5243,20 @@ Gfx *menuRender(Gfx *gdl) mainOverrideVariable("usePiece", &usepiece); if (usepiece) { - g_MenuData.unk5d5_03 = false; + g_MenuData.usezbuf = false; - gdl = menuRenderModels(gdl, &g_MenuData.unk01c, 1); + gdl = menuRenderModel(gdl, &g_MenuData.hudpiece, MENUMODELTYPE_HUDPIECE); gSPClearGeometryMode(gdl++, G_ZBUFFER); - g_MenuData.unk5d5_03 = true; + g_MenuData.usezbuf = true; } } else { - var8009de98 = var8009de9c = 0; + g_MenuProjectFromX = g_MenuProjectFromY = 0; } if (g_MenuData.unk5d5_04) { - var8009de98 = g_MenuData.unk670; - var8009de9c = g_MenuData.unk674; + g_MenuProjectFromX = g_MenuData.unk670; + g_MenuProjectFromY = g_MenuData.unk674; } // Render the second layer of the background (for the combat simulator cone, diff --git a/src/game/menugfx.c b/src/game/menugfx.c index a0e4b1bd4..636289cd5 100644 --- a/src/game/menugfx.c +++ b/src/game/menugfx.c @@ -1401,7 +1401,7 @@ Gfx *menugfxRenderBgFailure(Gfx *gdl) spb4 = M_TAU * g_20SecIntervalFrac; - var8009de98 = var8009de9c = 0; + g_MenuProjectFromX = g_MenuProjectFromY = 0; gdl = func0f0d4a3c(gdl, 0); @@ -1578,8 +1578,8 @@ Gfx *menugfxRenderBgCone(Gfx *gdl) */ Gfx *func0f0e458c(Gfx *gdl) { - var8009de98 = 0; - var8009de9c = -20 - viGetHeight() / 2; + g_MenuProjectFromX = 0; + g_MenuProjectFromY = -20 - viGetHeight() / 2; gdl = func0f0d4a3c(gdl, 0); @@ -1590,15 +1590,15 @@ Gfx *func0f0e458c(Gfx *gdl) gdl = menugfxDrawPlane(gdl, -1000, viGetHeight() + 10, 2000, viGetHeight() + 10, 0xffff00af, 0xffff00af, MENUPLANE_05); gdl = func0f0d4c80(gdl); - var8009de98 = var8009de9c = 0; + g_MenuProjectFromX = g_MenuProjectFromY = 0; return gdl; } Gfx *func0f0e46b0(Gfx *gdl, f32 arg1) { - s32 y1 = (var8009de9c + 120) + arg1 * (0.0f - (var8009de9c + 120)); - s32 y2 = (var8009de9c + 120) + arg1 * (240.0f - (var8009de9c + 120)); + s32 y1 = (g_MenuProjectFromY + 120) + arg1 * (0.0f - (g_MenuProjectFromY + 120)); + s32 y2 = (g_MenuProjectFromY + 120) + arg1 * (240.0f - (g_MenuProjectFromY + 120)); gdl = func0f0d4a3c(gdl, 0); @@ -1634,7 +1634,7 @@ Gfx *menugfxRenderBgFailureCopy(Gfx *gdl) spb4 = M_TAU * g_20SecIntervalFrac; - var8009de98 = var8009de9c = 0; + g_MenuProjectFromX = g_MenuProjectFromY = 0; gdl = func0f0d4a3c(gdl, 0); @@ -1809,8 +1809,8 @@ Gfx *menugfxRenderBgSuccess(Gfx *gdl) f0 = menuGetLinearIntervalFrac(10.0f); // Draw the two haze layers - var8009de98 = 0; - var8009de9c = 0; + g_MenuProjectFromX = 0; + g_MenuProjectFromY = 0; gdl = func0f0d4a3c(gdl, 0); diff --git a/src/game/menuitem.c b/src/game/menuitem.c index 7fa289e9c..2bf147771 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -2748,8 +2748,8 @@ char *menuitemScrollableGetText(u32 type) return challengeGetConfigDescription(g_Menus[g_MpPlayerNum].training.mpconfig); case DESCRIPTION_MPCHALLENGE: if (!challengeIsLoaded()) { - g_Menus[g_MpPlayerNum].unk840.unk010 = 0x4fac5ace; - challengeLoadAndStoreCurrent(g_Menus[g_MpPlayerNum].unk840.unk004, g_Menus[g_MpPlayerNum].unk840.unk008); + g_Menus[g_MpPlayerNum].menumodel.curparams = 0x4fac5ace; + challengeLoadAndStoreCurrent(g_Menus[g_MpPlayerNum].menumodel.allocstart, g_Menus[g_MpPlayerNum].menumodel.alloclen); } return challengeGetCurrentDescription(); case DESCRIPTION_CHRBIO: return ciGetChrBioDescription(); diff --git a/src/game/menutick.c b/src/game/menutick.c index f1e713d35..e6fefe0d3 100644 --- a/src/game/menutick.c +++ b/src/game/menutick.c @@ -690,9 +690,9 @@ void menuTick(void) if (g_Vars.currentplayer->gunctrl.gunmemowner == GUNMEMOWNER_INVMENU && g_Vars.stagenum != STAGE_CITRAINING) { g_MenuData.unk5d5_01 = true; - if (g_Menus[0].unk840.unk004) { + if (g_Menus[0].menumodel.allocstart) { bgunFreeGunMem(); - g_Menus[0].unk840.unk004 = NULL; + g_Menus[0].menumodel.allocstart = NULL; } } } diff --git a/src/game/mplayer/setup.c b/src/game/mplayer/setup.c index 7656332f4..915f09fe5 100644 --- a/src/game/mplayer/setup.c +++ b/src/game/mplayer/setup.c @@ -550,35 +550,35 @@ MenuItemHandlerResult func0f179d6c(s32 operation, struct menuitem *item, union h /** * This function is used by both player body selection and bot body selection. */ -MenuItemHandlerResult mpCharacterBodyMenuHandler(s32 operation, struct menuitem *item, union handlerdata *data, s32 mpheadnum, s32 mpbodynum, bool isplayer) +MenuItemHandlerResult mpCharacterBodyMenuHandler(s32 operation, struct menuitem *item, union handlerdata *data, s32 mpbodynum, s32 mpheadnum, bool isplayer) { switch (operation) { case MENUOP_GETOPTIONCOUNT: data->carousel.value = mpGetNumBodies(); break; case MENUOP_11: - g_Menus[g_MpPlayerNum].unk840.unk05c = 0x1fc; - g_Menus[g_MpPlayerNum].unk840.unk00c = mpbodynum << 16 | 0xffff | mpheadnum << 24; - g_Menus[g_MpPlayerNum].unk840.unk574 += g_Vars.diffframe60; + g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_01FC; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_MP_HEADBODY(mpheadnum, mpbodynum); + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 += g_Vars.diffframe60; - if (g_Menus[g_MpPlayerNum].unk840.unk574 > TICKS(480)) { - g_Menus[g_MpPlayerNum].unk840.unk574 -= TICKS(480); + if (g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 > TICKS(480)) { + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 -= TICKS(480); } - if (g_Menus[g_MpPlayerNum].unk840.unk578 > 0) { - g_Menus[g_MpPlayerNum].unk840.unk578 -= g_Vars.diffframe60; + if (g_Menus[g_MpPlayerNum].menumodel.rottimer60 > 0) { + g_Menus[g_MpPlayerNum].menumodel.rottimer60 -= g_Vars.diffframe60; } else { #if VERSION >= VERSION_PAL_BETA - f32 value = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60freal; + f32 value = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60freal; #else - f32 value = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60f; + f32 value = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60f; #endif - g_Menus[g_MpPlayerNum].unk840.unk54c = value; - g_Menus[g_MpPlayerNum].unk840.unk524 = value; + g_Menus[g_MpPlayerNum].menumodel.newroty = value; + g_Menus[g_MpPlayerNum].menumodel.curroty = value; } - g_Menus[g_MpPlayerNum].unk840.partvisibility = NULL; - g_Menus[g_MpPlayerNum].unk840.unk554 = 30; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = NULL; + g_Menus[g_MpPlayerNum].menumodel.zoom = 30; break; case MENUOP_21: if (!challengeIsFeatureUnlocked(mpGetBodyRequiredFeature(data->carousel.value))) { @@ -587,34 +587,36 @@ MenuItemHandlerResult mpCharacterBodyMenuHandler(s32 operation, struct menuitem break; #if VERSION >= VERSION_NTSC_1_0 case MENUOP_FOCUS: - g_Menus[g_MpPlayerNum].unk840.unk000 = 3; + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 3; break; #endif case MENUOP_GETSELECTEDINDEX: - data->carousel.value = mpheadnum; + data->carousel.value = mpbodynum; break; case MENUOP_SET: case MENUOP_CHECKPREFOCUSED: - g_Menus[g_MpPlayerNum].unk840.unk580 = 0; + g_Menus[g_MpPlayerNum].menumodel.removingpiece = false; - func0f0f372c(&g_Menus[g_MpPlayerNum].unk840, 0, 0, 0, 0, 0, 0, 1, 1); + menuConfigureModel(&g_Menus[g_MpPlayerNum].menumodel, 0, 0, 0, 0, 0, 0, 1, MENUMODELFLAG_HASSCALE); - g_Menus[g_MpPlayerNum].unk840.unk510 = 8.2f; - g_Menus[g_MpPlayerNum].unk840.unk514 = -4.1f; - g_Menus[g_MpPlayerNum].unk840.unk53c = -4.1f; + g_Menus[g_MpPlayerNum].menumodel.curposx = 8.2f; + g_Menus[g_MpPlayerNum].menumodel.newposx = 8.2f; - g_Menus[g_MpPlayerNum].unk840.unk538 = 8.2f; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0.002f; - g_Menus[g_MpPlayerNum].unk840.unk524 = -0.2f; - g_Menus[g_MpPlayerNum].unk840.unk54c = -0.2f; + g_Menus[g_MpPlayerNum].menumodel.curposy = -4.1f; + g_Menus[g_MpPlayerNum].menumodel.newposy = -4.1f; - g_Menus[g_MpPlayerNum].unk840.unk578 = TICKS(60); - g_Menus[g_MpPlayerNum].unk840.unk574 = TICKS(120); - g_Menus[g_MpPlayerNum].unk840.unk000 = 8; + g_Menus[g_MpPlayerNum].menumodel.curscale = 0.002f; + + g_Menus[g_MpPlayerNum].menumodel.curroty = -0.2f; + g_Menus[g_MpPlayerNum].menumodel.newroty = -0.2f; + + g_Menus[g_MpPlayerNum].menumodel.rottimer60 = TICKS(60); + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120); + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 8; #if VERSION >= VERSION_NTSC_1_0 if (operation == MENUOP_CHECKPREFOCUSED) { - g_Menus[g_MpPlayerNum].unk840.unk000 = 16; + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 16; } #endif @@ -1879,30 +1881,30 @@ MenuItemHandlerResult mpCharacterHeadMenuHandler(s32 operation, struct menuitem break; case MENUOP_11: #if VERSION >= VERSION_PAL_BETA - diffframe = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60freal; + diffframe = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60freal; #else - diffframe = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60f; + diffframe = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60f; #endif - g_Menus[g_MpPlayerNum].unk840.unk54c = diffframe; - g_Menus[g_MpPlayerNum].unk840.unk524 = diffframe; + g_Menus[g_MpPlayerNum].menumodel.newroty = diffframe; + g_Menus[g_MpPlayerNum].menumodel.curroty = diffframe; if (mpheadnum < mpGetNumHeads2()) { headnum = mpGetHeadId(mpheadnum); - g_Menus[g_MpPlayerNum].unk840.unk00c = g_HeadsAndBodies[headnum].filenum; - g_Menus[g_MpPlayerNum].unk840.unk5b1_01 = false; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(g_HeadsAndBodies[headnum].filenum); + g_Menus[g_MpPlayerNum].menumodel.isperfecthead = false; } else { headnum = mpGetBeauHeadId(func0f14a9f8(mpheadnum - mpGetNumHeads2())); - g_Menus[g_MpPlayerNum].unk840.unk00c = g_HeadsAndBodies[headnum].filenum; - g_Menus[g_MpPlayerNum].unk840.unk5b1_01 = true; - g_Menus[g_MpPlayerNum].unk840.unk5b0 = mpheadnum - mpGetNumHeads2(); + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(g_HeadsAndBodies[headnum].filenum); + g_Menus[g_MpPlayerNum].menumodel.isperfecthead = true; + g_Menus[g_MpPlayerNum].menumodel.perfectheadnum = mpheadnum - mpGetNumHeads2(); } - g_Menus[g_MpPlayerNum].unk840.unk574 = 0; - g_Menus[g_MpPlayerNum].unk840.partvisibility = visibility; - g_Menus[g_MpPlayerNum].unk840.unk554 = 30; + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = 0; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = visibility; + g_Menus[g_MpPlayerNum].menumodel.zoom = 30; break; case MENUOP_21: if (!challengeIsFeatureUnlocked(mpGetHeadRequiredFeature(data->carousel.value))) { @@ -1915,22 +1917,26 @@ MenuItemHandlerResult mpCharacterHeadMenuHandler(s32 operation, struct menuitem case MENUOP_SET: case MENUOP_FOCUS: #if VERSION >= VERSION_NTSC_1_0 - g_Menus[g_MpPlayerNum].unk840.unk000 = 3; + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 3; #endif mpGetNumHeads2(); - func0f0f372c(&g_Menus[g_MpPlayerNum].unk840, 0, 0, 0, 0, 0, 0, 1, 1); + menuConfigureModel(&g_Menus[g_MpPlayerNum].menumodel, 0, 0, 0, 0, 0, 0, 1, MENUMODELFLAG_HASSCALE); - g_Menus[g_MpPlayerNum].unk840.unk510 = 0; - g_Menus[g_MpPlayerNum].unk840.unk514 = 0; - g_Menus[g_MpPlayerNum].unk840.unk53c = -3; - g_Menus[g_MpPlayerNum].unk840.unk538 = 0; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0.01f; - g_Menus[g_MpPlayerNum].unk840.unk524 = -0.3f; - g_Menus[g_MpPlayerNum].unk840.unk54c = -0.3f; - g_Menus[g_MpPlayerNum].unk840.unk544 = 1; - g_Menus[g_MpPlayerNum].unk840.unk554 = 30; + g_Menus[g_MpPlayerNum].menumodel.curposx = 0; + g_Menus[g_MpPlayerNum].menumodel.curposy = 0; + + g_Menus[g_MpPlayerNum].menumodel.newposx = 0; + g_Menus[g_MpPlayerNum].menumodel.newposy = -3; + + g_Menus[g_MpPlayerNum].menumodel.curscale = 0.01f; + + g_Menus[g_MpPlayerNum].menumodel.curroty = -0.3f; + g_Menus[g_MpPlayerNum].menumodel.newroty = -0.3f; + + g_Menus[g_MpPlayerNum].menumodel.newscale = 1; + g_Menus[g_MpPlayerNum].menumodel.zoom = 30; break; } @@ -4051,12 +4057,12 @@ MenuDialogHandlerResult menudialog0017e3fc(s32 operation, struct menudialogdef * { switch (operation) { case MENUOP_OPEN: - g_Menus[g_MpPlayerNum].unk840.unk010 = 0; + g_Menus[g_MpPlayerNum].menumodel.curparams = 0; g_Menus[g_MpPlayerNum].training.mpconfig = challengeLoadBySlot( g_Menus[g_MpPlayerNum].training.unke1c, - g_Menus[g_MpPlayerNum].unk840.unk004, - g_Menus[g_MpPlayerNum].unk840.unk008); + g_Menus[g_MpPlayerNum].menumodel.allocstart, + g_Menus[g_MpPlayerNum].menumodel.alloclen); break; case MENUOP_CLOSE: break; @@ -4628,16 +4634,16 @@ MenuDialogHandlerResult mpCombatChallengesMenuDialog(s32 operation, struct menud && g_Menus[g_MpPlayerNum].curdialog && g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef && !challengeIsLoaded()) { - g_Menus[g_MpPlayerNum].unk840.unk010 = 0x4fac5ace; + g_Menus[g_MpPlayerNum].menumodel.curparams = 0x4fac5ace; challengeLoadAndStoreCurrent( - g_Menus[g_MpPlayerNum].unk840.unk004, - g_Menus[g_MpPlayerNum].unk840.unk008); + g_Menus[g_MpPlayerNum].menumodel.allocstart, + g_Menus[g_MpPlayerNum].menumodel.alloclen); } } if (operation == MENUOP_CLOSE) { - if (g_Menus[g_MpPlayerNum].unk840.unk010 == 0x4fac5ace) { + if (g_Menus[g_MpPlayerNum].menumodel.curparams == 0x4fac5ace) { challengeUnsetCurrent(); } } diff --git a/src/game/savebuffer.c b/src/game/savebuffer.c index d7ee77cca..b7fb2aef3 100644 --- a/src/game/savebuffer.c +++ b/src/game/savebuffer.c @@ -21,8 +21,8 @@ Vp var80070f10; s32 var8009de90; s32 var8009de94; -s32 var8009de98; -s32 var8009de9c; +s32 g_MenuProjectFromX; +s32 g_MenuProjectFromY; void func0f0d4690(Mtxf *mtx) { @@ -317,8 +317,8 @@ Gfx *menugfxDrawPlane(Gfx *gdl, s32 x1, s32 y1, s32 x2, s32 y2, u32 colour1, u32 vertices[1].y = y2; vertices[1].z = -10; - tmp1 = (f32) var8009de98 * a1 / scale; - tmp2 = (f32) var8009de9c * a1 / scale; + tmp1 = (f32) g_MenuProjectFromX * a1 / scale; + tmp2 = (f32) g_MenuProjectFromY * a1 / scale; vertices[2].x = vertices[0].v[0] + (s16) tmp1; vertices[2].y = vertices[0].v[1] + (s16) tmp2; diff --git a/src/game/trainingmenus.c b/src/game/trainingmenus.c index 53ba1232f..db90ba2a8 100644 --- a/src/game/trainingmenus.c +++ b/src/game/trainingmenus.c @@ -229,11 +229,9 @@ MenuDialogHandlerResult frTrainingInfoMenuDialog(s32 operation, struct menudialo break; case MENUOP_TICK: if (g_Menus[g_MpPlayerNum].curdialog && g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef) { - g_Menus[g_MpPlayerNum].unk840.unk574 -= g_Vars.diffframe60; - g_Menus[g_MpPlayerNum].unk840.unk54c = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk524 = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk528 = 0; - g_Menus[g_MpPlayerNum].unk840.unk550 = 0; + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 -= g_Vars.diffframe60; + g_Menus[g_MpPlayerNum].menumodel.curroty = g_Menus[g_MpPlayerNum].menumodel.newroty = 18.849555969238f * g_20SecIntervalFrac; + g_Menus[g_MpPlayerNum].menumodel.currotz = g_Menus[g_MpPlayerNum].menumodel.newrotz = 0; } break; case MENUOP_CLOSE: @@ -1538,14 +1536,14 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud case MENUOP_OPEN: if (bodynum == BODY_DRCAROLL) { scale = 0.7f; - g_Menus[g_MpPlayerNum].unk840.unk554 = -1; + g_Menus[g_MpPlayerNum].menumodel.zoom = -1; } else { - g_Menus[g_MpPlayerNum].unk840.unk554 = 30; + g_Menus[g_MpPlayerNum].menumodel.zoom = 30; scale = 1.0f; } - g_Menus[g_MpPlayerNum].unk840.unk574 = TICKS(120); - g_Menus[g_MpPlayerNum].unk840.unk580 = 0; + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120); + g_Menus[g_MpPlayerNum].menumodel.removingpiece = false; #if VERSION == VERSION_PAL_FINAL if (g_ViRes != VIRES_HI) { @@ -1585,14 +1583,15 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud scale = 0.8f; } - func0f0f372c(&g_Menus[g_MpPlayerNum].unk840, x, y, 0, 0, 0, 0, scale, 7); + menuConfigureModel(&g_Menus[g_MpPlayerNum].menumodel, x, y, 0, 0, 0, 0, scale, + MENUMODELFLAG_HASSCALE | MENUMODELFLAG_HASPOSITION | MENUMODELFLAG_HASROTATION); - g_Menus[g_MpPlayerNum].unk840.unk510 = 8.2f; - g_Menus[g_MpPlayerNum].unk840.unk514 = -4.1f; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0.00393f; - g_Menus[g_MpPlayerNum].unk840.unk524 = 0; - g_Menus[g_MpPlayerNum].unk840.unk54c = 0; - g_Menus[g_MpPlayerNum].unk840.unk578 = TICKS(60); + g_Menus[g_MpPlayerNum].menumodel.curposx = 8.2f; + g_Menus[g_MpPlayerNum].menumodel.curposy = -4.1f; + g_Menus[g_MpPlayerNum].menumodel.curscale = 0.00393f; + g_Menus[g_MpPlayerNum].menumodel.curroty = 0; + g_Menus[g_MpPlayerNum].menumodel.newroty = 0; + g_Menus[g_MpPlayerNum].menumodel.rottimer60 = TICKS(60); break; case MENUOP_CLOSE: break; @@ -1612,10 +1611,10 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud { 255 }, }; - g_Menus[g_MpPlayerNum].unk840.partvisibility = vis; - g_Menus[g_MpPlayerNum].unk840.unk05c = 318; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = vis; + g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_013E; } else { - g_Menus[g_MpPlayerNum].unk840.unk05c = 106; + g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_006A; } if (bodynum == BODY_THEKING) { @@ -1624,23 +1623,21 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud { 255 }, }; - g_Menus[g_MpPlayerNum].unk840.partvisibility = vis; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = vis; } - g_Menus[g_MpPlayerNum].unk840.unk00c = 0xffff; - g_Menus[g_MpPlayerNum].unk840.unk00c |= (mpheadnum << 16); - g_Menus[g_MpPlayerNum].unk840.unk00c |= (mpbodynum << 24); + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_MP_HEADBODY(mpheadnum, mpbodynum); - if (g_Menus[g_MpPlayerNum].unk840.unk578 > 0) { - g_Menus[g_MpPlayerNum].unk840.unk578 -= g_Vars.diffframe60; + if (g_Menus[g_MpPlayerNum].menumodel.rottimer60 > 0) { + g_Menus[g_MpPlayerNum].menumodel.rottimer60 -= g_Vars.diffframe60; } else { #if VERSION >= VERSION_PAL_BETA - f32 tmp = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60freal; + f32 roty = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60freal; #else - f32 tmp = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60f; + f32 roty = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60f; #endif - g_Menus[g_MpPlayerNum].unk840.unk54c = tmp; - g_Menus[g_MpPlayerNum].unk840.unk524 = tmp; + g_Menus[g_MpPlayerNum].menumodel.newroty = roty; + g_Menus[g_MpPlayerNum].menumodel.curroty = roty; } break; @@ -1887,58 +1884,54 @@ MenuDialogHandlerResult dtTrainingDetailsMenuDialog(s32 operation, struct menudi #if VERSION == VERSION_PAL_FINAL if (g_ViRes == VIRES_HI) { if (optionsGetScreenRatio() == SCREENRATIO_16_9) { - g_Menus[g_MpPlayerNum].unk840.unk538 = 84; - g_Menus[g_MpPlayerNum].unk840.unk510 = 84; + g_Menus[g_MpPlayerNum].menumodel.newposx = 84; + g_Menus[g_MpPlayerNum].menumodel.curposx = 84; } else { - g_Menus[g_MpPlayerNum].unk840.unk538 = 104; - g_Menus[g_MpPlayerNum].unk840.unk510 = 104; + g_Menus[g_MpPlayerNum].menumodel.newposx = 104; + g_Menus[g_MpPlayerNum].menumodel.curposx = 104; } } else { if (optionsGetScreenRatio() == SCREENRATIO_16_9) { - g_Menus[g_MpPlayerNum].unk840.unk538 = 64; - g_Menus[g_MpPlayerNum].unk840.unk510 = 64; + g_Menus[g_MpPlayerNum].menumodel.newposx = 64; + g_Menus[g_MpPlayerNum].menumodel.curposx = 64; } else { - g_Menus[g_MpPlayerNum].unk840.unk538 = 84; - g_Menus[g_MpPlayerNum].unk840.unk510 = 84; + g_Menus[g_MpPlayerNum].menumodel.newposx = 84; + g_Menus[g_MpPlayerNum].menumodel.curposx = 84; } } #elif VERSION == VERSION_PAL_BETA if (optionsGetScreenRatio() == SCREENRATIO_16_9) { - g_Menus[g_MpPlayerNum].unk840.unk538 = 64; - g_Menus[g_MpPlayerNum].unk840.unk510 = 64; + g_Menus[g_MpPlayerNum].menumodel.newposx = 64; + g_Menus[g_MpPlayerNum].menumodel.curposx = 64; } else { - g_Menus[g_MpPlayerNum].unk840.unk538 = 84; - g_Menus[g_MpPlayerNum].unk840.unk510 = 84; + g_Menus[g_MpPlayerNum].menumodel.newposx = 84; + g_Menus[g_MpPlayerNum].menumodel.curposx = 84; } #else if (optionsGetScreenRatio() == SCREENRATIO_16_9) { - g_Menus[g_MpPlayerNum].unk840.unk538 = 70; - g_Menus[g_MpPlayerNum].unk840.unk510 = 70; + g_Menus[g_MpPlayerNum].menumodel.newposx = 70; + g_Menus[g_MpPlayerNum].menumodel.curposx = 70; } else { - g_Menus[g_MpPlayerNum].unk840.unk538 = 90; - g_Menus[g_MpPlayerNum].unk840.unk510 = 90; + g_Menus[g_MpPlayerNum].menumodel.newposx = 90; + g_Menus[g_MpPlayerNum].menumodel.curposx = 90; } #endif - g_Menus[g_MpPlayerNum].unk840.unk544 /= 2.5f; + g_Menus[g_MpPlayerNum].menumodel.newscale /= 2.5f; } break; case MENUOP_CLOSE: break; case MENUOP_TICK: if (g_Menus[g_MpPlayerNum].curdialog && g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef) { - s32 weaponnum = dtGetWeaponByDeviceIndex(dtGetIndexBySlot(g_DtSlot)); - - if (weaponnum == WEAPON_DISGUISE41) { - g_Menus[g_MpPlayerNum].unk840.unk05c = ANIM_006A; - g_Menus[g_MpPlayerNum].unk840.unk578 = TICKS(60); - g_Menus[g_MpPlayerNum].unk840.unk574 = TICKS(120); + if (dtGetWeaponByDeviceIndex(dtGetIndexBySlot(g_DtSlot)) == WEAPON_DISGUISE41) { + g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_006A; + g_Menus[g_MpPlayerNum].menumodel.rottimer60 = TICKS(60); + g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120); } - g_Menus[g_MpPlayerNum].unk840.unk54c = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk524 = 18.849555969238f * g_20SecIntervalFrac; - g_Menus[g_MpPlayerNum].unk840.unk550 = 0; - g_Menus[g_MpPlayerNum].unk840.unk528 = 0; + g_Menus[g_MpPlayerNum].menumodel.curroty = g_Menus[g_MpPlayerNum].menumodel.newroty = 18.849555969238f * g_20SecIntervalFrac; + g_Menus[g_MpPlayerNum].menumodel.currotz = g_Menus[g_MpPlayerNum].menumodel.newrotz = 0; } break; } @@ -2651,15 +2644,11 @@ MenuDialogHandlerResult ciHangarHolographMenuDialog(s32 operation, struct menudi switch (operation) { case MENUOP_OPEN: - g_Menus[g_MpPlayerNum].unk840.unk548 = 0; - g_Menus[g_MpPlayerNum].unk840.unk520 = 0; - g_Menus[g_MpPlayerNum].unk840.unk54c = 0; - g_Menus[g_MpPlayerNum].unk840.unk524 = 0; - g_Menus[g_MpPlayerNum].unk840.unk538 = 0; - g_Menus[g_MpPlayerNum].unk840.unk510 = 0; - g_Menus[g_MpPlayerNum].unk840.unk53c = 0; - g_Menus[g_MpPlayerNum].unk840.unk514 = 0; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0; + g_Menus[g_MpPlayerNum].menumodel.currotx = g_Menus[g_MpPlayerNum].menumodel.newrotx = 0; + g_Menus[g_MpPlayerNum].menumodel.curroty = g_Menus[g_MpPlayerNum].menumodel.newroty = 0; + g_Menus[g_MpPlayerNum].menumodel.curposx = g_Menus[g_MpPlayerNum].menumodel.newposx = 0; + g_Menus[g_MpPlayerNum].menumodel.curposy = g_Menus[g_MpPlayerNum].menumodel.newposy = 0; + g_Menus[g_MpPlayerNum].menumodel.curscale = 0; break; case MENUOP_CLOSE: break; @@ -2675,29 +2664,24 @@ MenuDialogHandlerResult ciHangarHolographMenuDialog(s32 operation, struct menudi offset = items[index].y_offset; size = items[index].size * 0.001f; - g_Menus[g_MpPlayerNum].unk840.unk544 = size; - g_Menus[g_MpPlayerNum].unk840.unk514 = offset; - g_Menus[g_MpPlayerNum].unk840.unk53c = offset; + g_Menus[g_MpPlayerNum].menumodel.newscale = size; + g_Menus[g_MpPlayerNum].menumodel.curposy = offset; + g_Menus[g_MpPlayerNum].menumodel.newposy = offset; - if (g_Menus[g_MpPlayerNum].unk840.unk00c != items[index].fileid) { - g_Menus[g_MpPlayerNum].unk840.unk000 = 8; + if (g_Menus[g_MpPlayerNum].menumodel.newparams != items[index].fileid) { + g_Menus[g_MpPlayerNum].menumodel.loaddelay = 8; } - g_Menus[g_MpPlayerNum].unk840.unk00c = items[index].fileid; - g_Menus[g_MpPlayerNum].unk840.unk54c = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60freal; - g_Menus[g_MpPlayerNum].unk840.unk524 += 0.01f * g_Vars.diffframe60freal; - g_Menus[g_MpPlayerNum].unk840.partvisibility = g_BioPartVisibility; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(items[index].fileid); + g_Menus[g_MpPlayerNum].menumodel.newroty = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60freal; + g_Menus[g_MpPlayerNum].menumodel.curroty += 0.01f * g_Vars.diffframe60freal; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = g_BioPartVisibility; } else { - g_Menus[g_MpPlayerNum].unk840.unk548 = 0; - g_Menus[g_MpPlayerNum].unk840.unk520 = 0; - g_Menus[g_MpPlayerNum].unk840.unk54c = 0; - g_Menus[g_MpPlayerNum].unk840.unk524 = 0; - g_Menus[g_MpPlayerNum].unk840.unk538 = 0; - g_Menus[g_MpPlayerNum].unk840.unk510 = 0; - g_Menus[g_MpPlayerNum].unk840.unk53c = 0; - g_Menus[g_MpPlayerNum].unk840.unk514 = 0; - g_Menus[g_MpPlayerNum].unk840.unk544 = 0; - g_Menus[g_MpPlayerNum].unk840.unk51c = 0; + g_Menus[g_MpPlayerNum].menumodel.currotx = g_Menus[g_MpPlayerNum].menumodel.newrotx = 0; + g_Menus[g_MpPlayerNum].menumodel.curroty = g_Menus[g_MpPlayerNum].menumodel.newroty = 0; + g_Menus[g_MpPlayerNum].menumodel.curposx = g_Menus[g_MpPlayerNum].menumodel.newposx = 0; + g_Menus[g_MpPlayerNum].menumodel.curposy = g_Menus[g_MpPlayerNum].menumodel.newposy = 0; + g_Menus[g_MpPlayerNum].menumodel.curscale = g_Menus[g_MpPlayerNum].menumodel.newscale = 0; } #else if (g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef) { @@ -2709,18 +2693,18 @@ MenuDialogHandlerResult ciHangarHolographMenuDialog(s32 operation, struct menudi offset = items[index].y_offset; size = items[index].size * 0.001f; - g_Menus[g_MpPlayerNum].unk840.unk544 = size; - g_Menus[g_MpPlayerNum].unk840.unk514 = offset; - g_Menus[g_MpPlayerNum].unk840.unk53c = offset; - g_Menus[g_MpPlayerNum].unk840.unk00c = items[index].fileid; + g_Menus[g_MpPlayerNum].menumodel.newscale = size; + g_Menus[g_MpPlayerNum].menumodel.curposy = offset; + g_Menus[g_MpPlayerNum].menumodel.newposy = offset; + g_Menus[g_MpPlayerNum].menumodel.newparams = MENUMODELPARAMS_SET_FILENUM(items[index].fileid); #if VERSION >= VERSION_PAL_BETA - g_Menus[g_MpPlayerNum].unk840.unk54c = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60freal; - g_Menus[g_MpPlayerNum].unk840.unk524 += 0.01f * g_Vars.diffframe60freal; + g_Menus[g_MpPlayerNum].menumodel.newroty = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60freal; + g_Menus[g_MpPlayerNum].menumodel.curroty += 0.01f * g_Vars.diffframe60freal; #else - g_Menus[g_MpPlayerNum].unk840.unk54c = g_Menus[g_MpPlayerNum].unk840.unk524 + 0.01f * g_Vars.diffframe60f; - g_Menus[g_MpPlayerNum].unk840.unk524 += 0.01f * g_Vars.diffframe60f; + g_Menus[g_MpPlayerNum].menumodel.newroty = g_Menus[g_MpPlayerNum].menumodel.curroty + 0.01f * g_Vars.diffframe60f; + g_Menus[g_MpPlayerNum].menumodel.curroty += 0.01f * g_Vars.diffframe60f; #endif - g_Menus[g_MpPlayerNum].unk840.partvisibility = g_BioPartVisibility; + g_Menus[g_MpPlayerNum].menumodel.partvisibility = g_BioPartVisibility; } #endif } diff --git a/src/include/bss.h b/src/include/bss.h index 67eb234e9..bca6b3b48 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -163,8 +163,8 @@ extern s16 g_SpawnPoints[]; extern s32 g_NumSpawnPoints; extern s32 var8009de90; extern s32 var8009de94; -extern s32 var8009de98; -extern s32 var8009de9c; +extern s32 g_MenuProjectFromX; +extern s32 g_MenuProjectFromY; extern u8 g_MpSelectedPlayersForStats[MAX_PLAYERS]; extern char g_CheatMarqueeString[]; extern u8 *g_BlurBuffer; diff --git a/src/include/constants.h b/src/include/constants.h index 3a8e7ea97..db19cbbcc 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -1683,6 +1683,25 @@ #define MENUITEMTYPE_CONTROLLER 0x19 #define MENUITEMTYPE_END 0x1a +#define MENUMODELFLAG_HASSCALE 0x01 +#define MENUMODELFLAG_HASPOSITION 0x02 +#define MENUMODELFLAG_HASROTATION 0x04 + +#define MENUMODELPARAMS_HAS_MASTER_HEADBODY(params) (((params) & 0x80000000) != 0) +#define MENUMODELPARAMS_GET_MASTER_HEADNUM(params) ((params) & 0x3ff) +#define MENUMODELPARAMS_GET_MASTER_BODYNUM(params) (((params) & 0xffc00) >> 10) +#define MENUMODELPARAMS_GET_MP_HEADNUM(params) (((params) >> 16) & 0xff) +#define MENUMODELPARAMS_GET_MP_BODYNUM(params) (((params) >> 24) & 0xff) +#define MENUMODELPARAMS_GET_FILENUM(params) ((params) & 0xffff) +#define MENUMODELPARAMS_SET_FILENUM(filenum) (filenum) +#define MENUMODELPARAMS_SET_MP_HEADBODY(mpheadnum, mpbodynum) (0xffff | ((mpheadnum) << 16) | ((mpbodynum) << 24)) + +#define MENUMODELTYPE_DEFAULT 0 +#define MENUMODELTYPE_HUDPIECE 1 +#define MENUMODELTYPE_2 2 +#define MENUMODELTYPE_3 3 +#define MENUMODELTYPE_CREDITSLOGO 4 + #define MENUOP_GETOPTIONCOUNT 1 #define MENUOP_GETOPTGROUPCOUNT 2 #define MENUOP_GETOPTIONTEXT 3 diff --git a/src/include/game/endscreen.h b/src/include/game/endscreen.h index f8b6ccfe2..c12cf2566 100644 --- a/src/include/game/endscreen.h +++ b/src/include/game/endscreen.h @@ -28,7 +28,7 @@ char *endscreenMenuTextCurrentStageName3(struct menuitem *item); char *endscreenMenuTitleStageFailed(struct menuitem *item); char *endscreenMenuTextMissionTime(struct menuitem *item); struct menudialogdef *endscreenAdvance(void); -void endscreen0f10d770(void); +void endscreenResetModels(void); void endscreenContinue(s32 context); char *endscreenMenuTextTimedCheatName(struct menuitem *item); char *endscreenMenuTextCompletionCheatName(struct menuitem *item); diff --git a/src/include/game/menu.h b/src/include/game/menu.h index c6158141b..46fd44ad6 100644 --- a/src/include/game/menu.h +++ b/src/include/game/menu.h @@ -60,9 +60,9 @@ void menuCloseDialog(void); void menuUpdateCurFrame(void); void menuPopDialog(void); void func0f0f3704(struct menudialogdef *dialogdef); -void func0f0f372c(struct menu840 *arg0, f32 x, f32 y, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32 arg7, u8 flags); -void func0f0f37a4(struct menu840 *arg0); -Gfx *menuRenderModels(Gfx *gdl, struct menu840 *arg1, s32 arg2); +void menuConfigureModel(struct menumodel *menumodel, f32 x, f32 y, f32 z, f32 rotx, f32 roty, f32 rotz, f32 scale, u8 flags); +void menuUnsetModel(struct menumodel *menumodel); +Gfx *menuRenderModel(Gfx *gdl, struct menumodel *menumodel, s32 modeltype); void menuGetTeamTitlebarColours(u32 *top, u32 *middle, u32 *bottom); Gfx *menuApplyScissor(Gfx *gdl); Gfx *dialogRender(Gfx *gdl, struct menudialog *dialog, struct menu *menu, bool lightweight); @@ -85,7 +85,7 @@ void menuPushRootDialog(struct menudialogdef *dialogdef, s32 arg1); void func0f0f85e0(struct menudialogdef *dialogdef, s32 root); Gfx *menuRenderDialog(Gfx *gdl, struct menudialog *dialog, struct menu *menu, bool lightweight); Gfx *menuRenderDialogs(Gfx *gdl); -void func0f0f8bb4(struct menu840 *arg0, u32 arg1, u32 arg2); +void menuResetModel(struct menumodel *menumodel, u32 allocationlen, bool allocate); void menuReset(void); void menuSwipe(s32 direction); void dialogTick(struct menudialog *dialog, struct menuinputs *inputs, u32 tickflags); diff --git a/src/include/game/mplayer/setup.h b/src/include/game/mplayer/setup.h index 00d42360b..ebb915747 100644 --- a/src/include/game/mplayer/setup.h +++ b/src/include/game/mplayer/setup.h @@ -9,7 +9,7 @@ s16 mpChooseRandomStage(void); MenuItemHandlerResult mpArenaMenuHandler(s32 operation, struct menuitem *item, union handlerdata *data); char *mpMenuTextWeaponNameForSlot(struct menuitem *item); char *mpMenuTextSetupName(struct menuitem *item); -MenuItemHandlerResult mpCharacterBodyMenuHandler(s32 operation, struct menuitem *item, union handlerdata *data, s32 mpheadnum, s32 mpbodynum, bool isplayer); +MenuItemHandlerResult mpCharacterBodyMenuHandler(s32 operation, struct menuitem *item, union handlerdata *data, s32 mpbodynum, s32 mpheadnum, bool isplayer); MenuDialogHandlerResult menudialog0017a174(s32 operation, struct menudialogdef *dialogdef, union handlerdata *data); MenuItemHandlerResult mpChallengesListHandler(s32 operation, struct menuitem *item, union handlerdata *data); char *mpMenuTextKills(struct menuitem *item); diff --git a/src/include/types.h b/src/include/types.h index 74acdd7bf..58d52fb33 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -3815,71 +3815,70 @@ struct perfectheadtexturelist { struct textureconfig selectedtexture; }; -struct menu840 { - /*0x000*/ u8 unk000; - /*0x001*/ u8 unk001; +struct menumodel { + /*0x000*/ u8 loaddelay; /*0x002*/ s16 headnum; - /*0x004*/ u8 *unk004; - /*0x008*/ u32 unk008; - /*0x00c*/ u32 unk00c; - /*0x010*/ s32 unk010; - /*0x014*/ Mtxf unk014; + /*0x004*/ u8 *allocstart; + /*0x008*/ u32 alloclen; + /*0x00c*/ u32 newparams; + /*0x010*/ u32 curparams; + /*0x014*/ Mtxf mtx; /*0x054*/ struct modeldef *bodymodeldef; /*0x058*/ struct modeldef *headmodeldef; - /*0x05c*/ s16 unk05c; - /*0x05e*/ s16 unk05e; + /*0x05c*/ s16 newanimnum; + /*0x05e*/ s16 curanimnum; /*0x060*/ struct model bodymodel; /*0x084*/ struct anim bodyanim; - /*0x110*/ u32 unk110[256]; - /*0x510*/ f32 unk510; - /*0x514*/ f32 unk514; - /*0x518*/ f32 unk518; - /*0x51c*/ f32 unk51c; - /*0x520*/ f32 unk520; - /*0x524*/ f32 unk524; - /*0x528*/ f32 unk528; - /*0x52c*/ f32 unk52c; - /*0x530*/ f32 unk530; - /*0x534*/ f32 unk534; - /*0x538*/ f32 unk538; - /*0x53c*/ f32 unk53c; - /*0x540*/ f32 unk540; - /*0x544*/ f32 unk544; - /*0x548*/ f32 unk548; - /*0x54c*/ f32 unk54c; - /*0x550*/ f32 unk550; - /*0x554*/ f32 unk554; - /*0x558*/ f32 unk558; - /*0x55c*/ f32 unk55c; - /*0x560*/ s16 unk560; - /*0x564*/ f32 unk564; - /*0x568*/ u8 unk568; + /*0x110*/ u32 rwdata[256]; + /*0x510*/ f32 curposx; + /*0x514*/ f32 curposy; + /*0x518*/ f32 curposz; + /*0x51c*/ f32 curscale; + /*0x520*/ f32 currotx; + /*0x524*/ f32 curroty; + /*0x528*/ f32 currotz; + /*0x52c*/ f32 displacex; + /*0x530*/ f32 displacey; + /*0x534*/ f32 displacez; + /*0x538*/ f32 newposx; + /*0x53c*/ f32 newposy; + /*0x540*/ f32 newposz; + /*0x544*/ f32 newscale; + /*0x548*/ f32 newrotx; + /*0x54c*/ f32 newroty; + /*0x550*/ f32 newrotz; + /*0x554*/ f32 zoom; // character selection: far = 100, near = 370 + /*0x558*/ f32 unk558; // unused + /*0x55c*/ f32 unk55c; // unused + /*0x560*/ s16 unk560; // unused + /*0x564*/ f32 configurefrac; + /*0x568*/ u8 flags; /*0x56a*/ s16 bodynum; - /*0x56c*/ u32 unk56c; - /*0x570*/ u32 unk570; - /*0x574*/ s32 unk574; - /*0x578*/ s32 unk578; - /*0x57c*/ u32 unk57c; - /*0x580*/ u32 unk580; - /*0x584*/ u32 unk584; - /*0x588*/ u32 unk588; - /*0x58c*/ u32 unk58c; - /*0x590*/ u32 unk590; - /*0x594*/ u32 unk594; - /*0x598*/ u32 unk598; - /*0x59c*/ u32 unk59c; - /*0x5a0*/ u32 unk5a0; - /*0x5a4*/ u32 unk5a4; - /*0x5a8*/ u32 unk5a8; - /*0x5ac*/ u32 unk5ac; - /*0x5b0*/ u8 unk5b0; - /*0x5b1*/ u8 unk5b1_01 : 1; - /*0x5b1*/ u8 unk5b1_02 : 1; - /*0x5b1*/ u8 unk5b1_03 : 1; - /*0x5b1*/ u8 unk5b1_04 : 1; - /*0x5b1*/ u8 unk5b1_05 : 1; - /*0x5b1*/ u8 unk5b1_06 : 1; - /*0x5b1*/ u8 unk5b1_07 : 1; + /*0x56c*/ s32 unk56c; // unused + /*0x570*/ s32 unk570; // unused + /*0x574*/ s32 zoomtimer60; + /*0x578*/ s32 rottimer60; + /*0x57c*/ s32 unk57c; // unused + /*0x580*/ bool removingpiece; + /*0x584*/ s32 unk584; // unused + /*0x588*/ s32 unk588; // unused + /*0x58c*/ s32 unk58c; // unused + /*0x590*/ s32 unk590; // unused + /*0x594*/ s32 unk594; // unused + /*0x598*/ s32 unk598; // unused + /*0x59c*/ s32 unk59c; // unused + /*0x5a0*/ s32 unk5a0; // unused + /*0x5a4*/ s32 unk5a4; // unused + /*0x5a8*/ s32 unk5a8; // unused + /*0x5ac*/ s32 unk5ac; // unused + /*0x5b0*/ u8 perfectheadnum; + /*0x5b1*/ u8 isperfecthead : 1; + /*0x5b1*/ u8 unk5b1_02 : 1; // unused + /*0x5b1*/ u8 unk5b1_03 : 1; // unused + /*0x5b1*/ u8 reverseanim : 1; + /*0x5b1*/ u8 configuring : 1; + /*0x5b1*/ u8 unk5b1_06 : 1; // unused + /*0x5b1*/ u8 drawbehinddialog : 1; /*0x5b4*/ struct modelpartvisibility *partvisibility; }; @@ -3924,7 +3923,7 @@ struct menu { /*0x83d*/ u8 unk83d; /*0x83e*/ u8 unk83e; /*0x83f*/ u8 unk83f; - /*0x840*/ struct menu840 unk840; + /*0x840*/ struct menumodel menumodel; /*0xdf8*/ s8 bannernum; /*0xdfc*/ struct menudfc unkdfc[4]; @@ -4738,11 +4737,11 @@ struct menudata { /*0x016*/ u8 screenshottimer; /*0x017*/ u8 playerjoinalpha[MAX_PLAYERS]; /*0x01b*/ s8 bannernum; - /*0x01c*/ struct menu840 unk01c; + /*0x01c*/ struct menumodel hudpiece; /*0x5d4*/ u8 unk5d4; /*0x5d5*/ u8 unk5d5_01 : 1; /*0x5d5*/ u8 unk5d5_02 : 1; - /*0x5d5*/ u8 unk5d5_03 : 1; + /*0x5d5*/ u8 usezbuf : 1; /*0x5d5*/ u8 unk5d5_04 : 1; /*0x5d5*/ u8 unk5d5_05 : 1; /*0x5d5*/ u8 unk5d5_06 : 1; From 79a94b29ce51e5069936af5be8cf1dd25d9ed4db Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 Aug 2023 12:20:04 +1000 Subject: [PATCH 2/6] Name some texture symbols, mostly relating to LODs --- src/game/tex.c | 72 ++++++------- src/game/texdecompress.c | 177 ++++++++++++++++--------------- src/game/texreset.c | 22 ++-- src/game/texselect.c | 4 +- src/include/bss.h | 6 +- src/include/game/texdecompress.h | 8 +- src/include/types.h | 5 +- 7 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/game/tex.c b/src/game/tex.c index 9b3a30403..335d4cc03 100644 --- a/src/game/tex.c +++ b/src/game/tex.c @@ -268,7 +268,7 @@ s32 texGetWidthAtLod(struct tex *tex, s32 lod) return width; } - if (tex->unk0c_02) { + if (tex->hasloddata) { for (i = 0; i < g_TexCacheCount; i++) { if (tex->texturenum == g_TexCacheItems[i].texturenum) { return g_TexCacheItems[i].widths[lod - 1]; @@ -294,7 +294,7 @@ s32 texGetHeightAtLod(struct tex *tex, s32 lod) return height; } - if (tex->unk0c_02) { + if (tex->hasloddata) { for (i = 0; i < g_TexCacheCount; i++) { if (tex->texturenum == g_TexCacheItems[i].texturenum) { return g_TexCacheItems[i].heights[lod - 1]; @@ -339,7 +339,7 @@ s32 texGetSizeInBytes(struct tex *tex, s32 lod) void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg) { s32 depth = tex->depth; - s32 maxlod = tex->maxlod ? tex->maxlod : 1; + s32 numlods = tex->numlods ? tex->numlods : 1; s32 lod; *lenarg = 0; @@ -354,7 +354,7 @@ void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg) *deptharg = G_IM_SIZ_16b; } - for (lod = 0; lod < maxlod; lod++) { + for (lod = 0; lod < numlods; lod++) { *lenarg += texGetSizeInBytes(tex, lod) * 4; } } @@ -415,10 +415,10 @@ Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s3 tex0f173f48(0), sp88 - s0->unk04_08, shifts); } - uls = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + 0; - ult = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + 0; - lrs = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + ((tex->width - 1) << 2); - lrt = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + ((tex->height - 1) << 2); + uls = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0; + ult = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0; + lrs = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->width - 1) << 2); + lrt = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->height - 1) << 2); if (tex0f173b8c(0, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, 0, uls, ult, lrs, lrt); @@ -429,7 +429,7 @@ Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s3 Gfx *tex0f1742e4(Gfx *arg0, Gfx *arg1, struct tex *tex, bool arg3) { - s32 lod = tex->maxlod ? tex->maxlod - 1 : 0; + s32 lod = tex->numlods ? tex->numlods - 1 : 0; if (arg3) { if (arg1 != NULL) { @@ -518,17 +518,17 @@ Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2) Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, u32 arg7) { u32 tmem; - s32 maxlod; + s32 numlods; s32 tile; tmem = arg7; - maxlod = tex->maxlod; + numlods = tex->numlods; - if (arg6 >= 0 && arg6 < maxlod) { - maxlod = arg6; + if (arg6 >= 0 && arg6 < numlods) { + numlods = arg6; } - for (tile = arg5; tile < maxlod + arg5 && tile < 6; tile++) { + for (tile = arg5; tile < numlods + arg5 && tile < 6; tile++) { s32 stack[2]; s32 lod = tile - arg5; u32 masks = tex0f173f18(texGetWidthAtLod(tex, lod)); @@ -539,7 +539,7 @@ Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar s32 lrs; s32 lrt; s32 bytes = texGetSizeInBytes(tex, lod); - s32 sp7c = tex->unk0c_02; + bool hasloddata = tex->hasloddata; if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); @@ -551,10 +551,10 @@ Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar tex0f173f48(arg2), masks, tile - arg5); } - uls = (arg4 == 2 && sp7c == 0 ? 2 : 0) + 0; - ult = (arg4 == 2 && sp7c == 0 ? 2 : 0) + 0; - lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && sp7c == 0 ? 2 : 0); - lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && sp7c == 0 ? 2 : 0); + uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; + ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; + lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0); + lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0); if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); @@ -635,12 +635,12 @@ Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ti s32 ult; s32 lrs; s32 lrt; - s32 sp50; + bool hasloddata; masks = tex0f173f18(tex->width); maskt = tex0f173f18(tex->height); line = texGetLineSizeInBytes(tex, 0); - sp50 = tex->unk0c_02; + hasloddata = tex->hasloddata; if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); @@ -652,10 +652,10 @@ Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ti tex0f173f48(arg2), masks, G_TX_NOLOD); } - uls = (arg4 == 2 && sp50 == 0 ? 2 : 0) + 0; - ult = (arg4 == 2 && sp50 == 0 ? 2 : 0) + 0; - lrs = (arg4 == 2 && sp50 == 0 ? 2 : 0) + ((tex->width - 1) << 2); - lrt = (arg4 == 2 && sp50 == 0 ? 2 : 0) + ((tex->height - 1) << 2); + uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; + ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; + lrs = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->width - 1) << 2); + lrt = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->height - 1) << 2); if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); @@ -677,9 +677,9 @@ Gfx *tex0f1751e4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); - sp34 += tex->maxlod; + sp34 += tex->numlods; - if (!arg5 && tex->maxlod == 1) { + if (!arg5 && tex->numlods == 1) { gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); } @@ -711,9 +711,9 @@ Gfx *tex0f175308(Gfx *gdl, struct tex *tex1, s32 arg2, s32 arg3, s32 arg4, struc gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); - sp38 += tex1->maxlod; + sp38 += tex1->numlods; - if (!arg9 && tex1->maxlod == 1) { + if (!arg9 && tex1->numlods == 1) { gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); } @@ -740,9 +740,9 @@ Gfx *tex0f175490(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); - sp34 += tex->maxlod; + sp34 += tex->numlods; - if (!arg8 && tex->maxlod == 1) { + if (!arg8 && tex->numlods == 1) { gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); } @@ -1111,13 +1111,13 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo return (uintptr_t) s6 - (uintptr_t) arg2; } -void texCopyGdls(Gfx *src, Gfx *dst, s32 arg2) +void texCopyGdls(Gfx *src, Gfx *dst, s32 count) { - arg2 = (arg2 >> 3); - src = src + (arg2 - 1); - dst = dst + (arg2 - 1); + count = (count >> 3); + src = src + (count - 1); + dst = dst + (count - 1); - while (arg2--) { + while (count--) { dst->force_structure_alignment = src->force_structure_alignment; dst--; src--; diff --git a/src/game/texdecompress.c b/src/game/texdecompress.c index 734363920..0162a4b76 100644 --- a/src/game/texdecompress.c +++ b/src/game/texdecompress.c @@ -17,9 +17,9 @@ struct texpool g_TexSharedPool; struct texcacheitem g_TexCacheItems[150]; s32 g_TexCacheCount; s32 g_TexNumToLoad; -u8 *var800ab540; -u32 var800ab544; -s32 var800ab548; +u8 *g_TexBitstring; +u32 g_TexAccumValue; +s32 g_TexAccumNumBits; u32 var800ab54c; u32 g_TexBase; u8 *g_TextureConfigSegment; @@ -141,7 +141,7 @@ void func0f16e810(u32 arg0) * * The zlib data is prefixed with the standard 5-byte rarezip header. */ -s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5) +s32 texInflateZlib(u8 *src, u8 *dst, bool hasloddata, s32 numlods, struct texpool *pool, bool unusedarg) { s32 i; s32 imagebytesout; @@ -153,9 +153,9 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo s32 width; s32 height; s32 numcolours; - u8 *end; - u8 *start; - s32 j; + u8 *loddst; + u8 *lodsrc; + s32 lod; u8 scratch2[0x800]; u16 palette[256]; u8 scratch[5120]; @@ -165,16 +165,16 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo texSetBitstring(src); - if (arg2 && forcenumimages) { - numimages = forcenumimages; + if (hasloddata && numlods) { + numimages = numlods; } else { numimages = 1; } - pool->rightpos->maxlod = forcenumimages; - pool->rightpos->unk0c_02 = arg2; + pool->rightpos->numlods = numlods; + pool->rightpos->hasloddata = hasloddata; - if (arg2) { + if (hasloddata) { writetocache = true; for (i = 0; i < g_TexCacheCount; i++) { @@ -193,11 +193,11 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo foundthething = false; - for (j = 0; j < numimages; j++) { + for (lod = 0; lod < numimages; lod++) { width = texReadBits(8); height = texReadBits(8); - if (j == 0) { + if (lod == 0) { pool->rightpos->width = width; pool->rightpos->height = height; pool->rightpos->unk0a = numcolours - 1; @@ -205,19 +205,19 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo pool->rightpos->depth = g_TexFormatDepths[format]; pool->rightpos->lutmodeindex = g_TexFormatLutModes[format] >> G_MDSFT_TEXTLUT; } else if (writetocache) { - g_TexCacheItems[g_TexCacheCount].widths[j - 1] = width; - g_TexCacheItems[g_TexCacheCount].heights[j - 1] = height; + g_TexCacheItems[g_TexCacheCount].widths[lod - 1] = width; + g_TexCacheItems[g_TexCacheCount].heights[lod - 1] = height; } - if (rzipInflate(var800ab540, scratch2, scratch) == 0) { + if (rzipInflate(g_TexBitstring, scratch2, scratch) == 0) { #if VERSION < VERSION_NTSC_1_0 char message[128]; sprintf(message, "DMA-Crash %s %d Ram: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", "texdecompress.c", 357, - var800ab540[0], var800ab540[1], var800ab540[2], var800ab540[3], - var800ab540[4], var800ab540[5], var800ab540[6], var800ab540[7], - var800ab540[8], var800ab540[9], var800ab540[10], var800ab540[11], - var800ab540[12], var800ab540[13], var800ab540[14], var800ab540[15]); + g_TexBitstring[0], g_TexBitstring[1], g_TexBitstring[2], g_TexBitstring[3], + g_TexBitstring[4], g_TexBitstring[5], g_TexBitstring[6], g_TexBitstring[7], + g_TexBitstring[8], g_TexBitstring[9], g_TexBitstring[10], g_TexBitstring[11], + g_TexBitstring[12], g_TexBitstring[13], g_TexBitstring[14], g_TexBitstring[15]); crashSetMessage(message); CRASH(); #endif @@ -226,19 +226,19 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo imagebytesout = texAlignIndices(scratch2, width, height, format, &dst[totalbytesout]); texSetBitstring(rzipGetSomething()); - if (arg2 == 1) { - if (IS4MB() && j == 2 && !foundthething) { - pool->rightpos->maxlod = j; + if (hasloddata == true) { + if (IS4MB() && lod == 2 && !foundthething) { + pool->rightpos->numlods = lod; foundthething = true; } if (totalbytesout + imagebytesout > 0x800 || foundthething) { if (!foundthething) { - pool->rightpos->maxlod = j; + pool->rightpos->numlods = lod; foundthething = true; } } else { - texSwapAltRowBytes(&dst[totalbytesout], width, height, format); + texSwizzle(&dst[totalbytesout], width, height, format); totalbytesout += imagebytesout; } } else { @@ -256,41 +256,43 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo } } - if (!arg2) { - if (forcenumimages >= 2) { + // If the texture data doesn't contain multiple LODs but the header has a numlods value, + // generate the other LODs by shrinking the image. + if (!hasloddata) { + if (numlods >= 2) { s32 tmpwidth = width; s32 tmpheight = height; - start = dst; - end = &dst[totalbytesout]; + lodsrc = dst; + loddst = &dst[totalbytesout]; - for (j = 1; j < forcenumimages; j++) { - imagebytesout = texShrinkPaletted(start, end, tmpwidth, tmpheight, format, palette, numcolours); + for (lod = 1; lod < numlods; lod++) { + imagebytesout = texShrinkPaletted(lodsrc, loddst, tmpwidth, tmpheight, format, palette, numcolours); - if (IS4MB() && j == 2) { - pool->rightpos->maxlod = j; + if (IS4MB() && lod == 2) { + pool->rightpos->numlods = lod; break; } if (totalbytesout + imagebytesout > 0x800) { - pool->rightpos->maxlod = j; + pool->rightpos->numlods = lod; break; } - texSwapAltRowBytes(start, tmpwidth, tmpheight, format); + texSwizzle(lodsrc, tmpwidth, tmpheight, format); totalbytesout += imagebytesout; tmpwidth = (tmpwidth + 1) >> 1; tmpheight = (tmpheight + 1) >> 1; - start = end; - end += imagebytesout; + lodsrc = loddst; + loddst += imagebytesout; } - texSwapAltRowBytes(start, tmpwidth, tmpheight, format); + texSwizzle(lodsrc, tmpwidth, tmpheight, format); } else { - texSwapAltRowBytes(dst, width, height, format); + texSwizzle(dst, width, height, format); } } @@ -678,7 +680,7 @@ s32 texFindClosestColourIndexIA(u16 *palette, s32 numcolours, s32 intensity, s32 * h = height in pixels * c = compression method (see TEXCOMPMETHOD constants) */ -s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5) +s32 texInflateNonZlib(u8 *src, u8 *dst, bool hasloddata, s32 numlods, struct texpool *pool, bool unusedarg) { u8 scratch[0x2000]; u8 lookup[0x1000]; @@ -693,18 +695,18 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex s32 imagebytesout; s32 format; s32 value; - u8 *start; - u8 *end; + u8 *lodsrc; + u8 *loddst; bool writetocache = false; texSetBitstring(src); - numimages = arg2 && forcenumimages ? forcenumimages : 1; + numimages = hasloddata && numlods ? numlods : 1; - pool->rightpos->maxlod = forcenumimages; - pool->rightpos->unk0c_02 = arg2; + pool->rightpos->numlods = numlods; + pool->rightpos->hasloddata = hasloddata; - if (arg2) { + if (hasloddata) { writetocache = true; for (i = 0; i < g_TexCacheCount; i++) { @@ -807,17 +809,17 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex break; } - if (arg2 == 1) { - texSwapAltRowBytes(&dst[totalbytesout], width, height, format); + if (hasloddata == true) { + texSwizzle(&dst[totalbytesout], width, height, format); } imagebytesout = (imagebytesout + 7) & ~7; totalbytesout += imagebytesout; - if (var800ab548 == 0) { - var800ab540++; + if (g_TexAccumNumBits == 0) { + g_TexBitstring++; } else { - var800ab548 = 0; + g_TexAccumNumBits = 0; } } @@ -838,32 +840,34 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex } } - if (!arg2) { - if (forcenumimages >= 2) { + // If the texture data doesn't contain multiple LODs but the header has a numlods value, + // generate the other LODs by shrinking the image. + if (!hasloddata) { + if (numlods >= 2) { s32 tmpwidth = width; s32 tmpheight = height; - start = dst; + lodsrc = dst; if (1); - end = &dst[totalbytesout]; + loddst = &dst[totalbytesout]; - for (i = 1; i < forcenumimages; i++) { - imagebytesout = texShrinkNonPaletted(start, end, tmpwidth, tmpheight, format); + for (i = 1; i < numlods; i++) { + imagebytesout = texShrinkNonPaletted(lodsrc, loddst, tmpwidth, tmpheight, format); - texSwapAltRowBytes(start, tmpwidth, tmpheight, format); + texSwizzle(lodsrc, tmpwidth, tmpheight, format); totalbytesout += imagebytesout; tmpwidth = (tmpwidth + 1) >> 1; tmpheight = (tmpheight + 1) >> 1; - start = end; - end += imagebytesout; + lodsrc = loddst; + loddst += imagebytesout; } - texSwapAltRowBytes(start, tmpwidth, tmpheight, format); + texSwizzle(lodsrc, tmpwidth, tmpheight, format); } else { - texSwapAltRowBytes(dst, width, height, format); + texSwizzle(dst, width, height, format); } } @@ -1902,48 +1906,45 @@ s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *look } /** - * For every second row, swap the bytes within that row. - * - * For textures with 32-bit colour values (in GBI format), swap every pair - * within each word. For all other textures, swap every byte within each pair. + * For every second row, swap every pair of words within that row. */ -void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format) +void texSwizzle(u8 *dst, s32 width, s32 height, s32 format) { s32 x; s32 y; - s32 alignedwidth; + s32 wordsperrow; u32 *row = (u32 *)dst; s32 tmp; switch (format) { case TEXFORMAT_RGBA32: case TEXFORMAT_RGB24: - alignedwidth = (width + 3) & 0xffc; + wordsperrow = (width + 3) & 0xffc; break; case TEXFORMAT_RGBA16: case TEXFORMAT_RGB15: case TEXFORMAT_IA16: - alignedwidth = ((width + 3) & 0xffc) >> 1; + wordsperrow = ((width + 3) & 0xffc) >> 1; break; case TEXFORMAT_IA8: case TEXFORMAT_I8: case TEXFORMAT_RGBA16_CI8: case TEXFORMAT_IA16_CI8: - alignedwidth = ((width + 7) & 0xff8) >> 2; + wordsperrow = ((width + 7) & 0xff8) >> 2; break; case TEXFORMAT_IA4: case TEXFORMAT_I4: case TEXFORMAT_RGBA16_CI4: case TEXFORMAT_IA16_CI4: - alignedwidth = ((width + 0xf) & 0xff0) >> 3; + wordsperrow = ((width + 0xf) & 0xff0) >> 3; break; } - row += alignedwidth; + row += wordsperrow; if (format == TEXFORMAT_RGBA32 || format == TEXFORMAT_RGB24) { for (y = 1; y < height; y += 2) { - for (x = 0; x < alignedwidth; x += 4) { + for (x = 0; x < wordsperrow; x += 4) { tmp = row[x + 0]; row[x + 0] = row[x + 2]; row[x + 2] = tmp; @@ -1953,17 +1954,17 @@ void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format) row[x + 3] = tmp; } - row += alignedwidth * 2; + row += wordsperrow * 2; } } else { for (y = 1; y < height; y += 2) { - for (x = 0; x < alignedwidth; x += 2) { + for (x = 0; x < wordsperrow; x += 2) { tmp = row[x + 0]; row[x + 0] = row[x + 1]; row[x + 1] = tmp; } - row += alignedwidth * 2; + row += wordsperrow * 2; } } } @@ -2080,7 +2081,7 @@ void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2) texLoad((s32 *)((s32)bytes + 4), pool, arg2); } - bytes += 8; + bytes += sizeof(Gfx); } } @@ -2121,13 +2122,13 @@ extern u8 _texturesdataSegmentRomStart; * z = texture is compressed with zlib * l = number of levels of detail within the texture */ -void texLoad(s32 *updateword, struct texpool *pool, bool arg2) +void texLoad(s32 *updateword, struct texpool *pool, bool unusedarg) { u8 compbuffer[4 * 1024 + 0x40]; u8 *compptr; - s32 sp14a8; + s32 hasloddata; s32 iszlib; - s32 lod; + s32 numlods; struct tex *tex; u8 *alignedcompbuffer; u32 stack; @@ -2184,12 +2185,12 @@ void texLoad(s32 *updateword, struct texpool *pool, bool arg2) compptr = (u8 *) alignedcompbuffer + (thisoffset & 7); thisoffset = 0; - sp14a8 = (*compptr & 0x80) >> 7; + hasloddata = (*compptr & 0x80) >> 7; iszlib = (*compptr & 0x40) >> 6; - lod = *compptr & 0x3f; + numlods = *compptr & 0x3f; - if (lod > 5) { - lod = 5; + if (numlods > 5) { + numlods = 5; } compptr++; @@ -2241,9 +2242,9 @@ void texLoad(s32 *updateword, struct texpool *pool, bool arg2) // Extract the texture data to the allocation (pool->leftpos) if (iszlib) { - bytesout = texInflateZlib(compptr, pool->leftpos, sp14a8, lod, pool, arg2); + bytesout = texInflateZlib(compptr, pool->leftpos, hasloddata, numlods, pool, unusedarg); } else { - bytesout = texInflateNonZlib(compptr, pool->leftpos, sp14a8, lod, pool, arg2); + bytesout = texInflateNonZlib(compptr, pool->leftpos, hasloddata, numlods, pool, unusedarg); } // If we're using the shared pool, the data must be copied out of diff --git a/src/game/texreset.c b/src/game/texreset.c index e53631099..635075698 100644 --- a/src/game/texreset.c +++ b/src/game/texreset.c @@ -11,24 +11,24 @@ #include "textureconfig.h" #include "types.h" -void texSetBitstring(u8 *arg0) +void texSetBitstring(u8 *bitstring) { - var800ab540 = arg0; - var800ab544 = 0; - var800ab548 = 0; + g_TexBitstring = bitstring; + g_TexAccumValue = 0; + g_TexAccumNumBits = 0; } -s32 texReadBits(s32 arg0) +s32 texReadBits(s32 wantnumbits) { - while (var800ab548 < arg0) { - var800ab544 = *var800ab540 | var800ab544 << 8; - var800ab540++; - var800ab548 += 8; + while (g_TexAccumNumBits < wantnumbits) { + g_TexAccumValue = g_TexAccumValue << 8 | *g_TexBitstring; + g_TexBitstring++; + g_TexAccumNumBits += 8; } - var800ab548 -= arg0; + g_TexAccumNumBits -= wantnumbits; - return var800ab544 >> var800ab548 & ((1 << arg0) - 1); + return (g_TexAccumValue >> g_TexAccumNumBits) & ((1 << wantnumbits) - 1); } extern u8 *g_TextureConfigSegment; diff --git a/src/game/texselect.c b/src/game/texselect.c index 3d5197a6e..9a4983e36 100644 --- a/src/game/texselect.c +++ b/src/game/texselect.c @@ -448,7 +448,7 @@ void texSelect(Gfx **gdlptr, struct textureconfig *tconfig, u32 arg2, s32 arg3, depth = tconfig->depth; } - if (tex && tex->unk0c_02) { + if (tex && tex->hasloddata) { tex0f173e50(tex, &depth2, &lrs); } else { switch (depth) { @@ -541,7 +541,7 @@ void texSelect(Gfx **gdlptr, struct textureconfig *tconfig, u32 arg2, s32 arg3, s32 line; if (tile > 0) { - if (tex && tex->unk0c_02) { + if (tex && tex->hasloddata) { width = texGetWidthAtLod(tex, tile); height = texGetHeightAtLod(tex, tile); } else { diff --git a/src/include/bss.h b/src/include/bss.h index bca6b3b48..7f338ab67 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -253,9 +253,9 @@ extern struct texture *g_Textures; extern struct texpool g_TexSharedPool; extern struct texcacheitem g_TexCacheItems[150]; extern s32 g_TexCacheCount; -extern u8 *var800ab540; -extern u32 var800ab544; -extern s32 var800ab548; +extern u8 *g_TexBitstring; +extern u32 g_TexAccumValue; +extern s32 g_TexAccumNumBits; extern s32 g_TexNumConfigs; extern struct tex **g_TexWords; extern struct textureconfig *g_TexWallhitConfigs; diff --git a/src/include/game/texdecompress.h b/src/include/game/texdecompress.h index cbecd9a80..8dada258c 100644 --- a/src/include/game/texdecompress.h +++ b/src/include/game/texdecompress.h @@ -5,7 +5,7 @@ #include "types.h" void func0f16e810(u32 arg0); -s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5); +s32 texInflateZlib(u8 *src, u8 *dst, bool arg2, s32 forcenumimages, struct texpool *pool, s32 unusedarg); s32 texAlignIndices(u8 *arg0, s32 width, s32 height, s32 format, u8 *dst); s32 texGetAverageRed(u16 colour1, u16 colour2, u16 colour3, u16 colour4); s32 texGetAverageGreen(u16 colour1, u16 colour2, u16 colour3, u16 colour4); @@ -14,7 +14,7 @@ s32 texGetAverageAlpha(u16 colour1, u16 colour2, u16 colour3, u16 colour4); s32 texShrinkPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format, u16 *palette, s32 numcolours); s32 texFindClosestColourIndexRGBA(u8 *palette, s32 numcolours, s32 r, s32 g, s32 b, s32 a); s32 texFindClosestColourIndexIA(u16 *palette, s32 numcolours, s32 intensity, s32 alpha); -s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5); +s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 unusedarg); s32 texShrinkNonPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format); void texInflateHuffman(u8 *dst, s32 numiterations, s32 chansize); void texInflateRle(u8 *arg0, s32 arg1); @@ -25,14 +25,14 @@ s32 texReadUncompressed(u8 *dst, s32 width, s32 height, s32 format); s32 texChannelsToPixels(u8 *src, s32 width, s32 height, u8 *dst, s32 format); s32 texInflateLookup(s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format); s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format); -void texSwapAltRowBytes(u8 *arg0, s32 width, s32 height, s32 format); +void texSwizzle(u8 *arg0, s32 width, s32 height, s32 format); void texBlur(u8 *pixels, s32 width, s32 height, s32 method, s32 chansize); void texInitPool(struct texpool *pool, u8 *start, s32 len); struct tex *texFindInPool(s32 texturenum, struct texpool *pool); s32 texGetPoolFreeBytes(struct texpool *pool); u8 *texGetPoolLeftPos(struct texpool *pool); void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2); -void texLoad(s32 *updateword, struct texpool *pool, bool arg2); +void texLoad(s32 *updateword, struct texpool *pool, bool unusedarg); void texLoadFromConfigs(struct textureconfig *configs, s32 numconfigs, struct texpool *pool, s32 arg3); void texLoadFromTextureNum(u32 arg0, struct texpool *pool); diff --git a/src/include/types.h b/src/include/types.h index 58d52fb33..fb3ee9ba0 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5952,16 +5952,15 @@ struct awardmetrics { struct tex { /*0x00*/ u16 texturenum : 12; - /*0x00*/ u16 unk00_0c : 4; /*0x04*/ u8 *data; /*0x08*/ u8 width; /*0x09*/ u8 height; /*0x0a*/ u8 unk0a; - /*0x0b*/ u8 maxlod : 3; + /*0x0b*/ u8 numlods : 3; /*0x0b*/ u8 gbiformat : 3; /*0x0b*/ u8 depth : 2; /*0x0c*/ u32 lutmodeindex : 2; - /*0x0c*/ u32 unk0c_02 : 1; + /*0x0c*/ u32 hasloddata : 1; /*0x0c*/ u32 unk0c_03 : 1; /*0x0c*/ u32 next : 24; }; From 0b1aabf345c855c04662375b5bb2dd4bf17953d9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 Aug 2023 22:28:40 +1000 Subject: [PATCH 3/6] Set names for a heap of shotdata symbols --- src/game/bg.c | 50 +++--- src/game/bondgun.c | 99 ++++++----- src/game/botact.c | 2 +- src/game/camera.c | 19 +-- src/game/chr.c | 68 ++++---- src/game/lv.c | 2 +- src/game/prop.c | 327 ++++++++++++++++++++----------------- src/game/propobj.c | 182 ++++++++++----------- src/game/splat.c | 100 ++++++------ src/include/constants.h | 3 + src/include/game/camera.h | 2 +- src/include/game/chr.h | 4 +- src/include/game/prop.h | 8 +- src/include/game/propobj.h | 4 +- src/include/types.h | 20 +-- 15 files changed, 454 insertions(+), 436 deletions(-) diff --git a/src/game/bg.c b/src/game/bg.c index be420950c..9822d9b5f 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -3790,9 +3790,9 @@ bool bgTestHitOnObj(struct coord *arg0, struct coord *arg1, struct coord *arg2, lowestsqdist = sqdist; - hitthing->unk00.x = sp8c.x; - hitthing->unk00.y = sp8c.y; - hitthing->unk00.z = sp8c.z; + hitthing->pos.x = sp8c.x; + hitthing->pos.y = sp8c.y; + hitthing->pos.z = sp8c.z; hitthing->unk0c.x = sp80.x; hitthing->unk0c.y = sp80.y; hitthing->unk0c.z = sp80.z; @@ -4068,9 +4068,9 @@ bool bgTestHitOnChr(struct model *model, struct coord *arg1, struct coord *arg2, *sqdistptr = sqdist; - hitthing->unk00.x = sp84.x; - hitthing->unk00.y = sp84.y; - hitthing->unk00.z = sp84.z; + hitthing->pos.x = sp84.x; + hitthing->pos.y = sp84.y; + hitthing->pos.z = sp84.z; hitthing->unk0c.x = sp78.x; hitthing->unk0c.y = sp78.y; hitthing->unk0c.z = sp78.z; @@ -4292,9 +4292,9 @@ bool bgTestHitInVtxBatch(struct coord *arg0, struct coord *arg1, struct coord *a if (hit) { lowestsqdist = sqdist; - hitthing->unk00.x = spb0.x; - hitthing->unk00.y = spb0.y; - hitthing->unk00.z = spb0.z; + hitthing->pos.x = spb0.x; + hitthing->pos.y = spb0.y; + hitthing->pos.z = spb0.z; hitthing->unk0c.x = spa4.x; hitthing->unk0c.y = spa4.y; hitthing->unk0c.z = spa4.z; @@ -4469,20 +4469,20 @@ bool bgTestHitInRoom(struct coord *frompos, struct coord *topos, s32 roomnum, st numbatches = g_Rooms[roomnum].numvtxbatches; for (i = 0; i < numbatches; batch++, i++) { - j = bg0f1612e4(&batch->bbmin, &batch->bbmax, &from, &dist, &sp94, &hitthing->unk00); + j = bg0f1612e4(&batch->bbmin, &batch->bbmax, &from, &dist, &sp94, &hitthing->pos); if (j == 0) { continue; } if (j == 1) { - f0 = from.x - hitthing->unk00.x; + f0 = from.x - hitthing->pos.x; f20 = f0 * f0; - f0 = from.y - hitthing->unk00.y; + f0 = from.y - hitthing->pos.y; f20 += f0 * f0; - f0 = from.z - hitthing->unk00.z; + f0 = from.z - hitthing->pos.z; f20 += f0 * f0; } else { f20 = -1.0f; @@ -4512,13 +4512,13 @@ bool bgTestHitInRoom(struct coord *frompos, struct coord *topos, s32 roomnum, st for (j = 0; j < ARRAYCOUNT(var800a6538); j++) { if (bgTestHitInVtxBatch(&from, &to, &dist, &g_Rooms[roomnum].vtxbatches[var800a6538[j].vtxbatchindex], roomnum, hitthing)) { - f0 = from.x - hitthing->unk00.x; + f0 = from.x - hitthing->pos.x; f2 = f0 * f0; - f0 = from.y - hitthing->unk00.y; + f0 = from.y - hitthing->pos.y; f2 += f0 * f0; - f0 = from.z - hitthing->unk00.z; + f0 = from.z - hitthing->pos.z; f2 += f0 * f0; if (count == 0) { @@ -4564,31 +4564,31 @@ bool bgTestHitInRoom(struct coord *frompos, struct coord *topos, s32 roomnum, st i++; if (i < count) { - f0 = from.x - hitthing->unk00.x; + f0 = from.x - hitthing->pos.x; spc8 = f0 * f0; - f0 = from.y - hitthing->unk00.y; + f0 = from.y - hitthing->pos.y; spc8 += f0 * f0; - f0 = from.z - hitthing->unk00.z; + f0 = from.z - hitthing->pos.z; spc8 += f0 * f0; for (; i < count; i++) { if (var800a6538[i].unk04 <= spc8) { if (bgTestHitInVtxBatch(&from, &to, &dist, &batch[var800a6538[i].vtxbatchindex], roomnum, &sp60)) { - f0 = from.f[0] - sp60.unk00.f[0]; + f0 = from.f[0] - sp60.pos.f[0]; f20 = f0 * f0; - f0 = from.f[1] - sp60.unk00.f[1]; + f0 = from.f[1] - sp60.pos.f[1]; f20 += f0 * f0; - f0 = from.f[2] - sp60.unk00.f[2]; + f0 = from.f[2] - sp60.pos.f[2]; f20 += f0 * f0; if (f20 < spc8) { - hitthing->unk00.x = sp60.unk00.x; - hitthing->unk00.y = sp60.unk00.y; - hitthing->unk00.z = sp60.unk00.z; + hitthing->pos.x = sp60.pos.x; + hitthing->pos.y = sp60.pos.y; + hitthing->pos.z = sp60.pos.z; hitthing->unk0c.x = sp60.unk0c.x; hitthing->unk0c.y = sp60.unk0c.y; hitthing->unk0c.z = sp60.unk0c.z; diff --git a/src/game/bondgun.c b/src/game/bondgun.c index 6a733f5f5..fe3f6bc81 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -4447,8 +4447,8 @@ void bgunCreateThrownProjectile(s32 handnum, struct gset *gset) { struct coord velocity = {0, 0, 0}; Mtxf sp1f4; - struct coord sp1e8; - struct coord sp1dc; + struct coord gunpos; + struct coord gundir; struct prop *playerprop = g_Vars.currentplayer->prop; struct coord *prevpos = &g_Vars.currentplayer->bondprevpos; struct coord *extrapos = &g_Vars.currentplayer->bondextrapos; @@ -4520,17 +4520,17 @@ void bgunCreateThrownProjectile(s32 handnum, struct gset *gset) playerSetPerimEnabled(playerprop, true); - bgunCalculatePlayerShotSpread(&sp1e8, &sp1dc, handnum, true); - mtx4RotateVecInPlace(camGetProjectionMtxF(), &sp1dc); + bgunCalculatePlayerShotSpread(&gunpos, &gundir, handnum, true); + mtx4RotateVecInPlace(camGetProjectionMtxF(), &gundir); if (droppinggrenade) { // Dropping a grenade because player is in an nbomb storm - velocity.x = sp1dc.x * 1.6666666f; - velocity.y = sp1dc.y * 1.6666666f; - velocity.z = sp1dc.z * 1.6666666f; + velocity.x = gundir.x * 1.6666666f; + velocity.y = gundir.y * 1.6666666f; + velocity.z = gundir.z * 1.6666666f; } else if (gsetHasFunctionFlags(&hand->gset, FUNCFLAG_CALCULATETRAJECTORY)) { // Calculate the velocity based on the trajectory to the aimpos - func0f061d54(0, 0, 0); + propFindAimingAt(HAND_RIGHT, false, FINDPROPCONTEXT_QUERY); if (hand->hasdotinfo) { aimpos.x = hand->dotpos.x; @@ -4539,11 +4539,11 @@ void bgunCreateThrownProjectile(s32 handnum, struct gset *gset) chrCalculateTrajectory(&spawnpos, 21.666666f, &aimpos, &sp140); - radians = acosf(sp1dc.f[0] * sp140.f[0] + sp1dc.f[1] * sp140.f[1] + sp1dc.f[2] * sp140.f[2]); + radians = acosf(gundir.f[0] * sp140.f[0] + gundir.f[1] * sp140.f[1] + gundir.f[2] * sp140.f[2]); // Check within 20 degrees if (radians > 0.34901026f || radians < -0.34901026f) { - mtx00016b58(&spf8, 0, 0, 0, sp1dc.x, sp1dc.y, sp1dc.z, 0, 1, 0); + mtx00016b58(&spf8, 0, 0, 0, gundir.x, gundir.y, gundir.z, 0, 1, 0); mtx00016b58(&spb8, 0, 0, 0, sp140.x, sp140.y, sp140.z, 0, 1, 0); quaternion0f097044(&spf8, sp68); @@ -4559,24 +4559,24 @@ void bgunCreateThrownProjectile(s32 handnum, struct gset *gset) quaternionSlerp(sp68, sp58, frac, sp48); quaternionToMtx(sp48, &sp78); - sp1dc.x = -sp78.m[2][0]; - sp1dc.y = -sp78.m[2][1]; - sp1dc.z = -sp78.m[2][2]; + gundir.x = -sp78.m[2][0]; + gundir.y = -sp78.m[2][1]; + gundir.z = -sp78.m[2][2]; } else { - sp1dc.x = sp140.x; - sp1dc.y = sp140.y; - sp1dc.z = sp140.z; + gundir.x = sp140.x; + gundir.y = sp140.y; + gundir.z = sp140.z; } } - velocity.x = sp1dc.x * 21.666666f; - velocity.y = sp1dc.y * 21.666666f; - velocity.z = sp1dc.z * 21.666666f; + velocity.x = gundir.x * 21.666666f; + velocity.y = gundir.y * 21.666666f; + velocity.z = gundir.z * 21.666666f; } else { // Simple velocity - velocity.x = sp1dc.x * 16.666666f; - velocity.y = sp1dc.y * 16.666666f; - velocity.z = sp1dc.z * 16.666666f; + velocity.x = gundir.x * 16.666666f; + velocity.y = gundir.y * 16.666666f; + velocity.z = gundir.z * 16.666666f; if (gset->weaponnum == WEAPON_GRENADE || gset->weaponnum == WEAPON_NBOMB) { velocity.y += 1.6666666f; @@ -4722,8 +4722,8 @@ void bgunCreateFiredProjectile(s32 handnum) f32 sp25c; struct coord sp250; Mtxf sp210; - struct coord sp204; - struct coord sp1f8; + struct coord gunpos; + struct coord gundir; struct prop *playerprop; struct coord *prevpos; struct coord *extrapos; @@ -4757,24 +4757,24 @@ void bgunCreateFiredProjectile(s32 handnum) funcdef = (struct weaponfunc_shootprojectile *)tmp; mtx4LoadIdentity(&sp270); - bgunCalculatePlayerShotSpread(&sp204, &sp1f8, handnum, true); - mtx4RotateVecInPlace(camGetProjectionMtxF(), &sp1f8); + bgunCalculatePlayerShotSpread(&gunpos, &gundir, handnum, true); + mtx4RotateVecInPlace(camGetProjectionMtxF(), &gundir); spawnpos.x = hand->muzzlepos.x; spawnpos.y = hand->muzzlepos.y; spawnpos.z = hand->muzzlepos.z; if (hand->gset.weaponnum == WEAPON_SLAYER && hand->gset.weaponfunc == FUNC_SECONDARY) { - spawnpos.x += 50.0f * sp1f8.x; - spawnpos.y += 50.0f * sp1f8.y; - spawnpos.z += 50.0f * sp1f8.z; + spawnpos.x += 50.0f * gundir.x; + spawnpos.y += 50.0f * gundir.y; + spawnpos.z += 50.0f * gundir.z; } sp260 = funcdef->speed * 1.6666666f / 60.0f; sp25c = funcdef->traveldist * 1.6666666f; if (gsetHasFunctionFlags(&hand->gset, FUNCFLAG_CALCULATETRAJECTORY)) { - func0f061d54(0, 0, 0); + propFindAimingAt(HAND_RIGHT, false, FINDPROPCONTEXT_QUERY); if (hand->hasdotinfo) { aimpos.x = hand->dotpos.x; @@ -4783,10 +4783,10 @@ void bgunCreateFiredProjectile(s32 handnum) chrCalculateTrajectory(&spawnpos, sp25c, &aimpos, &sp1bc); - radians = acosf(sp1f8.f[0] * sp1bc.f[0] + sp1f8.f[1] * sp1bc.f[1] + sp1f8.f[2] * sp1bc.f[2]); + radians = acosf(gundir.f[0] * sp1bc.f[0] + gundir.f[1] * sp1bc.f[1] + gundir.f[2] * sp1bc.f[2]); if (radians > 0.17450513f || radians < -0.17450513f) { - mtx00016b58(&sp174, 0.0f, 0.0f, 0.0f, sp1f8.x, sp1f8.y, sp1f8.z, 0.0f, 1.0f, 0.0f); + mtx00016b58(&sp174, 0.0f, 0.0f, 0.0f, gundir.x, gundir.y, gundir.z, 0.0f, 1.0f, 0.0f); mtx00016b58(&sp134, 0.0f, 0.0f, 0.0f, sp1bc.x, sp1bc.y, sp1bc.z, 0.0f, 1.0f, 0.0f); quaternion0f097044(&sp174, spe4); @@ -4802,24 +4802,24 @@ void bgunCreateFiredProjectile(s32 handnum) quaternionSlerp(spe4, spd4, frac, spc4); quaternionToMtx(spc4, &spf4); - sp1f8.x = -spf4.m[2][0]; - sp1f8.y = -spf4.m[2][1]; - sp1f8.z = -spf4.m[2][2]; + gundir.x = -spf4.m[2][0]; + gundir.y = -spf4.m[2][1]; + gundir.z = -spf4.m[2][2]; } else { - sp1f8.x = sp1bc.x; - sp1f8.y = sp1bc.y; - sp1f8.z = sp1bc.z; + gundir.x = sp1bc.x; + gundir.y = sp1bc.y; + gundir.z = sp1bc.z; } } } - sp250.x = sp1f8.x * sp260; - sp250.y = sp1f8.y * sp260; - sp250.z = sp1f8.z * sp260; + sp250.x = gundir.x * sp260; + sp250.y = gundir.y * sp260; + sp250.z = gundir.z * sp260; - sp264.x = sp250.f[0] * g_Vars.lvupdate60freal + sp1f8.f[0] * sp25c; - sp264.y = sp250.f[1] * g_Vars.lvupdate60freal + sp1f8.f[1] * sp25c; - sp264.z = sp250.f[2] * g_Vars.lvupdate60freal + sp1f8.f[2] * sp25c; + sp264.x = sp250.f[0] * g_Vars.lvupdate60freal + gundir.f[0] * sp25c; + sp264.y = sp250.f[1] * g_Vars.lvupdate60freal + gundir.f[1] * sp25c; + sp264.z = sp250.f[2] * g_Vars.lvupdate60freal + gundir.f[2] * sp25c; if ((funcdef->base.base.flags & FUNCFLAG_FLYBYWIRE) == 0 && g_Vars.lvupdate240 > 0) { sp264.x += (playerprop->pos.x - prevpos->x + extrapos->x) / g_Vars.lvupdate60freal; @@ -5236,7 +5236,7 @@ void bgun0f0a0c44(s32 handnum, struct coord *arg1, struct coord *arg2) cam0f0b4c3c(g_Vars.currentplayer->hands[handnum].crosspos, arg2, 1); } -void bgunCalculatePlayerShotSpread(struct coord *arg0, struct coord *arg1, s32 handnum, bool dorandom) +void bgunCalculatePlayerShotSpread(struct coord *gunpos2d, struct coord *gundir2d, s32 handnum, bool dorandom) { f32 crosspos[2]; f32 spread = 0; @@ -5250,7 +5250,6 @@ void bgunCalculatePlayerShotSpread(struct coord *arg0, struct coord *arg1, s32 h spread = shootfunc->spread; } - // Unsure what this is if (weaponHasAimFlag(bgunGetWeaponNum2(handnum), INVAIMFLAG_ACCURATESINGLESHOT) && player->hands[handnum].burstbullets == 1) { spread *= 0.25f; @@ -5286,11 +5285,11 @@ void bgunCalculatePlayerShotSpread(struct coord *arg0, struct coord *arg1, s32 h crosspos[1] = player->crosspos[1] + (randfactor * scaledspread * camGetScreenHeight()) / viGetHeight(); - arg0->x = 0; - arg0->y = 0; - arg0->z = 0; + gunpos2d->x = 0; + gunpos2d->y = 0; + gunpos2d->z = 0; - cam0f0b4c3c(crosspos, arg1, 1); + cam0f0b4c3c(crosspos, gundir2d, 1); } void bgunCalculateBotShotSpread(struct coord *arg0, s32 weaponnum, s32 funcnum, bool arg3, s32 crouchpos, bool dual) diff --git a/src/game/botact.c b/src/game/botact.c index f691b305e..c2aa48cd4 100644 --- a/src/game/botact.c +++ b/src/game/botact.c @@ -259,7 +259,7 @@ bool botactShootFarsight(struct chrdata *chr, s32 arg1, struct coord *vector, st // chance of passing. if (oppchr != chr && value > rand - && func0f06b39c(arg3, vector, &oppprop->pos, chr0f0278a4(oppchr))) { + && func0f06b39c(arg3, vector, &oppprop->pos, chrGetHitRadius(oppchr))) { bgunPlayPropHitSound(&gset, oppprop, -1); if (oppchr->model && chrGetShield(oppchr) > 0) { diff --git a/src/game/camera.c b/src/game/camera.c index 2c1f833de..92996ae26 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -105,7 +105,7 @@ void camSetScale(void) player->c_cameraleftnorm.z = -fVar5 * fVar4; } -void cam0f0b4c3c(f32 *crosspos, struct coord *dst, f32 arg2) +void cam0f0b4c3c(f32 pos2d[2], struct coord *dir2d, f32 arg2) { struct player *player = g_Vars.currentplayer; f32 sp20; @@ -113,14 +113,14 @@ void cam0f0b4c3c(f32 *crosspos, struct coord *dst, f32 arg2) f32 sp18 = -1.0f; f32 f2; - sp1c = (player->c_halfheight - (crosspos[1] - player->c_screentop)) * player->c_scaley; - sp20 = (crosspos[0] - player->c_screenleft - player->c_halfwidth) * player->c_scalex; + sp1c = (player->c_halfheight - (pos2d[1] - player->c_screentop)) * player->c_scaley; + sp20 = (pos2d[0] - player->c_screenleft - player->c_halfwidth) * player->c_scalex; f2 = arg2 / sqrtf(sp20 * sp20 + sp1c * sp1c + sp18 * sp18); - dst->x = sp20 * f2; - dst->y = sp1c * f2; - dst->z = sp18 * f2; + dir2d->x = sp20 * f2; + dir2d->y = sp1c * f2; + dir2d->z = sp18 * f2; } void cam0f0b4d04(struct coord *in, f32 *out) @@ -128,11 +128,8 @@ void cam0f0b4d04(struct coord *in, f32 *out) struct player *player = g_Vars.currentplayer; f32 value = 1.0f / in->z; - out[1] = in->y * value * player->c_recipscaley - + (player->c_screentop + player->c_halfheight); - - out[0] = (player->c_screenleft + player->c_halfwidth) - - in->x * value * player->c_recipscalex; + out[1] = in->y * value * player->c_recipscaley + (player->c_screentop + player->c_halfheight); + out[0] = (player->c_screenleft + player->c_halfwidth) - in->x * value * player->c_recipscalex; } void cam0f0b4d68(struct coord *in, f32 out[2]) diff --git a/src/game/chr.c b/src/game/chr.c index c91af0795..1c4901630 100644 --- a/src/game/chr.c +++ b/src/game/chr.c @@ -4449,7 +4449,7 @@ void chrDisfigure(struct chrdata *chr, struct coord *exppos, f32 damageradius) } } -f32 chr0f0278a4(struct chrdata *chr) +f32 chrGetHitRadius(struct chrdata *chr) { s32 i; f32 result; @@ -4481,16 +4481,16 @@ f32 chr0f0278a4(struct chrdata *chr) return result; } -void chr0f027994(struct prop *prop, struct shotdata *shotdata, bool arg2, bool arg3) +void chrTestHit(struct prop *prop, struct shotdata *shotdata, bool isshooting, bool cheap) { struct coord spdc; struct coord spd0; struct chrdata *chr = prop->chr; if ((chr->chrflags & CHRCFLAG_HIDDEN) == 0 && (prop->flags & PROPFLAG_ONTHISSCREENTHISTICK)) { - f32 fStack32 = chr0f0278a4(chr); + f32 radius = chrGetHitRadius(chr); - if (prop->z - fStack32 < shotdata->unk34) { + if (prop->z - radius < shotdata->distance) { struct model *model = chr->model; s32 hitpart = 0; struct modelnode *node = NULL; @@ -4498,14 +4498,14 @@ void chr0f027994(struct prop *prop, struct shotdata *shotdata, bool arg2, bool a struct hitthing sp88; s32 sp84 = 0; struct modelnode *sp80 = NULL; - Mtxf *iVar5 = modelGetRootMtx(model); + Mtxf *rootmtx = modelGetRootMtx(model); struct prop *next; struct prop *child; f32 sp70; Mtxf *mtx; f32 sp68; - if (func0f06b39c(&shotdata->unk00, &shotdata->unk0c, (struct coord *)iVar5->m[3], fStack32)) { + if (func0f06b39c(&shotdata->gunpos2d, &shotdata->gundir2d, (struct coord *)rootmtx->m[3], radius)) { spb8 = 1; hitpart = 1; } @@ -4523,27 +4523,27 @@ void chr0f027994(struct prop *prop, struct shotdata *shotdata, bool arg2, bool a child = next; } - if (arg3 || var8005efc0 > 0.0f) { - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node); + if (cheap || var8005efc0 > 0.0f) { + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node); while (hitpart > 0) { - if (func0f084594(model, node, &shotdata->unk00, &shotdata->unk0c, &sp88, &sp84, &sp80)) { - mtx4TransformVec(&model->matrices[sp84], &sp88.unk00, &spdc); + if (func0f084594(model, node, &shotdata->gunpos2d, &shotdata->gundir2d, &sp88, &sp84, &sp80)) { + mtx4TransformVec(&model->matrices[sp84], &sp88.pos, &spdc); mtx4TransformVecInPlace(camGetProjectionMtxF(), &spdc); mtx4RotateVec(&model->matrices[sp84], &sp88.unk0c, &spd0); mtx4RotateVecInPlace(camGetProjectionMtxF(), &spd0); break; } - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node); + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node); } } else { - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node); + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node); if (hitpart > 0) { - if (func0f06bea0(model, model->definition->rootnode, model->definition->rootnode, &shotdata->unk00, - &shotdata->unk0c, &sp88.unk00, &sp70, &node, &hitpart, &sp84, &sp80)) { - mtx4TransformVec(camGetProjectionMtxF(), &sp88.unk00, &spdc); + if (func0f06bea0(model, model->definition->rootnode, model->definition->rootnode, &shotdata->gunpos2d, + &shotdata->gundir2d, &sp88.pos, &sp70, &node, &hitpart, &sp84, &sp80)) { + mtx4TransformVec(camGetProjectionMtxF(), &sp88.pos, &spdc); mtx4RotateVec(camGetProjectionMtxF(), &sp88.unk0c, &spd0); } else { hitpart = 0; @@ -4561,12 +4561,12 @@ void chr0f027994(struct prop *prop, struct shotdata *shotdata, bool arg2, bool a sp68 = spdc.x * mtx->m[0][2] + spdc.y * mtx->m[1][2] + spdc.z * mtx->m[2][2] + mtx->m[3][2]; sp68 = -sp68; - if (sp68 < shotdata->unk34) { - func0f061fa8(shotdata, prop, sp68, hitpart, node, &sp88, sp84, sp80, model, 1, chrGetShield(chr) > 0.0f, &spdc, &spd0); + if (sp68 < shotdata->distance) { + hitCreate(shotdata, prop, sp68, hitpart, node, &sp88, sp84, sp80, model, true, chrGetShield(chr) > 0.0f, &spdc, &spd0); } } - if (spb8 && hitpart <= 0 && prop->z <= shotdata->unk34 && arg2) { + if (spb8 && hitpart <= 0 && prop->z <= shotdata->distance && isshooting) { if (chrGetTargetProp(chr) == g_Vars.currentplayer->prop) { chr->chrflags |= CHRCFLAG_NEAR_MISS; } @@ -4607,24 +4607,24 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) chr = prop->chr; if ((chr->chrflags & CHRCFLAG_HIDDEN) == 0) { - sp98.x = shotdata->unk00.x - (hit->distance * shotdata->unk0c.x) / shotdata->unk0c.z; - sp98.y = shotdata->unk00.y - (hit->distance * shotdata->unk0c.y) / shotdata->unk0c.z; - sp98.z = shotdata->unk00.z - hit->distance; + sp98.x = shotdata->gunpos2d.x - (hit->distance * shotdata->gundir2d.x) / shotdata->gundir2d.z; + sp98.y = shotdata->gunpos2d.y - (hit->distance * shotdata->gundir2d.y) / shotdata->gundir2d.z; + sp98.z = shotdata->gunpos2d.z - hit->distance; mtx4TransformVec(camGetProjectionMtxF(), &sp98, &hitpos); bgunSetHitPos(&hitpos); bgunPlayPropHitSound(&shotdata->gset, hit->prop, -1); - chrEmitSparks(chr, hit->prop, hit->hitpart, &hitpos, &shotdata->dir, g_Vars.currentplayer->prop->chr); + chrEmitSparks(chr, hit->prop, hit->hitpart, &hitpos, &shotdata->gundir3d, g_Vars.currentplayer->prop->chr); - sp90[0] = hit->hitthing.unk00.x; - sp90[1] = hit->hitthing.unk00.y; - sp90[2] = hit->hitthing.unk00.z; + sp90[0] = hit->hitthing.pos.x; + sp90[1] = hit->hitthing.pos.y; + sp90[2] = hit->hitthing.pos.z; shield = chrGetShield(chr); - func0f0341dc(chr, gsetGetDamage(&shotdata->gset), &shotdata->dir, &shotdata->gset, - g_Vars.currentplayer->prop, hit->hitpart, hit->prop, hit->node, + func0f0341dc(chr, gsetGetDamage(&shotdata->gset), &shotdata->gundir3d, &shotdata->gset, + g_Vars.currentplayer->prop, hit->hitpart, hit->prop, hit->bboxnode, hit->model, hit->hitthing.unk28 / 2, sp90); if (g_Vars.antiplayernum >= 0 @@ -4679,9 +4679,9 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) index = random() % type->numwallhittexes; wallhitCreate( - &hit->hitthing.unk00, + &hit->hitthing.pos, &hit->hitthing.unk0c, - &shotdata->gunpos, + &shotdata->gunpos3d, 0, 0, type->wallhittexes[index], @@ -4715,9 +4715,9 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) index = random() % type->numwallhittexes; wallhitCreate( - &hit->hitthing.unk00, + &hit->hitthing.pos, &hit->hitthing.unk0c, - &shotdata->gunpos, + &shotdata->gunpos3d, 0, 0, type->wallhittexes[index], @@ -4731,7 +4731,7 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) // Shot a chr in the flesh s32 race = CHRRACE(chr); struct coord sp5c; - Mtxf *sp58 = modelFindNodeMtx(hit->model, hit->node, 0); + Mtxf *sp58 = modelFindNodeMtx(hit->model, hit->bboxnode, 0); // Create blood mtx0001719c(sp58->m, spb0.m); @@ -4753,7 +4753,7 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) } if (!chrIsUsingPaintball(g_Vars.currentplayer->prop->chr)) { - chrBruise(hit->model, hit->hitpart, hit->node, &sp5c); + chrBruise(hit->model, hit->hitpart, hit->bboxnode, &sp5c); } splatsCreateForChrHit(prop, shotdata, &sp98, &hitpos, darker, 0, g_Vars.currentplayer->prop->chr); @@ -4776,7 +4776,7 @@ void chrHit(struct shotdata *shotdata, struct hit *hit) darker = false; } - chrBruise(hit->model, hit->hitpart, hit->node, &sp5c); + chrBruise(hit->model, hit->hitpart, hit->bboxnode, &sp5c); splatsCreateForChrHit(prop, shotdata, &sp98, &hitpos, darker, 0, g_Vars.currentplayer->prop->chr); } diff --git a/src/game/lv.c b/src/game/lv.c index 6d5516152..d4134f4fa 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -1199,7 +1199,7 @@ Gfx *lvRender(Gfx *gdl) || g_Vars.coopplayernum >= 0 || g_Vars.antiplayernum >= 0 || (weaponHasFlag(bgunGetWeaponNum(HAND_RIGHT), WEAPONFLAG_AIMTRACK) && bmoveIsInSightAimMode())) { - g_Vars.currentplayer->lookingatprop.prop = func0f061d54(HAND_RIGHT, 0, 0); + g_Vars.currentplayer->lookingatprop.prop = propFindAimingAt(HAND_RIGHT, false, FINDPROPCONTEXT_QUERY); if (g_Vars.currentplayer->lookingatprop.prop) { if (g_Vars.currentplayer->lookingatprop.prop->type == PROPTYPE_CHR diff --git a/src/game/prop.c b/src/game/prop.c index 2a0c496f3..1daed88a7 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -564,13 +564,13 @@ void func0f060bac(s32 weaponnum, struct prop *prop) * * The return value is the final prop that was hit. */ -struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struct coord *arg3, struct coord *gunpos, struct coord *dir, u32 arg6, f32 arg7, bool arg8) +struct prop *shotCalculateHits(s32 handnum, bool isshooting, struct coord *gunpos2d, struct coord *gundir2d, struct coord *gunpos3d, struct coord *gundir3d, u32 arg6, f32 distance, bool cheap) { u32 index; struct prop **propptr; struct prop *root; bool explosiveshells = false; - bool sp6cc = false; + bool blockedbyprop = false; bool hitbg = false; s32 room = 0; struct hitthing sp694; @@ -583,7 +583,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc s32 s1 = 0; struct weaponfunc *func; bool laserstream = false; - bool shortrange = false; + bool ismelee = false; f32 range = 200; struct prop *result = NULL; s32 hitindex; @@ -599,46 +599,46 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc RoomNum spc8[8]; RoomNum spb8[8]; - s32 uVar6; + s32 texnum; RoomNum *roomsptr; struct prop *prop; struct coord spa0; struct defaultobj *obj; bool doexplosiveshells; - struct coord sp8c; - RoomNum sp7c[8]; - RoomNum sp6c[8]; + struct coord exppos; + RoomNum exprooms[8]; + RoomNum rooms2[8]; struct prop *hitprop; bgun0f0a9494(arg6); - shotdata.gunpos.x = gunpos->x; - shotdata.gunpos.y = gunpos->y; - shotdata.gunpos.z = gunpos->z; + shotdata.gunpos3d.x = gunpos3d->x; + shotdata.gunpos3d.y = gunpos3d->y; + shotdata.gunpos3d.z = gunpos3d->z; - shotdata.unk00.x = arg2->x; - shotdata.unk00.y = arg2->y; - shotdata.unk00.z = arg2->z; + shotdata.gunpos2d.x = gunpos2d->x; + shotdata.gunpos2d.y = gunpos2d->y; + shotdata.gunpos2d.z = gunpos2d->z; - shotdata.dir.x = dir->x; - shotdata.dir.y = dir->y; - shotdata.dir.z = dir->z; + shotdata.gundir3d.x = gundir3d->x; + shotdata.gundir3d.y = gundir3d->y; + shotdata.gundir3d.z = gundir3d->z; - shotdata.unk0c.x = arg3->x; - shotdata.unk0c.y = arg3->y; - shotdata.unk0c.z = arg3->z; + shotdata.gundir2d.x = gundir2d->x; + shotdata.gundir2d.y = gundir2d->y; + shotdata.gundir2d.z = gundir2d->z; gsetPopulateFromCurrentPlayer(handnum, &shotdata.gset); func = gsetGetWeaponFunction(&shotdata.gset); if (func) { - if (arg1 && (func->flags & FUNCFLAG_EXPLOSIVESHELLS)) { + if (isshooting && (func->flags & FUNCFLAG_EXPLOSIVESHELLS)) { explosiveshells = true; } - if ((func->type & 0xff) == INVENTORYFUNCTYPE_MELEE && arg1) { - shortrange = true; - arg1 = false; + if ((func->type & 0xff) == INVENTORYFUNCTYPE_MELEE && isshooting) { + ismelee = true; + isshooting = false; } } @@ -646,41 +646,41 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc laserstream = true; } - if (arg1) { + if (isshooting) { shotdata.penetration = gsetGetSinglePenetration(&shotdata.gset); } else { shotdata.penetration = 1; } - shotdata.unk34 = arg7; + shotdata.distance = distance; for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { shotdata.hits[i].prop = NULL; shotdata.hits[i].hitpart = 0; - shotdata.hits[i].node = NULL; + shotdata.hits[i].bboxnode = NULL; } if (laserstream) { - hitpos.x = shotdata.gunpos.x + shotdata.dir.x * 300; - hitpos.y = shotdata.gunpos.y + shotdata.dir.y * 300; - hitpos.z = shotdata.gunpos.z + shotdata.dir.z * 300; - } else if (shortrange) { + hitpos.x = shotdata.gunpos3d.x + shotdata.gundir3d.x * 300; + hitpos.y = shotdata.gunpos3d.y + shotdata.gundir3d.y * 300; + hitpos.z = shotdata.gunpos3d.z + shotdata.gundir3d.z * 300; + } else if (ismelee) { if ((func->type & 0xff) == INVENTORYFUNCTYPE_MELEE) { struct weaponfunc_melee *meleefunc = (struct weaponfunc_melee *) func; range = meleefunc->range; } - hitpos.x = shotdata.gunpos.x + shotdata.dir.x * range; - hitpos.y = shotdata.gunpos.y + shotdata.dir.y * range; - hitpos.z = shotdata.gunpos.z + shotdata.dir.z * range; + hitpos.x = shotdata.gunpos3d.x + shotdata.gundir3d.x * range; + hitpos.y = shotdata.gunpos3d.y + shotdata.gundir3d.y * range; + hitpos.z = shotdata.gunpos3d.z + shotdata.gundir3d.z * range; } else { - hitpos.x = shotdata.gunpos.x + shotdata.dir.x * 65536; - hitpos.y = shotdata.gunpos.y + shotdata.dir.y * 65536; - hitpos.z = shotdata.gunpos.z + shotdata.dir.z * 65536; + hitpos.x = shotdata.gunpos3d.x + shotdata.gundir3d.x * 65536; + hitpos.y = shotdata.gunpos3d.y + shotdata.gundir3d.y * 65536; + hitpos.z = shotdata.gunpos3d.z + shotdata.gundir3d.z * 65536; } - portal00018148(&playerprop->pos, &shotdata.gunpos, playerprop->rooms, spc8, 0, 0); - portal00018148(&shotdata.gunpos, &hitpos, spc8, spb8, rooms, 30); + portal00018148(&playerprop->pos, &shotdata.gunpos3d, playerprop->rooms, spc8, 0, 0); + portal00018148(&shotdata.gunpos3d, &hitpos, spc8, spb8, rooms, 30); if (shotdata.gset.weaponnum != WEAPON_FARSIGHT || g_Vars.currentplayer->visionmode != VISIONMODE_XRAY) { roomsptr = rooms; @@ -693,36 +693,36 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc bgGetForceOnscreenRooms(roomsptr, 100); for (i = 0; rooms[i] != -1; i++) { - if (bgTestHitInRoom(&shotdata.gunpos, &hitpos, rooms[i], &sp664)) { - sp664.unk00.x *= 1; - sp664.unk00.y *= 1; - sp664.unk00.z *= 1; + if (bgTestHitInRoom(&shotdata.gunpos3d, &hitpos, rooms[i], &sp664)) { + sp664.pos.x *= 1; + sp664.pos.y *= 1; + sp664.pos.z *= 1; - if (((hitpos.x >= shotdata.gunpos.x && hitpos.x >= sp664.unk00.x && sp664.unk00.x >= shotdata.gunpos.x) - || (hitpos.x <= shotdata.gunpos.x && hitpos.x <= sp664.unk00.x && sp664.unk00.x <= shotdata.gunpos.x)) - && ((hitpos.y >= shotdata.gunpos.y && hitpos.y >= sp664.unk00.y && sp664.unk00.y >= shotdata.gunpos.y) - || (hitpos.y <= shotdata.gunpos.y && hitpos.y <= sp664.unk00.y && sp664.unk00.y <= shotdata.gunpos.y)) - && ((shotdata.gunpos.z <= hitpos.z && sp664.unk00.z <= hitpos.z && shotdata.gunpos.z <= sp664.unk00.z) - || (hitpos.z <= shotdata.gunpos.z && hitpos.z <= sp664.unk00.z && sp664.unk00.z <= shotdata.gunpos.z)) - && (shotdata.gunpos.x != sp664.unk00.x || shotdata.gunpos.y != sp664.unk00.y || shotdata.gunpos.z != sp664.unk00.z)) { + if (((hitpos.x >= shotdata.gunpos3d.x && hitpos.x >= sp664.pos.x && sp664.pos.x >= shotdata.gunpos3d.x) + || (hitpos.x <= shotdata.gunpos3d.x && hitpos.x <= sp664.pos.x && sp664.pos.x <= shotdata.gunpos3d.x)) + && ((hitpos.y >= shotdata.gunpos3d.y && hitpos.y >= sp664.pos.y && sp664.pos.y >= shotdata.gunpos3d.y) + || (hitpos.y <= shotdata.gunpos3d.y && hitpos.y <= sp664.pos.y && sp664.pos.y <= shotdata.gunpos3d.y)) + && ((shotdata.gunpos3d.z <= hitpos.z && sp664.pos.z <= hitpos.z && shotdata.gunpos3d.z <= sp664.pos.z) + || (hitpos.z <= shotdata.gunpos3d.z && hitpos.z <= sp664.pos.z && sp664.pos.z <= shotdata.gunpos3d.z)) + && (shotdata.gunpos3d.x != sp664.pos.x || shotdata.gunpos3d.y != sp664.pos.y || shotdata.gunpos3d.z != sp664.pos.z)) { hitbg = true; room = rooms[i]; sp694 = sp664; - hitpos.x = sp664.unk00.x; - hitpos.y = sp664.unk00.y; - hitpos.z = sp664.unk00.z; + hitpos.x = sp664.pos.x; + hitpos.y = sp664.pos.y; + hitpos.z = sp664.pos.z; } } } } if (hitbg && shotdata.gset.weaponnum != WEAPON_FARSIGHT) { - mtx4TransformVec(camGetWorldToScreenMtxf(), &sp694.unk00, &sp658); + mtx4TransformVec(camGetWorldToScreenMtxf(), &sp694.pos, &sp658); - if (shotdata.unk34 > -sp658.z) { - shotdata.unk34 = -sp658.z; + if (shotdata.distance > -sp658.z) { + shotdata.distance = -sp658.z; } } @@ -734,11 +734,11 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc if (prop) { if (prop->type == PROPTYPE_CHR || (prop->type == PROPTYPE_PLAYER && prop->chr && playermgrGetPlayerNumByProp(prop) != g_Vars.currentplayernum)) { - if (!shortrange) { - chr0f027994(prop, &shotdata, arg1, arg8); + if (!ismelee) { + chrTestHit(prop, &shotdata, isshooting, cheap); } } else if (prop->type == PROPTYPE_OBJ || prop->type == PROPTYPE_WEAPON || prop->type == PROPTYPE_DOOR) { - func0f085e00(prop, &shotdata); + objTestHit(prop, &shotdata); } } @@ -759,10 +759,10 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc if (hitindex != -1) { bgun0f0a94d0(arg6, &shotdata.hits[hitindex].pos, &shotdata.hits[hitindex].dir); } else if (hitbg) { - bgun0f0a94d0(arg6, &sp694.unk00, &sp694.unk0c); + bgun0f0a94d0(arg6, &sp694.pos, &sp694.unk0c); } - if (arg1) { + if (isshooting) { for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { hitprop = shotdata.hits[i].prop; @@ -781,18 +781,18 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc objHit(&shotdata, &shotdata.hits[i]); } - if (shotdata.hits[i].unk4d) { - sp6cc = true; + if (shotdata.hits[i].bulletproof) { + blockedbyprop = true; doexplosiveshells = explosiveshells; hitpos.x = shotdata.hits[i].pos.x; hitpos.y = shotdata.hits[i].pos.y; hitpos.z = shotdata.hits[i].pos.z; - } else if (shotdata.hits[i].unk4c + } else if (shotdata.hits[i].slowsbullet || (explosiveshells && (obj->type == OBJTYPE_GLASS || obj->type == OBJTYPE_TINTEDGLASS))) { s1++; if (s1 >= shotdata.penetration) { - sp6cc = true; + blockedbyprop = true; doexplosiveshells = explosiveshells; hitpos.x = shotdata.hits[i].pos.x; hitpos.y = shotdata.hits[i].pos.y; @@ -801,21 +801,21 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc } if (doexplosiveshells) { - sp8c.x = shotdata.hits[i].pos.x; - sp8c.y = shotdata.hits[i].pos.y; - sp8c.z = shotdata.hits[i].pos.z; + exppos.x = shotdata.hits[i].pos.x; + exppos.y = shotdata.hits[i].pos.y; + exppos.z = shotdata.hits[i].pos.z; - func0f065e74(&root->pos, root->rooms, &sp8c, sp7c); - explosionCreateSimple(0, &sp8c, sp7c, EXPLOSIONTYPE_PHOENIX, g_Vars.currentplayernum); + func0f065e74(&root->pos, root->rooms, &exppos, exprooms); + explosionCreateSimple(0, &exppos, exprooms, EXPLOSIONTYPE_PHOENIX, g_Vars.currentplayernum); } } } - if (hitbg && !sp6cc) { - sp6c[0] = room; - sp6c[1] = -1; + if (hitbg && !blockedbyprop) { + rooms2[0] = room; + rooms2[1] = -1; - uVar6 = lightsHandleHit(&shotdata.gunpos, &hitpos, room); + texnum = lightsHandleHit(&shotdata.gunpos3d, &hitpos, room); if (sp694.texturenum < 0 || sp694.texturenum >= NUM_TEXTURES) { surfacetype = g_SurfaceTypes[SURFACETYPE_DEFAULT]; @@ -829,47 +829,47 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc } } - bgunSetHitPos(&sp694.unk00); + bgunSetHitPos(&sp694.pos); if (surfacetype->numwallhittexes > 0 && (!func || (func->type & 0xff) != INVENTORYFUNCTYPE_MELEE)) { if (shotdata.gset.weaponnum != WEAPON_UNARMED && shotdata.gset.weaponnum != WEAPON_LASER && shotdata.gset.weaponnum != WEAPON_TRANQUILIZER && shotdata.gset.weaponnum != WEAPON_FARSIGHT) { - uVar6 = random() % surfacetype->numwallhittexes; - uVar6 = surfacetype->wallhittexes[uVar6]; + texnum = random() % surfacetype->numwallhittexes; + texnum = surfacetype->wallhittexes[texnum]; - if (uVar6 >= WALLHITTEX_GLASS1 && uVar6 <= WALLHITTEX_GLASS3) { + if (texnum >= WALLHITTEX_GLASS1 && texnum <= WALLHITTEX_GLASS3) { // Use bulletproof glass hit textures instead - uVar6 += 10; + texnum += 10; } - if (uVar6) { - wallhitCreate(&sp694.unk00, &sp694.unk0c, &shotdata.gunpos, 0, 0, uVar6, room, 0, -1, 0, g_Vars.currentplayer->prop->chr, sp694.unk2c == 2); + if (texnum) { + wallhitCreate(&sp694.pos, &sp694.unk0c, &shotdata.gunpos3d, 0, 0, texnum, room, 0, -1, 0, g_Vars.currentplayer->prop->chr, sp694.unk2c == 2); } } - bgunPlayBgHitSound(&shotdata.gset, &sp694.unk00, sp694.texturenum, sp6c); + bgunPlayBgHitSound(&shotdata.gset, &sp694.pos, sp694.texturenum, rooms2); if (explosiveshells) { - explosionCreateSimple(NULL, &sp694.unk00, sp6c, EXPLOSIONTYPE_PHOENIX, g_Vars.currentplayernum); + explosionCreateSimple(NULL, &sp694.pos, rooms2, EXPLOSIONTYPE_PHOENIX, g_Vars.currentplayernum); } else { if (!chrIsUsingPaintball(g_Vars.currentplayer->prop->chr)) { if (PLAYERCOUNT() >= 2) { if ((random() % 8) == 0) { - smokeCreateSimple(&sp694.unk00, sp6c, SMOKETYPE_BULLETIMPACT); + smokeCreateSimple(&sp694.pos, rooms2, SMOKETYPE_BULLETIMPACT); } } else { - if (uVar6) { - explosionCreateSimple(NULL, &sp694.unk00, sp6c, EXPLOSIONTYPE_BULLETHOLE, g_Vars.currentplayernum); + if (texnum) { + explosionCreateSimple(NULL, &sp694.pos, rooms2, EXPLOSIONTYPE_BULLETHOLE, g_Vars.currentplayernum); } } } if (PLAYERCOUNT() <= 2 || g_Vars.lvupdate240 <= 8 || (random() % 4) == 0) { - if (sp694.unk00.x > -32000 && sp694.unk00.x < 32000 - && sp694.unk00.y > -32000 && sp694.unk00.y < 32000 - && sp694.unk00.z > -32000 && sp694.unk00.z < 32000) { + if (sp694.pos.x > -32000 && sp694.pos.x < 32000 + && sp694.pos.y > -32000 && sp694.pos.y < 32000 + && sp694.pos.z > -32000 && sp694.pos.z < 32000) { sparktype = SPARKTYPE_DEFAULT; if (chrIsUsingPaintball(g_Vars.currentplayer->prop->chr)) { @@ -893,14 +893,14 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc break; } - uVar6 = g_Textures[sp694.texturenum].surfacetype; + texnum = g_Textures[sp694.texturenum].surfacetype; - if (uVar6 == SURFACETYPE_SHALLOWWATER || uVar6 == SURFACETYPE_DEEPWATER) { + if (texnum == SURFACETYPE_SHALLOWWATER || texnum == SURFACETYPE_DEEPWATER) { sparktype = SPARKTYPE_SHALLOWWATER; } } - sparksCreate(room, NULL, &sp694.unk00, &shotdata.dir, &sp694.unk0c, sparktype); + sparksCreate(room, NULL, &sp694.pos, &shotdata.gundir3d, &sp694.unk0c, sparktype); } } } @@ -908,7 +908,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc } else { bgunSetHitPos(&hitpos); } - } else if (shortrange) { + } else if (ismelee) { s32 hitindex; bool hitaprop = false; @@ -927,18 +927,17 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc if (shotdata.gset.weaponnum != WEAPON_UNARMED && shotdata.gset.weaponnum != WEAPON_TRANQUILIZER) { if (hitaprop) { - sparksCreate(shotdata.hits[hitindex].prop->rooms[0], NULL, &shotdata.hits[hitindex].pos, &shotdata.dir, &shotdata.hits[hitindex].dir, SPARKTYPE_DEFAULT); + sparksCreate(shotdata.hits[hitindex].prop->rooms[0], NULL, &shotdata.hits[hitindex].pos, &shotdata.gundir3d, &shotdata.hits[hitindex].dir, SPARKTYPE_DEFAULT); } else { - sparksCreate(room, NULL, &sp694.unk00, &shotdata.dir, &sp694.unk0c, SPARKTYPE_DEFAULT); + sparksCreate(room, NULL, &sp694.pos, &shotdata.gundir3d, &sp694.unk0c, SPARKTYPE_DEFAULT); } } } else { weaponPlayWhooshSound(shotdata.gset.weaponnum, g_Vars.currentplayer->prop); } } else { - // Figure out what prop was hit so it can be returned, - // by iterating the props in order of distance. - // For laser stream, bail early once the laser's range is reached. + // The caller is querying which prop is being aimed at rather than taking a shot. + // Find the closest object and return it. done = false; for (i = 0; i < ARRAYCOUNT(shotdata.hits); i++) { @@ -959,10 +958,7 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc done = true; } - // This seems like it handles penetration (bullets going - // through multiple props), but the loop is effectively - // stopped when any prop is hit so this seems unlikely. - if (shotdata.hits[i].unk4c) { + if (shotdata.hits[i].slowsbullet) { s1++; if (s1 >= shotdata.penetration) { @@ -977,59 +973,73 @@ struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struc return result; } -struct prop *func0f061d54(s32 handnum, u32 arg1, u32 arg2) +struct prop *propFindAimingAt(s32 handnum, bool isshooting, u32 context) { - struct coord sp64; - struct coord sp58; - struct coord sp4c; - struct coord sp40; + struct coord gundir2d; + struct coord gunpos2d; + struct coord gundir3d; + struct coord gunpos3d; - bgunCalculatePlayerShotSpread(&sp58, &sp64, handnum, arg2); + bgunCalculatePlayerShotSpread(&gunpos2d, &gundir2d, handnum, context); - if (arg2 == 2 && bgunGetWeaponNum(HAND_RIGHT) == WEAPON_REAPER) { - sp58.y -= 15 * RANDOMFRAC(); + if (context == FINDPROPCONTEXT_SHOOT && bgunGetWeaponNum(HAND_RIGHT) == WEAPON_REAPER) { + gunpos2d.y -= 15 * RANDOMFRAC(); } - mtx4TransformVec(camGetProjectionMtxF(), &sp58, &sp40); - mtx4RotateVec(camGetProjectionMtxF(), &sp64, &sp4c); + mtx4TransformVec(camGetProjectionMtxF(), &gunpos2d, &gunpos3d); + mtx4RotateVec(camGetProjectionMtxF(), &gundir2d, &gundir3d); - return shotCalculateHits(handnum, arg1, &sp58, &sp64, &sp40, &sp4c, 0, 4294836224, PLAYERCOUNT() >= 2); + return shotCalculateHits(handnum, isshooting, &gunpos2d, &gundir2d, &gunpos3d, &gundir3d, 0, 4294836224, PLAYERCOUNT() >= 2); } -void shotCreate(s32 handnum, bool arg1, bool dorandom, s32 arg3, bool arg4) +void shotCreate(s32 handnum, bool isshooting, bool dorandom, s32 numshots, bool cheap) { - struct coord shootdir; - struct coord shootpos; - struct coord sp44; - struct coord sp38; + struct coord gundir3d; + struct coord gunpos3d; + struct coord gundir2d; + struct coord gunpos2d; - bgunCalculatePlayerShotSpread(&sp38, &sp44, handnum, dorandom); + bgunCalculatePlayerShotSpread(&gunpos2d, &gundir2d, handnum, dorandom); - if (arg3 > 0) { - mtx4TransformVec(camGetProjectionMtxF(), &sp38, &shootpos); - mtx4RotateVec(camGetProjectionMtxF(), &sp44, &shootdir); + if (numshots > 0) { + mtx4TransformVec(camGetProjectionMtxF(), &gunpos2d, &gunpos3d); + mtx4RotateVec(camGetProjectionMtxF(), &gundir2d, &gundir3d); - shotCalculateHits(handnum, arg1, &sp38, &sp44, &shootpos, &shootdir, 0, 4294836224, arg4); + shotCalculateHits(handnum, isshooting, &gunpos2d, &gundir2d, &gunpos3d, &gundir3d, 0, 4294836224, cheap); - if (arg3 < 2) { - bgunSetLastShootInfo(&shootpos, &shootdir, handnum); + if (numshots <= 1) { + bgunSetLastShootInfo(&gunpos3d, &gundir3d, handnum); } } } -void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hitpart, struct modelnode *node, struct hitthing *hitthing, s32 arg6, struct modelnode *arg7, struct model *model, bool arg9, s32 arg10, struct coord *arg11, struct coord *arg12) +/** + * Add a prop to the shot's hit list. + * + * Possible @bug: This function assumes the prop that's being added to the list + * is closer than the previous furtherest. This is okay if it's guaranteed that + * hits are added in the order of furtherest to closest. I'm unsure if this is + * true though. + */ +void hitCreate(struct shotdata *shotdata, struct prop *prop, f32 hitdistance, s32 hitpart, + struct modelnode *bboxnode, struct hitthing *hitthing, s32 mtxindex, struct modelnode *dlnode, + struct model *model, bool slowsbullet, bool bulletproof, struct coord *arg11, struct coord *arg12) { s32 i; f32 fVar8; - if (arg9) { + // If this prop "slows" the bullet, it means it contributes to the bullet's + // penetration total. Most props slow the bullet. Glass does not. + if (slowsbullet) { s32 bestindex = 0; s32 count = 0; f32 mostdist = 0; f32 prevmostdist = 0; + // Count the number of existing hits that slow the bullet, + // and note which hit of these is the furtherest. for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { - if (shotdata->hits[i].prop && shotdata->hits[i].unk4c) { + if (shotdata->hits[i].prop && shotdata->hits[i].slowsbullet) { count++; if (shotdata->hits[i].distance > mostdist) { @@ -1041,49 +1051,58 @@ void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hi } if (count >= shotdata->penetration) { + // There are too many props for the bullet to penetrate all of them. + // Remove the furtherest from the hit list, as well as any glass + // which is be beyond the now-reduced shot distance. shotdata->hits[bestindex].prop = NULL; - shotdata->unk34 = prevmostdist; + shotdata->distance = prevmostdist; - if (shotdata->unk34 < arg2) { - shotdata->unk34 = arg2; + if (shotdata->distance < hitdistance) { + shotdata->distance = hitdistance; } for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { - if (shotdata->hits[i].prop && !shotdata->hits[i].unk4c && shotdata->hits[i].distance > prevmostdist) { + if (shotdata->hits[i].prop && !shotdata->hits[i].slowsbullet && shotdata->hits[i].distance > prevmostdist) { shotdata->hits[i].prop = NULL; } } - } else if (count + 1 == shotdata->penetration) { - if (shotdata->unk34 > arg2) { - shotdata->unk34 = arg2; + } else { + // If this hit will be stopping the bullet, adjust the shot distance. + if (count + 1 == shotdata->penetration) { + if (shotdata->distance > hitdistance) { + shotdata->distance = hitdistance; + } } } } - if (arg10) { + // If this prop must stop the bullet (eg. because it's bulletproof), + // remove any hits that are beyond it. + if (bulletproof) { for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { - if (shotdata->hits[i].prop && shotdata->hits[i].distance > arg2) { + if (shotdata->hits[i].prop && shotdata->hits[i].distance > hitdistance) { shotdata->hits[i].prop = NULL; } } - shotdata->unk34 = arg2; + shotdata->distance = hitdistance; } + // Record the new hit for (i = 0; i < ARRAYCOUNT(shotdata->hits); i++) { if (shotdata->hits[i].prop == NULL) { struct hit *hit = &shotdata->hits[i]; - hit->distance = arg2; + hit->distance = hitdistance; hit->prop = prop; hit->hitpart = hitpart; - hit->node = node; + hit->bboxnode = bboxnode; hit->hitthing = *hitthing; - hit->mtxindex = arg6; - hit->unk44 = arg7; + hit->mtxindex = mtxindex; + hit->dlnode = dlnode; hit->model = model; - hit->unk4c = arg9; - hit->unk4d = arg10; + hit->slowsbullet = slowsbullet; + hit->bulletproof = bulletproof; hit->pos.x = arg11->x; hit->pos.y = arg11->y; hit->pos.z = arg11->z; @@ -1202,13 +1221,13 @@ void handInflictMeleeDamage(s32 handnum, struct gset *gset, bool arg2) if (cdTestLos04(&playerprop->pos, playerprop->rooms, &prop->pos, cdtypes)) { if (isglass) { struct model *model = obj->model; - struct coord spd8; - struct coord spcc; + struct coord gunpos2d; + struct coord gundir2d; struct modelnode *node = NULL; - bgunCalculatePlayerShotSpread(&spd8, &spcc, handnum, true); + bgunCalculatePlayerShotSpread(&gunpos2d, &gundir2d, handnum, true); - if (modelTestForHit(model, &spd8, &spcc, &node) > 0) { + if (modelTestForHit(model, &gunpos2d, &gundir2d, &node) > 0) { f32 damage = gsetGetDamage(gset) * 2.5f; skipthething = true; bgunPlayGlassHitSound(&playerprop->pos, playerprop->rooms, -1); @@ -1218,21 +1237,21 @@ void handInflictMeleeDamage(s32 handnum, struct gset *gset, bool arg2) } else if (arg2) { chr->chrflags |= CHRCFLAG_AVOIDING; } else { - struct coord spb8; - struct coord vector; + struct coord gunpos2d; + struct coord gundir2d; struct modelnode *node = NULL; struct model *model = NULL; s32 side = -1; s32 hitpart = HITPART_TORSO; if (!chrIsAvoiding(chr)) { - bgunCalculatePlayerShotSpread(&spb8, &vector, handnum, true); + bgunCalculatePlayerShotSpread(&gunpos2d, &gundir2d, handnum, true); skipthething = true; - mtx4RotateVecInPlace(camGetProjectionMtxF(), &vector); + mtx4RotateVecInPlace(camGetProjectionMtxF(), &gundir2d); bgunPlayPropHitSound(gset, prop, -1); if (chr->model && chrGetShield(chr) > 0) { - chrCalculateShieldHit(chr, &playerprop->pos, &vector, &node, &hitpart, &model, &side); + chrCalculateShieldHit(chr, &playerprop->pos, &gundir2d, &node, &hitpart, &model, &side); } if (bmoveGetCrouchPos() == CROUCHPOS_DUCK) { @@ -1243,7 +1262,7 @@ void handInflictMeleeDamage(s32 handnum, struct gset *gset, bool arg2) hitpart = HITPART_TORSO; } - func0f0341dc(chr, gsetGetDamage(gset), &vector, gset, + func0f0341dc(chr, gsetGetDamage(gset), &gundir2d, gset, g_Vars.currentplayer->prop, hitpart, chr->prop, node, model, side, 0); } } @@ -1271,7 +1290,7 @@ void handTickAttack(s32 handnum) } if (doit) { - func0f061d54(handnum, 1, 2); + propFindAimingAt(handnum, true, FINDPROPCONTEXT_SHOOT); } g_Vars.currentplayer->hands[handnum].unk0d0f_02 = false; diff --git a/src/game/propobj.c b/src/game/propobj.c index 76d6ad75b..e4e4974fb 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -2689,7 +2689,7 @@ bool func0f06b610(struct defaultobj *obj, struct coord *arg1, struct coord *arg2 while (hitpart > 0) { if (func0f084594(model, spe4, arg5, arg6, &thing1, &mtxindex1, &node1)) { - mtx4TransformVec(&model->matrices[mtxindex1], &thing1.unk00, &spfc); + mtx4TransformVec(&model->matrices[mtxindex1], &thing1.pos, &spfc); sum2 = (spfc.f[0] - arg5->f[0]) * arg6->f[0] + (spfc.f[1] - arg5->f[1]) * arg6->f[1] @@ -2715,9 +2715,9 @@ bool func0f06b610(struct defaultobj *obj, struct coord *arg1, struct coord *arg2 g_EmbedNode = spe4; g_EmbedSide = thing1.unk28 / 2; - var8006993c[0] = thing1.unk00.x; - var8006993c[1] = thing1.unk00.y; - var8006993c[2] = thing1.unk00.z; + var8006993c[0] = thing1.pos.x; + var8006993c[1] = thing1.pos.y; + var8006993c[2] = thing1.pos.z; result = 1; } @@ -2741,13 +2741,13 @@ bool func0f06b610(struct defaultobj *obj, struct coord *arg1, struct coord *arg2 if (node && func0f084594(model, node, arg5, arg6, &thing2, &mtxindex2, &node2)) { if (hitpart <= 0 || - + model->matrices[mtxindex2].m[0][2] * thing2.unk00.f[0] - + model->matrices[mtxindex2].m[1][2] * thing2.unk00.f[1] - + model->matrices[mtxindex2].m[2][2] * thing2.unk00.f[2] + + model->matrices[mtxindex2].m[0][2] * thing2.pos.f[0] + + model->matrices[mtxindex2].m[1][2] * thing2.pos.f[1] + + model->matrices[mtxindex2].m[2][2] * thing2.pos.f[2] > - + model->matrices[mtxindex1].m[0][2] * thing1.unk00.f[0] - + model->matrices[mtxindex1].m[1][2] * thing1.unk00.f[1] - + model->matrices[mtxindex1].m[2][2] * thing1.unk00.f[2] + + model->matrices[mtxindex1].m[0][2] * thing1.pos.f[0] + + model->matrices[mtxindex1].m[1][2] * thing1.pos.f[1] + + model->matrices[mtxindex1].m[2][2] * thing1.pos.f[2] ) { hitpart = 1; @@ -2760,7 +2760,7 @@ bool func0f06b610(struct defaultobj *obj, struct coord *arg1, struct coord *arg2 } if (hitpart > 0) { - mtx4TransformVec(&model->matrices[mtxindex1], &thing1.unk00, &spfc); + mtx4TransformVec(&model->matrices[mtxindex1], &thing1.pos, &spfc); sum3 = (spfc.f[0] - arg5->f[0]) * arg6->f[0] + (spfc.f[1] - arg5->f[1]) * arg6->f[1] @@ -2798,9 +2798,9 @@ bool func0f06b610(struct defaultobj *obj, struct coord *arg1, struct coord *arg2 if (thing1.texturenum == 10000) { g_EmbedSide = thing1.unk28 / 2; - var8006993c[0] = thing1.unk00.x; - var8006993c[1] = thing1.unk00.y; - var8006993c[2] = thing1.unk00.z; + var8006993c[0] = thing1.pos.x; + var8006993c[1] = thing1.pos.y; + var8006993c[2] = thing1.pos.z; } } } @@ -2994,7 +2994,7 @@ bool func0f06c28c(struct chrdata *chr, struct coord *arg1, struct coord *arg2, s { f32 spec; struct prop *prop = chr->prop; - f32 spe4 = chr0f0278a4(chr); + f32 spe4 = chrGetHitRadius(chr); f32 x = (prop->pos.f[0] - arg1->f[0]); f32 y = (prop->pos.f[1] - arg1->f[1]); f32 z = (prop->pos.f[2] - arg1->f[2]); @@ -3021,7 +3021,7 @@ bool func0f06c28c(struct chrdata *chr, struct coord *arg1, struct coord *arg2, s while (hitpart > 0) { if (func0f084594(model, spcc, arg5, arg6, &sp7c, &sp78, &sp74)) { - mtx4TransformVec(&model->matrices[sp78], &sp7c.unk00, &spb8); + mtx4TransformVec(&model->matrices[sp78], &sp7c.pos, &spb8); spec = (spb8.f[0] - arg5->f[0]) * arg6->f[0] + (spb8.f[1] - arg5->f[1]) * arg6->f[1] @@ -3047,9 +3047,9 @@ bool func0f06c28c(struct chrdata *chr, struct coord *arg1, struct coord *arg2, s g_EmbedNode = spcc; g_EmbedSide = sp7c.unk28 / 2; - var8006993c[0] = sp7c.unk00.x; - var8006993c[1] = sp7c.unk00.y; - var8006993c[2] = sp7c.unk00.z; + var8006993c[0] = sp7c.pos.x; + var8006993c[1] = sp7c.pos.y; + var8006993c[2] = sp7c.pos.z; result = true; } @@ -3061,10 +3061,10 @@ bool func0f06c28c(struct chrdata *chr, struct coord *arg1, struct coord *arg2, s hitpart = modelTestForHit(model, arg5, arg6, &spcc); if (hitpart > 0 - && func0f06bea0(model, model->definition->rootnode, model->definition->rootnode, arg5, arg6, &sp7c.unk00, &spec, &spcc, &hitpart, &sp78, &sp74) + && func0f06bea0(model, model->definition->rootnode, model->definition->rootnode, arg5, arg6, &sp7c.pos, &spec, &spcc, &hitpart, &sp78, &sp74) && spec < *arg9) { *arg9 = spec; - mtx4TransformVec(camGetProjectionMtxF(), &sp7c.unk00, arg7); + mtx4TransformVec(camGetProjectionMtxF(), &sp7c.pos, arg7); mtx4RotateVec(camGetProjectionMtxF(), &sp7c.unk0c, arg8); if (arg8->x != 0.0f || arg8->y != 0.0f || arg8->z != 0.0f) { @@ -3270,9 +3270,9 @@ s32 func0f06cd00(struct defaultobj *obj, struct coord *pos, struct coord *arg2, if (bgRoomIsLoaded(spcc[i])) { if (bgTestHitInRoom(&prop->pos, &sp1c4, spcc[i], &hitthing)) { - hitthing.unk00.x *= scale; - hitthing.unk00.y *= scale; - hitthing.unk00.z *= scale; + hitthing.pos.x *= scale; + hitthing.pos.y *= scale; + hitthing.pos.z *= scale; var80069944 = hitthing.texturenum; @@ -3281,7 +3281,7 @@ s32 func0f06cd00(struct defaultobj *obj, struct coord *pos, struct coord *arg2, if (g_Textures[hitthing.texturenum].surfacetype == SURFACETYPE_DEEPWATER) { struct coord spa4 = {0, 0, 0}; s0 = false; - sparksCreate(prop->rooms[0], prop, &hitthing.unk00, &spa4, &hitthing.unk0c, SPARKTYPE_DEEPWATER); + sparksCreate(prop->rooms[0], prop, &hitthing.pos, &spa4, &hitthing.unk0c, SPARKTYPE_DEEPWATER); psCreate(0, prop, SFX_HIT_WATER, -1, -1, PSFLAG_0400, 0, PSTYPE_NONE, 0, -1.0f, 0, -1, -1.0f, -1.0f, -1.0f); obj->hidden |= OBJHFLAG_DELETING; } @@ -3294,28 +3294,28 @@ s32 func0f06cd00(struct defaultobj *obj, struct coord *pos, struct coord *arg2, if (cdExamLos09(&prop->pos, spa0, &sp1c4, CDTYPE_BG) == CDRESULT_COLLISION) { s0 = true; #if VERSION >= VERSION_PAL_FINAL - cdGetPos(&hitthing.unk00, 4258, "prop/propobj.c"); + cdGetPos(&hitthing.pos, 4258, "prop/propobj.c"); #elif VERSION >= VERSION_PAL_BETA - cdGetPos(&hitthing.unk00, 4258, "propobj.c"); + cdGetPos(&hitthing.pos, 4258, "propobj.c"); #elif VERSION >= VERSION_NTSC_1_0 - cdGetPos(&hitthing.unk00, 4257, "propobj.c"); + cdGetPos(&hitthing.pos, 4257, "propobj.c"); #else - cdGetPos(&hitthing.unk00, 4246, "propobj.c"); + cdGetPos(&hitthing.pos, 4246, "propobj.c"); #endif cdGetObstacleNormal(&hitthing.unk0c); } } if (s0 - && ((prop->pos.x <= sp1c4.x && hitthing.unk00.x <= sp1c4.x && prop->pos.x <= hitthing.unk00.x) || (sp1c4.x <= prop->pos.x && sp1c4.x <= hitthing.unk00.x && hitthing.unk00.x <= prop->pos.x)) - && ((prop->pos.y <= sp1c4.y && hitthing.unk00.y <= sp1c4.y && prop->pos.y <= hitthing.unk00.y) || (sp1c4.y <= prop->pos.y && sp1c4.y <= hitthing.unk00.y && hitthing.unk00.y <= prop->pos.y)) - && ((prop->pos.z <= sp1c4.z && hitthing.unk00.z <= sp1c4.z && prop->pos.z <= hitthing.unk00.z) || (sp1c4.z <= prop->pos.z && sp1c4.z <= hitthing.unk00.z && hitthing.unk00.z <= prop->pos.z)) - && (prop->pos.f[0] != hitthing.unk00.f[0] || prop->pos.f[1] != hitthing.unk00.f[1] || prop->pos.f[2] != hitthing.unk00.f[2])) { + && ((prop->pos.x <= sp1c4.x && hitthing.pos.x <= sp1c4.x && prop->pos.x <= hitthing.pos.x) || (sp1c4.x <= prop->pos.x && sp1c4.x <= hitthing.pos.x && hitthing.pos.x <= prop->pos.x)) + && ((prop->pos.y <= sp1c4.y && hitthing.pos.y <= sp1c4.y && prop->pos.y <= hitthing.pos.y) || (sp1c4.y <= prop->pos.y && sp1c4.y <= hitthing.pos.y && hitthing.pos.y <= prop->pos.y)) + && ((prop->pos.z <= sp1c4.z && hitthing.pos.z <= sp1c4.z && prop->pos.z <= hitthing.pos.z) || (sp1c4.z <= prop->pos.z && sp1c4.z <= hitthing.pos.z && hitthing.pos.z <= prop->pos.z)) + && (prop->pos.f[0] != hitthing.pos.f[0] || prop->pos.f[1] != hitthing.pos.f[1] || prop->pos.f[2] != hitthing.pos.f[2])) { cdresult = CDRESULT_COLLISION; - sp1c4.x = hitthing.unk00.x; - sp1c4.y = hitthing.unk00.y; - sp1c4.z = hitthing.unk00.z; + sp1c4.x = hitthing.pos.x; + sp1c4.y = hitthing.pos.y; + sp1c4.z = hitthing.pos.z; arg3->x = hitthing.unk0c.x; arg3->y = hitthing.unk0c.y; @@ -14102,7 +14102,7 @@ void objDeform(struct defaultobj *obj, s32 level) /** * Bounce an object, such as a hoverbot when it's destroyed. */ -void objBounce(struct defaultobj *obj, struct coord *arg1) +void objBounce(struct defaultobj *obj, struct coord *gundir2d) { struct coord dir; struct coord rot = {0, 0, 0}; @@ -14135,9 +14135,9 @@ void objBounce(struct defaultobj *obj, struct coord *arg1) projectile->flags |= PROJECTILEFLAG_AIRBORNE; - dir.x = arg1->x; - dir.y = arg1->y; - dir.z = arg1->z; + dir.x = gundir2d->x; + dir.y = gundir2d->y; + dir.z = gundir2d->z; mtx4RotateVecInPlace(camGetProjectionMtxF(), &dir); @@ -14740,8 +14740,8 @@ void objCheckDestroyed(struct defaultobj *obj, struct coord *pos, s32 playernum) obj->flags &= ~OBJFLAG_CHOPPER_INACTIVE; } else if (obj->type == OBJTYPE_HOVERCAR) { struct hovercarobj *hovercar = (struct hovercarobj *)obj; - struct coord sp40; - struct coord sp34; + struct coord gunpos2d; + struct coord gundir2d; if (obj->flags & OBJFLAG_HOVERCAR_ISHOVERBOT) { // Hoverbots bounce and spark when dead @@ -14749,8 +14749,8 @@ void objCheckDestroyed(struct defaultobj *obj, struct coord *pos, s32 playernum) hovercar->deadtimer60 = TICKS(250); hovercar->sparkstimer60 = TICKS(50); - bgunCalculatePlayerShotSpread(&sp40, &sp34, HAND_RIGHT, false); - objBounce(obj, &sp34); + bgunCalculatePlayerShotSpread(&gunpos2d, &gundir2d, HAND_RIGHT, false); + objBounce(obj, &gundir2d); } else if (obj->modelnum == MODEL_TAXICAB || obj->modelnum == MODEL_POLICECAR) { // Taxi and police car (limo) fall to the ground and retain collision objDeform(obj, 10); @@ -14888,7 +14888,7 @@ bool func0f084594(struct model *model, struct modelnode *node, struct coord *arg if (reset) { for (i = 0; i < 3; i++) { - hitthing->unk00.f[i] = spb8.f[i]; + hitthing->pos.f[i] = spb8.f[i]; } hitthing->unk0c.x = 0.0f; @@ -14917,13 +14917,13 @@ bool func0f084594(struct model *model, struct modelnode *node, struct coord *arg } else { for (i = 0; i < 3; i++) { if (maxindex != i) { - hitthing->unk00.f[i] = spb8.f[i] + sp7c.f[maxindex] * spac.f[i]; + hitthing->pos.f[i] = spb8.f[i] + sp7c.f[maxindex] * spac.f[i]; - if (hitthing->unk00.f[i] < min.f[i] || hitthing->unk00.f[i] > max.f[i]) { + if (hitthing->pos.f[i] < min.f[i] || hitthing->pos.f[i] > max.f[i]) { ok = false; } } else { - hitthing->unk00.f[i] = sp88.f[i]; + hitthing->pos.f[i] = sp88.f[i]; } } @@ -15570,20 +15570,20 @@ void func0f0859a0(struct prop *prop, struct shotdata *shotdata) } if (var8005efc0 > 0.0f) { - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node1); + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node1); while (hitpart > 0) { - if (func0f084594(model, node1, &shotdata->unk00, &shotdata->unk0c, &hitthing1, &spe4, &node2)) { + if (func0f084594(model, node1, &shotdata->gunpos2d, &shotdata->gundir2d, &hitthing1, &spe4, &node2)) { break; } - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node1); + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node1); } } else { do { - hitpart = modelTestForHit(model, &shotdata->unk00, &shotdata->unk0c, &node1); + hitpart = modelTestForHit(model, &shotdata->gunpos2d, &shotdata->gundir2d, &node1); - if (hitpart > 0 && func0f0849dc(model, node1, &shotdata->unk00, &shotdata->unk0c, &hitthing1, &spe4, &node2)) { + if (hitpart > 0 && func0f0849dc(model, node1, &shotdata->gunpos2d, &shotdata->gundir2d, &hitthing1, &spe4, &node2)) { break; } } while (hitpart > 0); @@ -15592,10 +15592,10 @@ void func0f0859a0(struct prop *prop, struct shotdata *shotdata) if (obj->flags3 & OBJFLAG3_HOVERBEDSHIELD) { node3 = modelGetPart(model->definition, MODELPART_0067); - if (node3 && func0f084594(model, node3, &shotdata->unk00, &shotdata->unk0c, &hitthing2, &sp90, &node4)) { + if (node3 && func0f084594(model, node3, &shotdata->gunpos2d, &shotdata->gundir2d, &hitthing2, &sp90, &node4)) { if (hitpart <= 0 || - model->matrices[sp90].m[0][2] * hitthing2.unk00.f[0] + model->matrices[sp90].m[1][2] * hitthing2.unk00.f[1] + model->matrices[sp90].m[2][2] * hitthing2.unk00.f[2] > - model->matrices[spe4].m[0][2] * hitthing1.unk00.f[0] + model->matrices[spe4].m[1][2] * hitthing1.unk00.f[1] + model->matrices[spe4].m[2][2] * hitthing1.unk00.f[2]) { + model->matrices[sp90].m[0][2] * hitthing2.pos.f[0] + model->matrices[sp90].m[1][2] * hitthing2.pos.f[1] + model->matrices[sp90].m[2][2] * hitthing2.pos.f[2] > + model->matrices[spe4].m[0][2] * hitthing1.pos.f[0] + model->matrices[spe4].m[1][2] * hitthing1.pos.f[1] + model->matrices[spe4].m[2][2] * hitthing1.pos.f[2]) { hitpart = HITPART_LFOOT; hitthing1 = hitthing2; node1 = node3; @@ -15607,10 +15607,10 @@ void func0f0859a0(struct prop *prop, struct shotdata *shotdata) } if (hitpart > 0) { - mtx4TransformVec(&model->matrices[spe4], &hitthing1.unk00, &spd8); + mtx4TransformVec(&model->matrices[spe4], &hitthing1.pos, &spd8); spd4 = -spd8.f[2]; - if (spd4 <= shotdata->unk34) { + if (spd4 <= shotdata->distance) { isnotglass = true; if ((obj->flags & OBJFLAG_INVINCIBLE) == 0) { @@ -15626,7 +15626,7 @@ void func0f0859a0(struct prop *prop, struct shotdata *shotdata) mtx4RotateVec(&model->matrices[spe4], &hitthing1.unk0c, &sp70); mtx4RotateVecInPlace(camGetProjectionMtxF(), &sp70); - func0f061fa8(shotdata, prop, spd4, hitpart, + hitCreate(shotdata, prop, spd4, hitpart, node1, &hitthing1, spe4, node2, model, isnotglass && shotdata->gset.weaponnum != WEAPON_FARSIGHT, (obj->flags2 & OBJFLAG2_BULLETPROOF) @@ -15637,7 +15637,7 @@ void func0f0859a0(struct prop *prop, struct shotdata *shotdata) } } -void func0f085e00(struct prop *prop, struct shotdata *shotdata) +void objTestHit(struct prop *prop, struct shotdata *shotdata) { f32 tmp; struct defaultobj *obj = prop->obj; @@ -15649,7 +15649,7 @@ void func0f085e00(struct prop *prop, struct shotdata *shotdata) && (obj->flags2 & OBJFLAG2_SHOOTTHROUGH) == 0) { tmp = -(model->matrices[0].m[3][2] + objGetRotatedLocalZMaxByMtx4(bbox, model->matrices)); - if (tmp <= shotdata->unk34) { + if (tmp <= shotdata->distance) { func0f0859a0(prop, shotdata); } } @@ -15663,7 +15663,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) u8 ismeleefunc = false; s32 i; bool explosiveshells = false; - bool spfc = hit->unk4c; + bool slowsbullet = hit->slowsbullet; struct weaponfunc *func = gsetGetWeaponFunction(&shotdata->gset); struct coord spec; f32 tmp; @@ -15689,17 +15689,17 @@ void objHit(struct shotdata *shotdata, struct hit *hit) obj = hit->prop->obj; - sp110.x = shotdata->unk00.x - hit->distance * shotdata->unk0c.x / shotdata->unk0c.z; - sp110.y = shotdata->unk00.y - hit->distance * shotdata->unk0c.y / shotdata->unk0c.z; - sp110.z = shotdata->unk00.z - hit->distance; + sp110.x = shotdata->gunpos2d.x - hit->distance * shotdata->gundir2d.x / shotdata->gundir2d.z; + sp110.y = shotdata->gunpos2d.y - hit->distance * shotdata->gundir2d.y / shotdata->gundir2d.z; + sp110.z = shotdata->gunpos2d.z - hit->distance; mtx4TransformVecInPlace(camGetProjectionMtxF(), &sp110); - if (!spfc && chrIsUsingPaintball(g_Vars.currentplayer->prop->chr)) { - spfc = true; + if (!slowsbullet && chrIsUsingPaintball(g_Vars.currentplayer->prop->chr)) { + slowsbullet = true; } - if (hit->unk4c) { + if (hit->slowsbullet) { bgunSetHitPos(&sp110); } @@ -15711,7 +15711,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) && shotdata->gset.weaponnum != WEAPON_FARSIGHT #endif ) { - // For some penetrating weapons, unset hits beyond the shot distance? + // For some penetrating weapons, unset hits beyond the shot distance spe4 = hit->prop; mtx4TransformVec(obj->model->matrices, &sp110, &spec); tmp = -spec.z; @@ -15722,7 +15722,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) } } - shotdata->unk34 = tmp; + shotdata->distance = tmp; } } @@ -15737,20 +15737,20 @@ void objHit(struct shotdata *shotdata, struct hit *hit) // Create shield hit if object is shielded if (hit->hitthing.texturenum == 10000) { - spdc[0] = hit->hitthing.unk00.x; - spdc[1] = hit->hitthing.unk00.y; - spdc[2] = hit->hitthing.unk00.z; + spdc[0] = hit->hitthing.pos.x; + spdc[1] = hit->hitthing.pos.y; + spdc[2] = hit->hitthing.pos.z; - shieldhitCreate(prop, (obj->flags3 & OBJFLAG3_SHOWSHIELD) ? 4.0f : 8.0f, hit->prop, hit->node, hit->model, hit->hitthing.unk28 / 2, spdc); + shieldhitCreate(prop, (obj->flags3 & OBJFLAG3_SHOWSHIELD) ? 4.0f : 8.0f, hit->prop, hit->bboxnode, hit->model, hit->hitthing.unk28 / 2, spdc); } // Increment object hit count - if (objIsHealthy(obj) && objIsMortal(obj) && hit->unk4c) { + if (objIsHealthy(obj) && objIsMortal(obj) && hit->slowsbullet) { mpstatsIncrementPlayerShotCount2(&shotdata->gset, SHOTREGION_OBJECT); } // Play hit sound - if (!spfc) { + if (!slowsbullet) { bgunPlayGlassHitSound(&hit->prop->pos, hit->prop->rooms, hit->hitthing.texturenum); } else if (!ismeleefunc) { bgunPlayPropHitSound(&shotdata->gset, hit->prop, hit->hitthing.texturenum); @@ -15763,7 +15763,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) && shotdata->gset.weaponnum != WEAPON_LASER && shotdata->gset.weaponnum != WEAPON_TRANQUILIZER && shotdata->gset.weaponnum != WEAPON_FARSIGHT) { - if (hit->unk4c == 0) { + if (!hit->slowsbullet) { struct prop *hitprop = hit->prop; s8 iswindoweddoor = obj->model->definition->skel == &g_SkelWindowedDoor ? true : false; @@ -15776,7 +15776,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) textureindex += 10; } - wallhitCreate(&hit->hitthing.unk00, &hit->hitthing.unk0c, &shotdata->gunpos, 0, + wallhitCreate(&hit->hitthing.pos, &hit->hitthing.unk0c, &shotdata->gunpos3d, 0, 0, textureindex, 1, hitprop, hit->mtxindex, iswindoweddoor, g_Vars.currentplayer->prop->chr, true); } else { s16 textureindex; @@ -15797,8 +15797,8 @@ void objHit(struct shotdata *shotdata, struct hit *hit) spc4 = false; spcc = random() % surfacetype->numwallhittexes; - if ((obj->model->definition->skel == &g_SkelWindowedDoor && hit->unk44 == modelGetPart(obj->model->definition, MODELPART_WINDOWEDDOOR_0003)) - || (obj->model->definition->skel == &g_SkelCctv && hit->unk44 == modelGetPart(obj->model->definition, MODELPART_CCTV_LENS))) { + if ((obj->model->definition->skel == &g_SkelWindowedDoor && hit->dlnode == modelGetPart(obj->model->definition, MODELPART_WINDOWEDDOOR_0003)) + || (obj->model->definition->skel == &g_SkelCctv && hit->dlnode == modelGetPart(obj->model->definition, MODELPART_CCTV_LENS))) { spcb = true; } @@ -15815,7 +15815,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) spc4 = true; } - wallhitCreate(&hit->hitthing.unk00, &hit->hitthing.unk0c, &shotdata->gunpos, 0, + wallhitCreate(&hit->hitthing.pos, &hit->hitthing.unk0c, &shotdata->gunpos3d, 0, 0, textureindex, 1, hit->prop, hit->mtxindex, spcb, g_Vars.currentplayer->prop->chr, spc4); } } @@ -15830,7 +15830,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) } else if (obj->type == OBJTYPE_CCTV) { // Leftover from GE: shots to a CCTV's lens is a one hit kill if (obj->model->definition->skel == &g_SkelCctv) { - if (modelGetPart(obj->model->definition, MODELPART_CCTV_LENS) == hit->unk44) { + if (modelGetPart(obj->model->definition, MODELPART_CCTV_LENS) == hit->dlnode) { damage *= 100.0f; cctvHandleLensShot(obj); } @@ -15847,7 +15847,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) objTakeGunfire(obj, damage, &sp110, shotdata->gset.weaponnum, g_Vars.currentplayernum); - if (obj->model->definition->skel == &g_SkelWindowedDoor && !hit->unk4c) { + if (obj->model->definition->skel == &g_SkelWindowedDoor && !hit->slowsbullet) { struct doorobj *door = (struct doorobj *)obj; door->glasshits++; @@ -15867,16 +15867,16 @@ void objHit(struct shotdata *shotdata, struct hit *hit) struct coord pushdir; Mtxf sp58; - spb0.x = shotdata->dir.x * 3.0f; - spb0.y = shotdata->dir.y * 3.0f; - spb0.z = shotdata->dir.z * 3.0f; + spb0.x = shotdata->gundir3d.x * 3.0f; + spb0.y = shotdata->gundir3d.y * 3.0f; + spb0.z = shotdata->gundir3d.z * 3.0f; mtx4MultMtx4(camGetProjectionMtxF(), &obj->model->matrices[hit->mtxindex], &sp58); - mtx4TransformVec(&sp58, &hit->hitthing.unk00, &spa4); + mtx4TransformVec(&sp58, &hit->hitthing.pos, &spa4); - pushdir.x = shotdata->dir.x; - pushdir.y = shotdata->dir.y; - pushdir.z = shotdata->dir.z; + pushdir.x = shotdata->gundir3d.x; + pushdir.y = shotdata->gundir3d.y; + pushdir.z = shotdata->gundir3d.z; func0f082e84(obj, &spa4, &pushdir, &spb0, true); } else { @@ -15901,7 +15901,7 @@ void objHit(struct shotdata *shotdata, struct hit *hit) } if (bounce) { - objBounce(obj, &shotdata->unk0c); + objBounce(obj, &shotdata->gundir2d); } } } diff --git a/src/game/splat.c b/src/game/splat.c index 15079869a..ce9c6bb96 100644 --- a/src/game/splat.c +++ b/src/game/splat.c @@ -162,13 +162,13 @@ s32 splatsCreate(s32 qty, f32 arg1, struct prop *prop, struct shotdata *shotdata s32 j; if (splattype == 0) { - dist = coordsGetDistance(&shotdata->gunpos, arg5); + dist = coordsGetDistance(&shotdata->gunpos3d, arg5); for (i = 0; i < 3; i++) { - spfc.f[i] = shotdata->dir.f[i]; - spf0.f[i] = shotdata->unk0c.f[i]; - shotdata->gunpos.f[i] = arg5->f[i]; - shotdata->unk00.f[i] = arg4->f[i]; + spfc.f[i] = shotdata->gundir3d.f[i]; + spf0.f[i] = shotdata->gundir2d.f[i]; + shotdata->gunpos3d.f[i] = arg5->f[i]; + shotdata->gunpos2d.f[i] = arg4->f[i]; } } else { f32 extraheight; @@ -181,21 +181,21 @@ s32 splatsCreate(s32 qty, f32 arg1, struct prop *prop, struct shotdata *shotdata dist = 0.7f; - spfc.x = shotdata->dir.x = 0; - spfc.y = shotdata->dir.y = -1; - spfc.z = shotdata->dir.z = 0; + spfc.x = shotdata->gundir3d.x = 0; + spfc.y = shotdata->gundir3d.y = -1; + spfc.z = shotdata->gundir3d.z = 0; - spf0.x = shotdata->unk0c.x = 0; - spf0.y = shotdata->unk0c.y = -1; - spf0.z = shotdata->unk0c.z = 0; + spf0.x = shotdata->gundir2d.x = 0; + spf0.y = shotdata->gundir2d.y = -1; + spf0.z = shotdata->gundir2d.z = 0; - shotdata->gunpos.x = prop->pos.x; - shotdata->gunpos.y = prop->pos.y + extraheight; - shotdata->gunpos.z = prop->pos.z; + shotdata->gunpos3d.x = prop->pos.x; + shotdata->gunpos3d.y = prop->pos.y + extraheight; + shotdata->gunpos3d.z = prop->pos.z; - shotdata->unk00.x = prop->pos.x; - shotdata->unk00.y = prop->pos.y + extraheight; - shotdata->unk00.z = prop->pos.z; + shotdata->gunpos2d.x = prop->pos.x; + shotdata->gunpos2d.y = prop->pos.y + extraheight; + shotdata->gunpos2d.z = prop->pos.z; } for (i = 0; i < qty; i++) { @@ -204,15 +204,15 @@ s32 splatsCreate(s32 qty, f32 arg1, struct prop *prop, struct shotdata *shotdata } mtx4LoadRotation(&spe4, &spa4); - mtx4RotateVec(&spa4, &spfc, &shotdata->dir); - mtx4RotateVec(&spa4, &spf0, &shotdata->unk0c); + mtx4RotateVec(&spa4, &spfc, &shotdata->gundir3d); + mtx4RotateVec(&spa4, &spf0, &shotdata->gundir2d); #if VERSION >= VERSION_NTSC_1_0 - func0f177164(&shotdata->dir, &shotdata->dir, 403, "splat.c"); - func0f177164(&shotdata->unk0c, &shotdata->unk0c, 404, "splat.c"); + func0f177164(&shotdata->gundir3d, &shotdata->gundir3d, 403, "splat.c"); + func0f177164(&shotdata->gundir2d, &shotdata->gundir2d, 404, "splat.c"); #else - func0f177164(&shotdata->dir, &shotdata->dir, 405, "splat.c"); - func0f177164(&shotdata->unk0c, &shotdata->unk0c, 406, "splat.c"); + func0f177164(&shotdata->gundir3d, &shotdata->gundir3d, 405, "splat.c"); + func0f177164(&shotdata->gundir2d, &shotdata->gundir2d, 406, "splat.c"); #endif if (splat0f149274(arg1, prop, shotdata, /*reused var*/ dist, isskedar, splattype, timermax, chr, timerspeed)) { @@ -262,33 +262,33 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 struct shotdata stackshotdata; for (i = 0; i < 3; i++) { - stackshotdata.unk00.f[i] = shotdata->unk00.f[i]; - stackshotdata.unk0c.f[i] = shotdata->unk0c.f[i]; - stackshotdata.gunpos.f[i] = shotdata->gunpos.f[i]; - stackshotdata.dir.f[i] = shotdata->dir.f[i]; + stackshotdata.gunpos2d.f[i] = shotdata->gunpos2d.f[i]; + stackshotdata.gundir2d.f[i] = shotdata->gundir2d.f[i]; + stackshotdata.gunpos3d.f[i] = shotdata->gunpos3d.f[i]; + stackshotdata.gundir3d.f[i] = shotdata->gundir3d.f[i]; } stackshotdata.penetration = 1; for (i = 0; i < 3; i++) { - endpos.f[i] = stackshotdata.gunpos.f[i] + stackshotdata.dir.f[i] * g_SplatMaxDistance; + endpos.f[i] = stackshotdata.gunpos3d.f[i] + stackshotdata.gundir3d.f[i] * g_SplatMaxDistance; } - portal00018148(&chrprop->pos, &stackshotdata.gunpos, chrprop->rooms, gunrooms, NULL, 0); - portal00018148(&stackshotdata.gunpos, &endpos, gunrooms, endrooms, rooms, ARRAYCOUNT(rooms) - 1); + portal00018148(&chrprop->pos, &stackshotdata.gunpos3d, chrprop->rooms, gunrooms, NULL, 0); + portal00018148(&stackshotdata.gunpos3d, &endpos, gunrooms, endrooms, rooms, ARRAYCOUNT(rooms) - 1); for (i = 0; rooms[i] != -1; i++) { - if (bgTestHitInRoom(&stackshotdata.gunpos, &endpos, rooms[i], &hitthing) - && ((stackshotdata.gunpos.x <= endpos.x && hitthing.unk00.x <= endpos.x && stackshotdata.gunpos.x <= hitthing.unk00.x) || (endpos.x <= stackshotdata.gunpos.x && endpos.x <= hitthing.unk00.x && hitthing.unk00.x <= stackshotdata.gunpos.x)) - && ((stackshotdata.gunpos.y <= endpos.y && hitthing.unk00.y <= endpos.y && stackshotdata.gunpos.y <= hitthing.unk00.y) || (endpos.y <= stackshotdata.gunpos.y && endpos.y <= hitthing.unk00.y && hitthing.unk00.y <= stackshotdata.gunpos.y)) - && ((stackshotdata.gunpos.z <= endpos.z && hitthing.unk00.z <= endpos.z && stackshotdata.gunpos.z <= hitthing.unk00.z) || (endpos.z <= stackshotdata.gunpos.z && endpos.z <= hitthing.unk00.z && hitthing.unk00.z <= stackshotdata.gunpos.z))) { - if (stackshotdata.gunpos.x != hitthing.unk00.x || stackshotdata.gunpos.y != hitthing.unk00.y || stackshotdata.gunpos.z != hitthing.unk00.z) { + if (bgTestHitInRoom(&stackshotdata.gunpos3d, &endpos, rooms[i], &hitthing) + && ((stackshotdata.gunpos3d.x <= endpos.x && hitthing.pos.x <= endpos.x && stackshotdata.gunpos3d.x <= hitthing.pos.x) || (endpos.x <= stackshotdata.gunpos3d.x && endpos.x <= hitthing.pos.x && hitthing.pos.x <= stackshotdata.gunpos3d.x)) + && ((stackshotdata.gunpos3d.y <= endpos.y && hitthing.pos.y <= endpos.y && stackshotdata.gunpos3d.y <= hitthing.pos.y) || (endpos.y <= stackshotdata.gunpos3d.y && endpos.y <= hitthing.pos.y && hitthing.pos.y <= stackshotdata.gunpos3d.y)) + && ((stackshotdata.gunpos3d.z <= endpos.z && hitthing.pos.z <= endpos.z && stackshotdata.gunpos3d.z <= hitthing.pos.z) || (endpos.z <= stackshotdata.gunpos3d.z && endpos.z <= hitthing.pos.z && hitthing.pos.z <= stackshotdata.gunpos3d.z))) { + if (stackshotdata.gunpos3d.x != hitthing.pos.x || stackshotdata.gunpos3d.y != hitthing.pos.y || stackshotdata.gunpos3d.z != hitthing.pos.z) { bestroom = rooms[i]; besthitthing = hitthing; - endpos.x = hitthing.unk00.x; - endpos.y = hitthing.unk00.y; - endpos.z = hitthing.unk00.z; + endpos.x = hitthing.pos.x; + endpos.y = hitthing.pos.y; + endpos.z = hitthing.pos.z; hasresult = true; break; @@ -297,11 +297,11 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 } if (hasresult) { - spraydistance = coordsGetDistance(&stackshotdata.gunpos, &besthitthing.unk00); + spraydistance = coordsGetDistance(&stackshotdata.gunpos3d, &besthitthing.pos); if (spraydistance < g_SplatMaxDistance) { - sp50c = &hitthing.unk00; - hitpos = &hitthing.unk00; + sp50c = &hitthing.pos; + hitpos = &hitthing.pos; sp504 = &hitthing.unk0c; objprop = NULL; mtxindex = 0; @@ -316,13 +316,13 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 } if (splattype == 0) { - stackshotdata.unk34 = (spraydistance < g_SplatMaxDistance ? spraydistance : g_SplatMaxDistance); - stackshotdata.unk34 += arg3; + stackshotdata.distance = (spraydistance < g_SplatMaxDistance ? spraydistance : g_SplatMaxDistance); + stackshotdata.distance += arg3; for (i = 0; i < ARRAYCOUNT(stackshotdata.hits); i++) { stackshotdata.hits[i].prop = NULL; stackshotdata.hits[i].hitpart = 0; - stackshotdata.hits[i].node = NULL; + stackshotdata.hits[i].bboxnode = NULL; } propptr = g_Vars.endonscreenprops - 1; @@ -332,7 +332,7 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 if (prop) { if (prop->type == PROPTYPE_OBJ || prop->type == PROPTYPE_DOOR || prop->type == PROPTYPE_WEAPON) { - func0f085e00(prop, &stackshotdata); + objTestHit(prop, &stackshotdata); if (1); } } @@ -346,7 +346,7 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 if (hit->prop && (hit->hitthing.texturenum < 0 || hit->hitthing.texturenum >= NUM_TEXTURES || g_SurfaceTypes[g_Textures[hit->hitthing.texturenum].surfacetype]->numwallhittexes != 0)) { - sp50c = &hit->hitthing.unk00; + sp50c = &hit->hitthing.pos; hitpos = &hit->pos; sp504 = &hit->hitthing.unk0c; objprop = hit->prop; @@ -366,7 +366,7 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 for (i = 0; i < 3; i++) { splatdata.relpos.f[i] = sp50c->f[i]; splatdata.unk0c.f[i] = hitpos->f[i]; - splatdata.gunpos.f[i] = stackshotdata.gunpos.f[i]; + splatdata.gunpos.f[i] = stackshotdata.gunpos3d.f[i]; splatdata.unk18.f[i] = sp504->f[i]; } @@ -387,9 +387,9 @@ bool splat0f149274(f32 arg0, struct prop *chrprop, struct shotdata *shotdata, f3 return true; } - if (hitthing.unk00.x); - if (hitthing.unk00.y); - if (hitthing.unk00.z); + if (hitthing.pos.x); + if (hitthing.pos.y); + if (hitthing.pos.z); return false; } diff --git a/src/include/constants.h b/src/include/constants.h index db19cbbcc..4333d8171 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -947,6 +947,9 @@ #define FILETYPE_MPPLAYER 2 #define FILETYPE_CAMERA 3 +#define FINDPROPCONTEXT_QUERY 0 +#define FINDPROPCONTEXT_SHOOT 2 + #define FLOORTYPE_DEFAULT 0 #define FLOORTYPE_WOOD 1 #define FLOORTYPE_STONE 2 diff --git a/src/include/game/camera.h b/src/include/game/camera.h index f8dd37acf..9047f5d50 100644 --- a/src/include/game/camera.h +++ b/src/include/game/camera.h @@ -9,7 +9,7 @@ void camSetScreenPosition(f32 left, f32 top); void camSetPerspective(f32 near, f32 fovy, f32 aspect); f32 cam0f0b49b8(f32 arg0); void camSetScale(void); -void cam0f0b4c3c(f32 *crosspos, struct coord *dst, f32 arg2); +void cam0f0b4c3c(f32 pos2d[2], struct coord *dir2d, f32 arg2); void cam0f0b4d04(struct coord *in, f32 *out); void cam0f0b4d68(struct coord *in, f32 out[2]); void cam0f0b4dec(struct coord *in, f32 out[2]); diff --git a/src/include/game/chr.h b/src/include/game/chr.h index 151da2705..0287d1b26 100644 --- a/src/include/game/chr.h +++ b/src/include/game/chr.h @@ -45,8 +45,8 @@ void chrEmitSparks(struct chrdata *chr, struct prop *prop, s32 hitpart, struct c void chr0f0260c4(struct model *model, s32 hitpart, struct modelnode *node, struct coord *arg3); void chrBruise(struct model *model, s32 hitpart, struct modelnode *node, struct coord *arg3); void chrDisfigure(struct chrdata *chr, struct coord *exppos, f32 damageradius); -f32 chr0f0278a4(struct chrdata *chr); -void chr0f027994(struct prop *prop, struct shotdata *shotdata, bool arg2, bool arg3); +f32 chrGetHitRadius(struct chrdata *chr); +void chrTestHit(struct prop *prop, struct shotdata *shotdata, bool isshooting, bool cheap); void chrHit(struct shotdata *shotdata, struct hit *hit); void chr0f028498(bool value); void chrsCheckForNoise(f32 noiseradius); diff --git a/src/include/game/prop.h b/src/include/game/prop.h index b26589518..2105cc061 100644 --- a/src/include/game/prop.h +++ b/src/include/game/prop.h @@ -24,10 +24,10 @@ Gfx *propRender(Gfx *gdl, struct prop *prop, bool xlupass); Gfx *propsRender(Gfx *gdl, RoomNum renderroomnum, s32 renderpass, RoomNum *roomnumsbyprop); void weaponPlayWhooshSound(s32 weaponnum, struct prop *prop); void func0f060bac(s32 weaponnum, struct prop *prop); -struct prop *shotCalculateHits(s32 handnum, bool arg1, struct coord *arg2, struct coord *arg3, struct coord *gunpos, struct coord *dir, u32 arg6, f32 arg7, bool arg8); -struct prop *func0f061d54(s32 handnum, u32 arg1, u32 arg2); -void shotCreate(s32 handnum, bool arg1, bool dorandom, s32 arg3, bool arg4); -void func0f061fa8(struct shotdata *shotdata, struct prop *prop, f32 arg2, s32 hitpart, struct modelnode *node, struct hitthing *hitthing, s32 arg6, struct modelnode *arg7, struct model *model, bool arg9, s32 arg10, struct coord *arg11, struct coord *arg12); +struct prop *shotCalculateHits(s32 handnum, bool isshooting, struct coord *gunpos2d, struct coord *gundir2d, struct coord *gunpos3d, struct coord *gundir3d, u32 arg6, f32 distance, bool arg8); +struct prop *propFindAimingAt(s32 handnum, bool isshooting, u32 context); +void shotCreate(s32 handnum, bool arg1, bool dorandom, s32 numshots, bool arg4); +void hitCreate(struct shotdata *shotdata, struct prop *prop, f32 hitdistance, s32 hitpart, struct modelnode *bboxnode, struct hitthing *hitthing, s32 arg6, struct modelnode *dlnode, struct model *model, bool slowsbullet, bool bulletproof, struct coord *arg11, struct coord *arg12); void handInflictMeleeDamage(s32 handnum, struct gset *gset, bool arg2); void handTickAttack(s32 handnum); void handsTickAttack(void); diff --git a/src/include/game/propobj.h b/src/include/game/propobj.h index 98752dd7a..9939e260b 100644 --- a/src/include/game/propobj.h +++ b/src/include/game/propobj.h @@ -211,7 +211,7 @@ Gfx *objRenderShadow(struct defaultobj *obj, Gfx *gdl); Gfx *objRender(struct prop *prop, Gfx *gdl, bool xlupass); bool modelIsNodeNotTvscreen(struct modeldef *modeldef, struct modelnode *node); void objDeform(struct defaultobj *obj, s32 level); -void objBounce(struct defaultobj *obj, struct coord *arg1); +void objBounce(struct defaultobj *obj, struct coord *gundir2d); void objSetDropped(struct prop *prop, u32 droptype); void objApplyMomentum(struct defaultobj *obj, struct coord *speed, f32 rotation, bool addspeed, bool addrotation); void piracyRestore(void); @@ -233,7 +233,7 @@ bool objIsMortal(struct defaultobj *obj); void objTakeGunfire(struct defaultobj *obj, f32 damage, struct coord *pos, s32 weaponnum, s32 playernum); void objDamage(struct defaultobj *obj, f32 damage, struct coord *pos, s32 weaponnum, s32 playernum); void func0f0859a0(struct prop *prop, struct shotdata *shotdata); -void func0f085e00(struct prop *prop, struct shotdata *shotdata); +void objTestHit(struct prop *prop, struct shotdata *shotdata); void objHit(struct shotdata *shotdata, struct hit *hit); u32 propobjGetCiTagId(struct prop *prop); bool objIsHealthy(struct defaultobj *obj); diff --git a/src/include/types.h b/src/include/types.h index fb3ee9ba0..714803bb3 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5662,7 +5662,7 @@ struct warpparams { }; struct hitthing { - struct coord unk00; + struct coord pos; // world pos struct coord unk0c; Vtx *unk18; Vtx *unk1c; @@ -5677,24 +5677,24 @@ struct hit { /*0x00*/ f32 distance; /*0x04*/ struct prop *prop; /*0x08*/ s32 hitpart; - /*0x0c*/ struct modelnode *node; + /*0x0c*/ struct modelnode *bboxnode; /*0x10*/ struct hitthing hitthing; /*0x40*/ s32 mtxindex; - /*0x44*/ struct modelnode *unk44; + /*0x44*/ struct modelnode *dlnode; /*0x48*/ struct model *model; - /*0x4c*/ s8 unk4c; - /*0x4d*/ s8 unk4d; + /*0x4c*/ s8 slowsbullet; + /*0x4d*/ s8 bulletproof; /*0x50*/ struct coord pos; /*0x5c*/ struct coord dir; }; struct shotdata { - /*0x00*/ struct coord unk00; - /*0x0c*/ struct coord unk0c; + /*0x00*/ struct coord gunpos2d; + /*0x0c*/ struct coord gundir2d; /*0x18*/ struct gset gset; - /*0x1c*/ struct coord gunpos; - /*0x28*/ struct coord dir; - /*0x34*/ f32 unk34; + /*0x1c*/ struct coord gunpos3d; + /*0x28*/ struct coord gundir3d; + /*0x34*/ f32 distance; /*0x38*/ s32 penetration; /*0x3c*/ struct hit hits[10]; }; From 4f56cd4c09b73542651516157bab60ec6042859c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 28 Aug 2023 22:18:05 +1000 Subject: [PATCH 4/6] Set names for symbols relating to the gfx C0 command --- src/game/tex.c | 689 ++++++++++++++++++++++------------------- src/game/texselect.c | 2 +- src/include/game/tex.h | 21 +- src/include/types.h | 22 -- 4 files changed, 368 insertions(+), 366 deletions(-) diff --git a/src/game/tex.c b/src/game/tex.c index 335d4cc03..49fd3782b 100644 --- a/src/game/tex.c +++ b/src/game/tex.c @@ -9,10 +9,36 @@ #include "textures.h" #include "types.h" +#define TXMODE_WRAP 0 +#define TXMODE_CLAMP 1 +#define TXMODE_MIRROR 2 + +struct tilestate { + bool inuse; + s32 format; + s32 depth; + s32 line; + s32 tmem; + s32 smode; + s32 tmode; + s32 masks; + s32 maskt; + s32 shifts; + s32 shiftt; +}; + +struct tilesize { + bool inuse; + s32 uls; + s32 ult; + s32 lrs; + s32 lrt; +}; + s32 g_TexLutMode; u32 var800ab5b4; -struct var800ab5b8 var800ab5b8[8]; -struct var800ab718 var800ab718[8]; +struct tilestate g_TexTileStates[8]; +struct tilesize g_TexTileSizes[8]; // Default u16 g_SurfaceTypeDefaultSounds[] = { SFX_HIT_STONE_8087, SFX_HIT_STONE_8088 }; @@ -23,91 +49,91 @@ struct surfacetype g_SurfaceTypeDefault = { }; // Stone -u16 var80084344[] = { SFX_HIT_STONE_8087, SFX_HIT_STONE_8088 }; -u8 var80084348[] = { WALLHITTEX_BULLET1 }; +u16 g_SurfaceTypeStoneSounds[] = { SFX_HIT_STONE_8087, SFX_HIT_STONE_8088 }; +u8 g_SurfaceTypeStoneTexes[] = { WALLHITTEX_BULLET1 }; struct surfacetype g_SurfaceTypeStone = { - var80084344, var80084348, 2, 1, + g_SurfaceTypeStoneSounds, g_SurfaceTypeStoneTexes, 2, 1, }; // Wood u16 g_SurfaceTypeWoodSounds[] = { SFX_HIT_WOOD_807E, SFX_HIT_WOOD_807F }; -u8 var8008435c[] = { WALLHITTEX_WOOD }; +u8 g_SurfaceTypeWoodTexes[] = { WALLHITTEX_WOOD }; struct surfacetype g_SurfaceTypeWood = { - g_SurfaceTypeWoodSounds, var8008435c, 2, 1, + g_SurfaceTypeWoodSounds, g_SurfaceTypeWoodTexes, 2, 1, }; // Metal u16 g_SurfaceTypeMetalSounds[] = { SFX_HIT_METAL_8079, SFX_HIT_METAL_807B }; -u8 var80084370[] = { WALLHITTEX_METAL }; +u8 g_SurfaceTypeMetalTexes[] = { WALLHITTEX_METAL }; struct surfacetype g_SurfaceTypeMetal = { - g_SurfaceTypeMetalSounds, var80084370, 2, 1, + g_SurfaceTypeMetalSounds, g_SurfaceTypeMetalTexes, 2, 1, }; // Glass u16 g_SurfaceTypeGlassSounds[] = { SFX_HIT_GLASS }; -u8 var80084384[] = { WALLHITTEX_GLASS1, WALLHITTEX_GLASS2, WALLHITTEX_GLASS3 }; +u8 g_SurfaceTypeGlassTexes[] = { WALLHITTEX_GLASS1, WALLHITTEX_GLASS2, WALLHITTEX_GLASS3 }; struct surfacetype g_SurfaceTypeGlass = { - g_SurfaceTypeGlassSounds, var80084384, 1, 3, + g_SurfaceTypeGlassSounds, g_SurfaceTypeGlassTexes, 1, 3, }; // Snow u16 g_SurfaceTypeSnowSounds[] = { SFX_HIT_SNOW }; -u8 var80084398[] = { WALLHITTEX_BULLET1 }; +u8 g_SurfaceTypeSnowTexes[] = { WALLHITTEX_BULLET1 }; struct surfacetype g_SurfaceTypeSnow = { - g_SurfaceTypeSnowSounds, var80084398, 1, 1, + g_SurfaceTypeSnowSounds, g_SurfaceTypeSnowTexes, 1, 1, }; // Dirt u16 g_SurfaceTypeDirtSounds[] = { SFX_HIT_DIRT_8084, SFX_HIT_DIRT_8085 }; -u8 var800843ac[] = { WALLHITTEX_SOFT }; +u8 g_SurfaceTypeDirtTexes[] = { WALLHITTEX_SOFT }; struct surfacetype g_SurfaceTypeDirt = { - g_SurfaceTypeDirtSounds, var800843ac, 2, 1, + g_SurfaceTypeDirtSounds, g_SurfaceTypeDirtTexes, 2, 1, }; // Mud u16 g_SurfaceTypeMudSounds[] = { SFX_HIT_MUD_8081, SFX_HIT_MUD_8082, SFX_HIT_MUD_8083 }; -u8 var800843c4[] = { WALLHITTEX_SOFT }; +u8 g_SurfaceTypeMudTexes[] = { WALLHITTEX_SOFT }; struct surfacetype g_SurfaceTypeMud = { - g_SurfaceTypeMudSounds, var800843c4, 3, 1, + g_SurfaceTypeMudSounds, g_SurfaceTypeMudTexes, 3, 1, }; // Tile u16 g_SurfaceTypeTileSounds[] = { SFX_HIT_TILE }; -u8 var800843d8[] = { WALLHITTEX_BULLET1 }; +u8 g_SurfaceTypeTileTexes[] = { WALLHITTEX_BULLET1 }; struct surfacetype g_SurfaceTypeTile = { - g_SurfaceTypeTileSounds, var800843d8, 1, 1, + g_SurfaceTypeTileSounds, g_SurfaceTypeTileTexes, 1, 1, }; // Metal obj u16 g_SurfaceTypeMetalObjSounds[] = { SFX_HIT_METALOBJ_8089, SFX_HIT_METALOBJ_808A }; -u8 var800843ec[] = { WALLHITTEX_BULLET1, WALLHITTEX_BULLET2 }; +u8 g_SurfaceTypeMetalObjTexes[] = { WALLHITTEX_BULLET1, WALLHITTEX_BULLET2 }; struct surfacetype g_SurfaceTypeMetalObj = { - g_SurfaceTypeMetalObjSounds, var800843ec, 2, 2, + g_SurfaceTypeMetalObjSounds, g_SurfaceTypeMetalObjTexes, 2, 2, }; // Chr u16 g_SurfaceTypeChrSounds[] = { SFX_HIT_CHR }; -u8 var80084400[] = { WALLHITTEX_SOFT }; +u8 g_SurfaceTypeChrTexes[] = { WALLHITTEX_SOFT }; struct surfacetype g_SurfaceTypeChr = { - g_SurfaceTypeChrSounds, var80084400, 1, 1, + g_SurfaceTypeChrSounds, g_SurfaceTypeChrTexes, 1, 1, }; // Glass XLU u16 g_SurfaceTypeGlassXluSounds[] = { SFX_HIT_GLASS }; -u8 var80084414[] = { WALLHITTEX_GLASS1, WALLHITTEX_GLASS2, WALLHITTEX_GLASS3 }; +u8 g_SurfaceTypeGlassXluTexes[] = { WALLHITTEX_GLASS1, WALLHITTEX_GLASS2, WALLHITTEX_GLASS3 }; struct surfacetype g_SurfaceTypeGlassXlu = { - g_SurfaceTypeGlassXluSounds, var80084414, 1, 3, + g_SurfaceTypeGlassXluSounds, g_SurfaceTypeGlassXluTexes, 1, 3, }; // None @@ -117,18 +143,18 @@ struct surfacetype g_SurfaceTypeNone = { // Shallow water u16 g_SurfaceTypeShallowWaterSounds[] = { SFX_HIT_WATER }; -u8 var80084434[] = { WALLHITTEX_WATER }; +u8 g_SurfaceTypeShallowWaterTexes[] = { WALLHITTEX_WATER }; struct surfacetype g_SurfaceTypeShallowWater = { - g_SurfaceTypeShallowWaterSounds, var80084434, 1, 1, + g_SurfaceTypeShallowWaterSounds, g_SurfaceTypeShallowWaterTexes, 1, 1, }; // Deep water u16 g_SurfaceTypeDeepWaterSounds[] = { SFX_HIT_WATER }; -u8 var80084448[] = { WALLHITTEX_WATER }; +u8 g_SurfaceTypeDeepWaterTexes[] = { WALLHITTEX_WATER }; struct surfacetype g_SurfaceTypeDeepWater = { - g_SurfaceTypeDeepWaterSounds, var80084448, 1, 1, + g_SurfaceTypeDeepWaterSounds, g_SurfaceTypeDeepWaterTexes, 1, 1, }; struct surfacetype *g_SurfaceTypes[] = { @@ -171,7 +197,7 @@ const char var7f1b7c24[] = ""; const char var7f1b7c28[] = ""; const char var7f1b7c2c[] = ""; -bool var800844d0 = false; +bool g_TexPipeSynced = false; u32 var800844d4 = 0x00000000; u32 var800844d8 = 0x00000000; u32 var800844dc = 0x00000000; @@ -185,19 +211,19 @@ void tex0f173a00(void) // empty } -void tex0f173a08(void) +void texResetTiles(void) { s32 i; - for (i = 0; i < 8; i++) { - var800ab5b8[i].unk00 = 0; - var800ab718[i].inuse = false; + for (i = 0; i < ARRAYCOUNT(g_TexTileStates); i++) { + g_TexTileStates[i].inuse = false; + g_TexTileSizes[i].inuse = false; } g_TexLutMode = -1; } -bool texSetLutMode(u32 lutmode) +bool texTrySetLutMode(u32 lutmode) { if (g_TexLutMode == lutmode) { return false; @@ -207,56 +233,56 @@ bool texSetLutMode(u32 lutmode) return true; } -bool tex0f173a70(s32 index, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, s32 arg8, s32 arg9, s32 arg10) +bool texTrySetTileState(s32 tile, s32 format, s32 depth, s32 line, s32 tmem, s32 smode, s32 tmode, s32 masks, s32 maskt, s32 shifts, s32 shiftt) { - bool result = false; + bool changed = false; - if (var800ab5b8[index].unk00 == 0 - || arg1 != var800ab5b8[index].unk04 - || arg2 != var800ab5b8[index].unk08 - || arg3 != var800ab5b8[index].unk0c - || arg4 != var800ab5b8[index].unk10 - || arg5 != var800ab5b8[index].unk14 - || arg6 != var800ab5b8[index].unk18 - || arg7 != var800ab5b8[index].unk1c - || arg8 != var800ab5b8[index].unk20 - || arg9 != var800ab5b8[index].unk24 - || arg10 != var800ab5b8[index].unk28) { - result = true; - var800ab5b8[index].unk00 = 1; - var800ab5b8[index].unk04 = arg1; - var800ab5b8[index].unk08 = arg2; - var800ab5b8[index].unk0c = arg3; - var800ab5b8[index].unk10 = arg4; - var800ab5b8[index].unk14 = arg5; - var800ab5b8[index].unk18 = arg6; - var800ab5b8[index].unk1c = arg7; - var800ab5b8[index].unk20 = arg8; - var800ab5b8[index].unk24 = arg9; - var800ab5b8[index].unk28 = arg10; + if (g_TexTileStates[tile].inuse == false + || format != g_TexTileStates[tile].format + || depth != g_TexTileStates[tile].depth + || line != g_TexTileStates[tile].line + || tmem != g_TexTileStates[tile].tmem + || smode != g_TexTileStates[tile].smode + || tmode != g_TexTileStates[tile].tmode + || masks != g_TexTileStates[tile].masks + || maskt != g_TexTileStates[tile].maskt + || shifts != g_TexTileStates[tile].shifts + || shiftt != g_TexTileStates[tile].shiftt) { + changed = true; + g_TexTileStates[tile].inuse = true; + g_TexTileStates[tile].format = format; + g_TexTileStates[tile].depth = depth; + g_TexTileStates[tile].line = line; + g_TexTileStates[tile].tmem = tmem; + g_TexTileStates[tile].smode = smode; + g_TexTileStates[tile].tmode = tmode; + g_TexTileStates[tile].masks = masks; + g_TexTileStates[tile].maskt = maskt; + g_TexTileStates[tile].shifts = shifts; + g_TexTileStates[tile].shiftt = shiftt; } - return result; + return changed; } -bool tex0f173b8c(s32 index, s32 uls, s32 ult, s32 lrs, s32 lrt) +bool texTrySetTileSize(s32 tile, s32 uls, s32 ult, s32 lrs, s32 lrt) { - bool result = false; + bool changed = false; - if (var800ab718[index].inuse == false - || uls != var800ab718[index].uls - || ult != var800ab718[index].ult - || lrs != var800ab718[index].lrs - || lrt != var800ab718[index].lrt) { - result = true; - var800ab718[index].inuse = true; - var800ab718[index].uls = uls; - var800ab718[index].ult = ult; - var800ab718[index].lrs = lrs; - var800ab718[index].lrt = lrt; + if (g_TexTileSizes[tile].inuse == false + || uls != g_TexTileSizes[tile].uls + || ult != g_TexTileSizes[tile].ult + || lrs != g_TexTileSizes[tile].lrs + || lrt != g_TexTileSizes[tile].lrt) { + changed = true; + g_TexTileSizes[tile].inuse = true; + g_TexTileSizes[tile].uls = uls; + g_TexTileSizes[tile].ult = ult; + g_TexTileSizes[tile].lrs = lrs; + g_TexTileSizes[tile].lrt = lrt; } - return result; + return changed; } s32 texGetWidthAtLod(struct tex *tex, s32 lod) @@ -336,7 +362,7 @@ s32 texGetSizeInBytes(struct tex *tex, s32 lod) return texGetHeightAtLod(tex, lod) * texGetLineSizeInBytes(tex, lod); } -void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg) +void texGetDepthAndSize(struct tex *tex, s32 *deptharg, s32 *lenarg) { s32 depth = tex->depth; s32 numlods = tex->numlods ? tex->numlods : 1; @@ -359,38 +385,38 @@ void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg) } } -s32 tex0f173f18(s32 arg0) +s32 texDimensionToMask(s32 dimension) { s32 i = 0; - arg0--; + dimension--; - while (arg0 > 0 && i < 8) { - arg0 >>= 1; + while (dimension > 0 && i < 8) { + dimension >>= 1; i++; } return i; } -s32 tex0f173f48(s32 arg0) +s32 texModeToGbiMode(s32 txmode) { - if (arg0 == 1) { - return 2; + if (txmode == TXMODE_CLAMP) { + return G_TX_CLAMP; } - if (arg0 == 2) { - return 1; + if (txmode == TXMODE_MIRROR) { + return G_TX_MIRROR; } - return 0; + return G_TX_WRAP; } -Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s32 arg5) +Gfx *texWriteTileFromDefinition(Gfx *gdl, struct tex *tex, s32 offset, s32 shifts, s32 shiftt, s32 min) { struct texture *s0 = &g_Textures[tex->texturenum]; - s32 sp88; - s32 sp84; + s32 masks; + s32 maskt; s32 line; u32 stack[4]; s32 uls; @@ -398,80 +424,90 @@ Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s3 s32 lrs; s32 lrt; - sp88 = tex0f173f18(tex->width); - sp84 = tex0f173f18(tex->height); + masks = texDimensionToMask(tex->width); + maskt = texDimensionToMask(tex->height); line = texGetLineSizeInBytes(tex, 0); - gDPSetPrimColorViaWord(gdl++, arg5, 0, 0xffffffff); + gDPSetPrimColorViaWord(gdl++, min, 0, 0xffffffff); - if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { + if (texTrySetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); } - if (tex0f173a70(0, tex->gbiformat, tex->depth, line, s0->unk04_00 + line * s0->unk04_04, 0, 0, sp88 - s0->unk04_08, sp84 - s0->unk04_0c, shifts, shiftt)) { + if (texTrySetTileState(0, tex->gbiformat, tex->depth, line, s0->unk04_00 + line * s0->unk04_04, 0, 0, masks - s0->unk04_08, maskt - s0->unk04_0c, shifts, shiftt)) { gDPSetTile(gdl++, tex->gbiformat, tex->depth, line, s0->unk04_00 + line * s0->unk04_04, 0, 0, - tex0f173f48(0), sp84 - s0->unk04_0c, shiftt, - tex0f173f48(0), sp88 - s0->unk04_08, shifts); + texModeToGbiMode(TXMODE_WRAP), maskt - s0->unk04_0c, shiftt, + texModeToGbiMode(TXMODE_WRAP), masks - s0->unk04_08, shifts); } - uls = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0; - ult = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0; - lrs = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->width - 1) << 2); - lrt = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->height - 1) << 2); + uls = (offset == 2 && !tex->hasloddata ? 2 : 0) + 0; + ult = (offset == 2 && !tex->hasloddata ? 2 : 0) + 0; + lrs = (offset == 2 && !tex->hasloddata ? 2 : 0) + ((tex->width - 1) << 2); + lrt = (offset == 2 && !tex->hasloddata ? 2 : 0) + ((tex->height - 1) << 2); - if (tex0f173b8c(0, uls, ult, lrs, lrt)) { + if (texTrySetTileSize(0, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, 0, uls, ult, lrs, lrt); } return gdl; } -Gfx *tex0f1742e4(Gfx *arg0, Gfx *arg1, struct tex *tex, bool arg3) +/** + * Write a gSPTexture command with the lowest detail LOD number. + * + * If texcmd is provided then it will be used as a reference, otherwise a new + * command is written with some assumed arguments. + * + * If append is true then the command will be appended to the given gdl, + * otherwise the existing texcmd will be patched in place. + */ +Gfx *texWriteTextureCmd(Gfx *gdl, Gfx *texcmd, struct tex *tex, bool append) { s32 lod = tex->numlods ? tex->numlods - 1 : 0; - if (arg3) { - if (arg1 != NULL) { - u32 v0 = (arg1->words.w0 & ~0x3800) | (lod << 11); + if (append) { + if (texcmd != NULL) { + // Copy the gSPTexture command, but with the new lod + u32 w0 = (texcmd->words.w0 & ~0x3800) | (lod << 11); - if (v0 != arg1->words.w0) { - arg0->words.w0 = v0; - arg0->words.w1 = arg1->words.w1; - arg0++; + if (w0 != texcmd->words.w0) { + gdl->words.w0 = w0; + gdl->words.w1 = texcmd->words.w1; + gdl++; } } else { - gSPTexture(arg0++, 0xffff, 0xffff, lod, G_TX_RENDERTILE, G_ON); + gSPTexture(gdl++, 0xffff, 0xffff, lod, G_TX_RENDERTILE, G_ON); } } else { - arg1->words.w0 &= ~0x3800; - arg1->words.w0 |= lod << 11; + texcmd->words.w0 &= ~0x3800; + texcmd->words.w0 |= lod << 11; } - return arg0; + return gdl; } -Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2) +Gfx *texWriteLoadToTmemAddr(Gfx *gdl, struct tex *tex, s32 tmemoffset) { s32 depth; s32 len; - tex0f173e50(tex, &depth, &len); + texGetDepthAndSize(tex, &depth, &len); if (tex->lutmodeindex == 0) { gDPSetTextureImage(gdl++, tex->gbiformat, depth, 1, tex->data); - if (!var800844d0) { + if (!g_TexPipeSynced) { gDPPipeSync(gdl++); - var800844d0 = true; + g_TexPipeSynced = true; } - if (depth == G_IM_SIZ_16b && arg2 == 0) { + if (depth == G_IM_SIZ_16b && tmemoffset == 0) { gDPLoadSync(gdl++); gDPLoadBlock(gdl++, G_TX_LOADTILE, 0, 0, len - 1, 0); } else { - if (tex0f173a70(5, 0, depth, 0, arg2, 0, 0, 0, 0, 0, 0)) { - gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, arg2, 5, 0, + if (texTrySetTileState(5, 0, depth, 0, tmemoffset, 0, 0, 0, 0, 0, 0)) { + gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, tmemoffset, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); } @@ -482,17 +518,17 @@ Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2) } else { gDPSetTextureImage(gdl++, tex->gbiformat, depth, 1, tex->data); - if (!var800844d0) { + if (!g_TexPipeSynced) { gDPPipeSync(gdl++); - var800844d0 = true; + g_TexPipeSynced = true; } - if (depth == G_IM_SIZ_16b && arg2 == 0) { + if (depth == G_IM_SIZ_16b && tmemoffset == 0) { gDPLoadSync(gdl++); gDPLoadBlock(gdl++, G_TX_LOADTILE, 0, 0, len - 1, 0); } else { - if (tex0f173a70(5, 0, depth, 0, arg2, 0, 0, 0, 0, 0, 0)) { - gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, arg2, 5, 0, + if (texTrySetTileState(5, 0, depth, 0, tmemoffset, 0, 0, 0, 0, 0, 0)) { + gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, tmemoffset, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); } @@ -515,24 +551,24 @@ Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2) return gdl; } -Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, u32 arg7) +Gfx *texWriteTileLods(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset, s32 starttile, s32 numlodsarg, u32 tmemoffsetarg) { - u32 tmem; + u32 tmemoffset; s32 numlods; s32 tile; - tmem = arg7; + tmemoffset = tmemoffsetarg; numlods = tex->numlods; - if (arg6 >= 0 && arg6 < numlods) { - numlods = arg6; + if (numlodsarg >= 0 && numlodsarg < numlods) { + numlods = numlodsarg; } - for (tile = arg5; tile < numlods + arg5 && tile < 6; tile++) { + for (tile = starttile; tile < numlods + starttile && tile < 6; tile++) { s32 stack[2]; - s32 lod = tile - arg5; - u32 masks = tex0f173f18(texGetWidthAtLod(tex, lod)); - u32 maskt = tex0f173f18(texGetHeightAtLod(tex, lod)); + s32 lod = tile - starttile; + s32 masks = texDimensionToMask(texGetWidthAtLod(tex, lod)); + s32 maskt = texDimensionToMask(texGetHeightAtLod(tex, lod)); s32 line = texGetLineSizeInBytes(tex, lod); s32 uls; s32 ult; @@ -541,51 +577,51 @@ Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar s32 bytes = texGetSizeInBytes(tex, lod); bool hasloddata = tex->hasloddata; - if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { + if (texTrySetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); } - if (tex0f173a70(tile, tex->gbiformat, tex->depth, line, tmem, arg2, arg3, masks, maskt, lod, lod)) { - gDPSetTile(gdl++, tex->gbiformat, tex->depth, line, tmem, tile, 0, - tex0f173f48(arg3), maskt, lod, - tex0f173f48(arg2), masks, tile - arg5); + if (texTrySetTileState(tile, tex->gbiformat, tex->depth, line, tmemoffset, smode, tmode, masks, maskt, lod, lod)) { + gDPSetTile(gdl++, tex->gbiformat, tex->depth, line, tmemoffset, tile, 0, + texModeToGbiMode(tmode), maskt, lod, + texModeToGbiMode(smode), masks, tile - starttile); } - uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; - ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; - lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0); - lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0); + uls = (offset == 2 && hasloddata == false ? 2 : 0) + 0; + ult = (offset == 2 && hasloddata == false ? 2 : 0) + 0; + lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (offset == 2 && hasloddata == false ? 2 : 0); + lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (offset == 2 && hasloddata == false ? 2 : 0); - if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { + if (texTrySetTileSize(tile, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); } - tmem += bytes; + tmemoffset += bytes; } return gdl; } -Gfx *tex0f174b54(Gfx *gdl, struct tex *tex) +Gfx *texWriteLoadToTmemZero(Gfx *gdl, struct tex *tex) { s32 depth; s32 len; - tex0f173e50(tex, &depth, &len); + texGetDepthAndSize(tex, &depth, &len); if (tex->lutmodeindex == 0) { gDPSetTextureImage(gdl++, tex->gbiformat, depth, 1, tex->data); - if (!var800844d0) { + if (!g_TexPipeSynced) { gDPPipeSync(gdl++); - var800844d0 = true; + g_TexPipeSynced = true; } if (depth == G_IM_SIZ_16b) { gDPLoadSync(gdl++); gDPLoadBlock(gdl++, G_TX_LOADTILE, 0, 0, len - 1, 0); } else { - if (tex0f173a70(5, 0, depth, 0, 0, 0, 0, 0, 0, 0, 0)) { + if (texTrySetTileState(5, 0, depth, 0, 0, 0, 0, 0, 0, 0, 0)) { gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, 0x0000, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); } @@ -595,16 +631,16 @@ Gfx *tex0f174b54(Gfx *gdl, struct tex *tex) } else { gDPSetTextureImage(gdl++, tex->gbiformat, depth, 1, tex->data); - if (!var800844d0) { + if (!g_TexPipeSynced) { gDPPipeSync(gdl++); - var800844d0 = true; + g_TexPipeSynced = true; } if (depth == G_IM_SIZ_16b) { gDPLoadSync(gdl++); gDPLoadBlock(gdl++, G_TX_LOADTILE, 0, 0, len - 1, 0); } else { - if (tex0f173a70(5, 0, depth, 0, 0, 0, 0, 0, 0, 0, 0)) { + if (texTrySetTileState(5, 0, depth, 0, 0, 0, 0, 0, 0, 0, 0)) { gDPSetTile(gdl++, G_IM_FMT_RGBA, depth, 0, 0x0000, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); } @@ -626,7 +662,7 @@ Gfx *tex0f174b54(Gfx *gdl, struct tex *tex) return gdl; } -Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 tile) +Gfx *texWriteTile(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset, s32 tile) { s32 masks; s32 maskt; @@ -637,165 +673,171 @@ Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ti s32 lrt; bool hasloddata; - masks = tex0f173f18(tex->width); - maskt = tex0f173f18(tex->height); + masks = texDimensionToMask(tex->width); + maskt = texDimensionToMask(tex->height); line = texGetLineSizeInBytes(tex, 0); hasloddata = tex->hasloddata; - if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { + if (texTrySetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); } - if (tex0f173a70(tile, tex->gbiformat, tex->depth, line, 0, arg2, arg3, masks, maskt, 0, 0)) { + if (texTrySetTileState(tile, tex->gbiformat, tex->depth, line, 0, smode, tmode, masks, maskt, 0, 0)) { gDPSetTile(gdl++, tex->gbiformat, tex->depth, line, 0x0000, tile, 0, - tex0f173f48(arg3), maskt, G_TX_NOLOD, - tex0f173f48(arg2), masks, G_TX_NOLOD); + texModeToGbiMode(tmode), maskt, G_TX_NOLOD, + texModeToGbiMode(smode), masks, G_TX_NOLOD); } - uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; - ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0; - lrs = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->width - 1) << 2); - lrt = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->height - 1) << 2); + uls = (offset == 2 && hasloddata == false ? 2 : 0) + 0; + ult = (offset == 2 && hasloddata == false ? 2 : 0) + 0; + lrs = (offset == 2 && hasloddata == false ? 2 : 0) + ((tex->width - 1) << 2); + lrt = (offset == 2 && hasloddata == false ? 2 : 0) + ((tex->height - 1) << 2); - if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { + if (texTrySetTileSize(tile, uls, ult, lrs, lrt)) { gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); } return gdl; } -Gfx *tex0f1751e4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5) +Gfx *texHandleType2(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset, bool flag) { - s32 sp34 = 0; + s32 tile = 0; - gdl = tex0f1743a0(gdl, tex, 0); + gdl = texWriteLoadToTmemAddr(gdl, tex, 0); - if (arg5) { - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, 0, 1, 0); - sp34++; + if (flag) { + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, 1, 0); + tile++; } - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, -1, 0); + tile += tex->numlods; - sp34 += tex->numlods; - - if (!arg5 && tex->numlods == 1) { - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); + if (!flag && tex->numlods == 1) { + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, -1, 0); + tile += tex->numlods; } gDPPipeSync(gdl++); - - var800844d0 = true; + g_TexPipeSynced = true; return gdl; } -Gfx *tex0f175308(Gfx *gdl, struct tex *tex1, s32 arg2, s32 arg3, s32 arg4, struct tex *tex2, s32 arg6, s32 arg7, s32 arg8, bool arg9) +Gfx *texHandleType1(Gfx *gdl, struct tex *tex1, s32 smode, s32 tmode, s32 offset, struct tex *tex2, s32 shifts, s32 shiftt, s32 min, bool flag) { s32 size = texGetSizeInBytes(tex2, 0); - s32 sp38 = 0; - - gdl = tex0f174b54(gdl, tex2); + s32 tile = 0; + gdl = texWriteLoadToTmemZero(gdl, tex2); gDPTileSync(gdl++); + gdl = texWriteLoadToTmemAddr(gdl, tex1, size); - gdl = tex0f1743a0(gdl, tex1, size); - gdl = tex0f173f78(gdl, tex2, arg4, arg6, arg7, arg8); + gdl = texWriteTileFromDefinition(gdl, tex2, offset, shifts, shiftt, min); + tile++; - sp38++; - - if (arg9) { - gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, 1, size); - sp38++; + if (flag) { + gdl = texWriteTileLods(gdl, tex1, smode, tmode, offset, tile, 1, size); + tile++; } - gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); + gdl = texWriteTileLods(gdl, tex1, smode, tmode, offset, tile, -1, size); + tile += tex1->numlods; - sp38 += tex1->numlods; - - if (!arg9 && tex1->numlods == 1) { - gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); + if (!flag && tex1->numlods == 1) { + gdl = texWriteTileLods(gdl, tex1, smode, tmode, offset, tile, -1, size); + tile += tex1->numlods; } gDPPipeSync(gdl++); - - var800844d0 = true; + g_TexPipeSynced = true; return gdl; } -Gfx *tex0f175490(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, bool arg8) +Gfx *texHandleType0(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset, s32 shifts, s32 shiftt, s32 min, bool flag) { - s32 sp34 = 0; + s32 tile = 0; - gdl = tex0f1743a0(gdl, tex, 0); - gdl = tex0f173f78(gdl, tex, arg4, arg5, arg6, arg7); + gdl = texWriteLoadToTmemAddr(gdl, tex, 0); - sp34++; + gdl = texWriteTileFromDefinition(gdl, tex, offset, shifts, shiftt, min); + tile++; - if (arg8) { - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, 1, 0); - sp34++; + if (flag) { + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, 1, 0); + tile++; } - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, -1, 0); + tile += tex->numlods; - sp34 += tex->numlods; - - if (!arg8 && tex->numlods == 1) { - gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); + if (!flag && tex->numlods == 1) { + gdl = texWriteTileLods(gdl, tex, smode, tmode, offset, tile, -1, 0); + tile += tex->numlods; } gDPPipeSync(gdl++); - - var800844d0 = true; + g_TexPipeSynced = true; return gdl; } -Gfx *tex0f1755dc(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4) +Gfx *texHandleType4(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset) { - gdl = tex0f174b54(gdl, tex); - gdl = tex0f174f30(gdl, tex, arg2, arg3, arg4, 0); + gdl = texWriteLoadToTmemZero(gdl, tex); + gdl = texWriteTile(gdl, tex, smode, tmode, offset, 0); + + gDPPipeSync(gdl++); + g_TexPipeSynced = true; + + return gdl; +} + +Gfx *texHandleType3(Gfx *gdl, struct tex *tex, s32 smode, s32 tmode, s32 offset) +{ + gdl = texWriteLoadToTmemZero(gdl, tex); + gdl = texWriteTile(gdl, tex, smode, tmode, offset, 0); + gdl = texWriteTile(gdl, tex, smode, tmode, offset, 1); gDPPipeSync(gdl++); - var800844d0 = true; + g_TexPipeSynced = true; return gdl; } -Gfx *tex0f17563c(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4) -{ - gdl = tex0f174b54(gdl, tex); - gdl = tex0f174f30(gdl, tex, arg2, arg3, arg4, 0); - gdl = tex0f174f30(gdl, tex, arg2, arg3, arg4, 1); - - gDPPipeSync(gdl++); - - var800844d0 = true; - - return gdl; -} - -s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *pool, u8 *arg4) +/** + * Read the instart displaylist and write the same displaylist to outstart, + * but substitute the special C0 commands with ones that the RSP will understand, + * and load textures from the ROM as they are found in the displaylist. + * + * The C0 command only exists in asset files. It has no implementation in the RSP. + * The command packs together several texture-related commands. It's likely done + * for ease of development, as it allows asset designers to spam its use everywhere + * in the displaylist rather than have to keep track of the RSP state. + * The code that expands the C0 commands keeps track of RSP state and avoids + * emitting duplicate or redundant commands. + */ +s32 texLoadFromGdl(Gfx *instart, s32 gdlsizeinbytes, Gfx *outstart, struct texpool *pool, u8 *vtxstart) { struct tex *tex1; struct tex *tex2; - Gfx *sp12c; - s32 sp128; - u32 tmp1; - u32 tmp2; - u32 tmp3; - u32 tmp4; - u32 tmp5; - u32 tmp6; + Gfx *texcmd; + s32 numcmdsremaining; + s32 smode; + s32 tmode; + s32 offset; + s32 shifts; + s32 shiftt; + s32 min; bool flag; s32 j; - bool sp104; + bool appendtex; u8 animated; - Gfx *s5; - Gfx *s6; + Gfx *ingdl; + Gfx *outgdl; u32 spf4; s32 texturenum; s32 texturenum2; @@ -804,27 +846,26 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo s32 spe0; Vtx *spa0[16]; u8 sp90[16]; - s32 i; - sp12c = NULL; - sp104 = true; + texcmd = NULL; + appendtex = true; animated = false; spe8 = false; spe4 = false; - var800844d0 = false; + g_TexPipeSynced = false; spf4 = 0; - s5 = arg0; - s6 = arg2; + ingdl = instart; + outgdl = outstart; - sp128 = gdlsizeinbytes >> 3; + numcmdsremaining = gdlsizeinbytes >> 3; - tex0f173a08(); + texResetTiles(); spe0 = dyntexHasRoom(); if (spe0) { - for (j = 0; j < 16; j++) { + for (j = 0; j < ARRAYCOUNT(sp90); j++) { sp90[j] = 0; } } @@ -833,17 +874,17 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo pool = &g_TexSharedPool; } - while (sp128 > 0) { - switch (s5->texture.cmd) { - case 0xc0: // Repurposed? + while (numcmdsremaining > 0) { + switch (ingdl->texture.cmd) { + case G_NOOP: // 0xc0, repurposed spe4 = true; if (animated) { spe8 = true; } - texturenum = s5->words.w1 & 0xfff; - flag = s5->words.w0 & 0x200; + texturenum = ingdl->words.w1 & 0xfff; + flag = ingdl->words.w0 & 0x200; texLoadFromTextureNum(texturenum, pool); @@ -856,57 +897,57 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } if (tex1 != NULL) { - s6 = tex0f1742e4(s6, sp12c, tex1, sp104); - sp104 = false; + outgdl = texWriteTextureCmd(outgdl, texcmd, tex1, appendtex); + appendtex = false; animated = false; - switch (s5->unkc0.subcmd) { + switch (ingdl->unkc0.subcmd) { case 0: - tmp6 = (s5->words.w1 >> 24) & 0xff; - tmp1 = (s5->words.w0 >> 22) & 3; - tmp2 = (s5->words.w0 >> 20) & 3; - tmp3 = (s5->words.w0 >> 18) & 3; - tmp4 = (s5->words.w0 >> 14) & 0xf; - tmp5 = (s5->words.w0 >> 10) & 0xf; + min = (ingdl->words.w1 >> 24) & 0xff; + smode = (ingdl->words.w0 >> 22) & 3; + tmode = (ingdl->words.w0 >> 20) & 3; + offset = (ingdl->words.w0 >> 18) & 3; + shifts = (ingdl->words.w0 >> 14) & 0xf; + shiftt = (ingdl->words.w0 >> 10) & 0xf; - s6 = tex0f175490(s6, tex1, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, flag); + outgdl = texHandleType0(outgdl, tex1, smode, tmode, offset, shifts, shiftt, min, flag); break; case 1: - texturenum2 = (s5->words.w1 >> 12) & 0xfff; + texturenum2 = (ingdl->words.w1 >> 12) & 0xfff; texLoadFromTextureNum(texturenum2, pool); tex2 = texFindInPool(texturenum2, pool); if (tex2 != NULL) { - tmp6 = (s5->words.w1 >> 24) & 0xff; - tmp1 = (s5->words.w0 >> 22) & 3; - tmp2 = (s5->words.w0 >> 20) & 3; - tmp3 = (s5->words.w0 >> 18) & 3; - tmp4 = (s5->words.w0 >> 14) & 0xf; - tmp5 = (s5->words.w0 >> 10) & 0xf; + min = (ingdl->words.w1 >> 24) & 0xff; + smode = (ingdl->words.w0 >> 22) & 3; + tmode = (ingdl->words.w0 >> 20) & 3; + offset = (ingdl->words.w0 >> 18) & 3; + shifts = (ingdl->words.w0 >> 14) & 0xf; + shiftt = (ingdl->words.w0 >> 10) & 0xf; - s6 = tex0f175308(s6, tex1, tmp1, tmp2, tmp3, tex2, tmp4, tmp5, tmp6, flag); + outgdl = texHandleType1(outgdl, tex1, smode, tmode, offset, tex2, shifts, shiftt, min, flag); } break; case 2: - tmp1 = (s5->words.w0 >> 22) & 3; - tmp2 = (s5->words.w0 >> 20) & 3; - tmp3 = (s5->words.w0 >> 18) & 3; + smode = (ingdl->words.w0 >> 22) & 3; + tmode = (ingdl->words.w0 >> 20) & 3; + offset = (ingdl->words.w0 >> 18) & 3; - s6 = tex0f1751e4(s6, tex1, tmp1, tmp2, tmp3, flag); + outgdl = texHandleType2(outgdl, tex1, smode, tmode, offset, flag); break; case 3: - tmp1 = (s5->words.w0 >> 22) & 3; - tmp2 = (s5->words.w0 >> 20) & 3; - tmp3 = (s5->words.w0 >> 18) & 3; + smode = (ingdl->words.w0 >> 22) & 3; + tmode = (ingdl->words.w0 >> 20) & 3; + offset = (ingdl->words.w0 >> 18) & 3; - s6 = tex0f17563c(s6, tex1, tmp1, tmp2, tmp3); + outgdl = texHandleType3(outgdl, tex1, smode, tmode, offset); break; case 4: - tmp1 = (s5->words.w0 >> 22) & 3; - tmp2 = (s5->words.w0 >> 20) & 3; - tmp3 = (s5->words.w0 >> 18) & 3; + smode = (ingdl->words.w0 >> 22) & 3; + tmode = (ingdl->words.w0 >> 20) & 3; + offset = (ingdl->words.w0 >> 18) & 3; - s6 = tex0f1755dc(s6, tex1, tmp1, tmp2, tmp3); + outgdl = texHandleType4(outgdl, tex1, smode, tmode, offset); break; } @@ -968,7 +1009,7 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } } - s5++; + ingdl++; break; case G_VTX: { @@ -978,9 +1019,9 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo Vtx *vtx; if (spe0) { - start = s5->bytes[1] & 0xf; - count = s5->vtx.unk08 + 1; - vtx = (Vtx *)(s5->dma.addr & 0x00ffffff); + start = ingdl->bytes[1] & 0xf; + count = ingdl->vtx.unk08 + 1; + vtx = (Vtx *)(ingdl->dma.addr & 0x00ffffff); for (i = start; i < start + count; i++) { if (animated && sp90[i]) { @@ -993,13 +1034,13 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } } - if (spf4 && arg4) { - s32 count = s5->vtx.unk08 + 1; + if (spf4 && vtxstart) { + s32 count = ingdl->vtx.unk08 + 1; Vtx *vtx; s32 i; - offset = s5->dma.addr & 0x00ffffff; - vtx = (Vtx *) (arg4 + offset); + offset = ingdl->dma.addr & 0x00ffffff; + vtx = (Vtx *) (vtxstart + offset); for (i = 0; i < count; i++) { vtx[i].s >>= 1; @@ -1008,25 +1049,25 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } } - *s6 = *s5; - s6++; - s5++; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; case G_RDPPIPESYNC: - var800844d0 = true; - *s6 = *s5; - s6++; - s5++; + g_TexPipeSynced = true; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; case (u8) G_TRI4: case (u8) G_TRI1: if (animated) { - if (s5->texture.cmd == (u8) G_TRI1) { - sp90[s5->tri.tri.v[0] / 10] = 1; - sp90[s5->tri.tri.v[1] / 10] = 1; - sp90[s5->tri.tri.v[2] / 10] = 1; + if (ingdl->texture.cmd == (u8) G_TRI1) { + sp90[ingdl->tri.tri.v[0] / 10] = 1; + sp90[ingdl->tri.tri.v[1] / 10] = 1; + sp90[ingdl->tri.tri.v[2] / 10] = 1; } else { - Gfx *tmp = s5; + Gfx *tmp = ingdl; if (tmp->tri4.x1 != tmp->tri4.y1 || tmp->tri4.z1 != tmp->tri4.y1) { sp90[tmp->tri4.x1] = 1; @@ -1054,12 +1095,12 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } } - sp104 = true; - var800844d0 = false; + appendtex = true; + g_TexPipeSynced = false; - *s6 = *s5; - s6++; - s5++; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; case (u8) G_TEXTURE: spe4 = true; @@ -1069,28 +1110,28 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } animated = false; - sp104 = false; + appendtex = false; - sp12c = s6; - *s6 = *s5; - s6++; - s5++; + texcmd = outgdl; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; case (u8) G_SETOTHERMODE_H: - *s6 = *s5; - s6++; - s5++; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; default: - *s6 = *s5; - s6++; - s5++; + *outgdl = *ingdl; + outgdl++; + ingdl++; break; } - sp128--; + numcmdsremaining--; - if (spe4 || sp128 <= 0) { + if (spe4 || numcmdsremaining <= 0) { spe4 = false; if (spe8 || animated) { @@ -1098,7 +1139,7 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo spe8 = false; - for (i = 0; i < 16; i++) { + for (i = 0; i < ARRAYCOUNT(sp90); i++) { if (sp90[i]) { dyntexAddVertex(spa0[i]); sp90[i] = 0; @@ -1108,7 +1149,7 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo } } - return (uintptr_t) s6 - (uintptr_t) arg2; + return (uintptr_t) outgdl - (uintptr_t) outstart; } void texCopyGdls(Gfx *src, Gfx *dst, s32 count) diff --git a/src/game/texselect.c b/src/game/texselect.c index 9a4983e36..ee0ad8acd 100644 --- a/src/game/texselect.c +++ b/src/game/texselect.c @@ -449,7 +449,7 @@ void texSelect(Gfx **gdlptr, struct textureconfig *tconfig, u32 arg2, s32 arg3, } if (tex && tex->hasloddata) { - tex0f173e50(tex, &depth2, &lrs); + texGetDepthAndSize(tex, &depth2, &lrs); } else { switch (depth) { case G_IM_SIZ_32b: diff --git a/src/include/game/tex.h b/src/include/game/tex.h index 5d8964147..e14fc9eea 100644 --- a/src/include/game/tex.h +++ b/src/include/game/tex.h @@ -21,29 +21,12 @@ void texSetRenderMode(Gfx **gdlptr, s32 arg1, s32 numcycles, s32 arg3); void texLoadFromConfig(struct textureconfig *config); void texSelect(Gfx **gdl, struct textureconfig *tconfig, u32 arg2, s32 arg3, u32 ulst, bool arg5, struct texpool *pool); -void tex0f173a08(void); -bool texSetLutMode(u32 value); -bool tex0f173a70(s32 index, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, s32 arg8, s32 shifts, s32 shiftt); -bool tex0f173b8c(s32 index, s32 uls, s32 ult, s32 lrs, s32 lrt); s32 texGetWidthAtLod(struct tex *tex, s32 lod); s32 texGetHeightAtLod(struct tex *tex, s32 lod); s32 texGetLineSizeInBytes(struct tex *tex, s32 lod); s32 texGetSizeInBytes(struct tex *tex, s32 lod); -void tex0f173e50(struct tex *tex, s32 *arg1, s32 *arg2); -s32 tex0f173f18(s32 arg0); -s32 tex0f173f48(s32 arg0); -Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s32 arg5); -Gfx *tex0f1742e4(Gfx *arg0, Gfx *arg1, struct tex *tex, bool arg3); -Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2); -Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, u32 size); -Gfx *tex0f174b54(Gfx *gdl, struct tex *tex); -Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 tile); -Gfx *tex0f1751e4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, bool arg5); -Gfx *tex0f175308(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, struct tex *arg5, s32 arg6, s32 arg7, s32 arg8, bool arg9); -Gfx *tex0f175490(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, bool arg8); -Gfx *tex0f1755dc(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4); -Gfx *tex0f17563c(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4); -s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *pool, u8 *arg4); +void texGetDepthAndSize(struct tex *tex, s32 *arg1, s32 *arg2); +s32 texLoadFromGdl(Gfx *instart, s32 gdlsizeinbytes, Gfx *outstart, struct texpool *pool, u8 *vtxstart); void texCopyGdls(Gfx *src, Gfx *dst, s32 numbytes); #endif diff --git a/src/include/types.h b/src/include/types.h index 714803bb3..c56b33607 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5228,28 +5228,6 @@ struct var80061420 { u8 *unk04; }; -struct var800ab5b8 { - u32 unk00; - u32 unk04; - u32 unk08; - u32 unk0c; - u32 unk10; - u32 unk14; - u32 unk18; - u32 unk1c; - u32 unk20; - u32 unk24; - u32 unk28; -}; - -struct var800ab718 { - bool inuse; - s32 uls; - s32 ult; - s32 lrs; - s32 lrt; -}; - struct menurendercontext { s16 x; s16 y; From 916d147619ffc29590360d79d78dac494422fa88 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 28 Aug 2023 15:03:51 +0200 Subject: [PATCH 5/6] port: skip detail textures this fixes the carpet in Defection and maybe other places, but means that detail textures are broken for now --- port/fast3d/gfx_pc.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index 9296cad85..7cf746a26 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -184,6 +184,7 @@ static struct RDP { uint64_t combine_mode; bool grayscale; bool tex_lod; + bool tex_detail; uint8_t prim_lod_fraction; struct RGBA env_color, prim_color, fog_color, fill_color, grayscale_color; @@ -842,7 +843,7 @@ static void import_texture(int i, int tile, bool importReplacement) { const uint32_t tmem_index = rdp.texture_tile[tile].tmem_index; const uint8_t palette_index = rdp.texture_tile[tile].palette; - if ((rdp.tex_lod && tile == rdp.first_tile_index) || !rdp.loaded_texture[tmem_index].addr) { + if (rdp.tex_lod || !rdp.loaded_texture[tmem_index].addr) { // set up miplevel 0; also acts as a catch-all for when .addr is NULL because my texture loader sucks rdp.loaded_texture[tmem_index].line_size_bytes = rdp.texture_tile[tile].line_size_bytes; rdp.loaded_texture[tmem_index].full_image_line_size_bytes = rdp.texture_tile[tile].line_size_bytes; @@ -1323,7 +1324,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo for (int i = 0; i < 2; i++) { // TODO: fix this; for now just ignore smaller mips - const uint32_t tile = rdp.first_tile_index + (rdp.tex_lod ? 0 : i); + const uint32_t tile = rdp.first_tile_index + (rdp.tex_lod ? rdp.tex_detail : i); if (comb->used_textures[i]) { if (rdp.textures_changed[i]) { gfx_flush(); @@ -1427,7 +1428,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo } // TODO: fix this; for now just ignore smaller mips - const uint32_t tile = (rdp.tex_lod ? 0 : t); + const uint32_t tile = (rdp.tex_lod ? rdp.tex_detail : t); float u = v_arr[i]->u / 32.0f; float v = v_arr[i]->v / 32.0f; @@ -2222,6 +2223,7 @@ static void gfx_sp_set_other_mode(uint32_t shift, uint32_t num_bits, uint64_t mo rdp.other_mode_h = (uint32_t)(om >> 32); rdp.palette_fmt = rdp.other_mode_h & (3U << G_MDSFT_TEXTLUT); rdp.tex_lod = (rdp.other_mode_h & G_TL_LOD) != 0; + rdp.tex_detail = (rdp.other_mode_h & (2U << G_MDSFT_TEXTDETAIL)) == G_TD_DETAIL; } static void gfx_sp_set_vertex_colors(uint32_t count, const struct NormalColor *vcn) { From d2574c4b493125f9b16f842c3abc94c3693efe36 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 28 Aug 2023 16:02:37 +0200 Subject: [PATCH 6/6] port: fix RGB555 textures in Grid fix submitted by Ryan --- src/game/texdecompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/texdecompress.c b/src/game/texdecompress.c index 2b0e6cb52..ad35e5f91 100644 --- a/src/game/texdecompress.c +++ b/src/game/texdecompress.c @@ -1603,7 +1603,7 @@ s32 texChannelsToPixels(u8 *src, s32 width, s32 height, u8 *dst, s32 format) case TEXFORMAT_RGB15: for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { - dst16[x] = src[pos] << 11 | src[pos + mult] << 6 | src[pos + mult * 2] << 1 | 1; + dst16[x] = PD_BE16(src[pos] << 11 | src[pos + mult] << 6 | src[pos + mult * 2] << 1 | 1); pos++; }