Skip to content

Commit

Permalink
Merge pull request #648 from MokhaLeee/flas
Browse files Browse the repository at this point in the history
Review event fadefx
  • Loading branch information
RevoSucks authored Jul 23, 2024
2 parents 683343b + 2babae4 commit 2d24e4c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 103 deletions.
4 changes: 2 additions & 2 deletions include/bmfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct EventFadeSt {
} BITPACKED;

void EventFadefx_Loop(struct ProcEventFade * proc);
void sub_80127C4(void);
void sub_8012824(void);
void EventStartFade(void);
void EventEndFade(void);
void NewEventFadefx(u16 speed, u32 mask, u16 r, u16 g, u16 b, ProcPtr parent);
void StartEventWarpAnim_ret(ProcPtr parent, s16 x, s16 y, s8 kind, s8 flag);
s8 EventWarpAnimExists_ret(void);
Expand Down
24 changes: 11 additions & 13 deletions include/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,15 @@ struct TalkDebugProc {
s16 unk_64;
};

struct Proc0859163C
struct ProcScreenFlashing
{
PROC_HEADER;
int unk_2c;
int unk_30;
int unk_34;
int unk_38;
int unk_3c;
int unk_40;
int unk_44;
int unk_48;
int duration;
int mask;
int speed_fadein;
int speed_fadeout;
int timer;
int r, b, g;
};

struct ChoiceEntryInfo
Expand Down Expand Up @@ -221,10 +219,10 @@ void sub_8008F64(int chr, int b, int c, ProcPtr parent);
void sub_8008FAC(struct TalkDebugProc *);
void sub_8008FB4(struct TalkDebugProc *);
void nullsub_15(ProcPtr, int);
void sub_800903C(struct Proc0859163C *);
void sub_800904C(struct Proc0859163C *);
void sub_8009100(struct Proc0859163C *);
void sub_800915C(int, int, int, int, int, int, int, ProcPtr);
void ScreenFlash_Init(struct ProcScreenFlashing *);
void ScreenFlash_FadeIn(struct ProcScreenFlashing *);
void ScreenFlash_FadeOut(struct ProcScreenFlashing *);
void StartScreenFlashing(int, int, int, int, int, int, int, ProcPtr);

extern struct ProcCmd gProcScr_TalkOpen[];

Expand Down
2 changes: 1 addition & 1 deletion include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ extern struct Glyph *TextGlyphs_Talk[];
extern struct Glyph *TextGlyphs_Special[];
extern struct ProcCmd CONST_DATA gProcScr_TalkPutSpriteText_Unused[];
extern struct ProcCmd CONST_DATA ProcScr_0859160C[];
extern struct ProcCmd CONST_DATA ProcScr_0859163C[];
extern struct ProcCmd CONST_DATA ProcScr_ScreenFlashing[];

extern const char *gStrPrefix[][2];
//extern struct {u32 *unk0; u32 *unk4; u32 *unk8;} gStrPrefix;
Expand Down
4 changes: 2 additions & 2 deletions src/eventcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ void SwapUnitStatsChar100(void)

void sub_8085550(ProcPtr proc)
{
sub_800915C(-1, 2, 0x20, 4, 0x180, 0x180, 0x180, proc);
StartScreenFlashing(-1, 2, 0x20, 4, 0x180, 0x180, 0x180, proc);
}

void sub_8085578(ProcPtr proc)
{
sub_800915C(-1, 2, 0x20, 4, 0x200, 0x140, 0x140, proc);
StartScreenFlashing(-1, 2, 0x20, 4, 0x200, 0x140, 0x140, proc);
}

void sub_80855A0(struct UnkProc80855A0 * proc)
Expand Down
4 changes: 2 additions & 2 deletions src/eventfx-fade.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void EventFadefx_Loop(struct ProcEventFade * proc)
}
}

void sub_80127C4(void)
void EventStartFade(void)
{
u8 i;
struct EventFadeSt * st;
Expand All @@ -54,7 +54,7 @@ void sub_80127C4(void)
}
}

void sub_8012824(void)
void EventEndFade(void)
{
u8 i;
struct EventFadeSt * st;
Expand Down
49 changes: 24 additions & 25 deletions src/eventscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,39 +756,38 @@ u8 Event18_ColorFade(struct EventEngineProc * proc)
u16 g = proc->pEventCurrent[4];
u16 b = proc->pEventCurrent[5];

switch (subcode)
{
case 0:
sub_80127C4();
return EVC_ADVANCE_YIELD;
switch (subcode) {
case EVSUBCMD_STARTFADE:
EventStartFade();
return EVC_ADVANCE_YIELD;

case 1:
sub_8012824();
return EVC_ADVANCE_YIELD;
case EVSUBCMD_ENDFADE:
EventEndFade();
return EVC_ADVANCE_YIELD;

case 2:
{
s8 i;
case EVSUBCMD_FADECOLORS:
{
s8 i;

if (EVENT_IS_SKIPPING(proc) || (proc->evStateBits & EV_STATE_FADEDIN))
speed = 0;
if (EVENT_IS_SKIPPING(proc) || (proc->evStateBits & EV_STATE_FADEDIN))
speed = 0;

mask = 0;
mask = 0;

for (i = size; i > 0; --i)
{
s8 tmp = start;
mask = mask | (1 << tmp);
start = tmp + 1;
}
for (i = size; i > 0; --i)
{
s8 tmp = start;
mask = mask | (1 << tmp);
start = tmp + 1;
}

NewEventFadefx(speed, mask, r, g, b, proc);
NewEventFadefx(speed, mask, r, g, b, proc);

return EVC_ADVANCE_YIELD;
}
return EVC_ADVANCE_YIELD;
}

default:
return EVC_ERROR;
default:
return EVC_ERROR;

} // switch (subcode)
}
Expand Down
98 changes: 40 additions & 58 deletions src/scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ struct ProcCmd CONST_DATA ProcScr_08591624[] =
PROC_END,
};

struct ProcCmd CONST_DATA ProcScr_0859163C[] =
struct ProcCmd CONST_DATA ProcScr_ScreenFlashing[] =
{
PROC_YIELD,

PROC_CALL(sub_800903C),
PROC_REPEAT(sub_800904C),
PROC_REPEAT(sub_8009100),
PROC_CALL(ScreenFlash_Init),
PROC_REPEAT(ScreenFlash_FadeIn),
PROC_REPEAT(ScreenFlash_FadeOut),

PROC_END,
};
Expand Down Expand Up @@ -2558,88 +2558,70 @@ void nullsub_15(ProcPtr proc, int label)
return;
}

//! FE8U = 0x0800903C
void sub_800903C(struct Proc0859163C * proc)
void ScreenFlash_Init(struct ProcScreenFlashing * proc)
{
proc->unk_3c = 0;
proc->timer = 0;
ArchiveCurrentPalettes();
return;
}

//! FE8U = 0x0800904C
void sub_800904C(struct Proc0859163C * proc)
void ScreenFlash_FadeIn(struct ProcScreenFlashing * proc)
{
int r;
int g;
int b;

proc->unk_3c += proc->unk_34;
int r, b, g;
proc->timer += proc->speed_fadein;

if (proc->unk_3c < 0x100)
if (proc->timer < 0x100)
{
r = (((0x100 - proc->unk_3c) * 0x100) + proc->unk_3c * proc->unk_40) / 0x100;
g = (((0x100 - proc->unk_3c) * 0x100) + proc->unk_3c * proc->unk_48) / 0x100;
b = (((0x100 - proc->unk_3c) * 0x100) + proc->unk_3c * proc->unk_44) / 0x100;
r = (((0x100 - proc->timer) * 0x100) + proc->timer * proc->r) / 0x100;
g = (((0x100 - proc->timer) * 0x100) + proc->timer * proc->g) / 0x100;
b = (((0x100 - proc->timer) * 0x100) + proc->timer * proc->b) / 0x100;
}
else
{
r = (proc->unk_40 * (0x200 - proc->unk_3c) + ((proc->unk_3c - 0x100) * 0x100)) / 0x100;
g = (proc->unk_48 * (0x200 - proc->unk_3c) + ((proc->unk_3c - 0x100) * 0x100)) / 0x100;
b = (proc->unk_44 * (0x200 - proc->unk_3c) + ((proc->unk_3c - 0x100) * 0x100)) / 0x100;
r = (proc->r * (0x200 - proc->timer) + ((proc->timer - 0x100) * 0x100)) / 0x100;
g = (proc->g * (0x200 - proc->timer) + ((proc->timer - 0x100) * 0x100)) / 0x100;
b = (proc->b * (0x200 - proc->timer) + ((proc->timer - 0x100) * 0x100)) / 0x100;
}

WriteFadedPaletteFromArchive(r, g, b, proc->unk_30);
WriteFadedPaletteFromArchive(r, g, b, proc->mask);

if (proc->unk_3c == 0x100)
if (proc->timer == 0x100)
{
proc->unk_2c--;
proc->duration--;

if (proc->unk_2c < 1)
if (proc->duration < 1)
{
proc->unk_3c = 0;
proc->timer = 0;
Proc_Break(proc);
}
}
else if (proc->unk_3c == 0x200)
{
proc->unk_3c = 0;
}

return;
else if (proc->timer == 0x200)
proc->timer = 0;
}

//! FE8U = 0x08009100
void sub_8009100(struct Proc0859163C * proc)
void ScreenFlash_FadeOut(struct ProcScreenFlashing * proc)
{
proc->unk_3c += proc->unk_38;
proc->timer += proc->speed_fadeout;

WriteFadedPaletteFromArchive(
((0x100 - proc->unk_3c) * proc->unk_40 + (proc->unk_3c * 0x100)) / 0x100,
((0x100 - proc->unk_3c) * proc->unk_48 + (proc->unk_3c * 0x100)) / 0x100,
((0x100 - proc->unk_3c) * proc->unk_44 + (proc->unk_3c * 0x100)) / 0x100,
proc->unk_30
((0x100 - proc->timer) * proc->r + (proc->timer * 0x100)) / 0x100,
((0x100 - proc->timer) * proc->g + (proc->timer * 0x100)) / 0x100,
((0x100 - proc->timer) * proc->b + (proc->timer * 0x100)) / 0x100,
proc->mask
);

if (proc->unk_3c == 0x100)
{
if (proc->timer == 0x100)
Proc_Break(proc);
}

return;
}

//! FE8U = 0x0800915C
void sub_800915C(int a, int b, int c, int d, int e, int f, int g, ProcPtr parent)
void StartScreenFlashing(int mask, int duration, int speed_fadein, int speed_fadeout, int r, int g, int b, ProcPtr parent)
{
struct Proc0859163C * proc = Proc_StartBlocking(ProcScr_0859163C, parent);

proc->unk_2c = b;
proc->unk_30 = a;
proc->unk_34 = c;
proc->unk_38 = d;
proc->unk_40 = e;
proc->unk_48 = f;
proc->unk_44 = g;

return;
struct ProcScreenFlashing * proc = Proc_StartBlocking(ProcScr_ScreenFlashing, parent);

proc->duration = duration;
proc->mask = mask;
proc->speed_fadein = speed_fadein;
proc->speed_fadeout = speed_fadeout;
proc->r = r;
proc->g = g;
proc->b = b;
}

0 comments on commit 2d24e4c

Please sign in to comment.