From 769899d6344e1bf46d993df15d69380be4dc0af0 Mon Sep 17 00:00:00 2001 From: Fuzzy2319 <61144247+Fuzzy2319@users.noreply.github.com> Date: Sun, 29 Dec 2024 16:06:55 +0100 Subject: [PATCH] Library/MapObj: Implement `RotateMapParts` (#212) --- data/odyssey_functions.csv | 40 +++---- lib/al/Library/MapObj/RollingCubeMapParts.cpp | 27 +++-- lib/al/Library/MapObj/RotateMapParts.cpp | 107 ++++++++++++++++++ lib/al/Library/MapObj/RotateMapParts.h | 28 +++++ lib/al/Library/Math/Axis.h | 15 +++ lib/al/Library/Math/MathAngleUtil.h | 8 +- src/Scene/ProjectActorFactory.cpp | 3 +- 7 files changed, 192 insertions(+), 36 deletions(-) create mode 100644 lib/al/Library/MapObj/RotateMapParts.cpp create mode 100644 lib/al/Library/MapObj/RotateMapParts.h create mode 100644 lib/al/Library/Math/Axis.h diff --git a/data/odyssey_functions.csv b/data/odyssey_functions.csv index f97e205c..32d45bc1 100644 --- a/data/odyssey_functions.csv +++ b/data/odyssey_functions.csv @@ -30473,7 +30473,7 @@ Address,Quality,Size,Name 0x00000071004bd14c,U,000052,_ZN2al19createActorFunctionI18RiseMapPartsHolderEEPNS_9LiveActorEPKc 0x00000071004bd180,U,000052,_ZN2al19createActorFunctionI12RocketFlowerEEPNS_9LiveActorEPKc 0x00000071004bd1b4,O,000052,_ZN2al19createActorFunctionINS_19RollingCubeMapPartsEEEPNS_9LiveActorEPKc -0x00000071004bd1e8,U,000052,_ZN2al19createActorFunctionINS_14RotateMapPartsEEEPNS_9LiveActorEPKc +0x00000071004bd1e8,O,000052,_ZN2al19createActorFunctionINS_14RotateMapPartsEEEPNS_9LiveActorEPKc 0x00000071004bd21c,U,000052,_ZN2al19createActorFunctionINS_14SeesawMapPartsEEEPNS_9LiveActorEPKc 0x00000071004bd250,U,000052,_ZN2al19createActorFunctionINS_13SlideMapPartsEEEPNS_9LiveActorEPKc 0x00000071004bd284,U,000052,_ZN2al19createActorFunctionINS_19SubActorLodMapPartsEEEPNS_9LiveActorEPKc @@ -58417,25 +58417,25 @@ Address,Quality,Size,Name 0x0000007100918098,O,000136,_ZNK12_GLOBAL__N_126RollingCubeMapPartsNrvStop7executeEPN2al11NerveKeeperE 0x0000007100918120,O,000012,_ZNK12_GLOBAL__N_126RollingCubeMapPartsNrvStop13getActionNameEv 0x000000710091812c,O,000380,_GLOBAL__sub_I_RollingCubeMapParts.cpp -0x00000071009182a8,U,000160,_ZN2al14RotateMapPartsC2EPKc -0x0000007100918348,U,000172,_ZN2al14RotateMapPartsC1EPKc -0x00000071009183f4,U,000276,_ZN2al14RotateMapParts4initERKNS_13ActorInitInfoE -0x0000007100918508,U,000068,_ZN2al14RotateMapParts5startEv -0x000000710091854c,U,000160,_ZN2al14RotateMapParts10receiveMsgEPKNS_9SensorMsgEPNS_9HitSensorES5_ -0x00000071009185ec,U,000052,_ZN2al14RotateMapParts17appearAndSetStartEv -0x0000007100918620,U,000004,_ZN2al14RotateMapParts10exeStandByEv -0x0000007100918624,U,000136,_ZN2al14RotateMapParts9exeRotateEv -0x00000071009186ac,U,000036,_ZN2al14RotateMapParts13exeAssistStopEv -0x00000071009186d0,U,000004, -0x00000071009186d4,U,000012, -0x00000071009186e0,U,000140, -0x000000710091876c,U,000012, -0x0000007100918778,U,000040, -0x00000071009187a0,U,000012, -0x00000071009187ac,U,000028,_ZNK2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEEclEv -0x00000071009187c8,U,000076,_ZNK2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEE5cloneEv -0x0000007100918814,U,000004,_ZN2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEED0Ev -0x0000007100918818,U,000116, +0x00000071009182a8,O,000160,_ZN2al14RotateMapPartsC2EPKc +0x0000007100918348,O,000172,_ZN2al14RotateMapPartsC1EPKc +0x00000071009183f4,O,000276,_ZN2al14RotateMapParts4initERKNS_13ActorInitInfoE +0x0000007100918508,O,000068,_ZN2al14RotateMapParts5startEv +0x000000710091854c,O,000160,_ZN2al14RotateMapParts10receiveMsgEPKNS_9SensorMsgEPNS_9HitSensorES5_ +0x00000071009185ec,O,000052,_ZN2al14RotateMapParts17appearAndSetStartEv +0x0000007100918620,O,000004,_ZN2al14RotateMapParts10exeStandByEv +0x0000007100918624,O,000136,_ZN2al14RotateMapParts9exeRotateEv +0x00000071009186ac,O,000036,_ZN2al14RotateMapParts13exeAssistStopEv +0x00000071009186d0,O,000004,_ZNK2al12_GLOBAL__N_124RotateMapPartsNrvStandBy7executeEPNS_11NerveKeeperE +0x00000071009186d4,O,000012,_ZNK2al12_GLOBAL__N_124RotateMapPartsNrvStandBy13getActionNameEv +0x00000071009186e0,O,000140,_ZNK2al12_GLOBAL__N_123RotateMapPartsNrvRotate7executeEPNS_11NerveKeeperE +0x000000710091876c,O,000012,_ZNK2al12_GLOBAL__N_123RotateMapPartsNrvRotate13getActionNameEv +0x0000007100918778,O,000040,_ZNK2al12_GLOBAL__N_127RotateMapPartsNrvAssistStop7executeEPNS_11NerveKeeperE +0x00000071009187a0,O,000012,_ZNK2al12_GLOBAL__N_127RotateMapPartsNrvAssistStop13getActionNameEv +0x00000071009187ac,O,000028,_ZNK2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEEclEv +0x00000071009187c8,O,000076,_ZNK2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEE5cloneEv +0x0000007100918814,O,000004,_ZN2al10FunctorV0MIPNS_14RotateMapPartsEMS1_FvvEED0Ev +0x0000007100918818,O,000116,_GLOBAL__sub_I_RotateMapParts.cpp 0x000000710091888c,U,000240,_ZN2al14SeesawMapPartsC2EPKc 0x000000710091897c,U,000252,_ZN2al14SeesawMapPartsC1EPKc 0x0000007100918a78,U,000280,_ZN2al14SeesawMapParts4initERKNS_13ActorInitInfoE diff --git a/lib/al/Library/MapObj/RollingCubeMapParts.cpp b/lib/al/Library/MapObj/RollingCubeMapParts.cpp index 5b47ce35..a5d09312 100644 --- a/lib/al/Library/MapObj/RollingCubeMapParts.cpp +++ b/lib/al/Library/MapObj/RollingCubeMapParts.cpp @@ -132,19 +132,20 @@ void RollingCubeMapParts::setNerveNextMovement(bool isNextFallKey) { return; } - s32 axis = sead::Mathi::abs(calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); + Axis axis = (Axis)sead::Mathi::abs( + (s32)calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); switch (axis) { default: return; - case 1: + case Axis::X: startNerveAction(this, "SlideX"); return; - case 2: + case Axis::Y: startNerveAction(this, "SlideY"); return; - case 3: + case Axis::Z: startNerveAction(this, "SlideZ"); return; @@ -198,19 +199,20 @@ s32 RollingCubeMapParts::getMovementTime() const { } void RollingCubeMapParts::setNerveNextLand() { - s32 axis = sead::Mathi::abs(calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); + Axis axis = (Axis)sead::Mathi::abs( + (s32)calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); switch (axis) { default: return; - case 1: + case Axis::X: startNerveAction(this, "LandX"); return; - case 2: + case Axis::Y: startNerveAction(this, "LandY"); return; - case 3: + case Axis::Z: startNerveAction(this, "LandZ"); return; @@ -262,19 +264,20 @@ void RollingCubeMapParts::exeFall() { } void RollingCubeMapParts::setNerveNextFallLand() { - s32 axis = sead::Mathi::abs(calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); + Axis axis = (Axis)sead::Mathi::abs( + (s32)calcNearVecFromAxis3(nullptr, sead::Vector3f::ey, getQuat(this))); switch (axis) { default: return; - case 1: + case Axis::X: startNerveAction(this, "FallLandX"); return; - case 2: + case Axis::Y: startNerveAction(this, "FallLandY"); return; - case 3: + case Axis::Z: startNerveAction(this, "FallLandZ"); return; diff --git a/lib/al/Library/MapObj/RotateMapParts.cpp b/lib/al/Library/MapObj/RotateMapParts.cpp new file mode 100644 index 00000000..ab76b2f3 --- /dev/null +++ b/lib/al/Library/MapObj/RotateMapParts.cpp @@ -0,0 +1,107 @@ +#include "Library/MapObj/RotateMapParts.h" + +#include "Library/LiveActor/ActorActionFunction.h" +#include "Library/LiveActor/ActorAreaFunction.h" +#include "Library/LiveActor/ActorInitFunction.h" +#include "Library/LiveActor/ActorModelFunction.h" +#include "Library/LiveActor/ActorMovementFunction.h" +#include "Library/LiveActor/ActorPoseKeeper.h" +#include "Library/LiveActor/ActorSensorMsgFunction.h" +#include "Library/MapObj/ChildStep.h" +#include "Library/Nerve/NerveSetupUtil.h" +#include "Library/Placement/PlacementFunction.h" +#include "Library/Se/SeFunction.h" +#include "Library/Stage/StageSwitchKeeper.h" +#include "Library/Thread/FunctorV0M.h" + +namespace al { +namespace { +NERVE_ACTION_IMPL(RotateMapParts, StandBy) +NERVE_ACTION_IMPL(RotateMapParts, Rotate) +NERVE_ACTION_IMPL(RotateMapParts, AssistStop) + +NERVE_ACTIONS_MAKE_STRUCT(RotateMapParts, StandBy, Rotate, AssistStop) +} // namespace + +RotateMapParts::RotateMapParts(const char* name) : LiveActor(name) {} + +void RotateMapParts::init(const ActorInitInfo& info) { + using RotateMapPartsFunctor = FunctorV0M; + + tryInitSubActorKeeperChildStep(this, info); + initNerveAction(this, "Rotate", &NrvRotateMapParts.mCollector, 0); + initMapPartsActor(this, info, nullptr); + tryGetQuatPtr(this); + registerAreaHostMtx(this, info); + + mQuat.set(getQuat(this)); + tryGetArg((s32*)&mRotateAxis, info, "RotateAxis"); + tryGetArg(&mRotateSpeed, info, "RotateSpeed"); + + createChildStep(info, this, true); + initMaterialCode(this, info); + + if (listenStageSwitchOnStart(this, RotateMapPartsFunctor(this, &RotateMapParts::start))) + startNerveAction(this, "StandBy"); + + trySyncStageSwitchAppear(this); +} + +void RotateMapParts::start() { + if (isNerve(this, NrvRotateMapParts.StandBy.data())) + startNerveAction(this, "Rotate"); +} + +bool RotateMapParts::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) { + if (isMsgTouchAssist(message)) { + mAssistTimer = 45; + + return true; + } + + if (isMsgShowModel(message)) { + showModelIfHide(this); + + return true; + } + + if (isMsgHideModel(message)) { + hideModelIfShow(this); + + return true; + } + + if (isMsgRestart(message)) { + appearAndSetStart(); + + return true; + } + + return false; +} + +void RotateMapParts::appearAndSetStart() { + mAssistTimer = 0; + setQuat(this, mQuat); + + makeActorAlive(); +} + +void RotateMapParts::exeStandBy() {} + +void RotateMapParts::exeRotate() { + rotateQuatLocalDirDegree(this, (s32)mRotateAxis, mRotateSpeed / 100.0f); + if (mAssistTimer > 0) + startNerveAction(this, "AssistStop"); + + tryHoldSeWithParam(this, "RotateWithSpeed", mRotateSpeed, ""); +} + +void RotateMapParts::exeAssistStop() { + mAssistTimer--; + if (mAssistTimer <= 0) { + mAssistTimer = 0; + startNerveAction(this, "Rotate"); + } +} +} // namespace al diff --git a/lib/al/Library/MapObj/RotateMapParts.h b/lib/al/Library/MapObj/RotateMapParts.h new file mode 100644 index 00000000..e4aa365a --- /dev/null +++ b/lib/al/Library/MapObj/RotateMapParts.h @@ -0,0 +1,28 @@ +#pragma once + +#include "Library/LiveActor/LiveActor.h" +#include "Library/Math/Axis.h" + +namespace al { +class RotateMapParts : public LiveActor { +public: + RotateMapParts(const char* name); + + void init(const ActorInitInfo& info) override; + void start(); + bool receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) override; + void appearAndSetStart(); + + void exeStandBy(); + void exeRotate(); + void exeAssistStop(); + +private: + sead::Quatf mQuat = sead::Quatf::unit; + Axis mRotateAxis = Axis::X; + f32 mRotateSpeed = 100.0f; + s32 mAssistTimer = 0; +}; + +static_assert(sizeof(RotateMapParts) == 0x128); +} // namespace al diff --git a/lib/al/Library/Math/Axis.h b/lib/al/Library/Math/Axis.h new file mode 100644 index 00000000..92b56a70 --- /dev/null +++ b/lib/al/Library/Math/Axis.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace al { +enum class Axis : s32 { + InvertZ = -3, + InvertY = -2, + InvertX = -1, + None = 0, + X = 1, + Y = 2, + Z = 3, +}; +} diff --git a/lib/al/Library/Math/MathAngleUtil.h b/lib/al/Library/Math/MathAngleUtil.h index 5cacaa11..5ae3dd10 100644 --- a/lib/al/Library/Math/MathAngleUtil.h +++ b/lib/al/Library/Math/MathAngleUtil.h @@ -3,6 +3,8 @@ #include #include +#include "Library/Math/Axis.h" + namespace al { void verticalizeVec(sead::Vector3f* out, const sead::Vector3f& vertical, const sead::Vector3f& vec); @@ -43,7 +45,7 @@ bool tryNormalizeOrZero(sead::Vector3f*); void alongVectorNormalH(sead::Vector3f*, const sead::Vector3f&, const sead::Vector3f&, const sead::Vector3f&); -s32 calcNearVecFromAxis3(sead::Vector3f*, const sead::Vector3f&, const sead::Vector3f&, - const sead::Vector3f&, const sead::Vector3f&); -s32 calcNearVecFromAxis3(sead::Vector3f*, const sead::Vector3f&, const sead::Quatf&); +Axis calcNearVecFromAxis3(sead::Vector3f*, const sead::Vector3f&, const sead::Vector3f&, + const sead::Vector3f&, const sead::Vector3f&); +Axis calcNearVecFromAxis3(sead::Vector3f*, const sead::Vector3f&, const sead::Quatf&); } // namespace al diff --git a/src/Scene/ProjectActorFactory.cpp b/src/Scene/ProjectActorFactory.cpp index c5c3661f..8386ba3b 100644 --- a/src/Scene/ProjectActorFactory.cpp +++ b/src/Scene/ProjectActorFactory.cpp @@ -13,6 +13,7 @@ #include "Library/MapObj/OneMeshFixMapParts.h" #include "Library/MapObj/RailMoveMapParts.h" #include "Library/MapObj/RollingCubeMapParts.h" +#include "Library/MapObj/RotateMapParts.h" #include "Library/MapObj/SurfMapParts.h" #include "Library/Obj/AllDeadWatcher.h" @@ -576,7 +577,7 @@ static al::NameToCreator sProjectActorFactoryEntries[] {"RocketFlower", nullptr}, {"RollingCubeMapParts", al::createActorFunction}, {"RippleFixMapParts", nullptr}, - {"RotateMapParts", nullptr}, + {"RotateMapParts", al::createActorFunction}, {"SeesawMapParts", nullptr}, {"SlideMapParts", nullptr}, {"SubActorLodMapParts", nullptr},