Skip to content

Commit

Permalink
Fakematch J3DPEBlockFull::reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrkol committed Feb 9, 2025
1 parent 1f41941 commit 648aa48
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
6 changes: 3 additions & 3 deletions include/JSystem/J3D/J3DGraphBase/Components/J3DAlphaComp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
extern const u16 j3dDefaultAlphaCmpID;
extern u8 j3dAlphaCmpTable[768];

inline u16 calcAlphaCmpID(u32 comp0, u32 op, u32 comp1)
inline u16 calcAlphaCmpID(u8 comp0, u8 op, u8 comp1)
{
return (comp0 << 5) + ((op & 0xff) << 3) + (comp1 & 0xff);
return (comp0 << 5) + (op << 3) + comp1;
}

class J3DAlphaComp {
Expand Down Expand Up @@ -38,9 +38,9 @@ class J3DAlphaComp {

void setAlphaCompInfo(const J3DAlphaCompInfo& info)
{
mAlphaCmpID = calcAlphaCmpID(info.mComp0, info.mOp, info.mComp1);
mRef0 = info.mRef0;
mRef1 = info.mRef1;
mAlphaCmpID = calcAlphaCmpID(info.mComp0, info.mOp, info.mComp1);
}

GXCompare getComp0() const
Expand Down
6 changes: 6 additions & 0 deletions include/JSystem/J3D/J3DGraphBase/Components/J3DZMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class J3DZMode {
public:
J3DZMode() { mZModeID = j3dDefaultZModeID; }

J3DZMode& operator=(const J3DZMode& other)
{
mZModeID = other.mZModeID;
return *this;
}

u8 getCompareEnable() const { return j3dZModeTable[mZModeID * 3 + 0]; }
u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; }
u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; }
Expand Down
35 changes: 24 additions & 11 deletions include/JSystem/J3D/J3DGraphBase/J3DStruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class J3DLightInfo {
public:
void operator=(J3DLightInfo const& other)
J3DLightInfo& operator=(const J3DLightInfo& other)
{
mLightPosition.x = other.mLightPosition.x;
mLightPosition.y = other.mLightPosition.y;
Expand All @@ -28,6 +28,8 @@ class J3DLightInfo {
mDistAtten.x = other.mDistAtten.x;
mDistAtten.y = other.mDistAtten.y;
mDistAtten.z = other.mDistAtten.z;

return *this;
}

/* 0x00 */ Vec mLightPosition;
Expand All @@ -38,13 +40,14 @@ class J3DLightInfo {
}; // Size = 0x34

struct J3DTextureSRTInfo {
void operator=(const J3DTextureSRTInfo& other)
J3DTextureSRTInfo& operator=(const J3DTextureSRTInfo& other)
{
mScaleX = other.mScaleX;
mScaleY = other.mScaleY;
mRotation = other.mRotation;
mTranslationX = other.mTranslationX;
mTranslationY = other.mTranslationY;
return *this;
}

/* 0x00 */ f32 mScaleX;
Expand All @@ -70,7 +73,7 @@ enum J3DTexMtxMode {
};

struct J3DTexMtxInfo {
void operator=(J3DTexMtxInfo const& other)
J3DTexMtxInfo& operator=(const J3DTexMtxInfo& other)
{
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
Expand All @@ -83,6 +86,7 @@ struct J3DTexMtxInfo {
mProjection = other.mProjection;
mInfo = other.mInfo;
mSRT = other.mSRT;
return *this;
}
void setEffectMtx(Mtx m)
{
Expand Down Expand Up @@ -113,15 +117,17 @@ struct J3DTexMtxInfo {
}; // Size: 0x64

struct J3DIndTexMtxInfo {
void operator=(const J3DIndTexMtxInfo& other)
J3DIndTexMtxInfo& operator=(const J3DIndTexMtxInfo& other)
{
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
mOffsetMtx[i][j] = other.mOffsetMtx[i][j];
}
}
mScaleExp = other.mScaleExp;
return *this;
}

/* 0x00 */ f32 mOffsetMtx[2][3];
/* 0x18 */ s8 mScaleExp;
}; // Size: 0x1C
Expand Down Expand Up @@ -161,20 +167,22 @@ struct J3DNBTScaleInfo {
/* 0x0 */ u8 mbHasScale;
/* 0x4 */ Vec mScale;

inline void operator=(const J3DNBTScaleInfo& other)
J3DNBTScaleInfo& operator=(const J3DNBTScaleInfo& other)
{
mbHasScale = other.mbHasScale;
mScale.x = other.mScale.x;
mScale.y = other.mScale.y;
mScale.z = other.mScale.z;
return *this;
}
}; // Size: 0x10

struct J3DIndTexOrderInfo {
void operator=(const J3DIndTexOrderInfo& other)
J3DIndTexOrderInfo& operator=(const J3DIndTexOrderInfo& other)
{
mCoord = other.mCoord;
mMap = other.mMap;
return *this;
}

/* 0x0 */ u8 mCoord;
Expand Down Expand Up @@ -219,7 +227,7 @@ struct J3DTevStageInfo {
};

struct J3DIndTevStageInfo {
void operator=(const J3DIndTevStageInfo& other)
J3DIndTevStageInfo& operator=(const J3DIndTevStageInfo& other)
{
mIndStage = other.mIndStage;
mIndFormat = other.mIndFormat;
Expand All @@ -230,6 +238,7 @@ struct J3DIndTevStageInfo {
mPrev = other.mPrev;
mLod = other.mLod;
mAlphaSel = other.mAlphaSel;
return *this;
}

/* 0x0 */ u8 mIndStage;
Expand All @@ -247,11 +256,12 @@ struct J3DIndTevStageInfo {
};

struct J3DTexCoordInfo {
void operator=(const J3DTexCoordInfo& other)
J3DTexCoordInfo& operator=(const J3DTexCoordInfo& other)
{
mTexGenType = other.mTexGenType;
mTexGenSrc = other.mTexGenSrc;
mTexGenMtx = other.mTexGenMtx;
return *this;
}

/* 0x0 */ u8 mTexGenType __attribute__((aligned(4)));
Expand All @@ -260,10 +270,11 @@ struct J3DTexCoordInfo {
};

struct J3DIndTexCoordScaleInfo {
void operator=(const J3DIndTexCoordScaleInfo& other)
J3DIndTexCoordScaleInfo& operator=(const J3DIndTexCoordScaleInfo& other)
{
mScaleS = other.mScaleS;
mScaleT = other.mScaleT;
return *this;
}

/* 0x0 */ u8 mScaleS;
Expand All @@ -273,12 +284,13 @@ struct J3DIndTexCoordScaleInfo {
};

struct J3DBlendInfo {
void operator=(const J3DBlendInfo& other)
J3DBlendInfo& operator=(const J3DBlendInfo& other)
{
mBlendMode = other.mBlendMode;
mSrcFactor = other.mSrcFactor;
mDstFactor = other.mDstFactor;
mLogicOp = other.mLogicOp;
return *this;
}

/* 0x0 */ u8 mBlendMode;
Expand All @@ -288,11 +300,12 @@ struct J3DBlendInfo {
};

struct J3DTevOrderInfo {
void operator=(const J3DTevOrderInfo& other)
J3DTevOrderInfo& operator=(const J3DTevOrderInfo& other)
{
mTexCoord = other.mTexCoord;
mTexMap = other.mTexMap;
mColorChan = other.mColorChan;
return *this;
}

/* 0x0 */ u8 mTexCoord __attribute__((aligned(2)));
Expand Down
54 changes: 35 additions & 19 deletions src/JSystem/J3D/J3DGraphBase/J3DMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ void J3DIndBlockFull::reset(J3DIndBlock* block)
mIndTexCoordScale[i] = *block->getIndTexCoordScale(i);
}

// TODO: figure out the stack sizes here
void J3DPEBlockFull::reset(J3DPEBlock* block)
{
if (block->getFog() != nullptr) {
Expand All @@ -747,30 +748,45 @@ void J3DPEBlockFull::reset(J3DPEBlock* block)
DCStoreRange(mFog, sizeof(*mFog));
}

// TODO: ton of stupid inlines missing here
switch (block->getType()) {
case 'PEOP':
mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 7, 0, 0, 7, 0, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 0, 1, 0, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 1, 0 });
mZCompLoc = 1;
case 'PEOP': {
const J3DAlphaCompInfo alphaCompInfo = { 7, 0, 0, 7, 0, 0, 0, 0 };
const J3DBlendInfo blendInfo = { 0, 1, 0, 3 };
const J3DZModeInfo zModeInfo = { 1, 3, 1, 0 };
u32 zCompLoc = 1;

mAlphaComp.setAlphaCompInfo(alphaCompInfo);
mBlend.setBlendInfo(blendInfo);
mZMode.setZModeInfo(zModeInfo);
mZCompLoc = zCompLoc;
break;
case 'PEED':
mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 6, 0x80, 0, 3, 0xff, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 0, 1, 0, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 1, 0 });
mZCompLoc = 0;
}
case 'PEED': {
const J3DAlphaCompInfo alphaCompInfo = { 6, 0x80, 0, 3, 0xff, 0, 0, 0 };
const J3DBlendInfo blendInfo = { 0, 1, 0, 3 };
const J3DZModeInfo zModeInfo = { 1, 3, 1, 0 };
u32 zCompLoc = 0;

mAlphaComp.setAlphaCompInfo(alphaCompInfo);
mBlend.setBlendInfo(blendInfo);
mZMode.setZModeInfo(zModeInfo);
mZCompLoc = zCompLoc;
break;
case 'PEXL':
mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 7, 0, 0, 7, 0, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 1, 4, 5, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 0, 0 });
mZCompLoc = 1;
}
case 'PEXL': {
const J3DAlphaCompInfo alphaCompInfo = { 7, 0, 0, 7, 0, 0, 0, 0 };
const J3DBlendInfo blendInfo = { 1, 4, 5, 3 };
const J3DZModeInfo zModeInfo = { 1, 3, 0, 0 };
u32 zCompLoc = 1;

mAlphaComp.setAlphaCompInfo(alphaCompInfo);
mBlend.setBlendInfo(blendInfo);
mZMode.setZModeInfo(zModeInfo);
mZCompLoc = zCompLoc;
break;
}
case 'PEFL':
char trash[0x10];
mAlphaComp = *block->getAlphaComp();
mBlend = *block->getBlend();
mZMode = *block->getZMode();
Expand Down

0 comments on commit 648aa48

Please sign in to comment.