From e208087de042b6e9a68b106c4cb04533ccae3e4d Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Thu, 22 Jun 2023 13:19:42 -0400 Subject: [PATCH] Implement & link ac_sample.c --- config/rel_slices.yml | 5 + include/ac_sample.h | 34 +++++++ include/c_keyframe.h | 2 +- include/m_actor.h | 2 + include/m_collision_obj.h | 84 ++++++++++++++++ include/m_demo.h | 24 +++++ include/m_msg.h | 15 ++- include/m_name_table.h | 3 + include/m_play.h | 9 +- include/m_rcp.h | 1 + include/m_scene.h | 14 +++ include/sys_math3d.h | 7 ++ rel/ac_sample.c | 195 ++++++++++++++++++++++++++++++++++++++ rel/c_keyframe.c | 2 +- 14 files changed, 383 insertions(+), 14 deletions(-) create mode 100644 include/ac_sample.h create mode 100644 include/m_collision_obj.h create mode 100644 include/m_demo.h create mode 100644 rel/ac_sample.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 94d80748..b6ed1821 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -138,6 +138,11 @@ zurumode.c: sys_ucode.c: .text: [0x8040F008, 0x8040F048] .data: [0x8065FA30, 0x8065FA40] +ac_sample.c: + .text: [0x8040F048, 0x8040F614] + .rodata: [0x80643860, 0x80643868] + .data: [0x8065FA40, 0x8065FAA0] + .bss: [0x812F96A0, 0x812F96E0] ac_animal_logo.c: .text: [0x804104AC, 0x804117D4] .rodata: [0x80643918, 0x80643A88] diff --git a/include/ac_sample.h b/include/ac_sample.h new file mode 100644 index 00000000..a0ea4d14 --- /dev/null +++ b/include/ac_sample.h @@ -0,0 +1,34 @@ +#ifndef AC_SAMPLE_H +#define AC_SAMPLE_H + +#include "types.h" +#include "m_actor.h" +#include "m_collision_obj.h" +#include "c_keyframe.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct sample_actor_s { + ACTOR actor_class; + + cKF_SkeletonInfo_R_c keyframe; + s_xyz work_area[8]; + s_xyz morph_area[8]; + + ClObjPipe_c stand; + + int main_action; + int draw_action; + + char* obj_bank_ram_start; // maybe unused in AC? was used to exchange data on N64 +} SAMPLE_ACTOR; + +extern ACTOR_PROFILE Sample_Profile; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/c_keyframe.h b/include/c_keyframe.h index 7f1a7da0..13f7f8f5 100644 --- a/include/c_keyframe.h +++ b/include/c_keyframe.h @@ -93,7 +93,7 @@ extern f32 cKF_HermitCalc(f32 t, f32 tension, f32 p0, f32 p1, f32 m0, f32 m1); extern void cKF_SkeletonInfo_subRotInterpolation(f32 t, s16* out, s16 rot1, s16 rot2); extern void cKF_SkeletonInfo_R_ct(cKF_SkeletonInfo_R_c* keyframe, cKF_Skeleton_R_c* skeleton, cKF_Animation_R_c* animation, s_xyz* work_table, s_xyz* target_table); -extern void cKF_SkeletonInfo_R_dt(); +extern void cKF_SkeletonInfo_R_dt(cKF_SkeletonInfo_R_c* keyframe); extern void cKF_SkeletonInfo_R_init_standard_stop(cKF_SkeletonInfo_R_c* keyframe, cKF_Animation_R_c* animation, s_xyz* rotation_diff_table); extern void cKF_SkeletonInfo_R_init_standard_stop_morph(cKF_SkeletonInfo_R_c* keyframe, cKF_Animation_R_c* animation, s_xyz* rotation_diff_table, f32 morph); diff --git a/include/m_actor.h b/include/m_actor.h index 50655b5e..b44f11fc 100644 --- a/include/m_actor.h +++ b/include/m_actor.h @@ -18,6 +18,7 @@ typedef void (*mActor_proc)(ACTOR*, GAME*); #define ACTOR_OBJ_BANK_NONE 0 #define ACTOR_OBJ_BANK_3 3 /* TODO: rename, also likely an enum */ +#define ACTOR_OBJ_BANK_12 12 enum actor_part { ACTOR_PART_FG, @@ -139,6 +140,7 @@ typedef struct actor_info_s { extern void Actor_delete(ACTOR* actor); extern ACTOR* Actor_info_fgName_search(Actor_info* actor_info, mActor_name_t fg_name, int part); +extern void Actor_world_to_eye(ACTOR* actor, f32 eye_height); #ifdef __cplusplus } diff --git a/include/m_collision_obj.h b/include/m_collision_obj.h new file mode 100644 index 00000000..4d40a603 --- /dev/null +++ b/include/m_collision_obj.h @@ -0,0 +1,84 @@ +#ifndef M_COLLISION_OBJ_H +#define M_COLLISION_OBJ_H + +#include "types.h" +#include "m_actor.h" +#include "sys_math3d.h" +#include "m_play_h.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum collision_type { + ClObj_TYPE_JNT_SPH, + ClObj_TYPE_PIPE, + ClObj_TYPE_TRIS, + + ClObj_TYPE_NUM +}; + +typedef struct collision_obj_s { + ACTOR* owner_actor; // actor which owns this collision object + ACTOR* collided_actor; // actor which the owner collided with or NULL + + u8 collision_flags0; + u8 collision_flags1; + + u8 collision_type; +} ClObj_c; + +typedef struct collision_elem_s { + u8 flags; +} ClObjElem_c; + +typedef struct collision_pipe_attribute_s { + Math3D_pipe_c pipe; +} ClObjPipeAttr_c; + +typedef struct collision_pipe_s { + ClObj_c collision_obj; + ClObjElem_c element; + ClObjPipeAttr_c attribute; +} ClObjPipe_c; + +/* static data */ + +typedef struct collision_obj_data_s { + u8 collision_flags0; + u8 collision_flags1; + u8 type; +} ClObjData_c; + +typedef struct collision_obj_elem_data_s { + u8 flags; +} ClObjElemData_c; + +typedef struct collision_obj_pipe_attr_data_s { + Math3D_pipe_c pipe; +} ClObjPipeAttrData_c; + +typedef struct collision_obj_pipe_data_s { + ClObjData_c collision_data; + ClObjElemData_c element_data; + ClObjPipeAttrData_c attribute_data; +} ClObjPipeData_c; + +#define Cl_COLLIDER_NUM 50 +typedef struct collision_check_s { + u16 flags; + int collider_num; + ClObj_c* collider_table[Cl_COLLIDER_NUM]; +} CollisionCheck_c; + +extern void ClObjPipe_ct(GAME_PLAY* play, ClObjPipe_c* pipe); +extern void ClObjPipe_dt(GAME_PLAY* play, ClObjPipe_c* pipe); +extern void ClObjPipe_set5(GAME_PLAY* play, ClObjPipe_c* pipe, ACTOR* owner, ClObjPipeData_c* data); +extern void CollisionCheck_Uty_ActorWorldPosSetPipeC(ACTOR* actor, ClObjPipe_c* col_pipe); +extern int CollisionCheck_setOC(GAME_PLAY* play, CollisionCheck_c* collision_check, ClObj_c* col_obj); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/m_demo.h b/include/m_demo.h new file mode 100644 index 00000000..37bb07e5 --- /dev/null +++ b/include/m_demo.h @@ -0,0 +1,24 @@ +#ifndef M_DEMO_H +#define M_DEMO_H + +#include "types.h" +#include "m_actor_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*mDemo_REQUEST_PROC)(ACTOR*); + +extern int mDemo_Request(int type, ACTOR* actor, mDemo_REQUEST_PROC request_proc); +extern void mDemo_Set_msg_num(int msg_num); +extern int mDemo_Check(int type, ACTOR* actor); +extern int mDemo_Check_DiffAngle_forTalk(s16 angle); +extern int mDemo_Check_ListenAble(); +extern void mDemo_Set_ListenAble(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/m_msg.h b/include/m_msg.h index 25926a3e..ec107a61 100644 --- a/include/m_msg.h +++ b/include/m_msg.h @@ -9,19 +9,16 @@ extern "C" { #endif /* TODO: fill out message struct */ -typedef struct message_window_s M_MSG_WINDOW; +typedef struct message_window_s mMsg_Window_c; extern int mMsg_Get_Length_String(u8* buf, size_t buf_size); - -extern M_MSG_WINDOW* mMsg_Get_base_window_p(); - -extern void mMsg_Set_free_str(M_MSG_WINDOW* msg, int free_str_no, u8* str, size_t str_size); - +extern mMsg_Window_c* mMsg_Get_base_window_p(); +extern void mMsg_Set_free_str(mMsg_Window_c* msg, int free_str_no, u8* str, int str_size); extern void mMsg_debug_draw(gfxprint_t* gfxprint); - extern void mMsg_aram_init(); - -extern int mMsg_Check_MainHide(M_MSG_WINDOW* msg); +extern int mMsg_Check_MainHide(mMsg_Window_c* msg); +extern void mMsg_Set_item_str(mMsg_Window_c* msg_win, int str_no, u8* item_str, int str_len); +extern void mMsg_Set_mail_str(mMsg_Window_c* msg_win, int str_no, u8* str, int str_len); #ifdef __cplusplus } diff --git a/include/m_name_table.h b/include/m_name_table.h index 8ba766c9..f68574e3 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -472,6 +472,9 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define TRAIN0 0x580A #define TRAIN1 0x580B +#define MISC_ACTOR_START 0x9000 +#define MISC_ACTOR_SAMPLE MISC_ACTOR_START + #define SP_NPC_START 0xD000 #define SP_NPC_ARTIST (SP_NPC_START + 0) // D000 #define SP_NPC_BROKER (SP_NPC_START + 1) // D001 diff --git a/include/m_play.h b/include/m_play.h index 343882c1..1807ad2c 100644 --- a/include/m_play.h +++ b/include/m_play.h @@ -10,7 +10,9 @@ #include "m_pause.h" #include "m_field_info.h" #include "m_fbdemo_wipe.h" +#include "m_collision_obj.h" #include "m_play_h.h" +#include "m_scene.h" #ifdef __cplusplus extern "C" { @@ -23,7 +25,8 @@ struct game_play_s { /* 0x00E0 */ int _00E0; /* 0x00E4 */ mFI_block_tbl_c block_table; /* 0x00F4 */ mFI_block_tbl_c last_block_table; - /* 0x0104 */ u8 _0104[0x1A68 - 0x0104]; + /* 0x0104 */ u8 _0104[0x0110 - 0x0104]; + /* 0x0110 */ Object_Exchange_c object_exchange; /* 0x1A68 */ View view; /* 0x1B88 */ Camera2 camera; /* 0x1CC0 */ u8 _1CC0[0x1DA0 - 0x1CC0]; @@ -38,10 +41,10 @@ struct game_play_s { /* 0x20D1 */ u8 fb_wipe_type; /* 0x20D2 */ u8 fb_mode; /* 0x20D3 */ u8 fb_wipe_mode; - /* 0x20D4 */ //int _20D4; /* 0x20D8 */ fbdemo_wipe fbdemo_wipe; /* 0x2318 */ fbdemo_fade color_fade; - /* 0x2328 */ u8 _2328[0x2600 - 0x2328]; + /* 0x2328 */ CollisionCheck_c collision_check; + /* 0x23F8 */ u8 _23F8[0x2600 - 0x23F8]; }; diff --git a/include/m_rcp.h b/include/m_rcp.h index bca60e14..2185ec37 100644 --- a/include/m_rcp.h +++ b/include/m_rcp.h @@ -16,6 +16,7 @@ extern Gfx* gfx_tex_scroll2(Gfx** gfxpp, u32 x, u32 y, int width, int height); extern void DisplayList_initialize(GRAPH* graph, u32 clear_r, u32 clear_g, u32 clear_b, GAME* game); extern void fade_black_draw(Gfx** gfxpp, u32 alpha); extern void rect_moji(GRAPH* graph); +extern void _texture_z_light_fog_prim(GRAPH* graph); #ifdef __cplusplus } diff --git a/include/m_scene.h b/include/m_scene.h index 721ba752..89542997 100644 --- a/include/m_scene.h +++ b/include/m_scene.h @@ -20,6 +20,20 @@ typedef struct door_data_s { u8 pad[3]; // possibly necessary due to struct copy } Door_data_c; +#define mSc_OBJECT_BANK_NUM 70 + +typedef struct object_bank_s { + s16 bank_id; + char* ram_start; + // TODO: others + u8 _08[0x5C - 8]; +} Object_Bank_c; + +typedef struct object_exchange_s { + Object_Bank_c banks[mSc_OBJECT_BANK_NUM]; + u8 _1928[0x1958-0x1928]; +} Object_Exchange_c; + #ifdef __cplusplus } #endif diff --git a/include/sys_math3d.h b/include/sys_math3d.h index cee44a56..a81ed50b 100644 --- a/include/sys_math3d.h +++ b/include/sys_math3d.h @@ -8,6 +8,13 @@ extern "C" { #endif +typedef struct math_3d_pipe_s { + s16 radius; + s16 height; + s16 offset; + s_xyz center; +} Math3D_pipe_c; + extern f32 Math3DVecLength(xyz_t* vec); extern xyz_t ZeroVec; diff --git a/rel/ac_sample.c b/rel/ac_sample.c new file mode 100644 index 00000000..f1ce4a68 --- /dev/null +++ b/rel/ac_sample.c @@ -0,0 +1,195 @@ +#include "ac_sample.h" + +#include "m_demo.h" +#include "m_font.h" +#include "m_msg.h" +#include "m_mail.h" +#include "m_rcp.h" +#include "m_name_table.h" +#include "m_play.h" + +static ClObjPipeData_c Ac_Sample_OcInfoData_forStand = { + { 0x39, 0x20, ClObj_TYPE_PIPE }, // collision data + { 1 }, // element data + // Pipe specs + { + 30, // radius + 60, // height + 0, // offset + + { 0, 0, 0 } // center + } +}; + +static void Ac_Sample_ct_forCorect(ACTOR* actor, GAME* game) { + GAME_PLAY* play = (GAME_PLAY*)game; + SAMPLE_ACTOR* sample = (SAMPLE_ACTOR*)actor; + ClObjPipe_ct(play, &sample->stand); + ClObjPipe_set5(play, &sample->stand, (ACTOR*)actor, &Ac_Sample_OcInfoData_forStand); +} + +static void Ac_Sample_Excute_Corect(SAMPLE_ACTOR* actor, GAME_PLAY* play) { + ClObjPipe_c* stand = &actor->stand; + + CollisionCheck_Uty_ActorWorldPosSetPipeC((ACTOR*)actor, stand); + CollisionCheck_setOC(play, &play->collision_check, (ClObj_c*)stand); +} + +static void Ac_Sample_Actor_dt(ACTOR* actor, GAME* game) { + SAMPLE_ACTOR* sample = (SAMPLE_ACTOR*)actor; + cKF_SkeletonInfo_R_c* keyframe = &sample->keyframe; + if (actor->child_actor != NULL) { + Actor_delete(actor->child_actor); + } + + cKF_SkeletonInfo_R_dt(keyframe); + ClObjPipe_dt((GAME_PLAY*)game, &sample->stand); +} + +static void Ac_Sample_Animation_Base(SAMPLE_ACTOR* actor) { + cKF_SkeletonInfo_R_play(&actor->keyframe); +} + +static void Ac_Sample_Actor_wait_demo_ct(ACTOR* actor) { + // ドリキャス "Dreamcast" + static u8 str0[16] = { 0xDC, 0xB8, 0x97, 0x8C, 0x9D, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE, CHAR_SPACE }; + + // プレステ2 "Playstation 2" + static u8 str9[5] = { 0xE4, 0xBA, 0x9D, 0xA3, 0x32 }; + + static u8 str_mail[64]; + + mDemo_Set_msg_num(9); + mMsg_Set_item_str(mMsg_Get_base_window_p(), 0, str0, 6); + mMsg_Set_item_str(mMsg_Get_base_window_p(), 4, str9, 5); + mMsg_Set_free_str(mMsg_Get_base_window_p(), 0, str0, 16); + mMsg_Set_free_str(mMsg_Get_base_window_p(), 9, str9, 5); + mMsg_Set_mail_str(mMsg_Get_base_window_p(), 0, str_mail, 64); +} + +static void Ac_Sample_Actor_main_wait(SAMPLE_ACTOR* actor, GAME_PLAY* play) { + Ac_Sample_Animation_Base(actor); + Actor_world_to_eye((ACTOR*)actor, 48.0f); + Ac_Sample_Excute_Corect(actor, play); + + if (mDemo_Check(7, (ACTOR*)actor) == FALSE) { + mDemo_Request(7, (ACTOR*)actor, &Ac_Sample_Actor_wait_demo_ct); + } + else { + actor->main_action = 1; + } +} + +static void Ac_Sample_Actor_main_talk(SAMPLE_ACTOR* actor, GAME_PLAY* play) { + Ac_Sample_Animation_Base(actor); + Actor_world_to_eye((ACTOR*)actor, 48.0f); + Ac_Sample_Excute_Corect(actor, play); + + if (mDemo_Check(7, (ACTOR*)actor)) { + s16 angle = add_calc_short_angle2(&actor->actor_class.shape_info.rotation.y, actor->actor_class.player_angle_y, 1.0f, 5000, 100); + actor->actor_class.world_rotation.y = actor->actor_class.shape_info.rotation.y; + + if (mDemo_Check_ListenAble() == FALSE && mDemo_Check_DiffAngle_forTalk(angle)) { + mDemo_Set_ListenAble(); + } + } + else { + actor->main_action = 0; + } +} + +typedef void (*Ac_Sample_Actor_PROC)(SAMPLE_ACTOR*, GAME_PLAY*); + +static void Ac_Sample_Actor_main(ACTOR* actor, GAME* game) { + static Ac_Sample_Actor_PROC proc[] = { &Ac_Sample_Actor_main_wait, &Ac_Sample_Actor_main_talk }; + + SAMPLE_ACTOR* sample = (SAMPLE_ACTOR*)actor; + GAME_PLAY* play = (GAME_PLAY*)game; + + if (sample->main_action < 0 || sample->main_action >= 2 || proc[sample->main_action] == NULL) { + return; + } + + (*proc[sample->main_action])(sample, play); +} + +extern cKF_Skeleton_R_c cKF_bs_r_hnw; +extern cKF_Animation_R_c cKF_ba_r_hnw_move; + +static void Ac_Sample_Actor_ct(ACTOR* actor, GAME* game) { + cKF_SkeletonInfo_R_c* keyframe; + GAME_PLAY* play = (GAME_PLAY*)game; + SAMPLE_ACTOR* sample = (SAMPLE_ACTOR*)actor; + Object_Bank_c* bank; + + keyframe = &sample->keyframe; + cKF_SkeletonInfo_R_ct(keyframe, &cKF_bs_r_hnw, &cKF_ba_r_hnw_move, sample->work_area, sample->morph_area); + cKF_SkeletonInfo_R_init_standard_stop(keyframe, &cKF_ba_r_hnw_move, NULL); + Ac_Sample_ct_forCorect(actor, game); + + sample->draw_action = 1; + bank = &play->object_exchange.banks[actor->data_bank_id]; + sample->obj_bank_ram_start = bank->ram_start; +} + +extern u8 hnw_tmem_txt[]; +extern u16 hnw_face[]; + +static void Ac_Sample_Actor_draw_normal(SAMPLE_ACTOR* actor, GAME_PLAY* play) { + cKF_SkeletonInfo_R_c* keyframe = &actor->keyframe; + Mtx* m = GRAPH_ALLOC_TYPE(play->game.graph, Mtx, keyframe->skeleton->num_shown_joints); + + if (m != NULL) { + GRAPH* g; + Gfx* gfx; + _texture_z_light_fog_prim(play->game.graph); + + g = play->game.graph; + OPEN_DISP(g); + gfx = NOW_POLY_OPA_DISP; + + gDPLoadTextureBlockS( + gfx++, + hnw_tmem_txt, G_IM_FMT_I, G_IM_SIZ_8b, + 64, 64, + 0, + G_TX_MIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, + 7, 7, + G_TX_NOLOD, G_TX_NOLOD + ); + gDPLoadTLUT_pal16(gfx++, 15, hnw_face); // pal is different + gDPSetTextureLUT(gfx++, G_TT_RGBA16); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(g); + + cKF_Si3_draw_R_SV((GAME*)play, keyframe, m, NULL, NULL, NULL); + } +} + +static void Ac_Sample_Actor_draw(ACTOR* actor, GAME* game) { + static Ac_Sample_Actor_PROC proc[] = { (Ac_Sample_Actor_PROC)&none_proc2, &Ac_Sample_Actor_draw_normal }; + + SAMPLE_ACTOR* sample = (SAMPLE_ACTOR*)actor; + GAME_PLAY* play = (GAME_PLAY*)game; + + if (sample->draw_action < 0 || sample->draw_action >= 2 || proc[sample->draw_action] == NULL) { + return; + } + + (*proc[sample->draw_action])(sample, play); +} + +ACTOR_PROFILE Sample_Profile = { + 0x02, // TODO: enum + ACTOR_PART_BG, + 0, + MISC_ACTOR_SAMPLE, + ACTOR_OBJ_BANK_12, + sizeof(SAMPLE_ACTOR), + &Ac_Sample_Actor_ct, + &Ac_Sample_Actor_dt, + &Ac_Sample_Actor_main, + &Ac_Sample_Actor_draw, + NULL +}; diff --git a/rel/c_keyframe.c b/rel/c_keyframe.c index bd1e0245..2abbc888 100644 --- a/rel/c_keyframe.c +++ b/rel/c_keyframe.c @@ -227,7 +227,7 @@ extern void cKF_SkeletonInfo_R_ct(cKF_SkeletonInfo_R_c* keyframe, keyframe->target_joint = target_table; } -extern void cKF_SkeletonInfo_R_dt() {} +extern void cKF_SkeletonInfo_R_dt(cKF_SkeletonInfo_R_c* keyframe) {} extern void cKF_SkeletonInfo_R_init_standard_stop( cKF_SkeletonInfo_R_c* keyframe, cKF_Animation_R_c* animation,