Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library/MapObj: Implement ConveyerStep #208

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions data/odyssey_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -58221,17 +58221,17 @@ Address,Quality,Size,Name
0x0000007100912ea8,U,000028,_ZNK2al10FunctorV0MIPNS_16ConveyerMapPartsEMS1_FvvEEclEv
0x0000007100912ec4,U,000076,_ZNK2al10FunctorV0MIPNS_16ConveyerMapPartsEMS1_FvvEE5cloneEv
0x0000007100912f10,U,000004,_ZN2al10FunctorV0MIPNS_16ConveyerMapPartsEMS1_FvvEED0Ev
0x0000007100912f14,U,000140,_ZN2al12ConveyerStepC2EPKc
0x0000007100912fa0,U,000152,_ZN2al12ConveyerStepC1EPKc
0x0000007100913038,U,000076,_ZN2al12ConveyerStep4initERKNS_13ActorInitInfoE
0x0000007100913084,U,000024,_ZN2al12ConveyerStep10receiveMsgEPKNS_9SensorMsgEPNS_9HitSensorES5_
0x000000710091309c,U,000008,_ZN2al12ConveyerStep7setHostEPNS_9LiveActorE
0x00000071009130a4,U,000012,_ZN2al12ConveyerStep20setConveyerKeyKeeperEPKNS_17ConveyerKeyKeeperEf
0x00000071009130b0,U,000012,_ZN2al12ConveyerStep15setTransByCoordEfb
0x00000071009130bc,U,000480,_ZN2al12ConveyerStep15setTransByCoordEfbb
0x000000710091329c,U,000012,_ZN2al12ConveyerStep23setTransAndResetByCoordEf
0x00000071009132a8,U,000004,_ZN2al12ConveyerStep7exeWaitEv
0x00000071009132ac,U,000004,
0x0000007100912f14,O,000140,_ZN2al12ConveyerStepC2EPKc
0x0000007100912fa0,O,000152,_ZN2al12ConveyerStepC1EPKc
0x0000007100913038,O,000076,_ZN2al12ConveyerStep4initERKNS_13ActorInitInfoE
0x0000007100913084,O,000024,_ZN2al12ConveyerStep10receiveMsgEPKNS_9SensorMsgEPNS_9HitSensorES5_
0x000000710091309c,O,000008,_ZN2al12ConveyerStep7setHostEPNS_9LiveActorE
0x00000071009130a4,O,000012,_ZN2al12ConveyerStep20setConveyerKeyKeeperEPKNS_17ConveyerKeyKeeperEf
0x00000071009130b0,O,000012,_ZN2al12ConveyerStep15setTransByCoordEfb
0x00000071009130bc,O,000480,_ZN2al12ConveyerStep15setTransByCoordEfbb
0x000000710091329c,O,000012,_ZN2al12ConveyerStep23setTransAndResetByCoordEf
0x00000071009132a8,O,000004,_ZN2al12ConveyerStep7exeWaitEv
0x00000071009132ac,O,000004,_ZNK12_GLOBAL__N_119ConveyerStepNrvWait7executeEPN2al11NerveKeeperE
0x00000071009132b0,O,000156,_ZN2al12FallMapPartsC2EPKc
0x000000710091334c,O,000168,_ZN2al12FallMapPartsC1EPKc
0x00000071009133f4,O,000164,_ZN2al12FallMapParts4initERKNS_13ActorInitInfoE
Expand Down
109 changes: 109 additions & 0 deletions lib/al/Library/MapObj/ConveyerStep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "Library/MapObj/ConveyerStep.h"

#include "Library/Base/StringUtil.h"
#include "Library/LiveActor/ActorActionFunction.h"
#include "Library/LiveActor/ActorClippingFunction.h"
#include "Library/LiveActor/ActorCollisionFunction.h"
#include "Library/LiveActor/ActorInitFunction.h"
#include "Library/LiveActor/ActorModelFunction.h"
#include "Library/LiveActor/ActorMovementFunction.h"
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/Math/MathUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Placement/PlacementFunction.h"
#include "Project/LiveActor/ConveyerKeyKeeper.h"

namespace {
using namespace al;

NERVE_IMPL(ConveyerStep, Wait)

NERVES_MAKE_STRUCT(ConveyerStep, Wait)
} // namespace

namespace al {
ConveyerStep::ConveyerStep(const char* name) : LiveActor(name) {}

void ConveyerStep::init(const ActorInitInfo& info) {
initMapPartsActor(this, info, nullptr);
initNerve(this, &NrvConveyerStep.Wait, 0);
onDrawClipping(this);

makeActorAlive();
}

bool ConveyerStep::receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) {
if (mHost != nullptr)
return mHost->receiveMsg(message, other, self);

return false;
}

void ConveyerStep::setHost(LiveActor* host) {
mHost = host;
}

void ConveyerStep::setConveyerKeyKeeper(const ConveyerKeyKeeper* conveyerKeyKeeper, f32 coord) {
mConveyerKeyKeeper = conveyerKeyKeeper;
mMaxCoord = coord;
}

void ConveyerStep::setTransByCoord(f32 coord, bool isForwards) {
setTransByCoord(coord, isForwards, false);
}

void ConveyerStep::setTransByCoord(f32 coord, bool isForwards, bool isForceReset) {
f32 newCoord = modf(mMaxCoord + coord, mMaxCoord) + 0.0f;
s32 index = -1;

mConveyerKeyKeeper->calcPosAndQuat(getTransPtr(this), getQuatPtr(this), &index, newCoord);

const char* keyHitReactionName = nullptr;
const char* actionName = nullptr;

if (index > -1) {
const ConveyerKey* conveyerKey = mConveyerKeyKeeper->getConveyerKey(index);

if (tryGetStringArg(&keyHitReactionName, conveyerKey->mPlacementInfo,
"KeyHitReactionName") &&
(mKeyHitReactionName == nullptr ||
!isEqualString(mKeyHitReactionName, keyHitReactionName)))
startHitReaction(this, keyHitReactionName);

if (tryGetStringArg(&actionName, conveyerKey->mPlacementInfo, "ActionName") &&
(mActionName == nullptr || !isEqualString(mActionName, actionName)))
startAction(this, actionName);
}

mKeyHitReactionName = keyHitReactionName;
mActionName = actionName;

if ((isForwards && newCoord < mCurrentCoord) || (!isForwards && newCoord > mCurrentCoord) ||
isForceReset)
resetPosition(this);

if (newCoord > mConveyerKeyKeeper->get_34()) {
if (mIsExist) {
mIsExist = false;
if (getModelKeeper() != nullptr && !isHideModel(this))
hideModel(this);
if (isExistCollisionParts(this))
invalidateCollisionParts(this);
}
} else if (!mIsExist) {
mIsExist = true;
if (getModelKeeper() != nullptr && isHideModel(this))
showModel(this);
if (isExistCollisionParts(this))
validateCollisionParts(this);
}

mCurrentCoord = newCoord;
}

void ConveyerStep::setTransAndResetByCoord(f32 coord) {
setTransByCoord(coord, true, true);
}

void ConveyerStep::exeWait() {}
} // namespace al
32 changes: 32 additions & 0 deletions lib/al/Library/MapObj/ConveyerStep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "Library/LiveActor/LiveActor.h"

namespace al {
class ConveyerKeyKeeper;

class ConveyerStep : public LiveActor {
public:
ConveyerStep(const char* name);

void init(const ActorInitInfo& info) override;
bool receiveMsg(const SensorMsg* message, HitSensor* other, HitSensor* self) override;

void setHost(LiveActor* host);
void setConveyerKeyKeeper(const ConveyerKeyKeeper* conveyerKeyKeeper, f32 coord);
void setTransByCoord(f32 coord, bool isForwards);
void setTransByCoord(f32 coord, bool isForwards, bool isForceReset);
void setTransAndResetByCoord(f32 coord);

void exeWait();

private:
LiveActor* mHost = nullptr;
const ConveyerKeyKeeper* mConveyerKeyKeeper = nullptr;
const char* mKeyHitReactionName = nullptr;
const char* mActionName = nullptr;
f32 mCurrentCoord = 0.0f;
f32 mMaxCoord = 0.0f;
bool mIsExist = true;
};
} // namespace al
1 change: 1 addition & 0 deletions lib/al/Library/Placement/PlacementFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void getStringArg(const ActorInitInfo& initInfo, const char* key);
void getStringArg(const PlacementInfo& placementInfo, const char* key);
void getStringArg(const AreaInitInfo& initInfo, const char* key);
bool tryGetStringArg(const char** arg, const ActorInitInfo& initInfo, const char* key);
bool tryGetStringArg(const char** arg, const PlacementInfo& initInfo, const char* key);
bool tryGetStringArg(const char** arg, const AreaInitInfo& initInfo, const char* key);
bool tryGetArgV2f(sead::Vector2f* arg, const ActorInitInfo& initInfo, const char* key);
bool tryGetArgV2f(sead::Vector2f* arg, const PlacementInfo& initInfo, const char* key);
Expand Down
36 changes: 36 additions & 0 deletions lib/al/Project/LiveActor/ConveyerKeyKeeper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <math/seadQuat.h>
#include <math/seadVector.h>

namespace al {
class ActorInitInfo;
class PlacementInfo;

// TODO: I'm not sure about this
struct ConveyerKey {
void* _0[5];
PlacementInfo& mPlacementInfo;
};

class ConveyerKeyKeeper {
public:
ConveyerKeyKeeper();

void init(const ActorInitInfo& info);
void calcPosAndQuat(sead::Vector3f* pos, sead::Quatf* quat, s32* index, f32 coord) const;
void calcPosAndQuatByKeyIndex(sead::Vector3f* pos, sead::Quatf* quat, s32 index) const;
void calcClippingSphere(sead::Vector3f* clippingTrans, f32* clippingRadius, f32 offset) const;
const ConveyerKey* getConveyerKey(s32 index) const; // return type depends on the type of _0

f32 get_34() const { return _34; }

private:
ConveyerKey** mConveyerKeys; // array of a struct/class with a size of 0x30?
s32 mConveyerKeyCount;
sead::Quatf mQuat;
sead::Vector3f mTrans;
sead::Vector3f _28;
f32 _34;
};
} // namespace al
Loading