Skip to content

Commit bc7519d

Browse files
committed
Minor cleanup, fix CGraphics::Render2D
1 parent 476be87 commit bc7519d

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

Runtime/Graphics/CGraphics.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,23 @@ static constexpr GXVtxDescList skPosColorTexDirect[] = {
272272

273273
void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col) {
274274
Mtx44 proj;
275-
MTXOrtho(proj, mViewport.mHeight / 2, -mViewport.mHeight / 2, -mViewport.mWidth / 2, mViewport.mWidth / 2, -1.f,
275+
MTXOrtho(proj, mViewport.mHeight / 2, -(mViewport.mHeight / 2), -(mViewport.mWidth / 2), mViewport.mWidth / 2, -1.f,
276276
-10.f);
277277
GXSetProjection(proj, GX_ORTHOGRAPHIC);
278278
uint c = col.toRGBA();
279279

280280
Mtx mtx;
281281
MTXIdentity(mtx);
282282
GXLoadPosMtxImm(mtx, GX_PNMTX0);
283+
const float scaledX = static_cast<float>(x) / 640.f * static_cast<float>(mViewport.mWidth);
284+
const float scaledY = static_cast<float>(y) / 448.f * static_cast<float>(mViewport.mHeight);
285+
const float scaledW = static_cast<float>(w) / 640.f * static_cast<float>(mViewport.mWidth);
286+
const float scaledH = static_cast<float>(h) / 448.f * static_cast<float>(mViewport.mHeight);
283287

284-
float x2, y2, x1, y1;
285-
x1 = x - mViewport.mWidth / 2;
286-
y1 = y - mViewport.mHeight / 2;
287-
x2 = x1 + w;
288-
y2 = y1 + h;
288+
const float x1 = scaledX - (mViewport.mWidth / 2);
289+
const float y1 = scaledY - (mViewport.mHeight / 2);
290+
const float x2 = x1 + scaledW;
291+
const float y2 = y1 + scaledH;
289292

290293
// Save state + setup
291294
CGX::SetVtxDescv(skPosColorTexDirect);
@@ -298,6 +301,7 @@ void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::
298301
SetCullMode(ERglCullMode::None);
299302

300303
// Draw
304+
tex.Load(GX_TEXMAP0, EClampMode::Repeat);
301305
CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
302306
GXPosition3f32(x1, y1, 1.f);
303307
GXColor1u32(c);
@@ -543,24 +547,24 @@ CGraphics::CClippedScreenRect CGraphics::ClipScreenRectFromVS(const CVector3f& p
543547
return CClippedScreenRect();
544548
}
545549

546-
int right = minX + maxX + 2 & ~1;
550+
int right = minX + ((maxX + 2) & ~1);
547551
if (right <= mViewport.mLeft) {
548552
return CClippedScreenRect();
549553
}
550554
left = std::max(left, mViewport.mLeft) & ~1;
551-
right = std::min(right, mViewport.mLeft + mViewport.mWidth) + 1 & ~1;
555+
right = (std::min(right, mViewport.mLeft + mViewport.mWidth) + 1) & ~1;
552556

553557
int top = minY & ~1;
554558
if (top >= mViewport.mTop + mViewport.mHeight) {
555559
return CClippedScreenRect();
556560
}
557561

558-
int bottom = minY + maxY + 2 & ~1;
562+
int bottom = minY + ((maxY + 2) & ~1);
559563
if (bottom <= mViewport.mTop) {
560564
return CClippedScreenRect();
561565
}
562566
top = std::max(top, mViewport.mTop) & ~1;
563-
bottom = std::min(bottom, mViewport.mTop + mViewport.mHeight) + 1 & ~1;
567+
bottom = (std::min(bottom, mViewport.mTop + mViewport.mHeight) + 1) & ~1;
564568

565569
float minV = static_cast<float>(minY - top) / static_cast<float>(bottom - top);
566570
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
578582
case ETexelFormat::RGBA8:
579583
texAlign = 2;
580584
break;
585+
default:
586+
break;
581587
}
582588

583-
int texWidth = texAlign + (right - left) - 1 & ~(texAlign - 1);
589+
int texWidth = (texAlign + ((right - left) - 1)) & ~(texAlign - 1);
584590
float minU = static_cast<float>(minX - left) / static_cast<float>(texWidth);
585591
float maxU = static_cast<float>(maxX + (minX - left) + 1) / static_cast<float>(texWidth);
586592
return CClippedScreenRect(left, top, right - left, bottom - top, texWidth, minU, maxU, minV, maxV);

Runtime/Graphics/CMoviePlayer.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void MyTHPGXYuv2RgbSetup(bool interlaced2ndFrame, bool fieldFlip) {
4545
CGX::SetNumChans(0);
4646
CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
4747
CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
48-
if (!fieldFlip) {
48+
if (false && !fieldFlip) {
4949
CGX::SetNumTexGens(3);
5050
CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY);
5151
float n = interlaced2ndFrame ? 0.25f : 0.f;
@@ -299,28 +299,6 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo
299299
x80_textures.reserve(3);
300300
for (int i = 0; i < 3; ++i) {
301301
CTHPTextureSet& set = x80_textures.emplace_back();
302-
// if (deinterlace) {
303-
// /* metaforce addition: this way interlaced THPs don't look horrible */
304-
// set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, GX_TF_I8,
305-
// fmt::format("Movie {} Texture Set {} Y[0]", path,
306-
// i));
307-
// set.Y[1] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height / 2, 1, GX_TF_I8,
308-
// fmt::format("Movie {} Texture Set {} Y[1]", path,
309-
// i));
310-
// set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
311-
// fmt::format("Movie {} Texture Set {} U", path, i));
312-
// set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
313-
// fmt::format("Movie {} Texture Set {} V", path, i));
314-
// } else {
315-
// /* normal progressive presentation */
316-
// set.Y[0] = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width, x6c_videoInfo.height, 1, GX_TF_I8,
317-
// fmt::format("Movie {} Texture Set {} Y", path,
318-
// i));
319-
// set.U = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
320-
// fmt::format("Movie {} Texture Set {} U", path, i));
321-
// set.V = aurora::gfx::new_dynamic_texture_2d(x6c_videoInfo.width / 2, x6c_videoInfo.height / 2, 1, GX_TF_I8,
322-
// fmt::format("Movie {} Texture Set {} V", path, i));
323-
// }
324302
if (xf4_25_hasAudio)
325303
set.audioBuf.reset(new s16[x28_thpHead.maxAudioSamples * 2]);
326304
}

Runtime/MP1/CFrontEndUI.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ void CFrontEndUI::SFrontEndFrame::HandleActiveChange(CGuiTableGroup* active) {
11591159
active->SetColors(zeus::skWhite, zeus::CColor{0.627450f, 0.627450f, 0.627450f, 0.784313f});
11601160
}
11611161

1162-
void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller) { /* Intentionally empty */
1163-
}
1162+
void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller) { /* Intentionally empty */ }
11641163

11651164
void CFrontEndUI::SFrontEndFrame::DoSelectionChange(CGuiTableGroup* caller, int oldSel) {
11661165
CSfxManager::SfxStart(SFXfnt_selection_change, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
@@ -1395,7 +1394,8 @@ void CFrontEndUI::SOptionsFrontEndFrame::DoMenuSelectionChange(CGuiTableGroup* c
13951394

13961395
if (option.option == EGameOption::Rumble && caller->GetUserSelection() > 0) {
13971396
x40_rumbleGen.HardStopAll();
1398-
x40_rumbleGen.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One, EIOPort::Player1);
1397+
x40_rumbleGen.Rumble(RumbleFxTable[size_t(ERumbleFxId::PlayerBump)], 1.f, ERumblePriority::One,
1398+
EIOPort::Player1);
13991399
}
14001400
}
14011401
}
@@ -1643,18 +1643,16 @@ CFrontEndUI::CFrontEndUI() : CIOWin("FrontEndUI") {
16431643

16441644
CFrontEndUI::~CFrontEndUI() {
16451645
if (x14_phase >= EPhase::DisplayFrontEnd) {
1646-
//CAudioSys::RemoveAudioGroup(x44_frontendAudioGrp->GetAudioGroupData());
1646+
// CAudioSys::RemoveAudioGroup(x44_frontendAudioGrp->GetAudioGroupData());
16471647
}
16481648
}
16491649

16501650
void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue) {
1651-
//xf4_curAudio->StopMixing();
1651+
// xf4_curAudio->StopMixing();
16521652
queue.Push(MakeMsg::CreateCreateIOWin(EArchMsgTarget::IOWinManager, 12, 11, std::make_shared<CSlideShow>()));
16531653
}
16541654

1655-
std::string CFrontEndUI::GetAttractMovieFileName(int idx) {
1656-
return fmt::format("Video/attract{}.thp", idx);
1657-
}
1655+
std::string CFrontEndUI::GetAttractMovieFileName(int idx) { return fmt::format("Video/attract{}.thp", idx); }
16581656

16591657
std::string CFrontEndUI::GetNextAttractMovieFileName() {
16601658
std::string ret = GetAttractMovieFileName(xbc_nextAttract);
@@ -1771,9 +1769,9 @@ void CFrontEndUI::CompleteStateTransition() {
17711769
case EScreen::FileSelect:
17721770
SetCurrentMovie(EMenuMovie::FileSelectLoop);
17731771
if (oldScreen == EScreen::Title) {
1774-
//xf4_curAudio->StopMixing();
1775-
//xf4_curAudio = xd8_audio2.get();
1776-
//xf4_curAudio->StartMixing();
1772+
// xf4_curAudio->StopMixing();
1773+
// xf4_curAudio = xd8_audio2.get();
1774+
// xf4_curAudio->StartMixing();
17771775
}
17781776
if (xdc_saveUI)
17791777
xdc_saveUI->ResetCardDriver();
@@ -1829,8 +1827,8 @@ void CFrontEndUI::Draw() {
18291827
g_Renderer->SetDepthReadWrite(false, false);
18301828
const auto width = x38_pressStart->GetWidth();
18311829
const auto height = x38_pressStart->GetHeight();
1832-
CGraphics::Render2D(*x38_pressStart, 320 - width / 2, 72 - height / 2, width, height,
1833-
zeus::CColor{1.f, x64_pressStartAlpha});
1830+
CGraphics::Render2D(*x38_pressStart, 320 - (width / 2), 72 - (height / 2), width,
1831+
height, zeus::CColor{1.f, x64_pressStartAlpha});
18341832
}
18351833

18361834
if (xc0_attractCount > 0) {
@@ -1966,16 +1964,16 @@ void CFrontEndUI::ProcessUserInput(const CFinalInput& input, CArchitectureQueue&
19661964

19671965
if (x50_curScreen != x54_nextScreen) {
19681966
if (x54_nextScreen == EScreen::AttractMovie &&
1969-
(input.PStart() || input.PA() || input.PSpecialKey(ESpecialKey::Esc) ||
1970-
input.PSpecialKey(ESpecialKey::Enter) || input.PMouseButton(EMouseButton::Primary))) {
1967+
(input.PStart() || input.PA() || input.PSpecialKey(ESpecialKey::Esc) || input.PSpecialKey(ESpecialKey::Enter) ||
1968+
input.PMouseButton(EMouseButton::Primary))) {
19711969
/* Player wants to return to opening credits from attract movie */
19721970
SetFadeBlackTimer(std::min(1.f, x58_fadeBlackTimer));
19731971
PlayAdvanceSfx();
19741972
return;
19751973
}
19761974

1977-
if (input.PA() || input.PStart() || input.PSpecialKey(ESpecialKey::Esc) ||
1978-
input.PSpecialKey(ESpecialKey::Enter) || input.PMouseButton(EMouseButton::Primary)) {
1975+
if (input.PA() || input.PStart() || input.PSpecialKey(ESpecialKey::Esc) || input.PSpecialKey(ESpecialKey::Enter) ||
1976+
input.PMouseButton(EMouseButton::Primary)) {
19791977
if (x50_curScreen == EScreen::OpenCredits && x54_nextScreen == EScreen::Title && x58_fadeBlackTimer > 1.f) {
19801978
/* Player is too impatient to view opening credits */
19811979
xd0_playerSkipToTitle = true;
@@ -2046,7 +2044,7 @@ void CFrontEndUI::ProcessUserInput(const CFinalInput& input, CArchitectureQueue&
20462044
StartStateTransition(EScreen::FileSelect);
20472045
return;
20482046
case SFusionBonusFrame::EAction::PlayNESMetroid:
2049-
//xf4_curAudio->StopMixing();
2047+
// xf4_curAudio->StopMixing();
20502048
xec_emuFrme = std::make_unique<SNesEmulatorFrame>();
20512049
if (xdc_saveUI)
20522050
xdc_saveUI->SetInGame(true);
@@ -2119,9 +2117,9 @@ CIOWin::EMessageReturn CFrontEndUI::Update(float dt, CArchitectureQueue& queue)
21192117
}
21202118
xe8_frontendNoCardFrme = std::make_unique<SFrontEndFrame>(x1c_rndB);
21212119
x38_pressStart.GetObj();
2122-
//CAudioSys::AddAudioGroup(x44_frontendAudioGrp->GetAudioGroupData());
2123-
// xd4_audio1 = std::make_unique<CStaticAudioPlayer>("Audio/frontend_1.rsf", 416480, 1973664);
2124-
// xd8_audio2 = std::make_unique<CStaticAudioPlayer>("Audio/frontend_2.rsf", 273556, 1636980);
2120+
// CAudioSys::AddAudioGroup(x44_frontendAudioGrp->GetAudioGroupData());
2121+
// xd4_audio1 = std::make_unique<CStaticAudioPlayer>("Audio/frontend_1.rsf", 416480, 1973664);
2122+
// xd8_audio2 = std::make_unique<CStaticAudioPlayer>("Audio/frontend_2.rsf", 273556, 1636980);
21252123
x14_phase = EPhase::LoadFrames;
21262124
}
21272125
if (x14_phase == EPhase::LoadDeps)
@@ -2136,8 +2134,8 @@ CIOWin::EMessageReturn CFrontEndUI::Update(float dt, CArchitectureQueue& queue)
21362134
if (/*!xd4_audio1->IsReady() || !xd8_audio2->IsReady() || */ !xe0_frontendCardFrme->PumpLoad() ||
21372135
!xe8_frontendNoCardFrme->PumpLoad() || !xdc_saveUI->PumpLoad())
21382136
return EMessageReturn::Exit;
2139-
// xf4_curAudio = xd4_audio1.get();
2140-
// xf4_curAudio->StartMixing();
2137+
// xf4_curAudio = xd4_audio1.get();
2138+
// xf4_curAudio->StartMixing();
21412139
x14_phase = EPhase::LoadMovies;
21422140
[[fallthrough]];
21432141

@@ -2178,15 +2176,15 @@ CIOWin::EMessageReturn CFrontEndUI::Update(float dt, CArchitectureQueue& queue)
21782176
xec_emuFrme.reset();
21792177
if (xdc_saveUI)
21802178
xdc_saveUI->SetInGame(false);
2181-
//xf4_curAudio->StartMixing();
2179+
// xf4_curAudio->StartMixing();
21822180
}
21832181
break;
21842182
}
21852183

21862184
if (xd2_deferSlideShow) {
21872185
/* Start mixing slideshow music */
21882186
xd2_deferSlideShow = false;
2189-
//xf4_curAudio->StartMixing();
2187+
// xf4_curAudio->StartMixing();
21902188
if (xdc_saveUI)
21912189
xdc_saveUI->ResetCardDriver();
21922190
}

extern/aurora

0 commit comments

Comments
 (0)