NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_color_fader.cpp
1#include <game/mLib/m_color_fader.hpp>
2#include <lib/rvl/sc/SC.h>
3#include <lib/rvl/vi/VI.h>
4
5mColorFader_c::mColorFader_c(mColor col, mFaderBase_c::EStatus status) : mFaderBase_c(col, status) {
6 mAspectRatio = SCGetAspectRatio();
7}
8
9mColorFader_c::~mColorFader_c() {}
10
12 if (status == OPAQUE) {
14 mFaderColor.a = 255;
15 } else if (status == HIDDEN) {
17 mFaderColor.a = 0;
18 }
19}
20
22 int res = mFaderBase_c::calc();
23
24 u16 currFrame = mCurrFrame;
25 u16 endFrame = mFrameCount;
26
27 // Clamp to the duration of the fader
28 if (currFrame > mFrameCount) {
29 currFrame = mFrameCount;
30 }
31
32 switch (mStatus) {
33 case HIDDEN: mFaderColor.a = 0; break;
34 case OPAQUE: mFaderColor.a = 255; break;
35
36 // Linearly interpolate the alpha value
37 case FADE_IN: mFaderColor.a = 255 - (currFrame * 255 / endFrame); break;
38 case FADE_OUT: mFaderColor.a = (currFrame * 255 / endFrame); break;
39 }
40
41 return res;
42}
43
45 float h = (mAspectRatio == 1) ? VI_VIRTUAL_HALF_WIDTH_WIDE : VI_VIRTUAL_HALF_WIDTH_STD;
46
47 if (mFaderColor.a == 0) {
48 return;
49 }
50
51 Mtx44 projMtx;
52 C_MTXOrtho(&projMtx, -VI_VIRTUAL_HALF_HEIGHT, VI_VIRTUAL_HALF_HEIGHT, -h, h, 0, 1);
53 GXSetProjection(&projMtx, 1);
54
55 Mtx posMtx;
56 PSMTXIdentity(&posMtx);
57 GXLoadPosMtxImm(&posMtx, 0);
58 GXSetCurrentMtx(0);
59
60 GXClearVtxDesc();
61 GXInvalidateVtxCache();
62
63 GXSetVtxDesc(GX_VA_POS, GX_VA_TEX0MTXIDX);
64 GXSetVtxAttrFmt(0, GX_VA_POS, 1, 4, 0);
65
66 GXSetNumChans(1);
67 GXSetChanMatColor(GX_COLOR0A0, mFaderColor);
68 GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
69
70 GXSetNumTexGens(0);
71 GXSetNumIndStages(0);
72 __GXSetIndirectMask(0);
73
74 GXSetNumTevStages(1);
75 GXSetTevOp(GX_TEVSTAGE0, 4);
76 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
77
78 if (mFaderColor.a == 255) {
79 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
80 } else {
81 GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
82 }
83
84 GXSetColorUpdate(1);
85 GXSetAlphaUpdate(1);
86 GXSetZMode(0, GX_NEVER, 0);
87 GXSetCullMode(2);
88
89 GXBegin(GX_QUADS, GX_VTXFMT0, 4);
90
91 GXPosition3f32(-h, -VI_VIRTUAL_HALF_HEIGHT, 0);
92 GXPosition3f32(h, -VI_VIRTUAL_HALF_HEIGHT, 0);
93 GXPosition3f32(h, VI_VIRTUAL_HALF_HEIGHT, 0);
94 GXPosition3f32(-h, VI_VIRTUAL_HALF_HEIGHT, 0);
95
96 GXEnd();
97}
virtual int calc()
Calculates the fader at the current frame.
virtual void draw()
Draws the fader.
u8 mAspectRatio
The screen's aspect ratio. 0 = 4:3, 1 = 16:9.
virtual void setStatus(EStatus status)
Sets the fader's status.
Base fader implementation.
u16 mCurrFrame
The fader's current frame.
EStatus mStatus
The fader's status.
u16 mFrameCount
The fader's duration.
mColor mFaderColor
The fader's color.
EStatus
The fader's status.
@ FADE_IN
Transition from OPAQUE to HIDDEN.
@ FADE_OUT
Transition from HIDDEN to OPAQUE.
@ HIDDEN
The screen is completely unblocked.
@ OPAQUE
The screen is completely blacked out.
virtual int calc()
Calculates the fader at the current frame.
float Mtx44[4][4]
A 4x4 matrix.
Definition mtx.h:13
float Mtx[3][4]
A 3x4 matrix.
Definition mtx.h:12
void PSMTXIdentity(Mtx *mtx)
Sets the given matrix to the identity matrix.
A 32-bit RGBA color.
Definition m_color.hpp:6