do some random functions, ModelUtil, and move J3DModel to its proper location

This commit is contained in:
shibbo 2020-01-10 23:49:36 -05:00
parent d1ec5f3780
commit f7cb317d13
7 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,20 @@
#ifndef BCKCTRL_H
#define BCKCTRL_H
#include "types.h"
class BckCtrlData
{
public:
BckCtrlData();
u32 _0;
s16 _4;
s16 _6;
s16 _8;
s16 _A;
s16 _C;
u16 _E;
};
#endif // BCKCTRL_H

View File

@ -12,6 +12,11 @@ namespace MR
bool isNearZero(const JGeometry::TVec3<f32> &, f32);
f32 mod(f32, f32);
void normalize(JGeometry::TVec3<f32> *);
f32 getRandom();
f32 getRandom(f32, f32);
f32 getRandom(s32, s32);
f32 getRandomDegree();
};
#endif // MATHUTIL_H

View File

@ -3,6 +3,7 @@
#include "Actor/LiveActor/LiveActor.h"
#include "Model/J3D/J3DModel.h"
#include "OS/OSMutex.h"
namespace MR
{
@ -10,6 +11,8 @@ namespace MR
void calcAnimModelManager(LiveActor *);
J3DModel* getJ3DModel(const LiveActor *);
void calcJ3DModel(LiveActor *);
s16 getBckFrameMax(const LiveActor *, const char *);
ResourceHolder* getResourceHolder(const LiveActor *);
ResourceHolder* getModelResourceHolder(const LiveActor *);
@ -18,6 +21,13 @@ namespace MR
void syncJointAnimation(LiveActor *, const LiveActor *);
void syncMaterialAnimation(LiveActor *, const LiveActor *);
template<int T>
class MutexHolder
{
public:
static OSMutex sMutex;
};
}
#endif // MODELUTIL_H

View File

@ -13,7 +13,8 @@ public:
bool isExistMaterialAnim();
ResTable* mResourceTable; // _0
u8 _4[0x38-0x4];
ResTable* _4;
u8 _8[0x38-0x8];
u32 _38;
u32 _3C;
u32 _40;

View File

@ -11,4 +11,15 @@ namespace MR
{
return (a2 + (a1 / a4) * (a3 - a2));
}
f32 getRandom(f32 min, f32 max)
{
return min + ((max - min) * getRandom());
}
f32 getRandomDegree()
{
// todo -- figure out why 0.0f get omitted
return 0.0f + (360.0f * getRandom());
}
};

View File

@ -1,4 +1,5 @@
#include "MR/ModelUtil.h"
#include "Animation/BckCtrl.h"
namespace MR
{
@ -22,6 +23,13 @@ namespace MR
return pActor->mModelManager->getJ3DModel();
}
void calcJ3DModel(LiveActor *pActor)
{
OSLockMutex(&MR::MutexHolder<0>::sMutex);
MR::getJ3DModel(pActor)->calc();
OSUnlockMutex(&MR::MutexHolder<0>::sMutex);
}
J3DModelData* getJ3DModelData(const LiveActor *pActor)
{
if (pActor->mModelManager == 0)
@ -32,6 +40,12 @@ namespace MR
return pActor->mModelManager->getJ3DModelData();
}
s16 getBckFrameMax(const LiveActor *pActor, const char *pBck)
{
BckCtrlData* data = (BckCtrlData*)MR::getResourceHolder(pActor)->_4->getRes(pBck);
return data->_6;
}
ResourceHolder* getResourceHolder(const LiveActor *pActor)
{
if (pActor->mModelManager != 0)