Skip to content

Commit

Permalink
take: Decompile motsys2.c
Browse files Browse the repository at this point in the history
  • Loading branch information
entriphy committed Jul 5, 2023
1 parent 8f3d904 commit 4d22e12
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/take.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "kit.h"
#include "objwork.h"

#define DECADDR0 ((sceVu0FMATRIX *)0x70000000)
#define DECADDR1 ((sceVu0FMATRIX *)0x70001000)

// Structs

typedef struct { // 0x38
Expand Down Expand Up @@ -471,6 +474,12 @@ extern void DecodeMotion(sceVu0FMATRIX *DecodeBuff, MOTION *m, s32 Ind);
extern void ClearQwordMem(u32 Addrs, u32 Num);
extern void AcxDecodeMotion(sceVu0FMATRIX *DecodeBuff, MOTION *m, s32 Ind);

// motsys2.c
extern void GetSfxWorldMatrix(SFXOBJ *pObj);
extern void SetActCnt(SFXOBJ *pObj, f32 Cnt);
extern void SetActSpeed(SFXOBJ *pObj, f32 Speed);
extern void WorldIpMotion(SFXOBJ *pObj);

// ndhit.c
extern OBJWORK* SetNdhit(sceVu0FVECTOR Vec);
extern void NdhitEnvInit(NDHIT *pNh);
Expand Down
222 changes: 222 additions & 0 deletions src/take/motsys2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#include "common.h"

void GetSfxWorldMatrix(SFXOBJ *pObj) {
s32 i;
s32 ii;
s32 Ind;
f32 BaseFrameWeight;
s32 MbStackIndex[6];
s32 MbStack[6][4];
MOTION *m;
s32 BaseIndex;
s32 IpIndex;

m = pObj->pMot;
IpIndex = 0;
for (i = 0; i < 6; i++) {
MbStackIndex[i] = 0;
}
for (i = 0; i < 4; i++) {
MbStack[m->Mb[i].Type][MbStackIndex[m->Mb[i].Type]] = i;
MbStackIndex[m->Mb[i].Type]++;
}
BaseIndex = MbStack[1][0];
m->BaseIndex = BaseIndex;
BaseFrameWeight = m->Mb[BaseIndex].MotionCnt / m->Mb[BaseIndex].MotionEndCnt;
if (MbStackIndex[2] != 0) {
f32 yeet; // idk how to match this without adding a variable but it works
m->IpIndex = IpIndex = MbStack[2][0];
yeet = m->Mb[IpIndex].MotionEndCnt;
if (m->Mb[BaseIndex].SyncFlag != 0 && m->Mb[BaseIndex].SyncFlag == m->Mb[IpIndex].SyncFlag) {
m->Mb[IpIndex].MotionCnt = BaseFrameWeight * yeet;
}
}

DecodeMotion(DECADDR0, m, BaseIndex);
if (MbStackIndex[2] != 0) {
DecodeMotion(DECADDR1, m, IpIndex);
if (MbStackIndex[2] != 0) {
for (i = 0; i < m->CoordNum; i++) {
LinerInterPolateMatrix(DECADDR0[i], DECADDR0[i], DECADDR1[i], m->Mb[IpIndex].Weight);
}
}
}

m->Mb[BaseIndex].MotionCnt += m->Mb[BaseIndex].CntSpeed;
if (MbStackIndex[2] != 0) {
if (m->Mb[BaseIndex].CntSpeed > 0.0f) {
m->Mb[IpIndex].MotionCnt += m->Mb[IpIndex].CntSpeed;
m->Mb[IpIndex].Weight -= m->Mb[IpIndex].Weight / m->Mb[IpIndex].OutCnt;
m->Mb[IpIndex].OutCnt -= m->Mb[BaseIndex].CntSpeed;
} else if (m->Mb[BaseIndex].CntSpeed < 0.0f) {
m->Mb[IpIndex].MotionCnt += m->Mb[IpIndex].CntSpeed;
m->Mb[IpIndex].Weight -= m->Mb[IpIndex].Weight / m->Mb[IpIndex].OutCnt;
m->Mb[IpIndex].OutCnt += m->Mb[BaseIndex].CntSpeed;
}

if (m->Mb[IpIndex].OutCnt <= 0.0f) {
m->Mb[IpIndex].Type = 0;
for (i = 0; i < MbStackIndex[4]; i++) {
m->Mb[MbStack[4][i]].Type = 0;
}
}
}

for (i = 1; i < 5; i++) {
for (ii = 0; ii < MbStackIndex[i]; ii++) {
Ind = MbStack[i][ii];
m->EndFlag = 0;
if (m->Mb[Ind].StopFlag != 0) {
if (m->Mb[Ind].MotionCnt >= m->Mb[Ind].MotionEndCnt) {
m->Mb[Ind].MotionCnt = m->Mb[Ind].MotionEndCnt;
if (m->Mb[Ind].Type == 1)
m->EndFlag = 1;
}
if (m->Mb[Ind].MotionCnt < 0.0f)
m->Mb[Ind].MotionCnt = 0.0f;
} else {
if (m->Mb[Ind].MotionCnt >= m->Mb[Ind].MotionEndCnt) {
if (m->Mb[Ind].Type == 1)
m->EndFlag = 2;
do
m->Mb[Ind].MotionCnt -= m->Mb[Ind].MotionEndCnt;
while (!(m->Mb[Ind].MotionEndCnt > m->Mb[Ind].MotionCnt));
}

if (m->Mb[Ind].MotionCnt < 0.0f) {
if (m->Mb[Ind].Type == 1)
m->EndFlag = 2;
do
m->Mb[Ind].MotionCnt = m->Mb[Ind].MotionEndCnt + m->Mb[Ind].MotionCnt;
while (!(0 <= m->Mb[Ind].MotionCnt));
}
}
}
}

if (MbStackIndex[5] != 0) {
WorldIpMotion(pObj);
}

for (i = 0; i < m->CoordNum; i++) {
sceVu0CopyMatrix(m->pCoord[i].Mtx, DECADDR0[i]);
m->pCoord[i].Flag = 0;
}

for (i = 0; i < m->CoordNum; i++) {
GetLwMtx(&m->pCoord[i]);
}

if (m->pBaseCoord->Flag > -1) {
GetRotTransMatrixXYZ(m->pBaseCoord->Mtx, m->pBaseCoord->Rot, m->pBaseCoord->Trans);
}

for (i = 0; i < m->CoordNum; i++) {
sceVu0MulMatrix(m->pCoord[i].Mtx, m->pBaseCoord->Mtx, m->pCoord[i].Mtx);
}
}

void SetActCnt(SFXOBJ *pObj, f32 Cnt) {
SFXOBJ *pObjTmp;
s32 Ind;
MOTION *m;

pObjTmp = GetActiveSfx(pObj);
if (pObjTmp == NULL)
return;

Ind = pObjTmp->pMot->BaseIndex;
m = pObjTmp->pMot;
m->Mb[Ind].MotionCnt = Cnt;
if (m->Mb[Ind].StopFlag != 0) {
if (m->Mb[Ind].MotionEndCnt <= Cnt) {
m->Mb[Ind].MotionCnt = m->Mb[Ind].MotionEndCnt;
if (m->Mb[Ind].Type == 1) {
m->EndFlag = 1;
}
}
if (m->Mb[Ind].MotionCnt < 0.0f) {
m->Mb[Ind].MotionCnt = 0.0f;
}
} else {
if (m->Mb[Ind].MotionCnt >= m->Mb[Ind].MotionEndCnt) {
if (m->Mb[Ind].Type == 1)
m->EndFlag = 2;
do
m->Mb[Ind].MotionCnt -= m->Mb[Ind].MotionEndCnt;
while (!(m->Mb[Ind].MotionEndCnt > m->Mb[Ind].MotionCnt));
}

if (m->Mb[Ind].MotionCnt < 0.0f) {
if (m->Mb[Ind].Type == 1)
m->EndFlag = 2;
do
m->Mb[Ind].MotionCnt = m->Mb[Ind].MotionEndCnt + m->Mb[Ind].MotionCnt;
while (!(0 <= m->Mb[Ind].MotionCnt));
}
}
}

void SetActSpeed(SFXOBJ *pObj, f32 Speed) {
pObj->pMot->Mb[pObj->pMot->BaseIndex].CntSpeed = Speed;
}

void WorldIpMotion(SFXOBJ *pObj) {
s32 i;
s32 Ind;
s32 total;
MOTION *m;
sceVu0FMATRIX TmpMtx;

m = pObj->pMot;
for (i = 0; i < 4; i++) {
if (m->Mb[i].Type == 5) {
Ind = i;
break;
}
}

for (i = 0; i < m->CoordNum; i++) {
sceVu0CopyMatrix(m->pCoord[i].Mtx, DECADDR0[i]);
m->pCoord[i].Flag = 0;
}

for (i = 0; i < m->CoordNum; i++) {
GetLwMtx(&m->pCoord[i]);
}

if (m->pBaseCoord->Flag >= 0) {
GetRotTransMatrixXYZ(m->pBaseCoord->Mtx, m->pBaseCoord->Rot, m->pBaseCoord->Trans);
}

for (i = 0; i < m->CoordNum; i++) {
sceVu0MulMatrix(m->pCoord[i].Mtx, m->pBaseCoord->Mtx, m->pCoord[i].Mtx);
}

total = 0;
for (i = 0; i < m->CoordNum; i++) {
if ((m->Mb[Ind].OnFlag >> i) & 1 && m->pCoord[i].WipCnt > 0.0f) {
InterPolateMatrix(m->pCoord[i].Mtx, m->pCoord[i].MtxSav, m->pCoord[i].Mtx, 1.0f / m->pCoord[i].WipCnt);
sceVu0CopyMatrix(m->pCoord[i].MtxSav, m->pCoord[i].Mtx);
m->pCoord[i].WipCnt -= m->Mb[m->BaseIndex].CntSpeed;
if (m->pCoord[i].WipCnt <= 0.0f) {
m->pCoord[i].WipCnt = 0.0f;
}
total++;
}
}

if (total == 0) {
m->Mb[Ind].Type = 0;
} else {
for (i = 0; i < m->CoordNum; i++) {
if (m->pCoord[i].Super != NULL) {
ChangeLocalMatrix(TmpMtx, m->pCoord[i].Super->Mtx, m->pCoord[i].Mtx);
CopyRotMatrix(DECADDR0[i], TmpMtx);
} else {
ChangeLocalMatrix(TmpMtx, m->pBaseCoord->Mtx, m->pCoord[i].Mtx);
CopyRotMatrix(DECADDR0[i], TmpMtx);
}
}
}
}

0 comments on commit 4d22e12

Please sign in to comment.