Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
sprite_anim.c
Go to the documentation of this file.
1/* FIGHTSTG's sprite animations, the frames of a 2D effect. */
2
4
5/* Empty, and nothing calls it */
6void FIGHTSTG_nop(void) {
7}
8
9/* A layer callback that draws a sprite animation's frame: at its projected
10 position, or at a screen position when its z is 0x7FFF or -1, with its
11 scale, CLUT row and rotation. The match depends on taking the task as
12 void * */
13void FIGHTSTG_drawSpriteAnim(void *arg, Layer *layer) {
14 SpriteAnim *task = arg;
15 ShortVec3 screen;
16 SpriteDrawer drawer;
17
18 if (task->pos.vz != 0x7FFF && task->pos.vz != -1) {
19 FIGHTSTG_battle.project(layer, &task->pos, &screen);
20 } else {
21 screen.x = task->pos.vx;
22 screen.y = task->pos.vy;
23 if (task->pos.vz != 0x7FFF) {
24 screen.z = 0xFFF;
25 } else {
26 screen.z = 0;
27 }
28 }
29 screen.x += task->x;
30 screen.y += task->y;
31 initSpriteDrawer(&drawer);
32 drawer.setLayer(layer, screen.z);
33 drawer.setTexture(task->texPos.x, task->texPos.y);
34 if (task->scale.both != 0x10001000) {
35 drawer.setScale(task->scale.v[0], task->scale.v[1], 0);
36 }
37 if (task->clutRow != 0) {
38 drawer.setClutRow(task->clutRow);
39 }
40 if (task->rot.both != 0 || task->rotZ != 0) {
41 drawer.setRotation(task->rot.v[0], task->rot.v[1], task->rotZ);
42 }
43 drawer.setPivot(screen.x, screen.y);
44 drawer.draw(FILE_CACHE.getEntry(task->sheet), task->frame, screen.x, screen.y);
45}
46
47/* A frame-by-frame animation of a 2D effect: reads its flags, stride,
48 duration and first values from data, then each frame the values its flags
49 pick (frame, CLUT row, offset, scale, rotation) and has
50 FIGHTSTG_drawSpriteAnim draw it, until its duration is over */
52 s16 *data;
53 s32 i;
54
55 switch (task->state) {
56 case TASK_INIT:
57 default:
58 task->flags = *task->data++;
59 task->stride = *task->data++;
60 task->duration = *task->data++;
61 for (i = 0; i < 9; i++) {
62 (&task->frame)[i] = *task->data++;
63 }
64 task->nextState(task);
65 /* fallthrough */
66 case TASK_RUN:
67 data = task->data + task->time * task->stride;
68 if (task->flags & 1) {
69 task->frame = *data++;
70 }
71 if (task->flags & 2) {
72 task->clutRow = *data++;
73 }
74 if (task->flags & 4) {
75 task->x = *data++;
76 }
77 if (task->flags & 8) {
78 task->y = *data++;
79 }
80 if (task->flags & 0x10) {
81 task->scale.v[0] = *data++;
82 }
83 if (task->flags & 0x20) {
84 task->scale.v[1] = *data++;
85 }
86 if (task->flags & 0x40) {
87 task->rot.v[0] = *data++;
88 }
89 if (task->flags & 0x80) {
90 task->rot.v[1] = *data++;
91 }
92 if (task->flags & 0x100) {
93 task->rotZ = *data;
94 }
95 if (task->scale.v[0] != 0 && task->scale.v[1] != 0) {
96 Layer *layer = GFX.funcs.getLayer(task->layerId);
97
98 layer->addCallback(layer, FIGHTSTG_drawSpriteAnim, task);
99 }
100 task->time += FIGHTSTG_battle.frames;
101 if (task->time >= task->duration) {
102 task->setState(task, TASK_DONE);
103 }
104 break;
105 case TASK_DONE:
106 task->nextState(task);
107 break;
108 case TASK_KILL:
109 break;
110 }
111}
112
113/* Creates a sprite animation from data at pos, with frames of sheet
114 (textures at texPos) on layer layerId */
115SpriteAnim *FIGHTSTG_createSpriteAnim(s16 *data, SVECTOR *pos, s32 sheet, Vec2 *texPos, s32 layerId) {
117
118 task->data = data;
119 task->pos = *pos;
120 task->sheet = sheet;
121 task->texPos = *texPos;
122 task->layerId = layerId;
123 return task;
124}
Battle FIGHTSTG_battle
the battle: its fighters, speed and drawing functions
Definition battle.c:16
FIGHTSTG.PRO: the battle.
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
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
void FIGHTSTG_updateSpriteAnim(SpriteAnim *task)
A frame-by-frame animation of a 2D effect: reads its flags, stride, duration and first values from da...
Definition sprite_anim.c:51
SpriteAnim * FIGHTSTG_createSpriteAnim(s16 *data, SVECTOR *pos, s32 sheet, Vec2 *texPos, s32 layerId)
Creates a sprite animation from data at pos, with frames of sheet (textures at texPos) on layer layer...
void FIGHTSTG_drawSpriteAnim(void *arg, Layer *layer)
A layer callback that draws a sprite animation's frame: at its projected position,...
Definition sprite_anim.c:13
void FIGHTSTG_nop(void)
Empty, and nothing calls it.
Definition sprite_anim.c:6
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
s32 frames
since the last update
Definition battle.h:239
void(* project)(Layer *layer, SVECTOR *pos, ShortVec3 *out)
FIGHTSTG_projectPoint.
Definition battle.h:244
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
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(* addCallback)()
Definition gfx.h:161
A position or rotation, without the SVECTOR pad.
Definition model.h:14
s16 x
Definition model.h:15
s16 z
Definition model.h:17
s16 y
Definition model.h:16
One animation of a 2D effect (FIGHTSTG_createSpriteAnim), drawn by a layer callback.
Definition effect.h:64
void(* setState)(struct SpriteAnim *task, s32 state)
Definition effect.h:65
SVECTOR pos
vz 0x7FFF: on screen in front, -1: on screen
Definition effect.h:67
void(* nextState)(struct SpriteAnim *task)
Definition effect.h:65
s16 x
Definition effect.h:77
s16 y
Definition effect.h:78
s32 sheet
Definition effect.h:68
s32 time
Definition effect.h:71
s32 duration
Definition effect.h:74
Vec2 texPos
Definition effect.h:69
s32 layerId
Definition effect.h:70
s32 stride
of a frame's values
Definition effect.h:73
s16 clutRow
Definition effect.h:76
s32 state
Definition effect.h:65
union SpriteAnim::@1 rot
s16 frame
Definition effect.h:75
s16 v[2]
x, y; 0x1000 = 1.0
Definition effect.h:80
s16 * data
Definition effect.h:66
s32 flags
Definition effect.h:72
union SpriteAnim::@0 scale
s32 both
to test the two at once
Definition effect.h:81
s16 rotZ
Definition effect.h:87
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
void(* setLayer)()
(layer, depth)
Definition gfx.h:245
void(* setPivot)()
(x, y)
Definition gfx.h:250
void(* setScale)()
(x, y, z), ONE = 1.0
Definition gfx.h:248
void(* setClutRow)()
(row)
Definition gfx.h:247
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setRotation)()
(x, y, z); no prototype: callers would truncate s16 args
Definition gfx.h:249
void(* setTexture)()
(x, y)
Definition gfx.h:242
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105