Files
dusklight/src/JSystem/J2DGraph/J2DMaterial.cpp
T
2024-11-10 04:53:09 -05:00

343 lines
9.5 KiB
C++

//
// Generated By: dol2asm
// Translation Unit: J2DMaterial
//
#include "JSystem/J2DGraph/J2DMaterial.h"
#include "JSystem/J3DGraphBase/J3DStruct.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "JSystem/JUtility/JUTPalette.h"
#include "JSystem/JUtility/JUTTexture.h"
#include "dol2asm.h"
/* 802EA1AC-802EA2CC 2E4AEC 0120+00 0/0 1/1 0/0 .text __ct__11J2DMaterialFv */
J2DMaterial::J2DMaterial() {
field_0x4 = 0;
mIndex = -1;
mTevBlock = NULL;
mIndBlock = NULL;
mAnmPointer = NULL;
field_0x8 = 1;
mVisible = true;
}
J2DMaterial::~J2DMaterial() {
delete mTevBlock;
delete mIndBlock;
delete mAnmPointer;
}
/* 802EA38C-802EA410 2E4CCC 0084+00 0/0 8/8 0/0 .text setGX__11J2DMaterialFv */
void J2DMaterial::setGX() {
if (mVisible) {
getColorBlock()->setGX();
getTexGenBlock()->setGX();
if (getTevBlock() != NULL) {
getTevBlock()->setGX();
}
if (getIndBlock() != NULL) {
getIndBlock()->setGX();
}
getPEBlock()->setGX();
}
}
/* 802EA410-802EA5C4 2E4D50 01B4+00 0/0 1/1 0/0 .text createTevBlock__11J2DMaterialFib */
J2DTevBlock* J2DMaterial::createTevBlock(int block_type, bool noAlign) {
J2DTevBlock* block;
if (noAlign) {
if (block_type <= 1) {
block = new J2DTevBlock1();
} else if (block_type == 2) {
block = new J2DTevBlock2();
} else if (block_type <= 4) {
block = new J2DTevBlock4();
} else if (block_type <= 8) {
block = new J2DTevBlock8();
} else {
block = new J2DTevBlock16();
}
} else {
if (block_type <= 1) {
block = new (-4) J2DTevBlock1();
} else if (block_type == 2) {
block = new (-4) J2DTevBlock2();
} else if (block_type <= 4) {
block = new (-4) J2DTevBlock4();
} else if (block_type <= 8) {
block = new (-4) J2DTevBlock8();
} else {
block = new (-4) J2DTevBlock16();
}
}
return block;
}
/* 802EA5C4-802EA79C 2E4F04 01D8+00 0/0 1/1 0/0 .text createIndBlock__11J2DMaterialFib */
J2DIndBlock* J2DMaterial::createIndBlock(int block_type, bool noAlign) {
J2DIndBlock* block;
if (noAlign) {
if (block_type != 0) {
block = new J2DIndBlockFull();
} else {
block = new J2DIndBlockNull();
}
} else {
if (block_type != 0) {
block = new (-4) J2DIndBlockFull();
} else {
block = new (-4) J2DIndBlockNull();
}
}
return block;
}
/* 802EA79C-802EA84C 2E50DC 00B0+00 1/1 0/0 0/0 .text
* __ct__Q211J2DMaterial21J2DMaterialAnmPointerFv */
J2DMaterial::J2DMaterialAnmPointer::J2DMaterialAnmPointer() {
mColorAnm = NULL;
mColorIds = -1;
mSRTAnm = NULL;
for (int i = 0; i < 8; i++) {
mSRTIds[i] = -1;
}
mPatternAnm = NULL;
for (int i = 0; i < 8; i++) {
mPatternIds[i] = -1;
}
mTevAnm = NULL;
for (int i = 0; i < 4; i++) {
mTevCRegIds[i] = -1;
}
for (int i = 0; i < 4; i++) {
mTevKRegIds[i] = -1;
}
}
/* 802EA84C-802EA89C 2E518C 0050+00 4/4 0/0 0/0 .text makeAnmPointer__11J2DMaterialFv */
void J2DMaterial::makeAnmPointer() {
if (mAnmPointer == NULL) {
mAnmPointer = new J2DMaterialAnmPointer();
}
}
/* 802EA89C-802EA94C 2E51DC 00B0+00 0/0 4/4 0/0 .text setAnimation__11J2DMaterialFP11J2DAnmColor
*/
void J2DMaterial::setAnimation(J2DAnmColor* anm) {
if (anm != NULL || mAnmPointer != NULL) {
makeAnmPointer();
mAnmPointer->mColorAnm = anm;
mAnmPointer->mColorIds = -1;
if (anm != NULL) {
u16 matNum = anm->getUpdateMaterialNum();
u16 index = getIndex();
for (u16 i = 0; i < matNum; i++) {
u16 matID = anm->getUpdateMaterialID(i);
if (index == matID) {
mAnmPointer->mColorIds = i;
return;
}
}
}
}
}
/* 802EA94C-802EAA2C 2E528C 00E0+00 0/0 4/4 0/0 .text
* setAnimation__11J2DMaterialFP19J2DAnmTextureSRTKey */
void J2DMaterial::setAnimation(J2DAnmTextureSRTKey* anm) {
if (anm != NULL || mAnmPointer != NULL) {
makeAnmPointer();
mAnmPointer->mSRTAnm = anm;
for (int i = 0; i < 8; i++) {
mAnmPointer->mSRTIds[i] = -1;
}
if (anm != NULL) {
u16 matNum = anm->getUpdateMaterialNum();
u16 index = getIndex();
for (u16 i = 0; i < matNum; i++) {
u16 matID = anm->getUpdateMaterialID(i);
if (index == matID) {
u8 mtxID = anm->getUpdateTexMtxID(i);
mAnmPointer->mSRTIds[mtxID] = i;
}
}
}
}
}
/* 802EAA2C-802EAB0C 2E536C 00E0+00 0/0 4/4 0/0 .text
* setAnimation__11J2DMaterialFP16J2DAnmTexPattern */
void J2DMaterial::setAnimation(J2DAnmTexPattern* anm) {
if (anm != NULL || mAnmPointer != NULL) {
makeAnmPointer();
mAnmPointer->mPatternAnm = anm;
for (int i = 0; i < 8; i++) {
mAnmPointer->mPatternIds[i] = -1;
}
if (anm != NULL) {
u16 matNum = anm->getUpdateMaterialNum();
u16 index = getIndex();
J3DAnmTexPatternFullTable* anmTbl = anm->getAnmTable();
for (u16 i = 0; i < matNum; i++) {
u16 matID = anm->getUpdateMaterialID(i);
if (index == matID) {
mAnmPointer->mPatternIds[anmTbl[i].mTexNo] = i;
}
}
}
}
}
/* 802EAB0C-802EAC78 2E544C 016C+00 0/0 4/4 0/0 .text
* setAnimation__11J2DMaterialFP15J2DAnmTevRegKey */
void J2DMaterial::setAnimation(J2DAnmTevRegKey* anm) {
if (anm != NULL || mAnmPointer != NULL) {
makeAnmPointer();
mAnmPointer->mTevAnm = anm;
for (int i = 0; i < 4; i++) {
mAnmPointer->mTevCRegIds[i] = -1;
}
if (anm != NULL) {
u16 matNum = anm->getCRegUpdateMaterialNum();
u16 index = getIndex();
for (u16 i = 0; i < matNum; i++) {
u16 matID = anm->getCRegUpdateMaterialID(i);
if (index == matID) {
J3DAnmCRegKeyTable* anmTbl = anm->getAnmCRegKeyTable();
mAnmPointer->mTevCRegIds[anmTbl[i].mColorId] = i;
}
}
}
for (int i = 0; i < 4; i++) {
mAnmPointer->mTevKRegIds[i] = -1;
}
if (anm != NULL) {
u16 matNum = anm->getKRegUpdateMaterialNum();
u16 index = getIndex();
for (u16 i = 0; i < matNum; i++) {
u16 matID = anm->getKRegUpdateMaterialID(i);
if (index == matID) {
J3DAnmKRegKeyTable* anmTbl = anm->getAnmKRegKeyTable();
mAnmPointer->mTevKRegIds[anmTbl[i].mColorId] = i;
}
}
}
}
}
/* 802EAC78-802EB0F4 2E55B8 047C+00 0/0 1/1 0/0 .text animation__11J2DMaterialFv */
void J2DMaterial::animation() {
if (!mAnmPointer) {
return;
}
if (mAnmPointer->mColorAnm && mAnmPointer->mColorIds != 0xFFFF) {
GXColor color;
mAnmPointer->mColorAnm->getColor(mAnmPointer->mColorIds, &color);
getColorBlock()->setMatColor(0, color);
}
if (mAnmPointer->mSRTAnm) {
for (u8 i = 0; i < 8; i++) {
if (mAnmPointer->mSRTIds[i] != 0xFFFF) {
J3DTextureSRTInfo info3D;
mAnmPointer->mSRTAnm->getTransform(mAnmPointer->mSRTIds[i], &info3D);
J2DTextureSRTInfo info2D;
info2D.mScaleX = info3D.mScaleX;
info2D.mScaleY = info3D.mScaleY;
info2D.mRotationDeg = (360.0f * f32((u16)info3D.mRotation)) / 65535.0f;
info2D.mTranslationX = info3D.mTranslationX;
info2D.mTranslationY = info3D.mTranslationY;
J2DTexMtx texMtx;
getTexGenBlock()->getTexMtx(i, texMtx);
texMtx.getTexMtxInfo().mTexSRTInfo = info2D;
getTexGenBlock()->setTexMtx(i, texMtx);
getTexGenBlock()->getTexCoord(i).setTexGenMtx(i * 3 + 30);
}
}
}
if (getTevBlock() && mAnmPointer->mPatternAnm) {
for (u8 i = 0; i < 8; i++) {
if (mAnmPointer->mPatternIds[i] != 0xFFFF) {
JUTTexture* texture = getTevBlock()->getTexture(i);
if (!texture) {
continue;
}
u16 idx = mAnmPointer->mPatternIds[i];
u16 texNo;
mAnmPointer->mPatternAnm->getTexNo(idx, &texNo);
getTevBlock()->setTexNo(i, texNo);
ResTIMG* img = mAnmPointer->mPatternAnm->getResTIMG(idx);
if (texture->getTexInfo() != img) {
JUTPalette* palette = NULL;
u32 tlut = GX_TLUT0;
if (img->indexTexture != 0) {
palette = mAnmPointer->mPatternAnm->getPalette(idx);
if (palette->getNumColors() > 256) {
tlut = i % 4 + 16;
} else {
tlut = i;
}
}
texture->storeTIMG(img, palette, (GXTlut)tlut);
}
}
}
}
if (getTevBlock() && mAnmPointer->mTevAnm) {
for (u8 i = 0; i < 4; i++) {
if (mAnmPointer->mTevCRegIds[i] != 0xFFFF) {
J2DGXColorS10 color;
mAnmPointer->mTevAnm->getTevColorReg(mAnmPointer->mTevCRegIds[i], &color);
getTevBlock()->setTevColor(i, color);
}
}
for (u8 i = 0; i < 4; i++) {
u16 idx = mAnmPointer->mTevKRegIds[i];
if (idx != 0xFFFF) {
JUtility::TColor konstColor;
mAnmPointer->mTevAnm->getTevKonstReg(idx, &konstColor);
getTevBlock()->setTevKColor(i, konstColor);
}
}
}
}