Skip to content

Commit

Permalink
Library/MapObj: Implement RotateMapParts (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzy2319 authored Dec 29, 2024
1 parent c5b6725 commit 769899d
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 36 deletions.
40 changes: 20 additions & 20 deletions data/odyssey_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions lib/al/Library/MapObj/RollingCubeMapParts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
107 changes: 107 additions & 0 deletions lib/al/Library/MapObj/RotateMapParts.cpp
Original file line number Diff line number Diff line change
@@ -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<RotateMapParts*, void (RotateMapParts::*)()>;

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
28 changes: 28 additions & 0 deletions lib/al/Library/MapObj/RotateMapParts.h
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions lib/al/Library/Math/Axis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <basis/seadTypes.h>

namespace al {
enum class Axis : s32 {
InvertZ = -3,
InvertY = -2,
InvertX = -1,
None = 0,
X = 1,
Y = 2,
Z = 3,
};
}
8 changes: 5 additions & 3 deletions lib/al/Library/Math/MathAngleUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <math/seadQuat.h>
#include <math/seadVector.h>

#include "Library/Math/Axis.h"

namespace al {
void verticalizeVec(sead::Vector3f* out, const sead::Vector3f& vertical, const sead::Vector3f& vec);

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/Scene/ProjectActorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -576,7 +577,7 @@ static al::NameToCreator<al::ActorCreatorFunction> sProjectActorFactoryEntries[]
{"RocketFlower", nullptr},
{"RollingCubeMapParts", al::createActorFunction<al::RollingCubeMapParts>},
{"RippleFixMapParts", nullptr},
{"RotateMapParts", nullptr},
{"RotateMapParts", al::createActorFunction<al::RotateMapParts>},
{"SeesawMapParts", nullptr},
{"SlideMapParts", nullptr},
{"SubActorLodMapParts", nullptr},
Expand Down

0 comments on commit 769899d

Please sign in to comment.