diff --git a/include/common_structs.h b/include/common_structs.h index 5cb77c88b5..1f1df02201 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -940,21 +940,6 @@ typedef struct StaticAnimatorNode { /* 0x2A */ char unk_2A[0x2]; } StaticAnimatorNode; // size = 0x2C -typedef struct SpriteComponent { - /* 0x00 */ s32 initialized; - /* 0x04 */ s32 unk_04; - /* 0x08 */ s16** readPos; - /* 0x0C */ f32 waitTime; - /* 0x10 */ s32 loopCounter; - /* 0x14 */ s32 currentRaster; - /* 0x18 */ s32 currentPalette; - /* 0x1C */ Vec3f posOffset; - /* 0x28 */ Vec3f compPos; - /* 0x34 */ Vec3f rotation; - /* 0x40 */ Vec3f scale; - /* 0x4C */ char unk_4C[4]; -} SpriteComponent; // size = 0x50 - typedef struct MessagePrintState { /* 0x000 */ s8* srcBuffer; /* 0x004 */ s16 printBufferPos; diff --git a/include/functions.h b/include/functions.h index 55df7af9c1..c88a489c41 100644 --- a/include/functions.h +++ b/include/functions.h @@ -455,7 +455,6 @@ void state_step_demo(void); void state_drawUI_demo(void); void func_802B2078(void); -void spr_update_player_sprite(s32, s32, f32); void initialize_curtains(void); void update_curtains(void); @@ -492,10 +491,6 @@ s32 func_8004A784(Npc* npc, f32 arg1, f32* arg2, f32* arg3, f32* arg4, f32* arg5 void base_UnkNpcAIFunc1(Evt* script, NpcAISettings* aiSettings, EnemyTerritoryThing* territory); void UnkNpcAIFunc1(Evt* script, NpcAISettings* aiSettings, EnemyTerritoryThing* territory); -s32** spr_get_npc_palettes(s32 npcSpriteID); -void spr_draw_player_sprite(s32 arg0, s32 arg1, s32 arg2, s32 arg3, Matrix4f arg4); -void spr_draw_npc_sprite(s32 arg0, s32 arg1, s32 arg2, s32 arg3, Matrix4f* arg4); -s32 spr_update_sprite(s32 arg0, s32 arg1, f32 arg2); void sin_cos_rad(f32 rad, f32* outSinTheta, f32* outCosTheta); @@ -544,7 +539,6 @@ void btl_set_state(s32 battleState); void draw_entity_model_E(s32, Mtx*); void draw_entity_model_A(s32, Mtx*); void free_entity_model_by_index(s32 idx); -s32 func_802DDFF8(s32, s32, s32, s32, s32, s32, u16); void func_8024E40C(s32); void btl_cam_set_zoffset(s16); void btl_cam_target_actor(s32); diff --git a/src/182B30.c b/src/182B30.c index f1d71c1d79..deccee935d 100644 --- a/src/182B30.c +++ b/src/182B30.c @@ -1,4 +1,5 @@ #include "common.h" +#include "sprite.h" s32 func_80254250(void) { s32 ret; diff --git a/src/battle/battle.c b/src/battle/battle.c index cc0fa742f3..eada42fc4a 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -2,6 +2,7 @@ #include "ld_addrs.h" #include "battle.h" #include "hud_element.h" +#include "sprite.h" extern s32 D_800DC060; extern Stage* D_800DC064; diff --git a/src/entity/BlueWarpPipe.c b/src/entity/BlueWarpPipe.c index 21abc5e274..c7737cd6a9 100644 --- a/src/entity/BlueWarpPipe.c +++ b/src/entity/BlueWarpPipe.c @@ -1,5 +1,6 @@ #include "common.h" #include "map.h" +#include "sprite.h" typedef struct struct802E89B0 { /* 0x00 */ s32 unk_00; diff --git a/src/entity/jan_iwa/E2D730.c b/src/entity/jan_iwa/E2D730.c index 07ee47ed0b..ab5cc4e7b2 100644 --- a/src/entity/jan_iwa/E2D730.c +++ b/src/entity/jan_iwa/E2D730.c @@ -1,4 +1,5 @@ #include "common.h" +#include "sprite.h" extern StaticEntityData D_802BC7D0_E2F100; extern f32 D_802BCE20; @@ -72,7 +73,7 @@ void func_802BB298_E2DBC8(Entity* entity) { y = entity->position.y + 100.0f; z = entity->position.z; } - + data->unk_28 = x; data->unk_2A = y; data->unk_2C = z; diff --git a/src/evt/player_api.c b/src/evt/player_api.c index 7b1873b9d0..8fc877b1f9 100644 --- a/src/evt/player_api.c +++ b/src/evt/player_api.c @@ -1,4 +1,5 @@ #include "common.h" +#include "sprite.h" Npc* playerNpc = (Npc*) 0x802DB270; // XXX: raw ptr @@ -623,7 +624,7 @@ ApiStatus func_802D2520(Evt* script, s32 isInitialCall) { PlayerStatus* playerStatus = &gPlayerStatus; s32 a0 = *args++; s32 val = evt_get_variable(script, *args++); - s32 a2, a3, a4, a5; + s32 a2, a3, a4, a5; func_802DDFF8(a0, 0, 0, 0, 0, 0, 0); diff --git a/src/main_loop.c b/src/main_loop.c index f402c4d66b..d0d7119557 100644 --- a/src/main_loop.c +++ b/src/main_loop.c @@ -2,6 +2,7 @@ #include "nu/nusys.h" #include "ld_addrs.h" #include "hud_element.h" +#include "sprite.h" s8 D_80074020 = 1; s8 D_80074021 = 5; @@ -172,7 +173,7 @@ void gfx_draw_frame(void) { gSPMatrix(gMasterGfxPos++, D_800741A8, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - spr_render_init(gDisplayContext, &gMasterGfxPos); + spr_render_init(); if (!(gOverrideFlags & 2)) { render_frame(0); diff --git a/src/npc.c b/src/npc.c index a6c52cdeaa..642329415b 100644 --- a/src/npc.c +++ b/src/npc.c @@ -2,6 +2,7 @@ #include "map.h" #include "npc.h" #include "effects.h" +#include "sprite.h" extern s16 D_8010C97A; extern s32 D_8010C978; diff --git a/src/sprite.c b/src/sprite.c index 5b32f68d20..2c26497a52 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,38 +1,4 @@ -#include "common.h" - -struct spr_playerCurrentAnimInfo { - /* 0x00 */ SpriteComponent** componentList; - /* 0x04 */ s32 animID; - /* 0x08 */ s32 unk_08; -}; // size = 0xC - -struct D_802DFA48 { - s32 unk_00; - s32 unk_04; - s32 unk_08; - s32 unk_0C; - s32 unk_10; -}; // size = 0x14 - -typedef struct PlayerSpriteSet { - /// Number of cache entries. - /* 0x00 */ s32 cacheSize; - - /// Maximum raster size. - /* 0x04 */ s32 rasterSize; - - /// 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). - /* 0x08 */ s32 initiallyLoaded; -} PlayerSpriteSet; // size = 0xC - -/// Sprite data header. -typedef struct SpriteAnimData { - /* 0x00 */ s32** rastersOffset; - /* 0x04 */ s32** palettesOffset; - /* 0x08 */ s32 maxComponents; - /* 0x0C */ s32 colorVariations; -} SpriteAnimData; // size = 0x10 +#include "sprite.h" extern s32 D_802DF590[]; extern s32 D_802DFA58[]; diff --git a/src/sprite.h b/src/sprite.h new file mode 100644 index 0000000000..a1d3f752e8 --- /dev/null +++ b/src/sprite.h @@ -0,0 +1,195 @@ +#ifndef _SPRITE_H_ +#define _SPRITE_H_ + +#include "common.h" + +typedef struct SpriteComponent { + /* 0x00 */ s32 initialized; + /* 0x04 */ s32 unk_04; + /* 0x08 */ s16** readPos; + /* 0x0C */ f32 waitTime; + /* 0x10 */ s32 loopCounter; + /* 0x14 */ s32 currentRaster; + /* 0x18 */ s32 currentPalette; + /* 0x1C */ Vec3f posOffset; + /* 0x28 */ Vec3f compPos; + /* 0x34 */ Vec3f rotation; + /* 0x40 */ Vec3f scale; + /* 0x4C */ char unk_4C[4]; +} SpriteComponent; // size = 0x50 + +struct spr_playerCurrentAnimInfo { + /* 0x00 */ SpriteComponent** componentList; + /* 0x04 */ s32 animID; + /* 0x08 */ s32 unk_08; +}; // size = 0xC + +typedef struct SpriteComponentAnim { + /* 0x00 */ s16** cmdList; + /* 0x04 */ s16 cmdListSize; + /* 0x08 */ Vec3s compOffset; +} SpriteComponentAnim; // size = 0xC + +// TODO: consider moving to 101b90_len_8f0 (sprite_cache) +typedef struct SpriteRasterCacheEntry { + /* 0x00 */ void* image; + /* 0x04 */ u8 width; + /* 0x05 */ u8 height; + /* 0x06 */ u8 palette; + /* 0x07 */ u8 quadCacheIndex; +} SpriteRasterCacheEntry; // size = 0x8 + +struct D_802DFA48 { + s32 unk_00; + s32 unk_04; + s32 unk_08; + s32 unk_0C; + s32 unk_10; +}; // size = 0x14 + +typedef struct PlayerSpriteSet { + /// Number of cache entries. + /* 0x00 */ s32 cacheSize; + + /// Maximum raster size. + /* 0x04 */ s32 rasterSize; + + /// 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). + /* 0x08 */ s32 initiallyLoaded; +} PlayerSpriteSet; // size = 0xC + +/// Sprite data header. +typedef struct SpriteAnimData { + /* 0x00 */ s32** rastersOffset; + /* 0x04 */ s32** palettesOffset; + /* 0x08 */ s32 maxComponents; + /* 0x0C */ s32 colorVariations; +} SpriteAnimData; // size = 0x10 + +typedef struct SpriteRasterInfo { + /* 0x00 */ void* raster; + /* 0x04 */ void* defaultPal; + /* 0x08 */ s32 width; + /* 0x0C */ s32 height; +} SpriteRasterInfo; // size = 0x10 + +extern Vtx spr_defaultQuad[4]; +extern Vp D_802DF3D0; +extern Vp D_802DF3E0; +extern Gfx D_802DF3F0[]; +extern Gfx D_802DF428[]; +extern Gfx D_802DF460[]; +extern Gfx D_802DF490[]; +extern f32 spr_animUpdateTimeScale; +extern PlayerSpriteSet spr_playerSpriteSets[7]; + +void spr_init_quad_cache(void); + +Vtx* spr_get_cached_quad(s32* quadIndex); + +void spr_make_quad_for_size(Vtx* quad, s32 width, s32 height); + +Vtx* spr_get_quad_for_size(s32* quadIndex, s32 width, s32 height); + +void spr_clear_quad_cache(void); + +void spr_appendGfx_component_flat( + Vtx* vertices, + void* raster, void* palette, + s32 width, s32 height, + s32 arg5, + Matrix4f mtx, + s32 alpha +); + +void spr_appendGfx_component( + Vtx* vertices, + void* raster, void* palette, + s32 width, s32 height, + s32 arg5, + Matrix4f mtx, + s32 alpha +); + +void spr_transform_point(s32 rotX, s32 rotY, s32 rotZ, f32 inX, f32 inY, f32 inZ, f32* outX, f32* outY, f32* outZ); + +void spr_draw_component( + SpriteRasterCacheEntry* raster, + f32 dx, f32 dy, f32 dz, + f32 rotX, f32 rotY, f32 rotZ, + f32 scaleX, f32 scaleY, f32 scaleZ, + s32 opacity, + void* palette, + Matrix4f mtx +); + +s32 spr_sign_extend_12bit(u16 val); + +s32 spr_sign_extend_16bit(u16 val); + +void spr_component_update_commands(SpriteComponent* comp, SpriteComponentAnim* anim); + +void spr_component_update_finish( + SpriteComponent* comp, + SpriteComponent** compList, + SpriteRasterCacheEntry* rasterCacheEntry, + s32 overridePalette +); + +// TODO: anim possibly should be SpriteComponentAnim* +void spr_init_component_anim_state(SpriteComponent* comp, s16*** anim); + +void spr_init_anim_state(SpriteComponent** compList, s16** cmdList); + +void spr_set_anim_timescale(f32 timeScale); + +void spr_load_player_sprite(s32 spriteIndex); + +void spr_init_sprites(s32 playerSpriteSet); + +void spr_render_init(void); + +s32 func_802DDA84(void); + +void spr_update_player_sprite(s32 arg0, s32 arg1, f32 arg2); + +s32 spr_draw_player_sprite(s32 arg0, s32 yaw, s32 arg2, s16** paletteList, Matrix4f mtx); + +s32 func_802DDEC4(s32 arg0); + +s32 func_802DDEE4(s32, s32, s32, s32, s32, s32, s32, s32); + +// TODO: problem with arg6, see the NON_MATCHING in sprite.c +s32 func_802DDFF8(s32, s32, s32, s32, s32, s32, u16); + +void spr_get_player_raster_info(SpriteRasterInfo* out, s32 playerSpriteID, s32 rasterIndex); + +s16** spr_get_player_palettes(s32 spriteIndex); + +/// @param animID - Set MSB for tail allocation (i.e. `0x80XXYYZZ`) +s32 spr_load_npc_sprite(s32 animID, s32** extraAnimList); + +void spr_update_sprite(s32 spriteInstanceID, s32 animID, f32 timeScale); + +s32 spr_draw_npc_sprite(s32 spriteInstanceID, s32 yaw, s32 arg2, s16** paletteList, Matrix4f mtx); + +s32 func_802DE5C8(s32 arg0); + +s32 spr_free_sprite(s32 spriteInstanceID); + +//s32 func_802DE748(); // TODO + +//s32 func_802DE780(); // TODO + +s32 func_802DE894(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6); + +//s32 func_802DE8DC(); // TODO + +s32 spr_get_npc_raster_info(SpriteRasterInfo* out, int npcSpriteID, int rasterIndex); + +s32** spr_get_npc_palettes(s32 npcSpriteID); + +s32 spr_get_npc_color_variations(s32 npcSpriteID); + +#endif diff --git a/src/state_battle.c b/src/state_battle.c index e4c5af6dc3..b92f37333e 100644 --- a/src/state_battle.c +++ b/src/state_battle.c @@ -2,6 +2,7 @@ #include "nu/nusys.h" #include "hud_element.h" #include "ld_addrs.h" +#include "sprite.h" s32 D_800778A0[] = { &D_8038F800, &D_803B5000, &D_803DA800, diff --git a/src/state_demo.c b/src/state_demo.c index 64c8248632..46a5ddc419 100644 --- a/src/state_demo.c +++ b/src/state_demo.c @@ -1,5 +1,6 @@ #include "common.h" #include "hud_element.h" +#include "sprite.h" typedef struct DemoSceneData { /* 0x0 */ s16 unk_0; diff --git a/src/state_file_select.c b/src/state_file_select.c index dbfcb4d8f1..6f975caa1a 100644 --- a/src/state_file_select.c +++ b/src/state_file_select.c @@ -3,6 +3,7 @@ #include "nu/nusys.h" #include "camera.h" #include "hud_element.h" +#include "sprite.h" s32 D_80077980[] = { &D_8038F800, &D_803B5000, &D_803DA800, }; diff --git a/src/state_intro.c b/src/state_intro.c index a7676fa43f..b68d84abbf 100644 --- a/src/state_intro.c +++ b/src/state_intro.c @@ -1,5 +1,6 @@ #include "common.h" #include "hud_element.h" +#include "sprite.h" extern s32 D_800A0950; diff --git a/src/state_logos.c b/src/state_logos.c index facbad90cf..f1ec1f291c 100644 --- a/src/state_logos.c +++ b/src/state_logos.c @@ -2,6 +2,7 @@ #include "ld_addrs.h" #include "camera.h" #include "hud_element.h" +#include "sprite.h" void appendGfx_intro_logos(); diff --git a/src/state_pause.c b/src/state_pause.c index 6097beb1ed..5fa51deb43 100644 --- a/src/state_pause.c +++ b/src/state_pause.c @@ -3,6 +3,7 @@ #include "map.h" #include "nu/nusys.h" #include "hud_element.h" +#include "sprite.h" s32 D_80077950[] = { 0x8038F800, 0x803B5000, &D_803DA800 }; diff --git a/src/state_startup.c b/src/state_startup.c index 0ff1810aff..5cfdbfffce 100644 --- a/src/state_startup.c +++ b/src/state_startup.c @@ -1,5 +1,6 @@ #include "common.h" #include "hud_element.h" +#include "sprite.h" void state_init_startup(void) { gOverrideFlags |= 0x8; diff --git a/src/world/area_tst/tst_04/B1B570.c b/src/world/area_tst/tst_04/B1B570.c index 632cb53146..dd61066a0f 100644 --- a/src/world/area_tst/tst_04/B1B570.c +++ b/src/world/area_tst/tst_04/B1B570.c @@ -1,4 +1,5 @@ #include "tst_04.h" +#include "sprite.h" static char* N(exit_str_0) = "tst_03"; static char* N(exit_str_1) = ""; diff --git a/src/world/area_tst/tst_11/B1CA50.c b/src/world/area_tst/tst_11/B1CA50.c index 583d2fc2e6..73c6354e9c 100644 --- a/src/world/area_tst/tst_11/B1CA50.c +++ b/src/world/area_tst/tst_11/B1CA50.c @@ -1,4 +1,5 @@ #include "tst_11.h" +#include "sprite.h" void func_8024003C_B1CA8C(void); void func_80240100_B1CB50(PlayerStatus*); diff --git a/src/world/common/reflection.inc.c b/src/world/common/reflection.inc.c index 83b0c574a2..ceddbec569 100644 --- a/src/world/common/reflection.inc.c +++ b/src/world/common/reflection.inc.c @@ -5,6 +5,7 @@ #include "common.h" #include "map.h" +#include "sprite.h" enum Reflection { REFLECTION_FLOOR_WALL, @@ -189,9 +190,11 @@ void N(reflection_setup_floor)(void) { renderTaskPtr->renderMode = renderMode; renderTaskPtr->appendGfxArg = playerStatus; renderTaskPtr->distance = -screenZ; - renderTaskPtr->appendGfx = (!(playerStatus->flags & 0x20000) ? - N(reflection_render_floor) : - N(reflection_render_floor_fancy)); + renderTaskPtr->appendGfx = (void (*)(void*)) ( + !(playerStatus->flags & 0x20000) + ? N(reflection_render_floor) + : N(reflection_render_floor_fancy) + ); queue_render_task(renderTaskPtr); } } @@ -226,7 +229,7 @@ void N(reflection_render_floor)(PlayerStatus* playerStatus) { } void N(reflection_render_floor_fancy)(PlayerStatus* playerStatus) { - Matrix4f main; + Matrix4f mtx; Matrix4f translation; Matrix4f rotation; Matrix4f scale; @@ -267,8 +270,8 @@ void N(reflection_render_floor_fancy)(PlayerStatus* playerStatus) { func_802DDEE4(1, -1, 6, tint, tint, tint, 255, 0); guRotateF(rotation, yaw, 0.0f, -1.0f, 0.0f); - guRotateF(main, clamp_angle(playerStatus->unk_8C), 0.0f, 0.0f, 1.0f); - guMtxCatF(rotation, main, main); + guRotateF(mtx, clamp_angle(playerStatus->unk_8C), 0.0f, 0.0f, 1.0f); + guMtxCatF(rotation, mtx, mtx); px = playerStatus->position.x; py = playerStatus->position.y; pz = playerStatus->position.z; @@ -286,24 +289,24 @@ void N(reflection_render_floor_fancy)(PlayerStatus* playerStatus) { px = playerStatus->position.x; pz = playerStatus->position.z; func_802DDEE4(1, -1, 7, 0, 0, 0, 0x40, 0); - guRotateF(main, yaw, 0.0f, -1.0f, 0.0f); + guRotateF(mtx, yaw, 0.0f, -1.0f, 0.0f); guRotateF(rotation, yaw, 0.0f, -1.0f, 0.0f); - guRotateF(main, blurAngle, 0.0f, 1.0f, 0.0f); - guMtxCatF(rotation, main, main); + guRotateF(mtx, blurAngle, 0.0f, 1.0f, 0.0f); + guMtxCatF(rotation, mtx, mtx); } guTranslateF(translation, 0.0f, -playerStatus->colliderHeight * 0.5f, 0.0f); - guMtxCatF(translation, main, main); + guMtxCatF(translation, mtx, mtx); guRotateF(rotation, yaw, 0.0f, 1.0f, 0.0f); - guMtxCatF(main, rotation, main); + guMtxCatF(mtx, rotation, mtx); guRotateF(rotation, playerStatus->spriteFacingAngle, 0.0f, 1.0f, 0.0f); - guMtxCatF(main, rotation, main); + guMtxCatF(mtx, rotation, mtx); guTranslateF(translation, 0.0f, playerStatus->colliderHeight * 0.5f, 0.0f); - guMtxCatF(main, translation, main); + guMtxCatF(mtx, translation, mtx); guScaleF(scale, SPRITE_WORLD_SCALE, -SPRITE_WORLD_SCALE, SPRITE_WORLD_SCALE); - guMtxCatF(main, scale, main); + guMtxCatF(mtx, scale, mtx); guTranslateF(translation, px, -py, pz); - guMtxCatF(main, translation, main); + guMtxCatF(mtx, translation, mtx); if (playerStatus->spriteFacingAngle >= 90.0f && playerStatus->spriteFacingAngle < 270.0f) { flags = 0x10000001; @@ -311,7 +314,7 @@ void N(reflection_render_floor_fancy)(PlayerStatus* playerStatus) { flags = 1; } - spr_draw_player_sprite(flags, 0, 0, 0, &main); + spr_draw_player_sprite(flags, 0, 0, NULL, mtx); } } diff --git a/src/world/world.c b/src/world/world.c index 6d59656a79..09b325348f 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -3,6 +3,7 @@ #include "map.h" #include "camera.h" #include "hud_element.h" +#include "sprite.h" #define ASSET_TABLE_ROM_START 0x1E40000 #define ASSET_TABLE_HEADER_SIZE 0x20