Some small classes

This commit is contained in:
robojumper
2025-03-15 17:33:48 +01:00
parent 35b4e24039
commit 9b7889f034
23 changed files with 576 additions and 54 deletions
+66 -1
View File
@@ -1,3 +1,68 @@
#include "egg/gfx/eggFog.h"
namespace EGG {} // namespace EGG
#include "egg/egg_types.h"
#include "egg/gfx/eggDrawGX.h"
#include "rvl/GX/GXTypes.h"
namespace EGG {
template <>
const char *IBinary<Fog>::GetBinaryType() {
return "FOGD";
}
template <>
int IBinary<Fog>::GetVersion() {
return 0;
}
Fog::Fog() {
Reset();
}
void Fog::Reset() {
// TODO
mColor = DrawGX::WHITE;
mNearZ = 0.0f;
mFarZ = 0.0f;
mEndZ = 0.0f;
mStartZ = 0.0f;
mFogType = GX_FOG_NONE;
mFlags = 0;
}
void Fog::CopyToG3D(nw4r::g3d::Fog fog) const {
fog.SetFogType((mFlags & 1) ? mFogType : GX_FOG_NONE);
fog.SetZ(mStartZ, mEndZ);
fog.SetFogColor(mColor);
fog.SetFogRangeAdjEnable(mFlags & 2);
}
void Fog::SetBinaryInner(const Bin &bin) {
if (bin.mHeader.mVersion != 0) {
return;
}
mStartZ = bin.mData.mStartZ;
mEndZ = bin.mData.mEndZ;
mNearZ = bin.mData.mNearZ;
mFarZ = bin.mData.mFarZ;
mColor = bin.mData.mColor;
mFogType = (GXFogType)bin.mData.field_0x24;
mFlags = bin.mData.mFlag2;
}
void Fog::GetBinaryInner(Bin *pBin) const {
pBin->mData.mStartZ = mStartZ;
pBin->mData.mEndZ = mEndZ;
pBin->mData.mNearZ = mNearZ;
pBin->mData.mFarZ = mFarZ;
pBin->mData.mColor = mColor;
pBin->mData.field_0x24 = mFogType;
pBin->mData.mFlag2 = mFlags;
}
void Fog::SetBinaryInner(const Bin &, const Bin &, f32) {}
Fog::~Fog() {}
} // namespace EGG
+69
View File
@@ -0,0 +1,69 @@
#include "egg/gfx/eggFogManager.h"
#include "common.h"
#include "nw4r/g3d/g3d_scnroot.h"
namespace EGG {
FogManager::FogManager(u16 num) : mFlag(0), mCount(num), mCount2(num) {
mpFog = new Fog[num];
}
FogManager::~FogManager() {
delete[] mpFog;
}
void FogManager::ResetFog() {
for (int i = 0; i < mCount; i++) {
mpFog[i].Reset();
}
}
void FogManager::Calc() {
if (!(mFlag & 4)) {
mFlag |= 4;
}
}
void FogManager::CopyToG3D(nw4r::g3d::ScnRoot *root) const {
for (int i = 0; i < mCount; i++) {
mpFog[i].CopyToG3D(root->GetFog(i));
}
}
void FogManager::SetBinaryInner(const Bin &bin) {
if (bin.mHeader.mVersion == 0) {
u32 loopMax = bin.mData.mCount >= mCount2 ? mCount2 : bin.mData.mCount;
const IBinary<Fog>::Bin *pBinData = bin.mData.mFogData;
for (u16 i = 0; i < loopMax; i++) {
mpFog[i].SetBinary(&pBinData[i]);
}
}
}
void FogManager::SetBinaryInner(const Bin &bin1, const Bin &bin2, f32 blend) {
if (bin1.mHeader.mVersion == 0) {
u32 loopMax = bin1.mData.mCount >= mCount2 ? mCount2 : bin1.mData.mCount;
const IBinary<Fog>::Bin *pBinData1 = bin1.mData.mFogData;
const IBinary<Fog>::Bin *pBinData2 = bin2.mData.mFogData;
for (u16 i = 0; i < loopMax; i++) {
mpFog[i].SetBinaryBlend(&pBinData1[i], &pBinData2[i], blend);
}
}
}
void FogManager::GetBinaryInner(Bin *pOutBin) const {
pOutBin->mData.mCount = mCount2;
u16 max = mCount2;
IBinary<Fog>::Bin *pOutData = pOutBin->mData.mFogData;
for (u16 i = 0; i < max; i++) {
mpFog[i].GetBinary(&pOutData[i]);
}
}
size_t FogManager::GetBinarySize() const {
return sizeof(Bin) + (mCount2 - 1) * sizeof(Fog::Bin);
}
} // namespace EGG
+35 -1
View File
@@ -1,3 +1,37 @@
#include "egg/gfx/eggGlobalDrawState.h"
namespace EGG {} // namespace EGG
#include "common.h"
#include "egg/gfx/eggStateEfb.h"
#include "egg/gfx/eggStateGX.h"
#include "rvl/MTX/mtx.h"
namespace EGG {
Screen const *GlobalDrawState::spScreen;
u16 GlobalDrawState::sCameraId;
u32 GlobalDrawState::sDrawFlag;
// unknown
nw4r::math::MTX34 GlobalDrawState::sMtx;
GlobalDrawState sState;
void GlobalDrawState::beginDrawView(u16 cameraId, const nw4r::math::MTX34 &mtx, const Screen &screen) {
spScreen = &screen;
sCameraId = cameraId;
PSMTXCopy(mtx, sMtx);
StateEfb::Clean();
}
void GlobalDrawState::setDrawSettingGX(bool b1, bool b2) {
StateGX::GXSetColorUpdate_(sDrawFlag & 1);
StateGX::GXSetAlphaUpdate_(sDrawFlag & 2);
StateGX::GXSetDither_(sDrawFlag & 4);
StateGX::GXSetDstAlpha_(false, 0);
if (b2 && spScreen != nullptr) {
spScreen->SetProjectionGX();
}
}
} // namespace EGG
+86 -1
View File
@@ -1,3 +1,88 @@
#include "egg/gfx/eggIScnProc.h"
namespace EGG {} // namespace EGG
#include "common.h"
#include "egg/egg_types.h"
#include "egg/gfx/eggG3DUtility.h"
#include "egg/gfx/eggGlobalDrawState.h"
#include "egg/gfx/eggStateGX.h"
#include "nw4r/g3d/g3d_scnobj.h"
#include "nw4r/math/math_types.h"
#include "rvl/MTX/mtx.h"
namespace EGG {
IScnProc::~IScnProc() {
if (mpDataSet != nullptr) {
for (int i = 0; i < getNumScnProc(); i++) {
mpDataSet[i].mpScnProc->Destroy();
mpDataSet[i].mpScnProc = nullptr;
}
delete[] mpDataSet;
mpDataSet = nullptr;
}
}
void IScnProc::createScnProc(u16 procNum, MEMAllocator *pAllocator) {
mNumScnProc = procNum;
mpDataSet = new ProcData[mNumScnProc];
nw4r::math::MTX34 mtx;
PSMTXIdentity(mtx);
for (u16 i = 0; i < getNumScnProc(); i++) {
u32 sp8;
MEMAllocator *allocator = (pAllocator == nullptr) ? G3DUtility::getAllocator() : pAllocator;
mpDataSet[i].mpScnProc = nw4r::g3d::ScnProc::Construct(allocator, &sp8, IScnProc::drawProcFunc, true, false, 0);
mpDataSet[i].mpScnProc->SetUserData(&mpDataSet[i]);
mpDataSet[i].mpScnProc->SetMtx(nw4r::g3d::ScnObj::MTX_LOCAL, mtx);
mpDataSet[i].mIndex = i;
mpDataSet[i].mpThis = this;
mpDataSet[i].mFlags = 1 | 2;
setPriorityScnProc(i, i, true);
}
}
void IScnProc::setPriorityScnProc(u16 procIndex, u8 priority, bool bUseOpa) {
nw4r::g3d::ScnProc *pScnProc = getData(procIndex)->mpScnProc;
if (bUseOpa) {
pScnProc->SetDrawProc(IScnProc::drawProcFunc, true, false);
pScnProc->SetPriorityDrawOpa(priority);
mpDataSet[procIndex].mFlags |= 1;
} else {
pScnProc->SetDrawProc(IScnProc::drawProcFunc, false, true);
pScnProc->SetPriorityDrawXlu(priority);
mpDataSet[procIndex].mFlags &= ~1;
}
}
void IScnProc::pushBackToScnGroup(nw4r::g3d::ScnGroup *pScnGroup) {
for (u16 i = 0; i < getNumScnProc(); i++) {
bool is_push_back = pScnGroup->Insert(pScnGroup->Size(), getData(i)->mpScnProc);
}
}
void IScnProc::removeFromScnGroup(nw4r::g3d::ScnGroup *pScnGroup) {
for (u16 i = 0; i < getNumScnProc(); i++) {
bool is_remove = pScnGroup->Remove(getData(i)->mpScnProc);
}
}
void IScnProc::drawProcFunc(nw4r::g3d::ScnProc *pScnProc, bool b) {
GlobalDrawState::setDrawSettingGX(b, false);
StateGX::s_commandFlag &= ~0xF;
drawProcFuncNoGlobalState(pScnProc, b);
StateGX::resetGXCache();
GlobalDrawState::setDrawSettingGX(b, (StateGX::s_commandFlag & 0xF) != 0);
}
void IScnProc::drawProcFuncNoGlobalState(nw4r::g3d::ScnProc *pScnProc, bool b) {
ProcData *dat = static_cast<ProcData *>(pScnProc->GetUserData());
dat->mpThis->doDraw(dat->mIndex);
}
} // namespace EGG
+3
View File
@@ -0,0 +1,3 @@
#include "egg/gfx/eggLight.h"
namespace EGG {} // namespace EGG
+7 -1
View File
@@ -1,3 +1,9 @@
#include "egg/gfx/eggScreenEffectBase.h"
namespace EGG {} // namespace EGG
namespace EGG {
Screen ScreenEffectBase::sScreen;
ScreenEffectBase::ScreenEffectBase() : mFlag(1) {}
} // namespace EGG
+1 -1
View File
@@ -180,7 +180,7 @@ void drawDone(int idx) {
internal::l_lightMgr_pp[idx]->DoneDraw();
}
if (internal::l_fogMgr_pp && internal::l_fogMgr_pp[idx]) {
internal::l_fogMgr_pp[idx]->mFlag &= 0xFB;
internal::l_fogMgr_pp[idx]->DoneDraw();
}
}