Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
sprite.c File Reference

Go to the source code of this file.

Macros

#define MAX_SPRITE_ID   0xFF
 
#define MARIO_SPRITE_COMMON_BITS
 
#define MARIO_SPRITE_WORLD_BITS
 
#define MARIO_SPRITE_BATTLE_BITS
 
#define PEACH_SPRITE_BITS
 

Functions

SpriteComponent ** spr_allocate_components (s32)
 
void spr_load_npc_extra_anims (SpriteAnimData *, u32 *)
 
void spr_init_player_raster_cache (s32 cacheSize, s32 maxRasterSize)
 
void spr_init_quad_cache (void)
 
Quadspr_get_cached_quad (s32 quadIndex)
 
void spr_make_quad_for_size (Quad *quad, s32 width, s32 height)
 
Quadspr_get_quad_for_size (s32 *quadIndex, s32 width, s32 height)
 
void spr_clear_quad_cache (void)
 
void spr_appendGfx_component_flat (Quad *vertices, IMG_PTR raster, PAL_PTR palette, s32 width, s32 height, f32 arg5, Matrix4f mtx, s32 alpha)
 
void spr_appendGfx_component (SpriteRasterCacheEntry *cache, f32 dx, f32 dy, f32 dz, f32 rotX, f32 rotY, f32 rotZ, f32 scaleX, f32 scaleY, f32 scaleZ, s32 opacity, PAL_PTR palette, Matrix4f mtx)
 
void spr_transform_point (s32 rotX, s32 rotY, s32 rotZ, f32 inX, f32 inY, f32 inZ, f32 *outX, f32 *outY, f32 *outZ)
 
void spr_draw_component (s32 drawOpts, SpriteComponent *component, SpriteAnimComponent *anim, SpriteRasterCacheEntry **cache, PAL_PTR *palettes, f32 zscale, Matrix4f mtx)
 
s32 spr_unpack_signed_12bit (u16 val)
 
s32 spr_unpack_signed_16bit (u16 val)
 
void spr_component_update_commands (SpriteComponent *comp, SpriteAnimComponent *anim)
 
void spr_component_update_finish (SpriteComponent *comp, SpriteComponent **compList, SpriteRasterCacheEntry **rasterCacheEntry, s32 overridePalette)
 
s32 spr_component_update (s32 curNotifyValue, SpriteComponent **compList, SpriteAnimComponent **animList, SpriteRasterCacheEntry **rasterCache, s32 overridePalette)
 
void spr_init_component_anim_state (SpriteComponent *comp, SpriteAnimComponent *anim)
 
void spr_init_anim_state (SpriteComponent **compList, SpriteAnimComponent **animList)
 
void spr_set_anim_timescale (f32 timescale)
 
void spr_load_player_sprite (s32 spriteIndex)
 
void spr_init_sprites (s32 playerSpriteSet)
 
void spr_render_init (void)
 
s32 func_802DDA84 (void)
 
s32 spr_update_player_sprite (s32 spriteInstanceID, s32 animID, f32 timeScale)
 
s32 spr_draw_player_sprite (s32 spriteInstanceID, s32 yaw, s32 alphaIn, PAL_PTR *paletteList, Matrix4f mtx)
 
s32 func_802DDEC4 (s32 spriteIdx)
 
void set_player_imgfx_comp (s32 spriteIdx, s32 compIdx, ImgFXType imgfx, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 flags)
 
void set_player_imgfx_all (s32 animID, ImgFXType imgfxType, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
 
void spr_get_player_raster_info (SpriteRasterInfo *out, s32 playerSpriteID, s32 rasterIndex)
 
PAL_PTRspr_get_player_palettes (s32 spriteIndex)
 
s32 spr_load_npc_sprite (s32 animID, u32 *extraAnimList)
 
s32 spr_update_sprite (s32 spriteInstanceID, s32 animID, f32 timeScale)
 
s32 spr_draw_npc_sprite (s32 spriteInstanceID, s32 yaw, s32 arg2, PAL_PTR *paletteList, Matrix4f mtx)
 
s32 spr_get_notify_value (s32 spriteIndex)
 
s32 spr_free_sprite (s32 spriteInstanceID)
 
s32 get_npc_comp_imgfx_idx (s32 spriteIdx, s32 compIdx)
 
void set_npc_imgfx_comp (s32 spriteIdx, s32 compIdx, ImgFXType imgfx, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 imgfxArg5)
 
void set_npc_imgfx_all (s32 spriteIdx, ImgFXType imgfxType, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 imgfxArg5)
 
s32 spr_get_comp_position (s32 spriteIdx, s32 compListIdx, s32 *outX, s32 *outY, s32 *outZ)
 
s32 spr_get_npc_raster_info (SpriteRasterInfo *out, s32 npcSpriteID, s32 rasterIndex)
 
PAL_PTRspr_get_npc_palettes (s32 npcSpriteID)
 
s32 spr_get_npc_color_variations (s32 npcSpriteID)
 

Variables

HeapNode heap_generalHead
 
HeapNode heap_spriteHead
 
BSS s32 spr_allocateBtlComponentsOnWorldHeap
 
BSS s32 MaxLoadedSpriteInstanceID
 
BSS s32 D_802DF540
 
BSS SpriteAnimDataspr_playerSprites [13]
 
BSS s32 D_802DF57C
 
BSS s32 spr_playerMaxComponents
 
BSS PlayerCurrentAnimInfo spr_playerCurrentAnimInfo [3]
 
BSS SpriteAnimDataNpcSpriteData [0xFF]
 
BSS u8 NpcSpriteInstanceCount [0xFF]
 
BSS SpriteInstance SpriteInstances [51]
 
BSS QuadD_802DFE44
 
BSS s32 D_802DFE48 [22]
 
BSS s32 D_802DFEA0 [3]
 
BSS s32 SpriteUpdateNotifyValue
 
Quad spr_defaultQuad
 
Vp SprPauseVp
 
Vp SprPauseVpAlt
 
Gfx D_802DF3F0 []
 
Gfx D_802DF428 []
 
Gfx D_802DF460 []
 
Gfx D_802DF490 []
 
f32 spr_animUpdateTimeScale = 1.0f
 
PlayerSpriteSet spr_playerSpriteSets []
 

Macro Definition Documentation

◆ MAX_SPRITE_ID

#define MAX_SPRITE_ID   0xFF

Definition at line 4 of file sprite.c.

◆ MARIO_SPRITE_COMMON_BITS

#define MARIO_SPRITE_COMMON_BITS
Value:
1 << SPR_Mario1 \
| 1 << SPR_Mario1_Back \

Definition at line 89 of file sprite.c.

89#define MARIO_SPRITE_COMMON_BITS \
90 1 << SPR_Mario1 \
91 | 1 << SPR_Mario1_Back \
92

◆ MARIO_SPRITE_WORLD_BITS

#define MARIO_SPRITE_WORLD_BITS
Value:
| 1 << SPR_MarioW1 \
| 1 << SPR_MarioW1_Back \
| 1 << SPR_MarioW2 \
| 1 << SPR_MarioW3
#define MARIO_SPRITE_COMMON_BITS
Definition sprite.c:89

Definition at line 93 of file sprite.c.

93#define MARIO_SPRITE_WORLD_BITS \
94 MARIO_SPRITE_COMMON_BITS \
95 | 1 << SPR_MarioW1 \
96 | 1 << SPR_MarioW1_Back \
97 | 1 << SPR_MarioW2 \
98 | 1 << SPR_MarioW3

◆ MARIO_SPRITE_BATTLE_BITS

#define MARIO_SPRITE_BATTLE_BITS
Value:
| 1 << SPR_MarioB1 \
| 1 << SPR_MarioB2 \
| 1 << SPR_MarioB3

Definition at line 100 of file sprite.c.

100#define MARIO_SPRITE_BATTLE_BITS \
101 MARIO_SPRITE_COMMON_BITS \
102 | 1 << SPR_MarioB1 \
103 | 1 << SPR_MarioB2 \
104 | 1 << SPR_MarioB3

◆ PEACH_SPRITE_BITS

#define PEACH_SPRITE_BITS
Value:
1 << SPR_Peach1 \
| 1 << SPR_Peach1_Back \
| 1 << SPR_Peach2 \
| 1 << SPR_Peach3 \

Definition at line 106 of file sprite.c.

106#define PEACH_SPRITE_BITS \
107 1 << SPR_Peach1 \
108 | 1 << SPR_Peach1_Back \
109 | 1 << SPR_Peach2 \
110 | 1 << SPR_Peach3 \
111

Function Documentation

◆ spr_allocate_components()

SpriteComponent ** spr_allocate_components ( s32 count)

Definition at line 353 of file 101b90_len_8f0.c.

353 {
354 s32 listSize;
355 SpriteComponent** listStart;
356 SpriteComponent* component;
357 SpriteComponent** listPos;
358 u32 totalSize;
359 s32 i;
360
361 // data will contain a -1 terminated list, followed by the SpriteComponents
362 // corresponding to that list
363 listSize = (count + 1) * 4;
364 totalSize = (count * sizeof(SpriteComponent)) + listSize;
365
367 listStart = _heap_malloc(&heap_generalHead, totalSize);
368 listPos = listStart;
369 component = (SpriteComponent*) listPos;
370 } else {
371 listStart = _heap_malloc(&heap_spriteHead, totalSize);
372 listPos = listStart;
373 component = (SpriteComponent*) listPos;
374 }
375
376 component = (SpriteComponent*)((s32)(component) + (listSize / 4) * 4);
377
378 // fill list values
379 for (i = 0; i < count; i++) {
380 *listPos++ = component;
381 component++;
382 }
383 *listPos = PTR_LIST_END;
384
385 return listStart;
386}
s32 spr_allocateBtlComponentsOnWorldHeap
Definition sprite.c:9
HeapNode heap_generalHead
Definition heaps3.c:3
HeapNode heap_spriteHead
Definition heaps3.c:4
void * _heap_malloc(HeapNode *head, u32 size)
Definition 43F0.c:78
#define PTR_LIST_END
Definition macros.h:42

Referenced by spr_load_npc_sprite(), and spr_update_player_sprite().

◆ spr_load_npc_extra_anims()

void spr_load_npc_extra_anims ( SpriteAnimData * header,
u32 * extraAnimList )

Definition at line 229 of file 101b90_len_8f0.c.

229 {
230 u8* src;
231 s32 imgID;
232 s32 rasterSize;
233 s32 remaining;
234 u16 animCmd;
235 u16* cmdList;
236 u32 extraAnimID;
237 u8* dataPos;
238 void* copyEnd;
240 SpriteAnimComponent** compList;
241 void* writePos;
242 SpriteRasterCacheEntry** rasterList;
244 u16** oldPalList;
245 u16* palette;
246 // one extra required for 'done' sentinel
247 s32 sawRaster[100 + 1];
248 s32 i;
249
250 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
251 sawRaster[i] = FALSE;
252 }
253
254 while ((extraAnimID = *extraAnimList++) != -1) {
255 compList = header->animListStart[extraAnimID & 0xFF];
256 while ((comp = *compList++) != PTR_LIST_END) {
257 cmdList = comp->cmdList;
258 remaining = (s16) comp->cmdListSize / 2;
259 while (remaining > 0) {
260 animCmd = *cmdList++;
261 remaining--;
262 switch (animCmd & 0xF000) {
263 case 0x1000:
264 i = animCmd; // required to match
265 imgID = i & 0xFF;
266 if (imgID < ARRAY_COUNT(sawRaster) - 1) {
267 sawRaster[imgID] = TRUE;
268 }
269 break;
270 case 0x3000:
271 cmdList++;
272 remaining--;
273 // fallthrough
274 case 0x4000:
275 cmdList++;
276 remaining--;
277 // fallthrough
278 case 0x7000:
279 case 0x5000:
280 cmdList++;
281 remaining--;
282 // fallthrough
283 case 0x0000:
284 case 0x2000:
285 case 0x6000:
286 case 0x8000:
287 break;
288 }
289 }
290 }
291 }
292
293 rasterList = header->rastersOffset;
294 raster = *rasterList;
295 dataPos = raster->image;
296
297 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
298 if ((raster = *rasterList) == PTR_LIST_END) {
299 break;
300 }
301 if (sawRaster[i]) {
302 src = raster->image;
303 rasterSize = (raster->width * raster->height) / 2;
304 copyEnd = &dataPos[rasterSize];
305 rasterSize += 8;
306 if (dataPos != src) {
307 raster->image = dataPos;
308 bcopy(src, dataPos, rasterSize);
309 }
310 *rasterList = copyEnd;
311 dataPos += rasterSize;
312 }
313 rasterList++;
314 }
315 // sentinel value to mark end of valid data
316 sawRaster[i] = TRUE;
317
318 writePos = dataPos;
319
320 // copy raster list
321 rasterList = header->rastersOffset;
322 header->rastersOffset = writePos;
323
324 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
325 raster = *rasterList++;
326 if (sawRaster[i]) {
327 *(SpriteRasterCacheEntry**) writePos = raster;
328 } else {
329 *(SpriteRasterCacheEntry**) writePos = (SpriteRasterCacheEntry*) copyEnd;
330 }
331 writePos += 4;
332 if (raster == PTR_LIST_END) {
333 break;
334 }
335 }
336
337 // copy palette list
338 oldPalList = header->palettesOffset;
339 header->palettesOffset = writePos;
340
341 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
342 raster = (SpriteRasterCacheEntry*)*oldPalList++; // required to match
343 *(u16**)writePos = (u16*)raster;
344 writePos += 4;
345 if (raster == PTR_LIST_END) {
346 break;
347 }
348 }
349
350 _heap_realloc(&heap_spriteHead, header, (s32)writePos - (s32)header);
351}
void * _heap_realloc(HeapNode *heapNodeList, void *addr, u32 newSize)
Definition 43F0.c:286
#define ARRAY_COUNT(arr)
Definition macros.h:40
SpriteAnimComponent ** animListStart[VLA]
Definition sprite.h:79
SpriteRasterCacheEntry ** rastersOffset
Definition sprite.h:75
PAL_PTR * palettesOffset
Definition sprite.h:76

Referenced by spr_load_npc_sprite().

◆ spr_init_player_raster_cache()

void spr_init_player_raster_cache ( s32 cacheSize,
s32 maxRasterSize )

Definition at line 156 of file 101b90_len_8f0.c.

156 {
157 void* raster;
158 s32 i;
159
160 nuPiReadRom(SPRITE_ROM_START, &SpriteDataHeader, sizeof(SpriteDataHeader));
161 PlayerRasterCacheSize = cacheSize;
162 PlayerRasterMaxSize = maxRasterSize;
163 SpriteDataHeader[0] += SPRITE_ROM_START;
164 SpriteDataHeader[1] += SPRITE_ROM_START;
165 SpriteDataHeader[2] += SPRITE_ROM_START;
166 raster = _heap_malloc(&heap_spriteHead, maxRasterSize * cacheSize);
167
168 for (i = 0; i < ARRAY_COUNT(PlayerRasterCache); i++) {
169 PlayerRasterCache[i].raster = raster;
170 raster += PlayerRasterMaxSize;
174 }
175
178 }
180 nuPiReadRom(SpriteDataHeader[0], &PlayerRasterHeader, sizeof(PlayerRasterHeader));
182}
BSS PlayerRastersHeader PlayerRasterHeader
BSS s32 PlayerRasterCacheSize
BSS s32 PlayerRasterMaxSize
BSS s32 SpriteDataHeader[3]
BSS s32 PlayerSpriteRasterSets[SPR_Peach3+1]
BSS s32 PlayerRasterLoadDescNumLoaded
BSS s32 PlayerRasterLoadDescBeginSpriteIndex[SPR_Peach3]
BSS PlayerSpriteCacheEntry PlayerRasterCache[18]

Referenced by spr_init_sprites().

◆ spr_init_quad_cache()

void spr_init_quad_cache ( void )

Definition at line 124 of file sprite.c.

124 {
125 s32 i;
126
128
129 for (i = 0; i < ARRAY_COUNT(D_802DFE48); i++) {
130 D_802DFE48[i] = -1;
131 }
132}
BSS s32 D_802DFE48[22]
Definition sprite.c:20
BSS Quad * D_802DFE44
Definition sprite.c:19
HeapNode heap_spriteHead
Definition heaps3.c:4

Referenced by spr_init_sprites().

◆ spr_get_cached_quad()

Quad * spr_get_cached_quad ( s32 quadIndex)

Definition at line 134 of file sprite.c.

134 {
135 s32* temp_v1 = &D_802DFE48[quadIndex];
136
137 *temp_v1 |= 0x1F;
138 return &D_802DFE44[quadIndex];
139}

Referenced by spr_get_quad_for_size().

◆ spr_make_quad_for_size()

void spr_make_quad_for_size ( Quad * quad,
s32 width,
s32 height )

Definition at line 141 of file sprite.c.

141 {
142 Vtx* vtx = &quad->v[0];
143
144 *quad = spr_defaultQuad;
145
146 vtx->v.ob[0] = -width / 2;
147 vtx->v.ob[1] = height;
148 vtx->v.tc[0] = 0x2000;
149 vtx->v.tc[1] = 0x2000;
150
151 vtx++;
152 vtx->v.ob[0] = width / 2;
153 vtx->v.ob[1] = height;
154 vtx->v.tc[0] = (width + 256) * 32;
155 vtx->v.tc[1] = 0x2000;
156
157 vtx++;
158 vtx->v.tc[0] = (width + 256) * 32;
159 vtx->v.ob[0] = width / 2;
160 vtx->v.tc[1] = (height + 256) * 32;
161
162 vtx++;
163 vtx->v.ob[0] = -width / 2;
164 vtx->v.tc[0] = 0x2000;
165 vtx->v.tc[1] = (height + 256) * 32;
166}
Quad spr_defaultQuad
Definition sprite.c:28
Vtx v[4]
Definition sprite.h:116

Referenced by spr_get_quad_for_size().

◆ spr_get_quad_for_size()

Quad * spr_get_quad_for_size ( s32 * quadIndex,
s32 width,
s32 height )

Definition at line 168 of file sprite.c.

168 {
169 Quad* quad;
170 s32 qi;
171 s32 dimensions;
172 s32 i;
173
174 if ((width * height) / 2 <= 0x800) {
175 dimensions = (width << 0x18) + (height << 0x10);
176 qi = *quadIndex;
177 if (qi != -1 && (dimensions == (D_802DFE48[qi] & 0xFFFF0000))) {
178 return spr_get_cached_quad(qi);
179 }
180
181 for (i = 0; i < ARRAY_COUNT(D_802DFE48); i++) {
182 if (dimensions == (D_802DFE48[i] & 0xFFFF0000)) {
183 *quadIndex = i;
184 return spr_get_cached_quad(i);
185 }
186 }
187
188 for (i = 0; i < ARRAY_COUNT(D_802DFE48); i++) {
189 if (D_802DFE48[i] == -1) {
190 break;
191 }
192 }
193
194 if (i != ARRAY_COUNT(D_802DFE48)) {
195 *quadIndex = i;
196 D_802DFE48[i] = dimensions;
197 quad = spr_get_cached_quad(i);
198 spr_make_quad_for_size(quad, width, height);
199 return quad;
200 }
201 }
202 return NULL;
203}
Quad * spr_get_cached_quad(s32 quadIndex)
Definition sprite.c:134
void spr_make_quad_for_size(Quad *quad, s32 width, s32 height)
Definition sprite.c:141
Definition sprite.h:115

Referenced by spr_appendGfx_component().

◆ spr_clear_quad_cache()

void spr_clear_quad_cache ( void )

Definition at line 205 of file sprite.c.

205 {
206 s32 i;
207
208 for (i = 0; i < ARRAY_COUNT(D_802DFE48); i++) {
209 if (D_802DFE48[i] != -1) {
210 D_802DFE48[i]--;
211 if (!(D_802DFE48[i] & 0xFFFF)) {
212 D_802DFE48[i] = -1;
213 }
214 }
215 }
216}

Referenced by spr_render_init().

◆ spr_appendGfx_component_flat()

void spr_appendGfx_component_flat ( Quad * vertices,
IMG_PTR raster,
PAL_PTR palette,
s32 width,
s32 height,
f32 arg5,
Matrix4f mtx,
s32 alpha )

Definition at line 218 of file sprite.c.

225 {
226 gDPLoadTLUT_pal16(gMainGfxPos++, 0, palette);
228 gDPScrollMultiTile2_4b(gMainGfxPos++, raster, G_IM_FMT_CI, width, height,
229 0, 0, width - 1, height - 1, 0,
230 G_TX_CLAMP, G_TX_CLAMP, 8, 8, G_TX_NOLOD, G_TX_NOLOD,
231 256, 256);
232 gDPSetTile(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0x0100, 2, 0, G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD);
233 gDPSetTileSize(gMainGfxPos++, 2, 0, 0, 63 << 2, 0);
235 Camera* camera = &gCameras[gCurrentCamID];
237 gSPViewport(gMainGfxPos++, &SprPauseVpAlt);
238 } else {
239 gSPViewport(gMainGfxPos++, &camera->vpAlt);
240 }
241
242 if (alpha == 255) {
243 gDPSetRenderMode(gMainGfxPos++, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA |
244 G_RM_PASS, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA |
245 GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM));
246 } else {
247 gDPSetRenderMode(gMainGfxPos++, G_RM_PASS, G_RM_ZB_CLD_SURF2);
248 }
249
250 gDPSetEnvColor(gMainGfxPos++, 0, 0, 0, alpha);
251 gDPSetCombineMode(gMainGfxPos++, PM_CC_0B, PM_CC_0C);
252 gSPVertex(gMainGfxPos++, vertices, 4, 0);
253 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 0, 3, 2, 0);
254 gDPPipeSync(gMainGfxPos++);
255 }
256 create_shading_palette(mtx, 0, 0, width, height, alpha, alpha == 255 ? 0x111238 : 0x104B50); // TODO make macro for render mode
257 } else {
258 gDPScrollTextureBlock_4b(gMainGfxPos++, raster, G_IM_FMT_CI, width, height, 0,
259 G_TX_CLAMP, G_TX_CLAMP, 8, 8, G_TX_NOLOD, G_TX_NOLOD,
260 256, 256);
262 Camera* camera = &gCameras[gCurrentCamID];
264 gSPViewport(gMainGfxPos++, &SprPauseVpAlt);
265 } else {
266 gSPViewport(gMainGfxPos++, &camera->vpAlt);
267 }
268 if (alpha == 255) {
269 gDPSetRenderMode(gMainGfxPos++, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | ALPHA_CVG_SEL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM), AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | ALPHA_CVG_SEL | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM));
270 } else {
271 gDPSetRenderMode(gMainGfxPos++, G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2);
272 }
273
274 gDPSetEnvColor(gMainGfxPos++, 0, 0, 0, alpha);
275 gDPSetCombineMode(gMainGfxPos++, PM_CC_0A, PM_CC_0A);
276 gSPVertex(gMainGfxPos++, vertices, 4, 0);
277 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 0, 3, 2, 0);
278 gDPPipeSync(gMainGfxPos++);
279
280 if (alpha == 255) {
281 gDPSetRenderMode(gMainGfxPos++, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA |
282 GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM),
283 AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA |
284 GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM));
285 } else {
286 gDPSetRenderMode(gMainGfxPos++, G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2);
287 }
288
289 gDPSetEnvColor(gMainGfxPos++, 100, 100, 100, 255);
290 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, alpha);
291 gDPSetCombineMode(gMainGfxPos++, PM_CC_3D, PM_CC_3D);
292 gDPSetColorDither(gMainGfxPos++, G_CD_MAGICSQ);
293 }
294 }
295
297 Camera* camera = &gCameras[gCurrentCamID];
298
300 gSPViewport(gMainGfxPos++, &SprPauseVp);
301 SprPauseVpAlt.vp.vtrans[0] = SprPauseVp.vp.vtrans[0] + gGameStatusPtr->altViewportOffset.x;
302 SprPauseVpAlt.vp.vtrans[1] = SprPauseVp.vp.vtrans[1] + gGameStatusPtr->altViewportOffset.y;
303 } else {
304 gSPViewport(gMainGfxPos++, &camera->vp);
305 }
306 }
307
308 gSPVertex(gMainGfxPos++, vertices, 4, 0);
309 gSP2Triangles(gMainGfxPos++, 0, 2, 1, 0, 0, 3, 2, 0);
310 gDPPipeSync(gMainGfxPos++);
311}
Vec2b altViewportOffset
@ SPR_SHADING_FLAG_SET_VIEWPORT
Definition enums.h:5208
@ SPR_SHADING_FLAG_ENABLED
Definition enums.h:5207
@ CONTEXT_PAUSE
Definition enums.h:3531
#define gDPScrollMultiTile2_4b(pkt, timg, fmt, width, height, uls, ult, lrs, lrt, pal, cms, cmt, masks, maskt, shifts, shiftt, scrolls, scrollt)
Definition gbi_custom.h:6
#define gDPScrollTextureBlock_4b(pkt, timg, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt, scrolls, scrollt)
Definition gbi_custom.h:67
#define PM_CC_0A
Definition macros.h:285
#define PM_CC_0C
Definition macros.h:289
#define PM_CC_0B
Definition macros.h:287
#define PM_CC_3D
Definition macros.h:406
Vp SprPauseVp
Definition sprite.c:37
Vp SprPauseVpAlt
Definition sprite.c:43
void create_shading_palette(Matrix4f mtx, s32 uls, s32 ult, s32 lrs, s32 lrt, s32 alpha, s32)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
SpriteShadingProfile * gSpriteShadingProfile
s16 gCurrentCamID
Definition cam_main.c:13

Referenced by spr_appendGfx_component().

◆ spr_appendGfx_component()

void spr_appendGfx_component ( SpriteRasterCacheEntry * cache,
f32 dx,
f32 dy,
f32 dz,
f32 rotX,
f32 rotY,
f32 rotZ,
f32 scaleX,
f32 scaleY,
f32 scaleZ,
s32 opacity,
PAL_PTR palette,
Matrix4f mtx )

Definition at line 313 of file sprite.c.

319{
320 Matrix4f mtxTransform;
321 Matrix4f mtxTemp;
322 ImgFXTexture ifxImg;
323 s32 quadIndex;
324 Quad* quad;
325 s32 width;
326 s32 height;
327
328 guTranslateF(mtxTemp, dx, dy, dz);
329 guMtxCatF(mtxTemp, mtx, mtxTransform);
330
331 if (rotY != 0.0f) {
332 guRotateF(mtxTemp, rotY, 0.0f, 1.0f, 0.0f);
333 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
334 }
335 if (rotZ != 0.0f) {
336 guRotateF(mtxTemp, rotZ, 0.0f, 0.0f, 1.0f);
337 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
338 }
339 if (rotX != 0.0f) {
340 guRotateF(mtxTemp, rotX, 1.0f, 0.0f, 0.0f);
341 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
342 }
343
344 if (scaleX != 1.0f || scaleY != 1.0f || scaleZ != 1.0f) {
345 guScaleF(mtxTemp, scaleX, scaleY, scaleZ);
346 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
347 }
348
351 G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
352
354 if ((u8) opacity == 255) {
355 gSPDisplayList(gMainGfxPos++, D_802DF460);
356 } else {
357 gSPDisplayList(gMainGfxPos++, D_802DF490);
358 }
359 } else {
360 if ((u8) opacity == 255) {
361 gSPDisplayList(gMainGfxPos++, D_802DF3F0);
362 } else {
363 gDPSetPrimColor(gMainGfxPos++, 0, 0, 0, 0, 0, (u8) opacity);
364 gSPDisplayList(gMainGfxPos++, D_802DF428);
365 }
366 }
367
368 width = cache->width;
369 height = cache->height;
370 quadIndex = cache->quadCacheIndex;
371 quad = NULL;
373 quad = spr_get_quad_for_size(&quadIndex, width, height);
374 cache->quadCacheIndex = quadIndex;
375 }
376
377 if (quad != NULL) {
378 spr_appendGfx_component_flat(quad, cache->image, palette, width, height, rotY, mtxTransform, (u8) opacity);
379 } else {
380 ifxImg.raster = cache->image;
381 ifxImg.palette = palette;
382 ifxImg.width = width;
383 ifxImg.height = height;
384 ifxImg.xOffset = -(width / 2);
385 ifxImg.yOffset = height;
386 ifxImg.alpha = opacity;
387 if (imgfx_appendGfx_component((u8) D_802DF540, &ifxImg, IMGFX_FLAG_80000, mtxTransform) == 1) {
388 D_802DF540 &= ~SPR_IMGFX_FLAG_ALL;
389 }
390 }
391 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
392}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guScaleF
@ SPR_IMGFX_FLAG_ALL
Definition enums.h:5203
@ IMGFX_FLAG_80000
Definition enums.h:5112
s32 imgfx_appendGfx_component(s32, ImgFXTexture *, u32, Matrix4f)
Definition imgfx.c:704
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
Quad * spr_get_quad_for_size(s32 *quadIndex, s32 width, s32 height)
Definition sprite.c:168
Gfx D_802DF3F0[]
Definition sprite.c:49
void spr_appendGfx_component_flat(Quad *vertices, IMG_PTR raster, PAL_PTR palette, s32 width, s32 height, f32 arg5, Matrix4f mtx, s32 alpha)
Definition sprite.c:218
Gfx D_802DF428[]
Definition sprite.c:59
Gfx D_802DF490[]
Definition sprite.c:78
BSS s32 D_802DF540
Definition sprite.c:11
Gfx D_802DF460[]
Definition sprite.c:69
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by spr_draw_component().

◆ spr_transform_point()

void spr_transform_point ( s32 rotX,
s32 rotY,
s32 rotZ,
f32 inX,
f32 inY,
f32 inZ,
f32 * outX,
f32 * outY,
f32 * outZ )

Definition at line 394 of file sprite.c.

394 {
395 if (rotX == 0 && rotY == 0 && rotZ == 0) {
396 *outX = inX;
397 *outY = inY;
398 *outZ = inZ;
399 } else {
400 Matrix4f mtxTransform, mtxTemp;
401 f32 xx, yx, zx, xy, yy, zy, xz, yz, zz;
402
403 guRotateF(mtxTransform, rotY, 0.0f, 1.0f, 0.0f);
404 guRotateF(mtxTemp, rotZ, 0.0f, 0.0f, 1.0f);
405 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
406 guRotateF(mtxTemp, rotX, 1.0f, 0.0f, 0.0f);
407 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
408
409 xx = (mtxTransform[0][0] * inX);
410 yx = (mtxTransform[1][0] * inY);
411 zx = (mtxTransform[2][0] * inZ);
412 xy = (mtxTransform[0][1] * inX);
413 yy = (mtxTransform[1][1] * inY);
414 zy = (mtxTransform[2][1] * inZ);
415 xz = (mtxTransform[0][2] * inX);
416 yz = (mtxTransform[1][2] * inY);
417 zz = (mtxTransform[2][2] * inZ);
418
419 *outX = xx + yx + zx;
420 *outY = xy + yy + zy;
421 *outZ = xz + yz + zz;
422 }
423}

Referenced by spr_draw_component().

◆ spr_draw_component()

void spr_draw_component ( s32 drawOpts,
SpriteComponent * component,
SpriteAnimComponent * anim,
SpriteRasterCacheEntry ** cache,
PAL_PTR * palettes,
f32 zscale,
Matrix4f mtx )

Definition at line 425 of file sprite.c.

426 {
427 SpriteRasterCacheEntry* cacheEntry;
428 s32 paletteIdx;
429 PAL_PTR pal;
430 f32 dx, dy, dz;
431 f32 rotX, rotY, rotZ;
432 f32 inX, inY, inZ;
433
434 if (component->initialized && component->curRaster != -1) {
435 rotX = D_802DFEA0[0];
436 rotY = D_802DFEA0[1];
437 rotZ = D_802DFEA0[2];
438 inX = component->compPos.x + anim->compOffset.x;
439 inY = component->compPos.y + anim->compOffset.y;
440 inZ = component->compPos.z + anim->compOffset.z;
441
442 spr_transform_point(rotX, rotY, rotZ, inX, inY, inZ * zscale, &dx, &dy, &dz);
443 cacheEntry = cache[component->curRaster];
444 paletteIdx = component->curPalette;
445 if (drawOpts & DRAW_SPRITE_USE_PLAYER_RASTERS) {
446 cacheEntry->image = spr_get_player_raster(component->curRaster & 0xFFF, D_802DF57C);
447 }
448 D_802DF540 = component->imgfxIdx;
449 pal = palettes[paletteIdx];
450
452 cacheEntry,
453 dx, dy, dz,
454 rotX + component->rot.x,
455 rotY + component->rot.y,
456 rotZ + component->rot.z,
457 component->scale.x,
458 component->scale.y,
459 component->scale.z,
460 drawOpts, pal, mtx
461 );
462 component->imgfxIdx = D_802DF540;
463 }
464}
IMG_PTR spr_get_player_raster(s32 rasterIndex, s32 playerSpriteID)
#define PAL_PTR
void spr_transform_point(s32 rotX, s32 rotY, s32 rotZ, f32 inX, f32 inY, f32 inZ, f32 *outX, f32 *outY, f32 *outZ)
Definition sprite.c:394
BSS s32 D_802DFEA0[3]
Definition sprite.c:21
void spr_appendGfx_component(SpriteRasterCacheEntry *cache, f32 dx, f32 dy, f32 dz, f32 rotX, f32 rotY, f32 rotZ, f32 scaleX, f32 scaleY, f32 scaleZ, s32 opacity, PAL_PTR palette, Matrix4f mtx)
Definition sprite.c:313
BSS s32 D_802DF57C
Definition sprite.c:13
Vec3f compPos
Definition sprite.h:46
@ DRAW_SPRITE_USE_PLAYER_RASTERS
Definition sprite.h:18
s32 initialized
Definition sprite.h:38
Vec3f scale
Definition sprite.h:48

Referenced by spr_draw_npc_sprite(), and spr_draw_player_sprite().

◆ spr_unpack_signed_12bit()

s32 spr_unpack_signed_12bit ( u16 val)

Definition at line 466 of file sprite.c.

466 {
467 s32 temp = val & 0xFFF;
468
469 if (temp & 0x800) {
470 return temp | ~0xFFF;
471 } else {
472 return temp;
473 }
474}

Referenced by spr_component_update_commands().

◆ spr_unpack_signed_16bit()

s32 spr_unpack_signed_16bit ( u16 val)

Definition at line 476 of file sprite.c.

476 {
477 s32 temp = val & 0xFFFF;
478
479 if (temp & 0x8000) {
480 return temp | ~0xFFFF;
481 } else {
482 return temp;
483 }
484}

Referenced by spr_component_update_commands().

◆ spr_component_update_commands()

void spr_component_update_commands ( SpriteComponent * comp,
SpriteAnimComponent * anim )

Definition at line 486 of file sprite.c.

486 {
487 f32 posX, posY, posZ;
488 f32 rotX, rotY, rotZ;
489 f32 scaleX, scaleY, scaleZ;
490 s32 changedFlags;
491
492 u16* bufPos;
493 u16* gotoPos;
494 s32 cmdValue;
495
496 if (comp->initialized) {
497 scaleZ = 1.0f;
498 scaleY = 1.0f;
499 scaleX = 1.0f;
500 changedFlags = 0;
501
502 bufPos = comp->readPos;
503 gotoPos = (u16*) -1;
504
506
507 while (comp->waitTime <= 0.0f) {
508 // overflow check
509 if (bufPos >= &anim->cmdList[anim->cmdListSize / 2]) {
510 bufPos = anim->cmdList;
511 break;
512 }
513
514 switch (*bufPos & 0xF000) {
515 // 0VVV
516 // Wait
517 case 0x0000:
518 comp->waitTime = *bufPos++ & 0xFFF;
519 if (comp->waitTime == 0.0f) {
520 comp->waitTime = 4095.0f;
521 }
522 comp->posOffset.z = 0.0f;
523 comp->posOffset.y = 0.0f;
524 comp->posOffset.x = 0.0f;
525 comp->rot.z = 0;
526 comp->rot.y = 0;
527 comp->rot.x = 0;
528 comp->scale.z = 1.0f;
529 comp->scale.y = 1.0f;
530 comp->scale.x = 1.0f;
531 break;
532 // 2VVV
533 // Goto -- jump to another position in the list
534 case 0x2000:
535 bufPos = &anim->cmdList[spr_unpack_signed_12bit(*bufPos)];
536 if (bufPos == gotoPos) {
537 bufPos = anim->cmdList;
538 comp->waitTime = 1.0f;
539 }
540 gotoPos = bufPos;
541 break;
542 // 1VVV
543 // SetImage -- FFF is valid value for "no image"
544 case 0x1000:
545 cmdValue = *bufPos++ & 0xFFF;
546 if (cmdValue != 0xFFF) {
547 comp->curRaster = cmdValue;
548 } else {
549 comp->curRaster = -1;
550 }
551 comp->curPalette = -1;
552 break;
553 // 6VVV
554 // SetPalette -- FFF to clear
555 case 0x6000:
556 cmdValue = *bufPos++ & 0xFFF;
557 if (cmdValue != 0xFFF) {
558 comp->curPalette = cmdValue;
559 } else {
560 comp->curPalette = -1;
561 }
562 break;
563 // 8VUU
564 // SetProperty
565 // 81-XX parent to component XX
566 // 82-YY set notify value to YY
567 case 0x8000:
568 cmdValue = *bufPos++;
569 switch (cmdValue & 0xF00) {
570 case 0x100: // set parent
571 comp->properties = (comp->properties & 0xFFFF0000) | cmdValue;
572 break;
573 case 0x200: // set notify value
574 SpriteUpdateNotifyValue = cmdValue & 0xFF;
575 comp->properties = (comp->properties & 0xFF00FFFF) | (SpriteUpdateNotifyValue << 0x10);
576 break;
577 }
578 break;
579 // 3VVV XXXX YYYY ZZZZ
580 // SetPosition -- what does the flag do?
581 case 0x3000:
582 switch (*bufPos++ & 0xF) {
583 case 0:
584 case 1:
585 posX = spr_unpack_signed_16bit(*bufPos++);
586 posY = spr_unpack_signed_16bit(*bufPos++);
587 posZ = spr_unpack_signed_16bit(*bufPos++);
588 changedFlags |= 1;
589 break;
590 }
591 break;
592 // 4XXX YYYY ZZZZ
593 // SetRotation (euler angles)
594 case 0x4000:
595 rotX = spr_unpack_signed_12bit(*bufPos++);
596 rotY = spr_unpack_signed_16bit(*bufPos++);
597 rotZ = spr_unpack_signed_16bit(*bufPos++);
598 changedFlags |= 2;
599 break;
600 // 5VVV UUUU
601 // SetScale (%)
602 case 0x5000:
603 switch (*bufPos++ & 0xF) {
604 case 0:
605 scaleZ = *bufPos++ / 100.0f;
606 scaleY = scaleZ;
607 scaleX = scaleZ;
608 break;
609 case 1:
610 scaleX = *bufPos++ / 100.0f;
611 break;
612 case 2:
613 scaleY = *bufPos++ / 100.0f;
614 break;
615 case 3:
616 scaleZ = *bufPos++ / 100.0f;
617 break;
618 }
619 changedFlags |= 4;
620 break;
621 // 7VVV UUUU
622 // Loop -- VV iterations jumping back to UUUU
623 case 0x7000:
624 if (comp->loopCounter != 0) {
625 comp->loopCounter--;
626 if (comp->loopCounter == 0) {
627 bufPos += 2;
628 break;
629 }
630 } else {
631 comp->loopCounter = bufPos[1];
632 }
633 bufPos = &anim->cmdList[spr_unpack_signed_12bit(*bufPos)];
634 break;
635 // invalid command
636 default:
637 bufPos = anim->cmdList;
638 comp->waitTime = 1.0f;
639 break;
640 }
641 } // end loop
642
643 comp->readPos = bufPos;
644 if (changedFlags & 1) {
645 comp->posOffset.x = posX;
646 comp->posOffset.y = posY;
647 comp->posOffset.z = posZ;
648 }
649 if (changedFlags & 2) {
650 comp->rot.x = rotX;
651 comp->rot.y = rotY;
652 comp->rot.z = rotZ;
653 }
654 if (changedFlags & 4) {
655 comp->scale.x = scaleX;
656 comp->scale.y = scaleY;
657 comp->scale.z = scaleZ;
658 }
659 }
660}
s32 spr_unpack_signed_12bit(u16 val)
Definition sprite.c:466
s32 spr_unpack_signed_16bit(u16 val)
Definition sprite.c:476
BSS s32 SpriteUpdateNotifyValue
Definition sprite.c:22
f32 spr_animUpdateTimeScale
Definition sprite.c:87
Vec3f posOffset
Definition sprite.h:45
s32 properties
AABBCCCC : AA = unused?, BB = parent, CCCC = notify value.
Definition sprite.h:39
s16 * readPos
Definition sprite.h:40
s32 loopCounter
Definition sprite.h:42

Referenced by spr_component_update().

◆ spr_component_update_finish()

void spr_component_update_finish ( SpriteComponent * comp,
SpriteComponent ** compList,
SpriteRasterCacheEntry ** rasterCacheEntry,
s32 overridePalette )

Definition at line 662 of file sprite.c.

664{
665 SpriteComponent* listComp;
667
668 if (comp->initialized) {
669 comp->compPos.x = comp->posOffset.x;
670 comp->compPos.y = comp->posOffset.y;
671 comp->compPos.z = comp->posOffset.z;
672
673 if ((comp->properties & 0xF00) == 0x100) {
674 listComp = compList[comp->properties & 0xFF];
675 comp->compPos.x += listComp->compPos.x;
676 comp->compPos.y += listComp->compPos.y;
677 comp->compPos.z += listComp->compPos.z;
678 }
679
680 if (comp->curRaster != -1) {
681 cache = rasterCacheEntry[comp->curRaster];
682 if (comp->curPalette == -1) {
683 comp->curPalette = cache->palette;
684 if (overridePalette != 0 && comp->curPalette == 0) {
685 comp->curPalette = overridePalette;
686 }
687 }
688 }
689 }
690}

Referenced by spr_component_update().

◆ spr_component_update()

s32 spr_component_update ( s32 curNotifyValue,
SpriteComponent ** compList,
SpriteAnimComponent ** animList,
SpriteRasterCacheEntry ** rasterCache,
s32 overridePalette )

Definition at line 692 of file sprite.c.

693 {
694 SpriteComponent** compListIt;
695
696 SpriteUpdateNotifyValue = curNotifyValue;
697
698 compListIt = compList;
699 while (*compListIt != PTR_LIST_END) {
700 spr_component_update_commands(*compListIt++, *animList);
701 if (*animList != PTR_LIST_END) {
702 animList++;
703 }
704 }
705
706 compListIt = compList;
707 while (*compListIt != PTR_LIST_END) {
708 spr_component_update_finish(*compListIt++, compList, rasterCache, overridePalette);
709 }
710
712}
void spr_component_update_commands(SpriteComponent *comp, SpriteAnimComponent *anim)
Definition sprite.c:486
void spr_component_update_finish(SpriteComponent *comp, SpriteComponent **compList, SpriteRasterCacheEntry **rasterCacheEntry, s32 overridePalette)
Definition sprite.c:662

Referenced by spr_update_player_sprite(), and spr_update_sprite().

◆ spr_init_component_anim_state()

void spr_init_component_anim_state ( SpriteComponent * comp,
SpriteAnimComponent * anim )

Definition at line 714 of file sprite.c.

714 {
715 if (anim == PTR_LIST_END) {
716 comp->initialized = FALSE;
717 return;
718 }
719
720 comp->initialized = TRUE;
721 comp->properties = 0;
722 comp->readPos = anim->cmdList;
723 comp->waitTime = 0;
724 comp->loopCounter = 0;
725 comp->curRaster = -1;
726 comp->curPalette = -1;
727 comp->posOffset.x = 0.0f;
728 comp->posOffset.y = 0.0f;
729 comp->posOffset.z = 0.0f;
730 comp->compPos.x = 0.0f;
731 comp->compPos.y = 0.0f;
732 comp->compPos.z = 0.0f;
733 comp->rot.x = 0.0f;
734 comp->rot.y = 0.0f;
735 comp->rot.z = 0.0f;
736 comp->scale.x = 1.0f;
737 comp->scale.y = 1.0f;
738 comp->scale.z = 1.0f;
739}

Referenced by spr_init_anim_state().

◆ spr_init_anim_state()

void spr_init_anim_state ( SpriteComponent ** compList,
SpriteAnimComponent ** animList )

Definition at line 741 of file sprite.c.

741 {
742 while (*compList != PTR_LIST_END) {
743 SpriteComponent* component = *compList++;
744 spr_init_component_anim_state(component, *animList);
745 if (*animList != PTR_LIST_END) {
746 animList++;
747 }
748 }
749}
void spr_init_component_anim_state(SpriteComponent *comp, SpriteAnimComponent *anim)
Definition sprite.c:714

Referenced by spr_update_player_sprite(), and spr_update_sprite().

◆ spr_set_anim_timescale()

void spr_set_anim_timescale ( f32 timescale)

Definition at line 751 of file sprite.c.

751 {
752 spr_animUpdateTimeScale = timescale * 2.0f;
753}

Referenced by spr_update_player_sprite(), and spr_update_sprite().

◆ spr_load_player_sprite()

void spr_load_player_sprite ( s32 spriteIndex)

Definition at line 755 of file sprite.c.

755 {
756 SpriteAnimData* playerSprite = spr_load_sprite(spriteIndex - 1, TRUE, FALSE);
757
758 spr_playerSprites[spriteIndex - 1] = playerSprite;
759 if (spr_playerMaxComponents < playerSprite->maxComponents) {
761 }
762}
SpriteAnimData * spr_load_sprite(s32 idx, s32 isPlayerSprite, s32 useTailAlloc)
BSS SpriteAnimData * spr_playerSprites[13]
Definition sprite.c:12
BSS s32 spr_playerMaxComponents
Definition sprite.c:14
s32 maxComponents
Definition sprite.h:77
Sprite data header.
Definition sprite.h:74

Referenced by spr_init_sprites().

◆ spr_init_sprites()

void spr_init_sprites ( s32 playerSpriteSet)

Definition at line 764 of file sprite.c.

764 {
765 s32 loadedFlags;
766 s32 i;
767
770 imgfx_init();
771
772 for (i = 0; i < ARRAY_COUNT(spr_playerSprites); i++) {
773 SpriteAnimData** playerSprites = spr_playerSprites;
774 playerSprites[i] = 0;
775 }
776
778
780 playerSpriteSet = PLAYER_SPRITES_PEACH_WORLD;
781 }
782
783 loadedFlags = (&spr_playerSpriteSets[playerSpriteSet])->initiallyLoaded;
784 spr_init_player_raster_cache((&spr_playerSpriteSets[playerSpriteSet])->cacheSize,
785 (&spr_playerSpriteSets[playerSpriteSet])->rasterSize);
786
787 for (i = 1; i <= SPR_Peach3; i++) {
788 if ((loadedFlags >> i) & 1) {
790 }
791 }
792
793 for (i = 0; i < ARRAY_COUNT(spr_playerCurrentAnimInfo); i++) {
796 }
797
798 for (i = 0; i < ARRAY_COUNT(NpcSpriteData); i++) {
799 NpcSpriteData[i] = NULL;
801 }
802
803 for (i = 0; i < ARRAY_COUNT(SpriteInstances); i++) {
806 SpriteInstances[i].spriteData = NULL;
809 }
810
812}
@ PEACH_FLAG_IS_PEACH
Definition enums.h:2488
@ PLAYER_SPRITES_PEACH_WORLD
Definition enums.h:6350
HeapNode * _heap_create(HeapNode *addr, u32 size)
Definition 43F0.c:63
void imgfx_init(void)
Definition imgfx.c:243
#define SPRITE_HEAP_SIZE
Definition macros.h:113
BSS s32 spr_allocateBtlComponentsOnWorldHeap
Definition sprite.c:9
void spr_init_quad_cache(void)
Definition sprite.c:124
BSS SpriteAnimData * NpcSpriteData[0xFF]
Definition sprite.c:16
PlayerSpriteSet spr_playerSpriteSets[]
Definition sprite.c:114
BSS SpriteInstance SpriteInstances[51]
Definition sprite.c:18
BSS u8 NpcSpriteInstanceCount[0xFF]
Definition sprite.c:17
void spr_load_player_sprite(s32 spriteIndex)
Definition sprite.c:755
BSS PlayerCurrentAnimInfo spr_playerCurrentAnimInfo[3]
Definition sprite.c:15
void spr_init_player_raster_cache(s32 cacheSize, s32 maxRasterSize)
SpriteAnimData * spriteData
Definition sprite.h:85
s32 spriteIndex
Definition sprite.h:83
s32 curAnimID
Definition sprite.h:86
SpriteComponent ** componentList
Definition sprite.h:84
SpriteComponent ** componentList
Definition sprite.h:53
s32 notifyValue
Definition sprite.h:87

Referenced by load_demo_battle(), load_engine_data(), load_map_by_IDs(), state_init_logos(), state_init_title_screen(), state_step_battle(), state_step_demo(), state_step_end_battle(), state_step_intro(), state_step_pause(), state_step_startup(), state_step_title_screen(), and state_step_unpause().

◆ spr_render_init()

void spr_render_init ( void )

Definition at line 814 of file sprite.c.

814 {
817}
void spr_update_player_raster_cache(void)
void spr_clear_quad_cache(void)
Definition sprite.c:205

Referenced by gfx_draw_frame().

◆ func_802DDA84()

s32 func_802DDA84 ( void )

Definition at line 819 of file sprite.c.

819 {
820 return 0;
821}

◆ spr_update_player_sprite()

s32 spr_update_player_sprite ( s32 spriteInstanceID,
s32 animID,
f32 timeScale )

Definition at line 823 of file sprite.c.

823 {
824 u32* spriteData;
825 SpriteComponent** compList;
826 SpriteComponent* component;
827 SpriteAnimComponent** animList;
828 SpriteRasterCacheEntry** rasterList;
829 s32 spriteId = ((animID >> 16) & 0xFF) - 1;
830 s32 instanceIdx = spriteInstanceID & 0xFF;
831 s32 animIndex = animID & 0xFF;
832 D_802DF57C = spriteId;
833
834 if (spr_playerCurrentAnimInfo[instanceIdx].componentList == NULL) {
836 spr_playerCurrentAnimInfo[instanceIdx].componentList = compList;
837 while (*compList != PTR_LIST_END) {
838 component = *compList;
839 component->imgfxIdx = imgfx_get_free_instances(1);
840 compList++;
841 }
842 }
843
844 spriteData = (u32*)spr_playerSprites[spriteId];
845 compList = spr_playerCurrentAnimInfo[instanceIdx].componentList;
846
847 if (spriteData == NULL) {
848 return 0;
849 }
850
851 rasterList = (SpriteRasterCacheEntry**)*spriteData;
852 spriteData += 4 + animIndex;
853 animList = (SpriteAnimComponent**)*spriteData;
854
855 spr_set_anim_timescale(timeScale);
856 if ((spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) ||
857 (animID & ~SPRITE_ID_BACK_FACING) != (spr_playerCurrentAnimInfo[instanceIdx].animID & ~SPRITE_ID_BACK_FACING))
858 {
859 spr_init_anim_state(compList, animList);
860 spr_playerCurrentAnimInfo[instanceIdx].notifyValue = 0;
861 }
862
863 spr_playerCurrentAnimInfo[instanceIdx].animID = animID;
864
865 if (!(spriteInstanceID & DRAW_SPRITE_OVERRIDE_YAW)) {
867 compList, animList, rasterList, 0);
868 }
869 return spr_playerCurrentAnimInfo[instanceIdx].notifyValue;
870}
s32 imgfx_get_free_instances(s32)
Definition imgfx.c:338
void spr_set_anim_timescale(f32 timescale)
Definition sprite.c:751
s32 spr_component_update(s32 curNotifyValue, SpriteComponent **compList, SpriteAnimComponent **animList, SpriteRasterCacheEntry **rasterCache, s32 overridePalette)
Definition sprite.c:692
SpriteComponent ** spr_allocate_components(s32)
void spr_init_anim_state(SpriteComponent **compList, SpriteAnimComponent **animList)
Definition sprite.c:741
@ DRAW_SPRITE_OVERRIDE_YAW
Definition sprite.h:21
@ DRAW_SPRITE_OVERRIDE_ALPHA
Definition sprite.h:22
@ SPRITE_ID_BACK_FACING
Definition sprite.h:13

Referenced by appendGfx_player_actor(), player_update_sprite(), set_actor_anim(), set_actor_anim_by_ref(), update_npcs(), and update_player_actor_shadow().

◆ spr_draw_player_sprite()

s32 spr_draw_player_sprite ( s32 spriteInstanceID,
s32 yaw,
s32 alphaIn,
PAL_PTR * paletteList,
Matrix4f mtx )

Definition at line 872 of file sprite.c.

872 {
873 s32 instanceIdx = spriteInstanceID & 0xFF;
874 s32 animID = spr_playerCurrentAnimInfo[instanceIdx].animID;
875 SpriteRasterCacheEntry** rasters;
876 PAL_PTR* palettes;
877 SpriteAnimComponent** animComponents;
878 SpriteComponent** components;
879 f32 zscale;
880 u32 alpha;
881 u32* spriteData;
882 s32 spriteId;
883 s32 spriteIdBackFacing;
884
885 if (animID == ANIM_LIST_END) {
886 return FALSE;
887 }
888
889 D_802DF57C = spriteId = ((animID >> 0x10) & 0xFF) - 1;
890 spriteData = (u32*)spr_playerSprites[spriteId];
891 if (spriteData == NULL) {
892 return FALSE;
893 }
894
895 // TODO: fake match or not?
896 rasters = (SpriteRasterCacheEntry**)*spriteData++;
897 palettes = (PAL_PTR*)*spriteData++;
898 spriteData++;
899 spriteData++;
900 animComponents = (SpriteAnimComponent**)spriteData[animID & 0xFF];
901
902 if (animID & SPRITE_ID_BACK_FACING) {
903 switch (spriteId) {
904 case 0:
905 case 5:
906 case 9:
907 spriteIdBackFacing = spriteId + 1;
908 // TODO find better match
909 rasters = (SpriteRasterCacheEntry**)spr_playerSprites[spriteIdBackFacing];
910 D_802DF57C = spriteIdBackFacing;
911 rasters = (SpriteRasterCacheEntry**)*rasters;
912 break;
913 }
914 }
915
916 if (!(spriteInstanceID & DRAW_SPRITE_OVERRIDE_YAW)) {
917 yaw += (s32)-gCameras[gCurrentCamID].curYaw;
918 if (yaw > 360) {
919 yaw -= 360;
920 }
921 if (yaw < -360) {
922 yaw += 360;
923 }
924 }
925
926 if (yaw > 90 && yaw <= 270 || yaw >= -270 && yaw < -90) {
927 zscale = -1.5f;
928 } else {
929 zscale = 1.5f;
930 }
931
932 if (spriteInstanceID & DRAW_SPRITE_UPSIDE_DOWN) {
933 zscale = 0.0f - zscale;
934 }
935
936 D_802DFEA0[0] = 0;
937 D_802DFEA0[1] = yaw;
938 D_802DFEA0[2] = 0;
939
940
941 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) {
942 alpha = alphaIn & 0xFF;
943 if (alphaIn == 0) {
944 return FALSE;
945 }
946 } else {
947 alpha = 255;
948 }
949
950 components = spr_playerCurrentAnimInfo[instanceIdx].componentList;
951 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_PALETTES) {
952 palettes = paletteList;
953 }
954
955 while (*components != PTR_LIST_END) {
956 spr_draw_component(alpha | DRAW_SPRITE_USE_PLAYER_RASTERS, *components++, *animComponents, rasters, palettes, zscale, mtx);
957 if (*animComponents != PTR_LIST_END) {
958 animComponents++;
959 }
960 }
961
962 return TRUE;
963}
void spr_draw_component(s32 drawOpts, SpriteComponent *component, SpriteAnimComponent *anim, SpriteRasterCacheEntry **cache, PAL_PTR *palettes, f32 zscale, Matrix4f mtx)
Definition sprite.c:425
@ DRAW_SPRITE_OVERRIDE_PALETTES
Definition sprite.h:20
@ DRAW_SPRITE_UPSIDE_DOWN
Definition sprite.h:19
#define ANIM_LIST_END
Terminates an extraAnimationList.
Definition types.h:22

Referenced by appendGfx_npc(), appendGfx_npc_blur(), appendGfx_player(), appendGfx_player_spin(), func_unkA_draw_player(), func_unkB_draw_player(), npc_render_without_adjusted_palettes(), and render_with_adjusted_palettes().

◆ func_802DDEC4()

s32 func_802DDEC4 ( s32 spriteIdx)

Definition at line 965 of file sprite.c.

965 {
966 return spr_playerCurrentAnimInfo[spriteIdx].notifyValue;
967}

Referenced by appendGfx_npc().

◆ set_player_imgfx_comp()

void set_player_imgfx_comp ( s32 spriteIdx,
s32 compIdx,
ImgFXType imgfx,
s32 imgfxArg1,
s32 imgfxArg2,
s32 imgfxArg3,
s32 imgfxArg4,
s32 flags )

Definition at line 969 of file sprite.c.

969 {
970 SpriteComponent* component;
971 SpriteComponent** componentListIt;
972 s32 i;
973
974 if (spr_playerCurrentAnimInfo[spriteIdx].componentList != NULL) {
975 componentListIt = spr_playerCurrentAnimInfo[spriteIdx].componentList;
976 i = 0;
977
978 while (*componentListIt != PTR_LIST_END) {
979 component = *componentListIt;
980 if (compIdx == -1 || i == compIdx) {
981 imgfx_update(component->imgfxIdx & 0xFF, imgfx, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, flags);
982 if (imgfx != IMGFX_CLEAR) {
983 component->imgfxIdx |= SPR_IMGFX_FLAG_10000000;
984 } else {
985 component->imgfxIdx &= ~SPR_IMGFX_FLAG_ALL;
986 }
987 }
988 componentListIt++;
989 i++;
990 }
991 }
992}
s8 flags
Definition demo_api.c:15
@ IMGFX_CLEAR
Definition enums.h:5117
@ SPR_IMGFX_FLAG_10000000
Definition enums.h:5199
void imgfx_update(u32, ImgFXType, s32, s32, s32, s32, s32)
Definition imgfx.c:487

Referenced by appendGfx_player(), appendGfx_player_spin(), entity_CymbalPlant_idle(), render_player_model(), reset_outta_sight_alpha_on_menu_close(), and set_player_imgfx_all().

◆ set_player_imgfx_all()

void set_player_imgfx_all ( s32 animID,
ImgFXType imgfxType,
s32 arg2,
s32 arg3,
s32 arg4,
s32 arg5,
s32 arg6 )

Definition at line 995 of file sprite.c.

995 {
996 set_player_imgfx_comp(PLAYER_SPRITE_MAIN, -1, imgfxType, arg2, arg3, arg4, arg5, arg6);
997}
void set_player_imgfx_comp(s32 spriteIdx, s32 compIdx, ImgFXType imgfx, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 flags)
Definition sprite.c:969
@ PLAYER_SPRITE_MAIN
Definition sprite.h:26

Referenced by appendGfx_player(), appendGfx_player_spin(), entity_BlueWarpPipe_enter_pipe_init(), entity_BlueWarpPipe_enter_pipe_update(), entity_CymbalPlant_idle(), part_glow_off(), part_glow_on(), and update_riding_physics().

◆ spr_get_player_raster_info()

void spr_get_player_raster_info ( SpriteRasterInfo * out,
s32 playerSpriteID,
s32 rasterIndex )

Definition at line 999 of file sprite.c.

999 {
1000 SpriteAnimData* sprite;
1002 u16** paletteOffsetCopy;
1003
1004 playerSpriteID--;
1005 sprite = spr_playerSprites[playerSpriteID];
1006 if (sprite != NULL) {
1007 paletteOffsetCopy = sprite->palettesOffset;
1008 cache = sprite->rastersOffset[rasterIndex];
1009 out->width = cache->width;
1010 out->height = cache->height;
1011 out->defaultPal = paletteOffsetCopy[cache->palette];
1012 out->raster = spr_get_player_raster(rasterIndex, playerSpriteID);
1013 }
1014}

Referenced by gfx_build_knocked_down_player().

◆ spr_get_player_palettes()

◆ spr_load_npc_sprite()

s32 spr_load_npc_sprite ( s32 animID,
u32 * extraAnimList )
Parameters
animID- Set MSB for tail allocation (i.e. 0x80XXYYZZ)

Definition at line 1026 of file sprite.c.

1026 {
1027 SpriteAnimData* header;
1028 SpriteComponent** compList;
1029 s32 listIndex;
1030 s32 i;
1031
1032 s32 spriteIndex = (animID >> 0x10) & 0x7FFF;
1033 s32 useTailAlloc = (u32)animID >> 0x1F;
1034
1035 for (i = 0; i < ARRAY_COUNT(SpriteInstances); i++) {
1036 if (SpriteInstances[i].spriteIndex == 0) {
1037 break;
1038 }
1039 }
1040 if (MaxLoadedSpriteInstanceID < i) {
1042 }
1043 if (i == ARRAY_COUNT(SpriteInstances)) {
1044 return -1;
1045 }
1046 listIndex = i;
1047 if (NpcSpriteData[spriteIndex] != NULL) {
1048 NpcSpriteInstanceCount[spriteIndex]++;
1049 header = NpcSpriteData[spriteIndex];
1050 SpriteInstances[listIndex].spriteData = header;
1051 } else {
1052 NpcSpriteInstanceCount[spriteIndex] = 1;
1053 header = spr_load_sprite(spriteIndex - 1, FALSE, useTailAlloc);
1054 SpriteInstances[listIndex].spriteData = header;
1055 NpcSpriteData[spriteIndex] = header;
1056 if (extraAnimList != NULL) {
1057 spr_load_npc_extra_anims(header, extraAnimList);
1058 }
1059 }
1060 compList = spr_allocate_components(header->maxComponents);
1061 SpriteInstances[listIndex].componentList = compList;
1062 while (*compList != PTR_LIST_END) {
1063 SpriteComponent* comp = *compList;
1065 compList++;
1066 }
1067 SpriteInstances[listIndex].spriteIndex = spriteIndex;
1068 SpriteInstances[listIndex].curAnimID = -1;
1069 return listIndex;
1070}
void spr_load_npc_extra_anims(SpriteAnimData *, u32 *)
BSS s32 MaxLoadedSpriteInstanceID
Definition sprite.c:10

Referenced by create_actor(), create_npc_impl(), load_partner_actor(), npc_reload_all(), pause_init(), pause_partners_init(), pause_spirits_init(), set_npc_sprite(), and update_npcs().

◆ spr_update_sprite()

s32 spr_update_sprite ( s32 spriteInstanceID,
s32 animID,
f32 timeScale )

Definition at line 1072 of file sprite.c.

1072 {
1073 u32* spriteData;
1074 SpriteComponent** compList;
1075 SpriteAnimComponent** animList;
1076 SpriteRasterCacheEntry** rasterList;
1077
1078 s32 palID;
1079 s32 i = spriteInstanceID & 0xFF;
1080 s32 animIndex = animID & 0xFF;
1081
1082 ASSERT_MSG(i <= MaxLoadedSpriteInstanceID, "Invalid sprite instance ID %x", spriteInstanceID);
1083
1084 compList = SpriteInstances[i].componentList;
1085 spriteData = (u32*)SpriteInstances[i].spriteData;
1086
1087 rasterList = (SpriteRasterCacheEntry**)*spriteData;
1088 spriteData += 4 + animIndex;
1089 animList = (SpriteAnimComponent**)*spriteData;
1090
1091 palID = (animID >> 8) & 0xFF;
1092 spr_set_anim_timescale(timeScale);
1093 if ((spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) || ((SpriteInstances[i].curAnimID & 0xFF) != animIndex)) {
1094 ASSERT_MSG(animList != -1, "Anim %x is not loaded", animID);
1095 spr_init_anim_state(compList, animList);
1096 SpriteInstances[i].curAnimID = (palID << 8) | animIndex;
1098 }
1099 if (!(spriteInstanceID & DRAW_SPRITE_OVERRIDE_YAW)) {
1101 compList, animList, rasterList, palID);
1102 }
1103 return SpriteInstances[i].notifyValue;
1104}
#define ASSERT_MSG(condition, msg, args...)
Definition macros.h:66

Referenced by appendGfx_npc_actor(), pause_handle_input(), pause_partners_update(), pause_spirits_update(), set_actor_anim(), set_actor_anim_by_ref(), set_npc_sprite(), update_nonplayer_actor_shadow(), and update_npcs().

◆ spr_draw_npc_sprite()

s32 spr_draw_npc_sprite ( s32 spriteInstanceID,
s32 yaw,
s32 arg2,
PAL_PTR * paletteList,
Matrix4f mtx )

Definition at line 1106 of file sprite.c.

1106 {
1107 s32 i = spriteInstanceID & 0xFF;
1108 s32 animID = SpriteInstances[i].curAnimID;
1109 SpriteRasterCacheEntry** rasters;
1110 PAL_PTR* palettes;
1111 SpriteAnimComponent** animComponents;
1112 SpriteComponent** components;
1113 f32 zscale;
1114 u32 alpha;
1115 u32* spriteData;
1116
1117 if (animID == ANIM_LIST_END) {
1118 return FALSE;
1119 }
1120
1121 spriteData = (u32*)SpriteInstances[i].spriteData;
1122
1123 // TODO: fake match or not?
1124 rasters = (SpriteRasterCacheEntry**)*spriteData++;
1125 palettes = (PAL_PTR*)*spriteData++;
1126 spriteData++;
1127 spriteData++;
1128 animComponents = (SpriteAnimComponent**)spriteData[animID & 0xFF];
1129
1130 D_802DFEA0[0] = 0;
1131 D_802DFEA0[1] = yaw;
1132 D_802DFEA0[2] = 0;
1133
1134 if (!(spriteInstanceID & DRAW_SPRITE_OVERRIDE_YAW)) {
1136 if (yaw > 360) {
1137 yaw -= 360;
1138 }
1139 if (yaw < -360) {
1140 yaw += 360;
1141 }
1142 }
1143
1144 if (yaw > 90 && yaw <= 270 || yaw >= -270 && yaw < -90) {
1145 zscale = -1.5f;
1146 } else {
1147 zscale = 1.5f;
1148 }
1149
1150 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) {
1151 alpha = arg2 & 0xFF;
1152 if (arg2 == 0) {
1153 return FALSE;
1154 }
1155 } else {
1156 alpha = 255;
1157 }
1158
1159 components = SpriteInstances[i].componentList;
1160 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_PALETTES) {
1161 palettes = paletteList;
1162 }
1163
1164 while (*components != PTR_LIST_END) {
1165 spr_draw_component(alpha, *components++, *animComponents, rasters, palettes, zscale, mtx);
1166 if (*animComponents != PTR_LIST_END) {
1167 animComponents++;
1168 }
1169 }
1170
1171 return TRUE;
1172}

Referenced by appendGfx_nonplayer_actor_blur(), appendGfx_npc(), appendGfx_npc_blur(), func_unkA_draw_npc(), func_unkB_draw_npc(), npc_render_with_double_pal_blending(), npc_render_with_single_pal_blending(), npc_render_with_watt_idle_palettes(), npc_render_without_adjusted_palettes(), pause_partners_draw_contents(), pause_spirits_draw_contents(), pause_tutorial_draw_contents(), and render_with_adjusted_palettes().

◆ spr_get_notify_value()

s32 spr_get_notify_value ( s32 spriteIndex)

Definition at line 1174 of file sprite.c.

1174 {
1175 return SpriteInstances[spriteIndex].notifyValue;
1176}

Referenced by appendGfx_npc(), appendGfx_npc_actor(), set_actor_anim(), set_actor_anim_by_ref(), and update_nonplayer_actor_shadow().

◆ spr_free_sprite()

s32 spr_free_sprite ( s32 spriteInstanceID)

Definition at line 1178 of file sprite.c.

1178 {
1179 SpriteInstance* sprite = &SpriteInstances[spriteInstanceID];
1180 SpriteAnimData* spriteData;
1181 SpriteComponent** compList;
1182 s32 spriteIndex = sprite->spriteIndex;
1183
1184 if (spriteIndex == 0 || spriteIndex >= ARRAY_COUNT(NpcSpriteData)) {
1185 return spriteInstanceID;
1186 }
1187
1188 NpcSpriteInstanceCount[spriteIndex]--;
1189 spriteData = sprite->spriteData;
1190
1191 compList = sprite->componentList;
1192 while (*compList != PTR_LIST_END) {
1193 SpriteComponent* comp = *compList;
1194 imgfx_release_instance(comp->imgfxIdx & 0xFF);
1195 compList++;
1196 }
1197
1198 compList = SpriteInstances[spriteInstanceID].componentList;
1199
1200 if (NpcSpriteInstanceCount[spriteIndex] == 0) {
1201 NpcSpriteData[spriteIndex] = NULL;
1202 _heap_free(&heap_spriteHead, spriteData);
1203 }
1204
1206 _heap_free(&heap_generalHead, compList);
1207 } else {
1208 _heap_free(&heap_spriteHead, compList);
1209 }
1210
1211 SpriteInstances[spriteInstanceID].spriteIndex = 0;
1212 SpriteInstances[spriteInstanceID].componentList = NULL;
1213 SpriteInstances[spriteInstanceID].spriteData = NULL;
1214 SpriteInstances[spriteInstanceID].curAnimID = -1;
1215 return 0;
1216}
u32 _heap_free(HeapNode *heapNodeList, void *addrToFree)
Definition 43F0.c:221
void imgfx_release_instance(u32)
Definition imgfx.c:386
HeapNode heap_generalHead
Definition heaps3.c:3

Referenced by btl_delete_actor(), free_npc(), free_npc_by_index(), pause_cleanup(), pause_partners_cleanup(), pause_spirits_cleanup(), and set_npc_sprite().

◆ get_npc_comp_imgfx_idx()

s32 get_npc_comp_imgfx_idx ( s32 spriteIdx,
s32 compIdx )

Definition at line 1218 of file sprite.c.

1218 {
1219 SpriteComponent** componentList = SpriteInstances[spriteIdx].componentList;
1220
1221 if (componentList == NULL) {
1222 return -1;
1223 } else {
1224 return componentList[compIdx]->imgfxIdx & 0xFF;
1225 }
1226}

◆ set_npc_imgfx_comp()

void set_npc_imgfx_comp ( s32 spriteIdx,
s32 compIdx,
ImgFXType imgfx,
s32 imgfxArg1,
s32 imgfxArg2,
s32 imgfxArg3,
s32 imgfxArg4,
s32 imgfxArg5 )

Definition at line 1228 of file sprite.c.

1228 {
1229 SpriteInstance* sprite = &SpriteInstances[spriteIdx];
1230 SpriteComponent** componentList;
1231 s32 i;
1232
1233 if (sprite->componentList != NULL) {
1234 componentList = sprite->componentList;
1235 i = 0;
1236
1237 while (*componentList != PTR_LIST_END) {
1238 SpriteComponent* comp = *componentList;
1239
1240 if (compIdx == -1 || i == compIdx) {
1241 imgfx_update((u8)comp->imgfxIdx, imgfx, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, imgfxArg5);
1242 if (imgfx != IMGFX_CLEAR) {
1244 } else {
1245 comp->imgfxIdx &= ~SPR_IMGFX_FLAG_ALL;
1246 }
1247 }
1248 componentList++;
1249 i++;
1250 }
1251 }
1252}

Referenced by set_npc_imgfx_all().

◆ set_npc_imgfx_all()

void set_npc_imgfx_all ( s32 spriteIdx,
ImgFXType imgfxType,
s32 imgfxArg1,
s32 imgfxArg2,
s32 imgfxArg3,
s32 imgfxArg4,
s32 imgfxArg5 )

Definition at line 1254 of file sprite.c.

1254 {
1255 set_npc_imgfx_comp(spriteIdx, -1, imgfxType, imgfxArg1, imgfxArg2, imgfxArg3, imgfxArg4, imgfxArg5);
1256}
void set_npc_imgfx_comp(s32 spriteIdx, s32 compIdx, ImgFXType imgfx, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 imgfxArg5)
Definition sprite.c:1228

Referenced by appendGfx_npc_blur(), btl_delete_actor(), MagikoopaAI_11(), npc_imgfx_update(), npc_update_decoration_charged(), part_glow_off(), part_glow_on(), pause_partners_draw_contents(), pause_spirits_draw_contents(), pause_tutorial_draw_contents(), SentinelAI_Descend(), and SentinelAI_LosePlayerInit().

◆ spr_get_comp_position()

s32 spr_get_comp_position ( s32 spriteIdx,
s32 compListIdx,
s32 * outX,
s32 * outY,
s32 * outZ )

Definition at line 1258 of file sprite.c.

1258 {
1259 SpriteInstance* sprite = &SpriteInstances[spriteIdx];
1260 SpriteAnimComponent** animCompList;
1261 SpriteAnimComponent* anim;
1262 SpriteComponent** compList;
1263 SpriteComponent* comp;
1264 u8 animID;
1265 s32 i;
1266 u32* spriteData;
1267
1268 if (sprite->componentList == NULL) {
1269 return; // bug: does not return a value
1270 }
1271
1272 animID = sprite->curAnimID;
1273 if (animID != 255) {
1274 // following 3 lines equivalent to:
1275 // animCompList = sprite->spriteData->animListStart[animID];
1276 spriteData = (u32*)sprite->spriteData;
1277 spriteData += 4 + animID;
1278 animCompList = (SpriteAnimComponent**)*spriteData;
1279 compList = sprite->componentList;
1280 i = 0;
1281 while (*compList != PTR_LIST_END) {
1282 if (i == compListIdx) {
1283 anim = *animCompList;
1284 comp = *compList;
1285 *outX = comp->compPos.x + anim->compOffset.x;
1286 *outY = comp->compPos.y + anim->compOffset.y;
1287 *outZ = comp->compPos.z + anim->compOffset.z;
1288 return 0;
1289 }
1290 i++;
1291 compList++;
1292 if (*animCompList != PTR_LIST_END) {
1293 animCompList++;
1294 }
1295 }
1296 } else {
1297 return; // bug: does not return a value
1298 }
1299 return -1;
1300}

◆ spr_get_npc_raster_info()

s32 spr_get_npc_raster_info ( SpriteRasterInfo * out,
s32 npcSpriteID,
s32 rasterIndex )

Definition at line 1302 of file sprite.c.

1302 {
1303 SpriteAnimData* sprite = NpcSpriteData[npcSpriteID];
1305 PAL_PTR* paletteOffsetCopy;
1306
1307 if (sprite != NULL) {
1308 paletteOffsetCopy = sprite->palettesOffset;
1309 cache = sprite->rastersOffset[rasterIndex];
1310 out->raster = cache->image;
1311 out->width = cache->width;
1312 out->height = cache->height;
1313 out->defaultPal = paletteOffsetCopy[cache->palette];
1314 return TRUE;
1315 }
1316 return FALSE;
1317}

Referenced by appendGfx_message().

◆ spr_get_npc_palettes()

◆ spr_get_npc_color_variations()

s32 spr_get_npc_color_variations ( s32 npcSpriteID)

Definition at line 1329 of file sprite.c.

1329 {
1330 SpriteAnimData* sprite = NpcSpriteData[npcSpriteID];
1331
1332 if (sprite != NULL) {
1333 return sprite->colorVariations;
1334 } else {
1335 return -1;
1336 }
1337}
s32 colorVariations
Definition sprite.h:78

Referenced by npc_reload_all(), npc_render_with_watt_idle_palettes(), render_with_palset_blending(), render_with_player_debuff_palettes(), render_with_poison_palettes(), render_with_static_palettes(), render_with_watt_attack_palettes(), and render_with_watt_idle_palettes().

Variable Documentation

◆ heap_generalHead

HeapNode heap_generalHead
extern

Definition at line 3 of file heaps3.c.

Referenced by spr_free_sprite().

◆ heap_spriteHead

HeapNode heap_spriteHead
extern

Definition at line 4 of file heaps3.c.

Referenced by spr_free_sprite(), spr_init_quad_cache(), and spr_init_sprites().

◆ spr_allocateBtlComponentsOnWorldHeap

BSS s32 spr_allocateBtlComponentsOnWorldHeap

Definition at line 9 of file sprite.c.

Referenced by spr_allocate_components(), spr_free_sprite(), and spr_init_sprites().

◆ MaxLoadedSpriteInstanceID

BSS s32 MaxLoadedSpriteInstanceID

Definition at line 10 of file sprite.c.

Referenced by spr_load_npc_sprite(), and spr_update_sprite().

◆ D_802DF540

BSS s32 D_802DF540

Definition at line 11 of file sprite.c.

Referenced by spr_appendGfx_component(), and spr_draw_component().

◆ spr_playerSprites

◆ D_802DF57C

BSS s32 D_802DF57C

Definition at line 13 of file sprite.c.

Referenced by spr_draw_component(), spr_draw_player_sprite(), and spr_update_player_sprite().

◆ spr_playerMaxComponents

BSS s32 spr_playerMaxComponents

Definition at line 14 of file sprite.c.

Referenced by spr_init_sprites(), spr_load_player_sprite(), and spr_update_player_sprite().

◆ spr_playerCurrentAnimInfo

◆ NpcSpriteData

◆ NpcSpriteInstanceCount

BSS u8 NpcSpriteInstanceCount[0xFF]

Definition at line 17 of file sprite.c.

Referenced by spr_free_sprite(), spr_init_sprites(), and spr_load_npc_sprite().

◆ SpriteInstances

◆ D_802DFE44

BSS Quad* D_802DFE44

Definition at line 19 of file sprite.c.

Referenced by spr_get_cached_quad(), and spr_init_quad_cache().

◆ D_802DFE48

BSS s32 D_802DFE48[22]

◆ D_802DFEA0

BSS s32 D_802DFEA0[3]

Definition at line 21 of file sprite.c.

Referenced by spr_draw_component(), spr_draw_npc_sprite(), and spr_draw_player_sprite().

◆ SpriteUpdateNotifyValue

BSS s32 SpriteUpdateNotifyValue

Definition at line 22 of file sprite.c.

Referenced by spr_component_update(), and spr_component_update_commands().

◆ spr_defaultQuad

Quad spr_defaultQuad
Initial value:
= {
{
{{{ -16, 56, 0 }, FALSE, { 0, 0 }, { 240, 240, 240, 255 }}},
{{{ 16, 56, 0 }, FALSE, { 1024, 0 }, { 120, 120, 120, 255 }}},
{{{ 16, 0, 0 }, FALSE, { 1024, 1792 }, { 0, 0, 0, 255 }}},
{{{ -16, 0, 0 }, FALSE, { 0, 1792 }, { 120, 120, 120, 255 }}},
}
}

Definition at line 28 of file sprite.c.

28 {
29 {
30 {{{ -16, 56, 0 }, FALSE, { 0, 0 }, { 240, 240, 240, 255 }}},
31 {{{ 16, 56, 0 }, FALSE, { 1024, 0 }, { 120, 120, 120, 255 }}},
32 {{{ 16, 0, 0 }, FALSE, { 1024, 1792 }, { 0, 0, 0, 255 }}},
33 {{{ -16, 0, 0 }, FALSE, { 0, 1792 }, { 120, 120, 120, 255 }}},
34 }
35};

Referenced by spr_make_quad_for_size().

◆ SprPauseVp

Vp SprPauseVp
Initial value:
= {{
{ 640, 480, 511, 0 },
{ 640, 480, 511, 0 },
}
}

Definition at line 37 of file sprite.c.

37 {{
38 { 640, 480, 511, 0 },
39 { 640, 480, 511, 0 },
40 }
41};

Referenced by spr_appendGfx_component_flat().

◆ SprPauseVpAlt

Vp SprPauseVpAlt
Initial value:
= {{
{ 640, 480, 511, 0 },
{ 640, 480, 512, 0 },
}
}

Definition at line 43 of file sprite.c.

43 {{
44 { 640, 480, 511, 0 },
45 { 640, 480, 512, 0 },
46 }
47};

Referenced by spr_appendGfx_component_flat().

◆ D_802DF3F0

Gfx D_802DF3F0[]
Initial value:
= {
gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA),
gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
gsDPSetRenderMode(AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM), AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)),
gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE),
gsSPEndDisplayList(),
}

Definition at line 49 of file sprite.c.

49 {
50 gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
51 gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA),
52 gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
53 gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
54 gsDPSetRenderMode(AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM), AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)),
55 gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE),
56 gsSPEndDisplayList(),
57};

Referenced by spr_appendGfx_component().

◆ D_802DF428

Gfx D_802DF428[]
Initial value:
= {
gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
gsDPSetCombineMode(PM_CC_02, PM_CC_02),
gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
gsDPSetRenderMode(G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2),
gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE),
gsSPEndDisplayList(),
}
#define PM_CC_02
Definition macros.h:277

Definition at line 59 of file sprite.c.

59 {
60 gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
61 gsDPSetCombineMode(PM_CC_02, PM_CC_02),
62 gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
63 gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
64 gsDPSetRenderMode(G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2),
65 gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE),
66 gsSPEndDisplayList(),
67};

Referenced by spr_appendGfx_component().

◆ D_802DF460

Gfx D_802DF460[]
Initial value:
= {
gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
gsDPSetRenderMode(AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | G_RM_PASS, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)),
gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE),
gsSPEndDisplayList(),
}

Definition at line 69 of file sprite.c.

69 {
70 gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
71 gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
72 gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
73 gsDPSetRenderMode(AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | G_RM_PASS, AA_EN | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)),
74 gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE),
75 gsSPEndDisplayList(),
76};

Referenced by spr_appendGfx_component().

◆ D_802DF490

Gfx D_802DF490[]
Initial value:
= {
gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
gsDPSetRenderMode(G_RM_PASS, G_RM_ZB_CLD_SURF2),
gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE),
gsSPEndDisplayList(),
}

Definition at line 78 of file sprite.c.

78 {
79 gsSPClearGeometryMode(G_CULL_BOTH | G_LIGHTING),
80 gsSPTexture(-1, -1, 0, G_TX_RENDERTILE, G_ON),
81 gsSPSetGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH),
82 gsDPSetRenderMode(G_RM_PASS, G_RM_ZB_CLD_SURF2),
83 gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 18, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE),
84 gsSPEndDisplayList(),
85};

Referenced by spr_appendGfx_component().

◆ spr_animUpdateTimeScale

f32 spr_animUpdateTimeScale = 1.0f

Definition at line 87 of file sprite.c.

Referenced by spr_component_update_commands(), and spr_set_anim_timescale().

◆ spr_playerSpriteSets

PlayerSpriteSet spr_playerSpriteSets[]
Initial value:
= {
[PLAYER_SPRITES_MARIO_WORLD] { 6, 0x700, 1 << SPR_Mario1 | 1 << SPR_Mario1_Back | 1 << SPR_MarioW1 | 1 << SPR_MarioW1_Back | 1 << SPR_MarioW2 | 1 << SPR_MarioW3 },
[PLAYER_SPRITES_MARIO_REFLECT_FLOOR] { 18, 0x700, 1 << SPR_Mario1 | 1 << SPR_Mario1_Back | 1 << SPR_MarioW1 | 1 << SPR_MarioW1_Back | 1 << SPR_MarioW2 | 1 << SPR_MarioW3 },
[PLAYER_SPRITES_COMBINED_EPILOGUE] { 10, 0x900, 1 << SPR_Mario1 | 1 << SPR_Mario1_Back | 1 << SPR_MarioW1 | 1 << SPR_MarioW1_Back | 1 << SPR_MarioW2 | 1 << SPR_MarioW3 | 1 << SPR_Peach1 | 1 << SPR_Peach1_Back | 1 << SPR_Peach2 | 1 << SPR_Peach3 },
[PLAYER_SPRITES_MARIO_PARADE] { 3, 0x700, 1 << SPR_Mario1 | 1 << SPR_Mario1_Back },
[PLAYER_SPRITES_PEACH_WORLD] { 6, 0x900, 1 << SPR_Peach1 | 1 << SPR_Peach1_Back | 1 << SPR_Peach2 | 1 << SPR_Peach3 },
[PLAYER_SPRITES_MARIO_BATTLE] { 6, 0x700, 1 << SPR_Mario1 | 1 << SPR_Mario1_Back | 1 << SPR_MarioB1 | 1 << SPR_MarioB2 | 1 << SPR_MarioB3 },
[PLAYER_SPRITES_PEACH_BATTLE] { 6, 0x900, 1 << SPR_Peach1 | 1 << SPR_Peach1_Back | 1 << SPR_Peach2 | 1 << SPR_Peach3 },
}
@ PLAYER_SPRITES_MARIO_WORLD
Definition enums.h:6346
@ PLAYER_SPRITES_COMBINED_EPILOGUE
Definition enums.h:6348
@ PLAYER_SPRITES_MARIO_REFLECT_FLOOR
Definition enums.h:6347
@ PLAYER_SPRITES_PEACH_BATTLE
Definition enums.h:6352
@ PLAYER_SPRITES_MARIO_PARADE
Definition enums.h:6349
@ PLAYER_SPRITES_MARIO_BATTLE
Definition enums.h:6351

Definition at line 114 of file sprite.c.

Referenced by spr_init_sprites().