mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-13 01:57:18 -07:00
Port pause menu framebuffer handling from 2Ship (#4346)
* bring over framebuffer effects methods * Implement framebuffer capture and drawing for pause menu * revert hookshot and title cards to draw using original buffers * remove old game over crash fix * Adjust mirror mode handling for kaleido * Avoid flashing the hud when pausing
This commit is contained in:
parent
7192783451
commit
bd7155179e
14 changed files with 284 additions and 59 deletions
|
@ -104,14 +104,12 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) {
|
|||
pool->tailMagic = GFXPOOL_TAIL_MAGIC;
|
||||
THGA_Ct(&gfxCtx->polyOpa, pool->polyOpaBuffer, sizeof(pool->polyOpaBuffer));
|
||||
THGA_Ct(&gfxCtx->polyXlu, pool->polyXluBuffer, sizeof(pool->polyXluBuffer));
|
||||
THGA_Ct(&gfxCtx->worldOverlay, pool->worldOverlayBuffer, sizeof(pool->worldOverlayBuffer));
|
||||
THGA_Ct(&gfxCtx->polyKal, pool->polyKalBuffer, sizeof(pool->polyKalBuffer));
|
||||
THGA_Ct(&gfxCtx->overlay, pool->overlayBuffer, sizeof(pool->overlayBuffer));
|
||||
THGA_Ct(&gfxCtx->work, pool->workBuffer, sizeof(pool->workBuffer));
|
||||
|
||||
gfxCtx->polyOpaBuffer = pool->polyOpaBuffer;
|
||||
gfxCtx->polyXluBuffer = pool->polyXluBuffer;
|
||||
gfxCtx->worldOverlayBuffer = pool->worldOverlayBuffer;
|
||||
gfxCtx->polyKalBuffer = pool->polyKalBuffer;
|
||||
gfxCtx->overlayBuffer = pool->overlayBuffer;
|
||||
gfxCtx->workBuffer = pool->workBuffer;
|
||||
|
@ -324,8 +322,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
|
|||
|
||||
gSPBranchList(WORK_DISP++, gfxCtx->polyOpaBuffer);
|
||||
gSPBranchList(POLY_OPA_DISP++, gfxCtx->polyXluBuffer);
|
||||
gSPBranchList(POLY_XLU_DISP++, gfxCtx->worldOverlayBuffer);
|
||||
gSPBranchList(WORLD_OVERLAY_DISP++, gfxCtx->polyKalBuffer);
|
||||
gSPBranchList(POLY_XLU_DISP++, gfxCtx->polyKalBuffer);
|
||||
gSPBranchList(POLY_KAL_DISP++, gfxCtx->overlayBuffer);
|
||||
gDPPipeSync(OVERLAY_DISP++);
|
||||
gDPFullSync(OVERLAY_DISP++);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "global.h"
|
||||
#include <stdlib.h>
|
||||
#include "soh/framebuffer_effects.h"
|
||||
|
||||
uintptr_t sSysCfbFbPtr[2];
|
||||
uintptr_t sSysCfbEnd;
|
||||
|
@ -40,6 +41,9 @@ void SysCfb_Init(s32 n64dd) {
|
|||
|
||||
// "Frame buffer addresses are %08x and %08x"
|
||||
//osSyncPrintf("フレームバッファのアドレスは %08x と %08x です\n", sSysCfbFbPtr[0], sSysCfbFbPtr[1]);
|
||||
|
||||
// SOH [Port] Inform LUS on resolution changes
|
||||
FB_CreateFramebuffers();
|
||||
}
|
||||
|
||||
void SysCfb_Reset() {
|
||||
|
|
|
@ -1147,17 +1147,16 @@ void TitleCard_Draw(PlayState* play, TitleCardContext* titleCtx) {
|
|||
|
||||
OPEN_DISPS(play->state.gfxCtx);
|
||||
|
||||
// WORLD_OVERLAY_DISP Goes over POLY_XLU_DISP but under POLY_KAL_DISP
|
||||
WORLD_OVERLAY_DISP = Gfx_SetupDL_52NoCD(WORLD_OVERLAY_DISP);
|
||||
OVERLAY_DISP = Gfx_SetupDL_52NoCD(OVERLAY_DISP);
|
||||
|
||||
gDPSetPrimColor(WORLD_OVERLAY_DISP++, 0, 0, (u8)titleCtx->intensityR, (u8)titleCtx->intensityG, (u8)titleCtx->intensityB,
|
||||
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, (u8)titleCtx->intensityR, (u8)titleCtx->intensityG, (u8)titleCtx->intensityB,
|
||||
(u8)titleCtx->alpha);
|
||||
|
||||
gDPLoadTextureBlock(WORLD_OVERLAY_DISP++, (uintptr_t)titleCtx->texture, G_IM_FMT_IA,
|
||||
gDPLoadTextureBlock(OVERLAY_DISP++, (uintptr_t)titleCtx->texture, G_IM_FMT_IA,
|
||||
G_IM_SIZ_8b,
|
||||
width, height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK,
|
||||
G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
|
||||
gSPWideTextureRectangle(WORLD_OVERLAY_DISP++, titleX, titleY, ((doubleWidth * 2) + titleX) - 4, titleY + (height * 4),
|
||||
gSPWideTextureRectangle(OVERLAY_DISP++, titleX, titleY, ((doubleWidth * 2) + titleX) - 4, titleY + (height * 4),
|
||||
G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
|
||||
|
||||
height = titleCtx->height - height;
|
||||
|
|
|
@ -69,7 +69,7 @@ void KaleidoScopeCall_Update(PlayState* play) {
|
|||
if (ShrinkWindow_GetCurrentVal() == 0) {
|
||||
HREG(80) = 7;
|
||||
HREG(82) = 3;
|
||||
R_PAUSE_MENU_MODE = 3;
|
||||
R_PAUSE_MENU_MODE = 1;
|
||||
pauseCtx->unk_1E4 = 0;
|
||||
pauseCtx->unk_1EC = 0;
|
||||
pauseCtx->state = (pauseCtx->state & 0xFFFF) + 1;
|
||||
|
|
|
@ -162,11 +162,7 @@ void Lights_BindAll(Lights* lights, LightNode* listHead, Vec3f* vec) {
|
|||
|
||||
while (listHead != NULL) {
|
||||
info = listHead->info;
|
||||
// OTRTODO: we do not know the root cause of the info->type value being invalid
|
||||
// but this prevents it from crashing the game on the game over screen
|
||||
if (info->type < 3) {
|
||||
bindFuncs[info->type](lights, &info->params, vec);
|
||||
}
|
||||
bindFuncs[info->type](lights, &info->params, vec);
|
||||
listHead = listHead->next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <overlays/misc/ovl_kaleido_scope/z_kaleido_scope.h>
|
||||
#include "soh/Enhancements/enhancementTypes.h"
|
||||
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
|
||||
#include "soh/framebuffer_effects.h"
|
||||
|
||||
#include <libultraship/libultraship.h>
|
||||
|
||||
|
@ -1341,6 +1342,24 @@ void Play_Draw(PlayState* play) {
|
|||
Lights* sp228;
|
||||
Vec3f sp21C;
|
||||
|
||||
// #region SOH [Port] Frame buffer effects for pause menu
|
||||
// Track render size when paused and that a copy was performed
|
||||
static u32 lastPauseWidth;
|
||||
static u32 lastPauseHeight;
|
||||
static u8 hasCapturedPauseBuffer;
|
||||
u8 recapturePauseBuffer = false;
|
||||
|
||||
// If the size has changed or dropped frames leading to the buffer not being copied,
|
||||
// set the prerender state back to setup to copy a new frame.
|
||||
// This requires not rendering kaleido during this copy to avoid kaleido being copied
|
||||
if ((R_PAUSE_MENU_MODE == 2 || R_PAUSE_MENU_MODE == 3) &&
|
||||
(lastPauseWidth != OTRGetGameRenderWidth() || lastPauseHeight != OTRGetGameRenderHeight() ||
|
||||
!hasCapturedPauseBuffer)) {
|
||||
R_PAUSE_MENU_MODE = 1;
|
||||
recapturePauseBuffer = true;
|
||||
}
|
||||
// #endregion
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
gSegments[4] = VIRTUAL_TO_PHYSICAL(play->objectCtx.status[play->objectCtx.mainKeepIndex].segment);
|
||||
|
@ -1374,8 +1393,8 @@ void Play_Draw(PlayState* play) {
|
|||
func_800AAA50(&play->view, 15);
|
||||
|
||||
// Flip the projections and invert culling for the OPA and XLU display buffers
|
||||
// These manage the world and effects
|
||||
if (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0)) {
|
||||
// These manage the world and effects when we are not drawing kaleido
|
||||
if (R_PAUSE_MENU_MODE <= 1 && CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0)) {
|
||||
gSPSetExtraGeometryMode(POLY_OPA_DISP++, G_EX_INVERT_CULLING);
|
||||
gSPSetExtraGeometryMode(POLY_XLU_DISP++, G_EX_INVERT_CULLING);
|
||||
gSPMatrix(POLY_OPA_DISP++, play->view.projectionFlippedPtr, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
||||
|
@ -1455,13 +1474,13 @@ void Play_Draw(PlayState* play) {
|
|||
if (R_PAUSE_MENU_MODE == 3) {
|
||||
Gfx* sp84 = POLY_OPA_DISP;
|
||||
|
||||
// SOH [Port] Draw game framebuffer using our custom handling
|
||||
//func_800C24BC(&play->pauseBgPreRender, &sp84);
|
||||
FB_DrawFromFramebuffer(&sp84, gPauseFrameBuffer, 255);
|
||||
POLY_OPA_DISP = sp84;
|
||||
|
||||
//goto Play_Draw_DrawOverlayElements;
|
||||
}
|
||||
//else
|
||||
{
|
||||
goto Play_Draw_DrawOverlayElements;
|
||||
} else {
|
||||
s32 sp80;
|
||||
|
||||
if ((HREG(80) != 10) || (HREG(83) != 0)) {
|
||||
|
@ -1535,10 +1554,6 @@ void Play_Draw(PlayState* play) {
|
|||
Environment_FillScreen(gfxCtx, 0, 0, 0, play->unk_11E18, FILL_SCREEN_OPA);
|
||||
}
|
||||
|
||||
if ((play->pauseCtx.state != 0) && (HREG(80) != 10) || (HREG(89) != 0)) {
|
||||
Play_DrawOverlayElements(play);
|
||||
}
|
||||
|
||||
if ((HREG(80) != 10) || (HREG(85) != 0)) {
|
||||
func_800315AC(play, &play->actorCtx);
|
||||
}
|
||||
|
@ -1586,17 +1601,36 @@ void Play_Draw(PlayState* play) {
|
|||
|
||||
play->pauseBgPreRender.fbuf = gfxCtx->curFrameBuffer;
|
||||
play->pauseBgPreRender.fbufSave = (u16*)gZBuffer;
|
||||
func_800C1F20(&play->pauseBgPreRender, &sp70);
|
||||
// SOH [Port] Use our custom copy method instead of the prerender system
|
||||
// func_800C1F20(&play->pauseBgPreRender, &sp70);
|
||||
if (R_PAUSE_MENU_MODE == 1) {
|
||||
play->pauseBgPreRender.cvgSave = (u8*)gfxCtx->curFrameBuffer;
|
||||
func_800C20B4(&play->pauseBgPreRender, &sp70);
|
||||
// func_800C20B4(&play->pauseBgPreRender, &sp70);
|
||||
R_PAUSE_MENU_MODE = 2;
|
||||
|
||||
// #region SOH [Port] Custom handling for pause prerender background capture
|
||||
lastPauseWidth = OTRGetGameRenderWidth();
|
||||
lastPauseHeight = OTRGetGameRenderHeight();
|
||||
hasCapturedPauseBuffer = false;
|
||||
|
||||
FB_CopyToFramebuffer(&sp70, 0, gPauseFrameBuffer, false, &hasCapturedPauseBuffer);
|
||||
|
||||
// Set the state back to ready after the recapture is done
|
||||
if (recapturePauseBuffer) {
|
||||
R_PAUSE_MENU_MODE = 3;
|
||||
}
|
||||
// #endregion
|
||||
} else {
|
||||
gTrnsnUnkState = 2;
|
||||
}
|
||||
OVERLAY_DISP = sp70;
|
||||
play->unk_121C7 = 2;
|
||||
SREG(33) |= 1;
|
||||
|
||||
// 2S2H [Port] Continue to render the post world for pausing to avoid flashing the HUD
|
||||
if (!(gTrnsnUnkState == 1)) {
|
||||
goto Play_Draw_DrawOverlayElements;
|
||||
}
|
||||
} else if (R_PAUSE_MENU_MODE != 3) {
|
||||
Play_Draw_DrawOverlayElements:
|
||||
if ((HREG(80) != 10) || (HREG(89) != 0)) {
|
||||
|
@ -1627,15 +1661,6 @@ void Play_Draw(PlayState* play) {
|
|||
|
||||
Camera_Finish(GET_ACTIVE_CAM(play));
|
||||
|
||||
{
|
||||
Gfx* prevDisplayList = POLY_OPA_DISP;
|
||||
Gfx* gfxP = Graph_GfxPlusOne(POLY_OPA_DISP);
|
||||
gSPDisplayList(OVERLAY_DISP++, gfxP);
|
||||
gSPEndDisplayList(gfxP++);
|
||||
Graph_BranchDlist(prevDisplayList, gfxP);
|
||||
POLY_OPA_DISP = gfxP;
|
||||
}
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
|
||||
Interface_DrawTotalGameplayTimer(play);
|
||||
|
|
|
@ -1672,7 +1672,7 @@ void Player_DrawHookshotReticle(PlayState* play, Player* this, f32 hookshotRange
|
|||
if (BgCheck_AnyLineTest3(&play->colCtx, &hookshotStart, &hookshotEnd, &firstHit, &colPoly, 1, 1, 1, 1, &bgId)) {
|
||||
OPEN_DISPS(play->state.gfxCtx);
|
||||
|
||||
WORLD_OVERLAY_DISP = Gfx_SetupDL(WORLD_OVERLAY_DISP, 0x07);
|
||||
OVERLAY_DISP = Gfx_SetupDL(OVERLAY_DISP, 0x07);
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZW(&play->viewProjectionMtxF, &firstHit, &sp68, &sp64);
|
||||
|
||||
|
@ -1681,22 +1681,22 @@ void Player_DrawHookshotReticle(PlayState* play, Player* this, f32 hookshotRange
|
|||
Matrix_Translate(firstHit.x, firstHit.y, firstHit.z, MTXMODE_NEW);
|
||||
Matrix_Scale(sp60, sp60, sp60, MTXMODE_APPLY);
|
||||
|
||||
gSPMatrix(WORLD_OVERLAY_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
gSPMatrix(WORLD_OVERLAY_DISP++, SEG_ADDR(1, 0), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
|
||||
gSPTexture(WORLD_OVERLAY_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
|
||||
gDPLoadTextureBlock(WORLD_OVERLAY_DISP++, gLinkAdultHookshotReticleTex, G_IM_FMT_I, G_IM_SIZ_8b, 64, 64, 0,
|
||||
gSPMatrix(OVERLAY_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
gSPMatrix(OVERLAY_DISP++, SEG_ADDR(1, 0), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
|
||||
gSPTexture(OVERLAY_DISP++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
|
||||
gDPLoadTextureBlock(OVERLAY_DISP++, gLinkAdultHookshotReticleTex, G_IM_FMT_I, G_IM_SIZ_8b, 64, 64, 0,
|
||||
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, 6, 6, G_TX_NOLOD, G_TX_NOLOD);
|
||||
if (SurfaceType_IsHookshotSurface(&play->colCtx, colPoly, bgId) && CVarGetInteger(CVAR_ENHANCEMENT("HookshotableReticle"), false)) {
|
||||
const Color_RGBA8 defaultColor = { .r = 0, .g = 255, .b = 0, .a = 255 };
|
||||
const Color_RGBA8 color = CVarGetColor(CVAR_COSMETIC("HookshotReticle.Target.Value"), defaultColor);
|
||||
gDPSetPrimColor(WORLD_OVERLAY_DISP++, 0, 0, color.r, color.g, color.b, color.a);
|
||||
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, color.r, color.g, color.b, color.a);
|
||||
} else {
|
||||
const Color_RGBA8 defaultColor = { .r = 255, .g = 0, .b = 0, .a = 255 };
|
||||
const Color_RGBA8 color = CVarGetColor(CVAR_COSMETIC("HookshotReticle.NonTarget.Value"), defaultColor);
|
||||
gDPSetPrimColor(WORLD_OVERLAY_DISP++, 0, 0, color.r, color.g, color.b, color.a);
|
||||
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
gSPVertex(WORLD_OVERLAY_DISP++, (uintptr_t)gLinkAdultHookshotReticleVtx, 3, 0);
|
||||
gSP1Triangle(WORLD_OVERLAY_DISP++, 0, 1, 2, 0);
|
||||
gSPVertex(OVERLAY_DISP++, (uintptr_t)gLinkAdultHookshotReticleVtx, 3, 0);
|
||||
gSP1Triangle(OVERLAY_DISP++, 0, 1, 2, 0);
|
||||
|
||||
CLOSE_DISPS(play->state.gfxCtx);
|
||||
}
|
||||
|
@ -2095,8 +2095,14 @@ void Player_DrawPauseImpl(PlayState* play, void* gameplayKeep, void* linkObject,
|
|||
Mtx* perspMtx = Graph_Alloc(play->state.gfxCtx, sizeof(Mtx));
|
||||
Mtx* lookAtMtx = Graph_Alloc(play->state.gfxCtx, sizeof(Mtx));
|
||||
|
||||
u8 mirrorWorldActive = CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0);
|
||||
|
||||
OPEN_DISPS(play->state.gfxCtx);
|
||||
|
||||
if (mirrorWorldActive) {
|
||||
gSPSetExtraGeometryMode(POLY_OPA_DISP++, G_EX_INVERT_CULLING);
|
||||
}
|
||||
|
||||
gSPSegment(POLY_OPA_DISP++, 0x00, NULL);
|
||||
|
||||
gDPPipeSync(POLY_OPA_DISP++);
|
||||
|
@ -2148,7 +2154,7 @@ void Player_DrawPauseImpl(PlayState* play, void* gameplayKeep, void* linkObject,
|
|||
|
||||
Matrix_SetTranslateRotateYXZ(pos->x - ((CVarGetInteger(CVAR_ENHANCEMENT("PauseLiveLink"), 0) && LINK_AGE_IN_YEARS == YEARS_ADULT) ? 25 : 0),
|
||||
pos->y - (CVarGetInteger(CVAR_GENERAL("PauseTriforce"), 0) ? 16 : 0), pos->z, rot);
|
||||
Matrix_Scale(scale * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? -1 : 1), scale, scale, MTXMODE_APPLY);
|
||||
Matrix_Scale(scale * (mirrorWorldActive ? -1 : 1), scale, scale, MTXMODE_APPLY);
|
||||
|
||||
gSPSegment(POLY_OPA_DISP++, 0x04, gameplayKeep);
|
||||
gSPSegment(POLY_OPA_DISP++, 0x06, linkObject);
|
||||
|
@ -2170,7 +2176,7 @@ void Player_DrawPauseImpl(PlayState* play, void* gameplayKeep, void* linkObject,
|
|||
|
||||
Matrix_SetTranslateRotateYXZ(pos->x - (LINK_AGE_IN_YEARS == YEARS_ADULT ? 25 : 0),
|
||||
pos->y + 280 + (LINK_AGE_IN_YEARS == YEARS_ADULT ? 48 : 0), pos->z, rot);
|
||||
Matrix_Scale(scale * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? -1 : 1), scale * 1, scale * 1, MTXMODE_APPLY);
|
||||
Matrix_Scale(scale * (mirrorWorldActive ? -1 : 1), scale * 1, scale * 1, MTXMODE_APPLY);
|
||||
|
||||
Gfx* ohNo = POLY_XLU_DISP;
|
||||
POLY_XLU_DISP = POLY_OPA_DISP;
|
||||
|
@ -2181,6 +2187,10 @@ void Player_DrawPauseImpl(PlayState* play, void* gameplayKeep, void* linkObject,
|
|||
POLY_XLU_DISP = ohNo;
|
||||
}
|
||||
|
||||
if (mirrorWorldActive) {
|
||||
gSPClearExtraGeometryMode(POLY_OPA_DISP++, G_EX_INVERT_CULLING);
|
||||
}
|
||||
|
||||
POLY_OPA_DISP = Play_SetFog(play, POLY_OPA_DISP++);
|
||||
|
||||
CLOSE_DISPS(play->state.gfxCtx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue