JSystem work (#2384)

* object-id 100% on debug

Can't be linked due to .text alignment issues?

* J3DMaterialFactory and J3DMaterialFactory_v21 OK

* Match dKy_bg_MAxx_proc
This commit is contained in:
LagoLunatic
2025-04-09 01:17:20 -04:00
committed by GitHub
parent 396a464cc7
commit 6672817e41
19 changed files with 159 additions and 438 deletions
+54 -53
View File
@@ -718,6 +718,7 @@ extern const J3DFogInfo j3dDefaultFogInfo;
*/
struct J3DFog : public J3DFogInfo {
J3DFog() { *(J3DFogInfo*)this = j3dDefaultFogInfo; }
~J3DFog() {}
J3DFogInfo* getFogInfo() { return this; }
void setFogInfo(J3DFogInfo info) { *(J3DFogInfo*)this = info; }
void setFogInfo(J3DFogInfo* info) { *(J3DFogInfo*)this = *info; }
@@ -733,11 +734,11 @@ struct J3DFog : public J3DFogInfo {
*
*/
struct J3DAlphaCompInfo {
/* 0x0 */ u8 field_0x0;
/* 0x1 */ u8 field_0x1;
/* 0x2 */ u8 mRef0;
/* 0x3 */ u8 mRef1;
/* 0x4 */ u8 field_0x4;
/* 0x0 */ u8 mComp0;
/* 0x1 */ u8 mRef0;
/* 0x2 */ u8 mOp;
/* 0x3 */ u8 mComp1;
/* 0x4 */ u8 mRef1;
/* 0x5 */ u8 field_0x5;
/* 0x6 */ u8 field_0x6;
/* 0x7 */ u8 field_0x7;
@@ -745,15 +746,10 @@ struct J3DAlphaCompInfo {
extern const u16 j3dDefaultAlphaCmpID;
inline u32 calcAlphaCmpID(u32 param_1, u32 param_2, u32 param_3) {
return ((param_1 & 0xff) << 5) + ((param_2 & 0xff) << 3) + (param_3 & 0xff);
inline u16 calcAlphaCmpID(u8 comp0, u8 op, u8 comp1) {
return (comp0 << 5) + (op << 3) + (comp1);
}
// matches for `J3DMaterialFactory::newAlphaComp,J3DMaterialFactory_v21::newAlphaComp` but fails for `d_resorce::addWarpMaterial`
// inline u32 calcAlphaCmpID(u8 param_1, u8 param_2, u8 param_3) {
// return param_1 * 0x20 + param_2 * 8 + param_3;
// }
/**
* @ingroup jsystem-j3d
*
@@ -761,21 +757,17 @@ inline u32 calcAlphaCmpID(u32 param_1, u32 param_2, u32 param_3) {
struct J3DAlphaComp {
J3DAlphaComp() : mID(j3dDefaultAlphaCmpID), mRef0(0), mRef1(0) {}
J3DAlphaComp(u16 id) : mID(id), mRef0(0), mRef1(0) {}
J3DAlphaComp(J3DAlphaCompInfo const& info) :
mID(calcAlphaCmpID(info.field_0x0, info.mRef0, info.mRef1)),
mRef0(info.field_0x1),
mRef1(info.field_0x4)
{}
void setAlphaCompInfo(const J3DAlphaCompInfo& param_1) {
mRef0 = param_1.field_0x1;
mRef1 = param_1.field_0x4;
u32 p1_mref1 = param_1.mRef1;
mID = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, p1_mref1);
explicit J3DAlphaComp(const J3DAlphaCompInfo& info) {
mID = calcAlphaCmpID(info.mComp0, info.mOp, info.mComp1);
mRef0 = info.mRef0;
mRef1 = info.mRef1;
}
// this matches for `dKy_bg_MAxx_proc` but causes `addWarpMaterial` to fail,
// while the above matches for `addWarpMaterial` but causes `dKy_bg_MAxx_proc` to fail?
// mID = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, param_1.mRef1);
void setAlphaCompInfo(const J3DAlphaCompInfo& info) {
mRef0 = info.mRef0;
mRef1 = info.mRef1;
mID = calcAlphaCmpID(info.mComp0, info.mOp, info.mComp1);
}
GXCompare getComp0() const { return GXCompare(j3dAlphaCmpTable[mID * 3]); }
@@ -1121,12 +1113,12 @@ public:
*
*/
struct J3DColorChanInfo {
/* 0x0 */ u8 field_0x0;
/* 0x1 */ u8 field_0x1;
/* 0x2 */ u8 field_0x2;
/* 0x3 */ u8 field_0x3;
/* 0x4 */ u8 field_0x4;
/* 0x5 */ u8 field_0x5;
/* 0x0 */ u8 mEnable;
/* 0x1 */ u8 mMatSrc;
/* 0x2 */ u8 mLightMask;
/* 0x3 */ u8 mDiffuseFn;
/* 0x4 */ u8 mAttnFn;
/* 0x5 */ u8 mAmbSrc;
/* 0x6 */ u8 pad[2];
};
@@ -1140,6 +1132,25 @@ static inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matS
(attnFn != GX_AF_SPEC) << 10 | (lightMask >> 4 & 0x0F) << 11;
}
inline u16 calcColorChanID(u16 enable, u8 matSrc, u8 lightMask, u8 diffuseFn, u8 attnFn, u8 ambSrc) {
u32 reg = 0;
reg = (reg & ~0x0002) | enable << 1;
reg = (reg & ~0x0001) | matSrc;
reg = (reg & ~0x0040) | ambSrc << 6;
reg = (reg & ~0x0004) | bool(lightMask & 0x01) << 2;
reg = (reg & ~0x0008) | bool(lightMask & 0x02) << 3;
reg = (reg & ~0x0010) | bool(lightMask & 0x04) << 4;
reg = (reg & ~0x0020) | bool(lightMask & 0x08) << 5;
reg = (reg & ~0x0800) | bool(lightMask & 0x10) << 11;
reg = (reg & ~0x1000) | bool(lightMask & 0x20) << 12;
reg = (reg & ~0x2000) | bool(lightMask & 0x40) << 13;
reg = (reg & ~0x4000) | bool(lightMask & 0x80) << 14;
reg = (reg & ~0x0180) | (attnFn == GX_AF_SPEC ? 0 : diffuseFn) << 7;
reg = (reg & ~0x0200) | (attnFn != GX_AF_NONE) << 9;
reg = (reg & ~0x0400) | (attnFn != GX_AF_SPEC) << 10;
return reg;
}
/**
* @ingroup jsystem-j3d
*
@@ -1149,30 +1160,20 @@ struct J3DColorChan {
setColorChanInfo(j3dDefaultColorChanInfo);
}
J3DColorChan(J3DColorChanInfo const& info) {
setColorChanInfo(info);
u32 ambSrc = info.mAmbSrc == 0xFF ? 0 : info.mAmbSrc;
mColorChanID = calcColorChanID(info.mEnable, info.mMatSrc, info.mLightMask,
info.mDiffuseFn, info.mAttnFn, ambSrc);
}
void setColorChanInfo(J3DColorChanInfo const& info) {
mColorChanID = calcColorChanID(info.field_0x0, info.field_0x1, info.field_0x2,
info.field_0x3, info.field_0x4, info.field_0x5 == 0xff ? 0 : info.field_0x5);
}
u16 calcColorChanID(u16 param_0, u8 param_1, u8 param_2, u8 param_3, u8 param_4, u8 param_5) {
// if (param_4 == 0) {
// param_3 = 0;
// }
u32 b0 = ((param_2 & 1) != 0);
u32 b1 = ((param_2 & 2) != 0);
u32 b2 = ((param_2 & 4) != 0);
u32 b3 = ((param_2 & 8) != 0);
u32 b4 = ((param_2 & 0x10) != 0);
u32 b5 = ((param_2 & 0x20) != 0);
u32 b6 = ((param_2 & 0x40) != 0);
u32 b7 = ((param_2 & 0x80) != 0);
return param_1 | (param_0 << 1) | (b0 << 2) | (b1 << 3) | (b2 << 4) | (b3 << 5) |
(param_5 << 6) | (param_3 << 7) | ((param_4 != 2) << 9) | ((param_4 != 0) << 10) |
(b4 << 11) | (b5 << 12) | (b6 << 13) | (b7 << 14);
// return (b7 << 14) | (b6 << 13) | (b5 << 12) | (b4 << 11) |
// ((param_4 != 0) << 10) | ((param_4 != 2) << 9) | ((param_3 != 0) << 7) | ((param_5 != 0) << 6) |
// (b3 << 5) | (b2 << 4) | (b1 << 3) | (b0 << 2) | ((param_0 != 0) << 1) | param_1;
// Bug: It compares info.mAmbSrc (an 8 bit integer) with 0xFFFF instead of 0xFF.
// This inline is only called by the default constructor J3DColorChan().
// The J3DColorChan(const J3DColorChanInfo&) constructor does not call this inline, and instead duplicates the
// same logic but without the bug.
// See J3DMaterialFactory::newColorChan - both the bugged and correct behavior are present there, as it calls
// both constructors.
u32 ambSrc = info.mAmbSrc == 0xFFFF ? 0 : info.mAmbSrc;
mColorChanID = calcColorChanID(info.mEnable, info.mMatSrc, info.mLightMask,
info.mDiffuseFn, info.mAttnFn, ambSrc);
}
u8 getLightMask() { return ((mColorChanID >> 2) & 0xf) | ((mColorChanID >> 11) & 0xf) << 4; }
void setLightMask(u8 param_1) {
+9 -10
View File
@@ -47,24 +47,23 @@ public:
J3DMaterial() { initialize(); }
~J3DMaterial() {}
J3DMaterial* getNext() const { return mNext; }
J3DShape* getShape() const { return mShape; }
J3DTevBlock* getTevBlock() const { return mTevBlock; }
J3DColorBlock* getColorBlock() const { return mColorBlock; }
J3DTexGenBlock* getTexGenBlock() const { return mTexGenBlock; }
J3DDisplayListObj* getSharedDisplayListObj() { return mSharedDLObj; }
J3DIndBlock* getIndBlock() const { return mIndBlock; }
J3DMaterial* getNext() { return mNext; }
J3DShape* getShape() { return mShape; }
J3DTevBlock* getTevBlock() { return mTevBlock; }
J3DColorBlock* getColorBlock() { return mColorBlock; }
J3DTexGenBlock* getTexGenBlock() { return mTexGenBlock; }
J3DDisplayListObj* getSharedDisplayListObj() { return mSharedDLObj; }
J3DIndBlock* getIndBlock() { return mIndBlock; }
J3DJoint* getJoint() { return mJoint; }
J3DMaterialAnm* getMaterialAnm() const {
J3DMaterialAnm* getMaterialAnm() {
if ((u32)mMaterialAnm < 0xC0000000) {
return mMaterialAnm;
} else {
return NULL;
}
}
J3DNBTScale* getNBTScale() const { return mTexGenBlock->getNBTScale(); }
u16 getTexNo(u32 idx) const { return mTevBlock->getTexNo(idx); }
J3DNBTScale* getNBTScale() { return mTexGenBlock->getNBTScale(); }
u16 getTexNo(u32 idx) { return mTevBlock->getTexNo(idx); }
J3DGXColor* getTevKColor(u32 param_0) { return mTevBlock->getTevKColor(param_0); }
J3DGXColorS10* getTevColor(u32 param_0) { return mTevBlock->getTevColor(param_0); }
J3DFog* getFog() { return mPEBlock->getFog(); }
+4 -4
View File
@@ -91,10 +91,10 @@ struct J3DTexCoord : public J3DTexCoordInfo {
__memcpy(this, &info, sizeof(J3DTexCoordInfo));
}
u8 getTexGenType() { return mTexGenType; }
u8 getTexGenSrc() { return mTexGenSrc; }
u8 getTexGenMtx() { return mTexGenMtx & 0xff; }
u16 getTexMtxReg() { return mTexMtxReg & 0xff; }
u8 getTexGenType() const { return mTexGenType; }
u8 getTexGenSrc() const { return mTexGenSrc; }
u8 getTexGenMtx() const { return mTexGenMtx; }
u16 getTexMtxReg() const { return mTexMtxReg & 0xff; }
void setTexGenMtx(u8 param_1) { mTexGenMtx = param_1; }
void setTexMtxReg(u16 reg) { mTexMtxReg = reg; }
J3DTexCoord& operator=(const J3DTexCoord& other) {