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

Go to the source code of this file.

Data Structures

struct  SpriteComponent
 
struct  PlayerCurrentAnimInfo
 
struct  SpriteAnimComponent
 
struct  SpriteRasterCacheEntry
 
struct  SpriteAnimData
 Sprite data header. More...
 
struct  SpriteInstance
 
struct  PlayerRastersHeader
 
struct  PlayerSpriteSet
 
struct  PlayerSpriteCacheEntry
 
struct  Quad
 

Macros

#define SPR_PLAYER_COLOR_VARIATIONS   6
 
#define SPR_PEACH_BTL_PAL_STRIDE   4
 

Enumerations

enum  SpriteIDFields {
  SPRITE_ID_ANIM_MASK = 0x000000FF , SPRITE_ID_PAL_MASK = 0x0000FF00 , SPRITE_ID_SPR_MASK = 0x00FF0000 , SPRITE_ID_BACK_FACING = 0x01000000 ,
  SPRITE_ID_TAIL_ALLOCATE = 0x80000000
}
 
enum  DrawSpriteOptions {
  DRAW_SPRITE_USE_PLAYER_RASTERS = 0x08000000 , DRAW_SPRITE_UPSIDE_DOWN = 0x10000000 , DRAW_SPRITE_OVERRIDE_PALETTES = 0x20000000 , DRAW_SPRITE_OVERRIDE_YAW = 0x40000000 ,
  DRAW_SPRITE_OVERRIDE_ALPHA = 0x80000000
}
 
enum  { PLAYER_SPRITE_MAIN = 0 , PLAYER_SPRITE_AUX1 = 1 , PLAYER_SPRITE_AUX2 = 2 }
 
enum  { SPRITE_MODE_PLAYER = 0 , SPRITE_MODE_NPC = 1 }
 

Functions

void imgfx_init (void)
 
void spr_init_sprites (s32 playerSpriteSet)
 
void spr_render_init (void)
 
void spr_update_player_raster_cache (void)
 
s32 spr_update_player_sprite (s32 arg0, s32 arg1, f32 timescale)
 
s32 spr_draw_player_sprite (s32 spriteInstanceID, s32 yaw, s32 arg2, PAL_PTR *paletteList, Matrix4f mtx)
 
s32 func_802DDEC4 (s32 arg0)
 
void set_player_imgfx_comp (s32, s32, ImgFXType, s32, s32, s32, s32, s32)
 
void set_player_imgfx_all (s32, ImgFXType, s32, s32, s32, s32, s32)
 
IMG_PTR spr_get_player_raster (s32 rasterIndex, s32 playerSpriteID)
 
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 arg0)
 
s32 spr_free_sprite (s32 spriteInstanceID)
 
s32 get_npc_comp_imgfx_idx (s32, s32)
 
void set_npc_imgfx_comp (s32, s32, ImgFXType, s32, s32, s32, s32, s32)
 
void set_npc_imgfx_all (s32 arg0, ImgFXType arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
 
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)
 
void create_shading_palette (Matrix4f mtx, s32 uls, s32 ult, s32 lrs, s32 lrt, s32 alpha, s32)
 
SpriteAnimDataspr_load_sprite (s32 idx, s32 arg1, s32 arg2)
 

Variables

Quad spr_defaultQuad
 
Vp SprPauseVp
 
Vp SprPauseVpAlt
 
Gfx D_802DF3F0 []
 
Gfx D_802DF428 []
 
Gfx D_802DF460 []
 
Gfx D_802DF490 []
 
f32 spr_animUpdateTimeScale
 
PlayerSpriteSet spr_playerSpriteSets [7]
 

Data Structure Documentation

◆ SpriteComponent

struct SpriteComponent
Data Fields
s32 initialized
s32 properties AABBCCCC : AA = unused?, BB = parent, CCCC = notify value.
s16 * readPos
f32 waitTime
s32 loopCounter
s32 curRaster
s32 curPalette
Vec3f posOffset
Vec3f compPos
Vec3i rot
Vec3f scale
s32 imgfxIdx

◆ PlayerCurrentAnimInfo

struct PlayerCurrentAnimInfo
Data Fields
SpriteComponent ** componentList
s32 animID
s32 notifyValue

◆ SpriteAnimComponent

struct SpriteAnimComponent
Data Fields
u16 * cmdList
s16 cmdListSize
Vec3s compOffset

◆ SpriteRasterCacheEntry

struct SpriteRasterCacheEntry
Data Fields
IMG_PTR image
u8 width
u8 height
s8 palette
s8 quadCacheIndex

◆ SpriteAnimData

struct SpriteAnimData
Data Fields
SpriteRasterCacheEntry ** rastersOffset
PAL_PTR * palettesOffset
s32 maxComponents
s32 colorVariations
SpriteAnimComponent ** animListStart[VLA]

◆ SpriteInstance

struct SpriteInstance
Data Fields
s32 spriteIndex
SpriteComponent ** componentList
SpriteAnimData * spriteData
s32 curAnimID
s32 notifyValue

◆ PlayerRastersHeader

struct PlayerRastersHeader
Data Fields
s32 indexRanges
s32 loadDescriptors
s32 imageData

◆ PlayerSpriteSet

struct PlayerSpriteSet
Data Fields
s32 cacheSize Number of cache entries.
s32 rasterSize Maximum raster size.
s32 initiallyLoaded Flags saying which rasters to load into the cache in spr_init_sprites(), with each bit corresponding to the Nth raster (with LSB = raster 0).

◆ PlayerSpriteCacheEntry

struct PlayerSpriteCacheEntry
Data Fields
s32 lazyDeleteTime
s32 rasterIndex
s32 spriteIndex
IMG_PTR raster

◆ Quad

struct Quad
Data Fields
Vtx v[4]

Macro Definition Documentation

◆ SPR_PLAYER_COLOR_VARIATIONS

◆ SPR_PEACH_BTL_PAL_STRIDE

#define SPR_PEACH_BTL_PAL_STRIDE   4

Definition at line 7 of file sprite.h.

Referenced by render_with_player_debuff_palettes().

Enumeration Type Documentation

◆ SpriteIDFields

Enumerator
SPRITE_ID_ANIM_MASK 
SPRITE_ID_PAL_MASK 
SPRITE_ID_SPR_MASK 
SPRITE_ID_BACK_FACING 
SPRITE_ID_TAIL_ALLOCATE 

Definition at line 9 of file sprite.h.

9 {
10 SPRITE_ID_ANIM_MASK = 0x000000FF,
11 SPRITE_ID_PAL_MASK = 0x0000FF00,
12 SPRITE_ID_SPR_MASK = 0x00FF0000,
13 SPRITE_ID_BACK_FACING = 0x01000000,
14 SPRITE_ID_TAIL_ALLOCATE = 0x80000000,
15};
@ SPRITE_ID_SPR_MASK
Definition sprite.h:12
@ SPRITE_ID_ANIM_MASK
Definition sprite.h:10
@ SPRITE_ID_TAIL_ALLOCATE
Definition sprite.h:14
@ SPRITE_ID_PAL_MASK
Definition sprite.h:11
@ SPRITE_ID_BACK_FACING
Definition sprite.h:13

◆ DrawSpriteOptions

Enumerator
DRAW_SPRITE_USE_PLAYER_RASTERS 
DRAW_SPRITE_UPSIDE_DOWN 
DRAW_SPRITE_OVERRIDE_PALETTES 
DRAW_SPRITE_OVERRIDE_YAW 
DRAW_SPRITE_OVERRIDE_ALPHA 

Definition at line 17 of file sprite.h.

17 {
19 DRAW_SPRITE_UPSIDE_DOWN = 0x10000000,
21 DRAW_SPRITE_OVERRIDE_YAW = 0x40000000,
22 DRAW_SPRITE_OVERRIDE_ALPHA = 0x80000000,
23};
@ DRAW_SPRITE_OVERRIDE_YAW
Definition sprite.h:21
@ DRAW_SPRITE_OVERRIDE_ALPHA
Definition sprite.h:22
@ DRAW_SPRITE_OVERRIDE_PALETTES
Definition sprite.h:20
@ DRAW_SPRITE_UPSIDE_DOWN
Definition sprite.h:19
@ DRAW_SPRITE_USE_PLAYER_RASTERS
Definition sprite.h:18

◆ anonymous enum

anonymous enum
Enumerator
PLAYER_SPRITE_MAIN 
PLAYER_SPRITE_AUX1 
PLAYER_SPRITE_AUX2 

Definition at line 25 of file sprite.h.

25 {
29};
@ PLAYER_SPRITE_AUX1
Definition sprite.h:27
@ PLAYER_SPRITE_AUX2
Definition sprite.h:28
@ PLAYER_SPRITE_MAIN
Definition sprite.h:26

◆ anonymous enum

anonymous enum
Enumerator
SPRITE_MODE_PLAYER 
SPRITE_MODE_NPC 

Definition at line 32 of file sprite.h.

32 {
35};
@ SPRITE_MODE_NPC
Definition sprite.h:34
@ SPRITE_MODE_PLAYER
Definition sprite.h:33

Function Documentation

◆ imgfx_init()

void imgfx_init ( void )

Definition at line 243 of file imgfx.c.

243 {
244 s32 i;
245
246 for (i = 0; i < ARRAY_COUNT(ImgFXVtxBuffers); i++) {
248 }
249
251
252 for (i = 0; i < ARRAY_COUNT(*ImgFXInstances); i++) {
255 }
256
257 for (i = 0; i < ARRAY_COUNT(ImgFXDataCache); i++) {
258 ImgFXDataCache[i].data = NULL;
261 }
262
263 imgfx_vtxCount = 0;
265}
void * _heap_malloc(HeapNode *head, u32 size)
Definition 43F0.c:78
ImgFXState ImgFXInstanceList[MAX_IMGFX_INSTANCES]
Definition imgfx.c:112
void imgfx_clear_instance_data(ImgFXState *state)
Definition imgfx.c:443
u16 imgfx_vtxCount
Definition imgfx.c:126
BSS Vtx * ImgFXVtxBuffers[2]
Definition imgfx.c:117
u8 usingContextualHeap
Definition imgfx.c:98
BSS ImgFXInstanceList * ImgFXInstances
Definition imgfx.c:119
BSS Vtx * imgfx_vtxBuf
Definition imgfx.c:118
s32 * data
Definition imgfx.c:96
u16 ImgFXVtxBufferCapacity
Definition imgfx.c:144
HeapNode heap_spriteHead
Definition heaps3.c:4
void imgfx_init_instance(ImgFXState *state)
Definition imgfx.c:453
BSS ImgFXCacheEntry ImgFXDataCache[8]
Definition imgfx.c:121
u8 staleCooldownTimer
Definition imgfx.c:97
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 gCurrentDisplayContextIndex
Definition main_loop.c:47

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
BSS SpriteAnimData * spr_playerSprites[13]
Definition sprite.c:12
BSS s32 spr_playerMaxComponents
Definition sprite.c:14
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
HeapNode heap_spriteHead
Definition heaps3.c:4
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
Sprite data header.
Definition sprite.h:74
GameStatus * gGameStatusPtr
Definition main_loop.c:32

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().

◆ spr_update_player_raster_cache()

void spr_update_player_raster_cache ( void )

Definition at line 217 of file 101b90_len_8f0.c.

217 {
218 s32 i;
219
221
222 for (i = 0; i < PlayerRasterCacheSize; i++) {
223 if (PlayerRasterCache[i].lazyDeleteTime != 0) {
225 }
226 }
227}
BSS s32 PlayerRasterCacheSize
BSS PlayerSpriteCacheEntry PlayerRasterCache[18]
void func_8013A4D0(void)
Definition imgfx.c:267

Referenced by spr_render_init().

◆ spr_update_player_sprite()

s32 spr_update_player_sprite ( s32 arg0,
s32 arg1,
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
#define PTR_LIST_END
Definition macros.h:42
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
BSS s32 D_802DF57C
Definition sprite.c: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 arg2,
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}
#define PAL_PTR
void spr_draw_component(s32 drawOpts, SpriteComponent *component, SpriteAnimComponent *anim, SpriteRasterCacheEntry **cache, PAL_PTR *palettes, f32 zscale, Matrix4f mtx)
Definition sprite.c:425
BSS s32 D_802DFEA0[3]
Definition sprite.c:21
#define ANIM_LIST_END
Terminates an extraAnimationList.
Definition types.h:22
Camera gCameras[4]
Definition cam_main.c:17
s16 gCurrentCamID
Definition cam_main.c:13

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 arg0)

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

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()

IMG_PTR spr_get_player_raster ( s32 rasterIndex,
s32 playerSpriteID )

Definition at line 184 of file 101b90_len_8f0.c.

184 {
185 PlayerSpriteCacheEntry* cacheEntry;
186 u32 playerRasterInfo;
187 s32 idx = -1;
188 s32 i;
189
190 for (i = 0; i < PlayerRasterCacheSize; i++) {
191 if (PlayerRasterCache[i].lazyDeleteTime != 0) {
192 if (PlayerRasterCache[i].rasterIndex == rasterIndex && PlayerRasterCache[i].spriteIndex == playerSpriteID) {
194 return PlayerRasterCache[i].raster;
195 }
196 } else if (idx == -1) {
197 idx = i;
198 }
199 }
200
201 if (idx == -1) {
202 return NULL;
203 }
204
205 cacheEntry = &PlayerRasterCache[idx];
206 cacheEntry->rasterIndex = rasterIndex;
207 cacheEntry->spriteIndex = playerSpriteID;
208 cacheEntry->lazyDeleteTime = 2;
209
210 // each player raster load descriptor has image size (in bytes) and relative offset packed into one word
211 // upper three nibbles give size / 16, lower 5 give offset
212 playerRasterInfo = PlayerRasterLoadDesc[PlayerRasterLoadDescBeginSpriteIndex[playerSpriteID] + rasterIndex];
213 nuPiReadRom(SpriteDataHeader[0] + (playerRasterInfo & 0xFFFFF), cacheEntry->raster, (playerRasterInfo >> 0x10) & 0xFFF0);
214 return cacheEntry->raster;
215}
BSS s32 SpriteDataHeader[3]
BSS s32 PlayerRasterLoadDesc[0x2E0]
BSS s32 PlayerRasterLoadDescBeginSpriteIndex[SPR_Peach3]

Referenced by spr_draw_component(), and spr_get_player_raster_info().

◆ 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}
IMG_PTR spr_get_player_raster(s32 rasterIndex, s32 playerSpriteID)
SpriteRasterCacheEntry ** rastersOffset
Definition sprite.h:75
PAL_PTR * palettesOffset
Definition sprite.h:76

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}
SpriteAnimData * spr_load_sprite(s32 idx, s32 isPlayerSprite, s32 useTailAlloc)
void spr_load_npc_extra_anims(SpriteAnimData *, u32 *)
BSS s32 MaxLoadedSpriteInstanceID
Definition sprite.c:10
s32 maxComponents
Definition sprite.h:77

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 arg0)

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 arg0,
ImgFXType arg1,
s32 arg2,
s32 arg3,
s32 arg4,
s32 arg5,
s32 arg6 )

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}
Vec3f compPos
Definition sprite.h:46

◆ 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().

◆ create_shading_palette()

void create_shading_palette ( Matrix4f mtx,
s32 uls,
s32 ult,
s32 lrs,
s32 lrt,
s32 alpha,
s32 otherModeLBits )

Definition at line 66 of file sprite_shading.c.

66 {
68 SpriteShadingLightSource* lightSource;
69 f32 shadowDirX, shadowDirY, shadowDirZ;
70 f32 posX, posY, posZ;
71 f32 facingDir;
72 f32 Mxz, Myz, Mzz;
73 f32 shadowColorR, shadowColorG, shadowColorB;
74 f32 commonColorR, commonColorG, commonColorB;
75 f32 backColorR, backColorG, backColorB;
76 f32 frontColorR, frontColorG, frontColorB;
77 f32 shadowIntensity;
78 f32 lightIntensity;
79 f32 intensityScale;
80 f32 temp_f10;
81 f32 temp_f16;
82 f32 distSq;
83 f32 dx, dy, dz;
84 f32 dist;
85 f32 invDist;
86 f32 qx, qy, qz;
87 f32 wx, wy, wz;
88 f32 ex, ey, ez;
89 f32 Pxz, Pzz;
90 s32 i;
91
92 shadowDirX = 0.0f;
93 shadowDirY = 0.0f;
94 shadowDirZ = 0.0f;
95
96 posX = mtx[3][0];
97 posY = mtx[3][1];
98 posZ = mtx[3][2];
99
100 Mxz = mtx[0][2];
101 Myz = mtx[1][2];
102 Mzz = mtx[2][2];
103
104 commonColorR = 0.0f;
105 commonColorG = 0.0f;
106 commonColorB = 0.0f;
107
108 backColorR = 0.0f;
109 backColorG = 0.0f;
110 backColorB = 0.0f;
111
112 frontColorR = 0.0f;
113 frontColorG = 0.0f;
114 frontColorB = 0.0f;
115
116 shadowColorR = gSpriteShadingProfile->ambientColor.r;
117 shadowColorG = gSpriteShadingProfile->ambientColor.g;
118 shadowColorB = gSpriteShadingProfile->ambientColor.b;
119
120 Pxz = camera->mtxPerspective[0][2];
121 Pzz = camera->mtxPerspective[2][2];
122
123 if ((-Mxz * Pxz + Mzz * Pzz) < 0.0f) {
124 facingDir = 1.0f;
125 } else {
126 facingDir = -1.0f;
127 }
128
129 for (i = 0; i < ARRAY_COUNT(gSpriteShadingProfile->sources); i++) {
130 lightSource = &gSpriteShadingProfile->sources[i];
131 if (lightSource->flags & LIGHT_SOURCE_ENABLED) {
132 dx = posX - lightSource->pos.x;
133 dy = posY - lightSource->pos.y;
134 dz = posZ - lightSource->pos.z;
135
136 distSq = SQ(dx) + SQ(dy) + SQ(dz);
137
138 if (distSq != 0.0f) {
139 dist = sqrtf(distSq);
140 invDist = 1.0f / dist;
141 } else {
142 dist = 0.0f;
143 invDist = 0.0f;
144 }
145
146 // normalize dx/dy/dz
147 // they now form a normal vector pointing from light source to sprite
148 dx *= invDist;
149 dy *= invDist;
150 dz *= invDist;
151
152 // apply falloff from light source
153 if (lightSource->flags & LIGHT_SOURCE_LINEAR_FALLOFF) {
154 if ((dist == 0.0f) && (lightSource->falloff == 0.0f)) {
155 intensityScale = 1.0f;
156 } else {
157 intensityScale = 1.0f / (dist * lightSource->falloff);
158 dx *= intensityScale;
159 dy *= intensityScale;
160 dz *= intensityScale;
161 }
162 } else if (lightSource->flags & LIGHT_SOURCE_QUADRATIC_FALLOFF) {
163 if ((distSq == 0.0f) && (lightSource->falloff == 0.0f)) {
164 intensityScale = 1.0f;
165 } else {
166 intensityScale = 1.0f / (distSq * lightSource->falloff);
167 dx *= intensityScale;
168 dy *= intensityScale;
169 dz *= intensityScale;
170 }
171 } else {
172 intensityScale = 1.0f;
173 }
174
175 if (intensityScale > 1.0f) {
176 intensityScale = 1.0f;
177 }
178
179 shadowDirX += dx;
180 shadowDirY += dy;
181 shadowDirZ += dz;
182
183 if (facingDir < 0.0f) {
184 ex = Mxz;
185 ey = Myz;
186 ez = -Mzz;
187 } else {
188 ex = -Mxz;
189 ey = Myz;
190 ez = Mzz;
191 }
192 temp_f10 = ex * dx + ey * dy + ez * dz;
193
194 if (facingDir < 0.0f) {
195 wx = Mzz;
196 wy = Myz;
197 wz = Mxz;
198 } else {
199 wx = -Mzz;
200 wy = Myz;
201 wz = -Mxz;
202 }
203 temp_f16 = wx * dx + wy * dy + wz * dz;
204
205 shadowIntensity = intensityScale * fabsf(temp_f10);
206 lightIntensity = intensityScale * fabsf(temp_f16);
207 if (temp_f10 > 0.0f) {
208 commonColorR += lightSource->rgb.r * shadowIntensity;
209 commonColorG += lightSource->rgb.g * shadowIntensity;
210 commonColorB += lightSource->rgb.b * shadowIntensity;
211 if (temp_f16 > 0.0f) {
212 backColorR += lightSource->rgb.r * lightIntensity;
213 backColorG += lightSource->rgb.g * lightIntensity;
214 backColorB += lightSource->rgb.b * lightIntensity;
215 } else {
216 frontColorR += lightSource->rgb.r * lightIntensity;
217 frontColorG += lightSource->rgb.g * lightIntensity;
218 frontColorB += lightSource->rgb.b * lightIntensity;
219 }
220 } else {
221 shadowColorR += lightSource->rgb.r * shadowIntensity;
222 shadowColorG += lightSource->rgb.g * shadowIntensity;
223 shadowColorB += lightSource->rgb.b * shadowIntensity;
224 if (temp_f16 > 0.0f) {
225 backColorR += lightSource->rgb.r * lightIntensity;
226 backColorG += lightSource->rgb.g * lightIntensity;
227 backColorB += lightSource->rgb.b * lightIntensity;
228 } else {
229 frontColorR += lightSource->rgb.r * lightIntensity;
230 frontColorG += lightSource->rgb.g * lightIntensity;
231 frontColorB += lightSource->rgb.b * lightIntensity;
232 }
233 }
234 }
235 }
236
237 if (facingDir < 0.0f) {
238 qx = Mzz;
239 qy = Myz;
240 qz = Mxz;
241 } else {
242 qx = -Mzz;
243 qy = Myz;
244 qz = -Mxz;
245 }
246
247 if (qx * shadowDirX + qy * shadowDirY + qz * shadowDirZ > 0.0f) {
249 mtx,
250 uls, ult, lrs, lrt,
251 alpha,
252 shadowDirX, shadowDirY, shadowDirZ,
253 shadowColorR, shadowColorG, shadowColorB,
254 gSpriteShadingProfile->ambientColor.r + commonColorR + backColorR,
255 gSpriteShadingProfile->ambientColor.g + commonColorG + backColorG,
256 gSpriteShadingProfile->ambientColor.b + commonColorB + backColorB,
258 otherModeLBits
259 );
260 } else {
262 mtx,
263 uls, ult, lrs, lrt,
264 alpha,
265 shadowDirX, shadowDirY, shadowDirZ,
266 shadowColorR, shadowColorG, shadowColorB,
267 gSpriteShadingProfile->ambientColor.r + commonColorR + frontColorR,
268 gSpriteShadingProfile->ambientColor.g + commonColorG + frontColorG,
269 gSpriteShadingProfile->ambientColor.b + commonColorB + frontColorB,
271 otherModeLBits
272 );
273 }
274}
SpriteShadingLightSource sources[7]
#define sqrtf
@ LIGHT_SOURCE_ENABLED
Definition enums.h:2420
@ LIGHT_SOURCE_QUADRATIC_FALLOFF
Definition enums.h:2422
@ LIGHT_SOURCE_LINEAR_FALLOFF
Definition enums.h:2421
f32 fabsf(f32 f)
#define SQ(x)
Definition macros.h:166
SpriteShadingProfile * gSpriteShadingProfile
void appendGfx_shading_palette(Matrix4f mtx, s32 uls, s32 ult, s32 lrs, s32 lrt, s32 alpha, f32 shadowX, f32 shadowY, f32 shadowZ, s32 shadowR, s32 shadowG, s32 shadowB, s32 highlightR, s32 highlightG, s32 highlightB, s32 ambientPower, s32 otherModeLBits)
Matrix4f mtxPerspective
s32 gCurrentCameraID
Definition cam_math.c:4

Referenced by imgfx_appendGfx_mesh_anim(), imgfx_appendGfx_mesh_basic(), imgfx_appendGfx_mesh_grid(), and spr_appendGfx_component_flat().

◆ spr_load_sprite()

SpriteAnimData * spr_load_sprite ( s32 idx,
s32 arg1,
s32 arg2 )

Definition at line 69 of file 101b90_len_8f0.c.

69 {
70 SpriteAnimData* animData;
71 s32 base;
72 s32 i;
73 s32 compressedSize;
74 s32* ptr1;
75 IMG_PTR image;
76 s32 count;
77 s32** data;
78 s32** palettes;
79
80 if (isPlayerSprite) {
81 base = SpriteDataHeader[1];
82 } else {
83 base = SpriteDataHeader[2];
84 }
85
86 // read current and next sprite offsets, so we can find the difference
87 nuPiReadRom(base + idx * 4, &spr_asset_entry, sizeof(spr_asset_entry));
88
89 compressedSize = ALIGN8(spr_asset_entry[1] - spr_asset_entry[0]);
90 data = general_heap_malloc(compressedSize);
91 nuPiReadRom(base + spr_asset_entry[0], data, compressedSize);
92
93 ptr1 = (s32*)data;
94 // skip 4 bytes: 'YAY0' signature
95 ptr1++;
96
97 if (useTailAlloc) {
98 animData = _heap_malloc_tail(&heap_spriteHead, *ptr1);
99 } else {
100 animData = _heap_malloc(&heap_spriteHead, *ptr1);
101 }
102 ASSERT_MSG(animData, "out of sprite memory");
103 decode_yay0(data, animData);
104 general_heap_free(data);
105
106 // swizzle raster array
107 data = (s32**)animData->rastersOffset;
108 data = SPR_SWIZZLE(ALIGN4(animData), data);
109 animData->rastersOffset = (SpriteRasterCacheEntry**)data;
110
111 while (TRUE) {
112 ptr1 = *data;
113 if (ptr1 == PTR_LIST_END) {
114 break;
115 }
116 // swizzle each raster cache entry
117 ptr1 = SPR_SWIZZLE(ALIGN4(animData), ptr1);
118 *data++ = ptr1;
119 image = ((SpriteRasterCacheEntry*)ptr1)->image;
120
121 if (!isPlayerSprite) {
122 // swizzle image pointer in the cache entry
123 image = SPR_SWIZZLE(ALIGN4(animData), image);
124 *ptr1 = (s32)image;
125 }
126 }
127
128 if (isPlayerSprite) {
130 count = PlayerSpriteRasterSets[idx + 1] - PlayerSpriteRasterSets[idx];
131 // load a range of raster loading desciptors to a buffer and copy contents into PlayerRasterLoadDesc
134 for (i = 0; i < count; i++) {
136 }
137 }
138
139 // swizzle palettes array
140 palettes = SPR_SWIZZLE(ALIGN4(animData), animData->palettesOffset);
141 animData->palettesOffset = (PAL_PTR*)palettes;
142 while (TRUE) {
143 ptr1 = *palettes;
144 if (ptr1 == PTR_LIST_END) {
145 break;
146 }
147 // swizzle each palette pointer
148 ptr1 = SPR_SWIZZLE(ALIGN4(animData), ptr1);
149 *palettes++ = ptr1;
150 }
151
152 spr_swizzle_anim_offsets(0, 0, animData);
153 return animData;
154}
BSS PlayerRastersHeader PlayerRasterHeader
BSS s32 spr_asset_entry[2]
#define ALIGN4(v)
#define SPR_SWIZZLE(base, offset)
BSS s32 PlayerRasterLoadDescBuffer[101]
HeapNode heap_spriteHead
Definition heaps3.c:4
BSS s32 PlayerSpriteRasterSets[SPR_Peach3+1]
BSS s32 PlayerRasterLoadDescNumLoaded
void spr_swizzle_anim_offsets(s32 arg0, s32 base, void *spriteData)
#define IMG_PTR
#define general_heap_malloc
void * _heap_malloc_tail(HeapNode *head, u32 size)
Definition 43F0.c:153
s32 general_heap_free(void *data)
Definition heap.c:18
void decode_yay0(void *src, void *dst)
#define ALIGN8(val)
Definition macros.h:21

Referenced by spr_load_npc_sprite(), and spr_load_player_sprite().

Variable Documentation

◆ spr_defaultQuad

Quad spr_defaultQuad
extern

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
extern

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
extern

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[]
extern

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[]
extern

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};
#define PM_CC_02
Definition macros.h:277

Referenced by spr_appendGfx_component().

◆ D_802DF460

Gfx D_802DF460[]
extern

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[]
extern

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
extern

Definition at line 87 of file sprite.c.

Referenced by spr_component_update_commands(), and spr_set_anim_timescale().

◆ spr_playerSpriteSets

PlayerSpriteSet spr_playerSpriteSets[7]
extern

Definition at line 114 of file sprite.c.

114 {
122};
@ 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
#define MARIO_SPRITE_WORLD_BITS
Definition sprite.c:93
#define MARIO_SPRITE_BATTLE_BITS
Definition sprite.c:100
#define MARIO_SPRITE_COMMON_BITS
Definition sprite.c:89
#define PEACH_SPRITE_BITS
Definition sprite.c:106

Referenced by spr_init_sprites().