| 1 | #include "Library/Obj/BreakModel.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorActionFunction.h" |
| 4 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 5 | #include "Library/LiveActor/ActorInitUtil.h" |
| 6 | #include "Library/LiveActor/ActorModelFunction.h" |
| 7 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 8 | #include "Library/LiveActor/ActorResourceFunction.h" |
| 9 | #include "Library/Math/MathUtil.h" |
| 10 | #include "Library/Nerve/NerveSetupUtil.h" |
| 11 | #include "Library/Nerve/NerveUtil.h" |
| 12 | #include "Library/Yaml/ByamlIter.h" |
| 13 | #include "Library/Yaml/ByamlUtil.h" |
| 14 | |
| 15 | namespace { |
| 16 | using namespace al; |
| 17 | NERVE_IMPL(BreakModel, Wait); |
| 18 | NERVE_IMPL(BreakModel, Break); |
| 19 | |
| 20 | NERVES_MAKE_NOSTRUCT(BreakModel, Wait, Break); |
| 21 | } // namespace |
| 22 | |
| 23 | namespace al { |
| 24 | BreakModel::BreakModel(const LiveActor* rootActor, const char* objName, const char* modelName, |
| 25 | const char* fileSuffixName, const sead::Matrix34f* rootMtx, |
| 26 | const char* breakActionName) |
| 27 | : LiveActor(objName), mParent(rootActor), mRootMtx(rootMtx), mModelName(modelName), |
| 28 | mBreakAction(breakActionName), mInitSuffix(fileSuffixName) {} |
| 29 | |
| 30 | void BreakModel::init(const ActorInitInfo& initInfo) { |
| 31 | initActorWithArchiveName(actor: this, initInfo, archiveName: mModelName, suffix: mInitSuffix); |
| 32 | initNerve(actor: this, nerve: &Wait, maxStates: 0); |
| 33 | invalidateClipping(actor: this); |
| 34 | |
| 35 | ByamlIter actorInitFile; |
| 36 | |
| 37 | if (tryGetActorInitFileIter(&actorInitFile, this, "InitBreakModel" , mInitSuffix)) { |
| 38 | ByamlIter dither; |
| 39 | if (actorInitFile.tryGetIterByKey(iter: &dither, key: "DitherDisappear" )) { |
| 40 | mIsValid = tryGetByamlKeyBoolOrFalse(dither, "IsValid" ); |
| 41 | if (mIsValid) |
| 42 | mStep = getByamlKeyInt(dither, "Step" ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | makeActorDead(); |
| 47 | } |
| 48 | |
| 49 | void BreakModel::appear() { |
| 50 | if (mRootMtx) |
| 51 | updatePoseMtx(actor: this, mtx: mRootMtx); |
| 52 | else |
| 53 | copyPose(actor: this, target: mParent); |
| 54 | |
| 55 | if (mBreakAction) { |
| 56 | startAction(actor: this, actionName: mBreakAction); |
| 57 | if (!isNearZero(value: 1.0f - mActionFrameRate)) |
| 58 | setActionFrameRate(actor: this, rate: mActionFrameRate); |
| 59 | } |
| 60 | setNerve(user: this, nerve: &Break); |
| 61 | |
| 62 | LiveActor::makeActorAlive(); |
| 63 | } |
| 64 | |
| 65 | void BreakModel::exeWait() {} |
| 66 | |
| 67 | void BreakModel::exeBreak() { |
| 68 | if (mIsValid) { |
| 69 | if (mBreakAction) { |
| 70 | f32 ditherStart = getActionFrameMax(actor: this, actionName: mBreakAction) < mStep ? |
| 71 | 0.0f : |
| 72 | getActionFrameMax(actor: this, actionName: mBreakAction) - mStep; |
| 73 | |
| 74 | setModelAlphaMask(actor: this, 1.0f - normalize(x: (f32)getNerveStep(user: this), min: ditherStart, |
| 75 | max: getActionFrameMax(actor: this, actionName: mBreakAction))); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (isActionEnd(actor: this)) |
| 80 | kill(); |
| 81 | } |
| 82 | |
| 83 | } // namespace al |
| 84 | |