-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from robojumper/m_fader
m_faders
- Loading branch information
Showing
11 changed files
with
332 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef M_COLOR_H | ||
#define M_COLOR_H | ||
|
||
#include <nw4r/ut/ut_Color.h> | ||
#include <rvl/GX.h> | ||
|
||
struct mColor : public nw4r::ut::Color {}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef M_COLOR_FADER_H | ||
#define M_COLOR_FADER_H | ||
|
||
#include <common.h> | ||
#include <m/m_color.h> | ||
#include <m/m_fader_base.h> | ||
|
||
|
||
class mColorFader_c : public mFaderBase_c { | ||
public: | ||
mColorFader_c(const mColor &color, EStatus status); | ||
virtual ~mColorFader_c(); | ||
|
||
virtual void setStatus(EStatus status) override; | ||
virtual u8 calc() override; | ||
virtual void draw() override; | ||
|
||
u8 mAspectRatio; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef M_FADER_H | ||
#define M_FADER_H | ||
|
||
#include <m/m_fader_base.h> | ||
|
||
class mFader_c { | ||
public: | ||
void draw(); | ||
bool setFader(mFaderBase_c *fader); | ||
|
||
bool isStatus(mFaderBase_c::EStatus status) { | ||
return mpFader->getStatus() == status; | ||
} | ||
|
||
mFaderBase_c *mpFader; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef M_FADER_BASE_H | ||
#define M_FADER_BASE_H | ||
|
||
#include <common.h> | ||
#include <m/m_color.h> | ||
|
||
|
||
class mFaderBase_c { | ||
public: | ||
enum EStatus { | ||
FADED_OUT = 0, | ||
FADED_IN = 1, | ||
FADING_IN = 2, | ||
FADING_OUT = 3, | ||
}; | ||
|
||
enum EFlag { | ||
FLAG_1 = 1, | ||
FLAG_2 = 2, | ||
}; | ||
|
||
mFaderBase_c(const mColor &color, EStatus status); | ||
virtual ~mFaderBase_c(); | ||
|
||
virtual void setStatus(EStatus status) = 0; | ||
virtual EStatus getStatus() const; | ||
virtual bool fadeIn(); | ||
virtual bool fadeOut(); | ||
virtual u8 calc(); | ||
virtual void draw() = 0; | ||
|
||
void setFrame(u16 frame); | ||
void setColor(const mColor &color); | ||
|
||
EStatus mStatus; | ||
u8 mFlag; | ||
u16 mFrame; | ||
u16 mElapsed; | ||
mColor mFaderColor; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <m/m_color_fader.h> | ||
#include <rvl/SC.h> | ||
#include <rvl/VI.h> | ||
|
||
mColorFader_c::mColorFader_c(const mColor &color, EStatus status) : mFaderBase_c(color, status) { | ||
mAspectRatio = SCGetAspectRatio(); | ||
} | ||
|
||
mColorFader_c::~mColorFader_c() {} | ||
|
||
void mColorFader_c::setStatus(EStatus status) { | ||
if (status == FADED_OUT) { | ||
mStatus = FADED_OUT; | ||
mFaderColor.a = 0xff; | ||
} else if (status == FADED_IN) { | ||
mStatus = FADED_IN; | ||
mFaderColor.a = 0; | ||
} | ||
} | ||
|
||
u8 mColorFader_c::calc() { | ||
u8 result = mFaderBase_c::calc(); | ||
u16 elapsed = mElapsed; | ||
u16 frame = mFrame; | ||
if (elapsed > mFrame) { | ||
elapsed = frame; | ||
} | ||
|
||
switch (mStatus) { | ||
case FADED_IN: | ||
mFaderColor.a = 0; | ||
break; | ||
case FADED_OUT: | ||
mFaderColor.a = 0xff; | ||
break; | ||
case FADING_IN: | ||
mFaderColor.a = 0xff - (elapsed * 0xff / frame); | ||
break; | ||
case FADING_OUT: | ||
mFaderColor.a = elapsed * 0xff / frame; | ||
break; | ||
} | ||
|
||
|
||
return result; | ||
} | ||
|
||
#define VI_VIRTUAL_HALF_WIDTH_WIDE (406.0f) | ||
#define VI_VIRTUAL_HALF_WIDTH_STD (304.0f) | ||
#define VI_VIRTUAL_HALF_HEIGHT (228.0f) | ||
|
||
void mColorFader_c::draw() { | ||
f32 h = (mAspectRatio == 1) ? VI_VIRTUAL_HALF_WIDTH_WIDE : VI_VIRTUAL_HALF_WIDTH_STD; | ||
|
||
if (mFaderColor.a == 0) { | ||
return; | ||
} | ||
|
||
Mtx44 projMtx; | ||
C_MTXOrtho(projMtx, -VI_VIRTUAL_HALF_HEIGHT, VI_VIRTUAL_HALF_HEIGHT, -h, h, 0, 1); | ||
GXSetProjection(projMtx, GX_ORTHOGRAPHIC); | ||
|
||
Mtx posMtx; | ||
PSMTXIdentity(posMtx); | ||
GXLoadPosMtxImm(posMtx, 0); | ||
GXSetCurrentMtx(0); | ||
|
||
GXClearVtxDesc(); | ||
GXInvalidateVtxCache(); | ||
|
||
GXSetVtxDesc(GX_VA_POS, GX_DIRECT); | ||
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); | ||
|
||
GXSetNumChans(1); | ||
GXSetChanMatColor(GX_COLOR0A0, mFaderColor); | ||
GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); | ||
|
||
GXSetNumTexGens(0); | ||
GXSetNumIndStages(0); | ||
__GXSetIndirectMask(0); | ||
|
||
GXSetNumTevStages(1); | ||
GXSetTevOp(GX_TEVSTAGE0, 4); | ||
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); | ||
|
||
if (mFaderColor.a == 255) { | ||
GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET); | ||
} else { | ||
GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); | ||
} | ||
|
||
GXSetColorUpdate(1); | ||
GXSetAlphaUpdate(1); | ||
GXSetZMode(0, GX_NEVER, 0); | ||
GXSetCullMode(GX_CULL_BACK); | ||
|
||
GXBegin(GX_QUADS, GX_VTXFMT0, 4); | ||
|
||
GXPosition3f32(-h, -VI_VIRTUAL_HALF_HEIGHT, 0); | ||
GXPosition3f32(h, -VI_VIRTUAL_HALF_HEIGHT, 0); | ||
GXPosition3f32(h, VI_VIRTUAL_HALF_HEIGHT, 0); | ||
GXPosition3f32(-h, VI_VIRTUAL_HALF_HEIGHT, 0); | ||
|
||
// GXEnd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <m/m_fader.h> | ||
|
||
// nw4r::g3d::G3DState::Invalidate | ||
extern "C" void fn_8044E3B0(u32 flags); | ||
// m3d::resetMaterial according to NSMBW | ||
extern "C" void fn_802E46D0(); | ||
|
||
void mFader_c::draw() { | ||
fn_8044E3B0(0x7ff); | ||
fn_802E46D0(); | ||
mpFader->draw(); | ||
} | ||
|
||
bool mFader_c::setFader(mFaderBase_c *fader) { | ||
if (mpFader != nullptr) { | ||
bool isFading = isStatus(mFaderBase_c::FADING_IN) || isStatus(mFaderBase_c::FADING_OUT); | ||
|
||
if (isFading) { | ||
return false; | ||
} | ||
} | ||
|
||
mFaderBase_c::EStatus status = mpFader != nullptr ? mpFader->getStatus() : fader->getStatus(); | ||
|
||
mpFader = fader; | ||
switch (status) { | ||
case mFaderBase_c::FADED_OUT: | ||
fader->setStatus(mFaderBase_c::FADED_OUT); | ||
break; | ||
case mFaderBase_c::FADED_IN: | ||
fader->setStatus(mFaderBase_c::FADED_IN); | ||
break; | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.