From 9b7889f03497dfae5792ee24803a80a7cb6a7281 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 15 Mar 2025 17:33:48 +0100 Subject: [PATCH] Some small classes --- config/SOUE01/splits.txt | 21 ++++- config/SOUE01/symbols.txt | 28 +++--- configure.py | 10 ++- include/egg/gfx/eggFog.h | 40 ++++++--- include/egg/gfx/eggFogManager.h | 44 ++++++++++ include/egg/gfx/eggG3DUtility.h | 16 +++- include/egg/gfx/eggGlobalDrawState.h | 22 ++++- include/egg/gfx/eggIScnProc.h | 41 ++++++++- include/egg/gfx/eggLight.h | 10 ++- include/egg/gfx/eggScreenEffectBase.h | 19 +++- include/egg/gfx/eggStateEfb.h | 9 +- include/egg/gfx/eggStateGX.h | 8 ++ include/egg/prim/eggBinary.h | 81 +++++++++++++++-- include/m/m3d/m3d.h | 2 +- include/nw4r/g3d/g3d_fog.h | 7 ++ src/egg/gfx/eggFog.cpp | 67 +++++++++++++- src/egg/gfx/eggFogManager.cpp | 69 +++++++++++++++ src/egg/gfx/eggGlobalDrawState.cpp | 36 +++++++- src/egg/gfx/eggIScnProc.cpp | 87 ++++++++++++++++++- .../gfx/{eggLight.cpp => eggLightManager.cpp} | 0 src/egg/gfx/eggLightObject.cpp | 3 + src/egg/gfx/eggScreenEffectBase.cpp | 8 +- src/m/m3d/m3d.cpp | 2 +- 23 files changed, 576 insertions(+), 54 deletions(-) create mode 100644 include/egg/gfx/eggFogManager.h create mode 100644 src/egg/gfx/eggFogManager.cpp rename src/egg/gfx/{eggLight.cpp => eggLightManager.cpp} (100%) create mode 100644 src/egg/gfx/eggLightObject.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index b6711ae5..28407b19 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2200,7 +2200,14 @@ egg/gfx/eggDrawPathUnk2.cpp: .text start:0x804A4BF0 end:0x804A54E8 egg/gfx/eggFog.cpp: - .text start:0x804A54F0 end:0x804A5F60 + .text start:0x804A54F0 end:0x804A5A08 + .data start:0x8056EFF0 end:0x8056F010 + .sdata start:0x80574F20 end:0x80574F28 + .sdata2 start:0x8057F608 end:0x8057F618 + +egg/gfx/eggFogManager.cpp: + .text start:0x804A5A10 end:0x804A5F60 + .data start:0x8056F010 end:0x8056F030 egg/gfx/eggFrustum.cpp: .text start:0x804A5F60 end:0x804A6854 @@ -2215,15 +2222,21 @@ egg/gfx/eggGfxEngine.cpp: egg/gfx/eggGlobalDrawState.cpp: .text start:0x804A7750 end:0x804A7814 .ctors start:0x804DB9A0 end:0x804DB9A4 + .sbss start:0x80576838 end:0x80576848 + .bss start:0x80674E48 end:0x80674E78 egg/gfx/eggGXUtility.cpp: .text start:0x804A7820 end:0x804A7BC0 egg/gfx/eggIScnProc.cpp: .text start:0x804A7BC0 end:0x804A7F7C + .data start:0x8056F058 end:0x8056F068 -egg/gfx/eggLight.cpp: - .text start:0x804A7F80 end:0x804AB24C +egg/gfx/eggLightManager.cpp: + .text start:0x804A7F80 end:0x804A9808 + +egg/gfx/eggLightObject.cpp: + .text start:0x804A9810 end:0x804AB24C egg/gfx/eggLightTexture.cpp: .text start:0x804AB250 end:0x804AD448 @@ -2263,6 +2276,8 @@ egg/gfx/eggScreen.cpp: egg/gfx/eggScreenEffectBase.cpp: .text start:0x804B30C0 end:0x804B30EC .ctors start:0x804DB9AC end:0x804DB9B0 + .data start:0x8056F268 end:0x8056F278 + .bss start:0x80674F88 end:0x80675010 egg/gfx/eggScreenEffectBlur.cpp: .text start:0x804B30F0 end:0x804B3D98 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 9fb3a09b..9b81b258 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -9781,7 +9781,7 @@ fn_80171BD0 = .text:0x80171BD0; // type:function size:0xA90 fn_80172660 = .text:0x80172660; // type:function size:0x4C fn_801726B0 = .text:0x801726B0; // type:function size:0x218 EGG__DrawPathBase____dt = .text:0x801728D0; // type:function size:0x5C -fn_80172930 = .text:0x80172930; // type:function size:0x40 +__dt__Q23EGG16ScreenEffectBaseFv = .text:0x80172930; // type:function size:0x40 fn_80172970 = .text:0x80172970; // type:function size:0xB4 fn_80172A30 = .text:0x80172A30; // type:function size:0x40 fn_80172A70 = .text:0x80172A70; // type:function size:0x10DC @@ -10673,7 +10673,7 @@ nextPhase__22sFPhase<11dStageMgr_c>Fv = .text:0x8019C420; // type:function size: hasReachedEnd__22sFPhase<11dStageMgr_c>CFv = .text:0x8019C430; // type:function size:0x2C fn_8019C460 = .text:0x8019C460; // type:function size:0x10 fn_8019C470 = .text:0x8019C470; // type:function size:0x10 -fn_8019C480 = .text:0x8019C480; // type:function size:0x10 +SetBinary__Q23EGG19IBinaryFPCv = .text:0x8019C480; // type:function size:0x10 fn_8019C490 = .text:0x8019C490; // type:function size:0x8 fn_8019C4A0 = .text:0x8019C4A0; // type:function size:0x10 fn_8019C4B0 = .text:0x8019C4B0; // type:function size:0x8 @@ -26585,7 +26585,7 @@ createScnProc__Q23EGG8IScnProcFUsP12MEMAllocator = .text:0x804A7C80; // type:fun setPriorityScnProc__Q23EGG8IScnProcFUsUcb = .text:0x804A7D90; // type:function size:0xBC pushBackToScnGroup__Q23EGG8IScnProcFPQ34nw4r3g3d8ScnGroup = .text:0x804A7E50; // type:function size:0x84 drawProcFunc__Q23EGG8IScnProcFPQ34nw4r3g3d7ScnProcb = .text:0x804A7EE0; // type:function size:0x78 -EGG__IScnProc__drawProcFuncNoGlobalState = .text:0x804A7F60; // type:function size:0x1C +drawProcFuncNoGlobalState__Q23EGG8IScnProcFPQ34nw4r3g3d7ScnProcb = .text:0x804A7F60; // type:function size:0x1C __ct__Q23EGG12LightManagerFUlUlUc = .text:0x804A7F80; // type:function size:0x1A8 __ct__Q33EGG12LightManager9LightDataFv = .text:0x804A8130; // type:function size:0x30 __dt__Q23EGG11LightObjectFv = .text:0x804A8160; // type:function size:0x40 @@ -37364,11 +37364,11 @@ lbl_8056EE60 = .data:0x8056EE60; // type:object size:0x50 lbl_8056EEB0 = .data:0x8056EEB0; // type:object size:0x78 lbl_8056EF28 = .data:0x8056EF28; // type:object size:0x78 lbl_8056EFA0 = .data:0x8056EFA0; // type:object size:0x50 -EGG__Fog__vtable = .data:0x8056EFF0; // type:object size:0x20 -EGG__FogManager__vtable = .data:0x8056F010; // type:object size:0x20 +__vt__Q23EGG3Fog = .data:0x8056EFF0; // type:object size:0x20 +__vt__Q23EGG10FogManager = .data:0x8056F010; // type:object size:0x20 EGG__Frustum__vtable = .data:0x8056F030; // type:object size:0x18 EGG__GfxEnginer__Configuration__vtable = .data:0x8056F048; // type:object size:0x10 -lbl_8056F058 = .data:0x8056F058; // type:object size:0x10 +__vt__Q23EGG8IScnProc = .data:0x8056F058; // type:object size:0x10 EGG__LightManager__vtable = .data:0x8056F068; // type:object size:0x30 EGG__LightObject__vtable = .data:0x8056F098; // type:object size:0x20 EGG__LightTexture__vtable = .data:0x8056F0B8; // type:object size:0x38 @@ -37384,7 +37384,7 @@ lbl_8056F1F0 = .data:0x8056F1F0; // type:object size:0x20 lbl_8056F210 = .data:0x8056F210; // type:object size:0x20 sTVModeInfo__Q23EGG6Screen = .data:0x8056F230; // type:object size:0x24 data:2byte EGG__Screen__vtable = .data:0x8056F254; // type:object size:0x14 -lbl_8056F268 = .data:0x8056F268; // type:object size:0x10 +__vt__Q23EGG16ScreenEffectBase = .data:0x8056F268; // type:object size:0xC lbl_8056F278 = .data:0x8056F278; // type:object size:0x38 lbl_8056F2B0 = .data:0x8056F2B0; // type:object size:0x10 __vt__Q23EGG9ArcPlayer = .data:0x8056F2C0; // type:object size:0x5C @@ -41152,13 +41152,13 @@ EGG__DrawGX__sTexMapDefault = .sbss:0x8057680C; // type:object size:0x4 data:4by EGG__Frustum__sGlobalScale = .sbss:0x80576810; // type:object size:0x4 data:float EGG__Frustum__sGlobalOffset = .sbss:0x80576818; // type:object size:0x4 data:float lbl_80576820 = .sbss:0x80576820; // type:object size:0x1 data:byte -lbl_80576824 = .sbss:0x80576824; // type:object size:0x4 data:4byte +sAllocator__Q23EGG10G3DUtility = .sbss:0x80576824; // type:object size:0x4 data:4byte lbl_80576828 = .sbss:0x80576828; // type:object size:0x4 data:4byte lbl_8057682C = .sbss:0x8057682C; // type:object size:0x4 data:4byte lbl_80576830 = .sbss:0x80576830; // type:object size:0x8 data:4byte -EGG__GlobalDrawState__spScreen = .sbss:0x80576838; // type:object size:0x4 data:4byte -EGG__GlobalDrawState__sCameraID = .sbss:0x8057683C; // type:object size:0x2 data:2byte -lbl_80576840 = .sbss:0x80576840; // type:object size:0x8 data:4byte +spScreen__Q23EGG15GlobalDrawState = .sbss:0x80576838; // type:object size:0x4 data:4byte +sCameraId__Q23EGG15GlobalDrawState = .sbss:0x8057683C; // type:object size:0x2 data:2byte +sDrawFlag__Q23EGG15GlobalDrawState = .sbss:0x80576840; // type:object size:0x4 data:4byte lbl_80576848 = .sbss:0x80576848; // type:object size:0x2 data:2byte lbl_8057684A = .sbss:0x8057684A; // type:object size:0x2 data:2byte lbl_8057684C = .sbss:0x8057684C; // type:object size:0x2 data:2byte @@ -41186,7 +41186,7 @@ lbl_805768A4 = .sbss:0x805768A4; // type:object size:0x4 data:4byte lbl_805768A8 = .sbss:0x805768A8; // type:object size:0x4 data:4byte lbl_805768AC = .sbss:0x805768AC; // type:object size:0x1 data:byte lbl_805768B0 = .sbss:0x805768B0; // type:object size:0x2 data:2byte -lbl_805768B2 = .sbss:0x805768B2; // type:object size:0x6 data:2byte +s_commandFlag__Q23EGG7StateGX = .sbss:0x805768B2; // type:object size:0x6 data:2byte lbl_805768B8 = .sbss:0x805768B8; // type:object size:0x4 data:4byte lbl_805768BC = .sbss:0x805768BC; // type:object size:0x4 data:4byte lbl_805768C0 = .sbss:0x805768C0; // type:object size:0x4 data:4byte @@ -49802,12 +49802,12 @@ buf__Q23EGG6Assert = .bss:0x80674C60; // type:object size:0x104 lbl_80674D68 = .bss:0x80674D68; // type:object size:0x90 sCameraMtx = .bss:0x80674DF8; // type:object size:0x30 data:float lbl_80674E28 = .bss:0x80674E28; // type:object size:0x20 -lbl_80674E48 = .bss:0x80674E48; // type:object size:0x30 +sMtx__Q23EGG15GlobalDrawState = .bss:0x80674E48; // type:object size:0x30 CPU_TEX_ARR = .bss:0x80674E78; // type:object size:0x48 data:4byte lbl_80674EC0 = .bss:0x80674EC0; // type:object size:0x30 data:float lbl_80674EF0 = .bss:0x80674EF0; // type:object size:0x10 data:float lbl_80674F00 = .bss:0x80674F00; // type:object size:0x88 data:4byte -lbl_80674F88 = .bss:0x80674F88; // type:object size:0x88 +sScreen__Q23EGG16ScreenEffectBase = .bss:0x80674F88; // type:object size:0x88 lbl_80675010 = .bss:0x80675010; // type:object size:0x30 lbl_80675040 = .bss:0x80675040; // type:object size:0x18 data:float lbl_80675058 = .bss:0x80675058; // type:object size:0x18 data:float diff --git a/configure.py b/configure.py index d690c126..e6c5184d 100644 --- a/configure.py +++ b/configure.py @@ -877,13 +877,15 @@ config.libs = [ Object(NonMatching, "egg/gfx/eggDrawPathDOF.cpp"), Object(NonMatching, "egg/gfx/eggDrawPathUnk2.cpp"), Object(NonMatching, "egg/gfx/eggFog.cpp"), + Object(NonMatching, "egg/gfx/eggFogManager.cpp"), Object(NonMatching, "egg/gfx/eggFrustum.cpp"), Object(NonMatching, "egg/gfx/eggG3DUtility.cpp"), # Unknown Guess Object(NonMatching, "egg/gfx/eggGfxEngine.cpp"), - Object(NonMatching, "egg/gfx/eggGlobalDrawState.cpp"), + Object(Matching, "egg/gfx/eggGlobalDrawState.cpp"), Object(NonMatching, "egg/gfx/eggGXUtility.cpp"), - Object(NonMatching, "egg/gfx/eggIScnProc.cpp"), - Object(NonMatching, "egg/gfx/eggLight.cpp"), + Object(Matching, "egg/gfx/eggIScnProc.cpp"), + Object(NonMatching, "egg/gfx/eggLightManager.cpp"), + Object(NonMatching, "egg/gfx/eggLightObject.cpp"), Object(NonMatching, "egg/gfx/eggLightTexture.cpp"), Object(NonMatching, "egg/gfx/eggLightTextureMgr.cpp"), Object(NonMatching, "egg/gfx/eggModelEx.cpp"), @@ -895,7 +897,7 @@ config.libs = [ Object(NonMatching, "egg/gfx/eggPostEffectMaskDOF.cpp"), Object(NonMatching, "egg/gfx/eggPostEffectSimple.cpp"), Object(NonMatching, "egg/gfx/eggScreen.cpp"), - Object(NonMatching, "egg/gfx/eggScreenEffectBase.cpp"), + Object(Matching, "egg/gfx/eggScreenEffectBase.cpp"), Object(NonMatching, "egg/gfx/eggScreenEffectBlur.cpp"), # Unknown Guess Object(NonMatching, "egg/gfx/eggStateEfb.cpp"), Object(NonMatching, "egg/gfx/eggStateGX.cpp"), diff --git a/include/egg/gfx/eggFog.h b/include/egg/gfx/eggFog.h index 43f9a8d5..13d1bb94 100644 --- a/include/egg/gfx/eggFog.h +++ b/include/egg/gfx/eggFog.h @@ -1,26 +1,46 @@ #ifndef EGG_FOG_H #define EGG_FOG_H +#include "common.h" #include "egg/prim/eggBinary.h" +#include "nw4r/g3d/g3d_fog.h" #include "nw4r/types_nw4r.h" +#include "rvl/GX/GXTypes.h" namespace EGG { -// TODO: Add members -class FogManager : IBinary { +class Fog : public IBinary { public: - FogManager(u16); - virtual ~FogManager(); - virtual void SetBinaryInner(Bin &) override; + struct BinData { + /* 0x10 */ f32 mStartZ; + /* 0x14 */ f32 mEndZ; + /* 0x18 */ f32 mNearZ; + /* 0x1C */ f32 mFarZ; + /* 0x20 */ GXColor mColor; + /* 0x24 */ u8 field_0x24; + /* 0x25 */ u8 mFlag2; + /* 0x26 */ u16 field_0x26; + /* 0x28 */ UNKWORD field_0x28; + /* 0x2C */ UNKWORD field_0x2C; + }; + Fog(); + virtual ~Fog(); + virtual void SetBinaryInner(const Bin &) override; virtual void GetBinaryInner(Bin *) const override; - virtual size_t GetBinarySize() override; virtual void SetBinaryInner(const Bin &, const Bin &, f32) override; - void Calc(); - void CopyToG3D(nw4r::g3d::ScnRoot *) const; + void CopyToG3D(nw4r::g3d::Fog fof) const; + void Reset(); - /* 0x04 */ u8 mFlag; - /* 0x05 */ u8 TODO[0x10 - 0x05]; +private: + + /* 0x04 */ GXColor mColor; + /* 0x08 */ f32 mStartZ; + /* 0x0C */ f32 mEndZ; + /* 0x10 */ f32 mNearZ; + /* 0x14 */ f32 mFarZ; + /* 0x18 */ GXFogType mFogType; + /* 0x1C */ u8 mFlags; }; } // namespace EGG diff --git a/include/egg/gfx/eggFogManager.h b/include/egg/gfx/eggFogManager.h new file mode 100644 index 00000000..589b5041 --- /dev/null +++ b/include/egg/gfx/eggFogManager.h @@ -0,0 +1,44 @@ +#ifndef EGG_FOG_MANAGER_H +#define EGG_FOG_MANAGER_H + +#include "common.h" +#include "egg/gfx/eggFog.h" +#include "egg/prim/eggBinary.h" +#include "nw4r/types_nw4r.h" + +namespace EGG { + +// TODO: Add members +class FogManager : IBinary { +public: + struct BinData { + /* 0x10 */ u16 mCount; + /* 0x12 */ u8 _0x12[2]; + /* 0x14 */ IBinary::Bin mFogData[1]; + }; + FogManager(u16); + virtual ~FogManager(); + virtual void SetBinaryInner(const Bin &) override; + virtual void GetBinaryInner(Bin *) const override; + virtual size_t GetBinarySize() const override; + virtual void SetBinaryInner(const Bin &, const Bin &, f32) override; + + void ResetFog(); + void Calc(); + void CopyToG3D(nw4r::g3d::ScnRoot *) const; + + void DoneDraw() { + mFlag &= ~4; + } + +private: + /* 0x04 */ u8 mFlag; + /* 0x05 */ u8 TODO[0x08 - 0x05]; + /* 0x08 */ u16 mCount; + /* 0x0A */ u16 mCount2; + /* 0x0C */ Fog *mpFog; +}; + +} // namespace EGG + +#endif diff --git a/include/egg/gfx/eggG3DUtility.h b/include/egg/gfx/eggG3DUtility.h index 994b7376..059261c7 100644 --- a/include/egg/gfx/eggG3DUtility.h +++ b/include/egg/gfx/eggG3DUtility.h @@ -1,6 +1,20 @@ #ifndef EGG_G3D_UTILITY_H #define EGG_G3D_UTILITY_H -namespace EGG {} // namespace EGG +#include "rvl/MEM/mem_allocator.h" + +namespace EGG { + +class G3DUtility { +public: + static MEMAllocator *getAllocator() { + return sAllocator; + } + +private: + static MEMAllocator *sAllocator; +}; + +} // namespace EGG #endif diff --git a/include/egg/gfx/eggGlobalDrawState.h b/include/egg/gfx/eggGlobalDrawState.h index 36e5203a..11c070ec 100644 --- a/include/egg/gfx/eggGlobalDrawState.h +++ b/include/egg/gfx/eggGlobalDrawState.h @@ -1,6 +1,26 @@ #ifndef EGG_GLOBAL_DRAW_STATE_H #define EGG_GLOBAL_DRAW_STATE_H -namespace EGG {} // namespace EGG +#include "egg/gfx/eggScreen.h" +#include "nw4r/math/math_types.h" + +namespace EGG { + +class GlobalDrawState { +public: + GlobalDrawState() {} + static void setDrawSettingGX(bool, bool); + static void beginDrawView(u16, nw4r::math::MTX34 const &, Screen const &); + +private: + static u16 sCameraId; + static u32 sDrawFlag; + static Screen const *spScreen; + + // unknown + static nw4r::math::MTX34 sMtx; +}; + +} // namespace EGG #endif diff --git a/include/egg/gfx/eggIScnProc.h b/include/egg/gfx/eggIScnProc.h index c7ef3ce2..7096351c 100644 --- a/include/egg/gfx/eggIScnProc.h +++ b/include/egg/gfx/eggIScnProc.h @@ -1,6 +1,45 @@ #ifndef EGG_ISCNPROC_H #define EGG_ISCNPROC_H -namespace EGG {} // namespace EGG +#include "common.h" +#include "nw4r/g3d/g3d_scnproc.h" +#include "rvl/MEM/mem_allocator.h" + +namespace EGG { + +class IScnProc { +private: + // Unofficial name + struct ProcData { + IScnProc *mpThis; // at 0x0 + nw4r::g3d::ScnProc *mpScnProc; // at 0x4 + u16 mIndex; // at 0x8 + u8 mFlags; // at 0xA + }; + + ProcData *mpDataSet; // at 0x0 + u16 mNumScnProc; // at 0x4 + +public: + IScnProc() : mpDataSet(nullptr), mNumScnProc(0) {} + virtual void doDraw(u16) = 0; // at 0x8 + virtual ~IScnProc(); // at 0xC + + void createScnProc(u16 procNum, MEMAllocator *allocator); + void setPriorityScnProc(u16, u8, bool); + void pushBackToScnGroup(nw4r::g3d::ScnGroup *); + void removeFromScnGroup(nw4r::g3d::ScnGroup *); + static void drawProcFunc(nw4r::g3d::ScnProc *, bool); + static void drawProcFuncNoGlobalState(nw4r::g3d::ScnProc *, bool); + + u16 getNumScnProc() { + return mNumScnProc; + } + ProcData *getData(u16 procIndex) { + return &mpDataSet[procIndex]; + } +}; + +} // namespace EGG #endif diff --git a/include/egg/gfx/eggLight.h b/include/egg/gfx/eggLight.h index 16033dc3..d34d0b5d 100644 --- a/include/egg/gfx/eggLight.h +++ b/include/egg/gfx/eggLight.h @@ -16,10 +16,11 @@ public: // TODO: Fill out more class LightTextureManager : public IBinary { public: + struct BinData {}; virtual ~LightTextureManager(); - virtual void SetBinaryInner(Bin &) override; + virtual void SetBinaryInner(const Bin &) override; virtual void GetBinaryInner(Bin *) const override; - virtual size_t GetBinarySize() override; + virtual size_t GetBinarySize() const override; virtual void SetBinaryInner(const Bin &, const Bin &, f32) override; void replaceModelTextures(nw4r::g3d::ResMdl) const; @@ -29,12 +30,13 @@ public: // TODO: Fill out more class LightManager : public IBinary { public: + struct BinData {}; // vt at 0x00 LightManager(u32, u32, u8); virtual ~LightManager(); - virtual void SetBinaryInner(Bin &) override; + virtual void SetBinaryInner(const Bin &) override; virtual void GetBinaryInner(Bin *) const override; - virtual size_t GetBinarySize() override; + virtual size_t GetBinarySize() const override; virtual void SetBinaryInner(const Bin &, const Bin &, f32) override; virtual void Reset(); virtual void Calc(nw4r::g3d::ScnRoot *); diff --git a/include/egg/gfx/eggScreenEffectBase.h b/include/egg/gfx/eggScreenEffectBase.h index 447b328d..d2c25d15 100644 --- a/include/egg/gfx/eggScreenEffectBase.h +++ b/include/egg/gfx/eggScreenEffectBase.h @@ -1,6 +1,23 @@ #ifndef EGG_SCREEN_EFFECT_BASE_H #define EGG_SCREEN_EFFECT_BASE_H -namespace EGG {} // namespace EGG +#include "common.h" +#include "egg/gfx/eggScreen.h" + +namespace EGG { + +class ScreenEffectBase { +private: + u8 mFlag; + +public: + ScreenEffectBase(); + virtual ~ScreenEffectBase() {} // at 0x8 + +protected: + static Screen sScreen; +}; + +} // namespace EGG #endif diff --git a/include/egg/gfx/eggStateEfb.h b/include/egg/gfx/eggStateEfb.h index 5590f9c7..fdecd35a 100644 --- a/include/egg/gfx/eggStateEfb.h +++ b/include/egg/gfx/eggStateEfb.h @@ -1,6 +1,13 @@ #ifndef EGG_STATE_EFB_H #define EGG_STATE_EFB_H -namespace EGG {} // namespace EGG +namespace EGG { + +class StateEfb { +public: + static void Clean(); +}; + +} // namespace EGG #endif diff --git a/include/egg/gfx/eggStateGX.h b/include/egg/gfx/eggStateGX.h index 7351416c..3c1dce73 100644 --- a/include/egg/gfx/eggStateGX.h +++ b/include/egg/gfx/eggStateGX.h @@ -27,6 +27,11 @@ public: static void invalidateTexAllGX(); + static bool GXSetColorUpdate_(bool); + static bool GXSetAlphaUpdate_(bool); + static bool GXSetDither_(bool); + static bool GXSetDstAlpha_(bool, u8); + static bool GXSetColorUpdate(bool); static bool GXSetAlphaUpdate(bool); static bool GXSetDither(); @@ -38,6 +43,9 @@ public: static void GXSetViewport(f32, f32, f32, f32, f32, f32); static void GZSetScissor(u32, u32, u32, u32); static void GZSetScissorBoxOffset(s32, s32); + + + static u16 s_commandFlag; }; } // namespace EGG diff --git a/include/egg/prim/eggBinary.h b/include/egg/prim/eggBinary.h index 067bf8c1..990bd03c 100644 --- a/include/egg/prim/eggBinary.h +++ b/include/egg/prim/eggBinary.h @@ -3,23 +3,88 @@ #include "common.h" +namespace EGG { + +/** + * @brief Common interface for objects that can be serialized to + * and deserializized from binary. + * + * @tparam T The type of the Egg class. Must have a BinData type + * that describes the binary type. + */ template class IBinary { public: - class Bin {}; - virtual void SetBinaryInner(Bin &) = 0; +#pragma pack(push, 1) + struct BinHeader { + /* 0x00 */ char mType[4]; + /* 0x04 */ size_t mSize; + /* 0x08 */ u8 mVersion; + /* 0x09 */ u16 field_0x09; + /* 0x0B */ u8 field_0x0B; + /* 0x0C */ u32 field_0x0C; + }; + struct Bin { + BinHeader mHeader; + typename T::BinData mData; + }; +#pragma pack(pop) + +protected: + /** Load the object from binary */ + virtual void SetBinaryInner(const Bin &) = 0; + /** Save the object to binary */ virtual void GetBinaryInner(Bin *) const = 0; - virtual size_t GetBinarySize() = 0; + /** Get the size of the serialized data. Override if your binary has a dynamic size */ + virtual size_t GetBinarySize() const { + return sizeof(Bin); + } + /** Load the object from binary, interpolating between values */ virtual void SetBinaryInner(const Bin &, const Bin &, f32) = 0; + /** Get a 4-bytes long ID string corresponding to this type */ static const char *GetBinaryType(); - int GetVersion(); - - void GetBinary(void *) const; + /** Get the current version of this type */ + static int GetVersion(); +public: + // These functions below are automatically provided, you should not need to + // touch them to implement de-/serialization for your type. They will parse + // the binary header and then invoke the above virtual functions. + void GetBinary(void *pData) const; void SetBinary(const void *); - - void SetBinaryBlend(const void *, const void *, f32); + void SetBinaryBlend(const void *a, const void *b, f32 blend); }; +template +void IBinary::GetBinary(void *pData) const { + Bin *pBin = reinterpret_cast(pData); + BinHeader zeroedHeader = {0}; + pBin->mHeader = zeroedHeader; + + pBin->mHeader.mVersion = GetVersion(); + pBin->mHeader.mSize = GetBinarySize(); + for (int i = 0; i < 4; i++) { + pBin->mHeader.mType[i] = GetBinaryType()[i]; + } + typename T::BinData zeroedDatat = {0}; + pBin->mData = zeroedDatat; + GetBinaryInner(pBin); +} + +template +void IBinary::SetBinary(const void *a) { + const Bin *pBinA = reinterpret_cast(a); + SetBinaryInner(*pBinA); +} + +template +void IBinary::SetBinaryBlend(const void *a, const void *b, f32 blend) { + const Bin *pBinA = reinterpret_cast(a); + const Bin *pBinB = reinterpret_cast(b); + SetBinaryInner(*pBinA, *pBinB, blend); +} + +} // namespace EGG + #endif diff --git a/include/m/m3d/m3d.h b/include/m/m3d/m3d.h index f994db04..e1503ecf 100644 --- a/include/m/m3d/m3d.h +++ b/include/m/m3d/m3d.h @@ -2,7 +2,7 @@ #define M3D_H #include "egg/core/eggHeap.h" -#include "egg/gfx/eggFog.h" +#include "egg/gfx/eggFogManager.h" #include "egg/gfx/eggLight.h" #include "m/m_allocator.h" #include "nw4r/g3d/g3d_scnroot.h" diff --git a/include/nw4r/g3d/g3d_fog.h b/include/nw4r/g3d/g3d_fog.h index 417198d3..7cbe9e00 100644 --- a/include/nw4r/g3d/g3d_fog.h +++ b/include/nw4r/g3d/g3d_fog.h @@ -76,6 +76,13 @@ public: bool IsFogRangeAdjEnable() const { return IsValid() && ref().adjEnable == TRUE; } + + void SetFogRangeAdjEnable(bool enable) { + if (!IsValid()) { + return; + } + ref().adjEnable = enable; + } }; } // namespace g3d 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::GetBinaryType() { + return "FOGD"; +} + +template <> +int IBinary::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::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::Bin *pBinData1 = bin1.mData.mFogData; + const IBinary::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::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(pScnProc->GetUserData()); + dat->mpThis->doDraw(dat->mIndex); +} + +} // namespace EGG diff --git a/src/egg/gfx/eggLight.cpp b/src/egg/gfx/eggLightManager.cpp similarity index 100% rename from src/egg/gfx/eggLight.cpp rename to 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(); } }