Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
camera.c
Go to the documentation of this file.
1/* The camera, which follows an actor or looks at a spot, and shakes */
2
3#include "field/field_mode.h"
4
5/* Scrolls the map layer to the camera's center, kept inside the map, and
6 shakes it while shaking with its sound */
9 MapStreamer *map;
10 Vec2 *size;
11 s32 x;
12 s32 y;
13 s32 shake;
14
15 x = task->center.x - 0xA0;
16 y = task->center.y - 0x8C;
17 if (task->hasBounds == 0) {
19 if (map != NULL) {
20 if (map->state == TASK_RUN) {
21 size = map->getSize(map);
22 task->bounds = *size;
23 task->hasBounds = 1;
24 }
25 } else if (GAME.funcs.getMode() != 0x2DE) {
26 task->bounds.x = 0x7FFF;
27 task->bounds.y = 0x7FFF;
28 } else {
29 task->bounds.x = 0x500;
30 task->bounds.y = 0x400;
31 }
32 }
33 if (x < 0) {
34 x = 0;
35 }
36 if (y < 0) {
37 y = 0;
38 }
39 if (task->bounds.x - SCREEN_WIDTH < x) {
40 x = task->bounds.x - SCREEN_WIDTH;
41 }
42 if (task->bounds.y - SCREEN_HEIGHT < y) {
43 y = task->bounds.y - SCREEN_HEIGHT;
44 }
45 shake = 0;
46 if (task->shaking != 0) {
47 task->shake = (task->shake + 1) & 3;
48 shake = task->shake + 1;
49 if (task->voice == -1) {
51 }
52 } else if (task->voice != -1) {
54 task->voice = -1;
55 }
56 layer->setScroll(layer, (FIELDSTG_shakeOffsets[shake].x + x) << 8, (FIELDSTG_shakeOffsets[shake].y + y) << 8);
57}
58
59/* The camera's update: it follows its target actor (substate 0) or looks at
60 a spot (1), panning there unless it snaps */
62 Vec2 delta;
63 Vec2 sign;
64
65 switch (task->state) {
66 default:
67 case TASK_INIT:
69 task->snap = 1;
70 if (task->target != NULL) {
71 task->nextState(task);
72 }
73 break;
74 case TASK_RUN:
75 switch (task->substate) {
76 case 0:
77 task->center.x = task->target->tile.x;
78 task->center.y = task->target->tile.y - (task->target->z >> 8);
79 if ((task->step == 0) & (task->snap == 0)) {
80 task->nextStep(task);
81 }
82 break;
83 case 1:
84 task->center.x = task->spotX;
85 task->center.y = task->spotY;
86 if ((task->step == 0) & (task->snap == 0)) {
87 task->nextStep(task);
88 }
89 break;
90 }
91 if (task->step == 1) {
92 sign.x = 1;
93 sign.y = 1;
94 delta.x = task->center.x - task->pan.x;
95 if (delta.x < 0) {
96 sign.x = -1;
97 delta.x = -delta.x;
98 }
99 delta.y = task->center.y - task->pan.y;
100 if (delta.y < 0) {
101 sign.y = -1;
102 delta.y = -delta.y;
103 }
104 if (delta.x != 0 && delta.y != 0) {
105 if (delta.x > 4) {
106 delta.x /= 4;
107 } else if (delta.x > 2) {
108 delta.x /= 2;
109 } else {
110 delta.x = 1;
111 }
112 task->center.x = task->pan.x += delta.x * sign.x;
113 if (delta.y > 4) {
114 delta.y /= 4;
115 } else if (delta.y > 2) {
116 delta.y /= 2;
117 } else {
118 delta.y = 1;
119 }
120 task->center.y = task->pan.y += delta.y * sign.y;
121 } else {
122 task->nextStep(task);
123 }
124 }
126 break;
127 case TASK_DONE:
128 break;
129 case TASK_KILL:
130 if (task->voice != -1) {
132 task->voice = -1;
133 }
134 break;
135 }
136}
137
138/* Creates the camera */
141
142 task->voice = -1;
143 return task;
144}
145
146/* Points the camera at the actor id, at once if snap */
149
150 if (task != NULL) {
151 task->unk7C = 0;
152 task->snap = snap;
153 task->targetId = id;
155 task->pan = task->center;
156 task->setSubstate(task, 0);
157 }
158}
159
160/* Points the camera at the spot (x, y), at once if snap */
161void FIELDSTG_pointCamera(s32 snap, s32 x, s32 y) {
163
164 if (task != NULL) {
165 task->unk7C = 0;
166 task->snap = snap;
167 task->spotX = x;
168 task->spotY = y;
169 task->pan = task->center;
170 task->setSubstate(task, 1);
171 }
172}
173
174/* Starts or stops the camera's shake */
177
178 if (task != NULL) {
179 task->shaking = shaking;
180 }
181}
void FIELDSTG_updateCamera(Camera *task)
The camera's update: it follows its target actor (substate 0) or looks at a spot (1),...
Definition camera.c:61
void FIELDSTG_scrollCamera(Camera *task)
Scrolls the map layer to the camera's center, kept inside the map, and shakes it while shaking with i...
Definition camera.c:7
void FIELDSTG_followWithCamera(s32 snap, s32 id)
Points the camera at the actor id, at once if snap.
Definition camera.c:147
void FIELDSTG_shakeCamera(s32 shaking)
Starts or stops the camera's shake.
Definition camera.c:175
void FIELDSTG_pointCamera(s32 snap, s32 x, s32 y)
Points the camera at the spot (x, y), at once if snap.
Definition camera.c:161
Camera * FIELDSTG_createCamera(void)
Creates the camera.
Definition camera.c:139
#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
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#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 FIELD_TASK_MAP
The ids of the field's tasks (createTaskWithId, TASK_REGISTRY.funcs.find)
Definition field_map.h:25
#define FIELD_LAYER_MAP
the map, its objects and characters, and the menus
Definition field_map.h:20
#define FIELD_TASK_CAMERA
Definition field_map.h:30
#define FIELD_TASK_ACTOR
every character (FIELDSTG_createActor)
Definition field_map.h:26
FIELDSTG.PRO: the field mode, where the player walks around the map.
#define SOUND_COMCD203
held while the camera shakes
Definition field_mode.h:70
Vec2 FIELDSTG_shakeOffsets[]
the camera's shake offsets
Definition fieldstg.c:2027
#define SCREEN_WIDTH
The screen the modes draw on (setDisplayMode, their layers' rects)
Definition gfx.h:36
#define SCREEN_HEIGHT
Definition gfx.h:37
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 z
how high it is off the ground, in 1/256 pixels (drawn that much higher)
Definition field_map.h:339
Vec2 tile
Definition field_map.h:337
The camera (FIELD_TASK_CAMERA, FIELDSTG_createCamera): it centers the field's layer on an actor or a ...
Definition field_mode.h:252
s32 step
Definition field_mode.h:253
s32 shake
the step of the shake, 0-3
Definition field_mode.h:257
s32 snap
goes to center at once instead of panning
Definition field_mode.h:263
void(* nextStep)(struct Camera *task)
Definition field_mode.h:253
s32 state
Definition field_mode.h:253
s32 spotY
Definition field_mode.h:266
void(* nextState)(struct Camera *task)
Definition field_mode.h:253
Vec2 center
where it looks
Definition field_mode.h:255
s32 unk7C
cleared with each new target; nothing reads it
Definition field_mode.h:262
s16 voice
of the shaking sound, or -1
Definition field_mode.h:258
Vec2 pan
where it looks while it pans to center
Definition field_mode.h:259
s32 shaking
Definition field_mode.h:256
Vec2 bounds
the map's size
Definition field_mode.h:261
Actor * target
the actor it follows (substate 0)
Definition field_mode.h:254
s32 substate
Definition field_mode.h:253
void(* setSubstate)(struct Camera *task, s32 substate)
Definition field_mode.h:253
s32 spotX
the spot it looks at (substate 1)
Definition field_mode.h:265
s32 hasBounds
Definition field_mode.h:260
s32 targetId
the target's character (Actor.key1)
Definition field_mode.h:264
s32(* getMode)(void)
Definition game_state.h:19
GameFuncs funcs
Definition game_state.h:582
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
GfxFuncs funcs
Definition gfx.h:77
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* setScroll)()
Definition gfx.h:149
The task that streams the map's tiles from the CD around the view (FIELDSTG_runMapStreamer,...
Definition field_mode.h:487
Vec2 *(* getSize)(struct MapStreamer *)
in pixels (FIELDSTG_getMapSize)
Definition field_mode.h:502
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
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
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