From 57e735af3911621ce9482d033697bd95cbfdf290 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 30 Sep 2023 14:31:44 -0700 Subject: [PATCH] J3DMatBlock closer --- include/JSystem/J3DGraphBase/J3DMatBlock.h | 25 ++++++++-------------- src/JSystem/J3DGraphBase/J3DMatBlock.cpp | 5 +++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h index fb0b960f0..42cd2084a 100644 --- a/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -866,28 +866,21 @@ inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matSrc, u32 struct J3DColorChan { J3DColorChan(); - GXAttnFn getAttnFn() { - // Need a way to put this in sdata2 without affecting every single TU ever... - - // static const u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT, }; - // return GXAttnFn(attnFnTbl[mColorChanID >> 9 & 0x03]); - return GXAttnFn(mColorChanID >> 9 & 0x03); - } - GXDiffuseFn getDiffuseFn() { return GXDiffuseFn(mColorChanID >> 7 & 3); } - u8 getLightMask() { return ((mColorChanID >> 2 & 0x0f) | (mColorChanID >> 11 & 0x0f) << 4); } + GXAttnFn getAttnFn(); + GXDiffuseFn getDiffuseFn() { return GXDiffuseFn(mChanCtrl >> 7 & 3); } + u8 getLightMask() { return ((mChanCtrl >> 2 & 0x0f) | (mChanCtrl >> 11 & 0x0f) << 4); } void setLightMask(u8 param_1) { - mColorChanID = (mColorChanID & ~0x3c) | ((param_1 & 0x0f) << 2); - mColorChanID = (mColorChanID & ~0x7800) | ((param_1 & 0xf0) << 7); + mChanCtrl = (mChanCtrl & ~0x3c) | ((param_1 & 0x0f) << 2); + mChanCtrl = (mChanCtrl & ~0x7800) | ((param_1 & 0xf0) << 7); } - // bug? both enable and getMatSrc seem to use bit 0? enable should use bit 1 - GXColorSrc getMatSrc() { return GXColorSrc(mColorChanID >> 0 & 0x01); } - GXColorSrc getAmbSrc() { return GXColorSrc(mColorChanID >> 6 & 0x01); } - u8 getEnable() { return mColorChanID >> 0 & 0x01; } + GXColorSrc getMatSrc() { return GXColorSrc(mChanCtrl >> 0 & 0x01); } + GXColorSrc getAmbSrc() { return GXColorSrc(mChanCtrl >> 6 & 0x01); } + u8 getEnable() { return !!(mChanCtrl & 0x02); } void load() { J3DGDWrite_u32(setChanCtrlMacro(getEnable(), getAmbSrc(), getMatSrc(), getLightMask(), getDiffuseFn(), getAttnFn())); } - /* 0x0 */ u16 mColorChanID; + /* 0x0 */ u16 mChanCtrl; }; class J3DColorBlock { diff --git a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp index 6c125d748..edb8a2dda 100644 --- a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp +++ b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp @@ -14,6 +14,11 @@ #include "dolphin/types.h" #include "MSL_C/string.h" +inline GXAttnFn J3DColorChan::getAttnFn() { + u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT }; + return GXAttnFn(attnFnTbl[mChanCtrl >> 9 & 0x03]); +} + extern bool isTexNoReg(void*); extern u16 getTexNoReg(void*); extern void loadTexNo(u32, const u16 &);