Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
lights.c
Go to the documentation of this file.
1/* FIGHTSTG's stage lights. */
2
4
5/* The stage lights' task: steps their fade, then sets the three flat lights
6 and the ambient color for the layer each frame */
8 SVECTOR from;
9 SVECTOR to;
10 SVECTOR out;
11 Layer *layer;
12 s32 t;
13 s32 i;
14 s32 j;
15
16 switch (task->state) {
17 case TASK_INIT:
18 default:
19 task->t = 0x1000;
20 task->nextState(task);
21 break;
22 case TASK_DONE:
23 task->setState(task, TASK_RUN);
24 task->setSubstate(task, 1);
25 /* fallthrough */
26 case TASK_RUN:
27 switch (task->substate) {
28 case 1:
29 case 2:
30 if (task->t != 0x1000) {
31 task->t += task->tStep * GFX.funcs.getFrameTime();
32 if (task->t < 0x1000) {
33 t = task->t;
34 for (i = 0; i < 3; i++) {
35 from.vx = task->from.lights[i].vx;
36 from.vy = task->from.lights[i].vy;
37 from.vz = task->from.lights[i].vz;
38 to.vx = task->to.lights[i].vx;
39 to.vy = task->to.lights[i].vy;
40 to.vz = task->to.lights[i].vz;
41 FIGHTSTG_interp.lerp(&from, &to, t, &out);
42 task->current.lights[i].vx = out.vx;
43 task->current.lights[i].vy = out.vy;
44 task->current.lights[i].vz = out.vz;
45 from.vx = task->from.lights[i].r;
46 from.vy = task->from.lights[i].g;
47 from.vz = task->from.lights[i].b;
48 to.vx = task->to.lights[i].r;
49 to.vy = task->to.lights[i].g;
50 to.vz = task->to.lights[i].b;
51 FIGHTSTG_interp.lerp(&from, &to, t, &out);
52 task->current.lights[i].r = out.vx;
53 task->current.lights[i].g = out.vy;
54 task->current.lights[i].b = out.vz;
55 }
56 from.vx = task->from.ambient[0];
57 from.vy = task->from.ambient[1];
58 from.vz = task->from.ambient[2];
59 to.vx = task->to.ambient[0];
60 to.vy = task->to.ambient[1];
61 to.vz = task->to.ambient[2];
62 FIGHTSTG_interp.lerp(&from, &to, t, &out);
63 task->current.ambient[0] = out.vx;
64 task->current.ambient[1] = out.vy;
65 task->current.ambient[2] = out.vz;
66 } else {
67 task->t = 0x1000;
68 task->current = task->to;
69 }
70 }
71 GsSetLightMode(0);
72 for (j = 0; j < 3; j++) {
73 GsSetFlatLight(j, &task->current.lights[j]);
74 }
75 SetBackColor(task->current.ambient[0], task->current.ambient[1], task->current.ambient[2]);
76 layer = GFX.funcs.getLayer(task->layerId);
77 layer->setKeepLightMatrix(layer, 1);
78 if (task->t == 0x1000) {
79 task->nextSubstate(task);
80 }
81 break;
82 }
83 break;
84 case TASK_KILL:
85 layer = GFX.funcs.getLayer(task->layerId);
86 layer->setKeepLightMatrix(layer, 0);
87 break;
88 }
89}
90
91/* Lights.set: switches to SET at once */
93 task->current = *set;
94 task->setState(task, TASK_DONE);
95}
96
97/* Lights.fade: fades from FROM (NULL for the current lights) to TO over TIME */
98void FIGHTSTG_fadeLights(Lights *task, LightSet *from, LightSet *to, s32 time) {
99 if (from != NULL) {
100 task->from = *from;
101 } else {
102 task->from = task->current;
103 }
104 task->to = *to;
105 task->tStep = 0x1000 / time;
106 task->t = task->tStep * GFX.funcs.getFrameTime();
107 task->setState(task, TASK_DONE);
108}
109
110/* Lights.getStageLights: fight stage STAGE's lights */
113
114 return &stages[stage].lights;
115}
116
117/* Creates the stage lights (id 0x13) for layer layerId */
120 task->set = FIGHTSTG_setLights;
122 task->layerId = layerId;
124 return task;
125}
#define FILE_FIGHT_STAGES
The fight stages, the battle's backgrounds: WFIGHTTS lists them as MFSTG001-027.
Definition stage.h:14
#define BATTLE_TASK_LIGHTS
Definition types.h:22
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
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
InterpFuncs FIGHTSTG_interp
the functions that go between values
Definition interp.c:44
LightSet * FIGHTSTG_getStageLights(Lights *task, s32 stage)
Lights.getStageLights: fight stage STAGE's lights.
Definition lights.c:111
void FIGHTSTG_updateLights(Lights *task)
The stage lights' task: steps their fade, then sets the three flat lights and the ambient color for t...
Definition lights.c:7
Lights * FIGHTSTG_createLights(s32 layerId)
Creates the stage lights (id 0x13) for layer layerId.
Definition lights.c:118
void FIGHTSTG_fadeLights(Lights *task, LightSet *from, LightSet *to, s32 time)
Lights.fade: fades from FROM (NULL for the current lights) to TO over TIME.
Definition lights.c:98
void FIGHTSTG_setLights(Lights *task, LightSet *set)
Lights.set: switches to SET at once.
Definition lights.c:92
A fight stage, in FILE_FIGHT_STAGES.
Definition stage.h:24
LightSet lights
Definition stage.h:31
void *(* load)(u32 file)
Definition file.h:92
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(* setKeepLightMatrix)()
Definition gfx.h:166
A fight stage's lights: three flat lights and the ambient colour.
Definition stage.h:18
s32 ambient[3]
Definition stage.h:20
GsF_LIGHT lights[3]
Definition stage.h:19
The stage lights (FIGHTSTG_createLights), registered as BATTLE_TASK_LIGHTS: set puts a light set,...
Definition stage.h:59
LightSet from
Definition stage.h:64
s32 layerId
Definition stage.h:61
s32 state
Definition stage.h:60
void(* nextSubstate)(struct Lights *task)
Definition stage.h:60
void(* fade)(struct Lights *task, LightSet *from, LightSet *to, s32 time)
from: NULL for the current
Definition stage.h:68
void(* setState)(struct Lights *task, s32 state)
Definition stage.h:60
LightSet to
Definition stage.h:63
void(* setSubstate)(struct Lights *task, s32 substate)
Definition stage.h:60
s32 t
0-0x1000
Definition stage.h:65
void(* set)(struct Lights *task, LightSet *set)
Definition stage.h:67
LightSet *(* getStageLights)(struct Lights *task, s32 stage)
Definition stage.h:69
s32 tStep
per frame
Definition stage.h:66
LightSet current
Definition stage.h:62
void(* nextState)(struct Lights *task)
Definition stage.h:60
s32 substate
Definition stage.h:60
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