Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
stage.c
Go to the documentation of this file.
1/* The second object of FIGHTSTG.PRO (see model_mesh.c), the fight stage: its
2 rodata starts at 0x80082464 (USA), 4 bytes past a multiple of 8. */
3
5
6/* Sets the stage model's color and SCREEN_LAYER's background to their fades'
7 current values (a black background is drawn as 1, 1, 1) */
8void FIGHTSTG_fadeStage(FightStage *task, Model **children) {
9 u8 color[3];
10 Model *model;
11 Layer *layer;
12
13 FIGHTSTG_interp.lerp(&task->colorFrom, &task->colorTo, task->fade, &task->color);
14 color[0] = task->color.vx;
15 color[1] = task->color.vy;
16 color[2] = task->color.vz;
17 model = children[0];
18 model->setColor(model, 1, color);
19 FIGHTSTG_interp.lerp(&task->bgFrom, &task->bgTo, task->fade, &task->bg);
21 if (task->bg.vx != 0 || task->bg.vy != 0 || task->bg.vz != 0) {
22 layer->setBgColor(layer, (u8)task->bg.vx, (u8)task->bg.vy, (u8)task->bg.vz);
23 } else {
24 layer->setBgColor(layer, 1, 1, 1);
25 }
26}
27
28const Vec2 FIGHTSTG_stageTexPos = { 0x280, 0 };
29
30/* the fight stages' music (FightStageInfo.music), as sound ids */
32 0xA004E03C, 0xA004E0BD, 0xA004E13E, 0xA004E1BF,
33 0xA004E240, 0xA004E2C1, 0xA004E342, 0xA004E3C3,
34};
35
36/* Fades the stage's lights in. */
37static inline void fadeInStageLights(FightStage *task) {
39
40 if (lights != NULL) {
41 lights->fade(lights, NULL, lights->getStageLights(lights, task->stage), task->fadeInTime);
42 }
43}
44
45/* Once the stage's model is in: turns off the bounds check of the stage's
46 listed bones and starts the model and the background in black. */
47static inline void prepareStageModel(FightStage *task, Model **children, FightStageInfo *stages) {
48 Model *model;
49 Layer *layer;
50 u8 color[3];
51 s32 i;
52
53 for (i = 0; i < 8; i++) {
54 if (stages[task->stage].noBoundsBones[i] == 0) {
55 break;
56 }
57 model = children[0];
58 model->setBoneNoBoundsCheck(model, stages[task->stage].noBoundsBones[i], 1);
59 }
60 color[0] = 0;
61 color[1] = 0;
62 color[2] = 0;
63 model = children[0];
64 model->setColor(model, 1, color);
66 layer->setBgColor(layer, 1, 1, 1);
67}
68
69/* Sets the fade of the model's color and the background in from black. */
70static inline void startStageFadeIn(FightStage *task, FightStageInfo *stages) {
71 task->colorTo.vz = 0x80;
72 task->colorTo.vy = 0x80;
73 task->colorTo.vx = 0x80;
74 task->colorFrom.vz = 0;
75 task->colorFrom.vy = 0;
76 task->colorFrom.vx = 0;
77 task->bgTo.vx = stages[task->stage].bgColor[0];
78 task->bgTo.vy = stages[task->stage].bgColor[1];
79 task->bgTo.vz = stages[task->stage].bgColor[2];
80 task->bgFrom.vz = 0;
81 task->bgFrom.vy = 0;
82 task->bgFrom.vx = 0;
83 task->fade = 0;
84 task->fadeStep = 0x1000 / task->fadeInTime;
85}
86
87/* Moves the fade on by the frame's time, up to its end (0x1000). */
88static inline void advanceStageFade(FightStage *task) {
89 task->fade += task->fadeStep * GFX.funcs.getFrameTime();
90 if (task->fade > 0x1000) {
91 task->fade = 0x1000;
92 }
93}
94
95/* Sets the fade of the model's color and the old stage's background out to
96 black. */
97static inline void startStageFadeOut(FightStage *task, FightStageInfo *stages) {
98 task->colorFrom.vz = 0x80;
99 task->colorFrom.vy = 0x80;
100 task->colorFrom.vx = 0x80;
101 task->colorTo.vz = 0;
102 task->colorTo.vy = 0;
103 task->colorTo.vx = 0;
104 task->bgTo.vz = 0;
105 task->bgTo.vy = 0;
106 task->bgTo.vx = 0;
107 task->bgFrom.vx = stages[task->prevStage].bgColor[0];
108 task->bgFrom.vy = stages[task->prevStage].bgColor[1];
109 task->bgFrom.vz = stages[task->prevStage].bgColor[2];
110 task->fade = 0;
111 task->fadeStep = 0x1000 / task->fadeOutTime;
112}
113
114/* The fight stage's task: loads the stage's model, starts its music and fades
115 in its lights, then fades the model's color and the background in from
116 black; setStage fades them out, frees the old model and stops its music,
117 and loads the new stage */
118void FIGHTSTG_updateStage(FightStage *task, Model **children) {
120
121 switch (task->state) {
122 case TASK_INIT:
123 default:
124 task->nextState(task);
125 /* fallthrough */
126 case TASK_RUN:
127 switch (task->substate) {
128 case 0:
129 task->control.layers[0].enabled = 1;
131 task->control.fighter = 0;
132 task->control.layers[0].wireframe = 0;
133 children[0] = FIGHTSTG_createPlainModel(stages[task->stage].model, stages[task->stage].motions, FIGHTSTG_stageTexPos, &task->control);
134 if (stages[task->stage].music != -1) {
135 task->voice = SOUND.playSound(FIGHTSTG_stageMusic[stages[task->stage].music]);
136 }
137 fadeInStageLights(task);
138 task->nextSubstate(task);
139 /* fallthrough */
140 case 1:
141 if (children[0]->state == TASK_RUN) {
142 prepareStageModel(task, children, stages);
143 task->nextSubstate(task);
144 }
145 break;
146 case 2:
147 startStageFadeIn(task, stages);
148 task->nextSubstate(task);
149 /* fallthrough */
150 case 3:
151 advanceStageFade(task);
152 FIGHTSTG_fadeStage(task, children);
153 if (task->fade == 0x1000) {
154 task->nextSubstate(task);
155 }
156 break;
157 case 4:
158 break;
159 }
160 break;
161 case TASK_DONE:
162 switch (task->substate) {
163 case 0:
164 default:
165 FILE_CACHE.request((s16)(stages[task->stage].model >> 16));
166 startStageFadeOut(task, stages);
167 task->nextSubstate(task);
168 /* fallthrough */
169 case 1:
170 advanceStageFade(task);
171 FIGHTSTG_fadeStage(task, children);
172 if (task->fade == 0x1000) {
173 children[0]->setState(children[0], TASK_KILL);
174 task->setState(task, TASK_RUN);
175 if (stages[task->prevStage].music != -1) {
176 SOUND.keyOff(FIGHTSTG_stageMusic[stages[task->prevStage].music], task->voice);
177 }
178 }
179 break;
180 }
181 break;
182 case TASK_KILL:
183 break;
184 }
185}
186
187/* FightStage.setStage: changes to stage ID, fading the old one out over
188 FADEOUTTIME and the new one in over FADEINTIME */
189void FIGHTSTG_setStage(FightStage *task, s32 id, s32 fadeOutTime, s32 fadeInTime) {
190 if (task->stage != id) {
191 task->prevStage = task->stage;
192 task->stage = id;
193 task->fadeOutTime = fadeOutTime;
194 task->fadeInTime = fadeInTime;
195 task->setState(task, TASK_DONE);
196 }
197}
198
199/* A random fight stage, 1-27 */
201 return RANDOM.next() % 27 + 1;
202}
203
204/* The file of fight stage ID's motions */
207
208 return (s16)(stages[id].motions >> 16);
209}
210
211/* Creates the fight stage (id 0x15), which loads stage id and fades it in
212 over fadeInTime */
215
217 task->stage = id;
218 task->fadeInTime = fadeInTime;
219 return task;
220}
#define FILE_FIGHT_STAGES
The fight stages, the battle's backgrounds: WFIGHTTS lists them as MFSTG001-027.
Definition stage.h:14
#define BATTLE_LAYER_STAGE
Definition types.h:28
#define BATTLE_TASK_LIGHTS
Definition types.h:22
#define BATTLE_TASK_STAGE
Definition types.h:24
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
unsigned char u8
Definition common.h:8
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
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#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
InterpFuncs FIGHTSTG_interp
the functions that go between values
Definition interp.c:44
Model * FIGHTSTG_createPlainModel(s32 file, s32 motionFile, Vec2 texPos, ModelControl *control)
A model whose motions just end (FIGHTSTG_createModel)
Definition model_mesh.c:502
Random RANDOM
Definition random.c:533
TaskRegistry TASK_REGISTRY
Definition registry.c:122
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
s32 FIGHTSTG_getStageMotionsFile(s32 id)
The file of fight stage ID's motions.
Definition stage.c:205
static void startStageFadeOut(FightStage *task, FightStageInfo *stages)
Sets the fade of the model's color and the old stage's background out to black.
Definition stage.c:97
void FIGHTSTG_updateStage(FightStage *task, Model **children)
The fight stage's task: loads the stage's model, starts its music and fades in its lights,...
Definition stage.c:118
s32 FIGHTSTG_randomStage(void)
A random fight stage, 1-27.
Definition stage.c:200
static void fadeInStageLights(FightStage *task)
Fades the stage's lights in.
Definition stage.c:37
static void startStageFadeIn(FightStage *task, FightStageInfo *stages)
Sets the fade of the model's color and the background in from black.
Definition stage.c:70
const Vec2 FIGHTSTG_stageTexPos
Definition stage.c:28
static void advanceStageFade(FightStage *task)
Moves the fade on by the frame's time, up to its end (0x1000).
Definition stage.c:88
void FIGHTSTG_setStage(FightStage *task, s32 id, s32 fadeOutTime, s32 fadeInTime)
FightStage.setStage: changes to stage ID, fading the old one out over FADEOUTTIME and the new one in ...
Definition stage.c:189
void FIGHTSTG_fadeStage(FightStage *task, Model **children)
Sets the stage model's color and SCREEN_LAYER's background to their fades' current values (a black ba...
Definition stage.c:8
s32 FIGHTSTG_stageMusic[8]
the fight stages' music (FightStageInfo.music), as sound ids
Definition stage.c:31
FightStage * FIGHTSTG_createStage(s32 id, s32 fadeInTime)
Creates the fight stage (id 0x15), which loads stage id and fades it in over fadeInTime.
Definition stage.c:213
static void prepareStageModel(FightStage *task, Model **children, FightStageInfo *stages)
Once the stage's model is in: turns off the bounds check of the stage's listed bones and starts the m...
Definition stage.c:47
A fight stage, in FILE_FIGHT_STAGES.
Definition stage.h:24
s32 model
file << 16 | index
Definition stage.h:25
s32 motions
Definition stage.h:26
s32 music
an index in FIGHTSTG_stageMusic, or -1
Definition stage.h:27
u8 bgColor[3]
Definition stage.h:28
u8 noBoundsBones[8]
bones given to the model's setBoneNoBoundsCheck, up to a 0
Definition stage.h:30
The fight stage (FIGHTSTG_createStage), registered as BATTLE_TASK_STAGE: its model,...
Definition stage.h:38
s32 substate
Definition stage.h:39
SVECTOR bg
Definition stage.h:52
s32 fadeInTime
Definition stage.h:45
s32 fadeOutTime
Definition stage.h:46
SVECTOR colorTo
Definition stage.h:48
void(* setStage)(struct FightStage *task, s32 stage, s32 fadeOutTime, s32 fadeInTime)
Definition stage.h:54
SVECTOR colorFrom
the model's
Definition stage.h:47
s32 state
Definition stage.h:39
void(* nextSubstate)(struct FightStage *task)
Definition stage.h:39
s16 voice
the music's
Definition stage.h:53
SVECTOR color
Definition stage.h:49
s32 prevStage
Definition stage.h:41
s32 fadeStep
Definition stage.h:44
void(* setState)(struct FightStage *task, s32 state)
Definition stage.h:39
s32 stage
Definition stage.h:40
SVECTOR bgTo
Definition stage.h:51
s32 fade
0-0x1000
Definition stage.h:43
void(* nextState)(struct FightStage *task)
Definition stage.h:39
SVECTOR bgFrom
SCREEN_LAYER's background.
Definition stage.h:50
ModelControl control
Definition stage.h:42
void *(* load)(u32 file)
Definition file.h:92
void(* request)(s32 file)
Definition file.h:90
s32(* getFrameTime)(void)
Definition gfx.h:32
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
GfxFuncs funcs
Definition gfx.h:77
void(* lerp)(SVECTOR *from, SVECTOR *to, s32 t, SVECTOR *out)
t: 0-0x1000
Definition model.h:195
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* setBgColor)()
no prototype: callers would truncate u8 args
Definition gfx.h:152
The stage lights (FIGHTSTG_createLights), registered as BATTLE_TASK_LIGHTS: set puts a light set,...
Definition stage.h:59
void(* fade)(struct Lights *task, LightSet *from, LightSet *to, s32 time)
from: NULL for the current
Definition stage.h:68
LightSet *(* getStageLights)(struct Lights *task, s32 stage)
Definition stage.h:69
s32 wireframe
they are drawn as wireframe (Mesh.drawWireframe)
Definition model.h:114
s32 enabled
Definition model.h:112
s32 layerId
the layer its meshes are drawn in
Definition model.h:113
struct ModelControl::@3 layers[2]
the model is drawn once for each one enabled
s32 fighter
the Models task's
Definition model.h:105
A 3D model (FIGHTSTG_createModel), registered with id 0x11: a tree of bones, each drawn by a Mesh chi...
Definition model.h:132
void(* setColor)()
(model, mode, color): its meshes'
Definition model.h:160
void(* setState)(struct Model *task, s32 state)
Definition model.h:133
void(* setBoneNoBoundsCheck)()
Definition model.h:161
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
void(* keyOff)(s32 id, s16 voice)
Definition sound.h:189
void *(* find)(s32 id, s32 key1, s32 key2)
Definition task.h:18
TaskFuncs funcs
Definition task.h:76
Definition gfx.h:352
void * createTaskWithId(void(*update)(), s32 size, s32 childrenSize, s32 id)
Allocates a zeroed task of size bytes (header included) with room for childrenSize / 4 child tasks.
Definition task.c:80