Skip to content

Commit

Permalink
Merge pull request #487 from MaikelChan/mp-viewports
Browse files Browse the repository at this point in the history
Fixed viewport calculations for models in menus, and other menu fixes
  • Loading branch information
fgsfdsfgs authored Aug 6, 2024
2 parents b534a42 + 48c294f commit ca76416
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/game/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,21 @@ Gfx *menuRenderModel(Gfx *gdl, struct menumodel *menumodel, s32 modeltype)
gdl = func0f0d49c8(gdl);
gSPMatrix(gdl++, osVirtualToPhysical(camGetPerspectiveMtxL()), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
} else {
f32 aspect = (f32) (g_MenuScissorX2 - g_MenuScissorX1) / (f32) (g_MenuScissorY2 - g_MenuScissorY1);
#ifdef PLATFORM_N64
s32 x1 = g_MenuScissorX1;
s32 x2 = g_MenuScissorX2;
#else
s32 halfScreenWidth = SCREEN_WIDTH_LO >> 1;
f32 scale = SCREEN_ASPECT / videoGetAspect();
f32 width = (g_MenuScissorX2 - g_MenuScissorX1) * scale;
f32 center = (g_MenuScissorX1 + g_MenuScissorX2) * 0.5f;
center = ((center - halfScreenWidth) * scale) + halfScreenWidth;

s32 x1 = (s32)(center - width * 0.5f);
s32 x2 = (s32)(center + width * 0.5f);
#endif

f32 aspect = (f32) (x2 - x1) / (f32) (g_MenuScissorY2 - g_MenuScissorY1);

static u32 znear = 10;
static u32 zfar = 300;
Expand All @@ -2272,8 +2286,8 @@ Gfx *menuRenderModel(Gfx *gdl, struct menumodel *menumodel, s32 modeltype)

gdl = func0f0d49c8(gdl);

viSetViewPosition(g_MenuScissorX1 * g_ScaleX, g_MenuScissorY1);
viSetFovAspectAndSize(g_Vars.currentplayer->fovy, aspect, (g_MenuScissorX2 - g_MenuScissorX1) * g_ScaleX, g_MenuScissorY2 - g_MenuScissorY1);
viSetViewPosition(x1 * g_ScaleX, g_MenuScissorY1);
viSetFovAspectAndSize(g_Vars.currentplayer->fovy, aspect, (x2 - x1) * g_ScaleX, g_MenuScissorY2 - g_MenuScissorY1);

gdl = vi0000af00(gdl, var800a2048[g_MpPlayerNum]);
gdl = vi0000aca4(gdl, znear, zfar);
Expand Down
10 changes: 8 additions & 2 deletions src/game/menuitem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,11 +2607,17 @@ Gfx *menuitemCarouselRender(Gfx *gdl, struct menurendercontext *context)
colour = colourBlend(colourBlend(colour, 0x000000ff, 127), colour1, weight);
}

#ifdef PLATFORM_N64
s16 chevronOffset = 0;
#else
s16 chevronOffset = 3;
#endif

// Left arrow
gdl = menugfxDrawCarouselChevron(gdl, context->x, context->y + context->height / 2, 8, 1, -1, colour);
gdl = menugfxDrawCarouselChevron(gdl, context->x + chevronOffset, context->y + context->height / 2, 8, 1, -1, colour);

// Right arrow
gdl = menugfxDrawCarouselChevron(gdl, context->x + context->width, context->y + context->height / 2, 8, 3, -1, colour);
gdl = menugfxDrawCarouselChevron(gdl, context->x + context->width - chevronOffset, context->y + context->height / 2, 8, 3, -1, colour);

// This part of the function is unused because param2 is always zero.
// Setting it to 0x7b causes a crash.
Expand Down
80 changes: 80 additions & 0 deletions src/game/trainingmenus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,36 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud
f32 y;
f32 scale;

#ifndef PLATFORM_N64
#if VERSION == VERSION_PAL_FINAL
if (g_ViRes != VIRES_HI) {
x = -117;

if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
x = -87;
}
} else {
x = -177;

if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
x = -127;
}
}
#elif VERSION == VERSION_PAL_BETA
x = -117;

if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
x = -87;
}
#else
x = -130;

if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
x = -100;
}
#endif
#endif

switch (operation) {
case MENUOP_OPEN:
if (bodynum == BODY_DRCAROLL) {
Expand All @@ -1548,6 +1578,7 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud
g_Menus[g_MpPlayerNum].menumodel.zoomtimer60 = TICKS(120);
g_Menus[g_MpPlayerNum].menumodel.removingpiece = false;

#ifdef PLATFORM_N64
#if VERSION == VERSION_PAL_FINAL
if (g_ViRes != VIRES_HI) {
x = -117;
Expand All @@ -1574,6 +1605,7 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud
if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
x = -100;
}
#endif
#endif

y = -15;
Expand Down Expand Up @@ -1603,6 +1635,11 @@ MenuDialogHandlerResult ciCharacterProfileMenuDialog(s32 operation, struct menud
case MENUOP_CLOSE:
break;
case MENUOP_TICK:
#ifndef PLATFORM_N64
x = (float)x * ((f32)SCREEN_WIDTH_LO / (f32)SCREEN_HEIGHT_LO) / videoGetAspect();
g_Menus[g_MpPlayerNum].menumodel.newposx = x;
#endif

if (bodynum == BODY_DRCAROLL) {
static struct modelpartvisibility vis[] = {
{ MODELPART_DRCAROLL_0001, false },
Expand Down Expand Up @@ -1888,6 +1925,7 @@ MenuDialogHandlerResult dtTrainingDetailsMenuDialog(s32 operation, struct menudi
g_Menus[g_MpPlayerNum].training.weaponnum = weaponnum;
func0f105948(weaponnum);

#ifdef PLATFORM_N64
#if VERSION == VERSION_PAL_FINAL
if (g_ViRes == VIRES_HI) {
if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
Expand Down Expand Up @@ -1922,6 +1960,7 @@ MenuDialogHandlerResult dtTrainingDetailsMenuDialog(s32 operation, struct menudi
g_Menus[g_MpPlayerNum].menumodel.newposx = 90;
g_Menus[g_MpPlayerNum].menumodel.curposx = 90;
}
#endif
#endif

g_Menus[g_MpPlayerNum].menumodel.newscale /= 2.5f;
Expand All @@ -1930,6 +1969,47 @@ MenuDialogHandlerResult dtTrainingDetailsMenuDialog(s32 operation, struct menudi
case MENUOP_CLOSE:
break;
case MENUOP_TICK:
#ifndef PLATFORM_N64
#if VERSION == VERSION_PAL_FINAL
if (g_ViRes == VIRES_HI) {
if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
g_Menus[g_MpPlayerNum].menumodel.newposx = 84;
g_Menus[g_MpPlayerNum].menumodel.curposx = 84;
} else {
g_Menus[g_MpPlayerNum].menumodel.newposx = 104;
g_Menus[g_MpPlayerNum].menumodel.curposx = 104;
}
} else {
if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
g_Menus[g_MpPlayerNum].menumodel.newposx = 64;
g_Menus[g_MpPlayerNum].menumodel.curposx = 64;
} else {
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].menumodel.newposx = 64;
g_Menus[g_MpPlayerNum].menumodel.curposx = 64;
} else {
g_Menus[g_MpPlayerNum].menumodel.newposx = 84;
g_Menus[g_MpPlayerNum].menumodel.curposx = 84;
}
#else
if (optionsGetScreenRatio() == SCREENRATIO_16_9) {
g_Menus[g_MpPlayerNum].menumodel.newposx = 70;
g_Menus[g_MpPlayerNum].menumodel.curposx = 70;
} else {
g_Menus[g_MpPlayerNum].menumodel.newposx = 90;
g_Menus[g_MpPlayerNum].menumodel.curposx = 90;
}
#endif

g_Menus[g_MpPlayerNum].menumodel.newposx *= ((f32)SCREEN_WIDTH_LO / (f32)SCREEN_HEIGHT_LO) / videoGetAspect();
g_Menus[g_MpPlayerNum].menumodel.curposx = g_Menus[g_MpPlayerNum].menumodel.newposx;
#endif

if (g_Menus[g_MpPlayerNum].curdialog && g_Menus[g_MpPlayerNum].curdialog->definition == dialogdef) {
if (dtGetWeaponByDeviceIndex(dtGetIndexBySlot(g_DtSlot)) == WEAPON_DISGUISE41) {
g_Menus[g_MpPlayerNum].menumodel.newanimnum = ANIM_006A;
Expand Down

0 comments on commit ca76416

Please sign in to comment.