2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-06-04 15:21:20 +00:00

Minor cleanup, fix CGraphics::Render2D

This commit is contained in:
Phillip Stephens 2025-04-14 23:09:22 -07:00
parent 476be87c89
commit bc7519d175
4 changed files with 42 additions and 60 deletions

View File

@ -272,7 +272,7 @@ static constexpr GXVtxDescList skPosColorTexDirect[] = {
void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col) { void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col) {
Mtx44 proj; Mtx44 proj;
MTXOrtho(proj, mViewport.mHeight / 2, -mViewport.mHeight / 2, -mViewport.mWidth / 2, mViewport.mWidth / 2, -1.f, MTXOrtho(proj, mViewport.mHeight / 2, -(mViewport.mHeight / 2), -(mViewport.mWidth / 2), mViewport.mWidth / 2, -1.f,
-10.f); -10.f);
GXSetProjection(proj, GX_ORTHOGRAPHIC); GXSetProjection(proj, GX_ORTHOGRAPHIC);
uint c = col.toRGBA(); uint c = col.toRGBA();
@ -280,12 +280,15 @@ void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::
Mtx mtx; Mtx mtx;
MTXIdentity(mtx); MTXIdentity(mtx);
GXLoadPosMtxImm(mtx, GX_PNMTX0); GXLoadPosMtxImm(mtx, GX_PNMTX0);
const float scaledX = static_cast<float>(x) / 640.f * static_cast<float>(mViewport.mWidth);
const float scaledY = static_cast<float>(y) / 448.f * static_cast<float>(mViewport.mHeight);
const float scaledW = static_cast<float>(w) / 640.f * static_cast<float>(mViewport.mWidth);
const float scaledH = static_cast<float>(h) / 448.f * static_cast<float>(mViewport.mHeight);
float x2, y2, x1, y1; const float x1 = scaledX - (mViewport.mWidth / 2);
x1 = x - mViewport.mWidth / 2; const float y1 = scaledY - (mViewport.mHeight / 2);
y1 = y - mViewport.mHeight / 2; const float x2 = x1 + scaledW;
x2 = x1 + w; const float y2 = y1 + scaledH;
y2 = y1 + h;
// Save state + setup // Save state + setup
CGX::SetVtxDescv(skPosColorTexDirect); CGX::SetVtxDescv(skPosColorTexDirect);
@ -298,6 +301,7 @@ void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::
SetCullMode(ERglCullMode::None); SetCullMode(ERglCullMode::None);
// Draw // Draw
tex.Load(GX_TEXMAP0, EClampMode::Repeat);
CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
GXPosition3f32(x1, y1, 1.f); GXPosition3f32(x1, y1, 1.f);
GXColor1u32(c); GXColor1u32(c);
@ -543,24 +547,24 @@ CGraphics::CClippedScreenRect CGraphics::ClipScreenRectFromVS(const CVector3f& p
return CClippedScreenRect(); return CClippedScreenRect();
} }
int right = minX + maxX + 2 & ~1; int right = minX + ((maxX + 2) & ~1);
if (right <= mViewport.mLeft) { if (right <= mViewport.mLeft) {
return CClippedScreenRect(); return CClippedScreenRect();
} }
left = std::max(left, mViewport.mLeft) & ~1; left = std::max(left, mViewport.mLeft) & ~1;
right = std::min(right, mViewport.mLeft + mViewport.mWidth) + 1 & ~1; right = (std::min(right, mViewport.mLeft + mViewport.mWidth) + 1) & ~1;
int top = minY & ~1; int top = minY & ~1;
if (top >= mViewport.mTop + mViewport.mHeight) { if (top >= mViewport.mTop + mViewport.mHeight) {
return CClippedScreenRect(); return CClippedScreenRect();
} }
int bottom = minY + maxY + 2 & ~1; int bottom = minY + ((maxY + 2) & ~1);
if (bottom <= mViewport.mTop) { if (bottom <= mViewport.mTop) {
return CClippedScreenRect(); return CClippedScreenRect();
} }
top = std::max(top, mViewport.mTop) & ~1; top = std::max(top, mViewport.mTop) & ~1;
bottom = std::min(bottom, mViewport.mTop + mViewport.mHeight) + 1 & ~1; bottom = (std::min(bottom, mViewport.mTop + mViewport.mHeight) + 1) & ~1;
float minV = static_cast<float>(minY - top) / static_cast<float>(bottom - top); float minV = static_cast<float>(minY - top) / static_cast<float>(bottom - top);
float maxV = static_cast<float>(maxY + (minY - top) + 1) / static_cast<float>(bottom - top); float maxV = static_cast<float>(maxY + (minY - top) + 1) / static_cast<float>(bottom - top);
@ -578,9 +582,11 @@ CGraphics::CClippedScreenRect CGraphics::ClipScreenRectFromVS(const CVector3f& p
case ETexelFormat::RGBA8: case ETexelFormat::RGBA8:
texAlign = 2; texAlign = 2;
break; break;
default:
break;
} }
int texWidth = texAlign + (right - left) - 1 & ~(texAlign - 1); int texWidth = (texAlign + ((right - left) - 1)) & ~(texAlign - 1);
float minU = static_cast<float>(minX - left) / static_cast<float>(texWidth); float minU = static_cast<float>(minX - left) / static_cast<float>(texWidth);
float maxU = static_cast<float>(maxX + (minX - left) + 1) / static_cast<float>(texWidth); float maxU = static_cast<float>(maxX + (minX - left) + 1) / static_cast<float>(texWidth);
return CClippedScreenRect(left, top, right - left, bottom - top, texWidth, minU, maxU, minV, maxV); return CClippedScreenRect(left, top, right - left, bottom - top, texWidth, minU, maxU, minV, maxV);

View File

@ -45,7 +45,7 @@ static void MyTHPGXYuv2RgbSetup(bool interlaced2ndFrame, bool fieldFlip) {
CGX::SetNumChans(0); CGX::SetNumChans(0);
CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY); CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY); CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
if (!fieldFlip) { if (false && !fieldFlip) {
CGX::SetNumTexGens(3); CGX::SetNumTexGens(3);
CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY); CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY);
float n = interlaced2ndFrame ? 0.25f : 0.f; float n = interlaced2ndFrame ? 0.25f : 0.f;
@ -299,28 +299,6 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo
x80_textures.reserve(3); x80_textures.reserve(3);
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
CTHPTextureSet& set = x80_textures.emplace_back(); CTHPTextureSet& set = x80_textures.emplace_back();
// if (deinterlace) {
// /* metaforce addition: this way interlaced THPs don't look horrible */
// set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} Y[0]", path,
// i));
// set.Y[1] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} Y[1]", path,
// i));
// set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} U", path, i));
// set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} V", path, i));
// } else {
// /* normal progressive presentation */
// set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} Y", path,
// i));
// set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} U", path, i));
// set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
// fmt::format("Movie {} Texture Set {} V", path, i));
// }
if (xf4_25_hasAudio) if (xf4_25_hasAudio)
set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]); set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]);
} }

View File

@ -1159,8 +1159,7 @@ void CFrontEndUI::SFrontEndFrame::HandleActiveChange(CGuiTableGroup* active) {
active->SetColors(zeus::skWhite, zeus::CColor{0.627450f, 0.627450f, 0.627450f, 0.784313f}); active->SetColors(zeus::skWhite, zeus::CColor{0.627450f, 0.627450f, 0.627450f, 0.784313f});
} }
void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller) { /* Intentionally empty */ void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller) { /* Intentionally empty */ }
}
void CFrontEndUI::SFrontEndFrame::DoSelectionChange(CGuiTableGroup* caller, int oldSel) { void CFrontEndUI::SFrontEndFrame::DoSelectionChange(CGuiTableGroup* caller, int oldSel) {
CSfxManager::SfxStart(SFXfnt_selection_change, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId); CSfxManager::SfxStart(SFXfnt_selection_change, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
@ -1395,7 +1394,8 @@ void CFrontEndUI::SOptionsFrontEndFrame::DoMenuSelectionChange(CGuiTableGroup* c
if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) { if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) {
x40_rumbleGen.HardStopAll(); x40_rumbleGen.HardStopAll();
x40_rumbleGen.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Player1); x40_rumbleGen.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One,
EIOPort::Player1);
} }
} }
} }
@ -1652,9 +1652,7 @@ void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue) {
queue.Push(MakeMsg::CreateCreateIOWin(EArchMsgTarget::IOWinManager, 12, 11, std::make_shared<CSlideShow>())); queue.Push(MakeMsg::CreateCreateIOWin(EArchMsgTarget::IOWinManager, 12, 11, std::make_shared<CSlideShow>()));
} }
std::string CFrontEndUI::GetAttractMovieFileName(int idx) { std::string CFrontEndUI::GetAttractMovieFileName(int idx) { return fmt::format("Video/attract{}.thp", idx); }
return fmt::format("Video/attract{}.thp", idx);
}
std::string CFrontEndUI::GetNextAttractMovieFileName() { std::string CFrontEndUI::GetNextAttractMovieFileName() {
std::string ret = GetAttractMovieFileName(xbc_nextAttract); std::string ret = GetAttractMovieFileName(xbc_nextAttract);
@ -1829,8 +1827,8 @@ void CFrontEndUI::Draw() {
g_Renderer->SetDepthReadWrite(false, false); g_Renderer->SetDepthReadWrite(false, false);
const auto width = x38_pressStart->GetWidth(); const auto width = x38_pressStart->GetWidth();
const auto height = x38_pressStart->GetHeight(); const auto height = x38_pressStart->GetHeight();
CGraphics::Render2D(*x38_pressStart, 320 - width / 2, 72 - height / 2, width, height, CGraphics::Render2D(*x38_pressStart, 320 - (width / 2), 72 - (height / 2), width,
zeus::CColor{1.f, x64_pressStartAlpha}); height, zeus::CColor{1.f, x64_pressStartAlpha});
} }
if (xc0_attractCount > 0) { if (xc0_attractCount > 0) {
@ -1966,16 +1964,16 @@ void CFrontEndUI::ProcessUserInput(const CFinalInput& input, CArchitectureQueue&
if (x50_curScreen != x54_nextScreen) { if (x50_curScreen != x54_nextScreen) {
if (x54_nextScreen == EScreen::AttractMovie && if (x54_nextScreen == EScreen::AttractMovie &&
(input.PStart() || input.PA() || input.PSpecialKey(ESpecialKey::Esc) || (input.PStart() || input.PA() || input.PSpecialKey(ESpecialKey::Esc) || input.PSpecialKey(ESpecialKey::Enter) ||
input.PSpecialKey(ESpecialKey::Enter) || input.PMouseButton(EMouseButton::Primary))) { input.PMouseButton(EMouseButton::Primary))) {
/* Player wants to return to opening credits from attract movie */ /* Player wants to return to opening credits from attract movie */
SetFadeBlackTimer(std::min(1.f, x58_fadeBlackTimer)); SetFadeBlackTimer(std::min(1.f, x58_fadeBlackTimer));
PlayAdvanceSfx(); PlayAdvanceSfx();
return; return;
} }
if (input.PA() || input.PStart() || input.PSpecialKey(ESpecialKey::Esc) || if (input.PA() || input.PStart() || input.PSpecialKey(ESpecialKey::Esc) || input.PSpecialKey(ESpecialKey::Enter) ||
input.PSpecialKey(ESpecialKey::Enter) || input.PMouseButton(EMouseButton::Primary)) { input.PMouseButton(EMouseButton::Primary)) {
if (x50_curScreen == EScreen::OpenCredits && x54_nextScreen == EScreen::Title && x58_fadeBlackTimer > 1.f) { if (x50_curScreen == EScreen::OpenCredits && x54_nextScreen == EScreen::Title && x58_fadeBlackTimer > 1.f) {
/* Player is too impatient to view opening credits */ /* Player is too impatient to view opening credits */
xd0_playerSkipToTitle = true; xd0_playerSkipToTitle = true;

2
extern/aurora vendored

@ -1 +1 @@
Subproject commit fee77b3d2592b3ec18af9a70e285e7e8515b29ca Subproject commit 788c65592f07c3ca8e8b8bff303f4777fd2dd0cd