Alchemy
Loading...
Searching...
No Matches

camera.c

Go to the documentation of this file.
1/// @file
2/// The event camera.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// The event command "camera follow actor": the camera (the event's view
8/// centre) follows actor. Unless keepPosition is set it jumps there at once
9/// and, off the world map, the map is redrawn around it.
10void Camera_FollowActor(s32 actor, s32 keepPosition) {
11 struct ObjectRuntime *subject;
12 struct ObjectRuntime *camera;
13 struct FieldWork *work;
14 struct MapScrollWork *map;
15
16 subject = ObjectTable_Get(actor);
17 work = Runtime_AllocateBlock(HEAP_SLOT_EVENT, sizeof(struct FieldWork));
18 camera = work->camera;
19 map = gMapWork[0];
20 if (subject != 0) {
21 map->origin = &camera->x;
23 (s32)subject);
24 if (keepPosition == 0) {
25 SET_POSITION(camera, subject->x, subject->y, subject->z);
26 WaitFrames(1);
27 if (work->mode != MODE_WORLD_MAP) {
29 }
30 }
31 }
32}
33
34/// The event command "camera set speed": the camera's top speed and
35/// acceleration, 16.16 pixels per frame.
36void Camera_SetSpeedParameters(s32 speedLimit, s32 acceleration) {
37 struct FieldWork *owner =
39 owner->camera->speedLimit = speedLimit;
40 owner->camera->acceleration = acceleration;
41}
42
43/// The event command "camera move to": sends the camera to the requested axes,
44/// 16.16 pixels (-1 keeps that axis), kept far enough inside the map that the
45/// screen never shows past its edge. With glide 0 the camera jumps there at
46/// once; otherwise it travels at its own speed.
47void Camera_MoveWithinMapBounds(s32 requestedX, s32 requestedY, s32 requestedZ,
48 s32 glide) {
49 s32 shouldGlide;
50 struct FieldWork *runtimeBlock;
51 s32 minimumX;
52 s32 minimumZ;
53 s32 maximumX;
54 s32 cameraY;
55 s32 maximumZ;
56 s32 positionX;
57 s32 positionZ;
58 s32 positionY;
59 struct MapScrollWork *map;
60 struct ObjectRuntime *camera;
61
62 positionX = requestedX;
63 positionY = requestedY;
64 shouldGlide = glide;
65 positionZ = requestedZ;
66 runtimeBlock =
68 camera = runtimeBlock->camera;
69 map = gMapWork[0];
70
71 // Half a screen (120 by 64 to 96 pixels) inside the map's bounds.
72 minimumX = map->minX + 0x780000;
73 cameraY = camera->y;
74 minimumZ = map->minY + cameraY + 0x600000;
75 maximumX = map->maxX + 0xFF880000;
76 maximumZ = map->maxY + cameraY + 0xFFC00000;
77 map->origin = &camera->x;
79 if (positionX == -1) {
80 positionX = camera->x;
81 }
82 if (positionY == -1) {
83 positionY = camera->y;
84 }
85 if (positionZ == -1) {
86 positionZ = camera->z;
87 }
88 if (positionX < minimumX) {
89 positionX = minimumX;
90 }
91 if (positionZ < minimumZ) {
92 positionZ = minimumZ;
93 }
94 if (positionX > maximumX) {
95 positionX = maximumX;
96 }
97 if (positionZ > maximumZ) {
98 positionZ = maximumZ;
99 }
100 if (shouldGlide == 0) {
101 SET_POSITION(camera, positionX, positionY, positionZ);
102 WaitFrames(1U);
103 if (runtimeBlock->mode != MODE_WORLD_MAP) {
105 }
106 } else {
107 Object_SetMoveTargetFar(camera, positionX, positionY, positionZ);
108 }
109}
110
111/// The event command "camera move to actor": Camera_MoveWithinMapBounds to the
112/// actor's x and z.
114 struct ObjectRuntime *subject;
115
116 subject = ObjectTable_Get(actor);
117 Runtime_AllocateBlock(0x1B, 0xCCC);
118 if (subject != NULL) {
119 Camera_MoveWithinMapBounds(subject->x, -1, subject->z, glide);
120 }
121}
122
123/// The event command "camera wait for move": waits (at most 600 frames) for
124/// the camera to arrive, then 2 frames more.
127 HEAP_SLOT_EVENT, sizeof(struct FieldWork)))
128 ->camera);
130}
131
132/// The event command "get view centre": returns the camera object.
134 return (struct FieldActor *)((struct FieldWork *)Runtime_AllocateBlock(
135 HEAP_SLOT_EVENT, sizeof(struct FieldWork)))
136 ->camera;
137}
138
139/// Makes the camera follow target; unless keepCurrentPosition is set it jumps
140/// there at once.
142 s32 keepCurrentPosition) {
143 struct ObjectRuntime *camera;
144
146 sizeof(struct FieldWork)))
147 ->camera;
148 if (target != NULL) {
150 camera->linkedObject = target;
151 if (keepCurrentPosition == 0) {
152 SET_POSITION(camera, target->x, target->y, target->z);
153 }
154 }
155}
void * ObjectTable_Get(u32 actorIndex)
Returns the actor in slot index (0 to 65), or NULL.
Definition actors.c:462
void Camera_MoveWithinMapBounds(s32 requestedX, s32 requestedY, s32 requestedZ, s32 glide)
The event command "camera move to": sends the camera to the requested axes, 16.16 pixels (-1 keeps th...
Definition camera.c:47
void Camera_WaitForArrival(void)
The event command "camera wait for move": waits (at most 600 frames) for the camera to arrive,...
Definition camera.c:125
void Camera_SetSpeedParameters(s32 speedLimit, s32 acceleration)
The event command "camera set speed": the camera's top speed and acceleration, 16....
Definition camera.c:36
struct FieldActor * Camera_GetEventObject(void)
The event command "get view centre": returns the camera object.
Definition camera.c:133
void Camera_FollowActor(s32 actor, s32 keepPosition)
The event command "camera follow actor": the camera (the event's view centre) follows actor.
Definition camera.c:10
UNUSED void Camera_FollowObject(struct ObjectRuntime *target, s32 keepCurrentPosition)
Makes the camera follow target; unless keepCurrentPosition is set it jumps there at once.
Definition camera.c:141
void Object_PlaceCurrentWithinCameraBounds(s32 actor, s32 glide)
The event command "camera move to actor": Camera_MoveWithinMapBounds to the actor's x and z.
Definition camera.c:113
void ObjectDispatch_StartCameraFar(struct DispatchObject *obj, s32 arg)
void Object_SetMoveTargetFar(struct ObjectRuntime *object, s32 x, s32 y, s32 z)
void FieldObject_WaitForMoveFar(void *fieldObject)
void Map_CenterOnFollowedPointFar(void)
void ObjectDispatch_StartIdleFar(struct DispatchObject *obj)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
void * gMapWork[]
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
@ HEAP_SLOT_EVENT
Definition heap_state.h:40
#define SET_POSITION(p, px, py, pz)
Sets the position or the velocity of a particle, a piece of debris or an object in one statement.
Definition macros.h:16
void FieldEvent_WaitFrames(s32 frames)
The event command "wait": waits the requested frames, unless debug fast forward (Event_UpdateDebugSki...
Definition events.c:55
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define NULL
Definition bilibin.h:6
A field object as the object dispatcher's far calls take it.
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
Full event work allocated by Field_RunScene (heap slot 27).
struct ObjectRuntime * camera
the object the map view follows
s16 mode
MODE_WORLD_MAP (3) on the world map.
The field map's work: the followed position, screen shake, tile animations, blend script,...
Definition map_scroll.h:27
s32 * origin
The followed point, read as x, height and z in 16.16 fixed-point pixels; Camera_FollowActor points it...
Definition map_scroll.h:30
s32 maxY
16.16 fixed-point pixels
Definition map_scroll.h:41
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
s32 x
16.16 fixed-point pixels
s32 speedLimit
16.16 fixed-point pixels per frame
s32 y
16.16 fixed-point pixels
struct ObjectRuntime * linkedObject
The object its action script follows or faces.
signed int s32
Definition types.h:14
#define UNUSED
Definition types.h:22
#define MODE_WORLD_MAP
the world map
Definition object.h:78