From e5f349ee9c98811e1a2268b31cfab342fb38add6 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Mon, 4 Sep 2023 17:59:55 +0200 Subject: [PATCH 1/5] link m_collision_obj --- config/rel_slices.yml | 5 + include/m_collision_obj.h | 136 +++++- include/macros.inc | 109 ++--- include/sys_math3d.h | 22 + rel/m_collision_obj.c | 984 ++++++++++++++++++++++++++++++++++++++ tools/ppcdis | 2 +- 6 files changed, 1172 insertions(+), 86 deletions(-) create mode 100644 rel/m_collision_obj.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 0a536ed0..14dd74b3 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -32,6 +32,11 @@ m_banti.c: .bss: [0x8125A830, 0x8125AC80] m_cockroach.c: .text: [0x80385430, 0x80385A80] +m_collision_obj.c: + .text: [0x80394518, 0x80395B24] + .rodata: [0x80641CE8, 0x80641D20] + .data: [0x80651208,0x806512D8] + .bss: [0x812663D0, 0x81266400] m_common_data.c: .text: [0x80395B24, 0x80395BE8] m_controller.c: diff --git a/include/m_collision_obj.h b/include/m_collision_obj.h index 57efa3b2..4e9c1145 100644 --- a/include/m_collision_obj.h +++ b/include/m_collision_obj.h @@ -2,7 +2,7 @@ #define M_COLLISION_OBJ_H #include "types.h" -#include "m_actor.h" +#include "m_actor_type.h" #include "sys_math3d.h" #include "m_play_h.h" @@ -18,6 +18,15 @@ enum collision_type { ClObj_TYPE_NUM }; +enum weight{ + MASS_IMMOVABLE, + MASS_HEAVY, + MASS_NORMAL +}; + +#define MASSTYPE_IMMOVABLE 0XFF +#define MASSTYPE_HEAVY 0XFE + 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 @@ -64,6 +73,55 @@ typedef struct collision_obj_pipe_data_s { ClObjPipeAttrData_c attribute_data; } ClObjPipeData_c; +typedef struct collision_check_tris_element_attr_data_s{ + xyz_t vtx[3]; +}ClObjTrisElemAttrData_c; + +typedef struct collision_check_tris_element_data_s{ + ClObjElemData_c element; + ClObjTrisElemAttrData_c data; +}ClObjTrisElemData_c; + +typedef struct collision_check_tris_element_s{ + Math3D_triangle_c tri; + xyz_t t; +}ClObjTrisElemAttr_c; + +typedef struct collision_tris_elem_s{ + ClObjElem_c element; + ClObjTrisElemAttr_c attribute; +}ClObjTrisElem_c; + +typedef struct collision_tris_s { + ClObj_c collision_obj; + int count; + ClObjTrisElem_c* elements; +} ClObjTris_c; + +typedef struct ClObjTris_Init { + ClObjData_c data; + int count; + ClObjTrisElemData_c* elem_data; +} ClObjTrisData_c; + +typedef struct collision_obj_joint_sphere_elem_attribute_s{ + Math3D_sphere_c s1; + Math3D_sphere_c s2; + f32 unk8; + u8 unk14; +}ClObjJntSphElemAttr_c; + +typedef struct collision_joint_sphere_elem_s{ + ClObjElem_c element; + ClObjJntSphElemAttr_c attribute; +}ClObjJntSphElem_c; + +typedef struct collision_joint_sphere_s { + ClObj_c collision_obj; + int count; + ClObjJntSphElem_c* elements; +}ClObjJntSph_c; + #define Cl_COLLIDER_NUM 50 typedef struct collision_check_s { u16 flags; @@ -95,14 +153,74 @@ typedef struct status_data_s { u8 weight; } StatusData_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); -extern void CollisionCheck_Status_set3(Status_c* status, StatusData_c* data); -extern void CollisionCheck_Status_ct(Status_c* status); -extern void CollisionCheck_Status_Clear(Status_c* status); +typedef struct mco_work_s { + int count; + ClObj_c* colliders[10]; +} McoWork; + +extern McoWork mco_work; + + +typedef void (*CollisionOCFunction)(GAME_PLAY*, CollisionCheck_c*, ClObj_c*,ClObj_c*); +typedef int (*CollisionOCClear)(GAME_PLAY*, ClObj_c*); +typedef int (*CollisionClearFunction)(GAME_PLAY*, ClObj_c*); + +extern void CollisionCheck_workTrisElemCenter(ClObjTrisElem_c *, xyz_t *); +extern int ClObj_ct(GAME_PLAY *, ClObj_c *); +extern int ClObj_dt(GAME_PLAY *, ClObj_c *); +extern int ClObj_set4(GAME_PLAY *, ClObj_c *, ACTOR *, ClObjData_c *); +extern void ClObj_OCClear(GAME_PLAY *, ClObj_c *); +extern int ClObjElem_ct(ClObjElem_c *); +extern int ClObjElem_set(ClObjElem_c *, ClObjElemData_c *); +extern void ClObjElem_OCClear(GAME_PLAY *, ClObjElem_c *); +extern int ClObjJntSphElem_OCClear(GAME_PLAY *, ClObjJntSphElem_c *); +extern int ClObjJntSph_OCClear(GAME_PLAY *, ClObj_c *); +extern int ClObjPipeAttr_ct(GAME_PLAY *, ClObjPipeAttr_c *); +extern int ClObjPipeAttr_dt(GAME_PLAY *, ClObjPipeAttr_c *); +extern int ClObjPipeAttr_set(GAME_PLAY *, ClObjPipeAttr_c *, ClObjPipeAttr_c *); +extern int ClObjPipe_ct(GAME_PLAY *, ClObjPipe_c *); +extern int ClObjPipe_dt(GAME_PLAY *, ClObjPipe_c *); +extern int ClObjPipe_set5(GAME_PLAY *, ClObjPipe_c *, ACTOR *, ClObjPipeData_c *); +extern int ClObjPipe_OCClear(GAME_PLAY *, ClObj_c *); +extern int ClObjTrisElemAttr_ct(GAME_PLAY *, ClObjTrisElemAttr_c *); +extern int ClObjTrisElemAttr_dt(GAME_PLAY *, ClObjTrisElemAttr_c *); +extern int ClObjTrisElemAttr_set(GAME_PLAY *, ClObjTrisElemAttr_c *, ClObjTrisElemAttrData_c *); +extern int ClObjTrisElem_ct(GAME_PLAY *, ClObjTrisElem_c *); +extern int ClObjTrisElem_dt(GAME_PLAY *, ClObjTrisElem_c *); +extern int ClObjTrisElem_set(GAME_PLAY *, ClObjTrisElem_c *, ClObjTrisElemData_c *); +extern int ClObjTrisElem_OCClear(GAME_PLAY *, ClObjTrisElem_c *); +extern int ClObjTris_ct(GAME_PLAY *, ClObjTris_c *); +extern int ClObjTris_dt_nzf(GAME_PLAY *, ClObjTris_c *); +extern int ClObjTris_set5_nzm(GAME_PLAY *, ClObjTris_c *, ACTOR *, ClObjTrisData_c *, ClObjTrisElem_c *); +extern int ClObjTris_OCClear(GAME_PLAY *, ClObj_c *); +extern void CollisionCheck_ct(GAME_PLAY *, CollisionCheck_c *); +extern void CollisionCheck_dt(GAME_PLAY *, CollisionCheck_c *); +extern void CollisionCheck_clear(GAME_PLAY *, CollisionCheck_c *); +extern int CollisionCheck_setOC(GAME_PLAY *, CollisionCheck_c *, ClObj_c *); +extern int get_type(u8); +extern void CollisionCheck_setOC_HitInfo(ClObj_c *, ClObjElem_c *, xyz_t *, ClObj_c *, ClObjElem_c *, xyz_t *, f32); +extern void CollisionCheck_OC_JntSph_Vs_JntSph(GAME_PLAY *, CollisionCheck_c *, ClObj_c *, ClObj_c *); +extern void CollisionCheck_OC_JntSph_Vs_Pipe(GAME_PLAY *, CollisionCheck_c *, ClObj_c *, ClObj_c *); +extern void CollisionCheck_OC_Pipe_Vs_JntSph(GAME_PLAY *, CollisionCheck_c *, ClObj_c *, ClObj_c *); +extern void CollisionCheck_OC_Pipe_Vs_Pipe(GAME_PLAY *, CollisionCheck_c *, ClObj_c *, ClObj_c *); +extern int CollisionCheck_Check1ClObjNoOC(ClObj_c *); +extern int CollisionCheck_Check2ClObjNoOC(ClObj_c *, ClObj_c *); +extern void CollisionCheck_OC(GAME_PLAY *, CollisionCheck_c *); +extern void CollisionCheck_setOCC_HitInfo(GAME_PLAY *, ClObj_c *, ClObjTrisElem_c *, xyz_t *, ClObj_c *, ClObjElem_c *, xyz_t *, xyz_t *); +extern void CollisionCheck_OCC_Tris_Vs_JntSph(GAME_PLAY *, CollisionCheck_c *, ClObjTris_c *, ClObjJntSph_c *); +extern void CollisionCheck_OCC_Tris_Vs_Pipe(GAME_PLAY *, CollisionCheck_c *, ClObjTris_c *, ClObjPipe_c *); +extern int CollisionCheck_Check1ClObjNoOCC(ClObj_c *); +extern void CollisionCheck_OCC(GAME_PLAY *, CollisionCheck_c *); +extern int ClObjTrisElem_OCCClear(GAME_PLAY *, ClObjTrisElem_c *); +extern int ClObj_OCCClear(GAME_PLAY *, ClObj_c *); +extern int ClObjTris_OCCClear(GAME_PLAY *, ClObj_c *); +extern int CollisionCheck_setOCC(GAME_PLAY *, CollisionCheck_c *, ClObj_c *); +extern void CollisionCheck_Status_ct(Status_c *); +extern void CollisionCheck_Status_Clear(Status_c *); +extern void CollisionCheck_Status_set3(Status_c *, StatusData_c *); +extern int CollisionCheck_Uty_ActorWorldPosSetPipeC(ACTOR *, ClObjPipe_c *); + + #ifdef __cplusplus } diff --git a/include/macros.inc b/include/macros.inc index 825a317b..30cb010a 100644 --- a/include/macros.inc +++ b/include/macros.inc @@ -1,5 +1,4 @@ -# PowerPC Register Constants -# General Purpose Registers (GPRs) +/* Register name macros */ .set r0, 0 .set r1, 1 .set r2, 2 @@ -32,8 +31,6 @@ .set r29, 29 .set r30, 30 .set r31, 31 - -# Floating Point Registers (FPRs) .set f0, 0 .set f1, 1 .set f2, 2 @@ -66,8 +63,6 @@ .set f29, 29 .set f30, 30 .set f31, 31 - -# Graphics Quantization Registers (GQRs) .set qr0, 0 .set qr1, 1 .set qr2, 2 @@ -76,73 +71,35 @@ .set qr5, 5 .set qr6, 6 .set qr7, 7 - -# Special Purpose Registers (SPRs) -.set XER, 1 -.set LR, 8 -.set CTR, 9 -.set DSISR, 18 -.set DAR, 19 -.set DEC, 22 -.set SDR1, 25 -.set SRR0, 26 -.set SRR1, 27 -.set SPRG0, 272 -.set SPRG1, 273 -.set SPRG2, 274 -.set SPRG3, 275 -.set EAR, 282 -.set PVR, 287 -.set IBAT0U, 528 -.set IBAT0L, 529 -.set IBAT1U, 530 -.set IBAT1L, 531 -.set IBAT2U, 532 -.set IBAT2L, 533 -.set IBAT3U, 534 -.set IBAT3L, 535 -.set DBAT0U, 536 -.set DBAT0L, 537 -.set DBAT1U, 538 -.set DBAT1L, 539 -.set DBAT2U, 540 -.set DBAT2L, 541 -.set DBAT3U, 542 -.set DBAT3L, 543 -.set GQR0, 912 -.set GQR1, 913 -.set GQR2, 914 -.set GQR3, 915 -.set GQR4, 916 -.set GQR5, 917 -.set GQR6, 918 -.set GQR7, 919 -.set HID2, 920 -.set WPAR, 921 -.set DMA_U, 922 -.set DMA_L, 923 -.set UMMCR0, 936 -.set UPMC1, 937 -.set UPMC2, 938 -.set USIA, 939 -.set UMMCR1, 940 -.set UPMC3, 941 -.set UPMC4, 942 -.set USDA, 943 -.set MMCR0, 952 -.set PMC1, 953 -.set PMC2, 954 -.set SIA, 955 -.set MMCR1, 956 -.set PMC3, 957 -.set PMC4, 958 -.set SDA, 959 -.set HID0, 1008 -.set HID1, 1009 -.set IABR, 1010 -.set DABR, 1013 -.set L2CR, 1017 -.set ICTC, 1019 -.set THRM1, 1020 -.set THRM2, 1021 -.set THRM3, 1022 +.set cr0lt, 0 +.set cr0gt, 1 +.set cr0eq, 2 +.set cr0un, 3 +.set cr1lt, 4 +.set cr1gt, 5 +.set cr1eq, 6 +.set cr1un, 7 +.set cr2lt, 8 +.set cr2gt, 9 +.set cr2eq, 10 +.set cr2un, 11 +.set cr3lt, 12 +.set cr3gt, 13 +.set cr3eq, 14 +.set cr3un, 15 +.set cr4lt, 16 +.set cr4gt, 17 +.set cr4eq, 18 +.set cr4un, 19 +.set cr5lt, 20 +.set cr5gt, 21 +.set cr5eq, 22 +.set cr5un, 23 +.set cr6lt, 24 +.set cr6gt, 25 +.set cr6eq, 26 +.set cr6un, 27 +.set cr7lt, 28 +.set cr7gt, 29 +.set cr7eq, 30 +.set cr7un, 31 diff --git a/include/sys_math3d.h b/include/sys_math3d.h index 34e69e78..c3a1bb93 100644 --- a/include/sys_math3d.h +++ b/include/sys_math3d.h @@ -15,10 +15,32 @@ typedef struct math_3d_pipe_s { s_xyz center; } Math3D_pipe_c; +typedef struct math_3d_sphere_s{ + s_xyz center; + s16 radius; +}Math3D_sphere_c; + +typedef struct math_3d_plane_s { + xyz_t normal; + f32 originDist; +} Math3D_plane_c; // size = 0x10 + +typedef struct math_3d_triangle_s { + xyz_t vtx[3]; + Math3D_plane_c plane; +} Math3D_triangle_c; // size = 0x34 + extern f32 Math3DVecLength(xyz_t* vec); extern void sMath_RotateX(xyz_t* pos, f32 rad); extern void sMath_RotateY(xyz_t* pos, f32 rad); extern void sMath_RotateZ(xyz_t* pos, f32 rad); +extern void Math3DPlane(xyz_t* va, xyz_t* vb, xyz_t* vc, f32* nox, f32* noy, f32* noz, f32* odist); +extern int Math3D_sphereCrossSphere_cl(Math3D_sphere_c* a, Math3D_sphere_c* b, f32* in); +extern int Math3D_sphereVsPipe_cl(Math3D_sphere_c* s, Math3D_pipe_c* c, f32* in); +extern int Math3D_pipeVsPipe_cl(Math3D_pipe_c* a, Math3D_pipe_c* b , f32* d); +extern int Math3D_sphereCrossTriangle3_cp(Math3D_sphere_c* s, Math3D_triangle_c* tri, xyz_t* ip); +extern int Math3D_pipeCrossTriangle_cp(Math3D_pipe_c* c,Math3D_triangle_c* tri, xyz_t* in); + extern xyz_t ZeroVec; extern s_xyz ZeroSVec; diff --git a/rel/m_collision_obj.c b/rel/m_collision_obj.c new file mode 100644 index 00000000..05924eab --- /dev/null +++ b/rel/m_collision_obj.c @@ -0,0 +1,984 @@ +#include "m_collision_obj.h" +#include "m_actor.h" + +McoWork mco_work; + + +void CollisionCheck_workTrisElemCenter(ClObjTrisElem_c* tri, xyz_t* vec) +{ + + vec->x = (tri->attribute.tri.vtx[0].x + tri->attribute.tri.vtx[1].x + tri->attribute.tri.vtx[2].x) * (1.0f / 3.0f); + vec->y = (tri->attribute.tri.vtx[0].y + tri->attribute.tri.vtx[1].y + + tri->attribute.tri.vtx[2].y) * + (1.0f / 3.0f); + vec->z = (tri->attribute.tri.vtx[0].z + tri->attribute.tri.vtx[1].z + + tri->attribute.tri.vtx[2].z) * + (1.0f / 3.0f); +} + +int ClObj_ct(GAME_PLAY* play, ClObj_c* cl) +{ + static ClObj_c clobj_default = {NULL, NULL, 0, 0, 3}; + + *cl = clobj_default; + + return 1; +} + +int ClObj_dt(GAME_PLAY*, ClObj_c*) +{ + return 1; +} + +int ClObj_set4(GAME_PLAY*, ClObj_c* cl, ACTOR* actor, ClObjData_c* data) +{ + + cl->owner_actor = actor; + cl->collision_flags0 = data->collision_flags0; + cl->collision_flags1 = data->collision_flags1; + cl->collision_type = data->type; + + return 1; +} + +void ClObj_OCClear(GAME_PLAY *, ClObj_c* cl) +{ + + cl->collision_flags0 &= ~2; + cl->collided_actor = NULL; + cl->collision_flags1 &= 0xFE; +} + +int ClObjElem_ct(ClObjElem_c* elem) +{ + + elem->flags = 0; + + return 1; +} + +int ClObjElem_set(ClObjElem_c* elem, ClObjElemData_c* data) +{ + + elem->flags = data->flags; + + return 1; +} + +void ClObjElem_OCClear(GAME_PLAY*, ClObjElem_c* elem) +{ + + elem->flags &= ~2; +} + +int ClObjJntSphElem_OCClear(GAME_PLAY* play, ClObjJntSphElem_c* col) +{ + + ClObjElem_OCClear(play, &col->element); + + return 1; +} + +int ClObjJntSph_OCClear(GAME_PLAY* play, ClObj_c* cl) +{ + + ClObjJntSph_c* jntsph = (ClObjJntSph_c*)cl; + ClObjJntSphElem_c* elem; + + ClObj_OCClear(play, &jntsph->collision_obj); + + for (elem = jntsph->elements; elem < &jntsph->elements[jntsph->count]; elem++) + { + ClObjJntSphElem_OCClear(play, elem); + } + + return 1; +} + +int ClObjPipeAttr_ct(GAME_PLAY* play, ClObjPipeAttr_c* attribute) +{ + + static ClObjPipeAttr_c default_pipe_attr = {0, 0, 0}; + + *attribute = default_pipe_attr; + + return 1; +} + +int ClObjPipeAttr_dt(GAME_PLAY*, ClObjPipeAttr_c*) +{ + + return 1; +} + +int ClObjPipeAttr_set(GAME_PLAY* play, ClObjPipeAttr_c* dst, ClObjPipeAttr_c* src) +{ + + *dst = *src; + + return 1; +} + +int ClObjPipe_ct(GAME_PLAY* play, ClObjPipe_c* pipe) +{ + + ClObj_ct(play, &pipe->collision_obj); + ClObjElem_ct(&pipe->element); + ClObjPipeAttr_ct(play, &pipe->attribute); + + return 1; +} + +int ClObjPipe_dt(GAME_PLAY* play, ClObjPipe_c* pipe) +{ + + ClObj_dt(play, &pipe->collision_obj); + ClObjPipeAttr_dt(play, &pipe->attribute); + + return 1; +} + +int ClObjPipe_set5(GAME_PLAY* play, ClObjPipe_c* pipe, ACTOR* owner, ClObjPipeData_c* data) +{ + + ClObj_set4(play, &pipe->collision_obj, owner, &data->collision_data); + ClObjElem_set(&pipe->element, &data->element_data); + ClObjPipeAttr_set(play, &pipe->attribute, (ClObjPipeAttr_c *)&data->attribute_data); + + return 1; +} + +int ClObjPipe_OCClear(GAME_PLAY* play, ClObj_c* cl) +{ + + ClObjPipe_c* pipe = (ClObjPipe_c *)cl; + + ClObj_OCClear(play, &pipe->collision_obj); + ClObjElem_OCClear(play, &pipe->element); + + return 1; +} + +int ClObjTrisElemAttr_ct(GAME_PLAY *play, ClObjTrisElemAttr_c *tris) +{ + + static ClObjTrisElemAttr_c default_clobjtriselem_attr = { + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + *tris = default_clobjtriselem_attr; + + return 1; +} + +int ClObjTrisElemAttr_dt(GAME_PLAY *play, ClObjTrisElemAttr_c *tris) +{ + + return 1; +} + +int ClObjTrisElemAttr_set(GAME_PLAY* play, ClObjTrisElemAttr_c* tris, ClObjTrisElemAttrData_c* data) +{ + + xyz_t* dst; + xyz_t* src; + f32 nox, noy, noz, odist; + + for (dst = tris->tri.vtx, src = data->vtx; dst < &tris->tri.vtx[3]; dst++, src++) + { + *dst = *src; + } + + Math3DPlane(&data->vtx[0], &data->vtx[1], &data->vtx[2], &nox, &noy, &noz, &odist); + tris->tri.plane.normal.x = nox; + tris->tri.plane.normal.y = noy; + tris->tri.plane.normal.z = noz; + tris->tri.plane.originDist = odist; + + return 1; +} + +int ClObjTrisElem_ct(GAME_PLAY* play, ClObjTrisElem_c* tris) +{ + + ClObjElem_ct(&tris->element); + ClObjTrisElemAttr_ct(play, &tris->attribute); + + return 1; +} + +int ClObjTrisElem_dt(GAME_PLAY* play, ClObjTrisElem_c* tris) +{ + + ClObjTrisElemAttr_dt(play, &tris->attribute); + + return 1; +} + +int ClObjTrisElem_set(GAME_PLAY* play, ClObjTrisElem_c* tris, ClObjTrisElemData_c* data) +{ + + ClObjElem_set(&tris->element, &data->element); + ClObjTrisElemAttr_set(play, &tris->attribute, &data->data); + + return 1; +} + +int ClObjTrisElem_OCClear(GAME_PLAY* play, ClObjTrisElem_c* tris) +{ + + ClObjElem_OCClear(play, &tris->element); + + return 1; +} + +int ClObjTris_ct(GAME_PLAY* play, ClObjTris_c* tris) +{ + + ClObj_ct(play, &tris->collision_obj); + tris->count = 0; + tris->elements = NULL; + + return 1; +} + +int ClObjTris_dt_nzf(GAME_PLAY *play, ClObjTris_c *tris) +{ + + ClObjTrisElem_c *element; + + ClObj_dt(play, &tris->collision_obj); + + for (element = tris->elements; element < &tris->elements[tris->count]; element++) + { + ClObjTrisElem_dt(play, element); + } + tris->count = 0; + tris->elements = NULL; + + return 1; +} + +int ClObjTris_set5_nzm(GAME_PLAY* play, ClObjTris_c* tris, ACTOR* actor, ClObjTrisData_c* data, + ClObjTrisElem_c *elem) +{ + + ClObjTrisElem_c* element; + ClObjTrisElemData_c* elementData; + + ClObj_set4(play, &tris->collision_obj, actor, &data->data); + + tris->count = data->count; + tris->elements = elem; + + for (element = tris->elements, elementData = data->elem_data; + element < &tris->elements[tris->count]; element++, elementData++) + { + ClObjTrisElem_ct(play, element); + ClObjTrisElem_set(play, element, elementData); + } + + return 1; +} + +int ClObjTris_OCClear(GAME_PLAY* play, ClObj_c* cl) +{ + ClObjTris_c* tris = (ClObjTris_c*)cl; + ClObjTrisElem_c* element; + + ClObj_OCClear(play, &tris->collision_obj); + + for (element = tris->elements; element < &tris->elements[tris->count]; element++) + { + ClObjTrisElem_OCClear(play, element); + } + + return 1; +} + +void CollisionCheck_ct(GAME_PLAY* play, CollisionCheck_c* col) +{ + + col->flags = 0; + CollisionCheck_clear(play, col); +} + +void CollisionCheck_dt(GAME_PLAY* play, CollisionCheck_c* col) +{ +} + +void CollisionCheck_clear(GAME_PLAY* play, CollisionCheck_c* col) +{ + + ClObj_c** clp; + + if (col->flags & 1) + { + return; + } + + col->collider_num = 0; + + for (clp = col->collider_table; clp < &col->collider_table[Cl_COLLIDER_NUM]; clp++) + { + *clp = NULL; + } + + mco_work.count = 0; + + for (clp = mco_work.colliders; clp < &mco_work.colliders[10]; clp++) + { + *clp = NULL; + } +} + +CollisionClearFunction OCClearFunctionTable[ClObj_TYPE_NUM] = { + ClObjJntSph_OCClear,ClObjPipe_OCClear,ClObjTris_OCClear +}; + +CollisionOCFunction oc_collision_function[ClObj_TYPE_NUM][ClObj_TYPE_NUM] = { + {CollisionCheck_OC_JntSph_Vs_JntSph, CollisionCheck_OC_JntSph_Vs_Pipe, NULL}, + {CollisionCheck_OC_Pipe_Vs_JntSph, CollisionCheck_OC_Pipe_Vs_Pipe, NULL}, + {NULL, NULL, NULL}}; + +CollisionOCFunction occ_collision_function[ClObj_TYPE_NUM][ClObj_TYPE_NUM] = { + {NULL, NULL, NULL}, + {NULL, NULL, NULL}, + {(CollisionOCFunction)CollisionCheck_OCC_Tris_Vs_JntSph, (CollisionOCFunction)CollisionCheck_OCC_Tris_Vs_Pipe, NULL} + }; + +CollisionOCClear OCCClearFunctionTable[ClObj_TYPE_NUM] = { + NULL, NULL, ClObjTris_OCCClear}; + + +int CollisionCheck_setOC(GAME_PLAY* play, CollisionCheck_c* col, ClObj_c* cl) +{ + + int ret; + + if (_Game_play_isPause(play) == 1) + { + return -1; + } + else + { + OCClearFunctionTable[cl->collision_type](play, cl); + + if ((cl->owner_actor != NULL) && (cl->owner_actor->mv_proc == NULL)) + { + return -1; + } + + if (col->collider_num >= Cl_COLLIDER_NUM) + { + return -1; + } + + if (col->flags & 1) + { + return -1; + } + + ret = col->collider_num; + col->collider_table[col->collider_num] = cl; + col->collider_num++; + } + + return ret; +} + +int get_type(u8 type) +{ + + if (type == MASSTYPE_IMMOVABLE) + { + return MASS_IMMOVABLE; + } + + if (type == MASSTYPE_HEAVY) + { + return MASS_HEAVY; + } + + return MASS_NORMAL; +} + +void CollisionCheck_setOC_HitInfo(ClObj_c* col1, ClObjElem_c* colelem1, xyz_t* pos1, ClObj_c* col2, + ClObjElem_c* colelem2, xyz_t* pos2, f32 diff) +{ + + ACTOR* actor1; + ACTOR* actor2; + int type1; + int type2; + + f32 xdiff; + f32 zdiff; + f32 xzdist; + + f32 weight1; + f32 weight2; + f32 minweight; + f32 comweight; + + f32 coldis1; + f32 coldis2; + + actor1 = col1->owner_actor; + actor2 = col2->owner_actor; + + col1->collided_actor = actor2; + col1->collision_flags0 |= 2; + colelem1->flags |= 2; + + if (col2->collision_flags1 & 8) + { + col1->collision_flags1 |= 1; + } + + col2->collided_actor = actor1; + col2->collision_flags0 |= 2; + colelem2->flags |= 2; + + if (col1->collision_flags1 & 8) + { + col2->collision_flags1 |= 1; + } + + if ((actor1 == NULL) || (actor2 == NULL)) + { + return; + } + + if ((col1->collision_flags0 & 4) || (col2->collision_flags0 & 4)) + { + return; + } + + type1 = get_type(actor1->status_data.weight); + type2 = get_type(actor2->status_data.weight); + + weight1 = actor1->status_data.weight; + weight2 = actor2->status_data.weight; + + comweight = weight1 + weight2; + + if (fabsf(comweight) < 0.008f) + { + weight1 = weight2 = 1.0f; + comweight = 2.0f; + } + + minweight = 1.0f / comweight; + + xdiff = pos2->x - pos1->x; + zdiff = pos2->z - pos1->z; + + xzdist = sqrtf((xdiff * xdiff) + (zdiff * zdiff)); + + if (type1 == 0) + { + if (type2 == 0) + { + return; + } + coldis1 = 0.0f; + coldis2 = 1.0f; + } + else if (type1 == 1) + { + if (type2 == 0) + { + coldis1 = 1.0f; + coldis2 = 0.0f; + } + else if (type2 == 1) + { + coldis1 = 0.5f; + coldis2 = 0.5f; + } + else + { + coldis1 = 0.0f; + coldis2 = 1.0f; + } + } + else + { + if (type2 == 2) + { + coldis1 = weight2 * minweight; + coldis2 = weight1 * minweight; + } + else + { + coldis1 = 1.0f; + coldis2 = 0.0f; + } + } + + if (col1->collision_flags0 & 0x40) + { + coldis1 = 0.0f; + coldis2 = 1.0f; + actor2->speed = 0.0f; + } + else if (col2->collision_flags0 & 0x40) + { + coldis1 = 1.0f; + coldis2 = 0.0f; + actor1->speed = 0.0f; + } + + if (!(fabsf(xzdist) < 0.008f)) + { + + xdiff *= diff / xzdist; + zdiff *= diff / xzdist; + + actor1->status_data.collision_vec.x += -xdiff * coldis1; + actor1->status_data.collision_vec.z += -zdiff * coldis1; + + actor2->status_data.collision_vec.x += xdiff * coldis2; + actor2->status_data.collision_vec.z += zdiff * coldis2; + } + else if (diff != 0) + { + actor1->status_data.collision_vec.x += -diff * coldis1; + actor2->status_data.collision_vec.x += diff * coldis2; + } + else + { + actor1->status_data.collision_vec.x -= coldis1; + actor2->status_data.collision_vec.x += coldis2; + } +} + +void CollisionCheck_OC_JntSph_Vs_JntSph(GAME_PLAY* play, CollisionCheck_c* check, ClObj_c* col1, + ClObj_c* col2) +{ + + ClObjJntSph_c* jntsph1 = (ClObjJntSph_c*)col1; + ClObjJntSph_c* jntsph2 = (ClObjJntSph_c*)col2; + + ClObjJntSphElem_c* elem1; + ClObjJntSphElem_c* elem2; + + if ((jntsph1->count <= 0) || (jntsph1->elements == NULL) || (jntsph2->count <= 0) || (jntsph2->elements == NULL)) + { + return; + } + + for (elem1 = jntsph1->elements; elem1 < &jntsph1->elements[jntsph1->count]; elem1++) + { + + if ((elem1->element.flags & 1)) + { + + for (elem2 = jntsph2->elements; elem2 < &jntsph2->elements[jntsph2->count]; elem2++) + { + + f32 in; + + if ((elem2->element.flags & 1)) + { + + if (Math3D_sphereCrossSphere_cl(&elem1->attribute.s2, &elem2->attribute.s2, &in) == 1) + { + + xyz_t pos1; + xyz_t pos2; + + xyz_t_move_s_xyz(&pos1, &elem1->attribute.s2.center); + xyz_t_move_s_xyz(&pos2, &elem2->attribute.s2.center); + CollisionCheck_setOC_HitInfo(&jntsph1->collision_obj, &elem1->element, &pos1, + &jntsph2->collision_obj, &elem2->element, &pos2, in); + } + } + } + } + } +} + +void CollisionCheck_OC_JntSph_Vs_Pipe(GAME_PLAY* play, CollisionCheck_c* check, ClObj_c* col1, + ClObj_c* col2) +{ + + ClObjJntSph_c* jntsph = (ClObjJntSph_c*)col1; + ClObjPipe_c* pipe = (ClObjPipe_c*)col2; + ClObjJntSphElem_c* elem; + f32 in; + xyz_t sphpos; + xyz_t pipepos; + + if ((jntsph->count > 0) && (jntsph->elements) != NULL) + { + + if (!(jntsph->collision_obj.collision_flags0 & 1) || !(pipe->collision_obj.collision_flags0 & 1) || + !(pipe->element.flags & 1)) + { + return; + } + + for (elem = jntsph->elements; elem < &jntsph->elements[jntsph->count]; elem++) + { + + if (!(elem->element.flags & 1)) + { + continue; + } + + if (Math3D_sphereVsPipe_cl(&elem->attribute.s2, &pipe->attribute.pipe, &in) == 1) + { + + xyz_t_move_s_xyz(&sphpos, &elem->attribute.s2.center); + xyz_t_move_s_xyz(&pipepos, &pipe->attribute.pipe.center); + CollisionCheck_setOC_HitInfo(&jntsph->collision_obj, &elem->element, &sphpos, + &pipe->collision_obj, &pipe->element, &pipepos, in); + } + } + } +} + +void CollisionCheck_OC_Pipe_Vs_JntSph(GAME_PLAY* play, CollisionCheck_c* colcheck, ClObj_c* col1, + ClObj_c* col2) +{ + + CollisionCheck_OC_JntSph_Vs_Pipe(play, colcheck, col2, col1); +} + +void CollisionCheck_OC_Pipe_Vs_Pipe(GAME_PLAY* play, CollisionCheck_c* colcheck, ClObj_c* col1, + ClObj_c* col2) +{ + + ClObjPipe_c* pipe1 = (ClObjPipe_c*)col1; + ClObjPipe_c* pipe2 = (ClObjPipe_c*)col2; + f32 in; + xyz_t pipepos1; + xyz_t pipepos2; + + if (!(pipe1->collision_obj.collision_flags0 & 1) || !(pipe2->collision_obj.collision_flags0 & 1) || !(pipe1->element.flags & 1) || !(pipe2->element.flags & 1)) + { + return; + } + + if (Math3D_pipeVsPipe_cl(&pipe1->attribute.pipe, &pipe2->attribute.pipe, &in) != 1) + { + return; + } + + xyz_t_move_s_xyz(&pipepos1, &pipe1->attribute.pipe.center); + xyz_t_move_s_xyz(&pipepos2, &pipe2->attribute.pipe.center); + + CollisionCheck_setOC_HitInfo(&pipe1->collision_obj, &pipe1->element, &pipepos1, + &pipe2->collision_obj, &pipe2->element, &pipepos2, in); +} + +int CollisionCheck_Check1ClObjNoOC(ClObj_c* col) +{ + + return col->collision_flags0 & 1 ^ 1; +} + +int CollisionCheck_Check2ClObjNoOC(ClObj_c* col1, ClObj_c* col2) +{ + + if (!(col1->collision_flags0 & col2->collision_flags1 & 0x38) || + !(col1->collision_flags1 & col2->collision_flags0 & 0x38)) + { + return 1; + } + + if (col1->owner_actor == col2->owner_actor) + { + return 1; + } + return 0; +} + + + +void CollisionCheck_OC(GAME_PLAY* play, CollisionCheck_c* colcheck) +{ + + ClObj_c** col1p; + ClObj_c** col2p; + CollisionOCFunction current; + + for (col1p = colcheck->collider_table; col1p < &colcheck->collider_table[colcheck->collider_num]; col1p++) + { + + if (((*col1p) == NULL) || (CollisionCheck_Check1ClObjNoOC(*col1p) == 1)) + { + continue; + } + + for (col2p = col1p + 1; col2p < &colcheck->collider_table[colcheck->collider_num]; col2p++) + { + + if ((*col2p == NULL) || (CollisionCheck_Check1ClObjNoOC(*col2p) == 1) || + (CollisionCheck_Check2ClObjNoOC(*col1p, *col2p) == 1)) + { + continue; + } + current = oc_collision_function[(*col1p)->collision_type][(*col2p)->collision_type]; + + if (current == NULL) + { + continue; + } + + current(play, colcheck, *col1p, *col2p); + } + } + CollisionCheck_OCC(play, colcheck); +} + +void CollisionCheck_setOCC_HitInfo(GAME_PLAY* play, ClObj_c* col1, ClObjTrisElem_c* elem1, xyz_t* pos1, + ClObj_c* col2, ClObjElem_c* elem2, xyz_t* pos2, xyz_t* pos3) +{ + + col1->collided_actor = col2->owner_actor; + col1->collision_flags1 |= 4; + + elem1->attribute.t.x = pos3->x; + elem1->attribute.t.y = pos3->y; + elem1->attribute.t.z = pos3->z; +} + + +void CollisionCheck_OCC_Tris_Vs_JntSph(GAME_PLAY* play, CollisionCheck_c* colcheck, ClObjTris_c* tris, + ClObjJntSph_c* jntsph) +{ + + ClObjTrisElem_c* triselem; + ClObjJntSphElem_c* jntsphelem; + xyz_t pos; + xyz_t sphpos; + xyz_t trispos; + + if ((tris->count <= 0) || (tris->elements == NULL) || + (jntsph->count <= 0) || (jntsph->elements == NULL)) + { + return; + } + + for (jntsphelem = jntsph->elements; jntsphelem < &jntsph->elements[jntsph->count]; jntsphelem++) + { + + if ((jntsphelem->element.flags & 1)) + { + + for (triselem = tris->elements; triselem < &tris->elements[tris->count]; triselem++) + { + + if (Math3D_sphereCrossTriangle3_cp(&jntsphelem->attribute.s2, &triselem->attribute.tri, &pos) != 0) + { + + xyz_t_move_s_xyz(&sphpos, &jntsphelem->attribute.s2.center); + CollisionCheck_workTrisElemCenter(triselem, &trispos); + CollisionCheck_setOCC_HitInfo(play, &tris->collision_obj, triselem, &trispos, &jntsph->collision_obj, &jntsphelem->element, + &sphpos, &pos); + } + } + } + } +} + + +void CollisionCheck_OCC_Tris_Vs_Pipe(GAME_PLAY* play, CollisionCheck_c* colcheck, ClObjTris_c* tris, ClObjPipe_c* pipe) +{ + + ClObjTrisElem_c* triselem; + xyz_t pos; + xyz_t pipepos; + xyz_t trispos; + + if ((pipe->attribute.pipe.radius > 0) && (pipe->attribute.pipe.height > 0) && (pipe->element.flags & 1)) + { + + if ((tris->count <= 0) || (tris->elements == NULL)) + { + return; + } + + for (triselem = tris->elements; triselem < &tris->elements[tris->count]; triselem++) + { + + if (Math3D_pipeCrossTriangle_cp(&pipe->attribute.pipe, &triselem->attribute.tri, &pos) != 0) + { + + CollisionCheck_workTrisElemCenter(triselem, &trispos); + xyz_t_move_s_xyz(&pipepos, &pipe->attribute.pipe.center); + CollisionCheck_setOCC_HitInfo(play, &tris->collision_obj, triselem, &trispos, &pipe->collision_obj, &pipe->element, &pipepos, &pos); + break; + } + } + } +} + +int CollisionCheck_Check1ClObjNoOCC(ClObj_c* col) +{ + + return col->collision_flags1 >> 1 & 1 ^ 1; +} + +void CollisionCheck_OCC(GAME_PLAY* play, CollisionCheck_c* colcheck) +{ + + + ClObj_c** col1p; + ClObj_c** col2p; + CollisionOCFunction current; + + if (mco_work.count == 0) + { + return; + } + + for (col1p = mco_work.colliders; col1p < &mco_work.colliders[mco_work.count]; col1p++) + { + + if (((*col1p) == NULL) || (CollisionCheck_Check1ClObjNoOCC(*col1p) == 1)) + { + continue; + } + + for (col2p = colcheck->collider_table; col2p < &colcheck->collider_table[colcheck->collider_num]; col2p++) + { + + if ((*col2p) == NULL) + { + continue; + } + + if ((*col1p)->owner_actor == (*col2p)->owner_actor) + { + continue; + } + + current = occ_collision_function[(*col1p)->collision_type][(*col2p)->collision_type]; + + if (current == NULL) + { + continue; + } + + current(play, colcheck, *col1p, *col2p); + } + } +} + +int ClObjTrisElem_OCCClear(GAME_PLAY* play, ClObjTrisElem_c* triselem) +{ + + triselem->attribute.t.x = 0.0f; + triselem->attribute.t.y = 0.0f; + triselem->attribute.t.z = 0.0f; + return 1; +} + +int ClObj_OCCClear(GAME_PLAY* play, ClObj_c* col) +{ + + col->collided_actor = NULL; + col->collision_flags1 &= ~4; +} + +int ClObjTris_OCCClear(GAME_PLAY* play, ClObj_c* col) +{ + + ClObjTris_c* tris = (ClObjTris_c*)col; + ClObjTrisElem_c* triselem; + + ClObj_OCCClear(play, &tris->collision_obj); + + for (triselem = tris->elements; triselem < &tris->elements[tris->count]; triselem++) + { + + ClObjTrisElem_OCCClear(play, triselem); + } + + return 1; +} + +int CollisionCheck_setOCC(GAME_PLAY* play, CollisionCheck_c* colcheck, ClObj_c* col) +{ + + int ret; + + if (_Game_play_isPause(play) == 1) + { + + return -1; + } + + if ((col->collision_type == 0) || (col->collision_type == 1)) + { + + return -1; + } + + OCCClearFunctionTable[col->collision_type](play, col); + + if ((col->owner_actor != NULL) && (col->owner_actor->mv_proc == NULL)) + { + + return -1; + } + + if (mco_work.count >= 10) + { + + return -1; + } + + if (colcheck->flags & 1) + { + + return -1; + } + + ret = mco_work.count; + mco_work.colliders[mco_work.count] = col; + mco_work.count++; + + return ret; +} + +void CollisionCheck_Status_ct(Status_c* status) +{ + + static Status_c status_org = {{0.0f, 0.0f, 0.0f}, 10, 10, 0, 50, 8, 0, 0, 0}; + + *status = status_org; +} + +void CollisionCheck_Status_Clear(Status_c* status) +{ + + status->damage = 0; + status->damage_effect = 0; + status->at_hit_effect = 0; + status->ac_hit_effect = 0; + status->collision_vec.z = 0.0f; + status->collision_vec.y = 0.0f; + status->collision_vec.x = 0.0f; +} + +void CollisionCheck_Status_set3(Status_c* status, StatusData_c* data) +{ + + status->hp = data->health; + status->radius = data->radius; + status->height = data->height; + status->offset = data->offset; + status->weight = data->weight; +} + +int CollisionCheck_Uty_ActorWorldPosSetPipeC(ACTOR* actor, ClObjPipe_c* pipe) +{ + + pipe->attribute.pipe.center.x = actor->world.position.x; + pipe->attribute.pipe.center.y = actor->world.position.y; + pipe->attribute.pipe.center.z = actor->world.position.z; +} \ No newline at end of file diff --git a/tools/ppcdis b/tools/ppcdis index ef5a43f0..b49c7feb 160000 --- a/tools/ppcdis +++ b/tools/ppcdis @@ -1 +1 @@ -Subproject commit ef5a43f0e09f3aa3a694d14ab9a777f7254b60be +Subproject commit b49c7feb305e562d5d4503fc117bf9020f941ef8 From 68db2189f0d5a762a8843d1c7c954ca2c9c64ab2 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Fri, 8 Sep 2023 18:55:22 +0200 Subject: [PATCH 2/5] link m_play --- config/rel_slices.yml | 11 +- include/Famicom/famicom.h | 3 + include/PreRender.h | 5 + include/audio.h | 4 +- include/famicom_emu.h | 2 + include/m_camera2.h | 4 + include/m_card.h | 1 + include/m_collision_bg.h | 6 + include/m_common_data.h | 4 +- include/m_debug_display.h | 11 + include/m_demo.h | 3 + include/m_event.h | 6 +- include/m_fbdemo.h | 16 +- include/m_fbdemo_fade.h | 1 + include/m_fbdemo_triforce.h | 1 - include/m_field_make.h | 3 + include/m_fuusen.h | 2 +- include/m_kankyo.h | 4 + include/m_msg.h | 4 + include/m_notice.h | 2 + include/m_play.h | 56 +- include/m_player_lib.h | 2 + include/m_scene.h | 64 ++- include/m_scene_table.h | 4 + include/m_submenu.h | 7 + include/m_titledemo.h | 1 + include/version.h | 9 + rel/ac_animal_logo_misc.c | 1 + rel/audio.c | 4 +- rel/m_actor.c | 2 +- rel/m_all_grow.c | 1 + rel/m_all_grow_ovl.c | 1 + rel/m_eappli.c | 2 +- rel/m_fbdemo.c | 15 +- rel/m_fuusen.c | 2 +- rel/m_museum_display.c | 2 +- rel/m_play.c | 1018 +++++++++++++++++++++++++++++++++++ rel/m_post_office.c | 1 + rel/m_random_field.c | 2 +- rel/m_select.c | 2 +- rel/m_start_data_init.c | 2 +- rel/m_titledemo.c | 2 +- rel/m_trademark.c | 2 +- rel/m_watch_my_step.c | 2 +- src/version.c | 6 +- 45 files changed, 1254 insertions(+), 49 deletions(-) create mode 100644 include/m_debug_display.h create mode 100644 include/version.h create mode 100644 rel/m_play.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 69929662..fa3d5813 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -340,6 +340,13 @@ first_game.c: .text: [0x80629CA8, 0x80629D4C] sys_romcheck.c: .text: [0x80629D4C, 0x80629D8C] +sys_dynamic.c: + .bss: [0x813413F8, 0x81361820] +m_play.c: + .text: [0x80629D8C,0x8062B630] + .rodata: [0x8064D1B8, 0x8064D1C0] + .data: [0x806D46D0, 0x806D4958] + .bss: [0x81361820, 0x8148DA60] second_game.c: .text: [0x8062B630, 0x8062B848] .bss: [0x8148DA60, 0x8148DA68] @@ -363,10 +370,6 @@ audio.c: .rodata: [0x8064D340, 0x8064D360] .data: [0x806D4CB0,0x806D4D40] .bss: [0x8148DA78,0x8148DA7C] -sys_dynamic.c: - .bss: [0x813413F8, 0x81361820] -# ac_aprilfool_control/aPC_actor_dt.c: common_data is pure bs, - # .text: [0x805153f0, 0x8051542C] # dataobject.obj files data/titledemo/pact0.c: diff --git a/include/Famicom/famicom.h b/include/Famicom/famicom.h index f0f5495f..eff1fece 100644 --- a/include/Famicom/famicom.h +++ b/include/Famicom/famicom.h @@ -68,6 +68,9 @@ typedef struct famicom_common_s { /* 0xB4 */ int _b4; } FamicomCommon; + +extern void* my_malloc_current; + typedef u8 (*FAMICOM_GETSAVECHAN_PROC)(int* player_no, int* slot_card_result); extern void famicom_setCallback_getSaveChan(FAMICOM_GETSAVECHAN_PROC getSaveChan_proc); extern int famicom_mount_archive(); diff --git a/include/PreRender.h b/include/PreRender.h index 3be609cd..899ffebd 100644 --- a/include/PreRender.h +++ b/include/PreRender.h @@ -27,6 +27,11 @@ typedef struct prerender_s { u8 _24[0x24]; } PreRender; +extern void PreRender_setup_savebuf(PreRender* render, int arg1, int arg2, int arg3, int arg4, int arg5); +extern void PreRender_init(PreRender* render); +extern void PreRender_setup_renderbuf(PreRender* render, int arg1, int arg2, void* arg3, void* arg4); +extern void PreRender_cleanup(PreRender* render); + #ifdef __cplusplus } #endif diff --git a/include/audio.h b/include/audio.h index 326d97ee..9a3134a1 100644 --- a/include/audio.h +++ b/include/audio.h @@ -91,8 +91,8 @@ extern void sAdo_OngenTrgStartSpeed(f32 speed, u16 s1, xyz_t* pos); extern void sAdo_TrgSeEcho(u8 b); extern void sAdo_LevSeEcho(u8 b); -extern void sAdo_BgmFadeoutCheck(); -extern void sAdo_SeFadeoutCheck(); +extern u8 sAdo_BgmFadeoutCheck(); +extern u8 sAdo_SeFadeoutCheck(); extern void sAdo_RoomType(u8 type); extern void sAdo_Museum(u8 type); diff --git a/include/famicom_emu.h b/include/famicom_emu.h index 86c9a3b6..60ad768a 100644 --- a/include/famicom_emu.h +++ b/include/famicom_emu.h @@ -13,6 +13,8 @@ typedef struct game_famicom_emu_s { /* 0x00 */ GAME game; } GAME_FAMICOM_EMU; +extern void* my_malloc_func[]; + extern void famicom_emu_init(GAME_FAMICOM_EMU* famicom_emu); extern void famicom_emu_cleanup(GAME_FAMICOM_EMU* famicom_emu); diff --git a/include/m_camera2.h b/include/m_camera2.h index 14d0fd78..0dc93e6b 100644 --- a/include/m_camera2.h +++ b/include/m_camera2.h @@ -326,6 +326,10 @@ typedef struct camera_s { xyz_t* Camera2_getMicPos_p(GAME_PLAY*); +void Camera2_ClearActorTalking_Cull(GAME_PLAY*); +void Camera2_process(GAME_PLAY*); +void Init_Camera2(GAME_PLAY*); +void Camera2_draw(GAME_PLAY*); #ifdef __cplusplus } diff --git a/include/m_card.h b/include/m_card.h index f926ab67..de2e91ac 100644 --- a/include/m_card.h +++ b/include/m_card.h @@ -16,6 +16,7 @@ extern void mCD_init_card(); extern void mCD_PrintErrInfo(gfxprint_t* gfxprint); extern void mCD_InitAll(); extern void mCD_LoadLand(); +extern void mCD_toNextLand(); #ifdef __cplusplus } diff --git a/include/m_collision_bg.h b/include/m_collision_bg.h index f6517ddb..9d20ac3f 100644 --- a/include/m_collision_bg.h +++ b/include/m_collision_bg.h @@ -116,6 +116,12 @@ extern void mCoBG_SetPlussOffset(xyz_t wpos, s16 offset, s16 new_attrib); extern int mCoBG_GetLayer(const xyz_t* wpos); extern int mCoBG_BnumUnum2HoleNumber(int block_x, int block_z, int ut_x, int ut_z); +extern void mCoBG_InitMoveBgData(); +extern void mCoBG_InitBlockBgCheckMode(); +extern void mCoBG_InitDecalCircle(); + +extern void mCoBG_CalcTimerDecalCircle(); + extern f32 mCoBG_GetWaterHeight_File(xyz_t wpos, char* file, int line); #define mCoBG_GetWaterHeight(wpos) mCoBG_GetWaterHeight_File(wpos, __FILE__, __LINE__) diff --git a/include/m_common_data.h b/include/m_common_data.h index 13d1a16f..6a0a884d 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -200,7 +200,9 @@ typedef struct common_data_s { /* 0x028592 */ s16 demo_profiles[mDemo_CLIP_TYPE_NUM - 1]; /* 0x028596 */ u8 _28596[0x285C0 - 0x28596]; /* 0x0285C0 */ s8 player_decoy_flag; - /* 0x0285C1 */ u8 _285C1[0x028838 - 0x0285C1]; + /* 0x0285C1 */ u8 _285C1[0x0285C6 - 0x0285C1]; + /* 0x0285C6 */ u8 event_id; + /* 0x0285C7 */ u8 _285C3[0x028838 - 0x0285C7]; /* 0x028838 */ s8 player_bee_swell_flag; /* 0x028839 */ s8 player_bee_chase_flag; /* 0x02883A */ u8 goki_shocked_flag; diff --git a/include/m_debug_display.h b/include/m_debug_display.h new file mode 100644 index 00000000..d0c373e5 --- /dev/null +++ b/include/m_debug_display.h @@ -0,0 +1,11 @@ +#ifndef M_DEBUG_DISPLAY_H +#define M_DEBUG_DISPLAY_H + +#include "types.h" +#include "m_play.h" + + +extern void Debug_Display_output(GAME_PLAY*); +extern void Debug_Display_init(); + +#endif \ No newline at end of file diff --git a/include/m_demo.h b/include/m_demo.h index accdac37..d1773f66 100644 --- a/include/m_demo.h +++ b/include/m_demo.h @@ -60,6 +60,8 @@ enum demo_clip_type { mDemo_CLIP_TYPE_NUM }; +extern void mDemo_Init(GAME_PLAY*); +extern void mDemo_Main(GAME_PLAY*); 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); @@ -75,6 +77,7 @@ extern void mDemo_Set_talk_display_name(u8 value); extern void mDemo_Set_camera(u8 value); extern void mDemo_Set_talk_window_color(rgba_t* color); extern int mDemo_CheckDemo(); +extern void mDemo_stock_clear(); #ifdef __cplusplus } diff --git a/include/m_event.h b/include/m_event.h index bc8d9719..e3cd5d7e 100644 --- a/include/m_event.h +++ b/include/m_event.h @@ -240,7 +240,7 @@ extern int mEv_check_status(int event, s16 status); extern s8* mEv_get_common_area(int type, s8 id); extern int mEv_ArbeitPlayer(u32 player_no); extern u16 mEv_get_special_event_type(); -mEv_ClearEventSaveInfo(mEv_event_save_c* event_save_data); +extern int mEv_ClearEventSaveInfo(mEv_event_save_c* event_save_data); extern int mEv_weekday2day(lbRTC_month_t month, int week_type, lbRTC_weekday_t weekday); extern void mEv_ClearEventInfo(); @@ -248,12 +248,16 @@ extern void mEv_ClearEventInfo(); extern void mEv_init(Event_c* event); extern void mEv_2nd_init(Event_c* event); +extern void mEv_run(Event_c* event); +extern void mEv_finish(Event_c* event); + extern int mEv_CheckTitleDemo(); extern void mEv_SetTitleDemo(int titledemo_no); extern void mEv_debug_print4f(gfxprint_t* gfxprint); extern void mEv_sp_debug_print4f(gfxprint_t* gfxprint); + #ifdef __cplusplus } #endif diff --git a/include/m_fbdemo.h b/include/m_fbdemo.h index c227e880..0c0f9d76 100644 --- a/include/m_fbdemo.h +++ b/include/m_fbdemo.h @@ -17,16 +17,16 @@ typedef struct { /* 0x98 */ Mtx modelView2; /* 0xD8 */ Gfx* gfx; // "gfxtbl" /* 0xDC */ u16* zBuffer; -} fbdemo; // size = 0xE0 +} fbdemo_c; // size = 0xE0 -extern void fbdemo_init_gfx(fbdemo*); -extern void fbdemo_init_data(fbdemo*); -extern void fbdemo_cleanup(fbdemo*); -extern fbdemo* fbdemo_init(fbdemo*, int, int); -extern void fbdemo_update(fbdemo*); -extern void fbdemo_draw(fbdemo*, Gfx**); -extern void fbdemo_move(fbdemo*); +extern void fbdemo_init_gfx(fbdemo_c*); +extern void fbdemo_init_data(fbdemo_c*); +extern void fbdemo_cleanup(fbdemo_c*); +extern fbdemo_c* fbdemo_init(fbdemo_c*, int, int); +extern void fbdemo_update(fbdemo_c*); +extern void fbdemo_draw(fbdemo_c*, Gfx**); +extern void fbdemo_move(fbdemo_c*); #endif diff --git a/include/m_fbdemo_fade.h b/include/m_fbdemo_fade.h index f389c7cf..107b0ed8 100644 --- a/include/m_fbdemo_fade.h +++ b/include/m_fbdemo_fade.h @@ -18,6 +18,7 @@ typedef struct { extern fbdemo_fade* fbdemo_fade_init(fbdemo_fade*); extern void fbdemo_fade_move(fbdemo_fade*, int); +extern void fbdemo_fade_draw(fbdemo_fade* this, Gfx** gfxP); extern void fbdemo_fade_startup(fbdemo_fade*); extern void fbdemo_fade_settype(fbdemo_fade*, int); extern void fbdemo_fade_setcolor_rgba8888(fbdemo_fade* this, u32 color); diff --git a/include/m_fbdemo_triforce.h b/include/m_fbdemo_triforce.h index f4653ca8..5cdda014 100644 --- a/include/m_fbdemo_triforce.h +++ b/include/m_fbdemo_triforce.h @@ -26,5 +26,4 @@ extern s8 fbdemo_triforce_is_finish(fbdemo_triforce*); extern void fbdemo_triforce_settype(fbdemo_triforce*, int); extern void fbdemo_triforce_setcolor_rgba8888(void); - #endif \ No newline at end of file diff --git a/include/m_field_make.h b/include/m_field_make.h index 07372ea3..5e696b79 100644 --- a/include/m_field_make.h +++ b/include/m_field_make.h @@ -5,6 +5,7 @@ #include "m_actor_type.h" #include "libforest/gbi_extensions.h" #include "game_h.h" +#include "m_play.h" #ifdef __cplusplus extern "C" { @@ -91,6 +92,8 @@ typedef struct field_info_s { extern u8* g_block_type_p; extern int* g_block_kind_p; +extern void mFM_FieldInit(GAME_PLAY*); +extern void mFM_Field_dt(); extern void mFM_DecideBgTexIdx(u8* bg_tex_idx); extern void mFM_InitFgCombiSaveData(GAME* game); extern mActor_name_t mFM_GetReserveName(int block_x, int block_z); diff --git a/include/m_fuusen.h b/include/m_fuusen.h index eb91afcc..59a76215 100644 --- a/include/m_fuusen.h +++ b/include/m_fuusen.h @@ -20,7 +20,7 @@ enum { extern int fuusen_DEBUG_mode_flag; -extern void Balloon_init(); +extern void Balloon_init(GAME_PLAY*); extern void Balloon_make_fuusen(GAME_PLAY* play); extern void Balloon_chk_make_fuusen(GAME_PLAY* play); extern void Balloon_move(GAME_PLAY* play); diff --git a/include/m_kankyo.h b/include/m_kankyo.h index 14200d95..28d68de4 100644 --- a/include/m_kankyo.h +++ b/include/m_kankyo.h @@ -42,7 +42,11 @@ typedef struct kankyo_s { /* 0xC8 */ Nature nature; } Kankyo; +extern void Global_kankyo_ct(GAME_PLAY*, Kankyo*); extern int mEnv_NowWeather(); +extern int mEnv_WindMove(); +extern void mEnv_ManagePointLight(GAME_PLAY*, Kankyo*, Global_light*); +extern void Global_kankyo_set(GAME_PLAY*, Kankyo*, Global_light*); #ifdef __cplusplus } diff --git a/include/m_msg.h b/include/m_msg.h index fb40c949..989a66d7 100644 --- a/include/m_msg.h +++ b/include/m_msg.h @@ -218,6 +218,10 @@ struct message_window_s { extern int mMsg_Get_Length_String(u8* buf, size_t buf_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_ct(GAME_PLAY*); +extern void mMsg_dt(GAME_PLAY*); +extern void mMsg_Main(GAME_PLAY*); +extern void mMsg_Draw(GAME_PLAY*); extern void mMsg_debug_draw(gfxprint_t* gfxprint); extern void mMsg_aram_init(); extern void mMsg_aram_init2(); diff --git a/include/m_notice.h b/include/m_notice.h index 0fff4aff..8f99fe5c 100644 --- a/include/m_notice.h +++ b/include/m_notice.h @@ -17,6 +17,8 @@ typedef struct notice_board_post_s { /* 0xC0 */ lbRTC_time_c post_time; /* date-time of post */ } mNtc_board_post_c; +extern void mNtc_set_auto_nwrite_data(); + #ifdef __cplusplus } #endif diff --git a/include/m_play.h b/include/m_play.h index efbeeddf..b28e8969 100644 --- a/include/m_play.h +++ b/include/m_play.h @@ -16,12 +16,14 @@ #include "m_collision_obj.h" #include "m_play_h.h" #include "m_scene.h" +#include "PreRender.h" #ifdef __cplusplus extern "C" { #endif typedef int (*DRAW_CHK_PROC)(ACTOR*, GAME_PLAY*); +typedef void (*PLAY_WIPE_PROC)(GAME_PLAY*); /* sizeof(struct game_play_s) == 0x2600 */ struct game_play_s { @@ -30,7 +32,8 @@ struct game_play_s { /* 0x00E0 */ s16 scene_id; /* 0x00E4 */ mFI_block_tbl_c block_table; /* 0x00F4 */ mFI_block_tbl_c last_block_table; - /* 0x0104 */ u8 _0104[0x0110 - 0x0104]; + /* 0x0104 */ u8 _0104[0x010C - 0x0104]; + /* 0x010C */ Scene_status_c* current_scene_data; /* 0x0110 */ Object_Exchange_c object_exchange; /* 0x1A68 */ View view; /* 0x1B88 */ Camera2 camera; @@ -39,12 +42,16 @@ struct game_play_s { /* 0x1DA0 */ pause_t pause; /* 0x1DA8 */ Actor_info actor_info; /* 0x1DEC */ Submenu submenu; - /* 0x1FA4 */ u8 _1FA4[0x2008 - 0x1FA4]; + /* 0x1FA4 */ s8 unk1FA4; + /* 0x1FA8 */ u8 _1FA4[0x1FB8 - 0x1FA8]; + /* 0x1FB8 */ PreRender prerender; + /* 0x2000 */ Door_data_c* door_data; + /* 0x2004 */ int _2004; /* 0x2008 */ int next_scene_no; /* 0x200C */ MtxF projection_matrix; - /* 0x204C */ MtxF mtx_204C; - /* 0x208C */ int _208C; - /* 0x2090 */ u32 game_frame; + /* 0x204C */ MtxF billboard_matrix; + /* 0x208C */ Mtx* _208C; + /* 0x2090 */ u32 game_frame; /* 0x2094 */ u8 _2094; /* 0x2095 */ u8 actor_data_num; /* 0x2096 */ u8 ctrl_actor_data_num; @@ -63,12 +70,45 @@ struct game_play_s { /* 0x2318 */ fbdemo_fade color_fade; /* 0x2328 */ CollisionCheck_c collision_check; /* 0x23F8 */ DRAW_CHK_PROC draw_chk_proc; // only used by mikanbox actor - /* 0x23FC */ u8 _23FC[0x2600 - 0x23FC]; + /* 0x23FC */ u32 fade_color_value; + /* 0x2400 */ Scene_status_c* scene_data_2400; + /* 0x2404 */ u8 _2400[0x2600 - 0x2404]; }; +extern fbdemo_c fbdemo; -extern void play_init(GAME_PLAY* play); -extern void play_cleanup(GAME_PLAY* play); +extern void Game_play_Reset_destiny(); +extern void event_title_flag_on(); +extern void event_title_flag_off(); +extern void Game_play_camera_proc(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_destroy(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_create_sub(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_create(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_init(GAME_PLAY *); +extern void Game_play_fbdemo_fade_in_move_end(GAME_PLAY *); +extern void Game_play_fbdemo_fade_out_start_emu_move_end(GAME_PLAY *); +extern void Game_play_fbdemo_fade_out_game_end_move_end(GAME_PLAY *); +extern void Game_play_change_scene_move_end(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_move(GAME_PLAY *); +extern void Game_play_fbdemo_wipe_proc(GAME_PLAY *); +extern Gfx* game_play_set_fog(GAME_PLAY *, Gfx *); +extern void Game_play_fbdemo_proc(GAME_PLAY *); +extern void play_cleanup(GAME *); +extern void VR_Box_ct(GAME_PLAY *); +extern void play_init(GAME *); +extern void Game_play_move_fbdemo_not_move(GAME_PLAY *); +extern void Game_play_move(GAME_PLAY *); +extern void setupFog(GAME_PLAY *, GRAPH *); +extern void setupViewer(GAME_PLAY *); +extern void setupViewMatrix(GAME_PLAY *, GRAPH *, GRAPH *); +extern void copy_efb_to_texture(Gfx **, void *); +extern int makeBumpTexture(GAME_PLAY *, GRAPH *, GRAPH *); +extern void draw_version(GRAPH *); +extern void Game_play_draw(GAME *); +extern void play_main(GAME *); +extern void Gameplay_Scene_Init(GAME_PLAY *); +extern u8 mPl_SceneNo2SoundRoomType(int); +extern void Gameplay_Scene_Read(GAME_PLAY *, s16); #ifdef __cplusplus } diff --git a/include/m_player_lib.h b/include/m_player_lib.h index 18ce0144..51980270 100644 --- a/include/m_player_lib.h +++ b/include/m_player_lib.h @@ -9,9 +9,11 @@ extern "C" { #endif +extern void mPlib_Object_Exchange_keep_Player_dt(GAME_PLAY*); extern PLAYER_ACTOR* get_player_actor_withoutCheck(GAME_PLAY* play); extern void mPlib_SetData1_controller_data_for_title_demo(f32 stick_x, f32 stick_y, int btn_a, int btn_b); extern void mPlib_SetData2_controller_data_for_title_demo(mActor_name_t tool); +extern void mPlib_Clear_controller_data_for_title_demo(); extern void mPlib_request_main_invade_type1(GAME_PLAY* play); extern mActor_name_t mPlib_Get_itemNo_forWindow(); extern int mPlib_check_able_change_camera_normal_index(); diff --git a/include/m_scene.h b/include/m_scene.h index dfbcee91..ab67bdbd 100644 --- a/include/m_scene.h +++ b/include/m_scene.h @@ -2,7 +2,6 @@ #define M_SCENE_H #include "types.h" -#include "m_scene_table.h" #include "m_lib.h" #ifdef __cplusplus @@ -39,8 +38,71 @@ typedef struct object_exchange_s { u8 _1934[0x1958-0x1934]; } Object_Exchange_c; +typedef struct scene_status_s{ + u8 unk0[0x13]; + u8 unk13; +}Scene_status_c; + +extern Scene_status_c test01_info; +extern Scene_status_c test02_info; +extern Scene_status_c test03_info; +extern Scene_status_c water_test_info; +extern Scene_status_c test_step01_info; +extern Scene_status_c test04_info; +extern Scene_status_c npc_room01_info; +extern Scene_status_c test_fd_npc_land_info; +extern Scene_status_c field_tool_field_info; +extern Scene_status_c shop01_info; +extern Scene_status_c BG_TEST01_info; +extern Scene_status_c BG_TEST01_XLU_info; +extern Scene_status_c broker_shop_info; +extern Scene_status_c fg_tool_in_info; +extern Scene_status_c post_office_info; +extern Scene_status_c start_demo1_info; +extern Scene_status_c start_demo2_info; +extern Scene_status_c police_box_info; +extern Scene_status_c buggy_info; +extern Scene_status_c player_select_info; +extern Scene_status_c player_room_s_info; +extern Scene_status_c player_room_m_info; +extern Scene_status_c player_room_l_info; +extern Scene_status_c shop02_info; +extern Scene_status_c shop03_info; +extern Scene_status_c shop04_1f_info; +extern Scene_status_c test05_info; +extern Scene_status_c PLAYER_SELECT2_info; +extern Scene_status_c PLAYER_SELECT3_info; +extern Scene_status_c shop04_2f_info; +extern Scene_status_c event_notification_info; +extern Scene_status_c kamakura_info; +extern Scene_status_c field_tool_field_info; +extern Scene_status_c title_demo_info; +extern Scene_status_c PLAYER_SELECT4_info; +extern Scene_status_c museum_entrance_info; +extern Scene_status_c museum_picture_info; +extern Scene_status_c museum_fossil_info; +extern Scene_status_c museum_insect_info; +extern Scene_status_c museum_fish_info; +extern Scene_status_c player_room_ll1_info; +extern Scene_status_c player_room_ll2_info; +extern Scene_status_c p_room_bm_s_info; +extern Scene_status_c p_room_bm_m_info; +extern Scene_status_c p_room_bm_l_info; +extern Scene_status_c p_room_bm_ll1_info; +extern Scene_status_c NEEDLEWORK_info; +extern Scene_status_c player_room_island_info; +extern Scene_status_c npc_room_island_info; +extern Scene_status_c start_demo3_info; +extern Scene_status_c lighthouse_info; +extern Scene_status_c tent_info; + extern int mSc_bank_regist_check(Object_Exchange_c* exchange, s16 bank_id); extern void mSc_regist_initial_exchange_bank(GAME_PLAY* play); +extern void mSc_dmacopy_data_bank(Object_Exchange_c*); +extern void mSc_data_bank_ct(GAME_PLAY*, Object_Exchange_c*); +extern void Door_info_ct(Door_data_c**); +extern void Scene_ct(GAME_PLAY*, void*); +extern void mSc_decide_exchange_bank(Object_Exchange_c*); #ifdef __cplusplus } diff --git a/include/m_scene_table.h b/include/m_scene_table.h index dfc074f5..0d696412 100644 --- a/include/m_scene_table.h +++ b/include/m_scene_table.h @@ -2,6 +2,7 @@ #define M_SCENE_TABLE_H #include "types.h" +#include "m_scene.h" #ifdef __cplusplus extern "C" { @@ -78,6 +79,9 @@ enum scene_table { SCENE_NUM }; + +extern Scene_status_c scene_data_status[SCENE_NUM]; + #ifdef __cplusplus } #endif diff --git a/include/m_submenu.h b/include/m_submenu.h index 45c639dc..4c81aea4 100644 --- a/include/m_submenu.h +++ b/include/m_submenu.h @@ -104,6 +104,13 @@ struct submenu_s { }; extern void mSM_open_submenu(Submenu* submenu, int menu_type, int arg0, int arg1); +extern void mSM_submenu_dt(Submenu*); +extern void mSM_submenu_ovlptr_cleanup(Submenu*); +extern void mSM_submenu_ovlptr_init(GAME_PLAY*); +extern void mSM_submenu_ct(Submenu*); +extern void mSM_submenu_ctrl(GAME_PLAY*); +extern void mSM_submenu_move(Submenu*); +extern void mSM_submenu_draw(Submenu*, GAME_PLAY*); extern int mSM_CHECK_ALL_FISH_GET(); extern int mSM_CHECK_ALL_INSECT_GET(); diff --git a/include/m_titledemo.h b/include/m_titledemo.h index d9046b2a..d6a90579 100644 --- a/include/m_titledemo.h +++ b/include/m_titledemo.h @@ -25,6 +25,7 @@ extern u16 pact4_head_table[]; extern int mTD_demono_get(); extern void title_demo_move(GAME_PLAY* play); +extern void mTD_player_keydata_init(GAME_PLAY* play); extern void mTD_rtc_set(); extern void mTD_rtc_reserve(); extern int mTD_get_titledemo_no(); diff --git a/include/version.h b/include/version.h new file mode 100644 index 00000000..6d78fc45 --- /dev/null +++ b/include/version.h @@ -0,0 +1,9 @@ +#ifndef VERSION_H +#define VERSION_H + +#include "types.h" + +extern char __Creator__[]; +extern char __DateTime__[]; + +#endif \ No newline at end of file diff --git a/rel/ac_animal_logo_misc.c b/rel/ac_animal_logo_misc.c index b41cf77e..b9970490 100644 --- a/rel/ac_animal_logo_misc.c +++ b/rel/ac_animal_logo_misc.c @@ -9,6 +9,7 @@ #include "m_time.h" #include "m_titledemo.h" #include "m_event.h" +#include "m_scene_table.h" extern void flash_rom_and_player_info_clear() { Save* save = Common_GetPointer(save); diff --git a/rel/audio.c b/rel/audio.c index 6e9472c4..c562f2cb 100644 --- a/rel/audio.c +++ b/rel/audio.c @@ -341,12 +341,12 @@ extern void sAdo_LevSeEcho(u8 b){ Na_LevSeEcho(b); } -extern void sAdo_BgmFadeoutCheck(){ +extern u8 sAdo_BgmFadeoutCheck(){ Na_BgmFadeoutCheck(); } -extern void sAdo_SeFadeoutCheck(){ +extern u8 sAdo_SeFadeoutCheck(){ Na_SeFadeoutCheck(); } diff --git a/rel/m_actor.c b/rel/m_actor.c index a2f64a9a..655fc5ff 100644 --- a/rel/m_actor.c +++ b/rel/m_actor.c @@ -323,7 +323,7 @@ extern void Actor_info_ct(GAME* game, Actor_info* actor_info, Actor_data* player bzero(actor_info, sizeof(Actor_info)); actor_dlftbls_init(); - Matrix_copy_MtxF(&play->mtx_204C, &MtxF_clear); + Matrix_copy_MtxF(&play->billboard_matrix, &MtxF_clear); Matrix_copy_MtxF(&play->projection_matrix, &MtxF_clear); /* Reset the actor dlf table info */ diff --git a/rel/m_all_grow.c b/rel/m_all_grow.c index aec33a24..9715a384 100644 --- a/rel/m_all_grow.c +++ b/rel/m_all_grow.c @@ -9,6 +9,7 @@ #include "m_collision_bg.h" #include "zurumode.h" #include "m_common_data.h" +#include "m_scene_table.h" static mActor_name_t l_tree_max_table[mAGrw_FRUIT_NUM] = { TREE_APPLE_FRUIT, diff --git a/rel/m_all_grow_ovl.c b/rel/m_all_grow_ovl.c index 6e2d1913..485d73b5 100644 --- a/rel/m_all_grow_ovl.c +++ b/rel/m_all_grow_ovl.c @@ -10,6 +10,7 @@ #include "m_house.h" #include "m_snowman.h" #include "m_shop.h" +#include "m_scene_table.h" #ifdef MUST_MATCH #include "ppcdis.h" diff --git a/rel/m_eappli.c b/rel/m_eappli.c index 700af571..b38ead6b 100644 --- a/rel/m_eappli.c +++ b/rel/m_eappli.c @@ -3,7 +3,7 @@ #include "m_common_data.h" #include "m_private.h" #include "lb_rtc.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "m_malloc.h" #include "libjsys/jsyswrapper.h" diff --git a/rel/m_fbdemo.c b/rel/m_fbdemo.c index 7e4caded..efd539ea 100644 --- a/rel/m_fbdemo.c +++ b/rel/m_fbdemo.c @@ -3,6 +3,7 @@ #include "libc64/malloc.h" #include "libc64/sleep.h" #include "libultra/gu.h" +#include "m_play.h" Gfx fbdemo_gfx_init[] = { gsDPPipeSync(), @@ -19,7 +20,7 @@ Gfx fbdemo_gfx_init[] = { gsSPEndDisplayList(), }; -extern void fbdemo_init_gfx(fbdemo* this) { +extern void fbdemo_init_gfx(fbdemo_c* this) { int col; int col2; int colTex; @@ -87,7 +88,7 @@ extern void fbdemo_init_gfx(fbdemo* this) { gSPEndDisplayList(gfx++); } -extern void fbdemo_init_data(fbdemo* this) { +extern void fbdemo_init_data(fbdemo_c* this) { int col; int row; @@ -99,7 +100,7 @@ extern void fbdemo_init_data(fbdemo* this) { } } -extern void fbdemo_cleanup(fbdemo* this) { +extern void fbdemo_cleanup(fbdemo_c* this) { msleep(100); if (this->vtxData != NULL) { @@ -120,7 +121,7 @@ extern void fbdemo_cleanup(fbdemo* this) { } } -extern fbdemo* fbdemo_init(fbdemo* this, int cols, int rows) { +extern fbdemo_c* fbdemo_init(fbdemo_c* this, int cols, int rows) { s32 gridsize; bzero(this, sizeof(fbdemo)); @@ -168,7 +169,7 @@ extern fbdemo* fbdemo_init(fbdemo* this, int cols, int rows) { return this; } -extern void fbdemo_update(fbdemo* this) { +extern void fbdemo_update(fbdemo_c* this) { int col; int row; Vtx* vtx; @@ -186,7 +187,7 @@ extern void fbdemo_update(fbdemo* this) { } } -void fbdemo_draw(fbdemo* this, Gfx** gfxP) { +void fbdemo_draw(fbdemo_c* this, Gfx** gfxP) { Gfx* gfx = *gfxP; gSPDisplayList(gfx++, fbdemo_gfx_init); @@ -204,4 +205,4 @@ void fbdemo_draw(fbdemo* this, Gfx** gfxP) { *gfxP = gfx; } -extern void fbdemo_move(fbdemo* this) {} +extern void fbdemo_move(fbdemo_c* this) {} diff --git a/rel/m_fuusen.c b/rel/m_fuusen.c index 0bbda03f..396b001f 100644 --- a/rel/m_fuusen.c +++ b/rel/m_fuusen.c @@ -9,7 +9,7 @@ int fuusen_DEBUG_mode_flag; -extern void Balloon_init() { +extern void Balloon_init(GAME_PLAY*) { Common_Set(balloon_state, Balloon_STATE_DEAD); Common_Set(balloon_last_spawn_min, 0); Common_Set(balloon_spawn_percent, 0.05f); diff --git a/rel/m_museum_display.c b/rel/m_museum_display.c index ce2a909f..c0d29930 100644 --- a/rel/m_museum_display.c +++ b/rel/m_museum_display.c @@ -2,7 +2,7 @@ #include "m_name_table.h" #include "m_room_type.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "m_common_data.h" extern int mMmd_FossilInfo(int fossil_no) { diff --git a/rel/m_play.c b/rel/m_play.c new file mode 100644 index 00000000..9cd8c971 --- /dev/null +++ b/rel/m_play.c @@ -0,0 +1,1018 @@ +#include "m_play.h" + +#include "m_common_data.h" +#include "libultra/libultra.h" +#include "m_fbdemo_wipe1.h" +#include "m_fbdemo_triforce.h" +#include "m_fbdemo_fade.h" +#include "m_debug.h" +#include "boot.h" +#include "version.h" +#include "m_bgm.h" +#include "m_rcp.h" +#include "m_msg.h" +#include "m_banti.h" +#include "m_event.h" +#include "m_npc.h" +#include "m_huusui_room.h" +#include "m_field_make.h" +#include "m_card.h" +#include "m_eappli.h" +#include "famicom_emu.h" +#include "Famicom/famicom.h" +#include "m_malloc.h" +#include "m_field_info.h" +#include "m_time.h" +#include "m_titledemo.h" +#include "sys_matrix.h" +#include "m_fuusen.h" +#include "m_watch_my_step.h" +#include "m_vibctl.h" +#include "m_train_control.h" +#include "gfxalloc.h" +#include "m_debug_display.h" +#include "jsyswrap.h" +#include "m_trademark.h" +#include "zurumode.h" +#include "m_scene_table.h" + +u16 S_back_title_timer; +u16 S_se_endcheck_timeout; +fbdemo_c fbdemo; +u8 gxbuf[0x140] ATTRIBUTE_ALIGN(32); +u8 prbuf[0x12c000] ATTRIBUTE_ALIGN(32); + +void Game_play_Reset_destiny(){ + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + mPr_destiny_c* destiny = &Common_Get(now_private)->destiny; + + if (destiny->type == mPr_DESTINY_NORMAL) { + return; + } + + if( + (rtc_time->year != destiny->received_time.year) || + (rtc_time->month != destiny->received_time.month) || + (rtc_time->day != destiny->received_time.day) + ) { + + Common_Set(now_private->destiny.type, mPr_DESTINY_NORMAL); + } +} + +void event_title_flag_on(){ + if(Common_Get(event_id) != 0){ + Common_Set(event_notification_active,1); + } +} + +void event_title_flag_off(){ + + if(Common_Get(event_id) == 2){ + Common_Set(event_id,0); + Common_Set(event_notification_active,0); + + } +} + +void Game_play_camera_proc(GAME_PLAY* play){ + + Camera2_ClearActorTalking_Cull(play); + Camera2_process(play); +} + +void Game_play_fbdemo_wipe_destroy(GAME_PLAY* play){ + + play->fbdemo_wipe.wipe_procs.cleanup_proc(&play->fbdemo_wipe.wipe_data); + play->fb_wipe_mode = 0; + play->fbdemo_wipe.wipe_type = -1; +} + +void Game_play_fbdemo_wipe_create_sub(GAME_PLAY* play){ + static void* wipe_normal_proc[] = { + fbdemo_wipe1_init, + none_proc1, + fbdemo_wipe1_move, + fbdemo_wipe1_draw, + fbdemo_wipe1_startup, + fbdemo_wipe1_settype, + fbdemo_wipe1_setcolor_rgba8888, + NULL, + fbdemo_wipe1_is_finish, + }; + static void* wipe_triforce_proc[] = { + fbdemo_triforce_init, + none_proc1, + fbdemo_triforce_move, + fbdemo_triforce_draw, + fbdemo_triforce_startup, + fbdemo_triforce_settype, + fbdemo_triforce_setcolor_rgba8888, + NULL, + fbdemo_triforce_is_finish, + }; + static void* wipe_fade_proc[] = { + fbdemo_fade_init, + none_proc1, + fbdemo_fade_move, + fbdemo_fade_draw, + fbdemo_fade_startup, + fbdemo_fade_settype, + fbdemo_fade_setcolor_rgba8888, + NULL, + fbdemo_fade_is_finish, + }; + + static void* wipe_proc[] = { + wipe_normal_proc, + wipe_triforce_proc, + wipe_fade_proc, + wipe_fade_proc, + wipe_triforce_proc, + wipe_triforce_proc, + wipe_fade_proc, + }; + + int type = play->fb_wipe_type; + fbdemo_wipe_proc_c* cur; + + + bzero(&play->fbdemo_wipe, sizeof(fbdemo_wipe)); + + if(type >= 7){ + type = 1; + } + + play->fbdemo_wipe.wipe_type = type; + cur = wipe_proc[type]; + play->fbdemo_wipe.wipe_procs.init_proc = cur->init_proc; + play->fbdemo_wipe.wipe_procs.cleanup_proc = cur->cleanup_proc; + play->fbdemo_wipe.wipe_procs.move_proc = cur->move_proc; + play->fbdemo_wipe.wipe_procs.draw_proc = cur->draw_proc; + play->fbdemo_wipe.wipe_procs.startup_proc = cur->startup_proc; + play->fbdemo_wipe.wipe_procs.settype_proc = cur->settype_proc; + play->fbdemo_wipe.wipe_procs.setcolor_proc = cur->setcolor_proc; + play->fbdemo_wipe.wipe_procs.isfinished_proc = cur->isfinished_proc; +} + +void Game_play_fbdemo_wipe_create(GAME_PLAY* play){ + + Game_play_fbdemo_wipe_create_sub(play); + Game_play_fbdemo_wipe_init(play); +} + +void Game_play_fbdemo_wipe_init(GAME_PLAY* play){ + fbdemo_wipe* wipe = &play->fbdemo_wipe; + u8 type; + + play->fbdemo_wipe.wipe_procs.init_proc(&wipe->wipe_data); + + Common_Set(transWipeSpeed, 28); + Common_Set(transFadeDuration, 30); + + wipe->wipe_procs.setcolor_proc(&wipe->wipe_data,0); + + type = play->fb_fade_type; + + if(wipe->wipe_type == 4){ + type |= 0x80; + } + else if(wipe->wipe_type == 5){ + type |= 0x40; + } + wipe->wipe_procs.settype_proc(&wipe->wipe_data, type); + wipe->wipe_procs.startup_proc(&wipe->wipe_data); + + play->fb_wipe_mode = 3; + + S_back_title_timer = 120; + S_se_endcheck_timeout = 120; +} + +void Game_play_fbdemo_fade_in_move_end(GAME_PLAY* play){ + Game_play_fbdemo_wipe_destroy(play); + + if(play->fb_mode == 3){ + fbdemo_cleanup(&fbdemo); + play->fb_mode = 0; + SetGameFrame(3); + } +} + +void Game_play_fbdemo_fade_out_start_emu_move_end(GAME_PLAY* play){ + + GAME_GOTO_NEXT(&play->game, famicom_emu, FAMICOM_EMU); + +} + +void Game_play_fbdemo_fade_out_game_end_move_end(GAME_PLAY* play){ + + GAME_GOTO_NEXT(&play->game, trademark, TRADEMARK); +} + +void Game_play_change_scene_move_end(GAME_PLAY* play){ + + game_goto_next_game_play(&play->game); + Common_Set(last_scene_no, Save_Get(scene_no)); + Save_Set(scene_no,play->next_scene_no); + +} + +void Game_play_fbdemo_wipe_move(GAME_PLAY* play){ + fbdemo_wipe* wipe = &play->fbdemo_wipe; + s16 wipet = FALSE; + int isDone = TRUE; + + if(wipe->wipe_procs.isfinished_proc(&wipe->wipe_data) != 0) { + if((play->fb_fade_type != 1) && (play->fb_fade_type != 11)){ + if(S_se_endcheck_timeout != 0){ + S_se_endcheck_timeout--; + } + + if((sAdo_SeFadeoutCheck() == 0) && (S_se_endcheck_timeout != 0)){ + isDone = FALSE; + } + else{ + sAdo_Set_ongenpos_refuse_fg(1); + } + } + if(play->fb_fade_type == 11){ + sAdo_Set_ongenpos_refuse_fg(2); + } + + if(isDone == TRUE){ + switch(play->fb_fade_type){ + case 1: + Game_play_fbdemo_fade_in_move_end(play); + break; + + case 3: + if(S_back_title_timer != 0){ + S_back_title_timer--; + } + + if((sAdo_BgmFadeoutCheck() == 1) || (S_back_title_timer == 0)){ + Game_play_fbdemo_fade_out_start_emu_move_end(play); + } + else{ + wipet = TRUE; + } + break; + + case 4: + case 6: + if(S_back_title_timer == 120){ + mBGMPsComp_make_ps_wipe(360); + } + case 5: + case 10: + if(S_back_title_timer != 0){ + S_back_title_timer--; + } + + if((sAdo_BgmFadeoutCheck() == 1) || (S_back_title_timer == 0)){ + Game_play_fbdemo_fade_out_game_end_move_end(play); + } + else{ + wipet = TRUE; + } + break; + + case 8: + if(S_back_title_timer != 0){ + S_back_title_timer--; + } + + if((sAdo_BgmFadeoutCheck() == 1) || (S_back_title_timer == 0)){ + if((Common_Get(clip.animal_logo_clip) != NULL) && + (Common_Get(clip.animal_logo_clip->data_init_proc) != NULL)){ + Common_Get(clip.animal_logo_clip->data_init_proc)(play); + Game_play_change_scene_move_end(play); + } + } + else{ + wipet = TRUE; + } + break; + + case 9: + if(S_back_title_timer != 0){ + S_back_title_timer--; + } + + if((sAdo_BgmFadeoutCheck() == 1) || (S_back_title_timer == 0)){ + Game_play_change_scene_move_end(play); + } + else{ + wipet = TRUE; + } + break; + + case 11: + case 12: + Game_play_change_scene_move_end(play); + break; + + + default: + if(S_back_title_timer != 0){ + S_back_title_timer--; + } + + if((sAdo_BgmFadeoutCheck() == 1) || (S_back_title_timer == 0)){ + Game_play_change_scene_move_end(play); + } + else{ + wipet = TRUE; + } + break; + } + if(!wipet){ + play->fb_fade_type = 0; + } + } + } + else { + wipe->wipe_procs.move_proc(&wipe->wipe_data, game_GameFrame); + } +} + + +void Game_play_fbdemo_wipe_proc(GAME_PLAY* play){ + static PLAY_WIPE_PROC wipe_proc[] = { + (PLAY_WIPE_PROC)none_proc1,Game_play_fbdemo_wipe_create, + Game_play_fbdemo_wipe_init,Game_play_fbdemo_wipe_move + }; + + if((play->fb_wipe_mode == 0) && (play->fb_fade_type != 0)){ + play->fb_wipe_mode = 1; + } + + wipe_proc[play->fb_wipe_mode](play); +} + +Gfx* game_play_set_fog(GAME_PLAY* play, Gfx* gfx){ + + return gfx_set_fog_nosync(gfx, play->global_light.fogColor[0], play->global_light.fogColor[1], + play->global_light.fogColor[2], 0, play->global_light.fogNear, play->global_light.fogFar); +} + +void Game_play_fbdemo_proc(GAME_PLAY* play){ + + switch(play->fb_mode){ + case 2: + if(fbdemo_init(&fbdemo, 10, 7) == 0){ + play->fb_mode = 0; + } + else{ + play->fb_mode = 3; + SetGameFrame(1); + } + break; + + case 3: + fbdemo_move(&fbdemo); + break; + } +} + +void play_cleanup(GAME* game){ + GAME_PLAY* play = (GAME_PLAY*)game; + + mMsg_dt(play); + banti_dt(); + + play->game.graph->taskEndCallback = NULL; + play->game.graph->taskEndData = NULL; + play->submenu.mode = 0; + + PreRender_cleanup(&play->prerender); + CollisionCheck_dt(play, &play->collision_check); + + if(play->fb_mode == 3){ + fbdemo_cleanup(&fbdemo); + play->fb_mode = 0; + } + + if(play->fb_wipe_mode == 3){ + Game_play_fbdemo_wipe_destroy(play); + } + + Actor_info_dt(&play->actor_info, play); + mEv_finish(&play->event); + mNpc_ClearEventNpc(); + mNpc_ClearMaskNpc(); + + mSM_submenu_dt(&play->submenu); + play->unk1FA4 = -1; + mSM_submenu_ovlptr_cleanup(&play->submenu); + + mPlib_Object_Exchange_keep_Player_dt(play); + + mHsRm_GetHuusuiRoom(NULL, Common_Get(player_no)); + mFM_Field_dt(); + mCD_toNextLand(); + mEA_CleanCardDLProgram(); + + if(my_malloc_current == my_malloc_func){ + my_malloc_current = NULL; + } + + zelda_CleanupArena(); + +} + +void VR_Box_ct(GAME_PLAY* play){ + + Global_kankyo_ct(play, &play->kankyo); +} + +void play_init(GAME* game){ + GAME_PLAY* play = (GAME_PLAY*)game; + + GRAPH* graph = play->game.graph; + int type; + fbdemo_fade* fade; + int freebytes; + u32 alloc; + u32 aligned; + u32 size; + + game_resize_hyral(&play->game, 0xFFFC1800); + Common_Set(rhythym_updated,0); + + mFI_ChangeClimate_ForEventNotice(); + mTM_time_init(); + sAdo_Set_ongenpos_refuse_fg(0); + event_title_flag_on(); + mTD_rtc_set(); + mTM_set_season(); + mPlib_Clear_controller_data_for_title_demo(); + + mSM_submenu_ovlptr_init(play); + mDemo_Init(play); + mEv_init(&play->event); + + initView(&play->view, graph); + Init_Camera2(play); + CollisionCheck_ct(play, &play->collision_check); + + mCoBG_InitMoveBgData(); + mCoBG_InitBlockBgCheckMode(); + mCoBG_InitDecalCircle(); + + play->unk1FA4 = -1; + + Gameplay_Scene_Read(play, Save_Get(scene_no)); + + mSM_submenu_ct(&play->submenu); + play->submenu.mode = 0; + + PreRender_init(&play->prerender); + PreRender_setup_savebuf(&play->prerender, SCREEN_WIDTH * 2 ,SCREEN_HEIGHT * 2, 0, 0, 0 ); + PreRender_setup_renderbuf(&play->prerender, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, 0,0); + + play->fb_mode = 0; + type = 1; + + play->fb_wipe_mode = 0; + play->fb_fade_type = 1; + + if(Common_Get(wipeType) != 0xFF){ + type = Common_Get(wipeType); + Common_Set(wipeType, 0xFF); + } + + play->fb_wipe_type = type; + + Pause_ct(&play->pause); + new_Matrix(&play->game); + + fade = &play->color_fade; + + play->game.exec = play_main; + play->game.cleanup = play_cleanup; + fbdemo_fade_init(fade); + fbdemo_fade_settype(fade, 7); + fbdemo_fade_setcolor_rgba8888(fade, 0xA0A0A0FF); + fbdemo_fade_startup(fade); + + play->fade_color_value = 0; + + freebytes = game_getFreeBytes(&play->game); + alloc = (u32)THA_alloc16(&play->game.tha, freebytes); + aligned = ALIGN_NEXT(alloc, 16); + size = aligned - alloc; + + zelda_InitArena((void*)aligned, freebytes - size); + + if(my_malloc_current == NULL){ + my_malloc_current = my_malloc_func; + } + + mFM_FieldInit(play); + VR_Box_ct(play); + mMmd_MakeMuseumDisplayData(); + Actor_info_ct(&play->game, &play->actor_info, play->player_data); + play->draw_chk_proc = none_proc1; + mMsg_ct(play); + mEv_2nd_init(&play->event); + mTD_player_keydata_init(play); + Balloon_init(play); + mNtc_set_auto_nwrite_data(); + banti_ct(); + watch_my_step_ct(); + event_title_flag_off(); + mEA_GetCardDLProgram(); +} + +void Game_play_move_fbdemo_not_move(GAME_PLAY* play){ + + play->game.doing_point = 0; + play->game.doing_point_specific = 0x8F; + play->game.doing_point = 1; + + mSM_submenu_ctrl(play); + + if(play->submenu.process_status == 0){ + + play->game.doing_point = 2; + mDemo_Main(play); + play->game.doing_point = 3; + mEv_run(&play->event); + } + + play->game.doing_point = 4; + mDemo_stock_clear(); + play->game.doing_point = 5; + mSc_dmacopy_data_bank(&play->object_exchange); + play->game.doing_point = 6; + mSM_submenu_move(&play->submenu); + + if(play->submenu.process_status == 0){ + + play->game_frame++; + mVibctl_clr_force_stop(2); + play->game.doing_point = 7; + CollisionCheck_OC(play, &play->collision_check); + play->game.doing_point = 8; + CollisionCheck_clear(play, &play->collision_check); + play->game.doing_point = 9; + play->game.doing_point = 0; + play->game.doing_point_specific = 0x90; + Actor_info_call_actor(play, &play->actor_info); + play->game.doing_point = 0; + play->game.doing_point_specific = 0x91; + play->game.doing_point = 1; + mCoBG_CalcTimerDecalCircle(); + play->game.doing_point = 2; + mMsg_Main(play); + } + else{ + mVibctl_set_force_stop(2); + } + + fbdemo_fade_move(&play->color_fade, game_GameFrame); + +} + +void Game_play_move(GAME_PLAY* play){ + + int debug; + + play->game.doing_point = 0; + play->game.doing_point_specific = 0x8D; + play->game.doing_point = 1; + Game_play_Reset_destiny(); + play->game.doing_point = 2; + + debug = (zurumode_flag >= 2) ? (Pause_proc(&play->pause, &play->game.pads[1]) == 0) : 0; + + play->game.doing_point = 0; + play->game.doing_point_specific = 0x8E; + + if(debug == 0){ + + play->game.doing_point = 1; + Game_play_fbdemo_wipe_proc(play); + play->game.doing_point = 2; + Game_play_fbdemo_proc(play); + play->game.doing_point = 3; + + if(play->fb_mode != 3){ + Game_play_move_fbdemo_not_move(play); + } + } + + if(play->submenu.process_status == 0){ + + play->game.doing_point = 0; + play->game.doing_point_specific = 0x92; + play->game.doing_point = 1; + Game_play_camera_proc(play); + play->game.doing_point = 2; + mPO_business_proc(play); + play->game.doing_point = 3; + mTRC_move(play); + play->game.doing_point = 4; + Balloon_move(play); + mEnv_ManagePointLight(play, &play->kankyo, &play->global_light); + + } + + play->game.doing_point = 0; + play->game.doing_point_specific = 0x93; + play->game.doing_point = 1; + Global_kankyo_set(play, &play->kankyo, &play->global_light); + play->game.doing_point = 2; + mEnv_WindMove(); + play->game.doing_point = 3; + watch_my_step_move(play); + play->game.doing_point = 4; + banti_move(play); + play->game.doing_point = 5; + title_demo_move(play); + play->game.doing_point = 0; + play->game.doing_point_specific = 0x95; + +} + + +void setupFog(GAME_PLAY* play, GRAPH* graph){ + + OPEN_DISP(graph); + + SET_POLY_OPA_DISP(game_play_set_fog(play, NOW_POLY_OPA_DISP)); + SET_POLY_XLU_DISP(game_play_set_fog(play, NOW_POLY_XLU_DISP)); + + + CLOSE_DISP(graph); +} + +void setupViewer(GAME_PLAY* play) { + + showView(&play->view, 0xF); +} + +void setupViewMatrix(GAME_PLAY* play, GRAPH* graph1, GRAPH* graph2){ + Mtx* t; + + OPEN_DISP(graph1); + + + Matrix_MtxtoMtxF(&play->view.mtx_viewing, &play->billboard_matrix); + Matrix_MtxtoMtxF(&play->view.mtx_projection, &play->projection_matrix); + Skin_Matrix_MulMatrix(&play->projection_matrix, &play->billboard_matrix, &play->projection_matrix); + + play->billboard_matrix.mf[0][3] = 0.0f; + play->billboard_matrix.mf[1][3] = 0.0f; + play->billboard_matrix.mf[2][3] = 0.0f; + play->billboard_matrix.mf[3][0] = 0.0f; + play->billboard_matrix.mf[3][1] = 0.0f; + play->billboard_matrix.mf[3][2] = 0.0f; + + Matrix_reverse(&play->billboard_matrix); + + t = _MtxF_to_Mtx(&play->billboard_matrix, GRAPH_ALLOC(graph2, sizeof(MtxF) * 1)); + play->_208C = t; + + gSPSegment(NEXT_BG_OPA_DISP, 7, play->_208C); + gSPSegment(NEXT_POLY_OPA_DISP, 7, play->_208C); + + + CLOSE_DISP(graph1); +} + + void copy_efb_to_texture(Gfx** graph, void* buf){ + u32 dl; + + GXBeginDisplayList(gxbuf, sizeof(gxbuf)); + GXSetTexCopySrc(0,0,SCREEN_WIDTH * 2,SCREEN_HEIGHT * 2); + GXSetTexCopyDst(SCREEN_WIDTH * 2, SCREEN_HEIGHT *2, GX_TF_RGB565, 0); + GXSetCopyFilter(0,0,0,0); + GXCopyTex(buf, 0); + dl = GXEndDisplayList(); + gGXCallDisplayList((*graph)++, gxbuf ,dl); + } + +int makeBumpTexture(GAME_PLAY* play, GRAPH* graph1, GRAPH* graph2){ + + Gfx* newdisp; + Gfx* polydisp; + Gfx* rect_disp; + View* v; + Gfx* fbdemo_disp; + Gfx* fb_disp; + Gfx* old_fb; + Gfx* poly; + View view; + rect rect; + + OPEN_DISP(graph1); + + if((GETREG(HREG, 80) != 10) || (GETREG(HREG, 92) != 0)){ + + newdisp = NOW_POLY_OPA_DISP; + polydisp = gfxopen(newdisp); + + gSPDisplayList(NEXT_OVERLAY_DISP, polydisp); + + if(play->fb_wipe_mode == 3){ + v = &view; + initView(v, graph2); + v->flag = 10; + rect.top = 0; + rect.bottom = SCREEN_HEIGHT; + rect.l = 0; + rect.r = SCREEN_WIDTH; + setScissorView(v, &rect); + showView1(v, 15, &polydisp); + play->fbdemo_wipe.wipe_procs.draw_proc(&play->fbdemo_wipe.wipe_data, &polydisp); + } + + fbdemo_fade_draw(&play->color_fade, &polydisp); + fade_rgba8888_draw(&polydisp, play->fade_color_value); + + gSPEndDisplayList(polydisp++); + + gfxclose(newdisp, polydisp); + + SET_POLY_OPA_DISP(polydisp); + } + + if(play->fb_mode == 3){ + fbdemo_disp = NOW_POLY_OPA_DISP; + fbdemo_draw(&fbdemo, &fbdemo_disp); + SET_POLY_OPA_DISP(fbdemo_disp); + return 1; + } + + if(play->submenu.mode == 2){ + play->submenu.mode = 3; + SETREG(SREG, 3, -(GETREG(SREG, 3))); + } + else if(play->submenu.mode >= 5){ + play->submenu.mode = 0; + } + + if(play->submenu.mode == 3){ + poly = NOW_POLY_OPA_DISP; + + gDPPipeSync(poly++); + rect_disp = gfx_rect_moji(poly++); + gDPSetOtherMode(rect_disp++, G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | + G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_COPY | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2); + gDPSetTextureImage_Dolphin(rect_disp++, G_IM_FMT_I, G_IM_SIZ_16b, 480, 640, prbuf); + gDPSetTile_Dolphin(rect_disp++, G_DOLPHIN_TLUT_DEFAULT_MODE, 0, 0, 0, 0, 0, 0); + gSPTextureRectangle(rect_disp++, 0, 0, (640-1) << 2, (480-1) << 2, G_TX_RENDERTILE, 0, 0, (256) << 2, (256) << 2); + + SET_POLY_OPA_DISP(rect_disp); + return 1; + } + + if((GETREG(HREG, 80) != 10) || (GETREG(HREG, 85) != 0)){ + Actor_info_draw_actor(play, &play->actor_info); + Camera2_draw(play); + mMsg_Draw(play); + } + + if((GETREG(HREG, 80) != 10) || (GETREG(HREG, 93) != 0)){ + Debug_Display_output(play); + } + + if((play->submenu.mode == 1) || (play->fb_mode == 1)){ + + old_fb = NOW_POLY_OPA_DISP; + fb_disp = gfxopen(old_fb); + + gSPDisplayList(NEXT_LIGHT_DISP, fb_disp); + copy_efb_to_texture(&fb_disp, &prbuf); + gSPEndDisplayList(fb_disp++); + + gfxclose(old_fb, fb_disp); + + SET_POLY_OPA_DISP(fb_disp); + + if(play->submenu.mode == 1){ + play->submenu.mode = 2; + SETREG(SREG, 3, -(GETREG(SREG, 3))); + } + else { + play->fb_mode = 2; + } + return 1; + } + return 1; + CLOSE_DISP(graph1); +} + +void draw_version(GRAPH*) { + JW_JUTReport(0x82, 0x172, 1, "[CopyDate:%.19s]", boot_copyDate); + JW_JUTReport(0x82, 0x180, 1, "[Date:%s]" , &__DateTime__); + JW_JUTReport(0x82, 0x18E, 1, "[Creator:%s]", &__Creator__); +} + +void Game_play_draw(GAME* game){ + GRAPH* graph = game->graph; + GAME_PLAY* play = (GAME_PLAY*)game; + + + DisplayList_initialize(graph, 0,0,0,&play->game); + + if((GETREG(HREG, 80) != 10) || (GETREG(HREG, 82) != 0)){ + + setupFog(play, graph); + setupViewer(play); + setupViewMatrix(play, graph, graph); + + if((makeBumpTexture(play, graph, graph) == 1) && ((GETREG(HREG, 80) != 10) || (GETREG(HREG, 89) != 0))){ + + watch_my_step_draw(play); + banti_draw(play); + mSM_submenu_draw(&play->submenu, play); + } + } + if (zurumode_flag != 0) { + switch (mEv_CheckTitleDemo()) { + case -9: + case -1: + default: + draw_version(graph); + break; + + case 0: + break; + } + } +} + +void play_main(GAME* game) { + GAME_PLAY* play = (GAME_PLAY*)game; + + GRAPH* graph; + + game->doing_point = 0; + game->doing_point_specific = 0x6E; + fqrand(); + game->doing_point = 0; + game->doing_point_specific = 0x78; + mCon_main(game); + game->doing_point = 0; + game->doing_point_specific = 0x82; + Debug_Display_init(); + + if((GETREG(HREG, 80) == 10) && (GETREG(HREG, 94) != 10)){ + SETREG(HREG, 81,1); + SETREG(HREG, 82,1); + SETREG(HREG, 83,1); + SETREG(HREG, 84,3); + SETREG(HREG, 85,1); + SETREG(HREG, 86,1); + SETREG(HREG, 87,1); + SETREG(HREG, 88,1); + SETREG(HREG, 89,1); + SETREG(HREG, 90,15); + SETREG(HREG, 91,1); + SETREG(HREG, 92,1); + SETREG(HREG, 93,1); + SETREG(HREG, 94,10); + + } + + game->doing_point = 0; + game->doing_point_specific = 0x8C; + + if((GETREG(HREG, 80) != 10) || (GETREG(HREG, 81) != 0)){ + Game_play_move(play); + } + game->doing_point = 0; + game->doing_point_specific = 0xAA; + Game_play_draw(game); + + game->doing_point = 0; + game->doing_point_specific = 0xB4; + + graph = game->graph; + game_debug_draw_last(game, graph); + game_draw_last(graph); + + game->doing_point = 0; + game->doing_point_specific = 0XBe; +} + +void Gameplay_Scene_Init(GAME_PLAY* play){ + + play->player_data = NULL; + play->actor_data_num = 0; + play->ctrl_actor_data_num = 0; + play->obj_bank_data_num = 0; + play->_20A8 = 0; + + mSc_data_bank_ct(play, &play->object_exchange); + Global_light_ct(&play->global_light); + Door_info_ct(&play->door_data); + common_data_clear(); + Scene_ct(play, play->current_scene_data); + mSc_decide_exchange_bank(&play->object_exchange); + +} + +u8 mPl_SceneNo2SoundRoomType(int scene) { + switch (scene) { + case 20: + return 1; + + case 6: + case 9: + case 12: + case 14: + case 18: + case 21: + case 31: + case 41: + case 51: + return 2; + + case 22: + case 23: + case 24: + case 25: + case 29: + case 40: + case 47: + case 17: + return 3; + + default: + return 0; + } +} + +void Gameplay_Scene_Read(GAME_PLAY* play, s16 idx){ + static Scene_status_c* scene_word_data[SCENE_NUM] = { + &test01_info, + &test02_info, + &test03_info, + &water_test_info, + &test_step01_info, + &test04_info, + &npc_room01_info, + &test_fd_npc_land_info, + &field_tool_field_info, + &shop01_info, + &BG_TEST01_info, + &BG_TEST01_XLU_info, + &broker_shop_info, + &fg_tool_in_info, + &post_office_info, + &start_demo1_info, + &start_demo2_info, + &police_box_info, + &buggy_info, + &player_select_info, + &player_room_s_info, + &player_room_m_info, + &player_room_l_info, + &shop02_info, + &shop03_info, + &shop04_1f_info, + &test05_info, + &PLAYER_SELECT2_info, + &PLAYER_SELECT3_info, + &shop04_2f_info, + &event_notification_info, + &kamakura_info, + &field_tool_field_info, + &title_demo_info, + &PLAYER_SELECT4_info, + &museum_entrance_info, + &museum_picture_info, + &museum_fossil_info, + &museum_insect_info, + &museum_fish_info, + &player_room_ll1_info, + &player_room_ll2_info, + &p_room_bm_s_info, + &p_room_bm_m_info, + &p_room_bm_l_info, + &p_room_bm_ll1_info, + &NEEDLEWORK_info, + &player_room_island_info, + &npc_room_island_info, + &start_demo3_info, + &lighthouse_info, + &tent_info, + }; + + Scene_status_c* current = &scene_data_status[idx]; + + current->unk13 = 0; + play->scene_data_2400 = current; + play->scene_id = idx; + play->current_scene_data = scene_word_data[idx]; + current->unk13 = 0; + Gameplay_Scene_Init(play); + sAdo_RoomType(mPl_SceneNo2SoundRoomType(Save_Get(scene_no))); + +} \ No newline at end of file diff --git a/rel/m_post_office.c b/rel/m_post_office.c index dac9dbcd..de5390b0 100644 --- a/rel/m_post_office.c +++ b/rel/m_post_office.c @@ -14,6 +14,7 @@ #include "m_play.h" #include "libultra/libultra.h" #include "m_common_data.h" +#include "m_scene_table.h" static int mPO_keep_contents(Mail_c* mail) { int res = FALSE; diff --git a/rel/m_random_field.c b/rel/m_random_field.c index bc08dd4b..4b45e58e 100644 --- a/rel/m_random_field.c +++ b/rel/m_random_field.c @@ -4,7 +4,7 @@ #include "m_collision_bg.h" #include "m_field_info.h" #include "m_common_data.h" -#include "m_scene.h" +#include "m_scene_table.h" extern void mRF_MakeRandomField(mFM_combination_c* combi_table, mFM_combo_info_c* combo_info, int combo_count, GAME* game) { mRF_MakeRandomField_ovl(combi_table, combo_info, combo_count, game); diff --git a/rel/m_select.c b/rel/m_select.c index 04dfaf89..43ca8c45 100644 --- a/rel/m_select.c +++ b/rel/m_select.c @@ -6,7 +6,7 @@ #include "m_kabu_manager.h" #include "m_font.h" #include "m_time.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "m_controller.h" #include "m_kankyo.h" #include "audio.h" diff --git a/rel/m_start_data_init.c b/rel/m_start_data_init.c index 3ce3e60d..5d9177d6 100644 --- a/rel/m_start_data_init.c +++ b/rel/m_start_data_init.c @@ -7,7 +7,7 @@ #include "m_font.h" #include "m_field_info.h" #include "m_field_make.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "libultra/libultra.h" #include "m_cockroach.h" #include "m_melody.h" diff --git a/rel/m_titledemo.c b/rel/m_titledemo.c index 9ea77864..c94eb7e4 100644 --- a/rel/m_titledemo.c +++ b/rel/m_titledemo.c @@ -40,7 +40,7 @@ extern int mTD_demono_get() { return S_now_demono; } -static void mTD_player_keydata_init(GAME_PLAY* play) { +extern void mTD_player_keydata_init(GAME_PLAY* play) { PLAYER_ACTOR* player = get_player_actor_withoutCheck(play); if (mEv_CheckTitleDemo() > 0) { diff --git a/rel/m_trademark.c b/rel/m_trademark.c index 364e4718..6c2d4067 100644 --- a/rel/m_trademark.c +++ b/rel/m_trademark.c @@ -1,6 +1,6 @@ #include "m_trademark.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "m_name_table.h" #include "m_npc.h" #include "m_kankyo.h" diff --git a/rel/m_watch_my_step.c b/rel/m_watch_my_step.c index adc0e001..a70085a8 100644 --- a/rel/m_watch_my_step.c +++ b/rel/m_watch_my_step.c @@ -16,7 +16,7 @@ #include "m_room_type.h" #include "m_msg.h" #include "audio.h" -#include "m_scene.h" +#include "m_scene_table.h" #include "m_private.h" typedef struct watch_my_step_s { diff --git a/src/version.c b/src/version.c index e8a523c0..8360da8d 100644 --- a/src/version.c +++ b/src/version.c @@ -1,10 +1,10 @@ -#include "types.h" +#include "version.h" -u8 __Creator__[] = { +char __Creator__[] = { #include "assets/__Creator__.inc" }; -u8 __DateTime__[] = { +char __DateTime__[] = { #include "assets/__DateTime__.inc" }; From 269cd5ef88d9f3ac8d2f65871f003c5fb56dca34 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Sat, 9 Sep 2023 15:07:18 +0200 Subject: [PATCH 3/5] link famicom_emu --- config/rel_slices.yml | 4 + config/symbols.yml | 1 + include/Famicom/famicom.h | 6 + include/audio.h | 2 +- include/famicom_emu.h | 12 +- include/jaudio_NES/game64.h | 2 +- include/jsyswrap.h | 13 ++ include/libc64/sprintf.h | 6 + include/m_common_data.h | 8 +- include/m_scene.h | 3 + rel/audio.c | 2 +- rel/famicom_emu.c | 256 ++++++++++++++++++++++++++++++++++++ src/libc64/sprintf.c | 3 + 13 files changed, 311 insertions(+), 7 deletions(-) create mode 100644 include/libc64/sprintf.h create mode 100644 rel/famicom_emu.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index fa3d5813..d518201c 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -362,6 +362,10 @@ save_menu.c: .text: [0x8062CA5C, 0x8062D39C] .rodata: [0x8064D1F8, 0x8064D318] .data: [0x806D4B80, 0x806D4B98] +famicom_emu.c: + .text: [0x8062D39C, 0x8062D8FC] + .data: [0x806D4B98, 0x806D4CB0] + .bss: [0x8148DA68, 0x8148DA78] m_prenmi.c: .text: [0x8062D8FC, 0x8062DC04] .rodata: [0x8064D318, 0x8064D340] diff --git a/config/symbols.yml b/config/symbols.yml index 89179927..df056c81 100644 --- a/config/symbols.yml +++ b/config/symbols.yml @@ -3335,6 +3335,7 @@ global: 0x801ef128: FREE_SEQP_QUEUE 0x801ef580: commentImageBuffer 0x801f4dc4: famicomCommon + 0x801f4dc0: save_game_image 0x801f4e7c: famicomCommonSave 0x801f683c: nesrom_filename_ptrs 0x801f6840: nesrom_filename_strbuf diff --git a/include/Famicom/famicom.h b/include/Famicom/famicom.h index eff1fece..98e7cdcf 100644 --- a/include/Famicom/famicom.h +++ b/include/Famicom/famicom.h @@ -70,11 +70,17 @@ typedef struct famicom_common_s { extern void* my_malloc_current; +extern u8 save_game_image; typedef u8 (*FAMICOM_GETSAVECHAN_PROC)(int* player_no, int* slot_card_result); extern void famicom_setCallback_getSaveChan(FAMICOM_GETSAVECHAN_PROC getSaveChan_proc); extern int famicom_mount_archive(); extern int famicom_mount_archive_end_check(); +extern int famicom_rom_load_check(); +extern int famicom_1frame(); +extern int famicom_init(int, void*, u8); +extern int famicom_cleanup(); + #ifdef __cplusplus } diff --git a/include/audio.h b/include/audio.h index 9a3134a1..5fe96d79 100644 --- a/include/audio.h +++ b/include/audio.h @@ -73,7 +73,7 @@ extern void sAdo_BgmCrossfadeStart(u8 b); extern void sAdo_SubGameStart(); extern void sAdo_SubGameEnd(); -extern u8 sAdo_SubGameOK(); +extern int sAdo_SubGameOK(); extern void sAdo_Tenki(u8 mode); diff --git a/include/famicom_emu.h b/include/famicom_emu.h index 60ad768a..242feea9 100644 --- a/include/famicom_emu.h +++ b/include/famicom_emu.h @@ -15,8 +15,16 @@ typedef struct game_famicom_emu_s { extern void* my_malloc_func[]; -extern void famicom_emu_init(GAME_FAMICOM_EMU* famicom_emu); -extern void famicom_emu_cleanup(GAME_FAMICOM_EMU* famicom_emu); +void my_alloc_cleanup(); +void my_zelda_getmemblocksize(void *); +void my_zelda_gettotalfreesize(); +void* my_zelda_malloc_align(size_t, u32); +void my_zelda_free(void *); +void famicom_emu_main(GAME *); +void famicom_emu_init(GAME_FAMICOM_EMU *); +void famicom_emu_cleanup(GAME *); +int famicom_gba_getImage(u32, int *); +void famicom_gba_removeImage(void *); #ifdef __cplusplus } diff --git a/include/jaudio_NES/game64.h b/include/jaudio_NES/game64.h index b6b3e8e7..624fbcf2 100644 --- a/include/jaudio_NES/game64.h +++ b/include/jaudio_NES/game64.h @@ -36,7 +36,7 @@ extern void Na_MDPlayerPos(u16,u16,u16,int, f32); extern void Na_BGMVolume(f32,u16); extern void Na_SubGameStart(); extern void Na_SubGameEnd(); -extern int Na_SubGameOK(); +extern u8 Na_SubGameOK(); extern void Na_Tenki(u8); extern void Na_KishaStatusTrg(u8); extern void Na_KishaStatusLevel(f32 speed, u32 ongenNum1, u16 angle1, f32 distance1, u32 ongenNum2, u16 angle2, f32 distance2); diff --git a/include/jsyswrap.h b/include/jsyswrap.h index 47509eb2..801e9c9c 100644 --- a/include/jsyswrap.h +++ b/include/jsyswrap.h @@ -2,12 +2,25 @@ #define JSYSWRAP_H #include "types.h" +#include "dolphin/gx.h" #ifdef __cplusplus extern "C" { #endif extern void JW_JUTReport(int pos_x, int pos_y, int show_count, const char* fmt, ...); +extern void JC_JFWDisplay_startFadeOut(void*, int); +extern void* JC_JFWDisplay_getManager(); +extern void JC_JFWDisplay_clearEfb(void*, GXColor*); +extern GXRenderModeObj* JC_JFWDisplay_getRenderMode(void*); +extern void* JC_JFWDisplay_changeToSingleXfb(void*, int); + +extern void JC_JFWDisplay_startFadeIn(void*, int); +extern void JC_JFWDisplay_changeToDoubleXfb(void*); +extern u32 JC__JKRGetResource(char*); +extern int JC__JKRGetMemBlockSize(int, u32); + +extern void JC__JKRRemoveResource(void*); #ifdef __cplusplus } diff --git a/include/libc64/sprintf.h b/include/libc64/sprintf.h new file mode 100644 index 00000000..34c9fc3a --- /dev/null +++ b/include/libc64/sprintf.h @@ -0,0 +1,6 @@ +#ifndef SPRINTF_H +#define SPRINTF_H + +s32 sprintf(char* dst, const char* fmt, ...); + +#endif \ No newline at end of file diff --git a/include/m_common_data.h b/include/m_common_data.h index 6a0a884d..7af759ee 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -202,7 +202,10 @@ typedef struct common_data_s { /* 0x0285C0 */ s8 player_decoy_flag; /* 0x0285C1 */ u8 _285C1[0x0285C6 - 0x0285C1]; /* 0x0285C6 */ u8 event_id; - /* 0x0285C7 */ u8 _285C3[0x028838 - 0x0285C7]; + /* 0x0285C7 */ u8 _285C3[0x0287F8 - 0x0285C7]; + /* 0x0287F8 */ s8 current_famicom_rom; + /* 0x0287F9 */ s8 famicom_287F9; + /* 0x0287FA */ u8 _287FA[0x28838 - 0x0287FA]; /* 0x028838 */ s8 player_bee_swell_flag; /* 0x028839 */ s8 player_bee_chase_flag; /* 0x02883A */ u8 goki_shocked_flag; @@ -249,7 +252,8 @@ typedef struct common_data_s { /* 0x02DB40 */ u8 auto_nwrite_set; /* when true, saved nwrite time will be utilized. Seems to be used to keep same date for fishing tourney stuff. */ /* 0x02DB42 */ u16 select_last_select_no; /* 0x02DB44 */ u16 select_last_top_no; - /* 0x02DB46 */ u8 tmp3[0x2DBB0 - 0x2DB46]; + /* 0x02DB46 */ u8 tmp3[0x2DBAC - 0x2DB46]; + /* 0X02DBAC */ int famicom_2DBAC; /* 0x02DBB0 */ s16 can_look_goki_count; /* 0x02DBB4 */ f32 rainbow_opacity; /* current opacity of rainbow (0.0f - 1.0f) */ /* 0x02DBB8 */ u32 event_flags[7]; /* TODO: make array size a definition/enum */ diff --git a/include/m_scene.h b/include/m_scene.h index ab67bdbd..f3ff2ae8 100644 --- a/include/m_scene.h +++ b/include/m_scene.h @@ -3,6 +3,7 @@ #include "types.h" #include "m_lib.h" +#include "famicom_emu.h" #ifdef __cplusplus extern "C" { @@ -103,6 +104,8 @@ extern void mSc_data_bank_ct(GAME_PLAY*, Object_Exchange_c*); extern void Door_info_ct(Door_data_c**); extern void Scene_ct(GAME_PLAY*, void*); extern void mSc_decide_exchange_bank(Object_Exchange_c*); +extern void return_emu_game(GAME*); + #ifdef __cplusplus } diff --git a/rel/audio.c b/rel/audio.c index c562f2cb..33707972 100644 --- a/rel/audio.c +++ b/rel/audio.c @@ -281,7 +281,7 @@ extern void sAdo_SubGameEnd(){ Na_SubGameEnd(); } -extern u8 sAdo_SubGameOK(){ +extern int sAdo_SubGameOK(){ return Na_SubGameOK(); } diff --git a/rel/famicom_emu.c b/rel/famicom_emu.c new file mode 100644 index 00000000..e43e63bb --- /dev/null +++ b/rel/famicom_emu.c @@ -0,0 +1,256 @@ + +#include "famicom_emu.h" + +#include "m_malloc.h" +#include "_mem.h" +#include "dolphin/gx.h" +#include "Famicom/famicom.h" +#include "m_scene.h" +#include "jsyswrap.h" +#include "m_common_data.h" +#include "m_debug.h" +#include "libc64/sprintf.h" + +int famicom_done; +int famicom_done_countdown; +void* freeXfbBase; +u32 freeXfbSize; + +void* my_malloc_func[] = { + my_zelda_malloc_align, + my_zelda_free, + my_zelda_getmemblocksize, + my_zelda_gettotalfreesize, +}; + + + +void my_alloc_init(GAME_FAMICOM_EMU* famicom, void* start, size_t size){ + + u32 freebytes; + u32 alloc; + u32 aligned; + u32 tsize; + + freebytes = game_getFreeBytes(&famicom->game); + alloc = (u32)THA_alloc16(&famicom->game.tha, freebytes); + aligned = ALIGN_NEXT(alloc, 16); + tsize = aligned - alloc; + + zelda_InitArena((void*)aligned, freebytes - tsize); + + if((start != NULL) && (size != 0)){ + + zelda_AddBlockArena(start, size); + } + +} + +void my_alloc_cleanup(){ + + zelda_CleanupArena(); +} + +void my_zelda_getmemblocksize(void* ptr){ + + zelda_GetMemBlockSize(ptr); +} + +void my_zelda_gettotalfreesize(){ + + zelda_GetTotalFreeSize(); +} + +void* my_zelda_malloc_align(size_t size, u32 align){ + + void* aligned = zelda_malloc_align(size, align); + + if(aligned != NULL){ + + memset(aligned, 0xFF, size); + } + return aligned; +} + +void my_zelda_free(void* ptr){ + + zelda_free(ptr); +} +#pragma pool_data off + +void famicom_emu_main(GAME* famicom){ + static GXColor black_color = {0,0,0,0}; + GXColor t; + int i; + int padid; + pad_t* current_pad; + u32 combo; + void* manager; + + if(famicom_done == 0){ + if(famicom_rom_load_check() < 0){ + Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 1); + famicom_done = 1; + famicom_done_countdown = 0; + } + else{ + for(padid = 0,i = 4; i != 0; i--, padid++){ + + current_pad = &gamePT->pads[padid]; + combo = current_pad->now.button | current_pad->on.button; + + if(combo == (BUTTON_Z | BUTTON_R | BUTTON_L) || (combo == 0xF0)){ + + famicom_done = 1; + famicom_done_countdown = 60; + JC_JFWDisplay_startFadeOut(JC_JFWDisplay_getManager(), famicom_done_countdown); + break; + } + } + } + } + if (famicom_done != 0) { + if ( famicom_done_countdown == 0) { + return_emu_game(famicom); + } else { + famicom_done_countdown -= 1; + } + } + + JW_BeginFrame(); + famicom->disable_display = 1; + + if(famicom_done == 0){ + + famicom_1frame(); + } + else{ + manager = JC_JFWDisplay_getManager(); + t = black_color; + JC_JFWDisplay_clearEfb(manager, &t); + } + JW_EndFrame(); +} + +#pragma pool_data on + + +void famicom_emu_init(GAME_FAMICOM_EMU* famicom){ + + int rom_id; + u8 player; + int debug; + void* manager; + GXRenderModeObj* render; + + famicom_done = 0; + famicom_done_countdown = 0; + game_resize_hyral(&famicom->game, 0); + Common_Set(famicom_287F9, 0); + + rom_id = Common_Get(current_famicom_rom); + player = Common_Get(player_no); + save_game_image = (GETREG(HREG, 4) == 1); + debug = GETREG(HREG,3); + + if((rom_id > 0) && ( debug != 0)){ + rom_id = debug & (-debug & ~debug) >> 0x1f; + } + + famicom->game.exec = famicom_emu_main; + famicom->game.cleanup = famicom_emu_cleanup; + + + while(sAdo_SubGameOK() == 0){ + VIWaitForRetrace(); + sAdo_GameFrame(); + } + + manager = JC_JFWDisplay_getManager(); + render = JC_JFWDisplay_getRenderMode(manager); + freeXfbBase = JC_JFWDisplay_changeToSingleXfb(manager, 1); + freeXfbSize = render->efbHeight * render->viXOrigin * sizeof(u16); + + my_alloc_init(famicom, freeXfbBase, freeXfbSize); + + if(famicom_init(rom_id, my_malloc_func, player) != 0){ + Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 1); + return_emu_game(&famicom->game); + } +} + + +void famicom_emu_cleanup(GAME*){ + + JC_JFWDisplay_startFadeIn(JC_JFWDisplay_getManager(), 1); + + if(famicom_cleanup() != 0){ + + Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 2); + } + + my_alloc_cleanup(); + + if(freeXfbBase != NULL){ + + JC_JFWDisplay_changeToDoubleXfb(JC_JFWDisplay_getManager()); + freeXfbBase = NULL; + freeXfbSize = 0; + } + sAdo_SubGameEnd(); +} + +int famicom_gba_getImage(u32 rom_id, int* ptr){ + static char* names[] = { + "cluclu", + "usa_balloon", + "donkey", + "usa_jr_math", + "pinball", + "tennis", + "usa_golf", + NULL, + "usa_baseball", + NULL, + "usa_donkey3", + "donkeyjr", + "soccer", + "exbike", + NULL, + "usa_icecl", + "mario", + "smario", + NULL + }; + + char buf[256]; + u32 resource; + int block; + char* rom; + + + if(rom_id > 0x13){ + return 0; + } + + + rom = names[(rom_id == 0) ? 0 : rom_id -1]; + + if(rom == NULL){ + return 0; + } + else{ + sprintf(buf, "/FAMICOM/GBA/jb_%s.bin.szs", rom); + resource = JC__JKRGetResource(buf); + if((resource != 0) && (ptr != NULL)){ + block = JC__JKRGetMemBlockSize(0, resource); + *ptr = block; + } + } + return resource; +} + +void famicom_gba_removeImage(void* p){ + + JC__JKRRemoveResource(p); +} \ No newline at end of file diff --git a/src/libc64/sprintf.c b/src/libc64/sprintf.c index 338d7f40..c81ad969 100644 --- a/src/libc64/sprintf.c +++ b/src/libc64/sprintf.c @@ -1,6 +1,9 @@ +#include "libc64/sprintf.h" + #include "libultra/xprintf.h" #include "_mem.h" + static void* proutPrintf(void* dst, const char* fmt, size_t size) { return (void*)((u8*)memcpy(dst, fmt, size) + size); } From 59544e5ebe9052629e714fd273dd0d6b5fcb2bdb Mon Sep 17 00:00:00 2001 From: Prakxo Date: Sat, 9 Sep 2023 17:31:13 +0200 Subject: [PATCH 4/5] link m_actor_shadow --- config/rel_slices.yml | 4 + include/m_actor.h | 18 +- include/m_actor_shadow.h | 35 ++++ include/m_collision_bg.h | 1 + include/m_kankyo.h | 7 +- rel/ac_airplane.c | 1 + rel/m_actor_shadow.c | 411 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 473 insertions(+), 4 deletions(-) create mode 100644 include/m_actor_shadow.h create mode 100644 rel/m_actor_shadow.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index d518201c..c6df974f 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -25,6 +25,10 @@ m_actor_dlftbls.c: .text: [0x8037619C, 0x803761BC] .data: [0x8064D628, 0x8064F4E8] .bss: [0x8125A828, 0x8125A830] +m_actor_shadow.c: + .text: [0x803761BC, 0x80377114] + .rodata: [0x80641328, 0x80641388] + .data: [0x8064F4E8, 0x8064F548] m_banti.c: .text: [0x80377114, 0x80378858] .rodata: [0x80641388, 0x806413E0] diff --git a/include/m_actor.h b/include/m_actor.h index 6527c19e..a905e5d4 100644 --- a/include/m_actor.h +++ b/include/m_actor.h @@ -339,6 +339,22 @@ typedef struct actor_shape_info_s { /* 0x2F */ u8 unused_2F[0x48-0x2F]; } Shape_Info; +typedef struct actor_shadow_s{ + /* 0x00 */ xyz_t position; + /* 0x0C */ f32 groundY; + /* 0x10 */ f32 unk10; + /* 0x14 */ f32 unk14; + /* 0x18 */ f32 unk18; + /* 0x1C */ f32 unk1C; + /* 0x20 */ s16 unk20; + /* 0x22 */ s16 unk22; + /* 0x24 */ s16 unk24; + /* 0x26 */ s16 unk26; + /* 0x28 */ char pad28[0xC]; + /* 0x34 */ int unk34; + /* 0x38 */ int kind; +}Shadow_Info; + /* sizeof(struct actor_s) == 0x174 */ struct actor_s { /* 0x000 */ s16 id; /* unique actor type ID */ @@ -446,8 +462,6 @@ extern Hilite* HiliteReflect_xlu_init(xyz_t* pos, xyz_t* eye, xyz_t* light_direc extern void Setpos_HiliteReflect_init(xyz_t* pos, GAME_PLAY* play); extern void Setpos_HiliteReflect_xlu_init(xyz_t* pos, GAME_PLAY* play); -extern void mAc_ActorShadowCircle(ACTOR* actor, LightsN* lightsN, GAME_PLAY* play); -extern void mAc_ActorShadowEllipse(ACTOR* actor, LightsN* lightsN, GAME_PLAY* play); #ifdef __cplusplus } diff --git a/include/m_actor_shadow.h b/include/m_actor_shadow.h new file mode 100644 index 00000000..c3329259 --- /dev/null +++ b/include/m_actor_shadow.h @@ -0,0 +1,35 @@ +#ifndef M_ACTOR_SHADOW_H +#define M_ACTOR_SHADOW_H + +#include "types.h" +#include "m_actor.h" + +int mActorShadow_OperateScrollLimit(int, int, int); +Gfx* mActorShadow_TileScroll2(u32 *, u32 *, int, int, int, int, int, int, u32 *, u32 *, int, int, int, int, int, int, GAME *); +void mActorShadow_AdjustRate(f32 *); +void mActorShadow_GetTimeAngleY_TimeAlpha(Shadow_Info *, GAME_PLAY *); +void mActorShadow_GetGroundAverageAngle(Shadow_Info *); +void mActorShadow_GetDistanceRate(Shadow_Info *, f32); +f32 mActorShadow_GetAbsBigger(f32, f32); +void mActorShadow_RadiusScaleRate(ACTOR *, Shadow_Info *); +void mActorShadow_GetShadowTopPos_GetSlideS(Shadow_Info *); +Gfx* mActorShadow_SetTexScroll(ACTOR *, Shadow_Info *, GAME *); +void mActorShadow_GetLastAlphaScale(f32 *, u8 *, ACTOR *, Shadow_Info *); +void mActorShadow_DrawActorShadow(ACTOR *, Shadow_Info *, GAME_PLAY *, int, xyz_t, f32); +void mActorShadow_GetShadowPosition(ACTOR *, xyz_t *); +int mActorShadow_GetShadowKind(void); +f32 mAc_GetShadowGroundY_NoneForce(const Shadow_Info *); +f32 mAc_GetShadowGroundY_Force(const Shadow_Info *); +void mAc_DecideShadowRadius_IamNotFish(Shadow_Info *, ACTOR *, f32 *); +void mAc_DecideShadowRadius_IamFish(Shadow_Info *, ACTOR *, f32 *); +void mAc_ActorShadowDraw_ShadowDrawFlagOff(ACTOR *, GAME_PLAY *, int, xyz_t, f32); +void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR *, GAME_PLAY *, int, xyz_t, f32); +void mAc_ActorShadowDraw(ACTOR *, GAME_PLAY *, int, xyz_t, f32); +void mActorShadow_SetForceShadowPos(ACTOR *, xyz_t *); +void mActorShadow_UnSetForceShadowPos(ACTOR *); +void mAc_NormalActorShadow(ACTOR *, GAME_PLAY *, f32); +void mAc_UnagiActorShadow(ACTOR *, GAME_PLAY *, xyz_t); +void mAc_ActorShadowCircle(ACTOR *, LightsN *, GAME_PLAY *); +void mAc_ActorShadowEllipse(ACTOR *, LightsN *, GAME_PLAY *); + +#endif diff --git a/include/m_collision_bg.h b/include/m_collision_bg.h index 9d20ac3f..024c0b0b 100644 --- a/include/m_collision_bg.h +++ b/include/m_collision_bg.h @@ -106,6 +106,7 @@ extern u32 mCoBG_Wpos2BgAttribute_Original(xyz_t wpos); extern u32 mCoBG_Wpos2Attribute(xyz_t wpos, char* is_diggable); extern int mCoBG_CheckWaterAttribute(u32 attribute); extern f32 mCoBG_GetBgY_AngleS_FromWpos(s_xyz* angle_to_ground, xyz_t wpos, f32 offset_y); +extern f32 mCoBG_GetShadowBgY_AngleS_FromWpos(f32, s_xyz*, xyz_t); extern int mCoBG_CheckWaterAttribute_OutOfSea(u32 attribute); extern int mCoBG_CheckHole_OrgAttr(u32 attribute); extern f32 mCoBG_GetBgY_OnlyCenter_FromWpos2(xyz_t wpos, f32 foot_dist); diff --git a/include/m_kankyo.h b/include/m_kankyo.h index 28d68de4..edc17e16 100644 --- a/include/m_kankyo.h +++ b/include/m_kankyo.h @@ -3,6 +3,7 @@ #include "types.h" #include "m_lights.h" +#include "game.h" #ifdef __cplusplus extern "C" { @@ -38,7 +39,9 @@ typedef struct kankyo_s { /* 0x00 */ Lights sun_light; /* 0x0E */ u8 pad[0x9A - 0x0E]; /* 0x9A */ u8 ambientColor[3]; - /* 0x9E */ u8 pad2[0xC8 - 0x9E]; + /* 0x9E */ u8 pad2[0xC0 - 0x9E]; + /* 0xC0 */ f32 unkC0; + /* 0xC4 */ u8 unkC4; /* 0xC8 */ Nature nature; } Kankyo; @@ -47,7 +50,7 @@ extern int mEnv_NowWeather(); extern int mEnv_WindMove(); extern void mEnv_ManagePointLight(GAME_PLAY*, Kankyo*, Global_light*); extern void Global_kankyo_set(GAME_PLAY*, Kankyo*, Global_light*); - +extern void mEnv_GetShadowPrimColor_Light(u8*,u8*,u8*,GAME*); #ifdef __cplusplus } #endif diff --git a/rel/ac_airplane.c b/rel/ac_airplane.c index 3a7d374e..62d10e4d 100644 --- a/rel/ac_airplane.c +++ b/rel/ac_airplane.c @@ -10,6 +10,7 @@ #include "m_controller.h" #include "m_name_table.h" #include "m_common_data.h" +#include "m_actor_shadow.h" static void Airplane_Actor_ct(ACTOR* actor, GAME* game); static void Airplane_Actor_dt(ACTOR* actor, GAME* game); diff --git a/rel/m_actor_shadow.c b/rel/m_actor_shadow.c new file mode 100644 index 00000000..c2e118bd --- /dev/null +++ b/rel/m_actor_shadow.c @@ -0,0 +1,411 @@ +#include "m_actor_shadow.h" + +#include "m_collision_bg.h" +#include "m_common_data.h" +#include "m_rcp.h" +#include "sys_matrix.h" +#include "m_lib.h" +#include "m_lights.h" + + +extern Gfx ef_shadow_out_modelT[]; +extern Gfx ef_shadow_in_modelT[]; + + +int mActorShadow_OperateScrollLimit(int value, int step, int limit) { + if (step != 0) { + if (step > 0) { + value += step; + if (value > limit) { + value = limit; + } + } else if (step < 0) { + value += step; + if (value < limit) { + value = limit; + } + } + } + return value; +} + +Gfx* mActorShadow_TileScroll2(u32* x1, u32* y1, int step1, int step2, int limit1, int limit2, int width1, +int height1, u32* x2, u32* y2, int step3, int step4, int limit3, int limit4, +int width2, int height2, GAME* game){ + + + *x1 = mActorShadow_OperateScrollLimit(*x1, step1, limit1); + *y1 = mActorShadow_OperateScrollLimit(*y1, step2, limit2); + *x2 = mActorShadow_OperateScrollLimit(*x2, step3, limit3); + *y2 = mActorShadow_OperateScrollLimit(*y2, step4, limit4); + + return two_tex_scroll(game->graph, 0, *x1, *y1, width1, height1, 1, *x2, *y2, width2, height2); +} + + +void mActorShadow_AdjustRate(f32* rate) { + if (*rate < 0.0f) { + *rate = 0.0f; + } else if (*rate > 1.0f) { + *rate = 1.0f; + } +} + +void mActorShadow_GetTimeAngleY_TimeAlpha(Shadow_Info* shadow, GAME_PLAY* play){ + f32 timef; + int timesec = Common_Get(time.now_sec); + shadow->unk1C = play->kankyo.unkC4; + + // Between 4 a.m and 8 p.m + if((timesec >= 14400) && ( timesec < 72000)){ + timef = (timesec - 14400) / 57600.0f; + } //Between 12 a.m and 4 a.m + else if (timesec < 14400){ + timef = 0.5f + timesec / 28800.0f; + } // Between 8 p.m and 12 a.m + else{ + timef = (timesec - 72000)/ 28800.0f; + } + + shadow->unk26 = 0x8000 - ((s16)(16384.0f * timef) + 0x6000); +} + + +void mActorShadow_GetGroundAverageAngle(Shadow_Info* shadow){ + static xyz_t angle_range_table[4] = { + { 10.0f, 0.0f, 10.0f }, + { 10.0f, 0.0f, -10.0f }, + { -10.0f, 0.0f, 10.0f }, + { -10.0f, 0.0f, -10.0f }, + }; + + int x = 0; + int y = 0; + int z = 0; + int i; + + for (i = 0; i < 4; i++) { + xyz_t pos = shadow->position; + s_xyz sangle = {0, 0, 0}; + + pos.x += angle_range_table[i].x; + pos.y += angle_range_table[i].y; + pos.z += angle_range_table[i].z; + + mCoBG_GetBgY_AngleS_FromWpos(&sangle, pos, 0.0f); + + x += sangle.x; + y += sangle.y; + z += sangle.z; + } + + shadow->unk20 = x >> 2; + shadow->unk22 = y >> 2; + shadow->unk24 = z >> 2; +} + +void mActorShadow_GetDistanceRate(Shadow_Info* shadow, f32 rate) { + f32 xcalc; + f32 disty = shadow->position.y - shadow->groundY; + + disty = disty >= 0.0f ? disty : -disty; + xcalc = rate + 100.0f; + + if (disty > xcalc){ + shadow->unk14 = 0.600000023842f; + shadow->unk18 = 0; + return; + } + + xcalc = (xcalc - disty) / xcalc; + shadow->unk14 = xcalc * 0.399999976158f + 0.6f; + shadow->unk18 = xcalc; +} +f32 mActorShadow_GetAbsBigger(f32 a, f32 b) { + a = a >= 0.0f ? a : -a; + b = b >= 0.0f ? b : -b; + + if(a > b){ + return a; + } + return b; +} + +void mActorShadow_RadiusScaleRate(ACTOR* actor, Shadow_Info* shadow) { + f32 abs_bigger = mActorShadow_GetAbsBigger(actor->shape_info.shadow_size_x, actor->shape_info.shadow_size_z); + shadow->unk10 = (abs_bigger / 19.0f) * 0.018f; +} + +void mActorShadow_GetShadowTopPos_GetSlideS(Shadow_Info* shadow) { + + xyz_t wpos; + xyz_t base; + f32 bg_y; + int res; + + if (shadow->kind == 0) { + base.x = 0.0f; + base.y = 0.0f; + base.z = -40.0f; + sMath_RotateY(&base, shadow->unk26 * (9.58738019108e-05f)); + wpos.x = shadow->position.x + base.x; + wpos.y = shadow->position.y + base.y; + wpos.z = shadow->position.z + base.z; + res = 0; + bg_y = mCoBG_GetShadowBgY_AngleS_FromWpos(0.0f, NULL, wpos); + if ((shadow->position.y - bg_y) > 20.0f) { + shadow->unk34 = 28; + return; + } + } + shadow->unk34 = 0; +} + +Gfx* mActorShadow_SetTexScroll(ACTOR* actor, Shadow_Info* shadow, GAME* game){ + + u32 y1 = 0; + u32 x1 = 0; + u32 y2 = 0; + int step; + + if(actor->shape_info.unk_20 < shadow->unk34){ + step = 0xD; + } + else if(actor->shape_info.unk_20 > shadow->unk34){ + step = -0xD; + } + else{ + step = 0; + } + + mActorShadow_TileScroll2(&x1, &y1, 0, 0, 0, 0, 0x20, 0x10, (u32*)&actor->shape_info.unk_20, &y2, step, 0, shadow->unk34, 0, 0x20, 0x10, game); +} + + +void mActorShadow_GetLastAlphaScale(f32* scale, u8* alpha, ACTOR* actor, Shadow_Info* shadow) { + + f32 alph = shadow->unk1C * shadow->unk18 * actor->shape_info.shadow_alpha_change_rate * 0.75f; + + *scale = shadow->unk10 * shadow->unk14 * actor->shape_info.shadow_size_change_rate; + + if (shadow->kind == 1) { + alph *= 0.7f; + } + *alpha = alph; +} + + +void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* play, int id, xyz_t ofs, f32 rad) { + f32 x, y, z; + f32 y_adjust; + f32 scale; + u8 alpha; + u8 r, g, b; + int scene; + Gfx* texscroll; + GRAPH* graph; + GAME* game = (GAME*)play; + + + scene = Save_Get(scene_no); + + mActorShadow_GetLastAlphaScale(&scale, &alpha, actor, shadow); + graph = game->graph; + _texture_z_light_fog_prim_shadow(graph); + + OPEN_DISP(graph); + + y_adjust = (scene == 19 || scene == 27 || scene == 28 || scene == 34) ? 0.5f : + ((scene == 15 || scene == 16 || scene == 49) ? 0.6f : 2.0f); + + switch (actor->shape_info.force_shadow_position) { + case 1: + x = actor->shape_info.shadow_position->x + ofs.x; + y = actor->shape_info.shadow_position->y + y_adjust + ofs.y; + z = actor->shape_info.shadow_position->z + ofs.z; + Matrix_translate(x, y, z, 0); + break; + default: + x = shadow->position.x + ofs.x; + y = shadow->groundY + y_adjust + ofs.y; + z = shadow->position.z + ofs.z; + Matrix_translate(x, y, z, 0); + break; + } + + switch (actor->shape_info.force_shadow_position) { + case 1: + Matrix_RotateZ(0, 1); + Matrix_RotateX(0, 1); + break; + default: + Matrix_RotateZ(shadow->unk24, 1); + Matrix_RotateX(shadow->unk20, 1); + break; + } + + if ((shadow->kind == 0) && (id == 0)) { + Matrix_RotateY(shadow->unk26, 1); + } + + switch (id) { + case 1: + Matrix_scale(shadow->unk10, shadow->unk10, rad, 1); + break; + default: + switch (actor->shape_info.force_shadow_position) { + case 1: + Matrix_scale(shadow->unk10, shadow->unk10, shadow->unk10, 1); + break; + default: + Matrix_scale(scale, scale, scale, 1); + break; + } + break; + } + + gSPMatrix(NEXT_SHADOW_DISP, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + mEnv_GetShadowPrimColor_Light(&r, &g, &b, game); + gDPSetPrimColor(NEXT_SHADOW_DISP, 0, 0xFF, r, g, b, (u8)alpha); + + if ((shadow->kind == 0) && (id == 0)) { + texscroll = mActorShadow_SetTexScroll(actor, shadow, game); + if (texscroll != NULL) { + gSPSegment(NEXT_SHADOW_DISP, 0x08, texscroll); + gSPDisplayList(NEXT_SHADOW_DISP, ef_shadow_out_modelT); + } + } else { + gSPDisplayList(NEXT_SHADOW_DISP, ef_shadow_in_modelT); + } + + CLOSE_DISP(graph); + +} + +void mActorShadow_GetShadowPosition(ACTOR* actor, xyz_t* position){ + + if(actor->shape_info.shadow_position != NULL){ + *position = *actor->shape_info.shadow_position; + } + else { + *position = actor->world.position; + } +} + +int mActorShadow_GetShadowKind(void) { + if (!(mFI_GetFieldId() & 0xF000)) { + return 0; + } else { + return 1; + } +} + +f32 mAc_GetShadowGroundY_NoneForce(const Shadow_Info* shadow){ + f32 res = mCoBG_GetShadowBgY_AngleS_FromWpos(0.0f, NULL, shadow->position); + return res; +} + +f32 mAc_GetShadowGroundY_Force(const Shadow_Info* shadow){ + return mCoBG_GetBgY_OnlyCenter_FromWpos2(shadow->position, 0.0f); +} + +void mAc_DecideShadowRadius_IamNotFish(Shadow_Info* shadow, ACTOR* actor, f32* radius) { + mActorShadow_RadiusScaleRate(actor, shadow); + *radius = 0.01f; +} + +void mAc_DecideShadowRadius_IamFish(Shadow_Info* shadow, ACTOR* actor, f32* radius) { + shadow->unk10 = (actor->shape_info.shadow_size_x / 19.0f) * 0.018f; + *radius = (actor->shape_info.shadow_size_z / 19.0f) * 0.018f; +} + +void mAc_ActorShadowDraw_ShadowDrawFlagOff(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6){ + +} + +void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR* actor, GAME_PLAY* play, int proc, xyz_t pos, f32 rate){ + static void (*set_raius_proc[])(Shadow_Info*, ACTOR*, f32*) = { + mAc_DecideShadowRadius_IamNotFish, + mAc_DecideShadowRadius_IamFish, + }; + static f32 (*get_ground_y_proc[])(const Shadow_Info*) = { + mAc_GetShadowGroundY_NoneForce, + mAc_GetShadowGroundY_Force, + }; + + Shadow_Info shadow; + f32 rad = 0.01f; + u8 ground_y_proc; + bzero(&shadow, sizeof(Shadow_Info)); + + shadow.kind = mActorShadow_GetShadowKind(); + mActorShadow_GetShadowPosition(actor, &shadow.position); + mActorShadow_AdjustRate(&actor->shape_info.shadow_size_change_rate); + mActorShadow_AdjustRate(&actor->shape_info.shadow_alpha_change_rate); + + ground_y_proc = actor->shape_info.force_shadow_position & 1; + shadow.groundY = get_ground_y_proc[ground_y_proc](&shadow); + + mActorShadow_GetTimeAngleY_TimeAlpha(&shadow, play); + mActorShadow_GetGroundAverageAngle(&shadow); + mActorShadow_GetDistanceRate(&shadow, rate); + set_raius_proc[proc & 1](&shadow, actor, &rad); + mActorShadow_GetShadowTopPos_GetSlideS(&shadow); + mActorShadow_DrawActorShadow(actor, &shadow, play, proc, pos, rad); + actor->shape_info.force_shadow_position = 0; +} + +void mAc_ActorShadowDraw(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6) { + + static void (*shadwo_draw_proc[])(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6) = { + mAc_ActorShadowDraw_ShadowDrawFlagOff, + mAc_ActorShadowDraw_ShadowDrawFlagOn, +}; + + if (actor->id == 0x4A) { + mActorShadow_UnSetForceShadowPos(actor); + actor->shape_info.shadow_position = &actor->world.position; + } + + shadwo_draw_proc[actor->shape_info.draw_shadow & 1](actor, play, arg2, arg3, arg6); + actor->shape_info.shadow_position = &actor->world.position; +} + +xyz_t mActorShadow_offset0 = { 0.0f, 0.0f, 0.0f }; + + +void mActorShadow_SetForceShadowPos(ACTOR* actor, xyz_t* pos) { + actor->shape_info.force_shadow_position = 1; + actor->shape_info.shadow_position = pos; +} + +void mActorShadow_UnSetForceShadowPos(ACTOR* actor) { + actor->shape_info.force_shadow_position = 0; + actor->shape_info.shadow_position = &actor->world.position; +} + + +void mAc_NormalActorShadow(ACTOR* actor, GAME_PLAY* play, f32 rad){ + mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, rad); +} + +void mAc_UnagiActorShadow(ACTOR* actor, GAME_PLAY* play, xyz_t pos){ + mAc_ActorShadowDraw(actor, play, 1, pos, 1.0f); +} + +void mAc_ActorShadowCircle(ACTOR* actor, LightsN* lights, GAME_PLAY* play){ + mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, 1.0f); +} + +void mAc_ActorShadowEllipse(ACTOR* actor, LightsN* lights, GAME_PLAY* play){ + + static xyz_t tunekiti_offset = { 0.0f, 1.0f, 0.0f }; + + if(actor->id == 0x79){ + mAc_ActorShadowDraw(actor, play, 0, tunekiti_offset, 1.0f); + + } + else{ + mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, 1.0f); + } +} \ No newline at end of file From d0e60827b27f2b50e86658700d1bb1afb56233ae Mon Sep 17 00:00:00 2001 From: Prakxo Date: Sat, 9 Sep 2023 18:52:47 +0200 Subject: [PATCH 5/5] link m_bg_item --- config/rel_slices.yml | 4 ++++ include/m_bg_item.h | 8 +++++++ rel/m_bg_item.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 rel/m_bg_item.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index c6df974f..dda16f0d 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -34,6 +34,10 @@ m_banti.c: .rodata: [0x80641388, 0x806413E0] .data: [0x8064F548, 0x8064F658] .bss: [0x8125A830, 0x8125AC80] +m_bg_item.c: + .text: [0x80378858, 0x803789F8] + .rodata: [0x806413E0, 0x806413F0] + .bss: [0x81263080, 0x81263088] m_calendar.c: .text: [0x8037D190, 0x8037DA54] m_cockroach.c: diff --git a/include/m_bg_item.h b/include/m_bg_item.h index 3129b4c5..e90fd1c0 100644 --- a/include/m_bg_item.h +++ b/include/m_bg_item.h @@ -2,14 +2,22 @@ #define M_BG_ITEM_H #include "types.h" +#include "m_actor.h" #ifdef __cplusplus extern "C" { #endif +extern ACTOR* mBI_search_bg_item(Actor_info* info); +extern void mBI_make_bg_item(GAME_PLAY* play); +extern void mBI_change_bg_item(GAME_PLAY* play); extern void mBI_ct(); extern void mBI_move(GAME_PLAY* play); +typedef void (*BI_PROC)(GAME_PLAY*); + +extern BI_PROC mBI_make_proc; + #ifdef __cplusplus } #endif diff --git a/rel/m_bg_item.c b/rel/m_bg_item.c new file mode 100644 index 00000000..8263d7a3 --- /dev/null +++ b/rel/m_bg_item.c @@ -0,0 +1,55 @@ +#include "m_bg_item.h" + +#include "m_common_data.h" +#include "m_name_table.h" + +BI_PROC mBI_make_proc; + + +ACTOR* mBI_search_bg_item(Actor_info* info){ + static const s16 name_data[] = { + 0x4f, 0x1, 0x50,0x51 + }; + + int i; + for( i = 0; i < 4; i++){ + if(Actor_info_name_search(info,name_data[i], ACTOR_PART_ITEM) != 0){ + return; + } + } +} + +void mBI_make_bg_item(GAME_PLAY* play){ + + + if(mBI_search_bg_item(&play->actor_info) == NULL){ + + Actor_info_make_actor(&play->actor_info, &play->game, Common_Get(bg_item_profile),0, + 0.0f,0.0f,0,0,0 ,-1, -1,-1, EMPTY_NO,-1,-1,-1); + mBI_make_proc = NULL; + } +} + +void mBI_change_bg_item(GAME_PLAY* play){ + + ACTOR* actor = mBI_search_bg_item(&play->actor_info); + + if(actor != NULL){ + Actor_delete(actor); + mBI_make_proc = mBI_make_bg_item; + Common_Set(bg_item_profile, Common_Get(time.bgitem_profile)); + } +} + +void mBI_ct(){ + + mBI_make_proc = NULL; + +} + +void mBI_move(GAME_PLAY* play){ + + if(mBI_make_proc != NULL){ + mBI_make_proc(play); + } +} \ No newline at end of file