From 489a69b6f5765eab70590727fa7097509f6917c5 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 26 May 2024 04:21:52 -0400 Subject: [PATCH] lyt_picture match... Im dreading Material --- config/SOUE01/splits.txt | 7 + config/SOUE01/symbols.txt | 8 +- configure.py | 1 + include/nw4r/lyt/lyt_animation.h | 89 --------- include/nw4r/lyt/lyt_bounding.h | 3 - include/nw4r/lyt/lyt_common.h | 65 +++--- include/nw4r/lyt/lyt_group.h | 8 - include/nw4r/lyt/lyt_layout.h | 26 +-- include/nw4r/lyt/lyt_material.h | 96 ++++++--- include/nw4r/lyt/lyt_pane.h | 41 +--- include/nw4r/lyt/lyt_picture.h | 34 ++-- include/nw4r/lyt/lyt_resources.h | 189 ++++++++++++++++++ include/nw4r/lyt/lyt_texMap.h | 85 ++++---- include/nw4r/lyt/lyt_textBox.h | 18 -- include/nw4r/lyt/lyt_types.h | 333 ++++++++++++++++++++++++++----- include/nw4r/lyt/lyt_window.h | 22 -- src/nw4r/lyt/lyt_layout.cpp | 8 +- src/nw4r/lyt/lyt_pane.cpp | 12 +- src/nw4r/lyt/lyt_picture.cpp | 117 +++++++++++ 19 files changed, 800 insertions(+), 362 deletions(-) create mode 100644 include/nw4r/lyt/lyt_resources.h diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 77753f30..f9938f3d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -338,6 +338,13 @@ nw4r/lyt/lyt_layout.cpp: .sbss start:0x805766F8 end:0x805766FC .sdata2 start:0x8057F240 end:0x8057F248 +nw4r/lyt/lyt_picture.cpp: + .text start:0x80489270 end:0x804897FC + .ctors start:0x804DB978 end:0x804DB97C + .data start:0x8056E4F8 end:0x8056E570 + .sbss start:0x80576700 end:0x80576704 + .sdata2 start:0x8057F248 end:0x8057F250 + nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 .data start:0x8056E7E0 end:0x8056E7F8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 829dfb90..164e97b6 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -163,7 +163,7 @@ fn_80007660 = .text:0x80007660; // type:function size:0x94 fn_80007700 = .text:0x80007700; // type:function size:0xDC fn_800077E0 = .text:0x800077E0; // type:function size:0xA0 fn_80007880 = .text:0x80007880; // type:function size:0x33C -fn_80007BC0 = .text:0x80007BC0; // type:function size:0x40 +__dt__Q34nw4r2ut5ColorFv = .text:0x80007BC0; // type:function size:0x40 fn_80007C00 = .text:0x80007C00; // type:function size:0x40 fn_80007C40 = .text:0x80007C40; // type:function size:0x30 fn_80007C70 = .text:0x80007C70; // type:function size:0x1C @@ -25922,7 +25922,7 @@ GetVtxColorElement__Q34nw4r3lyt7PictureCFUl = .text:0x804896C0; // type:function SetVtxColorElement__Q34nw4r3lyt7PictureFUlUc = .text:0x804896E0; // type:function size:0x18 DrawSelf__Q34nw4r3lyt7PictureFRCQ34nw4r3lyt8DrawInfo = .text:0x80489700; // type:function size:0xDC GetRuntimeTypeInfo__Q34nw4r3lyt7PictureCFv = .text:0x804897E0; // type:function size:0x8 -__sinit_lyt_picture_cpp = .text:0x804897F0; // type:function size:0xC +__sinit_\lyt_picture_cpp = .text:0x804897F0; // type:function size:0xC scope:local __ct__Q34nw4r3lyt7TextBoxFPCQ44nw4r3lyt3res7TextBoxRCQ34nw4r3lyt11ResBlockSet = .text:0x80489800; // type:function size:0x2EC __dt__Q34nw4r3lyt7TextBoxFv = .text:0x80489AF0; // type:function size:0x1A0 GetVtxColor__Q34nw4r3lyt7TextBoxCFUl = .text:0x80489C90; // type:function size:0x14 @@ -37075,7 +37075,7 @@ lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x46 scope:local data:strin __vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 __vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC __vt__Q34nw4r3lyt6Layout = .data:0x8056E4B8; // type:object size:0x40 -lbl_8056E4F8 = .data:0x8056E4F8; // type:object size:0x78 +__vt__Q34nw4r3lyt7Picture = .data:0x8056E4F8; // type:object size:0x78 lbl_8056E570 = .data:0x8056E570; // type:object size:0x88 lbl_8056E5F8 = .data:0x8056E5F8; // type:object size:0x3C lbl_8056E634 = .data:0x8056E634; // type:object size:0x8C @@ -47566,7 +47566,7 @@ lbl_8057F230 = .sdata2:0x8057F230; // type:object size:0x4 data:float lbl_8057F238 = .sdata2:0x8057F238; // type:object size:0x8 data:double lbl_8057F240 = .sdata2:0x8057F240; // type:object size:0x4 data:float lbl_8057F244 = .sdata2:0x8057F244; // type:object size:0x4 data:float -lbl_8057F248 = .sdata2:0x8057F248; // type:object size:0x8 data:float +lbl_8057F248 = .sdata2:0x8057F248; // type:object size:0x4 data:float lbl_8057F250 = .sdata2:0x8057F250; // type:object size:0x4 data:float lbl_8057F258 = .sdata2:0x8057F258; // type:object size:0x8 data:double lbl_8057F260 = .sdata2:0x8057F260; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index f8306211..63abe94c 100644 --- a/configure.py +++ b/configure.py @@ -356,6 +356,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_pane.cpp"), Object(Matching, "nw4r/lyt/lyt_group.cpp"), Object(Matching, "nw4r/lyt/lyt_layout.cpp"), + Object(Matching, "nw4r/lyt/lyt_picture.cpp"), Object(Matching, "nw4r/lyt/lyt_resourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), diff --git a/include/nw4r/lyt/lyt_animation.h b/include/nw4r/lyt/lyt_animation.h index dbb5af4a..fe11a440 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -8,58 +8,6 @@ namespace nw4r { namespace lyt { -namespace res { -struct AnimationBlock { - DataBlockHeader blockHeader; // at 0x00 - u16 frameSize; // at 0x08 - bool loop; // at 0x0A - u8 padding1; // at 0x0B - u16 fileNum; // at 0x0C - u16 animContNum; // at 0x0E - u32 animContOffsetsOffset; // at 0x10 -}; - -struct AnimationTagBlock { - DataBlockHeader blockHeader; // at 0x00 - u16 tagOrder; // at 0x08 - u16 groupNum; // at 0x0A - u32 nameOffset; // at 0x0C - u32 groupsOffset; // at 0x10 - u16 startFrame; // at 0x14 - u16 endFrame; // at 0x16 - u8 flag; // at 0x18 - u8 padding[3]; // at 0x19 -}; - -struct AnimationShareBlock { - DataBlockHeader blockHeader; // at 0x00 - u32 animShareInfoOffset; // at 0x04 - u16 shareNum; // at 0x0C - u8 padding[2]; // at 0x0E -}; -} // namespace res - -struct AnimationShareInfo { - const char *GetTargetGroupName() const { - return targetGroupName; - } - const char *GetSrcPaneName() const { - return srcPaneName; - } - - char srcPaneName[17]; // at 0x00 - char targetGroupName[17]; // at 0x11 - u8 padding[2]; // at 0x12 -}; -struct AnimationGroupRef { - const char *GetName() const { - return name; - } - - char name[17]; // at 0x00 - u8 flag; // at 0x11 - u8 padding[2]; // at 0x12 -}; class AnimResource { public: @@ -121,44 +69,7 @@ private: }; } // namespace detail -struct AnimTransform { - inline AnimTransform() : mLink(), mpRes(NULL), mFrame(0.0f) {} - u16 GetFrameSize() const; - bool IsLoopData() const; - virtual ~AnimTransform() = 0; - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) = 0; - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum) = 0; - virtual void Bind(Pane *pPane, bool bRecursive) = 0; - virtual void Bind(Material *pMaterial, bool bDisable) = 0; - virtual void Animate(u32 idx, Pane *pPane) = 0; - virtual void Animate(u32 idx, Material *pMaterial) = 0; - - ut::LinkListNode mLink; // at 0x4 - res::AnimationBlock *mpRes; // at 0xC - f32 mFrame; // at 0x10 -}; - -struct AnimationLink { - inline AnimationLink() : mLink() { - Reset(); - } - - inline void Reset() { - Set(NULL, 0, false); - } - - inline void Set(AnimTransform *pTransform, u16 us, bool b) { - mAnimTrans = pTransform; - mIdx = us; - mbDisable = b; - } - - ut::LinkListNode mLink; // at 0x0 - AnimTransform *mAnimTrans; // at 0x8 - u16 mIdx; // at 0xC - bool mbDisable; // at 0xE -}; class AnimTransformBasic : public AnimTransform { public: AnimTransformBasic(); diff --git a/include/nw4r/lyt/lyt_bounding.h b/include/nw4r/lyt/lyt_bounding.h index 0131c016..56fe12d2 100644 --- a/include/nw4r/lyt/lyt_bounding.h +++ b/include/nw4r/lyt/lyt_bounding.h @@ -7,9 +7,6 @@ namespace nw4r { namespace lyt { -namespace res { -struct Bounding : Pane {}; -} // namespace res struct ResBlockSet { const res::TextureList *pTextureList; // at 0x00 diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index f546e652..3023d73b 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -2,41 +2,52 @@ #define NW4R_LYT_COMMON_H #include "common.h" #include "nw4r/math/math_types.h" -#include "nw4r/ut/ut_binaryFileFormat.h" - -#define NW4R_RES_NAME_SIZE 16 -#define NW4R_MAT_NAME_SIZE 20 - -#define TEXCOORD_VTX_COUNT 4 +#include +#include namespace nw4r { namespace lyt { -namespace res { -struct BinaryFileHeader { - char signature[4]; // at 0x00 - u16 byteOrder; // at 0x04; - u16 version; // at 0x06 - u32 fileSize; // at 0x08 - u16 headerSize; // at 0x0C - u16 dataBlocks; // at 0x0E -}; - -struct DataBlockHeader { - u32 kind; // at 0x0 - u32 size; // at 0x4 -}; -} // namespace res namespace detail { + +inline s32 GetSignatureInt(const char *sig) { + return *((s32 *)sig); +} +inline bool TestFileVersion(const res::BinaryFileHeader &fileHeader) { + u32 majorVer = (fileHeader.version >> 8) & 0xFF; + u32 minorVer = fileHeader.version & 0xFF; + bool ret = majorVer == 0 && (minorVer > 7 && minorVer <= 10); + return ret; +} + +inline u8 GetVtxColorElement(const ut::Color *cols, u32 idx) { + return ((u8 *)cols)[(idx & ~3) + (idx & 3)]; +} + +inline void SetVtxColElement(ut::Color *cols, u32 idx, u8 value) { + ((u8 *)cols)[(idx & ~3) + (idx & 3)] = value; +} + typedef math::VEC2 TexCoordData[TEXCOORD_VTX_COUNT]; -struct TexCoordAry { +class TexCoordAry { +public: TexCoordAry(); void Free(); void Reserve(u8); void SetSize(u8); void Copy(const void *, u8); + bool IsEmpty() const { + return mCap == 0; + } + u8 GetSize() const { + return mNum; + } + TexCoordData *GetArray() const { + return mpData; + } +private: u8 mCap; // at 0x0 u8 mNum; // at 0x1 TexCoordData *mpData; // at 0x4 @@ -54,16 +65,6 @@ void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const ut::Color *, u8); void DrawLine(const math::VEC2 &pos, const Size &size, ut::Color color); -inline s32 GetSignatureInt(const char *sig) { - return *((s32 *)sig); -} -inline bool TestFileVersion(const res::BinaryFileHeader &fileHeader) { - u32 majorVer = (fileHeader.version >> 8) & 0xFF; - u32 minorVer = fileHeader.version & 0xFF; - bool ret = majorVer == 0 && (minorVer > 7 && minorVer <= 10); - return ret; -} - } // namespace detail } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_group.h b/include/nw4r/lyt/lyt_group.h index 9c732c2b..959d1aad 100644 --- a/include/nw4r/lyt/lyt_group.h +++ b/include/nw4r/lyt/lyt_group.h @@ -7,14 +7,6 @@ namespace nw4r { namespace lyt { -namespace res { -struct Group { - DataBlockHeader blockHeader; // at 0x00 "grp1" - char mName[NW4R_RES_NAME_SIZE]; // at 0x08 - u16 paneNum; // at 0x18 - u16 padding; // at 0x1A -}; -} // namespace res namespace detail { struct PaneLink { diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index ebe0f6c7..3eebfff9 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -88,29 +88,29 @@ public: template static T *NewObj() { - T *obj = (T *)AllocMemory(sizeof(T)); - if (obj) { - return new (obj) T(); + T *pMem = (T *)AllocMemory(sizeof(T)); + if (pMem) { + return new (pMem) T(); } else { return nullptr; } } - template - static T *NewObj(T2 p2) { - T *obj = (T *)AllocMemory(sizeof(T)); - if (obj) { - return new (obj) T(p2); + template + static T *NewObj(P1 param1) { + T *pMem = (T *)AllocMemory(sizeof(T)); + if (pMem) { + return new (pMem) T(param1); } else { return nullptr; } } - template - static T *NewObj(T2 p2, T3 p3) { - T *obj = (T *)AllocMemory(sizeof(T)); - if (obj) { - return new (obj) T(p2, p3); + template + static T *NewObj(P1 param1, P2 param2) { + T *pMem = (T *)AllocMemory(sizeof(T)); + if (pMem) { + return new (pMem) T(param1, param2); } else { return nullptr; } diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index 7a8d986c..b0566173 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -2,48 +2,54 @@ #define NW4R_LYT_MATERIAL_H #include "nw4r/lyt/lyt_animation.h" #include "nw4r/ut/ut_LinkList.h" +#include +#include #include #include -#define MATERIAL_NAME_SIZE 20 - namespace nw4r { namespace lyt { -namespace res { -struct MaterialList { - DataBlockHeader blockHeader; // at 0x00 - u16 materialNum; // at 0x08 - u8 padding[2]; // at 0x0A -}; - -} // namespace res - -struct BitGXNums { - union { - u32 texSRT; - u32 texCoordGen; - u32 indSRT; - u32 indStage; - u32 tevSwap; - u32 tevStage; - u32 chanCtrl; - u32 matCol; - u32 alpComp; - u32 blendMode; - }; -}; - -struct Material { +class Material { +public: + Material(const res::Material *pResMat, const ResBlockSet &ResBlockSet); // IsBlendModeCap__Q34nw4r3lyt8MaterialCFv + bool IsBlendModeCap() const { + return mGXMemCap.blendMode; + } + // IsAlphaCompareCap__Q34nw4r3lyt8MaterialCFv + bool IsAlphaCompareCap() const { + return mGXMemCap.alpComp; + } + // IsTevSwapCap__Q34nw4r3lyt8MaterialCFv + bool IsTevSwapCap() const { + return mGXMemCap.tevSwap; + } + // IsMatColorCap__Q34nw4r3lyt8MaterialCFv + bool IsMatColorCap() const { + return mGXMemCap.matCol; + } + // IsChanCtrlCap__Q34nw4r3lyt8MaterialCFv + bool IsChanCtrlCap() const { + return mGXMemCap.chanCtrl; + } + // SetTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf // GetTexturePtr__Q34nw4r3lyt8MaterialFUc + // GetTexSRTCap__Q34nw4r3lyt8MaterialCFv + u8 GetTexSRTCap() const { + return mGXMemCap.texSRT; + } + // GetIndTexSRTCap__Q34nw4r3lyt8MaterialCFv + u8 GetIndTexSRTCap() const { + return mGXMemCap.indSRT; + } // SetIndTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf ut::LinkList *GetAnimationList() { @@ -56,8 +62,35 @@ struct Material { return mName; } + u8 GetTexCoordGenCap() const { + return mGXMemCap.texCoordGen; + } + u8 GetTexCoordGenNum() const { + return mGXMemNum.texCoordGen; + } + u8 GetTextureCap() const { + return mGXMemCap.texMap; + } + + u8 GetTextureNum() const { + return mGXMemNum.texMap; + } + void SetTextureNum(u8 val); + void SetTexCoordGenNum(u8 val); + TexMap *GetTexMapAry() const; + TexMap *GetTexMapAry(); + TexCoordGen *GetTexCoordGenAry(); + + void SetTexture(u32 texMapIdx, const TexMap &texMap) { + GetTexMapAry()[texMapIdx] = texMap; + } + + void SetTexCoordGen(u32 idx, TexCoordGen value) { + GetTexCoordGenAry()[idx] = value; + } + virtual ~Material(); // at 0x08 - virtual bool SetupGX(bool bModVtxCok, u8 alpha); // at 0x0C + virtual bool SetupGX(bool bModVtxCol, u8 alpha); // at 0x0C virtual void BindAnimation(AnimTransform *pAnimTrans); // at 0x10 virtual void UnbindAnimation(AnimTransform *pAnimTrans); // at 0x14 virtual void UnbindAllAnimation(); // at 0x18 @@ -78,6 +111,13 @@ private: bool mbUserAllocated; // at 0x59 u8 mPadding[2]; // at 0x5A }; + +namespace detail { + +Size GetTextureSize(Material *pMaterial, u8 texMapIdx); + +} // namespace detail + } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index d7a83067..37d9dbaf 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -7,13 +7,10 @@ #include "nw4r/ut/ut_LinkList.h" #include "nw4r/ut/ut_RuntimeTypeInfo.h" #include "nw4r/ut/ut_algorithm.h" +#include #include #include -#define PANE_NAME_SIZE 16 -#define PANE_USERDATA_SIZE 8 -#define ANIMTARGET_PANE_MAX 10 - namespace nw4r { namespace lyt { namespace detail { @@ -25,38 +22,6 @@ struct PaneBase { } // namespace detail -namespace res { - -// TODO: Find proper place? -// GUESS: In the FindExtUserDataByName function it iterates through ExtUserData -struct ExtUserData { - u32 nameOffs; // at 0x00 - u32 datOffs; // at 0x04 - u16 numEntries; // at 0x08 - u8 type; // at 0x0A - u8 padding; // at 0x0B -}; - -struct ExtUserDataList { - DataBlockHeader blockHeader; // at 0x00 - u16 num; // at 0x08 - u16 padding; // at 0x0A -}; -struct Pane { - DataBlockHeader blockHeader; // at 0x00 "pan1" - u8 flag; // at 0x08 - u8 basePosition; // at 0x09 - u8 alpha; // at 0x0A - u8 padding; // - char name[PANE_NAME_SIZE]; // at 0x0C - char mUserData[PANE_USERDATA_SIZE]; // at 0x1C - math::VEC3 translate; // at 0x24 - math::VEC3 rotate; // at 0x30 - math::VEC2 scale; // at 0x3C - Size size; // at 0x44 -}; -} // namespace res - class Pane : detail::PaneBase { public: // For use with TestBit @@ -146,7 +111,7 @@ public: virtual void DrawSelf(const DrawInfo &); // at 0x18 virtual void Animate(u32); // at 0x1C virtual void AnimateSelf(u32); // at 0x20 - virtual ut::Color GetVtxColor(u32) const; // at 0x24 + virtual ut::Color GetVtxColor(u32 idx) const; // at 0x24 virtual void SetVtxColor(u32, ut::Color); // at 0x28 virtual u8 GetColorElement(u32 idx) const; // at 0x2C virtual void SetColorElement(u32 idx, u8 value); // at 0x30 @@ -167,7 +132,7 @@ public: virtual Material *GetMaterial(u32 idx) const; // at 0x6C virtual void LoadMtx(const DrawInfo &drawInfo); // at 0x70 -private: +protected: Pane *mpParent; // at 0x0C ut::LinkList mChildList; // at 0x10 ut::LinkList mAnimList; // at 0x1C; diff --git a/include/nw4r/lyt/lyt_picture.h b/include/nw4r/lyt/lyt_picture.h index 8df1e561..2d223812 100644 --- a/include/nw4r/lyt/lyt_picture.h +++ b/include/nw4r/lyt/lyt_picture.h @@ -3,26 +3,36 @@ #include #include +#include namespace nw4r { namespace lyt { -namespace res { - -struct Picture : public Pane {}; - -} // namespace res - class Picture : public Pane { public: - Picture(const res::Picture *, const ResBlockSet &resDataSet); - virtual ~Picture(); - NW4R_UT_RTTI_DECL(Picture); + Picture(u8); + Picture(const TexMap &texMap); + Picture(const res::Picture *pResPic, const ResBlockSet &resDataSet); -private: - ut::Color mVtxColors[4]; // at 0xD8 - detail::TexCoordAry mTexCoordAry; // at 0xE8 + virtual ~Picture(); // at 0x08 + NW4R_UT_RTTI_DECL(Picture); // at 0x0C + virtual void DrawSelf(const DrawInfo &drawInfo); // at 0x18 + virtual ut::Color GetVtxColor(u32 idx) const; // at 0x24 + virtual void SetVtxColor(u32 idx, ut::Color value); // at 0x28 + virtual u8 GetVtxColorElement(u32 idx) const; // at 0x34 + virtual void SetVtxColorElement(u32 idx, u8 value); // at 0x38 + virtual void Append(const TexMap &); // at 0x78 + + void Init(u8 texNum); + + void ReserveTexCoord(u8 texNum); + + void SetTexCoordNum(u8 texNum); + +protected: + ut::Color mVtxColors[TEXCOORD_VTX_COUNT]; // at 0xD8 + detail::TexCoordAry mTexCoordAry; // at 0xE8 }; } // namespace lyt diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h new file mode 100644 index 00000000..d4cb6a76 --- /dev/null +++ b/include/nw4r/lyt/lyt_resources.h @@ -0,0 +1,189 @@ +#ifndef NW4R_LYT_RESOURCES_H +#define NW4R_LYT_RESOURCES_H + +#include +#include +#include + +#define PANE_NAME_SIZE 16 +#define PANE_USERDATA_SIZE 8 +#define ANIMTARGET_PANE_MAX 10 +#define MATERIAL_NAME_SIZE 20 +#define NW4R_RES_NAME_SIZE 16 +#define NW4R_MAT_NAME_SIZE 20 + +#define TEXCOORD_VTX_COUNT 4 + +namespace nw4r { + +namespace lyt { + +namespace res { +struct BinaryFileHeader { + char signature[4]; // at 0x00 + u16 byteOrder; // at 0x04; + u16 version; // at 0x06 + u32 fileSize; // at 0x08 + u16 headerSize; // at 0x0C + u16 dataBlocks; // at 0x0E +}; + +struct DataBlockHeader { + u32 kind; // at 0x0 + u32 size; // at 0x4 +}; + +struct TexMap { + // GetWarpModeS__Q44nw4r3lyt3res6TexMapCFv + // GetWarpModeT__Q44nw4r3lyt3res6TexMapCFv + // GetMinFilter__Q44nw4r3lyt3res6TexMapCFv + // GetMagFilter__Q44nw4r3lyt3res6TexMapCFv + u8 texIdx; // at 0x0 + u8 wrapSflt; // at 0x1 + u8 wrapTflt; // at 0x2 +}; + +struct Material {}; +struct MaterialList { + DataBlockHeader blockHeader; // at 0x00 + u16 materialNum; // at 0x08 + u8 padding[2]; // at 0x0A +}; +struct MaterialResourceNum { + // GetTevStageNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetIndTexStageNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetIndTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // HasBlendMode__Q44nw4r3lyt3res19MaterialResourceNumCFv + // HasAlphaCompare__Q44nw4r3lyt3res19MaterialResourceNumCFv + // HasTevSwapTable__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetMatColNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetChanCtrlNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetTexCoordGenNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + // GetTexMapNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u32 bits; +}; + +struct Group { + DataBlockHeader blockHeader; // at 0x00 "grp1" + char mName[NW4R_RES_NAME_SIZE]; // at 0x08 + u16 paneNum; // at 0x18 + u16 padding; // at 0x1A +}; +struct ExtUserData { + u32 nameOffs; // at 0x00 + u32 datOffs; // at 0x04 + u16 numEntries; // at 0x08 + u8 type; // at 0x0A + u8 padding; // at 0x0B +}; + +struct ExtUserDataList { + DataBlockHeader blockHeader; // at 0x00 + u16 num; // at 0x08 + u16 padding; // at 0x0A +}; +struct Pane { + DataBlockHeader blockHeader; // at 0x00 "pan1" + u8 flag; // at 0x08 + u8 basePosition; // at 0x09 + u8 alpha; // at 0x0A + u8 padding; // + char name[PANE_NAME_SIZE]; // at 0x0C + char mUserData[PANE_USERDATA_SIZE]; // at 0x1C + math::VEC3 translate; // at 0x24 + math::VEC3 rotate; // at 0x30 + math::VEC2 scale; // at 0x3C + Size size; // at 0x44 +}; + +struct Picture : public Pane { + u32 vtxCols[TEXCOORD_VTX_COUNT]; // at 0x4C + u16 materialIdx; // at 0x5C + u8 texCoordNum; // at 0x5E + u8 padding[1]; // at 0x5F +}; + +struct FontList { + DataBlockHeader blockHeader; // at 0x00 + u16 fontNum; // at 0x08 + u8 padding[2]; // at 0x0A +}; + +struct TextureList { + DataBlockHeader blockHeader; // at 0x00 + u16 texNum; // at 0x08 + u8 padding[2]; // at 0x0A +}; +struct TextBox : public Pane { + u16 textBufBytes; // at 0x4C + u16 materialIdx; // at 0x50 + u16 fontIdx; // at 0x52 + u8 textPosition; // at 0x54 + u8 textAlignment; // at 0x55 + u8 padding[2]; // at 0x56 + u32 textStrOffset; // at 0x58 + u32 textCols[2]; // at 0x5C + Size fontSize; // at 0x64 + f32 charSpace; // at 0x6C + f32 lineSpace; // at 0x70 +}; + +struct InflationLRTB { + f32 l; // at 0x00 + f32 r; // at 0x04 + f32 t; // at 0x08 + f32 b; // at 0x0C +}; + +struct Bounding : Pane {}; + +struct Window : Pane { + InflationLRTB inflation; // at 0x4C + u8 frameNum; // at 0x5C + u8 padding1; // at 0x5D + u8 padding2; // at 0x5E + u8 padding3; // at 0x5F + u32 contentOffset; // at 0x60 + u32 frameOffsetTableOffset; // at 0x64 +}; + +struct AnimationBlock { + DataBlockHeader blockHeader; // at 0x00 + u16 frameSize; // at 0x08 + bool loop; // at 0x0A + u8 padding1; // at 0x0B + u16 fileNum; // at 0x0C + u16 animContNum; // at 0x0E + u32 animContOffsetsOffset; // at 0x10 +}; + +struct AnimationTagBlock { + DataBlockHeader blockHeader; // at 0x00 + u16 tagOrder; // at 0x08 + u16 groupNum; // at 0x0A + u32 nameOffset; // at 0x0C + u32 groupsOffset; // at 0x10 + u16 startFrame; // at 0x14 + u16 endFrame; // at 0x16 + u8 flag; // at 0x18 + u8 padding[3]; // at 0x19 +}; + +struct AnimationShareBlock { + DataBlockHeader blockHeader; // at 0x00 + u32 animShareInfoOffset; // at 0x04 + u16 shareNum; // at 0x0C + u8 padding[2]; // at 0x0E +}; + +// TODO +struct HermiteKey {}; +struct StepKey {}; + +} // namespace res +} // namespace lyt + +} // namespace nw4r + +#endif diff --git a/include/nw4r/lyt/lyt_texMap.h b/include/nw4r/lyt/lyt_texMap.h index a277fa92..38a78a40 100644 --- a/include/nw4r/lyt/lyt_texMap.h +++ b/include/nw4r/lyt/lyt_texMap.h @@ -7,13 +7,15 @@ namespace nw4r { namespace lyt { namespace detail { -bool IsCITexelFormat(GXTexFmt fmt) { +inline bool IsCITexelFormat(GXTexFmt fmt) { return (fmt == GX_TF_C4 || fmt == GX_TF_C8 || fmt == GX_TF_C14X2); } } // namespace detail class TexMap { public: + TexMap() {} + void Get(GXTexObj *) const; void Get(GXTlutObj *) const; @@ -27,17 +29,17 @@ public: void SetNoWrap(const TPLDescriptor *); void *GetImage() const { - return mImage; + return mpImage; } void SetImage(void *img) { - mImage = img; + mpImage = img; } void *GetPalette() const { - return mPalette; + return mpPalette; } void SetPalette(void *pal) { - mPalette = pal; + mpPalette = pal; } u16 GetWidth() const { @@ -77,90 +79,91 @@ public: } GXTexFmt GetTexelFormat() const { - return (GXTexFmt)mTexelFormat; + return (GXTexFmt)mBits.mTexelFormat; } void SetTexelFormat(GXTexFmt fmt) { - mTexelFormat = fmt; + mBits.mTexelFormat = fmt; } bool IsMipMap() const { - return mIsMipMap; + return mBits.mIsMipMap; } void SetMipMap(bool b) { - mIsMipMap = b; + mBits.mIsMipMap = b; } GXTexWrapMode GetWrapModeS() const { - return (GXTexWrapMode)mWrapModeS; + return (GXTexWrapMode)mBits.mWrapModeS; } GXTexWrapMode GetWrapModeT() const { - return (GXTexWrapMode)mWrapModeT; + return (GXTexWrapMode)mBits.mWrapModeT; } void SetWrapMode(GXTexWrapMode wrapS, GXTexWrapMode wrapT) { - mWrapModeS = wrapS; - mWrapModeT = wrapT; + mBits.mWrapModeS = wrapS; + mBits.mWrapModeT = wrapT; } GXTexFilter GetMinFilter() const { - return (GXTexFilter)mMinFilter; + return (GXTexFilter)mBits.mMinFilter; } GXTexFilter GetMagFilter() const { - return (GXTexFilter)mMagFilter; + return (GXTexFilter)mBits.mMagFilter; } void SetFilter(GXTexFilter minFlt, GXTexFilter magFlt) { - mMinFilter = minFlt; - mMagFilter = magFlt; + mBits.mMinFilter = minFlt; + mBits.mMagFilter = magFlt; } bool IsBiasClampEnable() const { - return mIsBiasClampEnable; + return mBits.mIsBiasClampEnable; } void SetBiasClampEnable(bool b) { - mIsBiasClampEnable = b; + mBits.mIsBiasClampEnable = b; } bool IsEdgeLODEnable() const { - return mIsEdgeLODEnable; + return mBits.mIsEdgeLODEnable; } void SetEdgeLODEnable(bool b) { - mIsEdgeLODEnable = b; + mBits.mIsEdgeLODEnable = b; } GXAnisotropy GetAnisotropy() const { - return (GXAnisotropy)mAnisotropy; + return (GXAnisotropy)mBits.mAnisotropy; } void SetAnisotropy(GXAnisotropy a) { - mAnisotropy = a; + mBits.mAnisotropy = a; } GXTlutFmt GetPaletteFormat() const { - return (GXTlutFmt)mPaletteFormat; + return (GXTlutFmt)mBits.mPaletteFormat; } void SetPaletteFormat(GXTlutFmt fmt) { - mPaletteFormat = fmt; + mBits.mPaletteFormat = fmt; } private: - void *mImage; // at 0x0 - void *mPalette; // at 0x4 - u16 mWidth; // at 0x8 - u16 mHeight; // at 0xA - f32 mMinLOD; // at 0xC + void *mpImage; // at 0x00 + void *mpPalette; // at 0x04 + u16 mWidth; // at 0x08 + u16 mHeight; // at 0x0A + f32 mMinLOD; // at 0x0C f32 mMaxLOD; // at 0x10 u16 mLODBias; // at 0x14 u16 mPaletteEntryNum; // at 0x16 + struct { + u32 mTexelFormat : 4; // GXTexFmt + u32 mIsMipMap : 1; // bool + u32 mWrapModeS : 2; // GXTexWrapMode + u32 mWrapModeT : 2; // GXTexWrapMode + u32 mMinFilter : 3; // GXTexFilter + u32 mMagFilter : 3; // GXTexFilter + u32 mIsBiasClampEnable : 1; // bool + u32 mIsEdgeLODEnable : 1; // bool + u32 mAnisotropy : 2; // GXAnisotropy + u32 mPaletteFormat : 2; // GXTlutFmt - // at 0x18 - u32 mTexelFormat : 4; // GXTexFmt - u32 mIsMipMap : 1; // bool - u32 mWrapModeS : 2; // GXTexWrapMode - u32 mWrapModeT : 2; // GXTexWrapMode - u32 mMinFilter : 3; // GXTexFilter - u32 mMagFilter : 3; // GXTexFilter - u32 mIsBiasClampEnable : 1; // bool - u32 mIsEdgeLODEnable : 1; // bool - u32 mAnisotropy : 2; // GXAnisotropy - u32 mPaletteFormat : 2; // GXTlutFmt + } mBits; // at 0x18 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_textBox.h b/include/nw4r/lyt/lyt_textBox.h index 4eefc5b4..f2fab1ba 100644 --- a/include/nw4r/lyt/lyt_textBox.h +++ b/include/nw4r/lyt/lyt_textBox.h @@ -6,24 +6,6 @@ namespace nw4r { namespace lyt { -namespace res { - -struct TextBox : public Pane { - u16 textBufBytes; // at 0x4C - u16 materialIdx; // at 0x50 - u16 fontIdx; // at 0x52 - u8 textPosition; // at 0x54 - u8 textAlignment; // at 0x55 - u8 padding[2]; // at 0x56 - u32 textStrOffset; // at 0x58 - u32 textCols[2]; // at 0x5C - Size fontSize; // at 0x64 - f32 charSpace; // at 0x6C - f32 lineSpace; // at 0x70 -}; - -} // namespace res - class TextBox : public Pane { public: void SetTagProcessor(ut::TagProcessorBase *pTagProcessor) { diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 3cd60079..1acade59 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -1,55 +1,12 @@ #ifndef NW4R_LYT_TYPES_H #define NW4R_LYT_TYPES_H -#include +#include #include namespace nw4r { namespace lyt { -struct Size { - inline Size() : width(), height() {} - - inline Size &operator=(const Size &rhs) { - width = rhs.width; - height = rhs.height; - return *this; - } - - f32 width, height; -}; - -namespace res { -// struct AnimationBlock {}; // in lyt_animation.h -// struct AnimationTagBlock {}; // in lyt_animation.h -// struct AnimationShareBlock {}; // in lyt_animation.h -// struct Bounding {}; // in lyt_bounding.h -// struct Group {}; // in lyt_group.h -// struct Material {}; // in lyt_material.h -// struct Pane {}; // in lyt_pane.h -// struct TextBox {}; // in lyt_textbox.h -// struct Window {}; // in lyt_window.h -// struct BinaryFileHeader {}; // in lyt_common.h - -// IDK Proper place for this one -struct FontList { - DataBlockHeader blockHeader; // at 0x00 - u16 fontNum; // at 0x08 - u8 padding[2]; // at 0x0A -}; - -struct TextureList { - DataBlockHeader blockHeader; // at 0x00 - u16 texNum; // at 0x08 - u8 padding[2]; // at 0x0A -}; - -// belong in Animation? -struct HermiteKey {}; -struct StepKey {}; - -} // namespace res - namespace detail { template inline bool TestBit(T bits, int index) { @@ -66,8 +23,294 @@ template T *ConvertOffsetToPtr(const void *baseAddress, unsigned int offset) { return (T *)((u32)baseAddress + offset); } - } // namespace detail +struct Size { + Size() : width(), height() {} + + Size(f32 w, f32 h) : width(w), height(h) {} + + Size(const Size &r) { + width = r.width; + height = r.height; + } + + f32 width, height; +}; + +inline bool operator==(const Size &a, const Size &b) { + return (a.width == b.width && a.height == b.height); +} +struct AnimTransform { + inline AnimTransform() : mLink(), mpRes(NULL), mFrame(0.0f) {} + + u16 GetFrameSize() const; + bool IsLoopData() const; + virtual ~AnimTransform() = 0; + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) = 0; + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum) = 0; + virtual void Bind(Pane *pPane, bool bRecursive) = 0; + virtual void Bind(Material *pMaterial, bool bDisable) = 0; + virtual void Animate(u32 idx, Pane *pPane) = 0; + virtual void Animate(u32 idx, Material *pMaterial) = 0; + + ut::LinkListNode mLink; // at 0x4 + res::AnimationBlock *mpRes; // at 0xC + f32 mFrame; // at 0x10 +}; +struct AnimationShareInfo { + const char *GetTargetGroupName() const { + return targetGroupName; + } + const char *GetSrcPaneName() const { + return srcPaneName; + } + + char srcPaneName[17]; // at 0x00 + char targetGroupName[17]; // at 0x11 + u8 padding[2]; // at 0x12 +}; + +class AnimationLink { +public: + inline AnimationLink() : mLink() { + Reset(); + } + + AnimTransform *GetAnimTransform() const { + return mAnimTrans; + } + u16 GetIndex() const { + return mIdx; + } + void SetIndex(u16 val) { + mIdx = val; + } + + bool IsEnable() const { + return !mbDisable; + } + void SetEnable(bool enable) { + mbDisable = !enable; + } + + void Reset() { + Set(NULL, 0, false); + } + + void Set(AnimTransform *pTransform, u16 us, bool b) { + mAnimTrans = pTransform; + mIdx = us; + mbDisable = b; + } + +private: + ut::LinkListNode mLink; // at 0x0 + AnimTransform *mAnimTrans; // at 0x8 + u16 mIdx; // at 0xC + bool mbDisable; // at 0xE +}; + +struct AnimationGroupRef { + const char *GetName() const { + return name; + } + + char name[17]; // at 0x00 + u8 flag; // at 0x11 + u8 padding[2]; // at 0x12 +}; + +struct TexCoordGen { + // __ct__Q34nw4r3lyt11TexCoordGenFv + TexCoordGen() { + reserve = 0; + Set(GX_TG_MTX2x4, GX_TG_TEX0, GX_TEXMTX_IDENT); + } + + // Set__Q34nw4r3lyt11TexCoordGenF13_GXTexGenType12_GXTexGenSrcUl + void Set(GXTexGenType aTexGenType, GXTexGenSrc aTexGenSrc, u32 aTexMtx) { + texGenType = aTexGenType; + texGenSrc = aTexGenSrc; + texMtx = aTexMtx; + } + + // GetTexGenType__Q34nw4r3lyt11TexCoordGenCFv + u8 GetTexGenType() const { + return texGenType; + } + + // GetTexGenSrc__Q34nw4r3lyt11TexCoordGenCFv + u8 GetTexGenSrc() const { + return texGenSrc; + } + + // GetTexMtx__Q34nw4r3lyt11TexCoordGenCFv + u8 GetTexMtx() const { + return texMtx; + } + + u8 texGenType; // at 0x0 + u8 texGenSrc; // at 0x1 + u8 texMtx; // at 0x2 + u8 reserve; // at 0x3 +}; +struct ChanCtrl { // 17552 + // __ct__Q34nw4r3lyt8ChanCtrlFv + // Set__Q34nw4r3lyt8ChanCtrlF11_GXColorSrc11_GXColorSrc + // GetColorSrc__Q34nw4r3lyt8ChanCtrlCFv + // GetAlphaSrc__Q34nw4r3lyt8ChanCtrlCFv + + u8 matSrcCol; // at 0x0 + u8 matSrcAlp; // at 0x1 + u8 reserve1; // at 0x2 + u8 reserve2; // at 0x3 +}; + +struct BitGXNums { + u32 texMap : 4; + u32 texSRT : 4; + u32 texCoordGen : 4; + u32 indSRT : 2; + u32 indStage : 3; + u32 tevSwap : 1; + u32 tevStage : 5; + u32 chanCtrl : 1; + u32 matCol : 1; + u32 alpComp : 1; + u32 blendMode : 1; +}; +struct BlendMode { // 10c41 + // __ct__Q34nw4r3lyt9BlendModeFv + // Set__Q34nw4r3lyt9BlendModeF12_GXBlendMode14_GXBlendFactor14_GXBlendFactor10_GXLogicOp + // GetType__Q34nw4r3lyt9BlendModeCFv + // GetSrcFactor__Q34nw4r3lyt9BlendModeCFv + // GetDstFactor__Q34nw4r3lyt9BlendModeCFv + // GetOp__Q34nw4r3lyt9BlendModeCFv + + u8 type; // at 0x0 + u8 srcFactor; // at 0x1 + u8 dstFactor; // at 0x2 + u8 op; // at 0x3 +}; + +struct AlphaCompare { // 17457 + // __ct__Q34nw4r3lyt12AlphaCompareFv + // Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc + // GetComp0__Q34nw4r3lyt12AlphaCompareCFv + // GetRef0__Q34nw4r3lyt12AlphaCompareCFv + // GetOp__Q34nw4r3lyt12AlphaCompareCFv + // GetComp1__Q34nw4r3lyt12AlphaCompareCFv + // GetRef1__Q34nw4r3lyt12AlphaCompareCFv + + u8 comp; // at 0x0 + u8 op; // at 0x1 + u8 ref0; // at 0x2 + u8 ref1; // at 0x3 +}; +struct IndirectStage { // 172da + // __ct__Q34nw4r3lyt13IndirectStageFv + // Set__Q34nw4r3lyt13IndirectStageF13_GXTexCoordID11_GXTexMapID14_GXIndTexScale14_GXIndTexScale + // GetTexCoordGen__Q34nw4r3lyt13IndirectStageCFv + // GetTexMap__Q34nw4r3lyt13IndirectStageCFv + // GetScaleS__Q34nw4r3lyt13IndirectStageCFv + // GetScaleT__Q34nw4r3lyt13IndirectStageCFv + + u8 texCoordGen; // at 0x0 + u8 texMap; // at 0x1 + u8 scaleS; // at 0x2 + u8 scaleT; // at 0x3 +}; + +struct TexSRT { // 17243 + + math::VEC2 translate; // at 0x0 + f32 rotate; // at 0x8 + math::VEC2 scale; // at 0xC +}; + +struct TevStageInOp { // 16fe7 + // GetA__Q34nw4r3lyt12TevStageInOpCFv + // GetB__Q34nw4r3lyt12TevStageInOpCFv + // GetC__Q34nw4r3lyt12TevStageInOpCFv + // GetD__Q34nw4r3lyt12TevStageInOpCFv + // GetOp__Q34nw4r3lyt12TevStageInOpCFv + // GetBias__Q34nw4r3lyt12TevStageInOpCFv + // GetScale__Q34nw4r3lyt12TevStageInOpCFv + // IsClamp__Q34nw4r3lyt12TevStageInOpCFv + // GetOutReg__Q34nw4r3lyt12TevStageInOpCFv + // GetKSel__Q34nw4r3lyt12TevStageInOpCFv + // SetOp__Q34nw4r3lyt12TevStageInOpFUcUcUcbUcUc + + u8 ab; // at 0x0 + u8 cd; // at 0x1 + u8 op; // at 0x2 + u8 cl; // at 0x3 +}; +struct TevStage { // 17094 + // __ct__Q34nw4r3lyt8TevStageFv + // GetTexCoordGen__Q34nw4r3lyt8TevStageCFv + // GetTexMap__Q34nw4r3lyt8TevStageCFv + // GetColorChan__Q34nw4r3lyt8TevStageCFv + // GetRasSwapSel__Q34nw4r3lyt8TevStageCFv + // GetTexSwapSel__Q34nw4r3lyt8TevStageCFv + // GetColorInA__Q34nw4r3lyt8TevStageCFv + // GetColorInB__Q34nw4r3lyt8TevStageCFv + // GetColorInC__Q34nw4r3lyt8TevStageCFv + // GetColorInD__Q34nw4r3lyt8TevStageCFv + // GetColorOp__Q34nw4r3lyt8TevStageCFv + // GetColorBias__Q34nw4r3lyt8TevStageCFv + // GetColorScale__Q34nw4r3lyt8TevStageCFv + // IsColorClamp__Q34nw4r3lyt8TevStageCFv + // GetColorOutReg__Q34nw4r3lyt8TevStageCFv + // GetKColorSel__Q34nw4r3lyt8TevStageCFv + // GetAlphaInA__Q34nw4r3lyt8TevStageCFv + // GetAlphaInB__Q34nw4r3lyt8TevStageCFv + // GetAlphaInC__Q34nw4r3lyt8TevStageCFv + // GetAlphaInD__Q34nw4r3lyt8TevStageCFv + // GetAlphaOp__Q34nw4r3lyt8TevStageCFv + // GetAlphaBias__Q34nw4r3lyt8TevStageCFv + // GetAlphaScale__Q34nw4r3lyt8TevStageCFv + // IsAlphaClamp__Q34nw4r3lyt8TevStageCFv + // GetAlphaOutReg__Q34nw4r3lyt8TevStageCFv + // GetKAlphaSel__Q34nw4r3lyt8TevStageCFv + // GetIndMtxSel__Q34nw4r3lyt8TevStageCFv + // GetIndStage__Q34nw4r3lyt8TevStageCFv + // GetIndFormat__Q34nw4r3lyt8TevStageCFv + // GetIndBiasSel__Q34nw4r3lyt8TevStageCFv + // GetIndWrapS__Q34nw4r3lyt8TevStageCFv + // GetIndWrapT__Q34nw4r3lyt8TevStageCFv + // IsIndAddPrev__Q34nw4r3lyt8TevStageCFv + // IsIndUtcLod__Q34nw4r3lyt8TevStageCFv + // GetIndAlphaSel__Q34nw4r3lyt8TevStageCFv + // SetOrder__Q34nw4r3lyt8TevStageF13_GXTexCoordID11_GXTexMapID12_GXChannelID13_GXTevSwapSel13_GXTevSwapSel + // SetColorIn__Q34nw4r3lyt8TevStageF14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg + // SetAlphaIn__Q34nw4r3lyt8TevStageF14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg + // SetColorOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKColorSel + // SetAlphaOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKAlphaSel + // SetIndirect__Q34nw4r3lyt8TevStageF16_GXIndTexStageID15_GXIndTexFormat16_GXIndTexBiasSel14_GXIndTexMtxID13_GXIndTexWrap13_GXIndTexWrapbb17_GXIndTexAlphaSel + + u8 texCoordGen; // at 0x0 + u8 colChan; // at 0x1 + u8 texMap; // at 0x2 + u8 swapSel; // at 0x3 + TevStageInOp colIn; // at 0x4 + TevStageInOp alpIn; // at 0x8 + u8 indStage; // at 0xC + u8 inBiMt; // at 0xD + u8 indWrap; // at 0xE + u8 indFoAdUtAl; // at 0xF +}; + +struct TevSwapMode { // 1750a + + // GetR__Q34nw4r3lyt11TevSwapModeCFv + // GetG__Q34nw4r3lyt11TevSwapModeCFv + // GetB__Q34nw4r3lyt11TevSwapModeCFv + // GetA__Q34nw4r3lyt11TevSwapModeCFv + // Set__Q34nw4r3lyt11TevSwapModeF15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan + + u8 swap; // at 0x0 +}; } // namespace lyt diff --git a/include/nw4r/lyt/lyt_window.h b/include/nw4r/lyt/lyt_window.h index 4a3c304a..3b41dad8 100644 --- a/include/nw4r/lyt/lyt_window.h +++ b/include/nw4r/lyt/lyt_window.h @@ -10,28 +10,6 @@ namespace nw4r { namespace lyt { -namespace res { - -// TODO: Idk where this is stored -struct InflationLRTB { - f32 l; // at 0x00 - f32 r; // at 0x04 - f32 t; // at 0x08 - f32 b; // at 0x0C -}; - -struct Window : res::Pane { - InflationLRTB inflation; // at 0x4C - u8 frameNum; // at 0x5C - u8 padding1; // at 0x5D - u8 padding2; // at 0x5E - u8 padding3; // at 0x5F - u32 contentOffset; // at 0x60 - u32 frameOffsetTableOffset; // at 0x64 -}; - -} // namespace res - struct Content { ut::Color vtxColors[4]; // at 0x00 detail::TexCoordAry texCoordAry; // at 0x10 diff --git a/src/nw4r/lyt/lyt_layout.cpp b/src/nw4r/lyt/lyt_layout.cpp index 11573c27..71a78288 100644 --- a/src/nw4r/lyt/lyt_layout.cpp +++ b/src/nw4r/lyt/lyt_layout.cpp @@ -35,7 +35,7 @@ void SetTagProcessorImpl(Pane *pPane, ut::TagProcessorBase *pTagProcess bool IsIncludeAnimationGroupRef(GroupContainer *pGroupContainer, const AnimationGroupRef *groupRefs, u16 bindGroupNum, bool bDescendingBind, Pane *pTargetPane) { for (u16 grpIdx = 0; grpIdx < bindGroupNum; grpIdx++) { - Group *pGroup = pGroupContainer->FindGroupByName(groupRefs[grpIdx].name); + Group *pGroup = pGroupContainer->FindGroupByName(groupRefs[grpIdx].GetName()); for (ut::LinkList::Iterator paneList = pGroup->GetPaneList()->GetBeginIter(); paneList != pGroup->GetPaneList()->GetEndIter(); paneList++) { const Pane *t = paneList->mTarget; @@ -95,9 +95,10 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { const res::DataBlockHeader *pDataBlockHead = (const res::DataBlockHeader *)dataPtr; switch (pDataBlockHead->kind) { case 'lyt1': // Main Layout + { const res::Layout *pResLyt = ((const res::Layout *)dataPtr); mLayoutSize = pResLyt->layoutSize; - break; + } break; case 'txl1': // Texture List resBlockSet.pTextureList = (const res::TextureList *)dataPtr; break; @@ -112,6 +113,7 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { case 'pic1': // Picture case 'txt1': // Text Box case 'bnd1': // Boundary Pane + { Pane *pPane = BuildPaneObj(pDataBlockHead->kind, dataPtr, resBlockSet); if (pPane) { if (mpRootPane == nullptr) { @@ -122,7 +124,7 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { } pLastPane = pPane; } - break; + } break; case 'usd1': // User Data pLastPane->SetExtUserDataList((const res::ExtUserDataList *)dataPtr); break; diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 9dd360ef..e0ef53f8 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -347,12 +347,12 @@ void Pane::Animate(u32 option) { void Pane::AnimateSelf(u32 option) { for (ut::LinkList::Iterator it = this->mAnimList.GetBeginIter(); it != this->mAnimList.GetEndIter(); it++) { - if (!it->mbDisable) { - AnimTransform *animTrans = it->mAnimTrans; - animTrans->Animate(it->mIdx, this); + if (it->IsEnable()) { + AnimTransform *animTrans = it->GetAnimTransform(); + animTrans->Animate(it->GetIndex(), this); } } - if (IsVisible() || !(option & 1)) { + if (IsVisible() || !detail::TestBit(option, 0)) { if (this->mpMaterial) { mpMaterial->Animate(); } @@ -407,7 +407,7 @@ AnimationLink *Pane::FindAnimationLinkSelf(const AnimResource &animRes) { void Pane::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable, bool bRecursive) { AnimationLink *pAnimLink = FindAnimationLinkSelf(pAnimTrans); if (pAnimLink) { - pAnimLink->mbDisable = !bEnable; + pAnimLink->SetEnable(bEnable); } u8 materialNum = GetMaterialNum(); @@ -426,7 +426,7 @@ void Pane::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable, bool bRec void Pane::SetAnimationEnable(const AnimResource &animRes, bool bEnable, bool bRecursive) { AnimationLink *pAnimLink = FindAnimationLinkSelf(animRes); if (pAnimLink) { - pAnimLink->mbDisable = !bEnable; + pAnimLink->SetEnable(bEnable); } u8 materialNum = GetMaterialNum(); diff --git a/src/nw4r/lyt/lyt_picture.cpp b/src/nw4r/lyt/lyt_picture.cpp index e69de29b..83e567d3 100644 --- a/src/nw4r/lyt/lyt_picture.cpp +++ b/src/nw4r/lyt/lyt_picture.cpp @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +namespace nw4r { +namespace lyt { + +NW4R_UT_RTTI_DEF_DERIVED(Picture, Pane); + +// __ct__Q34nw4r3lyt7PictureFUc +// COMPLETE GUESS (needed for the weak Color ctor) +Picture::Picture(u8 texNum) { + Init(texNum); +} + +// __ct__Q34nw4r3lyt7PictureFRCQ34nw4r3lyt6TexMap + +// __ct__Q34nw4r3lyt7PictureFPCQ44nw4r3lyt3res7PictureRCQ34nw4r3lyt11ResBlockSet +Picture::Picture(const res::Picture *pResPic, const ResBlockSet &resBlockSet) + : Pane(pResPic), mVtxColors(), mTexCoordAry() { + u8 texCoordNum = ut::Min(pResPic->texCoordNum, 8); + + Init(texCoordNum); + + for (int i = 0; i < TEXCOORD_VTX_COUNT; i++) { + mVtxColors[i] = pResPic->vtxCols[i]; + } + if (texCoordNum != 0 && !mTexCoordAry.IsEmpty()) { + mTexCoordAry.Copy((void *)&pResPic[1], texCoordNum); + } + const u32 *matOffsTbl = detail::ConvertOffsetToPtr(resBlockSet.pMaterialList, sizeof(res::MaterialList)); + const res::Material *pResMaterial = + detail::ConvertOffsetToPtr(resBlockSet.pMaterialList, matOffsTbl[pResPic->materialIdx]); + mpMaterial = Layout::NewObj(pResMaterial, resBlockSet); +} + +// Init__Q34nw4r3lyt7PictureFUc +void Picture::Init(u8 texNum) { + ReserveTexCoord(texNum); +} + +// __dt__Q34nw4r3lyt7PictureFv +Picture::~Picture() { + if (mpMaterial && !mpMaterial->IsUserAllocated()) { + Layout::DeleteObj(mpMaterial); + mpMaterial = nullptr; + } + mTexCoordAry.Free(); +} + +// Append__Q34nw4r3lyt7PictureFRCQ34nw4r3lyt6TexMap +void Picture::Append(const TexMap &texMap) { + if (mpMaterial->GetTextureNum() >= mpMaterial->GetTextureCap() || + mpMaterial->GetTextureNum() >= mpMaterial->GetTexCoordGenCap()) { + return; + } + u8 texIdx = mpMaterial->GetTextureNum(); + mpMaterial->SetTextureNum(texIdx + 1); + mpMaterial->SetTexture(texIdx, texMap); + mpMaterial->SetTexCoordGenNum(mpMaterial->GetTextureNum()); + mpMaterial->SetTexCoordGen(texIdx, TexCoordGen()); + SetTexCoordNum(mpMaterial->GetTextureNum()); + if (mSize == Size(0.0f, 0.0f) && mpMaterial->GetTextureNum() == 1) { + mSize = detail::GetTextureSize(mpMaterial, 0); + } +} + +// ReserveTexCoord__Q34nw4r3lyt7PictureFUc +void Picture::ReserveTexCoord(u8 texNum) { + if (texNum != 0) { + mTexCoordAry.Reserve(texNum); + } +} + +// GetTexCoordNum__Q34nw4r3lyt7PictureCFv + +// SetTexCoordNum__Q34nw4r3lyt7PictureFUc +void Picture::SetTexCoordNum(u8 num) { + mTexCoordAry.SetSize(num); +} + +// GetVtxColor__Q34nw4r3lyt7PictureCFUl +ut::Color Picture::GetVtxColor(u32 idx) const { + return mVtxColors[idx]; +} + +// SetVtxColor__Q34nw4r3lyt7PictureFUlQ34nw4r2ut5Color +void Picture::SetVtxColor(u32 idx, ut::Color value) { + mVtxColors[idx] = value; +} + +// GetVtxColorElement__Q34nw4r3lyt7PictureCFUl +u8 Picture::GetVtxColorElement(u32 idx) const { + return detail::GetVtxColorElement(mVtxColors, idx); +} + +// SetVtxColorElement__Q34nw4r3lyt7PictureFUlUc +void Picture::SetVtxColorElement(u32 idx, u8 value) { + detail::SetVtxColElement(mVtxColors, idx, value); +} + +// DrawSelf__Q34nw4r3lyt7PictureFRCQ34nw4r3lyt8DrawInfo +void Picture::DrawSelf(const DrawInfo &drawInfo) { + if (mpMaterial) { + LoadMtx(drawInfo); + bool bUseVtxCol = mpMaterial->SetupGX(detail::IsModulateVertexColor(mVtxColors, mGlbAlpha), mGlbAlpha); + detail::SetVertexFormat(bUseVtxCol, mTexCoordAry.GetSize()); + detail::DrawQuad(GetVtxPos(), mSize, mTexCoordAry.GetSize(), mTexCoordAry.GetArray(), + bUseVtxCol ? mVtxColors : nullptr, mGlbAlpha); + } +} + +} // namespace lyt + +} // namespace nw4r