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 242 of file imgfx.c.

242 {
243 s32 i;
244
245 for (i = 0; i < ARRAY_COUNT(ImgFXVtxBuffers); i++) {
247 }
248
250
251 for (i = 0; i < ARRAY_COUNT(*ImgFXInstances); i++) {
254 }
255
256 for (i = 0; i < ARRAY_COUNT(ImgFXDataCache); i++) {
257 ImgFXDataCache[i].data = NULL;
260 }
261
262 imgfx_vtxCount = 0;
264}
void * _heap_malloc(HeapNode *head, u32 size)
Definition 43F0.c:78
ImgFXState ImgFXInstanceList[MAX_IMGFX_INSTANCES]
Definition imgfx.c:111
void imgfx_clear_instance_data(ImgFXState *state)
Definition imgfx.c:442
u16 imgfx_vtxCount
Definition imgfx.c:125
BSS Vtx * ImgFXVtxBuffers[2]
Definition imgfx.c:116
u8 usingContextualHeap
Definition imgfx.c:97
BSS ImgFXInstanceList * ImgFXInstances
Definition imgfx.c:118
BSS Vtx * imgfx_vtxBuf
Definition imgfx.c:117
s32 * data
Definition imgfx.c:95
u16 ImgFXVtxBufferCapacity
Definition imgfx.c:143
HeapNode heap_spriteHead
Definition heaps3.c:4
void imgfx_init_instance(ImgFXState *state)
Definition imgfx.c:452
BSS ImgFXCacheEntry ImgFXDataCache[8]
Definition imgfx.c:120
u8 staleCooldownTimer
Definition imgfx.c:96
#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:6349
HeapNode * _heap_create(HeapNode *addr, u32 size)
Definition 43F0.c:63
void imgfx_init(void)
Definition imgfx.c:242
#define SPRITE_HEAP_SIZE
Definition macros.h:117
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:266

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:337
#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 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) {
941 alpha = alphaIn & 0xFF;
942 if (alphaIn == 0) {
943 return FALSE;
944 }
945 } else {
946 alpha = 255;
947 }
948
949 components = spr_playerCurrentAnimInfo[instanceIdx].componentList;
950 if (spriteInstanceID & DRAW_SPRITE_OVERRIDE_PALETTES) {
951 palettes = paletteList;
952 }
953
954 while (*components != PTR_LIST_END) {
955 spr_draw_component(alpha | DRAW_SPRITE_USE_PLAYER_RASTERS, *components++, *animComponents, rasters, palettes, zscale, mtx);
956 if (*animComponents != PTR_LIST_END) {
957 animComponents++;
958 }
959 }
960
961 return TRUE;
962}
#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 964 of file sprite.c.

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

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 968 of file sprite.c.

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

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 994 of file sprite.c.

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

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 998 of file sprite.c.

998 {
999 SpriteAnimData* sprite;
1001 u16** paletteOffsetCopy;
1002
1003 playerSpriteID--;
1004 sprite = spr_playerSprites[playerSpriteID];
1005 if (sprite != NULL) {
1006 paletteOffsetCopy = sprite->palettesOffset;
1007 cache = sprite->rastersOffset[rasterIndex];
1008 out->width = cache->width;
1009 out->height = cache->height;
1010 out->defaultPal = paletteOffsetCopy[cache->palette];
1011 out->raster = spr_get_player_raster(rasterIndex, playerSpriteID);
1012 }
1013}
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 1025 of file sprite.c.

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

1071 {
1072 u32* spriteData;
1073 SpriteComponent** compList;
1074 SpriteAnimComponent** animList;
1075 SpriteRasterCacheEntry** rasterList;
1076
1077 s32 palID;
1078 s32 i = spriteInstanceID & 0xFF;
1079 s32 animIndex = animID & 0xFF;
1080
1081 ASSERT_MSG(i <= MaxLoadedSpriteInstanceID, "Invalid sprite instance ID %x", spriteInstanceID);
1082
1083 compList = SpriteInstances[i].componentList;
1084 spriteData = (u32*)SpriteInstances[i].spriteData;
1085
1086 rasterList = (SpriteRasterCacheEntry**)*spriteData;
1087 spriteData += 4 + animIndex;
1088 animList = (SpriteAnimComponent**)*spriteData;
1089
1090 palID = (animID >> 8) & 0xFF;
1091 spr_set_anim_timescale(timeScale);
1092 if ((spriteInstanceID & DRAW_SPRITE_OVERRIDE_ALPHA) || ((SpriteInstances[i].curAnimID & 0xFF) != animIndex)) {
1093 ASSERT_MSG(animList != -1, "Anim %lx is not loaded", animID);
1094 spr_init_anim_state(compList, animList);
1095 SpriteInstances[i].curAnimID = (palID << 8) | animIndex;
1097 }
1098 if (!(spriteInstanceID & DRAW_SPRITE_OVERRIDE_YAW)) {
1100 compList, animList, rasterList, palID);
1101 }
1102 return SpriteInstances[i].notifyValue;
1103}
#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 1105 of file sprite.c.

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

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 1173 of file sprite.c.

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

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 1177 of file sprite.c.

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

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

◆ 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 1227 of file sprite.c.

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

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 1253 of file sprite.c.

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

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 1257 of file sprite.c.

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

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

Referenced by appendGfx_message().

◆ spr_get_npc_palettes()

◆ spr_get_npc_color_variations()

s32 spr_get_npc_color_variations ( s32 npcSpriteID)

Definition at line 1326 of file sprite.c.

1326 {
1327 SpriteAnimData* sprite = NpcSpriteData[npcSpriteID];
1328
1329 if (sprite != NULL) {
1330 return sprite->colorVariations;
1331 } else {
1332 return -1;
1333 }
1334}
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:170
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:152
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:281

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:6345
@ PLAYER_SPRITES_COMBINED_EPILOGUE
Definition enums.h:6347
@ PLAYER_SPRITES_MARIO_REFLECT_FLOOR
Definition enums.h:6346
@ PLAYER_SPRITES_PEACH_BATTLE
Definition enums.h:6351
@ PLAYER_SPRITES_MARIO_PARADE
Definition enums.h:6348
@ PLAYER_SPRITES_MARIO_BATTLE
Definition enums.h:6350
#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().