Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
battle_camera.c
Go to the documentation of this file.
1/* FIGHTSTG's battle camera and its views of the fighters. */
2
4
5/* The battle camera's task: fades its view from `from` to `to` (position,
6 reference, translation, rotation, roll and projection) by tStep a frame,
7 sets it on its layer every frame and goes to the next substate once there;
8 set and fade restart it through TASK_DONE */
10 SVECTOR from;
11 SVECTOR to;
12 SVECTOR out;
13 GsCOORDINATE2 coord;
14 GsRVIEW2 view;
15 Layer *layer;
16 s32 t;
17
18 switch (task->state) {
19 case TASK_INIT:
20 default:
21 task->t = 0x1000;
22 task->nextState(task);
23 break;
24 case TASK_DONE:
25 task->setState(task, TASK_RUN);
26 task->setSubstate(task, 1);
27 /* fallthrough */
28 case TASK_RUN:
29 switch (task->substate) {
30 case 1:
31 case 2:
32 if (task->t != 0x1000) {
33 task->t += (task->tStep >> 8) * GFX.funcs.getFrameTime();
34 t = task->t;
35 if (t < 0x1000) {
36 from.vx = task->from.vpx;
37 from.vy = task->from.vpy;
38 from.vz = task->from.vpz;
39 to.vx = task->to.vpx;
40 to.vy = task->to.vpy;
41 to.vz = task->to.vpz;
42 FIGHTSTG_interp.lerp(&from, &to, t, &out);
43 task->current.vpx = out.vx;
44 task->current.vpy = out.vy;
45 task->current.vpz = out.vz;
46 from.vx = task->from.vrx;
47 from.vy = task->from.vry;
48 from.vz = task->from.vrz;
49 to.vx = task->to.vrx;
50 to.vy = task->to.vry;
51 to.vz = task->to.vrz;
52 FIGHTSTG_interp.lerp(&from, &to, t, &out);
53 task->current.vrx = out.vx;
54 task->current.vry = out.vy;
55 task->current.vrz = out.vz;
56 from.vx = task->from.tx;
57 from.vy = task->from.ty;
58 from.vz = task->from.tz;
59 to.vx = task->to.tx;
60 to.vy = task->to.ty;
61 to.vz = task->to.tz;
62 FIGHTSTG_interp.lerp(&from, &to, t, &out);
63 task->current.tx = out.vx;
64 task->current.ty = out.vy;
65 task->current.tz = out.vz;
66 FIGHTSTG_interp.lerp(&task->from.rot, &task->to.rot, t, &out);
67 task->current.rot.vx = out.vx;
68 task->current.rot.vy = out.vy;
69 task->current.rot.vz = out.vz;
70 from.vx = task->from.rz;
71 from.vy = task->from.proj;
72 from.vz = 0;
73 to.vx = task->to.rz;
74 to.vy = task->to.proj;
75 to.vz = 0;
76 FIGHTSTG_interp.lerp(&from, &to, t, &out);
77 task->current.rz = out.vx;
78 task->current.proj = out.vy;
79 } else {
80 task->t = 0x1000;
81 task->current = task->to;
82 }
83 }
84 RotMatrixYXZ_gte(&task->current.rot, &coord.coord);
85 coord.coord.t[0] = task->current.tx;
86 coord.coord.t[1] = task->current.ty;
87 coord.coord.t[2] = task->current.tz;
88 coord.flg = 0;
89 coord.param = NULL;
90 coord.super = NULL;
91 coord.sub = NULL;
92 view.vpx = task->current.vpx;
93 view.vpy = task->current.vpy;
94 view.vpz = task->current.vpz;
95 view.vrx = task->current.vrx;
96 view.vry = task->current.vry;
97 view.vrz = task->current.vrz;
98 view.rz = task->current.rz << 12;
99 view.super = &coord;
100 GsSetRefView2(&view);
101 layer = GFX.funcs.getLayer(task->layerId);
102 layer->setKeepView(layer, 1, task->current.proj);
103 if (task->t == 0x1000) {
104 task->nextSubstate(task);
105 }
106 break;
107 }
108 break;
109 case TASK_KILL:
110 layer = GFX.funcs.getLayer(task->layerId);
111 layer->setKeepView(layer, 0, 0);
112 break;
113 }
114}
115
116/* BattleCamera.set: puts the battle camera at view */
118 task->current = *view;
119 task->t = 0x1000;
120 task->setState(task, TASK_DONE);
121}
122
123/* BattleCamera.fade: fades the battle camera from `from` (or where it is) to
124 `to` over time frames */
126 if (from != NULL) {
127 task->from = *from;
128 } else {
129 task->from = task->current;
130 }
131 task->to = *to;
132 task->tStep = 0x100000 / time;
133 task->t = 0;
134 task->setState(task, TASK_DONE);
135}
136
137/* The view of a fighter's camera (id as Models.getFighter takes it), which ends
138 the battle camera's fade */
140 Models *models;
141 s32 fighter;
142 FighterInfo *info;
143 FighterInfoEnemy *enemy;
144
145 /* the match depends on the do-while and its breaks, the early exit that
146 the stages' event code uses too */
147 do {
148 models = TASK_REGISTRY.funcs.find(BATTLE_TASK_MODELS, -1, -1);
149 if (models == NULL) {
150 break;
151 }
152 fighter = models->getFighter(models, id);
153 if (fighter == 0) {
154 break;
155 }
156 if (!(id & 0xF0)) {
157 info = FIGHTSTG_fighterCache.funcs.getInfo(fighter);
158 FIGHTSTG_fighterView.vpx = info->camPos[camera].x;
159 FIGHTSTG_fighterView.vpy = -info->camPos[camera].y;
160 FIGHTSTG_fighterView.vpz = -info->camPos[camera].z;
161 FIGHTSTG_fighterView.vrx = info->camRef[camera].x;
162 FIGHTSTG_fighterView.vry = -info->camRef[camera].y;
163 FIGHTSTG_fighterView.vrz = -info->camRef[camera].z;
164 FIGHTSTG_fighterView.proj = info->camProj[camera];
165 } else {
167 FIGHTSTG_fighterView.vpx = enemy->camPos[camera].x;
168 FIGHTSTG_fighterView.vpy = -enemy->camPos[camera].y;
169 FIGHTSTG_fighterView.vpz = -enemy->camPos[camera].z;
170 FIGHTSTG_fighterView.vrx = enemy->camRef[camera].x;
171 FIGHTSTG_fighterView.vry = -enemy->camRef[camera].y;
172 FIGHTSTG_fighterView.vrz = -enemy->camRef[camera].z;
173 FIGHTSTG_fighterView.proj = enemy->camProj[camera];
174 }
182 task->setState(task, TASK_DONE);
183 } while (0);
184 return &FIGHTSTG_fighterView;
185}
186
187/* The view of the enemy's last camera */
189 Models *models;
190 s32 fighter;
191
192 /* the match depends on the do-while and its breaks, as FIGHTSTG_getFighterView's */
193 do {
194 models = TASK_REGISTRY.funcs.find(BATTLE_TASK_MODELS, -1, -1);
195 if (models == NULL) {
196 break;
197 }
198 fighter = models->getFighter(models, 0x10);
199 if (fighter == 0) {
200 break;
201 }
204 } while (0);
205 return &FIGHTSTG_fighterView;
206}
207
208/* Creates the battle camera (BATTLE_TASK_CAMERA) on a layer */
FighterCache FIGHTSTG_fighterCache
the fighters' data, loaded one at a time
Definition battle.c:21
#define BATTLE_TASK_CAMERA
Definition types.h:21
#define BATTLE_TASK_MODELS
the fighters'
Definition types.h:23
CameraView * FIGHTSTG_getFighterView(BattleCamera *task, s32 id, s32 camera)
The view of a fighter's camera (id as Models.getFighter takes it), which ends the battle camera's fad...
void FIGHTSTG_updateBattleCamera(BattleCamera *task)
The battle camera's task: fades its view from from to to (position, reference, translation,...
CameraView * FIGHTSTG_getEnemyView(BattleCamera *task)
The view of the enemy's last camera.
void FIGHTSTG_setBattleCameraView(BattleCamera *task, CameraView *view)
BattleCamera.set: puts the battle camera at view.
void FIGHTSTG_fadeBattleCamera(BattleCamera *task, CameraView *from, CameraView *to, s32 time)
BattleCamera.fade: fades the battle camera from from (or where it is) to to over time frames.
BattleCamera * FIGHTSTG_createBattleCamera(s32 layerId)
Creates the battle camera (BATTLE_TASK_CAMERA) on a layer.
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
InterpFuncs FIGHTSTG_interp
the functions that go between values
Definition interp.c:44
CameraView FIGHTSTG_fighterView
the view FIGHTSTG_getFighterView makes
TaskRegistry TASK_REGISTRY
Definition registry.c:122
The battle camera (FIGHTSTG_createBattleCamera), registered as BATTLE_TASK_CAMERA on a layer: set put...
Definition camera.h:66
s32 t
0-0x1000
Definition camera.h:72
CameraView current
Definition camera.h:69
s32 substate
Definition camera.h:67
CameraView to
Definition camera.h:70
s32 layerId
Definition camera.h:68
s32 state
Definition camera.h:67
CameraView *(* getFighterView)(struct BattleCamera *task, s32 id, s32 camera)
Definition camera.h:77
s32 tStep
per frame, << 8
Definition camera.h:73
void(* setState)(struct BattleCamera *task, s32 state)
Definition camera.h:67
void(* nextSubstate)(struct BattleCamera *task)
Definition camera.h:67
void(* setSubstate)(struct BattleCamera *task, s32 substate)
Definition camera.h:67
CameraView *(* getEnemyView)(struct BattleCamera *task)
Definition camera.h:76
CameraView from
Definition camera.h:71
void(* set)(struct BattleCamera *task, CameraView *view)
Definition camera.h:74
void(* fade)(struct BattleCamera *task, CameraView *from, CameraView *to, s32 time)
from: NULL for the current
Definition camera.h:75
void(* nextState)(struct BattleCamera *task)
Definition camera.h:67
Where the battle camera looks from and to, as a GsRVIEW2 with the transform of its coordinate system.
Definition camera.h:49
s32 vry
Definition camera.h:54
s32 vpy
Definition camera.h:51
s32 tz
Definition camera.h:58
s32 tx
Definition camera.h:56
s32 vrx
Definition camera.h:53
s32 rz
the roll, in degrees
Definition camera.h:60
s32 ty
Definition camera.h:57
SVECTOR rot
Definition camera.h:59
s32 vpx
Definition camera.h:50
s32 vpz
Definition camera.h:52
s32 proj
the projection distance
Definition camera.h:61
s32 vrz
Definition camera.h:55
FighterInfo * enemyInfo
Definition model.h:271
FighterInfoFuncs funcs
Definition model.h:272
An enemy's FighterInfo: it has 3 cameras where a partner has 12.
Definition model.h:242
ShortVec3 camPos[3]
Definition model.h:250
s16 camProj[3]
Definition model.h:252
ShortVec3 camRef[3]
Definition model.h:251
FighterInfo *(* getInfo)(s32 id)
Definition model.h:258
A fighter's entry in its file, from FIGHTSTG_fighterCache.funcs.getInfo.
Definition model.h:225
s16 camProj[12]
Definition model.h:236
ShortVec3 camPos[12]
the cameras that look at it; an enemy has 3 of each and then their count
Definition model.h:233
ShortVec3 camRef[12]
Definition model.h:235
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(* setKeepView)()
Definition gfx.h:164
The fighters' models (FIGHTSTG_createModels), registered as BATTLE_TASK_MODELS: up to four,...
Definition model.h:284
s32(* getFighter)(struct Models *task, s32 id)
Definition model.h:291
s16 x
Definition model.h:15
s16 z
Definition model.h:17
s16 y
Definition model.h:16
void *(* find)(s32 id, s32 key1, s32 key2)
Definition task.h:18
TaskFuncs funcs
Definition task.h:76
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