NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_wipe_fader.cpp
1#include <game/mLib/m_wipe_fader.hpp>
2#include <lib/rvl/sc/SC.h>
3#include <lib/rvl/vi/VI.h>
4
5mWipeFader_c::mWipeFader_c(mColor col, mFaderBase_c::EStatus status) :
6 mFaderBase_c(col, status),
7 mpTextureData(nullptr) {
8
9 PSMTXIdentity(&mTexMtx);
10 mTexWidth = 0;
11 mTexHeight = 0;
12 if (SCGetAspectRatio() == 1) {
13 // [Should just be VI_VIRTUAL_WIDTH_WIDE / VI_VIRTUAL_WIDTH_STD,
14 // but that way of calculating the constant doesn't work...]
15 mAspectRatioFactor = 1.36842095f;
16 } else {
17 mAspectRatioFactor = 1;
18 }
19}
20
21mWipeFader_c::~mWipeFader_c() {}
22
23void mWipeFader_c::setTexture(void *data, int width, int height) {
24 mpTextureData = data;
25 mTexWidth = width;
26 mTexHeight = height;
27}
28
30 if (status == OPAQUE) {
32 mProgress = 255;
33 } else if (status == HIDDEN) {
35 mProgress = 0;
36 }
37}
38
40 int res = mFaderBase_c::calc();
41
42 u16 currFrame = mCurrFrame;
43 u16 endFrame = mFrameCount;
44
45 if (currFrame > mFrameCount) {
46 currFrame = mFrameCount;
47 }
48
49 switch (mStatus) {
50 case OPAQUE: mProgress = 255; break;
51 case HIDDEN: mProgress = 0; break;
52 case FADE_IN: mProgress = 255 - (currFrame * 255 / endFrame); break;
53 case FADE_OUT: mProgress = (currFrame * 255 / endFrame); break;
54 }
55
56 calcMtx();
57 return res;
58}
59
61 // Scales from 0.5x to 128.0x the screen size [This seems like a terrible scaling function...?]
62 float scale = 128.0f / (256 - mProgress);
63
64 // Move to center, scale, move back
65 PSMTXTrans(&mTexMtx, 0.5f, 0.5f, 0.0f);
66
67 Mtx scaleMtx;
68 float scrW = mAspectRatioFactor * VI_VIRTUAL_WIDTH_STD;
69 float scrH = VI_VIRTUAL_HEIGHT;
70 PSMTXScale(&scaleMtx, scale, scale * scrH / scrW, 0.0f);
71 PSMTXConcat(&mTexMtx, &scaleMtx, &mTexMtx);
72
73 Mtx transMtx;
74 PSMTXTrans(&transMtx, -0.5f, -0.5f, 0.0f);
75 PSMTXConcat(&mTexMtx, &transMtx, &mTexMtx);
76}
77
79 float width = mAspectRatioFactor * VI_VIRTUAL_HALF_WIDTH_STD;
80 if (mProgress == 0) {
81 return;
82 }
83
84 Mtx44 projMtx;
85 C_MTXOrtho(&projMtx, -VI_VIRTUAL_HALF_HEIGHT, VI_VIRTUAL_HALF_HEIGHT, -width, width, 0.0, 1.0);
86 GXSetProjection(&projMtx, 1);
87
88 Mtx posMtx;
89 PSMTXIdentity(&posMtx);
90 GXLoadPosMtxImm(&posMtx, 0);
91 GXSetCurrentMtx(0);
92 if (mProgress >= 255) {
93 GXClearVtxDesc();
94 GXInvalidateVtxCache();
95
96 GXSetVtxDesc(GX_VA_POS, GX_VA_TEX0MTXIDX);
97 GXSetVtxAttrFmt(0, GX_VA_POS, 1, 4, 0);
98
99 GXSetNumChans(1);
100 GXSetChanMatColor(GX_COLOR0A0, mFaderColor);
101 GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
102
103 GXSetNumTexGens(0);
104 GXSetNumIndStages(0);
105 __GXSetIndirectMask(0);
106
107 GXSetNumTevStages(1);
108 GXSetTevOp(GX_TEVSTAGE0, 4);
109 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
110
111 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
112
113 GXSetColorUpdate(1);
114 GXSetAlphaUpdate(1);
115 GXSetZMode(0, GX_NEVER, 0);
116 GXSetCullMode(2);
117
118 GXBegin(GX_QUADS, GX_VTXFMT0, 4);
119
120 GXPosition3f32(-width, -VI_VIRTUAL_HALF_HEIGHT, 0);
121 GXPosition3f32(width, -VI_VIRTUAL_HALF_HEIGHT, 0);
122 GXPosition3f32(width, VI_VIRTUAL_HALF_HEIGHT, 0);
123 GXPosition3f32(-width, VI_VIRTUAL_HALF_HEIGHT, 0);
124
125 GXEnd();
126 } else {
127 GXClearVtxDesc();
128 GXInvalidateVtxCache();
129
130 GXSetVtxDesc(GX_VA_POS, GX_VA_TEX0MTXIDX);
131 GXSetVtxDesc(GX_VA_TEX0, GX_VA_TEX0MTXIDX);
132 GXSetVtxAttrFmt(0, GX_VA_POS, 1, 4, 0);
133 GXSetVtxAttrFmt(0, GX_VA_TEX0, 1, 4, 0);
134
135 GXSetNumChans(0);
136 GXSetChanMatColor(GX_COLOR0A0, mFaderColor);
137 GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
138
139 GXTexObj texObj;
140 GXInitTexObj(&texObj, mpTextureData, mTexWidth, mTexHeight, GX_TF_I4, GX_CLAMP, GX_CLAMP, 0);
141 GXLoadTexObj(&texObj, GX_TEXMAP0);
142
143 Mtx texMtx;
144 PSMTXCopy(&mTexMtx, &texMtx);
145 GXLoadTexMtxImm(&texMtx, 30, GX_MTX_2x4);
146 GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 30, 0, 125);
147
148 GXSetNumTexGens(1);
149 GXSetNumIndStages(0);
150 __GXSetIndirectMask(0);
151
152 GXSetNumTevStages(1);
153 GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO);
154 GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_TEV_SCALE_0, 1, GX_TEVPREV);
155 GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA);
156 GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_TEV_SCALE_0, 1, GX_TEVPREV);
157 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
158
159 GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
160
161 GXSetZCompLoc(1);
162 GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_OR, GX_GREATER, 0);
163 GXSetZMode(0, GX_NEVER, 0);
164 GXSetCullMode(2);
165
166 GXBegin(GX_QUADS, GX_VTXFMT0, 4);
167
168 GXPosition3f32(-width, -VI_VIRTUAL_HALF_HEIGHT, 0);
169 GXTexCoord2f32(0, 0);
170 GXPosition3f32(width, -VI_VIRTUAL_HALF_HEIGHT, 0);
171 GXTexCoord2f32(1, 0);
172 GXPosition3f32(width, VI_VIRTUAL_HALF_HEIGHT, 0);
173 GXTexCoord2f32(1, 1);
174 GXPosition3f32(-width, VI_VIRTUAL_HALF_HEIGHT, 0);
175 GXTexCoord2f32(0, 1);
176
177 GXEnd();
178 }
179}
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.
int mTexWidth
The width of the texture.
virtual void draw()
Draws the fader.
Mtx mTexMtx
The texture matrix.
int mTexHeight
The height of the texture.
virtual void setStatus(EStatus status)
Sets the fader's status.
virtual int calc()
Calculates the fader at the current frame.
float mAspectRatioFactor
How much to stretch the texture horizontally to compensate for the screen's aspect ratio.
void * mpTextureData
The texture data.
virtual void calcMtx()
Calculates the texture matrix needed for drawing the texture to the screen.
virtual void setTexture(void *data, int width, int height)
Sets the texture to use for the fader.
u8 mProgress
A value from 0 to 255 that represents the current progress of the fader.
void PSMTXScale(Mtx *mtx, float x, float y, float z)
Sets a scaling matrix with the given components.
float Mtx44[4][4]
A 4x4 matrix.
Definition mtx.h:13
void PSMTXTrans(Mtx *mtx, float x, float y, float z)
Sets a translation matrix with the given components.
void PSMTXConcat(const Mtx *a, const Mtx *b, Mtx *out)
Concatenates two matrices.
void PSMTXCopy(const Mtx *src, Mtx *dst)
Copies a matrix.
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