2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2022-11-01 23:17:11 +00:00
|
|
|
#include "terminal.h"
|
2020-04-30 18:41:09 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef enum TransitionFadeDirection {
|
2022-12-24 02:46:56 +00:00
|
|
|
/* 0 */ TRANS_FADE_DIR_IN,
|
|
|
|
/* 1 */ TRANS_FADE_DIR_OUT
|
|
|
|
} TransitionFadeDirection;
|
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef enum TransitionFadeType {
|
2022-12-24 02:46:56 +00:00
|
|
|
/* 0 */ TRANS_FADE_TYPE_NONE,
|
|
|
|
/* 1 */ TRANS_FADE_TYPE_ONE_WAY,
|
|
|
|
/* 2 */ TRANS_FADE_TYPE_FLASH
|
|
|
|
} TransitionFadeType;
|
|
|
|
|
|
|
|
static Gfx sTransFadeSetupDL[] = {
|
2020-04-30 18:41:09 +00:00
|
|
|
gsDPPipeSync(),
|
|
|
|
gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN |
|
|
|
|
G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH),
|
|
|
|
gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
|
|
|
|
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_1PRIMITIVE,
|
|
|
|
G_AC_NONE | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2),
|
|
|
|
gsDPSetCombineLERP(0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE),
|
|
|
|
gsSPEndDisplayList(),
|
|
|
|
};
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_Start(void* thisx) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
switch (this->type) {
|
|
|
|
case TRANS_FADE_TYPE_NONE:
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
2022-12-24 02:46:56 +00:00
|
|
|
|
|
|
|
case TRANS_FADE_TYPE_ONE_WAY:
|
|
|
|
this->timer = 0;
|
|
|
|
this->color.a = (this->direction != TRANS_FADE_DIR_IN) ? 255 : 0;
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
2022-12-24 02:46:56 +00:00
|
|
|
|
|
|
|
case TRANS_FADE_TYPE_FLASH:
|
|
|
|
this->color.a = 0;
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-05-07 14:10:06 +00:00
|
|
|
this->isDone = false;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void* TransitionFade_Init(void* thisx) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
bzero(this, sizeof(TransitionFade));
|
2020-04-30 18:41:09 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_Destroy(void* thisx) {
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_Update(void* thisx, s32 updateRate) {
|
2020-04-30 18:41:09 +00:00
|
|
|
s32 alpha;
|
2020-09-03 18:13:57 +00:00
|
|
|
s16 newAlpha;
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2020-04-30 18:41:09 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
switch (this->type) {
|
|
|
|
case TRANS_FADE_TYPE_NONE:
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
2022-12-24 02:46:56 +00:00
|
|
|
|
|
|
|
case TRANS_FADE_TYPE_ONE_WAY:
|
2024-02-07 05:32:23 +00:00
|
|
|
((TransitionFade*)thisx)->timer += updateRate;
|
2022-12-24 02:46:56 +00:00
|
|
|
if (this->timer >= gSaveContext.transFadeDuration) {
|
|
|
|
this->timer = gSaveContext.transFadeDuration;
|
2022-05-07 14:10:06 +00:00
|
|
|
this->isDone = true;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
2022-12-24 02:46:56 +00:00
|
|
|
if ((u32)gSaveContext.transFadeDuration == 0) {
|
2024-08-27 12:32:33 +00:00
|
|
|
PRINTF(VT_COL(RED, WHITE) T("0除算! ZCommonGet fade_speed に0がはいってる",
|
|
|
|
"Divide by 0! Zero is included in ZCommonGet fade_speed") VT_RST);
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
2020-12-25 21:19:52 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
alpha = (255.0f * this->timer) / ((void)0, gSaveContext.transFadeDuration);
|
|
|
|
this->color.a = (this->direction != TRANS_FADE_DIR_IN) ? 255 - alpha : alpha;
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
2022-12-24 02:46:56 +00:00
|
|
|
|
|
|
|
case TRANS_FADE_TYPE_FLASH:
|
|
|
|
newAlpha = this->color.a;
|
|
|
|
if (R_TRANS_FADE_FLASH_ALPHA_STEP != 0) {
|
|
|
|
if (R_TRANS_FADE_FLASH_ALPHA_STEP < 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
if (Math_StepToS(&newAlpha, 255, 255)) {
|
2022-12-24 02:46:56 +00:00
|
|
|
R_TRANS_FADE_FLASH_ALPHA_STEP = 150;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-12-24 02:46:56 +00:00
|
|
|
Math_StepToS(&R_TRANS_FADE_FLASH_ALPHA_STEP, 20, 60);
|
|
|
|
if (Math_StepToS(&newAlpha, 0, R_TRANS_FADE_FLASH_ALPHA_STEP)) {
|
|
|
|
R_TRANS_FADE_FLASH_ALPHA_STEP = 0;
|
2022-05-07 14:10:06 +00:00
|
|
|
this->isDone = true;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 02:46:56 +00:00
|
|
|
this->color.a = newAlpha;
|
2020-04-30 18:41:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_Draw(void* thisx, Gfx** gfxP) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2020-04-30 18:41:09 +00:00
|
|
|
Gfx* gfx;
|
2022-12-24 02:46:56 +00:00
|
|
|
Color_RGBA8_u32* color = &this->color;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2024-08-12 01:12:27 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
if (color->a != 0)
|
|
|
|
#else
|
|
|
|
if (color->a > 0)
|
|
|
|
#endif
|
|
|
|
{
|
2020-04-30 18:41:09 +00:00
|
|
|
gfx = *gfxP;
|
2022-12-24 02:46:56 +00:00
|
|
|
gSPDisplayList(gfx++, sTransFadeSetupDL);
|
2020-04-30 18:41:09 +00:00
|
|
|
gDPSetPrimColor(gfx++, 0, 0, color->r, color->g, color->b, color->a);
|
|
|
|
gDPFillRectangle(gfx++, 0, 0, gScreenWidth - 1, gScreenHeight - 1);
|
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
*gfxP = gfx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 TransitionFade_IsDone(void* thisx) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-04-30 18:41:09 +00:00
|
|
|
return this->isDone;
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_SetColor(void* thisx, u32 color) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
this->color.rgba = color;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
void TransitionFade_SetType(void* thisx, s32 type) {
|
2021-12-04 16:33:00 +00:00
|
|
|
TransitionFade* this = (TransitionFade*)thisx;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2022-12-24 02:46:56 +00:00
|
|
|
if (type == TRANS_INSTANCE_TYPE_FILL_OUT) {
|
|
|
|
this->type = TRANS_FADE_TYPE_ONE_WAY;
|
|
|
|
this->direction = TRANS_FADE_DIR_OUT;
|
|
|
|
} else if (type == TRANS_INSTANCE_TYPE_FILL_IN) {
|
|
|
|
this->type = TRANS_FADE_TYPE_ONE_WAY;
|
|
|
|
this->direction = TRANS_FADE_DIR_IN;
|
|
|
|
} else if (type == TRANS_INSTANCE_TYPE_FADE_FLASH) {
|
|
|
|
this->type = TRANS_FADE_TYPE_FLASH;
|
2020-04-30 18:41:09 +00:00
|
|
|
} else {
|
2022-12-24 02:46:56 +00:00
|
|
|
this->type = TRANS_FADE_TYPE_NONE;
|
2020-04-30 18:41:09 +00:00
|
|
|
}
|
|
|
|
}
|