From 93e6d673e6344070fee24b57bda041f875d25faa Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Mon, 27 May 2024 15:27:19 -0600 Subject: [PATCH] Fixed sf64 clear screen buffer for widescreen --- include/macros.h | 3 ++- src/engine/fox_game.c | 17 ++++++++++------- src/port/Engine.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/port/Engine.h | 10 ++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/include/macros.h b/include/macros.h index a9e24eac..4e9480f9 100644 --- a/include/macros.h +++ b/include/macros.h @@ -7,7 +7,8 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -#define SCREEN_MARGIN 8 +// This should be part of a CVar +#define SCREEN_MARGIN 0 #define TIME_IN_SECONDS(x) (x * 30); diff --git a/src/engine/fox_game.c b/src/engine/fox_game.c index adfcfa89..6e522111 100644 --- a/src/engine/fox_game.c +++ b/src/engine/fox_game.c @@ -154,16 +154,19 @@ bool Game_ChangeScene(void) { return false; } +#define LEFT_MARGIN OTRGetRectDimensionFromLeftEdge(SCREEN_MARGIN) +#define RIGHT_MARGIN OTRGetRectDimensionFromRightEdge(SCREEN_WIDTH - SCREEN_MARGIN) + void Game_InitMasterDL(Gfx** dList) { gSPDisplayList((*dList)++, gRcpInitDL); gDPSetScissor((*dList)++, G_SC_NON_INTERLACE, SCREEN_MARGIN, SCREEN_MARGIN, SCREEN_WIDTH - SCREEN_MARGIN, SCREEN_HEIGHT - SCREEN_MARGIN); gDPSetDepthImage((*dList)++, &gZBuffer); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, &gZBuffer); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, RIGHT_MARGIN, &gZBuffer); gDPSetFillColor((*dList)++, FILL_COLOR(GPACK_ZDZ(G_MAXFBZ, 0))); - gDPFillRectangle((*dList)++, SCREEN_MARGIN, SCREEN_MARGIN, SCREEN_WIDTH - SCREEN_MARGIN - 1, - SCREEN_HEIGHT - SCREEN_MARGIN - 1); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, gFrameBuffer); + gDPFillWideRectangle((*dList)++, LEFT_MARGIN, SCREEN_MARGIN, RIGHT_MARGIN, + SCREEN_HEIGHT - SCREEN_MARGIN); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, RIGHT_MARGIN, gFrameBuffer); if (gBlurAlpha < 255) { gDPPipeSync((*dList)++); @@ -175,7 +178,7 @@ void Game_InitMasterDL(Gfx** dList) { } else { gDPSetFillColor((*dList)++, FILL_COLOR(gBgColor | 1)); } - gDPFillRectangle((*dList)++, SCREEN_MARGIN, SCREEN_MARGIN, SCREEN_WIDTH - SCREEN_MARGIN - 1, + gDPFillWideRectangle((*dList)++, LEFT_MARGIN, SCREEN_MARGIN, RIGHT_MARGIN, SCREEN_HEIGHT - SCREEN_MARGIN); gDPPipeSync((*dList)++); gDPSetColorDither((*dList)++, G_CD_MAGICSQ); @@ -185,8 +188,8 @@ void Game_InitStandbyDL(Gfx** dList) { gSPDisplayList((*dList)++, gRcpInitDL); gDPSetScissor((*dList)++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT * 3); gDPSetFillColor((*dList)++, FILL_COLOR(0x0001)); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, gFrameBuffers[0].data); - gDPFillRectangle((*dList)++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT * 3 - 1); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, RIGHT_MARGIN, gFrameBuffers[0].data); + gDPFillWideRectangle((*dList)++, OTRGetDimensionFromLeftEdge(0), 0, OTRGetRectDimensionFromRightEdge(0), SCREEN_HEIGHT * 3 - 1); gDPPipeSync((*dList)++); gDPSetColorDither((*dList)++, G_CD_MAGICSQ); } diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 603ba3d7..a27d586b 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -250,3 +250,44 @@ extern "C" void Timer_Update() { } } } + +// Gets the width of the main ImGui window +extern "C" uint32_t OTRGetCurrentWidth() { + return GameEngine::Instance->context->GetWindow()->GetWidth(); +} + +// Gets the height of the main ImGui window +extern "C" uint32_t OTRGetCurrentHeight() { + return GameEngine::Instance->context->GetWindow()->GetHeight(); +} + +extern "C" float OTRGetAspectRatio() { + return gfx_current_dimensions.aspect_ratio; +} + +extern "C" float OTRGetDimensionFromLeftEdge(float v) { + return (gfx_native_dimensions.width / 2 - gfx_native_dimensions.height / 2 * OTRGetAspectRatio() + (v)); +} + +extern "C" float OTRGetDimensionFromRightEdge(float v) { + return (gfx_native_dimensions.width / 2 + gfx_native_dimensions.height / 2 * OTRGetAspectRatio() - + (gfx_native_dimensions.width - v)); +} + +// Gets the width of the current render target area +extern "C" uint32_t OTRGetGameRenderWidth() { + return gfx_current_dimensions.width; +} + +// Gets the height of the current render target area +extern "C" uint32_t OTRGetGameRenderHeight() { + return gfx_current_dimensions.height; +} + +extern "C" int16_t OTRGetRectDimensionFromLeftEdge(float v) { + return ((int)floorf(OTRGetDimensionFromLeftEdge(v))); +} + +extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) { + return ((int)ceilf(OTRGetDimensionFromRightEdge(v))); +} \ No newline at end of file diff --git a/src/port/Engine.h b/src/port/Engine.h index 8e714710..1f78fb1b 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -32,4 +32,14 @@ class GameEngine { void GameEngine_ProcessGfxCommands(Gfx* commands); float GameEngine_GetAspectRatio(); uint8_t GameEngine_OTRSigCheck(char* imgData); +uint32_t OTRGetCurrentWidth(void); +uint32_t OTRGetCurrentHeight(void); +float OTRGetAspectRatio(void); +int32_t OTRConvertHUDXToScreenX(int32_t v); +float OTRGetDimensionFromLeftEdge(float v); +float OTRGetDimensionFromRightEdge(float v); +int16_t OTRGetRectDimensionFromLeftEdge(float v); +int16_t OTRGetRectDimensionFromRightEdge(float v); +uint32_t OTRGetGameRenderWidth(); +uint32_t OTRGetGameRenderHeight(); #endif \ No newline at end of file