|
| 1 | +#include "Shiraiwa/AnmPlayer.h" |
| 2 | +#include "JSystem/J3D/J3DAnmLoader.h" |
| 3 | +#include "JSystem/J3D/J3DFrameCtrl.h" |
| 4 | +#include "JSystem/JUtility/JUTAssert.h" |
| 5 | +#include "Osako/ResMgr.h" |
| 6 | +#include "Sato/AnmController.h" |
| 7 | +#include "Sato/J3DAnmObject.h" |
| 8 | + |
| 9 | +TAnmPlayer::TAnmPlayer() { |
| 10 | + mController = nullptr; |
| 11 | + mAnmInfo = nullptr; |
| 12 | + _e = 0; |
| 13 | + _10 = 0; |
| 14 | +} |
| 15 | + |
| 16 | +TAnmPlayer::~TAnmPlayer() {} |
| 17 | + |
| 18 | +void TAnmPlayer::resetAnimations(TAnmInfo *anmInfo, u8 n) { |
| 19 | + for (u8 i = 0; i < n; i++) { |
| 20 | + anmInfo[i].mTransAnm = nullptr; |
| 21 | + anmInfo[i].mCalcAnm = nullptr; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +void TAnmPlayer::loadAnimations(TAnmInfo *anmInfo, u8 n, J3DModelData *mdlData, ResMgr::ArchiveId archiveID) { |
| 26 | + u8 i; |
| 27 | + for (i = 0; i < n; i++) { |
| 28 | +#line 67 |
| 29 | + void *bck = ResMgr::getPtr(archiveID, anmInfo[i].mBckName); |
| 30 | + JUT_ASSERT_F(bck, "load failed: %s from archive id %d", anmInfo[i].mBckName, archiveID); |
| 31 | + J3DAnmObjTrans::loadTransAnm(&anmInfo[i].mTransAnm, bck); |
| 32 | + } |
| 33 | + |
| 34 | + for (i = 0; i < n; i++) { |
| 35 | + s8 i2 = anmInfo[i]._12; |
| 36 | + if (anmInfo[i].mBlendFrameCnt && i2 < n) { |
| 37 | + anmInfo[i].mCalcAnm = J3DUNewMtxCalcAnm(mdlData->getMtxCalcType(), anmInfo[i].mTransAnm, anmInfo[i2].mTransAnm, nullptr, nullptr, MTXCalc_Blend); |
| 38 | + } |
| 39 | + else { |
| 40 | + anmInfo[i].mCalcAnm = J3DNewMtxCalcAnm(mdlData->getMtxCalcType(), anmInfo[i].mTransAnm); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +void TAnmPlayer::registAnimations(AnmController *ctrl, ExModel *model, TAnmInfo *anmInfo, u8 n) { |
| 46 | + ctrl->InitRegistration(n, model); |
| 47 | + |
| 48 | + for (u8 i = 0; i < n; i++) { |
| 49 | + if (anmInfo[i].mBlendFrameCnt) { |
| 50 | + ctrl->RegisterTransBlend(i, anmInfo[i].mTransAnm, anmInfo[i].mCalcAnm); |
| 51 | + } |
| 52 | + else { |
| 53 | + ctrl->RegisterTrans(i, anmInfo[i].mTransAnm, anmInfo[i].mCalcAnm); |
| 54 | + } |
| 55 | + ctrl->getFrameCtrl(i)->setAttribute(anmInfo[i].mAnmCnt); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +void TAnmPlayer::init(AnmController *ctrl, TAnmInfo *info, u8 n) { |
| 60 | + mController = ctrl; |
| 61 | + mAnmInfo = info; |
| 62 | + mMaxAnm = n; |
| 63 | + reset(); |
| 64 | +} |
| 65 | + |
| 66 | +void TAnmPlayer::reset() { |
| 67 | + _d = 1; |
| 68 | + _e = 0; |
| 69 | + _11 = -1; |
| 70 | + _14 = -1.0f; |
| 71 | + |
| 72 | + mController->ChangeTransAnm(0); |
| 73 | + mController->Reset(); |
| 74 | + |
| 75 | + _10 = 1; |
| 76 | + _e = 0; |
| 77 | + firstEndCheck(0); |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +void TAnmPlayer::update() { |
| 82 | + if (mAnmInfo == nullptr || !_10) { |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + u8 anmNumber = getCurAnmNumber(); |
| 87 | + if (!mController->IsTransAnm2()) { |
| 88 | + if (_e & 1 || _e & 2 && isCurAnmReachEnd()) { |
| 89 | + s8 anmNo = (_11 != -1) ? _11 : mAnmInfo[getCurAnmNumber()].get_12(); |
| 90 | + |
| 91 | + _11 = -1; |
| 92 | + |
| 93 | + if (anmNo != -1 && anmNo < mMaxAnm) { |
| 94 | + _d = 1; |
| 95 | + |
| 96 | + if (mAnmInfo[anmNumber].mBlendFrameCnt) { |
| 97 | + mController->ChangeBlendTransAnm(anmNo, mAnmInfo[anmNumber].mBlendFrameCnt, 1); |
| 98 | + } |
| 99 | + else { |
| 100 | + mController->ChangeTransAnm(anmNo); |
| 101 | + } |
| 102 | + _e = 0; |
| 103 | + firstEndCheck(anmNo); |
| 104 | + } |
| 105 | + else { |
| 106 | + _10 = 0; |
| 107 | + } |
| 108 | + } |
| 109 | + else { |
| 110 | +#line 190 |
| 111 | + JUT_MINMAX_ASSERT(0, anmNumber, mMaxAnm); |
| 112 | + |
| 113 | + u8 anmNo = mAnmInfo[anmNumber]._11; |
| 114 | + if (anmNo != 0 && isGoArroundLoop()) { |
| 115 | + ++_d; |
| 116 | + if (_d >= anmNo - 1) { |
| 117 | + _10 = 1; |
| 118 | + _e |= 2; |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + _14 = mController->getFrameCtrl(getCurAnmNumber())->getFrame(); |
| 125 | +} |
| 126 | + |
| 127 | +void TAnmPlayer::firstEndCheck(u8 anmNumber) { |
| 128 | +#line 210 |
| 129 | + JUT_MINMAX_ASSERT(0, anmNumber, mMaxAnm); |
| 130 | + if (mAnmInfo[anmNumber]._11 == 1 || mAnmInfo[anmNumber].mAnmCnt == 0) { |
| 131 | + _10 = 1; |
| 132 | + _e |= 2; |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +bool TAnmPlayer::isCurAnmReachEnd() { |
| 137 | + bool ret = false; |
| 138 | + if (mController->getCurFrameCtrl()->checkState(1) || checkFrameEnd() || isFitBlendFrame()) { |
| 139 | + ret = true; |
| 140 | + } |
| 141 | + return ret; |
| 142 | +} |
| 143 | + |
| 144 | +bool TAnmPlayer::checkFrameEnd() { |
| 145 | + bool ret = false; |
| 146 | + |
| 147 | + if (_14 == -1.0f) { |
| 148 | + return false; |
| 149 | + } |
| 150 | + |
| 151 | + J3DFrameCtrl *ctrl = mController->getFrameCtrl(getCurAnmNumber()); |
| 152 | + |
| 153 | + switch (mAnmInfo[getCurAnmNumber()].mAnmCnt) { |
| 154 | + case 0: { |
| 155 | + if (ctrl->getFrame() > ctrl->getEnd() - ctrl->getRate()) { |
| 156 | + ret = true; |
| 157 | + } |
| 158 | + break; |
| 159 | + } |
| 160 | + case 1: { |
| 161 | + break; |
| 162 | + } |
| 163 | + case 2: { |
| 164 | + if ((ctrl->getFrame() - _14) * ctrl->getRate() < 0.0f) { |
| 165 | + ret = true; |
| 166 | + } |
| 167 | + break; |
| 168 | + } |
| 169 | + } |
| 170 | + return ret; |
| 171 | +} |
| 172 | + |
| 173 | +bool TAnmPlayer::isFitBlendFrame() { |
| 174 | + bool ret = false; |
| 175 | + u8 anmNumber = getCurAnmNumber(); |
| 176 | +#line 268 |
| 177 | + JUT_MINMAX_ASSERT(0, anmNumber, mMaxAnm); |
| 178 | + |
| 179 | + if (mAnmInfo[anmNumber].mBlendFrameCnt) { |
| 180 | + f32 frame = mController->getFrameCtrl(getCurAnmNumber())->getFrame(); |
| 181 | + f32 end = mController->getFrameCtrl(getCurAnmNumber())->getEnd(); |
| 182 | + if (end - frame <= mAnmInfo[anmNumber].mBlendFrameCnt) { |
| 183 | + ret = true; |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + return ret; |
| 188 | +} |
| 189 | + |
| 190 | +bool TAnmPlayer::isGoArroundLoop() { |
| 191 | + return mController->getFrameCtrl(getCurAnmNumber())->checkState(2); |
| 192 | +} |
0 commit comments