diff --git a/config/SOUE01/rels/d_t_sound_areaNP/splits.txt b/config/SOUE01/rels/d_t_sound_areaNP/splits.txt index 7acbb71c..5204477d 100644 --- a/config/SOUE01/rels/d_t_sound_areaNP/splits.txt +++ b/config/SOUE01/rels/d_t_sound_areaNP/splits.txt @@ -11,3 +11,5 @@ REL/executor.c: REL/d/t/d_t_sound_area.cpp: .text start:0x00000070 end:0x00000700 + .rodata start:0x00000000 end:0x0000002C + .data start:0x00000000 end:0x00000084 diff --git a/config/SOUE01/rels/d_t_sound_areaNP/symbols.txt b/config/SOUE01/rels/d_t_sound_areaNP/symbols.txt index d5bd8fe6..cdc4ffe7 100644 --- a/config/SOUE01/rels/d_t_sound_areaNP/symbols.txt +++ b/config/SOUE01/rels/d_t_sound_areaNP/symbols.txt @@ -1,21 +1,21 @@ _prolog = .text:0x00000000; // type:function size:0x2C scope:global _epilog = .text:0x00000030; // type:function size:0x2C scope:global _unresolved = .text:0x00000060; // type:function size:0x4 scope:global -fn_497_70 = .text:0x00000070; // type:function size:0x54 -fn_497_D0 = .text:0x000000D0; // type:function size:0x144 -fn_497_220 = .text:0x00000220; // type:function size:0x8 -fn_497_230 = .text:0x00000230; // type:function size:0xCC -fn_497_300 = .text:0x00000300; // type:function size:0x8 -fn_497_310 = .text:0x00000310; // type:function size:0x40 -fn_497_350 = .text:0x00000350; // type:function size:0xF0 -fn_497_440 = .text:0x00000440; // type:function size:0x54 -fn_497_4A0 = .text:0x000004A0; // type:function size:0x98 -fn_497_540 = .text:0x00000540; // type:function size:0x14C -fn_497_690 = .text:0x00000690; // type:function size:0x70 +dTgSndAr_c_classInit__Fv = .text:0x00000070; // type:function size:0x54 +create__10dTgSndAr_cFv = .text:0x000000D0; // type:function size:0x144 +doDelete__10dTgSndAr_cFv = .text:0x00000220; // type:function size:0x8 +actorExecute__10dTgSndAr_cFv = .text:0x00000230; // type:function size:0xCC +draw__10dTgSndAr_cFv = .text:0x00000300; // type:function size:0x8 +checkPosInArea__10dTgSndAr_cFR7mVec3_c = .text:0x00000310; // type:function size:0x40 +checkAlg0__10dTgSndAr_cFRC7mVec3_c = .text:0x00000350; // type:function size:0xF0 +checkAlg1__10dTgSndAr_cFRC7mVec3_c = .text:0x00000440; // type:function size:0x54 +checkAlg2__10dTgSndAr_cFRC7mVec3_c = .text:0x000004A0; // type:function size:0x98 +checkAlg3__10dTgSndAr_cFRC7mVec3_c = .text:0x00000540; // type:function size:0x14C +__dt__10dTgSndAr_cFv = .text:0x00000690; // type:function size:0x70 _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global lbl_497_rodata_0 = .rodata:0x00000000; // type:object size:0x18 data:float lbl_497_rodata_18 = .rodata:0x00000018; // type:object size:0x10 data:float lbl_497_rodata_28 = .rodata:0x00000028; // type:object size:0x4 data:float -lbl_497_data_0 = .data:0x00000000; // type:object size:0x10 -lbl_497_data_10 = .data:0x00000010; // type:object size:0x74 +g_profile_TAG_SOUND_AREA = .data:0x00000000; // type:object size:0x10 +__vt__10dTgSndAr_c = .data:0x00000010; // type:object size:0x74 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index ed5e1174..166c10e1 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -1143,7 +1143,7 @@ fn_8002EF70 = .text:0x8002EF70; // type:function size:0x28 fn_8002EFA0 = .text:0x8002EFA0; // type:function size:0x50 fn_8002EFF0 = .text:0x8002EFF0; // type:function size:0x194 fn_8002F190 = .text:0x8002F190; // type:function size:0x24 -fn_8002F1C0 = .text:0x8002F1C0; // type:function size:0x98 +createActorUnkGroup3__12dAcObjBase_cFQ28fProfile14PROFILE_NAME_eUlUlP7mVec3_cP7mAng3_cP7mVec3_cUl = .text:0x8002F1C0; // type:function size:0x98 fn_8002F260 = .text:0x8002F260; // type:function size:0xA0 fn_8002F300 = .text:0x8002F300; // type:function size:0x74 fn_8002F380 = .text:0x8002F380; // type:function size:0x74 @@ -3672,18 +3672,18 @@ fn_800A61C0 = .text:0x800A61C0; // type:function size:0x9C fn_800A6260 = .text:0x800A6260; // type:function size:0x9C fn_800A6300 = .text:0x800A6300; // type:function size:0x368 fn_800A6670 = .text:0x800A6670; // type:function size:0x1C -fn_800A6690 = .text:0x800A6690; // type:function size:0x3C -fn_800A66D0 = .text:0x800A66D0; // type:function size:0x40 +__ct__11ActorOnRailFv = .text:0x800A6690; // type:function size:0x3C +__dt__11ActorOnRailFv = .text:0x800A66D0; // type:function size:0x40 fn_800A6710 = .text:0x800A6710; // type:function size:0x18 fn_800A6730 = .text:0x800A6730; // type:function size:0xBC fn_800A67F0 = .text:0x800A67F0; // type:function size:0xBC -fn_800A68B0 = .text:0x800A68B0; // type:function size:0x58 +getPntPosForIndex__11ActorOnRailFi = .text:0x800A68B0; // type:function size:0x58 fn_800A6910 = .text:0x800A6910; // type:function size:0x2B4 fn_800A6BD0 = .text:0x800A6BD0; // type:function size:0x74 fn_800A6C50 = .text:0x800A6C50; // type:function size:0x110 fn_800A6D60 = .text:0x800A6D60; // type:function size:0x10 fn_800A6D70 = .text:0x800A6D70; // type:function size:0x18 -fn_800A6D90 = .text:0x800A6D90; // type:function size:0xC4 +init__11ActorOnRailFiii = .text:0x800A6D90; // type:function size:0xC4 fn_800A6E60 = .text:0x800A6E60; // type:function size:0x68 fn_800A6ED0 = .text:0x800A6ED0; // type:function size:0xB4 fn_800A6F90 = .text:0x800A6F90; // type:function size:0x184 @@ -17840,7 +17840,7 @@ fn_802F1660 = .text:0x802F1660; // type:function size:0x44 fn_802F16B0 = .text:0x802F16B0; // type:function size:0xBC fn_802F1770 = .text:0x802F1770; // type:function size:0x4C fn_802F17C0 = .text:0x802F17C0; // type:function size:0xBC -fn_802F1880 = .text:0x802F1880; // type:function size:0x4C +YrotM__6mMtx_cFRC4mAng = .text:0x802F1880; // type:function size:0x4C fn_802F18D0 = .text:0x802F18D0; // type:function size:0xBC fn_802F1990 = .text:0x802F1990; // type:function size:0x4C fn_802F19E0 = .text:0x802F19E0; // type:function size:0x60 @@ -22195,7 +22195,7 @@ fn_803B8460 = .text:0x803B8460; // type:function size:0xB0 fn_803B8510 = .text:0x803B8510; // type:function size:0x12C fn_803B8640 = .text:0x803B8640; // type:function size:0xB0 fn_803B86F0 = .text:0x803B86F0; // type:function size:0x7C -fn_803B8770 = .text:0x803B8770; // type:function size:0x34 +PSMTXTrans = .text:0x803B8770; // type:function size:0x34 fn_803B87B0 = .text:0x803B87B0; // type:function size:0x4C fn_803B8800 = .text:0x803B8800; // type:function size:0x28 fn_803B8830 = .text:0x803B8830; // type:function size:0x58 diff --git a/configure.py b/configure.py index 3b36a517..64820df5 100644 --- a/configure.py +++ b/configure.py @@ -1095,7 +1095,7 @@ config.libs = [ Rel(NonMatching, "d_t_siren_time_attack", "REL/d/t/d_t_siren_time_attack.cpp"), Rel(NonMatching, "d_t_skyEnemy", "REL/d/t/d_t_skyEnemy.cpp"), Rel(NonMatching, "d_t_sound", "REL/d/t/d_t_sound.cpp"), - Rel(NonMatching, "d_t_sound_area", "REL/d/t/d_t_sound_area.cpp"), + Rel(Matching, "d_t_sound_area", "REL/d/t/d_t_sound_area.cpp"), Rel(NonMatching, "d_t_sound_area_mgr", "REL/d/t/d_t_sound_area_mgr.cpp"), Rel(NonMatching, "d_t_sparks2", "REL/d/t/d_t_sparks2.cpp"), Rel(NonMatching, "d_t_sparks", "REL/d/t/d_t_sparks.cpp"), diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index 77fbd8a1..8988b8f6 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -81,9 +81,9 @@ public: /* 8002f190 */ void createChildAttached2(fProfile::PROFILE_NAME_e actorId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, u32 roomId); // These may not belong here - /* 8002f1c0 */ static dAcBase_c createActorUnkGroup3(fProfile::PROFILE_NAME_e actorId, u32 roomId, u32 params1, + /* 8002f1c0 */ static dAcBase_c *createActorUnkGroup3(fProfile::PROFILE_NAME_e actorId, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2); - /* 8002f260 */ static dAcBase_c createActorUnkGroup3(char *name, u32 roomId, u32 params1, mVec3_c *pos, + /* 8002f260 */ static dAcBase_c *createActorUnkGroup3(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, u16 id, u8 viewclipId); }; diff --git a/include/d/tg/d_t_sound_area.h b/include/d/tg/d_t_sound_area.h new file mode 100644 index 00000000..67c6fbfd --- /dev/null +++ b/include/d/tg/d_t_sound_area.h @@ -0,0 +1,34 @@ +#ifndef D_T_SOUND_AREA_H +#define D_T_SOUND_AREA_H + +#include +#include +#include +#include + + +class dTgSndAr_c : public dTg_c { +public: + dTgSndAr_c() {} + virtual ~dTgSndAr_c() {} + virtual int draw() override; + virtual int actorExecute() override; + virtual int doDelete() override; + virtual int create() override; + +private: + int getTypeFromParams() { + return params >> 0x1C; + } + bool checkPosInArea(mVec3_c &pos); + + bool checkAlg0(const mVec3_c &pos); + bool checkAlg1(const mVec3_c &pos); + bool checkAlg2(const mVec3_c &pos); + bool checkAlg3(const mVec3_c &pos); + + mMtx_c mtx; + ActorOnRail mRail; +}; + +#endif diff --git a/include/egg/math/eggVector.h b/include/egg/math/eggVector.h index 2090b5b7..9aa50ae8 100644 --- a/include/egg/math/eggVector.h +++ b/include/egg/math/eggVector.h @@ -111,7 +111,7 @@ struct Vector3f : public nw4r::math::VEC3 { struct Vector2f : nw4r::math::VEC2 { inline Vector2f() {} Vector2f(f32 fx, f32 fy) : VEC2(fx, fy) {} - inline ~Vector2f() {} + inline ~Vector2f() {} public: /* 805767c0 */ static const Vector2f zero; diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 832800a8..52c2408c 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -16,7 +16,6 @@ class mAng3_c { public: mAng3_c() {} - s16 x, y, z; mAng3_c(s16 fx, s16 fy, s16 fz) : x(fx), y(fy), z(fz) {} void set(s16 fx, s16 fy, s16 fz) { @@ -25,6 +24,8 @@ public: z = fz; } + mAng x, y, z; + static mAng3_c Zero; }; diff --git a/include/m/m_mtx.h b/include/m/m_mtx.h index 512ede2d..ee60b72d 100644 --- a/include/m/m_mtx.h +++ b/include/m/m_mtx.h @@ -9,16 +9,17 @@ #include class mMtx_c { +public: mMtx_c(){}; /* 802f1660 */ mMtx_c(f32 xx, f32 xy, f32 xz, f32 xw, f32 yx, f32 yy, f32 yz, f32 yw, f32 zx, f32 zy, f32 zz, f32 zw); - /* 802f16b0 */ void XrotS(mAng angle); ///< Generates a rotation matrix for the X axis with the given angle. - /* 802f1770 */ void XrotM(mAng angle); ///< Rotates the matrix on the X axis by the given angle. - /* 802f17c0 */ void YrotS(mAng angle); ///< Generates a rotation matrix for the Y axis with the given angle. - /* 802f1880 */ void YrotM(mAng angle); ///< Rotates the matrix on the Y axis by the given angle. - /* 802f18d0 */ void ZrotS(mAng angle); ///< Generates a rotation matrix for the Z axis with the given angle. - /* 802f1990 */ void ZrotM(mAng angle); ///< Rotates the matrix on the Z axis by the given angle. + /* 802f16b0 */ void XrotS(const mAng &angle); ///< Generates a rotation matrix for the X axis with the given angle. + /* 802f1770 */ void XrotM(const mAng &angle); ///< Rotates the matrix on the X axis by the given angle. + /* 802f17c0 */ void YrotS(const mAng &angle); ///< Generates a rotation matrix for the Y axis with the given angle. + /* 802f1880 */ void YrotM(const mAng &angle); ///< Rotates the matrix on the Y axis by the given angle. + /* 802f18d0 */ void ZrotS(const mAng &angle); ///< Generates a rotation matrix for the Z axis with the given angle. + /* 802f1990 */ void ZrotM(const mAng &angle); ///< Rotates the matrix on the Z axis by the given angle. /* 802f19e0 */ void ZXYrotS(mAng xRot, mAng yRot, mAng zRot); ///< Generates the matrix on the Y, X and Z axes by the given angles. diff --git a/include/m/m_vec.h b/include/m/m_vec.h index 1ea23afb..f7ba025d 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -9,7 +9,7 @@ class mVec3_c : public EGG::Vector3f { public: /// @brief Constructs an empty vector. /* 80009ee0 */ mVec3_c() {} - // /* 80007460 */ ~mVec3_c() {} + /* 80007460 */ ~mVec3_c() {} /// @brief Constructs a vector from a float array. mVec3_c(const f32 *p) { @@ -19,16 +19,11 @@ public: } mVec3_c(const mVec3_c &other) { - x = other.x; - y = other.y; - z = other.z; + set(other.x, other.y, other.z); } - /// @brief Constructs a vector from three floating point values. mVec3_c(f32 fx, f32 fy, f32 fz) { - x = fx; - y = fy; - z = fz; + set(fx, fy, fz); } mVec3_c &operator=(const mVec3_c &r) { @@ -65,6 +60,10 @@ public: return (Vec *)&x; } + operator EGG::Vector3f *() { + return (EGG::Vector3f *)&x; + } + /// @brief Const Vec cast operator. operator const Vec *() const { return (const Vec *)&x; diff --git a/include/toBeSorted/actor_on_rail.h b/include/toBeSorted/actor_on_rail.h new file mode 100644 index 00000000..a57d2753 --- /dev/null +++ b/include/toBeSorted/actor_on_rail.h @@ -0,0 +1,24 @@ +#ifndef ACTOR_ON_RAIL_H +#define ACTOR_ON_RAIL_H + +#include + +class ActorOnRail { +private: + void *mpPathPtr; + int mRoomIndex; + u8 mPathSubtype; + +public: + /* 800A6690 */ + ActorOnRail(); + /* 800A66D0 */ + virtual ~ActorOnRail(); + + /* 800A6D90 */ + bool init(int pathIndex, int roomId, int pathSubtype); + /* 800A68B0 */ + mVec3_c *getPntPosForIndex(int index); +}; + +#endif diff --git a/src/REL/d/t/d_t_sound_area.cpp b/src/REL/d/t/d_t_sound_area.cpp index e69de29b..a4165a6c 100644 --- a/src/REL/d/t/d_t_sound_area.cpp +++ b/src/REL/d/t/d_t_sound_area.cpp @@ -0,0 +1,178 @@ +#include +#include +#include +#include + +SPECIAL_ACTOR_PROFILE(TAG_SOUND_AREA, dTgSndAr_c, fProfile::TAG_SOUND_AREA, 0x0146, 0, 0); + +void float_ordering() { + f32 arr[6] = {0, 100, 100, 100, 100, 100}; + 0.01f; +} + +struct SoundAreaManager { + u8 unk[0xFC]; + u32 bgmFlags; +}; + +extern SoundAreaManager *lbl_805756EC; + +int dTgSndAr_c::create() { + scale *= 0.01f; + if (lbl_805756EC == nullptr) { + dAcObjBase_c::createActorUnkGroup3(fProfile::SOUND_AREA_MGR, roomid, 0, nullptr, nullptr, nullptr, -1); + } + + switch (getTypeFromParams()) { + case 0: + PSMTXTrans(mtx.m, position.x, position.y, position.z); + mtx.YrotM(rotation.y); + PSMTXInverse(mtx.m, mtx.m); + break; + case 3: + mRail.init(params >> 8 & 0xFF, roomid, 0); + break; + } + + fBase_c *base = nullptr; + while (true) { + if ((base = fManager_c::searchBaseByGroupType(ACTOR, base)) == nullptr) { + break; + } + // This has got to be just a member function + dAcBase_c *ac = static_cast(base); + if (!dBase_c::isActorPlayer(*ac) && checkPosInArea(ac->position)) { + ac->setBit_field_0xE8(params & 0xFF); + } + } + return 1; +} + +int dTgSndAr_c::doDelete() { + return 1; +} + +struct Unk { + u8 unk[0x144]; + mVec3_c v; +}; + +extern Unk *lbl_80575D58; + +int dTgSndAr_c::actorExecute() { + dAcBase_c *link = dPlayer::LINK; + if (link != nullptr && checkPosInArea(link->position)) { + link->setBit_field_0xE8(params & 0xFF); + } + if (lbl_80575D58 != nullptr) { + mVec3_c pos = lbl_80575D58->v; + if (checkPosInArea(pos) && lbl_805756EC != nullptr) { + lbl_805756EC->bgmFlags |= 1 << (params & 0xFF); + } + } + return 1; +} + +int dTgSndAr_c::draw() { + return 1; +} + +bool dTgSndAr_c::checkPosInArea(mVec3_c &pos) { + switch (getTypeFromParams()) { + case 0: + return checkAlg0(pos); + case 1: + return checkAlg1(pos); + case 2: + return checkAlg2(pos); + case 3: + return checkAlg3(pos); + } + + return false; +} + +inline bool inRange(f32 val, f32 tolerance) { + return (-tolerance <= val && val <= tolerance); +} + +// Box +bool dTgSndAr_c::checkAlg0(const mVec3_c &pos) { + mVec3_c c2 = pos; + PSMTXMultVec(mtx.m, c2, c2); + f32 sxLower = -50.0f * scale.x; + f32 sxUpper = 50.0f * scale.x; + f32 syLower = 0.0f; + f32 syUpper = 100.0f * scale.y; + f32 szLower = -50.0f * scale.z; + f32 szUpper = 50.0f * scale.z; + + if (sxLower <= c2.x && c2.x <= sxUpper && syLower <= c2.y && c2.y <= syUpper && szLower <= c2.z && + c2.z <= szUpper) { + return true; + } + return false; +} + +// Sphere +bool dTgSndAr_c::checkAlg1(const mVec3_c &pos) { + f32 tgtDist = scale.x * 100.0f; + f32 tgtDist2 = tgtDist * tgtDist; + return PSVECSquareDistance(position, pos) < tgtDist2; +} + +// Cylinder +bool dTgSndAr_c::checkAlg2(const mVec3_c &pos) { + if (pos.y < position.y || pos.y > (position.y + 100.0f * scale.y)) { + return false; + } + + f32 radius = scale.x * 100.0f; + mVec3_c diff = pos - position; + + f32 dist = diff.x * diff.x + diff.z * diff.z; + f32 r2 = radius * radius; + + return !(dist > r2); +} + +struct UnkStruct { + /* 0x00 */ mVec3_c vec; + /* 0x0C */ mVec3_c vec2; + /* 0x18 */ u32 unk; + /* 0x1C */ f32 field_0x1C; + /* 0x20 */ u8 field_0x20; + /* 0x24 */ u32 field_0x24; +}; + +extern "C" void fn_80337EA0(UnkStruct *); +extern "C" void fn_80337EF0(UnkStruct *, mVec3_c &, mVec3_c &, f32); +extern "C" int fn_8032BFB0(UnkStruct *, EGG::Vector3f &, f32 *, f32 &, int); + +// ??? +bool dTgSndAr_c::checkAlg3(const mVec3_c &pos) { + f32 q[4]; + UnkStruct unk; + + f32 radius = scale.x * 100.0f; + radius = radius * radius; + EGG::Vector3f a = pos; + fn_80337EA0(&unk); + + mVec3_c b = *mRail.getPntPosForIndex(0); + mVec3_c c = *mRail.getPntPosForIndex(1); + + fn_80337EF0(&unk, b, c, scale.x * 100.0f); + f32 d; + if (fn_8032BFB0(&unk, a, q, d, 0)) { + return d < radius; + } else { + f32 distSq = PSVECSquareDistance(unk.vec, pos); + if (distSq < radius) { + return true; + } else { + distSq = PSVECSquareDistance(unk.vec2, pos); + return distSq < radius; + } + } +}