Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
screen_fade.c
Go to the documentation of this file.
1#include "engine/game.h"
2
3/* Starts fading the screen to black (fadeIn 0) or back, over `duration` frames */
4void screenFadeStart(ScreenFade *task, s32 fadeIn, s32 duration) {
5 task->setState(task, TASK_RUN);
6 task->substate = 1;
7 task->fadeIn = fadeIn;
8 if (fadeIn == 0) {
9 task->level = 0;
10 task->levelStep = FADE_LEVEL_MAX / duration;
11 } else {
12 task->level = FADE_LEVEL_MAX;
13 task->levelStep = -(FADE_LEVEL_MAX / duration);
14 }
15}
16
17/* The fade's primitives, one after the other in the primitive buffer */
18typedef struct FadePrims {
19 POLY_F4 poly;
20 DR_TPAGE mode;
21} FadePrims;
22
23/* A full-screen POLY_F4 with subtractive blending (tpage 0xE1000245) */
25 Layer *layer = GFX.funcs.getLayer(task->layerId);
26 u_long *ot = layer->getOtEntry(layer, task->depth);
27 FadePrims *prims = GFX.funcs.getPrim();
28 POLY_F4 *poly = &prims->poly;
29 DR_TPAGE *mode = &prims->mode;
30
31 setlen(poly, 5);
32 poly->code = 0x2A;
33 poly->r0 = poly->g0 = poly->b0 = task->level >> 8;
34 poly->x0 = poly->x2 = 0;
35 poly->x1 = poly->x3 = SCREEN_WIDTH;
36 poly->y0 = poly->y1 = 0;
37 poly->y2 = poly->y3 = 256;
38 addPrim(ot, poly);
39 setlen(mode, 1);
40 mode->code[0] = 0xE1000245;
41 addPrim(ot, mode);
42 GFX.funcs.setPrim(prims + 1);
43}
44
45/* Moves the fade one frame on and draws it; TASK_DONE at the end, still drawn */
47 switch (task->state) {
48 case TASK_INIT:
49 default:
50 task->nextState(task);
51 break;
52 case TASK_RUN:
53 if (task->substate == 0) {
54 break;
55 }
56 task->level += task->levelStep;
57 if (task->fadeIn == 0) {
58 if (task->level > FADE_LEVEL_MAX) {
59 task->level = FADE_LEVEL_MAX;
60 task->state = TASK_DONE;
61 }
62 } else if (task->level < 0) {
63 task->level = 0;
64 task->state = TASK_DONE;
65 }
66 /* fallthrough */
67 case TASK_DONE:
68 drawScreenFade(task);
69 break;
70 case TASK_KILL:
71 break;
72 }
73}
74
75/* A screen fade task on a layer, idle until started */
78
79 task->start = screenFadeStart;
80 task->layerId = layerId;
81 task->depth = 0;
82 return task;
83}
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
#define SCREEN_WIDTH
The screen the modes draw on (setDisplayMode, their layers' rects)
Definition gfx.h:36
#define FADE_LEVEL_MAX
ScreenFade.level when the screen is black: 0xFF in 8.8 fixed point.
Definition gfx.h:358
ScreenFade * createScreenFade(s32 layerId)
A screen fade task on a layer, idle until started.
Definition screen_fade.c:76
void updateScreenFade(ScreenFade *task)
Moves the fade one frame on and draws it; TASK_DONE at the end, still drawn.
Definition screen_fade.c:46
void drawScreenFade(ScreenFade *task)
A full-screen POLY_F4 with subtractive blending (tpage 0xE1000245)
Definition screen_fade.c:24
void screenFadeStart(ScreenFade *task, s32 fadeIn, s32 duration)
Starts fading the screen to black (fadeIn 0) or back, over duration frames.
Definition screen_fade.c:4
The fade's primitives, one after the other in the primitive buffer.
Definition screen_fade.c:18
DR_TPAGE mode
Definition screen_fade.c:20
POLY_F4 poly
Definition screen_fade.c:19
void *(* getPrim)(void)
Definition gfx.h:19
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
void(* setPrim)(void *next)
Definition gfx.h:20
GfxFuncs funcs
Definition gfx.h:77
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
u_long *(* getOtEntry)(struct Layer *, s32 depth)
Definition gfx.h:155
Fades the whole screen to black and back with a subtractive rectangle.
Definition gfx.h:361
s32 depth
Definition gfx.h:364
s32 levelStep
Definition gfx.h:367
s32 fadeIn
0: to black
Definition gfx.h:365
void(* start)(struct ScreenFade *fade, s32 fadeIn, s32 frames)
TASK_DONE when done.
Definition gfx.h:368
s32 layerId
Definition gfx.h:363
void(* nextState)(struct ScreenFade *task)
Definition gfx.h:362
void(* setState)(struct ScreenFade *task, s32 state)
Definition gfx.h:362
s32 level
0-FADE_LEVEL_MAX
Definition gfx.h:366
s32 state
Definition gfx.h:362
s32 substate
Definition gfx.h:362
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105