From 6b948adff03b8aeee1f5b9bea5fb37bf5a89997d Mon Sep 17 00:00:00 2001 From: german77 <5944268+german77@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:16:10 -0600 Subject: [PATCH] item: Implement CoinCollectEmpty2D --- data/odyssey_functions.csv | 24 +++--- lib/al/Library/Model/ModelShapeUtil.h | 10 +++ src/Item/CoinCollectEmpty2D.cpp | 103 ++++++++++++++++++++++++++ src/Item/CoinCollectEmpty2D.h | 35 +++++++++ src/Util/ActorDimensionUtil.h | 15 ++++ src/Util/SensorMsgFunction.h | 1 + 6 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 lib/al/Library/Model/ModelShapeUtil.h create mode 100644 src/Item/CoinCollectEmpty2D.cpp create mode 100644 src/Item/CoinCollectEmpty2D.h create mode 100644 src/Util/ActorDimensionUtil.h diff --git a/data/odyssey_functions.csv b/data/odyssey_functions.csv index f2a3a747..2a3515d5 100644 --- a/data/odyssey_functions.csv +++ b/data/odyssey_functions.csv @@ -10885,18 +10885,18 @@ Address,Quality,Size,Name 0x00000071001c1704,U,000072,_ZNK12_GLOBAL__N_123CoinCollectEmptyNrvWait7executeEPN2al11NerveKeeperE 0x00000071001c174c,U,000008,_ZNK12_GLOBAL__N_126CoinCollectEmptyNrvCountUp7executeEPN2al11NerveKeeperE 0x00000071001c1754,U,000008,_ZNK12_GLOBAL__N_122CoinCollectEmptyNrvGot7executeEPN2al11NerveKeeperE -0x00000071001c175c,U,000160,_ZN18CoinCollectEmpty2DC2EPKcS1_ -0x00000071001c17fc,U,000148,_ZN18CoinCollectEmpty2DC1EPKcS1_ -0x00000071001c1890,U,000200,_ZN18CoinCollectEmpty2D4initERKN2al13ActorInitInfoE -0x00000071001c1958,U,000220,_ZN18CoinCollectEmpty2D18initAfterPlacementEv -0x00000071001c1a34,U,000044,_ZN18CoinCollectEmpty2D10endClippedEv -0x00000071001c1a60,U,000120,_ZN18CoinCollectEmpty2D10receiveMsgEPKN2al9SensorMsgEPNS0_9HitSensorES5_ -0x00000071001c1ad8,U,000016,_ZN18CoinCollectEmpty2D7exeWaitEv -0x00000071001c1ae8,U,000140,_ZN18CoinCollectEmpty2D6exeGotEv -0x00000071001c1b74,U,000008,_ZNK18CoinCollectEmpty2D23getActorDimensionKeeperEv -0x00000071001c1b7c,U,000008,_ZThn264_NK18CoinCollectEmpty2D23getActorDimensionKeeperEv -0x00000071001c1b84,U,000020,_ZNK12_GLOBAL__N_125CoinCollectEmpty2DNrvWait7executeEPN2al11NerveKeeperE -0x00000071001c1b98,U,000008,_ZNK12_GLOBAL__N_124CoinCollectEmpty2DNrvGot7executeEPN2al11NerveKeeperE +0x00000071001c175c,O,000160,_ZN18CoinCollectEmpty2DC2EPKcS1_ +0x00000071001c17fc,O,000148,_ZN18CoinCollectEmpty2DC1EPKcS1_ +0x00000071001c1890,O,000200,_ZN18CoinCollectEmpty2D4initERKN2al13ActorInitInfoE +0x00000071001c1958,O,000220,_ZN18CoinCollectEmpty2D18initAfterPlacementEv +0x00000071001c1a34,O,000044,_ZN18CoinCollectEmpty2D10endClippedEv +0x00000071001c1a60,O,000120,_ZN18CoinCollectEmpty2D10receiveMsgEPKN2al9SensorMsgEPNS0_9HitSensorES5_ +0x00000071001c1ad8,O,000016,_ZN18CoinCollectEmpty2D7exeWaitEv +0x00000071001c1ae8,O,000140,_ZN18CoinCollectEmpty2D6exeGotEv +0x00000071001c1b74,O,000008,_ZNK18CoinCollectEmpty2D23getActorDimensionKeeperEv +0x00000071001c1b7c,O,000008,_ZThn264_NK18CoinCollectEmpty2D23getActorDimensionKeeperEv +0x00000071001c1b84,O,000020,_ZNK12_GLOBAL__N_125CoinCollectEmpty2DNrvWait7executeEPN2al11NerveKeeperE +0x00000071001c1b98,O,000008,_ZNK12_GLOBAL__N_124CoinCollectEmpty2DNrvGot7executeEPN2al11NerveKeeperE 0x00000071001c1ba0,U,000064,_ZN20CoinCollectHintStateC2EPN2al9LiveActorE 0x00000071001c1be0,U,000016,_ZN20CoinCollectHintState4initEv 0x00000071001c1bf0,U,000072,_ZN20CoinCollectHintState6appearEv diff --git a/lib/al/Library/Model/ModelShapeUtil.h b/lib/al/Library/Model/ModelShapeUtil.h new file mode 100644 index 00000000..198a7b3a --- /dev/null +++ b/lib/al/Library/Model/ModelShapeUtil.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace al { +class ModelKeeper; + +void setModelProjMtx0(const ModelKeeper*, const sead::Matrix44f&); + +} // namespace al diff --git a/src/Item/CoinCollectEmpty2D.cpp b/src/Item/CoinCollectEmpty2D.cpp new file mode 100644 index 00000000..6d92a813 --- /dev/null +++ b/src/Item/CoinCollectEmpty2D.cpp @@ -0,0 +1,103 @@ +#include "Item/CoinCollectEmpty2D.h" + +#include +#include + +#include "Library/Collision/PartsConnector.h" +#include "Library/LiveActor/ActorActionFunction.h" +#include "Library/LiveActor/ActorClippingFunction.h" +#include "Library/LiveActor/ActorInitInfo.h" +#include "Library/LiveActor/ActorPoseKeeper.h" +#include "Library/LiveActor/ActorSensorMsgFunction.h" +#include "Library/Matrix/MatrixUtil.h" +#include "Library/Model/ModelShapeUtil.h" +#include "Library/Nerve/NerveSetupUtil.h" +#include "Library/Nerve/NerveUtil.h" + +#include "System/GameDataFunction.h" +#include "Util/ActorDimensionKeeper.h" +#include "Util/ActorDimensionUtil.h" +#include "Util/ItemUtil.h" +#include "Util/SensorMsgFunction.h" + +namespace { +NERVE_IMPL(CoinCollectEmpty2D, Wait); +NERVE_IMPL(CoinCollectEmpty2D, Got); + +struct { + NERVE_MAKE(CoinCollectEmpty2D, Wait); + NERVE_MAKE(CoinCollectEmpty2D, Got); +} NrvCoinCollectEmpty2D; + +} // namespace + +CoinCollectEmpty2D::CoinCollectEmpty2D(const char* name, const char* archiveName) + : al::LiveActor(name), IUseDimension(), mArchiveName(archiveName) {} + +void CoinCollectEmpty2D::init(const al::ActorInitInfo& initInfo) { + al::initActorSceneInfo(this, initInfo); + al::initActorWithArchiveName(this, initInfo, mArchiveName, nullptr); + al::tryAddDisplayOffset(this, initInfo); + mMtxConnector = al::tryCreateMtxConnector(this, initInfo); + mDimensionKeeper = rs::createDimensionKeeper(this); + rs::updateDimensionKeeper(mDimensionKeeper); + rs::snap2DParallelizeFront(this, this, 500.0f); + al::initNerve(this, &NrvCoinCollectEmpty2D.Wait, 0); + al::startAction(this, "Wait"); + makeActorAlive(); +} + +void CoinCollectEmpty2D::initAfterPlacement() { + if (mMtxConnector != nullptr) + al::attachMtxConnectorToCollision(mMtxConnector, this, false); + + sead::Matrix44f matrix = sead::Matrix44f::ident; + sead::Vector3f frontDir = sead::Vector3f::zero; + sead::Vector3f upDir = sead::Vector3f::zero; + al::calcFrontDir(&frontDir, this); + al::calcUpDir(&upDir, this); + const sead::Vector2f aDir(100.0f, 100.0f); + al::makeMtxProj(&matrix, aDir, frontDir, upDir); + const sead::Vector3f& objTrans = al::getTrans(this); + matrix.setCol(3, sead::Vector4f(objTrans.x, objTrans.y, objTrans.z, 1.0f)); + al::setModelProjMtx0(getModelKeeper(), matrix); +} + +bool CoinCollectEmpty2D::receiveMsg(const al::SensorMsg* message, al::HitSensor* other, + al::HitSensor* self) { + if (rs::isMsgItemGet2D(message) && al::isNerve(this, &NrvCoinCollectEmpty2D.Wait)) { + al::invalidateClipping(this); + al::setNerve(this, &NrvCoinCollectEmpty2D.Got); + return 1; + } + return al::isMsgPlayerDisregard(message); +} + +void CoinCollectEmpty2D::endClipped() { + rs::syncCoin2DAnimFrame(this, "Wait"); + al::LiveActor::endClipped(); +} + +ActorDimensionKeeper* CoinCollectEmpty2D::getActorDimensionKeeper() const { + return mDimensionKeeper; +} + +void CoinCollectEmpty2D::exeWait() { + if (mMtxConnector == nullptr) + return; + + al::connectPoseQT(this, mMtxConnector); +} + +void CoinCollectEmpty2D::exeGot() { + if (al::isFirstStep(this)) + al::startAction(this, "Got"); + + if (al::isActionEnd(this)) { + GameDataHolderAccessor gameData(this); + GameDataFunction::addCoin(gameData, 1); + GameDataHolderAccessor gameData2(this); + GameDataFunction::addCoin(gameData2, 1); + kill(); + } +} diff --git a/src/Item/CoinCollectEmpty2D.h b/src/Item/CoinCollectEmpty2D.h new file mode 100644 index 00000000..ee1fbeb5 --- /dev/null +++ b/src/Item/CoinCollectEmpty2D.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Library/LiveActor/LiveActor.h" + +#include "Util/IUseDimension.h" + +namespace al { +class ActorInitInfo; +class HitSensor; +class MtxConnector; +class SensorMsg; +} // namespace al + +class ActorDimensionKeeper; + +class CoinCollectEmpty2D : public al::LiveActor, public IUseDimension { +public: + CoinCollectEmpty2D(const char* name, const char* archiveName); + + void init(const al::ActorInitInfo& initInfo) override; + void initAfterPlacement() override; + bool receiveMsg(const al::SensorMsg* message, al::HitSensor* other, + al::HitSensor* self) override; + void endClipped() override; + + ActorDimensionKeeper* getActorDimensionKeeper() const override; + + void exeWait(); + void exeGot(); + +private: + al::MtxConnector* mMtxConnector = nullptr; + ActorDimensionKeeper* mDimensionKeeper = nullptr; + const char* mArchiveName = nullptr; +}; diff --git a/src/Util/ActorDimensionUtil.h b/src/Util/ActorDimensionUtil.h new file mode 100644 index 00000000..57babffe --- /dev/null +++ b/src/Util/ActorDimensionUtil.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace al { +class LiveActor; +} // namespace al + +class IUseDimension; + +namespace rs { + +void snap2DParallelizeFront(al::LiveActor*, const IUseDimension*, f32); + +} // namespace rs diff --git a/src/Util/SensorMsgFunction.h b/src/Util/SensorMsgFunction.h index 283679e4..6be4e2aa 100644 --- a/src/Util/SensorMsgFunction.h +++ b/src/Util/SensorMsgFunction.h @@ -9,6 +9,7 @@ class SensorMsg; namespace rs { +bool isMsgItemGet2D(const al::SensorMsg* msg); bool isMsgPlayerDisregardTargetMarker(const al::SensorMsg* msg); void requestHitReactionToAttacker(const al::SensorMsg*, const al::HitSensor*,