diff options
| author | robojumper <robojumper@gmail.com> | 2025-03-15 17:33:48 +0100 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-03-16 22:14:44 +0100 |
| commit | 9b7889f03497dfae5792ee24803a80a7cb6a7281 (patch) | |
| tree | c38c3e0a6622a995c25ef7897f9bb67a51009e32 /src | |
| parent | 35b4e2403982097c3783104dc3875d574219afd6 (diff) | |
Some small classes
Diffstat (limited to 'src')
| -rw-r--r-- | src/egg/gfx/eggFog.cpp | 67 | ||||
| -rw-r--r-- | src/egg/gfx/eggFogManager.cpp | 69 | ||||
| -rw-r--r-- | src/egg/gfx/eggGlobalDrawState.cpp | 36 | ||||
| -rw-r--r-- | src/egg/gfx/eggIScnProc.cpp | 87 | ||||
| -rw-r--r-- | src/egg/gfx/eggLightManager.cpp (renamed from src/egg/gfx/eggLight.cpp) | 0 | ||||
| -rw-r--r-- | src/egg/gfx/eggLightObject.cpp | 3 | ||||
| -rw-r--r-- | src/egg/gfx/eggScreenEffectBase.cpp | 8 | ||||
| -rw-r--r-- | src/m/m3d/m3d.cpp | 2 |
8 files changed, 267 insertions, 5 deletions
diff --git a/src/egg/gfx/eggFog.cpp b/src/egg/gfx/eggFog.cpp index 71bf0b8c..4669c270 100644 --- a/src/egg/gfx/eggFog.cpp +++ b/src/egg/gfx/eggFog.cpp @@ -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 diff --git a/src/egg/gfx/eggFogManager.cpp b/src/egg/gfx/eggFogManager.cpp new file mode 100644 index 00000000..44d504fb --- /dev/null +++ b/src/egg/gfx/eggFogManager.cpp @@ -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 diff --git a/src/egg/gfx/eggGlobalDrawState.cpp b/src/egg/gfx/eggGlobalDrawState.cpp index aed5311a..12a37a32 100644 --- a/src/egg/gfx/eggGlobalDrawState.cpp +++ b/src/egg/gfx/eggGlobalDrawState.cpp @@ -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 diff --git a/src/egg/gfx/eggIScnProc.cpp b/src/egg/gfx/eggIScnProc.cpp index 6b86ce5b..e293cc91 100644 --- a/src/egg/gfx/eggIScnProc.cpp +++ b/src/egg/gfx/eggIScnProc.cpp @@ -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 diff --git a/src/egg/gfx/eggLight.cpp b/src/egg/gfx/eggLightManager.cpp index c842a6ec..c842a6ec 100644 --- a/src/egg/gfx/eggLight.cpp +++ b/src/egg/gfx/eggLightManager.cpp diff --git a/src/egg/gfx/eggLightObject.cpp b/src/egg/gfx/eggLightObject.cpp new file mode 100644 index 00000000..c842a6ec --- /dev/null +++ b/src/egg/gfx/eggLightObject.cpp @@ -0,0 +1,3 @@ +#include "egg/gfx/eggLight.h" + +namespace EGG {} // namespace EGG diff --git a/src/egg/gfx/eggScreenEffectBase.cpp b/src/egg/gfx/eggScreenEffectBase.cpp index 6e8a1f55..890c7106 100644 --- a/src/egg/gfx/eggScreenEffectBase.cpp +++ b/src/egg/gfx/eggScreenEffectBase.cpp @@ -1,3 +1,9 @@ #include "egg/gfx/eggScreenEffectBase.h" -namespace EGG {} // namespace EGG +namespace EGG { + +Screen ScreenEffectBase::sScreen; + +ScreenEffectBase::ScreenEffectBase() : mFlag(1) {} + +} // namespace EGG diff --git a/src/m/m3d/m3d.cpp b/src/m/m3d/m3d.cpp index 688be98d..5ccdba26 100644 --- a/src/m/m3d/m3d.cpp +++ b/src/m/m3d/m3d.cpp @@ -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(); } } |
