Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
stream.c
Go to the documentation of this file.
1/* The tasks that read a tile of the map from the CD and draw it */
2
3#include "field/field_mode.h"
4
5/* Marks a stream task used now (FIELDSTG_findOldestStream) */
7 task->time = GFX.funcs.getTime();
8}
9
10/* Reads a frame of the map file, a tile, from the CD, unless it has it
11 already */
12void FIELDSTG_seekStream(StreamTask *task, s32 frame, s32 size) {
13 if (task->frame != frame) {
14 task->frame = frame;
15 task->loaded = 0;
16 task->loadedSlot = -1;
17 task->sector = frame * task->frameSectors + 1;
18 CD_READER.read(task->file, task->sector, size, task->buffer, &task->loaded);
19 task->loadedTime = 0;
20 }
22}
23
24/* Whether a stream task's read is done */
26 return task->loaded;
27}
28
29/* Draws a stream task's tile at (x, y) on a layer: its sprites at the three
30 depths */
31void FIELDSTG_drawStream(StreamTask *task, Layer *layer, s32 x, s32 y) {
32 Vec2 scroll;
33 PrimPtr prim;
34 u_long *ot;
35 s32 i;
36 s32 j;
37
38 layer->getScroll(layer, &scroll);
39 prim.any = GFX.funcs.getPrim();
40 for (i = 0; i < 3; i++) {
41 ot = layer->getOtEntry(layer, FIELDSTG_spriteDepths[i]);
42 for (j = 0; j < 5; j++) {
43 if (task->sprites[i][j].visible) {
44 SetSprt(prim.sprt);
45 if (i == 2 || FIELDSTG_state.spriteColor.cd != 0) {
46 prim.sprt->r0 = FIELDSTG_state.spriteColor.r;
47 prim.sprt->g0 = FIELDSTG_state.spriteColor.g;
48 prim.sprt->b0 = FIELDSTG_state.spriteColor.b;
49 } else {
50 prim.sprt->r0 = 0x80;
51 prim.sprt->g0 = 0x80;
52 prim.sprt->b0 = 0x80;
53 }
54 prim.sprt->x0 = task->sprites[i][j].x + x - scroll.x;
55 prim.sprt->y0 = task->sprites[i][j].y + y - scroll.y;
56 prim.sprt->w = task->sprites[i][j].w;
57 prim.sprt->h = task->sprites[i][j].h;
58 prim.sprt->clut = getClut(task->clutX, task->clutY);
59 prim.sprt->u0 = task->sprites[i][j].u;
60 prim.sprt->v0 = task->imageY + task->sprites[i][j].v;
61 addPrim(ot, prim.any);
62 prim.sprt++;
63 }
64 }
65 SetDrawTPage(prim.tpage, 0, 1, GetTPage(1, 0, task->imageX, task->imageY));
66 addPrim(ot, prim.any);
67 prim.tpage++;
68 }
69 GFX.funcs.setPrim(prim.any);
71}
72
73/* Decompresses a stream task's tile into slot */
75 task->slot = slot;
76 task->source = source;
77 source->start(source, task->buffer, 0x2800);
78 task->setSubstate(task, 1);
79}
80
81/* Takes a decompressed tile's sprites and loads its image into its slot's
82 VRAM */
84 TimLoader loader;
85 s32 i;
86 s32 j;
87 s32 count;
88 s32 *data = task->data;
89 s32 slot = task->slot;
90 s16 *p = (s16 *)(data + 1); /* the sprites of the three depths, after the first word */
91
92 for (i = 0; i < 3; i++) {
93 count = *(s32 *)p; /* a word: how many, then six halfwords each */
94 p += 2;
95 for (j = 0; j < count; j++) {
96 task->sprites[i][j].visible = 1;
97 task->sprites[i][j].x = *p++;
98 task->sprites[i][j].y = *p++;
99 task->sprites[i][j].u = *p++;
100 task->sprites[i][j].v = *p++;
101 task->sprites[i][j].w = *p++;
102 task->sprites[i][j].h = *p++;
103 }
104 for (; j < 5; j++) {
105 task->sprites[i][j].visible = 0;
106 }
107 }
108 task->loadedSlot = slot;
109 task->imageX = FIELDSTG_slotImages[slot].x;
110 task->imageY = FIELDSTG_slotImages[slot].y;
111 task->clutX = 0;
112 task->clutY = slot + 0xF0;
113 initTimLoader(&loader);
114 loader.setImagePos(task->imageX, task->imageY);
115 loader.setClutPos(task->clutX, task->clutY);
116 loader.load(FILE_CACHE.getArchiveEntry(0, data));
118}
119
120/* Forgets a stream task's slot */
122 task->loadedSlot = -1;
123}
124
125/* A stream task's slot, or -1 */
127 return task->loadedSlot;
128}
129
130/* A stream task's frame, the tile it holds */
132 return task->frame;
133}
134
135/* A stream task's update: takes its tile once decompressed, and notes when
136 its read ends */
138 switch (task->state) {
139 case TASK_INIT:
140 default:
141 task->nextState(task);
142 break;
143 case TASK_RUN:
144 switch (task->substate) {
145 case 0:
146 break;
147 case 1:
148 task->data = task->source->getData(task->source);
149 if (task->data != NULL) {
151 task->setSubstate(task, 0);
152 }
153 break;
154 }
155 if (task->loadedTime == 0 && task->loaded != 0) {
156 task->loadedTime = GFX.funcs.getTime();
157 }
158 break;
159 case TASK_DONE:
160 break;
161 case TASK_KILL:
162 HEAP.free(task->buffer);
163 break;
164 }
165}
166
167/* Creates a stream task of a file, with a buffer of size */
170
179 task->file = file;
180 task->frameSectors = size / 2048;
181 task->buffer = HEAP.allocHigh(size, 2);
182 task->frame = -1;
183 task->loadedSlot = -1;
184 task->loaded = 1;
185 return task;
186}
CdReader CD_READER
The CD reader.
Definition cd_reader.c:10
#define NULL
Definition common.h:17
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
FIELDSTG.PRO: the field mode, where the player walks around the map.
Vec2 FIELDSTG_slotImages[]
VRAM position of each StreamTask slot's image.
Definition fieldstg.c:1505
s32 FIELDSTG_spriteDepths[]
depth of each layer of a StreamTask's sprites
Definition fieldstg.c:1502
FieldState FIELDSTG_state
Definition fieldstg.c:2641
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
void FIELDSTG_loadStreamSprites(StreamTask *task)
Takes a decompressed tile's sprites and loads its image into its slot's VRAM.
Definition stream.c:83
s32 FIELDSTG_isStreamLoaded(StreamTask *task)
Whether a stream task's read is done.
Definition stream.c:25
void FIELDSTG_updateStream(StreamTask *task)
A stream task's update: takes its tile once decompressed, and notes when its read ends.
Definition stream.c:137
s32 FIELDSTG_getStreamFrame(StreamTask *task)
A stream task's frame, the tile it holds.
Definition stream.c:131
void FIELDSTG_touchStream(StreamTask *task)
Marks a stream task used now (FIELDSTG_findOldestStream)
Definition stream.c:6
void FIELDSTG_setStreamSource(StreamTask *task, s32 slot, Decompressor *source)
Decompresses a stream task's tile into slot.
Definition stream.c:74
StreamTask * FIELDSTG_createStream(s32 size, s32 file)
Creates a stream task of a file, with a buffer of size.
Definition stream.c:168
void FIELDSTG_seekStream(StreamTask *task, s32 frame, s32 size)
Reads a frame of the map file, a tile, from the CD, unless it has it already.
Definition stream.c:12
s32 FIELDSTG_getStreamSlot(StreamTask *task)
A stream task's slot, or -1.
Definition stream.c:126
void FIELDSTG_drawStream(StreamTask *task, Layer *layer, s32 x, s32 y)
Draws a stream task's tile at (x, y) on a layer: its sprites at the three depths.
Definition stream.c:31
void FIELDSTG_clearStreamSlot(StreamTask *task)
Forgets a stream task's slot.
Definition stream.c:121
void(* read)(s32 file, s32 offset, s32 size, void *buf, s32 *done)
Definition file.h:64
Expands "RLEN" data (a run-length encoding: a byte n < 0x80 copies n bytes, n | 0x80 repeats the next...
Definition file.h:110
void(* start)()
Definition file.h:123
void *(* getData)()
Definition file.h:122
CVECTOR spriteColor
the field's sprites' color, unless cd is 0
Definition field_map.h:458
void *(* getArchiveEntry)(s32 index, void *archive)
Definition file.h:97
void *(* getPrim)(void)
Definition gfx.h:19
void(* setPrim)(void *next)
Definition gfx.h:20
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
void *(* allocHigh)(s32 size, s32 tag)
from the end of the heap
Definition heap.h:30
void(* free)(void *ptr)
Definition heap.h:27
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
void(* getScroll)()
Definition gfx.h:148
u_long *(* getOtEntry)(struct Layer *, s32 depth)
Definition gfx.h:155
A task that reads the frames of a file from the disc (FIELDSTG_createStream)
Definition field_mode.h:424
s32 * data
the decompressed tile: its sprites, then its image
Definition field_mode.h:442
s32(* getFrame)(struct StreamTask *task)
Definition field_mode.h:447
s32(* getSlot)(struct StreamTask *task)
Definition field_mode.h:448
void(* seek)(struct StreamTask *task, s32 frame, s32 size)
Definition field_mode.h:443
void(* setSource)(struct StreamTask *task, s32 slot, Decompressor *source)
Definition field_mode.h:446
void(* clearSlot)(struct StreamTask *task)
Definition field_mode.h:449
void * buffer
Definition field_mode.h:432
void(* updateTime)(struct StreamTask *task)
Definition field_mode.h:450
void(* draw)(struct StreamTask *task, Layer *layer, s32 x, s32 y)
Definition field_mode.h:445
StreamSprite sprites[3][5]
Definition field_mode.h:439
Decompressor * source
what it reads its sprites from (FIELDSTG_setStreamSource)
Definition field_mode.h:441
s32(* isLoaded)(struct StreamTask *task)
Definition field_mode.h:444
s32 loadedTime
when its read ended, 0 while reading
Definition field_mode.h:427
void(* nextState)(struct StreamTask *task)
Definition field_mode.h:425
s32 frameSectors
Definition field_mode.h:431
void(* setSubstate)(struct StreamTask *task, s32 substate)
Definition field_mode.h:425
s32 loadedSlot
the slot its image is loaded into, or -1
Definition field_mode.h:434
Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER.
Definition gfx.h:325
void(* setClutPos)()
(x, y)
Definition gfx.h:337
void(* setImagePos)()
(x, y)
Definition gfx.h:336
void(* load)()
(TIM)
Definition gfx.h:335
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
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119
The next free primitive of the packet buffer (getPrim), written as the kind that is drawn next.
Definition gfx.h:344
DR_TPAGE * tpage
Definition gfx.h:349
void * any
Definition gfx.h:345
SPRT * sprt
Definition gfx.h:346