Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
face.c
Go to the documentation of this file.
1/* FIGHTSTG's faces: a model's blinking eyes and its other face parts. */
2
4
5/* The eyes' frame for the model's motion: 2 (closed) for motions 4 to 11, 1
6 for 2, else 0 (open) */
8 switch (task->model->motion) {
9 case 4:
10 case 5:
11 case 6:
12 case 7:
13 case 8:
14 case 9:
15 case 10:
16 case 11:
17 return 2;
18 case 2:
19 return 1;
20 default:
21 return 0;
22 }
23}
24
25/* Fills prim to copy part's frame of the face's texture over the part, in
26 VRAM */
27void FIGHTSTG_moveFacePart(Face *task, DR_MOVE *prim, s32 part, s32 frame) {
28 RECT rect;
29 Vec2 pos;
30
31 rect.x = task->parts[part].rect.frames[frame][0] + task->texPos.x;
32 rect.y = task->parts[part].rect.frames[frame][1] + task->texPos.y;
33 rect.w = task->parts[part].rect.w;
34 rect.h = task->parts[part].rect.h;
35 pos.x = task->parts[part].rect.x + task->texPos.x;
36 pos.y = task->parts[part].rect.y + task->texPos.y;
37 SetDrawMove(prim, &rect, pos.x, pos.y);
38}
39
40/* A fighter's face task: each frame, copies the eyes' frame (blinking at
41 random while open) and the other parts' frames (a three-frame cycle) over
42 the model's texture, for the parts whose frame changed */
44 Layer *layer;
45 u_long *ot;
46 DR_MOVE *prim;
47 s32 eyes;
48 s32 frame;
49 s32 i;
50
51 switch (task->state) {
52 case TASK_INIT:
53 default:
54 if (task->partCount == 0) {
55 task->setState(task, TASK_KILL);
56 } else {
57 task->nextState(task);
58 }
59 break;
60 case TASK_RUN:
61 eyes = FIGHTSTG_getEyesFrame(task);
62 if (eyes == 0) {
63 switch (task->blinkTimer >> 1) {
64 case 0:
65 task->blinkTimer = (RANDOM.next() & 0x7F) + 60;
66 /* fallthrough */
67 default:
68 eyes = 0;
69 break;
70 case 1:
71 case 2:
72 case 5:
73 case 6:
74 eyes = 1;
75 break;
76 case 3:
77 case 4:
78 eyes = 2;
79 break;
80 }
82 if (task->blinkTimer < 0) {
83 task->blinkTimer = 0;
84 }
85 } else {
86 task->blinkTimer = 0;
87 }
89 frame = task->time % 18 / 6;
91 ot = layer->getOtEntry(layer, 0);
92 prim = GFX.funcs.getPrim();
93 for (i = 0; i < 2; i++) {
94 if (task->parts[i].used && task->parts[i].frame != eyes) {
95 task->parts[i].frame = eyes;
96 FIGHTSTG_moveFacePart(task, prim, i, eyes);
97 addPrim(ot, prim);
98 prim++;
99 }
100 }
101 for (i = 2; i < 16; i++) {
102 if (task->parts[i].used && task->parts[i].frame != frame) {
103 task->parts[i].frame = frame;
104 FIGHTSTG_moveFacePart(task, prim, i, frame);
105 addPrim(ot, prim);
106 prim++;
107 }
108 }
109 GFX.funcs.setPrim(prim);
110 break;
111 case TASK_DONE:
112 case TASK_KILL:
113 break;
114 }
115}
116
117/* Creates the face of fighter's model, with its parts
118 (FIGHTSTG_fighterCache.getFace); none for fighter 0 */
120 Face *task;
121 FaceRect *rects;
122 s32 i;
123
124 if (fighter == 0) {
125 return NULL;
126 }
127 task = createTask(FIGHTSTG_updateFace, sizeof(Face), 0);
128 task->model = model;
129 task->texPos = model->texPos;
130 rects = FIGHTSTG_fighterCache.getFace(fighter);
131 for (i = 0; i < 16; i++) {
132 task->parts[i].used = 0;
133 }
134 for (i = 0; i < 16; i++) {
135 if (rects[i].x == 0xFF) {
136 return task;
137 }
138 if (rects[i].w != 0) {
139 task->parts[i].rect = rects[i];
140 task->parts[i].used = 1;
141 task->partCount++;
142 }
143 }
144 return task;
145}
FighterCache FIGHTSTG_fighterCache
the fighters' data, loaded one at a time
Definition battle.c:21
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
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
void FIGHTSTG_moveFacePart(Face *task, DR_MOVE *prim, s32 part, s32 frame)
Fills prim to copy part's frame of the face's texture over the part, in VRAM.
Definition face.c:27
s32 FIGHTSTG_getEyesFrame(Face *task)
The eyes' frame for the model's motion: 2 (closed) for motions 4 to 11, 1 for 2, else 0 (open)
Definition face.c:7
void FIGHTSTG_updateFace(Face *task)
A fighter's face task: each frame, copies the eyes' frame (blinking at random while open) and the oth...
Definition face.c:43
Face * FIGHTSTG_createFace(Model *model, s32 fighter)
Creates the face of fighter's model, with its parts (FIGHTSTG_fighterCache.getFace); none for fighter...
Definition face.c:119
#define SCREEN_LAYER
The layer over the whole screen that most modes create first and draw their menus on (FIELDSTG and ST...
Definition gfx.h:45
Random RANDOM
Definition random.c:533
s32 frames
since the last update
Definition battle.h:239
s32 used
Definition model.h:307
s32 frame
the one drawn
Definition model.h:308
FaceRect rect
Definition model.h:309
A part of a fighter's face (its eyes, then up to 14 more) and where its three frames are in its textu...
Definition model.h:298
u8 frames[3][2]
Definition model.h:303
u8 w
0: unused
Definition model.h:301
u8 x
Definition model.h:299
u8 y
Definition model.h:300
u8 h
Definition model.h:302
A model's face (FIGHTSTG_createFace, the model's first child): the eyes blink (or close for some moti...
Definition model.h:314
void(* setState)(struct Face *task, s32 state)
Definition model.h:315
FacePart parts[16]
Definition model.h:319
Model * model
Definition model.h:316
s32 time
Definition model.h:321
s32 partCount
Definition model.h:318
s32 state
Definition model.h:315
Vec2 texPos
the model's
Definition model.h:317
s32 blinkTimer
Definition model.h:320
void(* nextState)(struct Face *task)
Definition model.h:315
struct FaceRect *(* getFace)(s32 fighter)
up to an x of 0xFF
Definition model.h:273
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
A 3D model (FIGHTSTG_createModel), registered with id 0x11: a tree of bones, each drawn by a Mesh chi...
Definition model.h:132
Vec2 texPos
where its textures go in VRAM
Definition model.h:142
s32 motion
Definition model.h:145
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105