From fa9a9ce9496ea9571a7dd10a708d180168bd2829 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 12 May 2024 20:23:22 -0400 Subject: [PATCH 01/22] lyt_common match --- .vscode/settings.json | 3 +- config/SOUE01/splits.txt | 6 + config/SOUE01/symbols.txt | 8 +- configure.py | 7 + include/nw4r/ef/ef_animcurve.h | 14 +- include/nw4r/ef/ef_creationqueue.h | 74 +-- include/nw4r/ef/ef_drawbillboardstrategy.h | 31 +- include/nw4r/ef/ef_drawdirectionalstrategy.h | 31 +- include/nw4r/ef/ef_drawfreestrategy.h | 29 +- include/nw4r/ef/ef_drawinfo.h | 19 +- include/nw4r/ef/ef_drawlinestrategy.h | 29 +- include/nw4r/ef/ef_draworder.h | 27 +- include/nw4r/ef/ef_drawpointstrategy.h | 31 +- include/nw4r/ef/ef_drawsmoothstripestrategy.h | 31 +- include/nw4r/ef/ef_drawstrategy.h | 23 +- include/nw4r/ef/ef_drawstrategybuilder.h | 42 +- include/nw4r/ef/ef_drawstrategyimpl.h | 66 +- include/nw4r/ef/ef_drawstripestrategy.h | 31 +- include/nw4r/ef/ef_effect.h | 103 ++- include/nw4r/ef/ef_effectsystem.h | 98 ++- include/nw4r/ef/ef_emform.h | 42 +- include/nw4r/ef/ef_emitter.h | 490 +++++++-------- include/nw4r/ef/ef_emitterform.h | 28 +- include/nw4r/ef/ef_handle.h | 46 +- include/nw4r/ef/ef_list.h | 112 ++-- include/nw4r/ef/ef_memorymanagerbase.h | 75 ++- include/nw4r/ef/ef_particle.h | 35 +- include/nw4r/ef/ef_particlemanager.h | 138 ++-- include/nw4r/ef/ef_rand.h | 61 +- include/nw4r/ef/ef_ref.h | 83 ++- include/nw4r/ef/ef_resource.h | 25 +- include/nw4r/ef/ef_util.h | 32 +- include/nw4r/g3d/g3d_3dsmax.h | 24 +- include/nw4r/g3d/g3d_anmcamera.h | 2 +- include/nw4r/g3d/g3d_anmchr.h | 47 +- include/nw4r/g3d/g3d_anmclr.h | 32 +- include/nw4r/g3d/g3d_anmfog.h | 2 +- include/nw4r/g3d/g3d_anmobj.h | 214 +++---- include/nw4r/g3d/g3d_anmscn.h | 102 ++- include/nw4r/g3d/g3d_anmvis.h | 342 +++++----- include/nw4r/g3d/g3d_calcview.h | 16 +- include/nw4r/g3d/g3d_calcworld.h | 22 +- include/nw4r/g3d/g3d_camera.h | 2 +- include/nw4r/g3d/g3d_cpu.h | 23 +- include/nw4r/g3d/g3d_dcc.h | 15 +- include/nw4r/g3d/g3d_draw.h | 22 +- include/nw4r/g3d/g3d_draw1mat1shp.h | 22 +- include/nw4r/g3d/g3d_fog.h | 2 +- include/nw4r/g3d/g3d_gpu.h | 2 +- include/nw4r/g3d/g3d_init.h | 2 +- include/nw4r/g3d/g3d_light.h | 2 +- include/nw4r/g3d/g3d_maya.h | 24 +- include/nw4r/g3d/g3d_obj.h | 2 +- include/nw4r/g3d/g3d_resanm.h | 161 +++-- include/nw4r/g3d/g3d_resanmcamera.h | 40 +- include/nw4r/g3d/g3d_resanmchr.h | 50 +- include/nw4r/g3d/g3d_resanmfog.h | 40 +- include/nw4r/g3d/g3d_resanmscn.h | 68 +- include/nw4r/g3d/g3d_resanmshp.h | 50 +- include/nw4r/g3d/g3d_rescommon.h | 239 ++++--- include/nw4r/g3d/g3d_resdict.h | 93 ++- include/nw4r/g3d/g3d_resfile.h | 167 +++-- include/nw4r/g3d/g3d_resmat.h | 2 +- include/nw4r/g3d/g3d_resmdl.h | 159 +++-- include/nw4r/g3d/g3d_resnode.h | 108 ++-- include/nw4r/g3d/g3d_resshp.h | 216 +++---- include/nw4r/g3d/g3d_restex.h | 2 +- include/nw4r/g3d/g3d_scnmdl.h | 65 +- include/nw4r/g3d/g3d_scnmdl1mat1shp.h | 50 +- include/nw4r/g3d/g3d_scnmdlsmpl.h | 136 ++-- include/nw4r/g3d/g3d_scnobj.h | 590 ++++++++---------- include/nw4r/g3d/g3d_scnproc.h | 140 ++--- include/nw4r/g3d/g3d_scnrfl.h | 91 ++- include/nw4r/g3d/g3d_scnroot.h | 63 +- include/nw4r/g3d/g3d_state.h | 2 +- include/nw4r/g3d/g3d_tmem.h | 27 +- include/nw4r/g3d/g3d_workmem.h | 36 +- include/nw4r/g3d/g3d_xsi.h | 24 +- include/nw4r/lyt/lyt_animation.h | 127 ++-- include/nw4r/lyt/lyt_arcResourceAccessor.h | 7 +- include/nw4r/lyt/lyt_bounding.h | 48 +- include/nw4r/lyt/lyt_common.h | 85 ++- include/nw4r/lyt/lyt_drawInfo.h | 37 +- include/nw4r/lyt/lyt_group.h | 84 ++- include/nw4r/lyt/lyt_layout.h | 14 +- include/nw4r/lyt/lyt_material.h | 5 +- include/nw4r/lyt/lyt_pane.h | 274 ++++---- include/nw4r/lyt/lyt_resourceAccessor.h | 31 +- include/nw4r/lyt/lyt_texMap.h | 2 +- include/nw4r/snd/snd_BankFile.h | 178 +++--- include/nw4r/snd/snd_Channel.h | 294 +++++---- include/nw4r/snd/snd_ChannelManager.h | 28 +- include/nw4r/snd/snd_DisposeCallback.h | 34 +- include/nw4r/snd/snd_DisposeCallbackManager.h | 42 +- include/nw4r/snd/snd_FrameHeap.h | 153 ++--- include/nw4r/snd/snd_FxBase.h | 43 +- include/nw4r/snd/snd_FxChorus.h | 79 ++- include/nw4r/snd/snd_FxDelay.h | 79 ++- include/nw4r/snd/snd_FxReverbHi.h | 85 ++- include/nw4r/snd/snd_InstancePool.h | 3 +- include/nw4r/snd/snd_MmlParser.h | 76 ++- include/nw4r/snd/snd_MmlSeqTrack.h | 63 +- include/nw4r/snd/snd_MmlSeqTrackAllocator.h | 48 +- include/nw4r/snd/snd_NoteOn.h | 53 +- include/nw4r/snd/snd_PlayerHeap.h | 28 +- include/nw4r/snd/snd_RemoteSpeaker.h | 134 ++-- include/nw4r/snd/snd_SeqFile.h | 58 +- include/nw4r/snd/snd_SeqPlayer.h | 245 ++++---- include/nw4r/snd/snd_SeqSound.h | 181 +++--- include/nw4r/snd/snd_SeqSoundHandle.h | 31 +- include/nw4r/snd/snd_SeqTrack.h | 238 ++++--- include/nw4r/snd/snd_Sound3DListener.h | 33 +- include/nw4r/snd/snd_SoundArchive.h | 300 +++++---- include/nw4r/snd/snd_SoundArchiveFile.h | 513 +++++++-------- include/nw4r/snd/snd_SoundArchiveLoader.h | 85 ++- include/nw4r/snd/snd_SoundArchivePlayer.h | 71 +-- include/nw4r/snd/snd_SoundHandle.h | 63 +- include/nw4r/snd/snd_SoundHeap.h | 47 +- include/nw4r/snd/snd_SoundInstanceManager.h | 108 ++-- include/nw4r/snd/snd_SoundMemoryAllocatable.h | 23 +- include/nw4r/snd/snd_SoundPlayer.h | 58 +- include/nw4r/snd/snd_SoundStartable.h | 63 +- include/nw4r/snd/snd_SoundSystem.h | 48 +- include/nw4r/snd/snd_SoundThread.h | 2 +- include/nw4r/snd/snd_StrmChannel.h | 44 +- include/nw4r/snd/snd_StrmPlayer.h | 95 ++- include/nw4r/snd/snd_StrmSound.h | 56 +- include/nw4r/snd/snd_StrmSoundHandle.h | 32 +- include/nw4r/snd/snd_Task.h | 42 +- include/nw4r/snd/snd_TaskManager.h | 2 +- include/nw4r/snd/snd_TaskThread.h | 2 +- include/nw4r/snd/snd_Util.h | 130 ++-- include/nw4r/snd/snd_Voice.h | 110 ++-- include/nw4r/snd/snd_VoiceManager.h | 34 +- include/nw4r/snd/snd_WaveFile.h | 59 +- include/nw4r/snd/snd_WaveSound.h | 2 +- include/nw4r/snd/snd_WaveSoundHandle.h | 32 +- include/nw4r/snd/snd_WsdPlayer.h | 72 +-- include/rvl/ARC/arc.h | 7 + include/rvl/GX/GXInternal.h | 6 +- include/rvl/GX/GXTexture.h | 1 + src/nw4r/lyt/lyt_animation.cpp | 0 src/nw4r/lyt/lyt_arcResourceAccessor.cpp | 197 ++++++ src/nw4r/lyt/lyt_bounding.cpp | 0 src/nw4r/lyt/lyt_common.cpp | 189 ++++++ src/nw4r/lyt/lyt_drawInfo.cpp | 0 src/nw4r/lyt/lyt_group.cpp | 0 src/nw4r/lyt/lyt_init.cpp | 0 src/nw4r/lyt/lyt_layout.cpp | 0 src/nw4r/lyt/lyt_material.cpp | 0 src/nw4r/lyt/lyt_pane.cpp | 0 src/nw4r/lyt/lyt_picture.cpp | 0 src/nw4r/lyt/lyt_resourceAccessor.cpp | 0 src/nw4r/lyt/lyt_texMap.cpp | 0 src/nw4r/lyt/lyt_textBox.cpp | 0 src/nw4r/lyt/lyt_util.cpp | 33 + src/nw4r/lyt/lyt_window.cpp | 0 157 files changed, 5276 insertions(+), 5580 deletions(-) create mode 100644 src/nw4r/lyt/lyt_animation.cpp create mode 100644 src/nw4r/lyt/lyt_arcResourceAccessor.cpp create mode 100644 src/nw4r/lyt/lyt_bounding.cpp create mode 100644 src/nw4r/lyt/lyt_common.cpp create mode 100644 src/nw4r/lyt/lyt_drawInfo.cpp create mode 100644 src/nw4r/lyt/lyt_group.cpp create mode 100644 src/nw4r/lyt/lyt_init.cpp create mode 100644 src/nw4r/lyt/lyt_layout.cpp create mode 100644 src/nw4r/lyt/lyt_material.cpp create mode 100644 src/nw4r/lyt/lyt_pane.cpp create mode 100644 src/nw4r/lyt/lyt_picture.cpp create mode 100644 src/nw4r/lyt/lyt_resourceAccessor.cpp create mode 100644 src/nw4r/lyt/lyt_texMap.cpp create mode 100644 src/nw4r/lyt/lyt_textBox.cpp create mode 100644 src/nw4r/lyt/lyt_util.cpp create mode 100644 src/nw4r/lyt/lyt_window.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 6387bd67..4cc6a08a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -27,6 +27,7 @@ "xtr1common": "cpp", "limits": "cpp", "utility": "cpp", - "initializer_list": "cpp" + "initializer_list": "cpp", + "new": "cpp" } } diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index b1f0165e..cbff745b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -316,6 +316,12 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/lyt/lyt_common.cpp: + .text start:0x80492780 end:0x804932E0 + .sbss start:0x80576720 end:0x80576728 + .sdata2 start:0x8057F2E0 end:0x8057F2E8 + .bss start:0x80673AA8 end:0x80673AC8 + egg/core/eggArchive.cpp: .text start:0x80493510 end:0x80494254 .data start:0x8056E820 end:0x8056E830 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 48b7e544..33de0e69 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -22589,7 +22589,7 @@ fn_803CDAD0 = .text:0x803CDAD0; // type:function size:0xD0 fn_803CDBA0 = .text:0x803CDBA0; // type:function size:0x10 fn_803CDBB0 = .text:0x803CDBB0; // type:function size:0x8 MEMAllocFromAllocator = .text:0x803CDBC0; // type:function size:0x10 -fn_803CDBD0 = .text:0x803CDBD0; // type:function size:0x10 +MEMFreeToAllocator = .text:0x803CDBD0; // type:function size:0x10 fn_803CDBE0 = .text:0x803CDBE0; // type:function size:0x1C fn_803CDC00 = .text:0x803CDC00; // type:function size:0x18 fn_803CDC20 = .text:0x803CDC20; // type:function size:0x70 @@ -40878,12 +40878,12 @@ lbl_805766D8 = .sbss:0x805766D8; // type:object size:0x8 data:byte lbl_805766E0 = .sbss:0x805766E0; // type:object size:0x8 data:byte lbl_805766E8 = .sbss:0x805766E8; // type:object size:0x8 data:4byte lbl_805766F0 = .sbss:0x805766F0; // type:object size:0x8 data:4byte -lbl_805766F8 = .sbss:0x805766F8; // type:object size:0x8 data:4byte +mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x8 data:4byte lbl_80576700 = .sbss:0x80576700; // type:object size:0x8 data:4byte lbl_80576708 = .sbss:0x80576708; // type:object size:0x8 data:4byte lbl_80576710 = .sbss:0x80576710; // type:object size:0x8 data:4byte lbl_80576718 = .sbss:0x80576718; // type:object size:0x8 data:4byte -lbl_80576720 = .sbss:0x80576720; // type:object size:0x8 data:byte +@GUARD@SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc@texCoords = .sbss:0x80576720; // type:object size:0x1 data:byte lbl_80576728 = .sbss:0x80576728; // type:object size:0x8 data:byte lbl_80576730 = .sbss:0x80576730; // type:object size:0x8 data:byte lbl_80576738 = .sbss:0x80576738; // type:object size:0x8 data:4byte @@ -49350,7 +49350,7 @@ lbl_80673A38 = .bss:0x80673A38; // type:object size:0xC lbl_80673A44 = .bss:0x80673A44; // type:object size:0x3C lbl_80673A80 = .bss:0x80673A80; // type:object size:0xC lbl_80673A8C = .bss:0x80673A8C; // type:object size:0x1C data:byte -lbl_80673AA8 = .bss:0x80673AA8; // type:object size:0x20 data:float +@LOCAL@SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc@texCoords = .bss:0x80673AA8; // type:object size:0x20 scope:local data:float lbl_80673AC8 = .bss:0x80673AC8; // type:object size:0x10 lbl_80673AD8 = .bss:0x80673AD8; // type:object size:0x10 sHeapList__Q23EGG4Heap = .bss:0x80673AE8; // type:object size:0xC diff --git a/configure.py b/configure.py index 8b572602..21bb27b7 100644 --- a/configure.py +++ b/configure.py @@ -155,6 +155,7 @@ cflags_base = [ "-str reuse", "-enc SJIS", "-i include", + "-i include/MSL_C", f"-i build/{config.version}/include", f"-DVERSION={version_num}", ] @@ -347,6 +348,12 @@ config.libs = [ Object(Matching, "nw4r/ut/ut_TextWriterBase.cpp"), ], ), + nw4rLib( + "lyt", + [ + Object(Matching, "nw4r/lyt/lyt_common.cpp"), + ], + ), # EGG EGGLib( "core", diff --git a/include/nw4r/ef/ef_animcurve.h b/include/nw4r/ef/ef_animcurve.h index 3471172c..b5b4efca 100644 --- a/include/nw4r/ef/ef_animcurve.h +++ b/include/nw4r/ef/ef_animcurve.h @@ -1,13 +1,11 @@ #ifndef NW4R_EF_ANIMCURVE_H #define NW4R_EF_ANIMCURVE_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - UNKTYPE AnimCurveExecuteF32(u8 *, float *, u32, u16, u32); - } +namespace nw4r { +namespace ef { +UNKTYPE AnimCurveExecuteF32(u8 *, float *, u32, u16, u32); } +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/ef/ef_creationqueue.h b/include/nw4r/ef/ef_creationqueue.h index 9cccffc7..0a544783 100644 --- a/include/nw4r/ef/ef_creationqueue.h +++ b/include/nw4r/ef/ef_creationqueue.h @@ -1,46 +1,38 @@ #ifndef NW4R_EF_CREATIONQUEUE #define NW4R_EF_CREATIONQUEUE +#include "common.h" #include "ef_emitter.h" -#include "types_nw4r.h" -namespace nw4r -{ - namespace ef - { - enum CreationType - { - CreationType_Particle, - CreationType_Emitter - }; - - //sizeof(UNK_CREATIONQUEUE) = 0x14 - struct Creation - { - u8 mType; // at 0x0 - u16 SHORT_0x2; - EmitterInheritSetting mInheritSetting; // at 0x4 - Particle * mParticle; // at 0x8 - EmitterResource * mResource; // at 0xc - }; - - struct CreationQueue - { - CreationQueue(); - void AddParticleCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); - void AddEmitterCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); - - int mSize; - - Creation mCreations[0x400]; - - inline bool IsEmpty() - { - return mSize == 0; - } - - void Execute(); - }; - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace ef { +enum CreationType { CreationType_Particle, CreationType_Emitter }; + +// sizeof(UNK_CREATIONQUEUE) = 0x14 +struct Creation { + u8 mType; // at 0x0 + u16 SHORT_0x2; + EmitterInheritSetting mInheritSetting; // at 0x4 + Particle *mParticle; // at 0x8 + EmitterResource *mResource; // at 0xc +}; + +struct CreationQueue { + CreationQueue(); + void AddParticleCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); + void AddEmitterCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); + + int mSize; + + Creation mCreations[0x400]; + + inline bool IsEmpty() { + return mSize == 0; + } + + void Execute(); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawbillboardstrategy.h b/include/nw4r/ef/ef_drawbillboardstrategy.h index 2bdf88cf..291f53e4 100644 --- a/include/nw4r/ef/ef_drawbillboardstrategy.h +++ b/include/nw4r/ef/ef_drawbillboardstrategy.h @@ -1,22 +1,19 @@ #ifndef NW4R_EF_DRAW_BILLBOARD_STRATEGY_H #define NW4R_EF_DRAW_BILLBOARD_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawBillboardStrategy : public DrawStrategyImpl - { - public: - DrawBillboardStrategy(); - virtual ~DrawBillboardStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - void Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawBillboardStrategy : public DrawStrategyImpl { +public: + DrawBillboardStrategy(); + virtual ~DrawBillboardStrategy() {} // at 0x8 + virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 -#endif \ No newline at end of file + void Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawdirectionalstrategy.h b/include/nw4r/ef/ef_drawdirectionalstrategy.h index 47abae96..a88630e9 100644 --- a/include/nw4r/ef/ef_drawdirectionalstrategy.h +++ b/include/nw4r/ef/ef_drawdirectionalstrategy.h @@ -1,22 +1,19 @@ #ifndef NW4R_EF_DRAW_DIRECTIONAL_STRATEGY_H #define NW4R_EF_DRAW_DIRECTIONAL_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawDirectionalStrategy : public DrawStrategyImpl - { - public: - DrawDirectionalStrategy(); - virtual ~DrawDirectionalStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - void Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawDirectionalStrategy : public DrawStrategyImpl { +public: + DrawDirectionalStrategy(); + virtual ~DrawDirectionalStrategy() {} // at 0x8 + virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 -#endif \ No newline at end of file + void Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawfreestrategy.h b/include/nw4r/ef/ef_drawfreestrategy.h index 42b156b0..6de764a9 100644 --- a/include/nw4r/ef/ef_drawfreestrategy.h +++ b/include/nw4r/ef/ef_drawfreestrategy.h @@ -1,21 +1,18 @@ #ifndef NW4R_EF_DRAW_FREE_STRATEGY_H #define NW4R_EF_DRAW_FREE_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawFreeStrategy : public DrawStrategyImpl - { - public: - DrawFreeStrategy(); - virtual ~DrawFreeStrategy() {} // at 0x8 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawFreeStrategy : public DrawStrategyImpl { +public: + DrawFreeStrategy(); + virtual ~DrawFreeStrategy() {} // at 0x8 -#endif \ No newline at end of file + UNKTYPE Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawinfo.h b/include/nw4r/ef/ef_drawinfo.h index a156d1ab..4bbb83b3 100644 --- a/include/nw4r/ef/ef_drawinfo.h +++ b/include/nw4r/ef/ef_drawinfo.h @@ -1,16 +1,11 @@ #ifndef NW4R_EF_DRAWINFO #define NW4R_EF_DRAWINFO -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct DrawInfo - { - - }; - } -} +namespace nw4r { +namespace ef { +struct DrawInfo {}; +} // namespace ef +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/ef/ef_drawlinestrategy.h b/include/nw4r/ef/ef_drawlinestrategy.h index cdc87596..46a40d6b 100644 --- a/include/nw4r/ef/ef_drawlinestrategy.h +++ b/include/nw4r/ef/ef_drawlinestrategy.h @@ -1,21 +1,18 @@ #ifndef NW4R_EF_DRAW_LINE_STRATEGY_H #define NW4R_EF_DRAW_LINE_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawLineStrategy : public DrawStrategyImpl - { - public: - DrawLineStrategy(); - virtual ~DrawLineStrategy() {} // at 0x8 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawLineStrategy : public DrawStrategyImpl { +public: + DrawLineStrategy(); + virtual ~DrawLineStrategy() {} // at 0x8 -#endif \ No newline at end of file + UNKTYPE Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_draworder.h b/include/nw4r/ef/ef_draworder.h index 53a568bd..b72c51bb 100644 --- a/include/nw4r/ef/ef_draworder.h +++ b/include/nw4r/ef/ef_draworder.h @@ -1,20 +1,17 @@ #ifndef NW4R_EF_DRAWORDER #define NW4R_EF_DRAWORDER -#include "types_nw4r.h" -#include "ef_particlemanager.h" +#include "common.h" #include "ef_draworderbase.h" +#include "ef_particlemanager.h" -namespace nw4r -{ - namespace ef - { - struct DrawOrder : DrawOrderBase - { - void Draw(Effect *, const DrawInfo &); - void Add(Effect *, ParticleManager *); - void Remove(Effect *, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +struct DrawOrder : DrawOrderBase { + void Draw(Effect *, const DrawInfo &); + void Add(Effect *, ParticleManager *); + void Remove(Effect *, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/ef/ef_drawpointstrategy.h b/include/nw4r/ef/ef_drawpointstrategy.h index ef4ca9d1..8b037377 100644 --- a/include/nw4r/ef/ef_drawpointstrategy.h +++ b/include/nw4r/ef/ef_drawpointstrategy.h @@ -1,22 +1,19 @@ #ifndef NW4R_EF_DRAW_POINT_STRATEGY_H #define NW4R_EF_DRAW_POINT_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawPointStrategy : public DrawStrategyImpl - { - public: - DrawPointStrategy(); - virtual ~DrawPointStrategy() {} // at 0x8 - - void Draw(const DrawInfo&, ParticleManager *); - void InitGraphics(const DrawInfo&, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawPointStrategy : public DrawStrategyImpl { +public: + DrawPointStrategy(); + virtual ~DrawPointStrategy() {} // at 0x8 -#endif \ No newline at end of file + void Draw(const DrawInfo &, ParticleManager *); + void InitGraphics(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawsmoothstripestrategy.h b/include/nw4r/ef/ef_drawsmoothstripestrategy.h index 3a172b5f..d76971c4 100644 --- a/include/nw4r/ef/ef_drawsmoothstripestrategy.h +++ b/include/nw4r/ef/ef_drawsmoothstripestrategy.h @@ -1,22 +1,19 @@ #ifndef NW4R_EF_DRAW_SMOOTH_STRIPE_STRATEGY_H #define NW4R_EF_DRAW_SMOOTH_STRIPE_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawSmoothStripeStrategy : public DrawStrategyImpl - { - public: - DrawSmoothStripeStrategy(); - virtual ~DrawSmoothStripeStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawSmoothStripeStrategy : public DrawStrategyImpl { +public: + DrawSmoothStripeStrategy(); + virtual ~DrawSmoothStripeStrategy() {} // at 0x8 + virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 -#endif \ No newline at end of file + UNKTYPE Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawstrategy.h b/include/nw4r/ef/ef_drawstrategy.h index e3ed01d7..34d3c38c 100644 --- a/include/nw4r/ef/ef_drawstrategy.h +++ b/include/nw4r/ef/ef_drawstrategy.h @@ -1,17 +1,14 @@ #ifndef NW4R_EF_DRAWSTRATEGY_H #define NW4R_EF_DRAWSTRATEGY_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct DrawStrategy - { - inline virtual ~DrawStrategy() {} - virtual UNKTYPE Draw(const DrawInfo &, ParticleManager *) = 0; - }; - } -} +namespace nw4r { +namespace ef { +struct DrawStrategy { + inline virtual ~DrawStrategy() {} + virtual UNKTYPE Draw(const DrawInfo &, ParticleManager *) = 0; +}; +} // namespace ef +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/ef/ef_drawstrategybuilder.h b/include/nw4r/ef/ef_drawstrategybuilder.h index d39e638d..f2de9d2e 100644 --- a/include/nw4r/ef/ef_drawstrategybuilder.h +++ b/include/nw4r/ef/ef_drawstrategybuilder.h @@ -1,27 +1,23 @@ #ifndef NW4R_EF_DRAWSTRATEGYBUILDER_H #define NW4R_EF_DRAWSTRATEGYBUILDER_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - enum DrawStrategyType - { - DrawStratType_Point, - DrawStratType_Line, - DrawStratType_Free, - DrawStratType_Billboard, - DrawStratType_Directional, - DrawStratType_Stripe, - DrawStratType_SmoothStripe - }; - - struct DrawStrategyBuilder - { - virtual DrawStrategy * Create(u32); - }; - } -} +namespace nw4r { +namespace ef { +enum DrawStrategyType { + DrawStratType_Point, + DrawStratType_Line, + DrawStratType_Free, + DrawStratType_Billboard, + DrawStratType_Directional, + DrawStratType_Stripe, + DrawStratType_SmoothStripe +}; -#endif \ No newline at end of file +struct DrawStrategyBuilder { + virtual DrawStrategy *Create(u32); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_drawstrategyimpl.h b/include/nw4r/ef/ef_drawstrategyimpl.h index c236a044..2a88e87b 100644 --- a/include/nw4r/ef/ef_drawstrategyimpl.h +++ b/include/nw4r/ef/ef_drawstrategyimpl.h @@ -1,44 +1,40 @@ #ifndef NW4R_EF_DRAW_STRATEGY_IMPL_H #define NW4R_EF_DRAW_STRATEGY_IMPL_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategy.h" #include "math_types.h" -namespace nw4r -{ - namespace ef - { - class DrawStrategyImpl : public DrawStrategy - { - public: - struct PrevTexture - { - UNKWORD WORD_0x0; - f32 FLOAT_0x4; - f32 FLOAT_0x8; - f32 FLOAT_0xC; - f32 FLOAT_0x10; - UNKWORD WORD_0x14; - UNKWORD WORD_0x18; - math::VEC2 VEC2_0x1C; - f32 FLOAT_0x24; - math::VEC2 VEC2_0x28; - }; +namespace nw4r { +namespace ef { +class DrawStrategyImpl : public DrawStrategy { +public: + struct PrevTexture { + UNKWORD WORD_0x0; + f32 FLOAT_0x4; + f32 FLOAT_0x8; + f32 FLOAT_0xC; + f32 FLOAT_0x10; + UNKWORD WORD_0x14; + UNKWORD WORD_0x18; + math::VEC2 VEC2_0x1C; + f32 FLOAT_0x24; + math::VEC2 VEC2_0x28; + }; - public: - DrawStrategyImpl(); - virtual UNKTYPE GetGetFirstDrawParticleFunc(int); - virtual UNKTYPE GetGetNextDrawParticleFunc(int); +public: + DrawStrategyImpl(); + virtual UNKTYPE GetGetFirstDrawParticleFunc(int); + virtual UNKTYPE GetGetNextDrawParticleFunc(int); - void InitTexture(const EmitterDrawSetting &); - void InitTev(const EmitterDrawSetting &, const DrawInfo &); - void InitColor(ParticleManager *, const EmitterDrawSetting &, const DrawInfo &); + void InitTexture(const EmitterDrawSetting &); + void InitTev(const EmitterDrawSetting &, const DrawInfo &); + void InitColor(ParticleManager *, const EmitterDrawSetting &, const DrawInfo &); - private: - PrevTexture mPrevTextures[3]; // at 0x4 - char UNK_0x94[0xBC - 0x94]; - }; - } -} +private: + PrevTexture mPrevTextures[3]; // at 0x4 + char UNK_0x94[0xBC - 0x94]; +}; +} // namespace ef +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/ef/ef_drawstripestrategy.h b/include/nw4r/ef/ef_drawstripestrategy.h index ccdbc04f..2edf9238 100644 --- a/include/nw4r/ef/ef_drawstripestrategy.h +++ b/include/nw4r/ef/ef_drawstripestrategy.h @@ -1,22 +1,19 @@ #ifndef NW4R_EF_DRAW_STRIPE_STRATEGY_H #define NW4R_EF_DRAW_STRIPE_STRATEGY_H -#include "types_nw4r.h" +#include "common.h" #include "ef_drawstrategyimpl.h" -namespace nw4r -{ - namespace ef - { - class DrawStripeStrategy : public DrawStrategyImpl - { - public: - DrawStripeStrategy(); - virtual ~DrawStripeStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); - }; - } -} +namespace nw4r { +namespace ef { +class DrawStripeStrategy : public DrawStrategyImpl { +public: + DrawStripeStrategy(); + virtual ~DrawStripeStrategy() {} // at 0x8 + virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 -#endif \ No newline at end of file + UNKTYPE Draw(const DrawInfo &, ParticleManager *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_effect.h b/include/nw4r/ef/ef_effect.h index 24050fc8..bed4ac26 100644 --- a/include/nw4r/ef/ef_effect.h +++ b/include/nw4r/ef/ef_effect.h @@ -1,59 +1,56 @@ #ifndef NW4R_EF_EFFECT #define NW4R_EF_EFFECT -#include "types_nw4r.h" -#include "math_types.h" -#include "ef_ref.h" -#include "ut_list.h" +#include "common.h" #include "ef_list.h" +#include "ef_ref.h" #include "ef_util.h" +#include "math_types.h" +#include "ut_list.h" -namespace nw4r -{ - namespace ef - { - struct Effect : ReferencedObject - { - EffectSystem * mSystem; // at 0x20 - ActivityList mEmitters; // at 0x24 - u32 INDEX_0x40; - - void (* mEmissionPrologue)(Emitter *, ParticleManager *, int *, u32 *, float *, u16 *, float *, math::MTX34 *); // at 0x44 - - UNKWORD WORD_0x48; - UNKWORD WORD_0x4C; - u32 mFlags; // at 0x50 - math::MTX34 mRootMtx; // at 0x54 - math::VEC3 VEC_0x84; - ut::List UTLIST_0x90; - DrawOrder * mDrawOrder; // at 0x9c - - Effect(); - ~Effect(); - - virtual bool Initialize(EffectSystem *, EmitterResource *, u16); - virtual Emitter * CreateEmitter(ResEmitter, u8, u16); - virtual void Calc(bool); - virtual void Draw(const DrawInfo &); - - bool SendClosing(); - UNKTYPE DestroyFunc(); - bool Closing(Emitter *); - Emitter * CreateEmitter(EmitterResource *, u8, u16); - bool RetireEmitter(Emitter *); - u16 RetireEmitterAll(); - u16 RetireParticleAll(); - u16 GetNumEmitter() const; - Emitter * GetEmitter(u16); - u16 ForeachParticleManager(Action, u32, bool); - u16 ForeachEmitterFrom(Action, u32, bool, Emitter *); - UNKTYPE SetRootMtx(const math::MTX34 &); - - inline bool GetFlagDisableDraw() - { - return mFlags & 2; - } - }; - } -} +namespace nw4r { +namespace ef { +struct Effect : ReferencedObject { + EffectSystem *mSystem; // at 0x20 + ActivityList mEmitters; // at 0x24 + u32 INDEX_0x40; -#endif \ No newline at end of file + void (*mEmissionPrologue)(Emitter *, ParticleManager *, int *, u32 *, float *, u16 *, float *, + math::MTX34 *); // at 0x44 + + UNKWORD WORD_0x48; + UNKWORD WORD_0x4C; + u32 mFlags; // at 0x50 + math::MTX34 mRootMtx; // at 0x54 + math::VEC3 VEC_0x84; + ut::List UTLIST_0x90; + DrawOrder *mDrawOrder; // at 0x9c + + Effect(); + ~Effect(); + + virtual bool Initialize(EffectSystem *, EmitterResource *, u16); + virtual Emitter *CreateEmitter(ResEmitter, u8, u16); + virtual void Calc(bool); + virtual void Draw(const DrawInfo &); + + bool SendClosing(); + UNKTYPE DestroyFunc(); + bool Closing(Emitter *); + Emitter *CreateEmitter(EmitterResource *, u8, u16); + bool RetireEmitter(Emitter *); + u16 RetireEmitterAll(); + u16 RetireParticleAll(); + u16 GetNumEmitter() const; + Emitter *GetEmitter(u16); + u16 ForeachParticleManager(Action, u32, bool); + u16 ForeachEmitterFrom(Action, u32, bool, Emitter *); + UNKTYPE SetRootMtx(const math::MTX34 &); + + inline bool GetFlagDisableDraw() { + return mFlags & 2; + } +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_effectsystem.h b/include/nw4r/ef/ef_effectsystem.h index 93ccccf7..68177a21 100644 --- a/include/nw4r/ef/ef_effectsystem.h +++ b/include/nw4r/ef/ef_effectsystem.h @@ -1,57 +1,53 @@ #ifndef NW4R_EF_EFFECTSYSTEM #define NW4R_EF_EFFECTSYSTEM -#include "types_nw4r.h" +#include "common.h" #include "ef_creationqueue.h" -#include "ef_ref.h" -#include "ef_rand.h" #include "ef_list.h" +#include "ef_rand.h" +#include "ef_ref.h" -namespace nw4r -{ - namespace ef - { - struct EffectSystem - { - static bool mDisplayVersion; - - static EffectSystem instance; - - MemoryManager * mMemoryManager; // at 0x0 - DrawOrder * mDrawOrder; // at 0x4 - DrawStrategyBuilder * mDrawStrategyBuilder; // at 0x8 - EmitFormBuilder * mEmitFormBuilder; // at 0xc - CreationQueue mCreationQueue; // at 0x10 - u32 mNumGroup; - ActivityList * ARR_0x5018; - Random mRandom; // at 0x501C - math::VEC3 VEC_0x5020; - math::MTX34 MTX_0x502C; - float FLOAT_0x505C; - float FLOAT_0x5060; - char BYTE_0x5064; - - inline MemoryManager * GetMemoryManager() const - { - return mMemoryManager; - } - - EffectSystem(); - ~EffectSystem(); - - static EffectSystem * GetInstance(); - - bool Initialize(u32); - bool Closing(Effect *); - Effect * CreateEffect(const char *, u32, u16); - bool RetireEffect(Effect *); - u16 RetireEffectAll(u32); - u16 RetireEmitterAll(u32); - u16 RetireParticleAll(u32); - - void Calc(u32, bool); - void Draw(const DrawInfo &, u32); - }; - } -} +namespace nw4r { +namespace ef { +struct EffectSystem { + static bool mDisplayVersion; -#endif \ No newline at end of file + static EffectSystem instance; + + MemoryManager *mMemoryManager; // at 0x0 + DrawOrder *mDrawOrder; // at 0x4 + DrawStrategyBuilder *mDrawStrategyBuilder; // at 0x8 + EmitFormBuilder *mEmitFormBuilder; // at 0xc + CreationQueue mCreationQueue; // at 0x10 + u32 mNumGroup; + ActivityList *ARR_0x5018; + Random mRandom; // at 0x501C + math::VEC3 VEC_0x5020; + math::MTX34 MTX_0x502C; + float FLOAT_0x505C; + float FLOAT_0x5060; + char BYTE_0x5064; + + inline MemoryManager *GetMemoryManager() const { + return mMemoryManager; + } + + EffectSystem(); + ~EffectSystem(); + + static EffectSystem *GetInstance(); + + bool Initialize(u32); + bool Closing(Effect *); + Effect *CreateEffect(const char *, u32, u16); + bool RetireEffect(Effect *); + u16 RetireEffectAll(u32); + u16 RetireEmitterAll(u32); + u16 RetireParticleAll(u32); + + void Calc(u32, bool); + void Draw(const DrawInfo &, u32); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_emform.h b/include/nw4r/ef/ef_emform.h index 97f8adf2..c0d00924 100644 --- a/include/nw4r/ef/ef_emform.h +++ b/include/nw4r/ef/ef_emform.h @@ -1,27 +1,23 @@ #ifndef NW4R_EF_EMFORM_H #define NW4R_EF_EMFORM_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - enum EmitFormType - { - EmitForm_Disc, - EmitForm_Line, - EmitForm_Cube = 5, - EmitForm_Cylinder = 7, - EmitForm_Sphere, - EmitForm_Point, - EmitForm_Torus - }; - - struct EmitFormBuilder - { - virtual EmitterForm * Create(EmitFormType); - }; - } -} +namespace nw4r { +namespace ef { +enum EmitFormType { + EmitForm_Disc, + EmitForm_Line, + EmitForm_Cube = 5, + EmitForm_Cylinder = 7, + EmitForm_Sphere, + EmitForm_Point, + EmitForm_Torus +}; -#endif \ No newline at end of file +struct EmitFormBuilder { + virtual EmitterForm *Create(EmitFormType); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_emitter.h b/include/nw4r/ef/ef_emitter.h index b19ae39a..386eba51 100644 --- a/include/nw4r/ef/ef_emitter.h +++ b/include/nw4r/ef/ef_emitter.h @@ -1,259 +1,247 @@ #ifndef NW4R_EF_EMITTER #define NW4R_EF_EMITTER -#include -#include "types_nw4r.h" -#include "ef_ref.h" -#include "ut_list.h" +#include "ef_animcurve.h" #include "ef_list.h" #include "ef_rand.h" +#include "ef_ref.h" #include "ef_util.h" -#include "ef_animcurve.h" +#include "ut_list.h" +#include #include "common.h" -namespace nw4r -{ - namespace ef - { - struct ResEmitter - { - EmitterResource * mPtr; - - inline EmitterResource * ptr() { return mPtr; } - }; - - struct EmitterInheritSetting - { - s16 SHORT_0x0; - u8 BYTE_0x2; - u8 BYTE_0x3; - u8 BYTE_0x4; - u8 BYTE_0x5; - u8 BYTE_0x6; - u8 BYTE_0x7; - }; - struct EmitterDesc - { - UNKWORD FLAGS_0x0; // at 0x0/0x8 - UNKWORD EMFORMTYPE_0x4; // at 0x4/0xc - u16 SHORT_0x8; // at 0x8/0x10 - u16 SHORT_0xA; // at 0xa/0x12 - s8 SBYTE_0xC; // at 0xc/0x14 - s8 SBYTE_0xD; // at 0xd/0x15 - s8 SBYTE_0xE; // at 0xe/0x16 - s8 SBYTE_0xF; // at 0xf/0x17 - float FLOAT_0x10; // at 0x10/0x18 - u16 SHORT_0x14; // at 0x14/0x1c - u16 SHORT_0x16; // at 0x16/0x1e - u16 SHORT_0x18; // at 0x18/0x20 - s8 BYTE_0x1A; // at 0x1a/0x22 - s8 BYTE_0x1B; // at 0x1b/0x23 - float FLOAT_0x1C; - float FLOAT_0x20; - float FLOAT_0x24; - float FLOAT_0x28; - float FLOAT_0x2C; - float FLOAT_0x30; - u16 SHORT_0x34; - u8 BYTE_0x36; - u8 BYTE_0x37; - float FLOAT_0x38; - float FLOAT_0x3C; - float FLOAT_0x40; - float FLOAT_0x44; - float FLOAT_0x48; - float FLOAT_0x4C; - float FLOAT_0x50; - float FLOAT_0x54; - float FLOAT_0x58; - float FLOAT_0x5C; - - float FLOAT_0x60; - float FLOAT_0x64; - float FLOAT_0x68; - float FLOAT_0x6C; - float FLOAT_0x70; - float FLOAT_0x74; - - float FLOAT_0x78; - float FLOAT_0x7C; - float FLOAT_0x80; - - u8 BYTE_0x84; // at 0x84/0x8c - u8 BYTE_0x85; // at 0x85/0x8d - u8 BYTE_0x86; // at 0x86/0x8e - UNKWORD WORD_0x88; - }; - - struct EmitTrack - { - u8 BYTE_0x0; - u8 BYTE_0x1; - u16 SHORT_0x2; - - u8 BYTE_0x4; - }; - - struct EmitterResource - { - char UNK_0x0[0x4]; - u32 OFFSET_0x4; - - EmitterDesc STRUCT_0x8; - - inline UNKTYPE * SkipEmitterDesc() - { - return (char *)&STRUCT_0x8 + OFFSET_0x4; - } - - inline UNKTYPE * SkipParticleParameterDesc() - { - char * particleDesc = (char *)SkipEmitterDesc(); - - return particleDesc + *(int *)particleDesc; - } - - inline u16 NumEmitInitTrack() - { - u16 * ptr = (u16 *)SkipParticleParameterDesc(); - - return ptr[(4**(ptr += 2))+3]; - } - - inline u16 NumEmitTrack() - { - u16 * ptr = (u16 *)SkipParticleParameterDesc(); - - return ptr[(4**(ptr += 2))+2]; - } - - inline EmitTrack * GetEmitTrack(u16 i) - { - u16 * ptr = (u16 *)SkipParticleParameterDesc(); - - return reinterpret_cast(ptr)[(2**(ptr += 1))+1+i]; - } - }; - - struct Emitter : ReferencedObject - { - virtual bool Initialize(Effect *, EmitterResource *, u8); // at 0x10 - virtual Emitter * CreateEmitter(EmitterResource *, EmitterInheritSetting *, Particle *, u16); // at 0x14 - virtual void CalcEmitter(); // at 0x18 - virtual void CalcParticle(); // at 0x1c - virtual void CalcEmission(); // at 0x20 - virtual void CalcBillboard(); // at 0x24 - - u32 mFlags; - UNKWORD WORD_0x24; - - //char UNK_0x28[0x8C]; - float FLOAT_0x28; - float FLOAT_0x2C; - short SHORT_0x30; - short SHORT_0x32; - float FLOAT_0x34; - float FLOAT_0x38; - short SHORT_0x3C; - float FLOAT_0x40; - float FLOAT_0x44; - float FLOAT_0x48; - float FLOAT_0x4C; - float FLOAT_0x50; - float FLOAT_0x54; - float FLOAT_0x58; - float FLOAT_0x5C; - float FLOAT_0x60; - - u8 BYTE_0x64; - s8 BYTE_0x65; - u8 BYTE_0x66; - s8 BYTE_0x67; - - float FLOAT_0x68; - float FLOAT_0x6C; - float FLOAT_0x70; - float FLOAT_0x74; - float FLOAT_0x78; - float FLOAT_0x7C; - float FLOAT_0x80; - float FLOAT_0x84; - float FLOAT_0x88; - float FLOAT_0x8C; - /* - float FLOAT_0x90; - float FLOAT_0x94; - float FLOAT_0x98; - */ - math::VEC3 VEC_0x90; - /* - float FLOAT_0x9C; - float FLOAT_0xA0; - float FLOAT_0xA4; - */ - math::VEC3 VEC_0x9C; - /* - float FLOAT_0xA8; - float FLOAT_0xAC; - float FLOAT_0xB0; - */ - math::VEC3 VEC_0xA8; - - UNKWORD WORD_0xB4; - EmitterResource * mResource; // at 0xb8 - Effect * mEffect; // at 0xbc - ActivityList mManagers; // at 0xc0 - char UNK_0xDA[0x2]; - u8 BYTE_0xDC; - u16 SHORT_0xDE; - u16 SHORT_0xE0; - UNKWORD WORD_0xE4; - u16 SHORT_0xE8; - u16 SHORT_0xEA; - Random mRandom; // at 0xec - EmitterForm * mForm; // at 0xf0 - Emitter * mParent; // at 0xf4 - Particle * REF_0xF8; // at 0xf8 - - EmitterInheritSetting mInheritSettings; // at 0xfc - - bool mMtxDirtyFlag; // at 0x104 - - math::MTX34 mGlobalMtx; // at 0x108 - - Emitter(); - ~Emitter(); - - u16 RetireParticleAll(); - bool SendClosing(); - void DestroyFunc(); - bool Closing(ParticleManager *); - bool RetireParticleManager(ParticleManager *); - u16 RetireParticleManagerAll(); - bool InitializeDatas(EmitterResource *, Effect *); - - ParticleManager * FindParticleManager(EmitterResource *, bool, bool, s8, u8); - UNKTYPE CreateEmitterTmp(EmitterResource *, EmitterInheritSetting *, Particle *, u16); - - float GetLODratio(math::VEC3 &, math::VEC3 &, float, float, float, float); - - u16 ForeachParticleManager(Action, u32, bool, bool); - - UNKTYPE Emission(ParticleManager *, const math::MTX34 *); - - math::MTX34 * CalcGlobalMtx(math::MTX34 *); - UNKTYPE SetMtxDirty(); - - static math::MTX34 * RestructMatrix(math::MTX34 *, math::MTX34 *, bool, bool, s8); - - u16 GetNumParticleManager() const; - ParticleManager * GetParticleManager(u16); - - inline bool GetFlagDisableCalc() const - { - return mFlags & 0x200; - } - }; - } -} +namespace nw4r { +namespace ef { +struct ResEmitter { + EmitterResource *mPtr; -#endif \ No newline at end of file + inline EmitterResource *ptr() { + return mPtr; + } +}; + +struct EmitterInheritSetting { + s16 SHORT_0x0; + u8 BYTE_0x2; + u8 BYTE_0x3; + u8 BYTE_0x4; + u8 BYTE_0x5; + u8 BYTE_0x6; + u8 BYTE_0x7; +}; + +struct EmitterDesc { + UNKWORD FLAGS_0x0; // at 0x0/0x8 + UNKWORD EMFORMTYPE_0x4; // at 0x4/0xc + u16 SHORT_0x8; // at 0x8/0x10 + u16 SHORT_0xA; // at 0xa/0x12 + s8 SBYTE_0xC; // at 0xc/0x14 + s8 SBYTE_0xD; // at 0xd/0x15 + s8 SBYTE_0xE; // at 0xe/0x16 + s8 SBYTE_0xF; // at 0xf/0x17 + float FLOAT_0x10; // at 0x10/0x18 + u16 SHORT_0x14; // at 0x14/0x1c + u16 SHORT_0x16; // at 0x16/0x1e + u16 SHORT_0x18; // at 0x18/0x20 + s8 BYTE_0x1A; // at 0x1a/0x22 + s8 BYTE_0x1B; // at 0x1b/0x23 + float FLOAT_0x1C; + float FLOAT_0x20; + float FLOAT_0x24; + float FLOAT_0x28; + float FLOAT_0x2C; + float FLOAT_0x30; + u16 SHORT_0x34; + u8 BYTE_0x36; + u8 BYTE_0x37; + float FLOAT_0x38; + float FLOAT_0x3C; + float FLOAT_0x40; + float FLOAT_0x44; + float FLOAT_0x48; + float FLOAT_0x4C; + float FLOAT_0x50; + float FLOAT_0x54; + float FLOAT_0x58; + float FLOAT_0x5C; + + float FLOAT_0x60; + float FLOAT_0x64; + float FLOAT_0x68; + float FLOAT_0x6C; + float FLOAT_0x70; + float FLOAT_0x74; + + float FLOAT_0x78; + float FLOAT_0x7C; + float FLOAT_0x80; + + u8 BYTE_0x84; // at 0x84/0x8c + u8 BYTE_0x85; // at 0x85/0x8d + u8 BYTE_0x86; // at 0x86/0x8e + UNKWORD WORD_0x88; +}; + +struct EmitTrack { + u8 BYTE_0x0; + u8 BYTE_0x1; + u16 SHORT_0x2; + + u8 BYTE_0x4; +}; + +struct EmitterResource { + char UNK_0x0[0x4]; + u32 OFFSET_0x4; + + EmitterDesc STRUCT_0x8; + + inline UNKTYPE *SkipEmitterDesc() { + return (char *)&STRUCT_0x8 + OFFSET_0x4; + } + + inline UNKTYPE *SkipParticleParameterDesc() { + char *particleDesc = (char *)SkipEmitterDesc(); + + return particleDesc + *(int *)particleDesc; + } + + inline u16 NumEmitInitTrack() { + u16 *ptr = (u16 *)SkipParticleParameterDesc(); + + return ptr[(4 * *(ptr += 2)) + 3]; + } + + inline u16 NumEmitTrack() { + u16 *ptr = (u16 *)SkipParticleParameterDesc(); + + return ptr[(4 * *(ptr += 2)) + 2]; + } + + inline EmitTrack *GetEmitTrack(u16 i) { + u16 *ptr = (u16 *)SkipParticleParameterDesc(); + + return reinterpret_cast(ptr)[(2 * *(ptr += 1)) + 1 + i]; + } +}; + +struct Emitter : ReferencedObject { + virtual bool Initialize(Effect *, EmitterResource *, u8); // at 0x10 + virtual Emitter *CreateEmitter(EmitterResource *, EmitterInheritSetting *, Particle *, u16); // at 0x14 + virtual void CalcEmitter(); // at 0x18 + virtual void CalcParticle(); // at 0x1c + virtual void CalcEmission(); // at 0x20 + virtual void CalcBillboard(); // at 0x24 + + u32 mFlags; + UNKWORD WORD_0x24; + + // char UNK_0x28[0x8C]; + float FLOAT_0x28; + float FLOAT_0x2C; + short SHORT_0x30; + short SHORT_0x32; + float FLOAT_0x34; + float FLOAT_0x38; + short SHORT_0x3C; + float FLOAT_0x40; + float FLOAT_0x44; + float FLOAT_0x48; + float FLOAT_0x4C; + float FLOAT_0x50; + float FLOAT_0x54; + float FLOAT_0x58; + float FLOAT_0x5C; + float FLOAT_0x60; + + u8 BYTE_0x64; + s8 BYTE_0x65; + u8 BYTE_0x66; + s8 BYTE_0x67; + + float FLOAT_0x68; + float FLOAT_0x6C; + float FLOAT_0x70; + float FLOAT_0x74; + float FLOAT_0x78; + float FLOAT_0x7C; + float FLOAT_0x80; + float FLOAT_0x84; + float FLOAT_0x88; + float FLOAT_0x8C; + /* + float FLOAT_0x90; + float FLOAT_0x94; + float FLOAT_0x98; + */ + math::VEC3 VEC_0x90; + /* + float FLOAT_0x9C; + float FLOAT_0xA0; + float FLOAT_0xA4; + */ + math::VEC3 VEC_0x9C; + /* + float FLOAT_0xA8; + float FLOAT_0xAC; + float FLOAT_0xB0; + */ + math::VEC3 VEC_0xA8; + + UNKWORD WORD_0xB4; + EmitterResource *mResource; // at 0xb8 + Effect *mEffect; // at 0xbc + ActivityList mManagers; // at 0xc0 + char UNK_0xDA[0x2]; + u8 BYTE_0xDC; + u16 SHORT_0xDE; + u16 SHORT_0xE0; + UNKWORD WORD_0xE4; + u16 SHORT_0xE8; + u16 SHORT_0xEA; + Random mRandom; // at 0xec + EmitterForm *mForm; // at 0xf0 + Emitter *mParent; // at 0xf4 + Particle *REF_0xF8; // at 0xf8 + + EmitterInheritSetting mInheritSettings; // at 0xfc + + bool mMtxDirtyFlag; // at 0x104 + + math::MTX34 mGlobalMtx; // at 0x108 + + Emitter(); + ~Emitter(); + + u16 RetireParticleAll(); + bool SendClosing(); + void DestroyFunc(); + bool Closing(ParticleManager *); + bool RetireParticleManager(ParticleManager *); + u16 RetireParticleManagerAll(); + bool InitializeDatas(EmitterResource *, Effect *); + + ParticleManager *FindParticleManager(EmitterResource *, bool, bool, s8, u8); + UNKTYPE CreateEmitterTmp(EmitterResource *, EmitterInheritSetting *, Particle *, u16); + + float GetLODratio(math::VEC3 &, math::VEC3 &, float, float, float, float); + + u16 ForeachParticleManager(Action, u32, bool, bool); + + UNKTYPE Emission(ParticleManager *, const math::MTX34 *); + + math::MTX34 *CalcGlobalMtx(math::MTX34 *); + UNKTYPE SetMtxDirty(); + + static math::MTX34 *RestructMatrix(math::MTX34 *, math::MTX34 *, bool, bool, s8); + + u16 GetNumParticleManager() const; + ParticleManager *GetParticleManager(u16); + + inline bool GetFlagDisableCalc() const { + return mFlags & 0x200; + } +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_emitterform.h b/include/nw4r/ef/ef_emitterform.h index 28de21fb..67ba51e0 100644 --- a/include/nw4r/ef/ef_emitterform.h +++ b/include/nw4r/ef/ef_emitterform.h @@ -1,19 +1,17 @@ #ifndef NW4R_EF_EMITTERFORM_H #define NW4R_EF_EMITTERFORM_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *) = 0; - - UNKTYPE CalcVelocity(math::VEC3 *, Emitter *, const math::VEC3 &, const math::VEC3 &, const math::VEC3 &, const math::VEC3 &) const; - u16 CalcLife(u16, float, Emitter *); - }; - } -} +namespace nw4r { +namespace ef { +struct EmitterForm { + virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *) = 0; -#endif \ No newline at end of file + UNKTYPE CalcVelocity(math::VEC3 *, Emitter *, const math::VEC3 &, const math::VEC3 &, const math::VEC3 &, + const math::VEC3 &) const; + u16 CalcLife(u16, float, Emitter *); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_handle.h b/include/nw4r/ef/ef_handle.h index 4e0c4f6e..34b4e1d2 100644 --- a/include/nw4r/ef/ef_handle.h +++ b/include/nw4r/ef/ef_handle.h @@ -1,29 +1,25 @@ #ifndef NW4R_EF_HANDLE_H #define NW4R_EF_HANDLE_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct LinkedObject - { - char UNK_0x0[8]; - LinkedObject * PTR_0x8; - }; - - struct HandleBase - { - LinkedObject * PTR_0x0; - LinkedObject * mPtr; - - HandleBase(); - HandleBase & operator=(const HandleBase &); - HandleBase & operator=(LinkedObject *); - bool IsValid() const; - LinkedObject * GetPtr() const; - }; - } -} +namespace nw4r { +namespace ef { +struct LinkedObject { + char UNK_0x0[8]; + LinkedObject *PTR_0x8; +}; -#endif \ No newline at end of file +struct HandleBase { + LinkedObject *PTR_0x0; + LinkedObject *mPtr; + + HandleBase(); + HandleBase &operator=(const HandleBase &); + HandleBase &operator=(LinkedObject *); + bool IsValid() const; + LinkedObject *GetPtr() const; +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_list.h b/include/nw4r/ef/ef_list.h index d4ea3468..09efa06e 100644 --- a/include/nw4r/ef/ef_list.h +++ b/include/nw4r/ef/ef_list.h @@ -1,67 +1,57 @@ #ifndef NW4R_EF_LIST #define NW4R_EF_LIST -#include "types_nw4r.h" +#include "common.h" #include "ut_list.h" -namespace nw4r -{ - namespace ef - { - //sizeof(ActivityList) = 0x1C - struct ActivityList - { - ut::List mActive; - ut::List mClosing; - u16 mNumActive; - - inline void SetOffset(u16 offset) - { - ut::List_Init(&mActive, offset); - ut::List_Init(&mClosing, offset); - mNumActive = 0; - } - - inline ActivityList(u16 offset) - { - SetOffset(offset); - } - - inline ActivityList() - { - SetOffset(0); - } - - inline void Initialize() - { - mActive.first = NULL; - mActive.size = 0; - mActive.last = NULL; - - mClosing.first = NULL; - mClosing.size = 0; - mClosing.last = NULL; - - mNumActive = 0; - } - - inline void ToActive(void * pNode) - { - ut::List_Append(&mActive, pNode); - mNumActive++; - } - - inline void ToClosing(void * pNode) - { - ut::List_Remove(&mActive, pNode); - ut::List_Append(&mClosing, pNode); - } - - inline void ToWait(void * pNode) - { - mNumActive--; - } - }; - } -} +namespace nw4r { +namespace ef { +// sizeof(ActivityList) = 0x1C +struct ActivityList { + ut::List mActive; + ut::List mClosing; + u16 mNumActive; + + inline void SetOffset(u16 offset) { + ut::List_Init(&mActive, offset); + ut::List_Init(&mClosing, offset); + mNumActive = 0; + } + + inline ActivityList(u16 offset) { + SetOffset(offset); + } + + inline ActivityList() { + SetOffset(0); + } + + inline void Initialize() { + mActive.first = NULL; + mActive.size = 0; + mActive.last = NULL; + + mClosing.first = NULL; + mClosing.size = 0; + mClosing.last = NULL; + + mNumActive = 0; + } + + inline void ToActive(void *pNode) { + ut::List_Append(&mActive, pNode); + mNumActive++; + } + + inline void ToClosing(void *pNode) { + ut::List_Remove(&mActive, pNode); + ut::List_Append(&mClosing, pNode); + } + + inline void ToWait(void *pNode) { + mNumActive--; + } +}; +} // namespace ef +} // namespace nw4r #endif diff --git a/include/nw4r/ef/ef_memorymanagerbase.h b/include/nw4r/ef/ef_memorymanagerbase.h index bf722d83..61c67bbe 100644 --- a/include/nw4r/ef/ef_memorymanagerbase.h +++ b/include/nw4r/ef/ef_memorymanagerbase.h @@ -1,43 +1,40 @@ #ifndef NW4R_EF_MEMORYMANAGERBASE #define NW4R_EF_MEMORYMANAGERBASE -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct MemoryManagerBase - { - virtual ~MemoryManagerBase(); // at 0x8 - virtual UNKTYPE GarbageCollection() = 0; // at 0xc - - virtual Effect * AllocEffect() = 0; // at 0x10 - virtual UNKTYPE FreeEffect(void *) = 0; // at 0x14 - virtual UNKWORD GetNumAllocEffect() const = 0; // at 0x18 - virtual UNKWORD GetNumActiveEffect() const = 0; // at 0x1c - virtual UNKWORD GetNumFreeEffect() const = 0; // at 0x20 - - virtual Emitter * AllocEmitter() = 0; // at 0x24 - virtual UNKTYPE FreeEmitter(void *) = 0; // at 0x28 - virtual UNKWORD GetNumAllocEmitter() const = 0; // at 0x2c - virtual UNKWORD GetNumActiveEmitter() const = 0; // at 0x30 - virtual UNKWORD GetNumFreeEmitter() const = 0; // at 0x34 - - virtual ParticleManager * AllocParticleManager() = 0; // at 0x38 - virtual UNKTYPE FreeParticleManager(void *) = 0; // at 0x3c - virtual UNKWORD GetNumAllocParticleManager() const = 0; // at 0x40 - virtual UNKWORD GetNumActiveParticleManager() const = 0; // at 0x44 - virtual UNKWORD GetNumFreeParticleManager() const = 0; // at 0x48 - - virtual Particle * AllocParticle() = 0; // at 0x4c - virtual UNKTYPE FreeParticle(void *) = 0; // at 0x50 - virtual UNKWORD GetNumAllocParticle() const = 0; // at 0x54 - virtual UNKWORD GetNumActiveParticle() const = 0; // at 0x58 - virtual UNKWORD GetNumFreeParticle() const = 0; // at 0x5c - - virtual void * AllocHeap(u32) = 0; // at 0x60 - }; - } -} +namespace nw4r { +namespace ef { +struct MemoryManagerBase { + virtual ~MemoryManagerBase(); // at 0x8 + virtual UNKTYPE GarbageCollection() = 0; // at 0xc -#endif \ No newline at end of file + virtual Effect *AllocEffect() = 0; // at 0x10 + virtual UNKTYPE FreeEffect(void *) = 0; // at 0x14 + virtual UNKWORD GetNumAllocEffect() const = 0; // at 0x18 + virtual UNKWORD GetNumActiveEffect() const = 0; // at 0x1c + virtual UNKWORD GetNumFreeEffect() const = 0; // at 0x20 + + virtual Emitter *AllocEmitter() = 0; // at 0x24 + virtual UNKTYPE FreeEmitter(void *) = 0; // at 0x28 + virtual UNKWORD GetNumAllocEmitter() const = 0; // at 0x2c + virtual UNKWORD GetNumActiveEmitter() const = 0; // at 0x30 + virtual UNKWORD GetNumFreeEmitter() const = 0; // at 0x34 + + virtual ParticleManager *AllocParticleManager() = 0; // at 0x38 + virtual UNKTYPE FreeParticleManager(void *) = 0; // at 0x3c + virtual UNKWORD GetNumAllocParticleManager() const = 0; // at 0x40 + virtual UNKWORD GetNumActiveParticleManager() const = 0; // at 0x44 + virtual UNKWORD GetNumFreeParticleManager() const = 0; // at 0x48 + + virtual Particle *AllocParticle() = 0; // at 0x4c + virtual UNKTYPE FreeParticle(void *) = 0; // at 0x50 + virtual UNKWORD GetNumAllocParticle() const = 0; // at 0x54 + virtual UNKWORD GetNumActiveParticle() const = 0; // at 0x58 + virtual UNKWORD GetNumFreeParticle() const = 0; // at 0x5c + + virtual void *AllocHeap(u32) = 0; // at 0x60 +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_particle.h b/include/nw4r/ef/ef_particle.h index faae8309..f0c36aaf 100644 --- a/include/nw4r/ef/ef_particle.h +++ b/include/nw4r/ef/ef_particle.h @@ -1,24 +1,21 @@ #ifndef NW4R_EF_PARTICLE_H #define NW4R_EF_PARTICLE_H -#include "types_nw4r.h" +#include "common.h" #include "ef_ref.h" -namespace nw4r -{ - namespace ef - { - struct Particle : ReferencedObject - { - char UNK_0x20[0x8C]; - - math::VEC3 VEC_0xAC; - math::VEC3 VEC_0xB8; - - char UNK_0xC4[0x4]; - - ParticleManager * mManager; // at 0xc8 - }; - } -} +namespace nw4r { +namespace ef { +struct Particle : ReferencedObject { + char UNK_0x20[0x8C]; -#endif \ No newline at end of file + math::VEC3 VEC_0xAC; + math::VEC3 VEC_0xB8; + + char UNK_0xC4[0x4]; + + ParticleManager *mManager; // at 0xc8 +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_particlemanager.h b/include/nw4r/ef/ef_particlemanager.h index f850f3e9..f4fd3b20 100644 --- a/include/nw4r/ef/ef_particlemanager.h +++ b/include/nw4r/ef/ef_particlemanager.h @@ -1,91 +1,83 @@ #ifndef NW4R_EF_PARTICLEMANAGER #define NW4R_EF_PARTICLEMANAGER -#include "types_nw4r.h" -#include "math_types.h" +#include "common.h" #include "ef_list.h" #include "ef_ref.h" +#include "math_types.h" #include "ut_Color.h" -namespace nw4r -{ - namespace ef - { - struct ParticleManager : ReferencedObject - { - struct ParticleModifier - { - math::VEC2 mScale; // at 0x0 - math::VEC3 mRotate; // at 0x8 +namespace nw4r { +namespace ef { +struct ParticleManager : ReferencedObject { + struct ParticleModifier { + math::VEC2 mScale; // at 0x0 + math::VEC3 mRotate; // at 0x8 - struct SimpleLight - { - u8 mType; // at 0x0 - ut::Color mAmbColor; // at 0x1 - } mLight; - }; + struct SimpleLight { + u8 mType; // at 0x0 + ut::Color mAmbColor; // at 0x1 + } mLight; + }; - UNKTYPE BeginDraw(); - UNKTYPE EndDraw(); - UNKTYPE BeginCalc(bool); - UNKTYPE EndCalc(); - - bool SendClosing(); - UNKTYPE DestroyFunc(); - virtual bool Initialize(Emitter *, EmitterResource *); - virtual UNKTYPE CreateParticle(u16, math::VEC3, math::VEC3, const math::MTX34 *, float, const EmitterInheritSetting *, Particle *, u16); - virtual UNKTYPE Calc(); - virtual UNKTYPE Draw(const DrawInfo &); - - Emitter * mEmitter; // at 0x20 - EmitterResource * mResource; // at 0x24 - UNKWORD FLAGS_0x28; - char UNK_0x2C[0xC]; - ActivityList EFLIST_0x38; - char UNK_0x54[0x4]; + UNKTYPE BeginDraw(); + UNKTYPE EndDraw(); + UNKTYPE BeginCalc(bool); + UNKTYPE EndCalc(); - ParticleModifier mMod; // at 0x58 + bool SendClosing(); + UNKTYPE DestroyFunc(); + virtual bool Initialize(Emitter *, EmitterResource *); + virtual UNKTYPE CreateParticle(u16, math::VEC3, math::VEC3, const math::MTX34 *, float, + const EmitterInheritSetting *, Particle *, u16); + virtual UNKTYPE Calc(); + virtual UNKTYPE Draw(const DrawInfo &); - char UNK_0x74[0x14]; + Emitter *mEmitter; // at 0x20 + EmitterResource *mResource; // at 0x24 + UNKWORD FLAGS_0x28; + char UNK_0x2C[0xC]; + ActivityList EFLIST_0x38; + char UNK_0x54[0x4]; - s8 BYTE_0x88; - u8 BYTE_0x89; - bool BOOL_0x8A; + ParticleModifier mMod; // at 0x58 - UNKWORD FLAGS_0xB4; - - u16 RetireParticleAll(); - - UNKTYPE CalcGlobalMtx(math::MTX34 *); + char UNK_0x74[0x14]; - static void ModifierTravFunc_SetSimpleLightType(void *p, u32 payload) - { - ParticleManager *mgr = (ParticleManager *)p; - u8 type = (u8)payload; - mgr->mMod.mLight.mType = type; - } + s8 BYTE_0x88; + u8 BYTE_0x89; + bool BOOL_0x8A; - static void ModifierTravFunc_SetSimpleLightAmbient(void *p, u32 payload) - { - ParticleManager *mgr = (ParticleManager *)p; - ut::Color *color = (ut::Color *)payload; - mgr->mMod.mLight.mAmbColor = *color; - } + UNKWORD FLAGS_0xB4; - static void ModifierTravFunc_SetScale(void *p, u32 payload) - { - ParticleManager *mgr = (ParticleManager *)p; - math::VEC2 *scale = (math::VEC2 *)payload; - mgr->mMod.mScale = *scale; - } + u16 RetireParticleAll(); - static void ModifierTravFunc_SetRotate(void *p, u32 payload) - { - ParticleManager *mgr = (ParticleManager *)p; - math::VEC3 *rot = (math::VEC3 *)payload; - mgr->mMod.mRotate = *rot; - } - }; + UNKTYPE CalcGlobalMtx(math::MTX34 *); + + static void ModifierTravFunc_SetSimpleLightType(void *p, u32 payload) { + ParticleManager *mgr = (ParticleManager *)p; + u8 type = (u8)payload; + mgr->mMod.mLight.mType = type; } -} -#endif \ No newline at end of file + static void ModifierTravFunc_SetSimpleLightAmbient(void *p, u32 payload) { + ParticleManager *mgr = (ParticleManager *)p; + ut::Color *color = (ut::Color *)payload; + mgr->mMod.mLight.mAmbColor = *color; + } + + static void ModifierTravFunc_SetScale(void *p, u32 payload) { + ParticleManager *mgr = (ParticleManager *)p; + math::VEC2 *scale = (math::VEC2 *)payload; + mgr->mMod.mScale = *scale; + } + + static void ModifierTravFunc_SetRotate(void *p, u32 payload) { + ParticleManager *mgr = (ParticleManager *)p; + math::VEC3 *rot = (math::VEC3 *)payload; + mgr->mMod.mRotate = *rot; + } +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_rand.h b/include/nw4r/ef/ef_rand.h index a007d096..18741a1a 100644 --- a/include/nw4r/ef/ef_rand.h +++ b/include/nw4r/ef/ef_rand.h @@ -1,38 +1,31 @@ #ifndef NW4R_EF_RAND_H #define NW4R_EF_RAND_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct Random - { - u32 mSeed; // at 0x0 - - inline u32 MixRandomSeed() - { - return mSeed = mSeed * 0x343fd + 0x269ec3; - } - - inline void Srand(u32 seed) - { - mSeed = seed; - } - - inline u32 Rand() - { - //WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE - return MixRandomSeed() >> 0x10; - } - - inline float RandFloat() - { - //WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE - return (float)Rand() / 0xFFFF; - } - }; - } -} +namespace nw4r { +namespace ef { +struct Random { + u32 mSeed; // at 0x0 -#endif \ No newline at end of file + inline u32 MixRandomSeed() { + return mSeed = mSeed * 0x343fd + 0x269ec3; + } + + inline void Srand(u32 seed) { + mSeed = seed; + } + + inline u32 Rand() { + // WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE + return MixRandomSeed() >> 0x10; + } + + inline float RandFloat() { + // WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE + return (float)Rand() / 0xFFFF; + } +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_ref.h b/include/nw4r/ef/ef_ref.h index 2ee05712..4f71969f 100644 --- a/include/nw4r/ef/ef_ref.h +++ b/include/nw4r/ef/ef_ref.h @@ -1,48 +1,45 @@ #ifndef NW4R_EF_REF #define NW4R_EF_REF -#include "types_nw4r.h" +#include "common.h" #include "math_types.h" -namespace nw4r -{ - namespace ef - { - struct ReferencedObject - { - char UNK_0x0[0xC]; - UNKWORD WORD_0xC; - u32 mRefCount; // at 0x10 - char UNK_0x14[0x8]; - - virtual bool SendClosing(); - virtual UNKTYPE DestroyFunc(); - - inline void Initialize() - { - mRefCount = 0; - WORD_0xC = 1; - } - - inline void Ref() - { - mRefCount++; - } - - inline void UnRef() - { - if (--mRefCount == 0 && WORD_0xC == 2) SendClosing(); - } - - inline void Destroy() - { - DestroyFunc(); - WORD_0xC = 2; - if (mRefCount == 0) SendClosing(); - } - }; - - typedef ReferencedObject UNKREF; - } -} +namespace nw4r { +namespace ef { +struct ReferencedObject { + char UNK_0x0[0xC]; + UNKWORD WORD_0xC; + u32 mRefCount; // at 0x10 + char UNK_0x14[0x8]; -#endif \ No newline at end of file + virtual bool SendClosing(); + virtual UNKTYPE DestroyFunc(); + + inline void Initialize() { + mRefCount = 0; + WORD_0xC = 1; + } + + inline void Ref() { + mRefCount++; + } + + inline void UnRef() { + if (--mRefCount == 0 && WORD_0xC == 2) { + SendClosing(); + } + } + + inline void Destroy() { + DestroyFunc(); + WORD_0xC = 2; + if (mRefCount == 0) { + SendClosing(); + } + } +}; + +typedef ReferencedObject UNKREF; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_resource.h b/include/nw4r/ef/ef_resource.h index f3cdd672..ac461516 100644 --- a/include/nw4r/ef/ef_resource.h +++ b/include/nw4r/ef/ef_resource.h @@ -1,18 +1,15 @@ #ifndef NW4R_EF_RESOURCE #define NW4R_EF_RESOURCE -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace ef - { - struct Resource - { - EmitterResource * _FindEmitter(const char *, EffectProject *) const; - - static Resource * GetInstance(); - }; - } -} +namespace nw4r { +namespace ef { +struct Resource { + EmitterResource *_FindEmitter(const char *, EffectProject *) const; -#endif \ No newline at end of file + static Resource *GetInstance(); +}; +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/ef/ef_util.h b/include/nw4r/ef/ef_util.h index 5f7dd6b0..81ca35ef 100644 --- a/include/nw4r/ef/ef_util.h +++ b/include/nw4r/ef/ef_util.h @@ -1,22 +1,20 @@ #ifndef NW4R_EF_UTIL #define NW4R_EF_UTIL -#include "types_nw4r.h" +#include "common.h" #include "ut_list.h" -namespace nw4r -{ - namespace ef - { - typedef void (* Action)(void *, u32); - - u16 UtlistToArray(const ut::List *, void **, int); - - UNKTYPE GetDirMtxY(math::MTX34 *, const math::VEC3 &); - UNKTYPE MtxGetRotation(const math::MTX34 &, math::VEC3 *); - UNKTYPE MtxGetTranslate(const math::MTX34 &, math::VEC3 *); - UNKTYPE MtxGetRotationMtx(const math::MTX34 &, math::MTX34 *); - UNKTYPE MtxGetScale(const math::MTX34 &, math::VEC3 *); - } -} +namespace nw4r { +namespace ef { +typedef void (*Action)(void *, u32); -#endif \ No newline at end of file +u16 UtlistToArray(const ut::List *, void **, int); + +UNKTYPE GetDirMtxY(math::MTX34 *, const math::VEC3 &); +UNKTYPE MtxGetRotation(const math::MTX34 &, math::VEC3 *); +UNKTYPE MtxGetTranslate(const math::MTX34 &, math::VEC3 *); +UNKTYPE MtxGetRotationMtx(const math::MTX34 &, math::MTX34 *); +UNKTYPE MtxGetScale(const math::MTX34 &, math::VEC3 *); +} // namespace ef +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_3dsmax.h b/include/nw4r/g3d/g3d_3dsmax.h index 01be899b..56c56453 100644 --- a/include/nw4r/g3d/g3d_3dsmax.h +++ b/include/nw4r/g3d/g3d_3dsmax.h @@ -1,20 +1,16 @@ #ifndef NW4R_G3D_3DSMAX_H #define NW4R_G3D_3DSMAX_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_anmtexsrt.h" -namespace nw4r -{ - namespace g3d - { - namespace detail - { - namespace dcc - { - bool CalcTexMtx_3dsmax(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); - } - } - } +namespace nw4r { +namespace g3d { +namespace detail { +namespace dcc { +bool CalcTexMtx_3dsmax(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); } +} // namespace detail +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_anmcamera.h b/include/nw4r/g3d/g3d_anmcamera.h index 1ea8fd1c..972ed03e 100644 --- a/include/nw4r/g3d/g3d_anmcamera.h +++ b/include/nw4r/g3d/g3d_anmcamera.h @@ -1,7 +1,7 @@ #ifndef NW4R_G3D_ANMCAMERA_H #define NW4R_G3D_ANMCAMERA_H +#include "common.h" #include "math_types.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_anmchr.h b/include/nw4r/g3d/g3d_anmchr.h index 34c6ab51..577bd8ff 100644 --- a/include/nw4r/g3d/g3d_anmchr.h +++ b/include/nw4r/g3d/g3d_anmchr.h @@ -1,40 +1,25 @@ #ifndef NW4R_G3D_ANMCHR_H #define NW4R_G3D_ANMCHR_H -#include "types_nw4r.h" +#include "common.h" #include "math_types.h" -namespace nw4r -{ - namespace g3d - { - struct ChrAnmResult - { - u32 mFlags; // at 0x0 - math::VEC3 VEC3_0x4; - math::VEC3 VEC3_0x10; - math::MTX34 mMtx; // at 0x1C - }; +namespace nw4r { +namespace g3d { +struct ChrAnmResult { + u32 mFlags; // at 0x0 + math::VEC3 VEC3_0x4; + math::VEC3 VEC3_0x10; + math::MTX34 mMtx; // at 0x1C +}; - struct AnmObjChr - { +struct AnmObjChr {}; - }; - - struct AnmObjChrNode - { +struct AnmObjChrNode {}; - }; +struct AnmObjChrBlend {}; - struct AnmObjChrBlend - { +struct AnmObjChrRes {}; +} // namespace g3d +} // namespace nw4r - }; - - struct AnmObjChrRes - { - - }; - } -} - -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_anmclr.h b/include/nw4r/g3d/g3d_anmclr.h index dab07f60..6a009f19 100644 --- a/include/nw4r/g3d/g3d_anmclr.h +++ b/include/nw4r/g3d/g3d_anmclr.h @@ -1,23 +1,17 @@ #ifndef NW4R_G3D_ANMCLR_H #define NW4R_G3D_ANMCLR_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - struct ClrAnmResult - { - enum - { - ANM_COUNT = 11 - }; - - u32 mFlags; // at 0x0 - u32 COLORS_0x4[ANM_COUNT]; - UNKWORD WORDS_0x30[ANM_COUNT]; - }; - } -} +namespace nw4r { +namespace g3d { +struct ClrAnmResult { + enum { ANM_COUNT = 11 }; -#endif \ No newline at end of file + u32 mFlags; // at 0x0 + u32 COLORS_0x4[ANM_COUNT]; + UNKWORD WORDS_0x30[ANM_COUNT]; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_anmfog.h b/include/nw4r/g3d/g3d_anmfog.h index 10f6e72f..565f1bd3 100644 --- a/include/nw4r/g3d/g3d_anmfog.h +++ b/include/nw4r/g3d/g3d_anmfog.h @@ -1,6 +1,6 @@ #ifndef NW4R_G3D_ANMFOG_H #define NW4R_G3D_ANMFOG_H -#include "types_nw4r.h" +#include "common.h" #include "ut_Color.h" #include diff --git a/include/nw4r/g3d/g3d_anmobj.h b/include/nw4r/g3d/g3d_anmobj.h index da233a0e..421223a0 100644 --- a/include/nw4r/g3d/g3d_anmobj.h +++ b/include/nw4r/g3d/g3d_anmobj.h @@ -1,129 +1,103 @@ #ifndef NW4R_G3D_ANMOBJ_H #define NW4R_G3D_ANMOBJ_H -#include "types_nw4r.h" +#include "common.h" +#include "g3d_obj.h" #include "g3d_rescommon.h" #include "g3d_resmdl.h" -#include "g3d_obj.h" -namespace nw4r -{ - namespace g3d - { - enum AnmPolicy - { - ANM_POLICY_ONETIME, - ANM_POLICY_LOOP, - ANM_POLICY_MAX - }; +namespace nw4r { +namespace g3d { +enum AnmPolicy { ANM_POLICY_ONETIME, ANM_POLICY_LOOP, ANM_POLICY_MAX }; - typedef f32 (* PlayPolicyFunc)(f32, f32, f32); - f32 PlayPolicy_Onetime(f32, f32, f32); - f32 PlayPolicy_Loop(f32, f32, f32); +typedef f32 (*PlayPolicyFunc)(f32, f32, f32); +f32 PlayPolicy_Onetime(f32, f32, f32); +f32 PlayPolicy_Loop(f32, f32, f32); - inline PlayPolicyFunc GetAnmPlayPolicy(AnmPolicy policy) - { - static PlayPolicyFunc policyTable[ANM_POLICY_MAX] = { - PlayPolicy_Onetime, - PlayPolicy_Loop - }; - return policyTable[policy]; - } - - struct FrameCtrl - { - FrameCtrl(f32 f1, f32 f2, PlayPolicyFunc policy) - : mFrame(0.0f), mRate(1.0f), FLOAT_0x8(f1), mEndFrame(f2), mPolicy(policy) {} - - f32 GetFrm() const - { - return mFrame; - } - - f32 GetRate() const - { - return mRate; - } - - void SetFrm(f32 frm) - { - f32 newFrm = mPolicy(FLOAT_0x8, mEndFrame, frm); - mFrame = newFrm; - } - - void SetRate(f32 rate) - { - mRate = rate; - } - - void SetPolicy(PlayPolicyFunc func) - { - mPolicy = func; - } - - void UpdateFrm() - { - SetFrm(mFrame + mRate * smBaseUpdateRate); - } - - f32 mFrame; // at 0x0 - f32 mRate; // at 0x4 - f32 FLOAT_0x8; - f32 mEndFrame; - PlayPolicyFunc mPolicy; // at 0x10 - - static f32 smBaseUpdateRate; - }; - - class AnmObj : public G3dObj - { - public: - enum AnmFlag - { - ANMFLAG_2 = 0x2, - ANMFLAG_ISBOUND = 0x4 - }; - - public: - AnmObj(MEMAllocator *pAllocator, G3dObj *pParent) - : G3dObj(pAllocator, pParent), mFlags(0) {} - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : G3dObj::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *) = 0; // at 0xC - virtual ~AnmObj() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual void SetFrame(f32) = 0; // at 0x1C - virtual f32 GetFrame() const = 0; // at 0x20 - virtual void UpdateFrame() = 0; // at 0x24 - virtual void SetUpdateRate(f32) = 0; // at 0x28 - virtual f32 GetUpdateRate() const = 0; // at 0x2C - virtual bool Bind(ResMdl) = 0; // at 0x30 - virtual void Release(); // at 0x34 - - static const TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - void SetAnmFlag(AnmFlag, bool); - bool TestAnmFlag(AnmFlag) const; - - private: - u32 mFlags; // at 0x4 - - NW4R_G3D_TYPE_OBJ_DECL(AnmObj); - }; - } +inline PlayPolicyFunc GetAnmPlayPolicy(AnmPolicy policy) { + static PlayPolicyFunc policyTable[ANM_POLICY_MAX] = {PlayPolicy_Onetime, PlayPolicy_Loop}; + return policyTable[policy]; } -#endif \ No newline at end of file +struct FrameCtrl { + FrameCtrl(f32 f1, f32 f2, PlayPolicyFunc policy) + : mFrame(0.0f), mRate(1.0f), FLOAT_0x8(f1), mEndFrame(f2), mPolicy(policy) {} + + f32 GetFrm() const { + return mFrame; + } + + f32 GetRate() const { + return mRate; + } + + void SetFrm(f32 frm) { + f32 newFrm = mPolicy(FLOAT_0x8, mEndFrame, frm); + mFrame = newFrm; + } + + void SetRate(f32 rate) { + mRate = rate; + } + + void SetPolicy(PlayPolicyFunc func) { + mPolicy = func; + } + + void UpdateFrm() { + SetFrm(mFrame + mRate * smBaseUpdateRate); + } + + f32 mFrame; // at 0x0 + f32 mRate; // at 0x4 + f32 FLOAT_0x8; + f32 mEndFrame; + PlayPolicyFunc mPolicy; // at 0x10 + + static f32 smBaseUpdateRate; +}; + +class AnmObj : public G3dObj { +public: + enum AnmFlag { ANMFLAG_2 = 0x2, ANMFLAG_ISBOUND = 0x4 }; + +public: + AnmObj(MEMAllocator *pAllocator, G3dObj *pParent) : G3dObj(pAllocator, pParent), mFlags(0) {} + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : G3dObj::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *) = 0; // at 0xC + virtual ~AnmObj() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual void SetFrame(f32) = 0; // at 0x1C + virtual f32 GetFrame() const = 0; // at 0x20 + virtual void UpdateFrame() = 0; // at 0x24 + virtual void SetUpdateRate(f32) = 0; // at 0x28 + virtual f32 GetUpdateRate() const = 0; // at 0x2C + virtual bool Bind(ResMdl) = 0; // at 0x30 + virtual void Release(); // at 0x34 + + static const TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + void SetAnmFlag(AnmFlag, bool); + bool TestAnmFlag(AnmFlag) const; + +private: + u32 mFlags; // at 0x4 + + NW4R_G3D_TYPE_OBJ_DECL(AnmObj); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_anmscn.h b/include/nw4r/g3d/g3d_anmscn.h index 42643e0d..f32f99f4 100644 --- a/include/nw4r/g3d/g3d_anmscn.h +++ b/include/nw4r/g3d/g3d_anmscn.h @@ -1,60 +1,56 @@ #ifndef NW4R_G3D_ANMSCN_H #define NW4R_G3D_ANMSCN_H -#include "types_nw4r.h" -#include "g3d_obj.h" -#include "g3d_light.h" -#include "g3d_fog.h" +#include "common.h" #include "g3d_camera.h" +#include "g3d_fog.h" +#include "g3d_light.h" +#include "g3d_obj.h" -namespace nw4r -{ - namespace g3d - { - class AnmScnRes // : public AnmScn - { - }; +namespace nw4r { +namespace g3d { +class AnmScnRes // : public AnmScn +{}; - class AnmScn : G3dObj - { - public: - AnmScn(MEMAllocator *); - virtual bool IsDerivedFrom(TypeObj other) const; // at 0x8 - virtual ~AnmScn(); // at 0x10 - virtual const TypeObj GetTypeObj() const; // at 0x14 - virtual const char * GetTypeName() const; // at 0x18 - virtual void SetFrame(f32) = 0; // at 0x1C - virtual f32 GetFrame() const = 0; // at 0x20 - virtual void SetUpdateRate(f32) = 0; // at 0x24 - virtual f32 GetUpdateRate() const = 0; // at 0x28 - virtual void UpdateFrame() = 0; // at 0x2C - virtual void Attach(int, AnmScnRes); // at 0x30 - virtual void Detach(); // at 0x34 - virtual int GetNumLightSet() const = 0; // at 0x38 - virtual int GetNumAmbLight() const = 0; // at 0x3C - virtual int GetNumDiffuseLight() const = 0; // at 0x40 - virtual int GetNumSpecularLight() const = 0; // at 0x44 - virtual int GetNumFog() const = 0; // at 0x48 - virtual int GetNumCamera() const = 0; // at 0x4C - virtual int GetLightSetMaxRefNumber() const = 0; // at 0x50 - virtual int GetAmbLightMaxRefNumber() const = 0; // at 0x54 - virtual int GetDiffuseLightMaxRefNumber() const = 0; // at 0x58 - virtual int GetFogMaxRefNumber() const = 0; // at 0x5C - virtual int GetCameraMaxRefNumber() const = 0; // at 0x60 - virtual void GetLightSet(LightSet, u32) = 0; // at 0x64 - virtual ut::Color GetAmbLightColor(u32) = 0; // at 0x68 - virtual void GetLight(LightObj *, LightObj *, u32) = 0; // at 0x6C - virtual void GetFog(Fog, u32) = 0; // at 0x70 - virtual void GetCamera(Camera, u32) = 0; // at 0x74 - virtual int GetSpecularLightID(u32) const = 0; // at 0x78 - virtual bool HasSpecularLight(u32) const = 0; // at 0x7C - virtual void GetAmbLightResult(AmbLightAnmResult *, u32) = 0; // at 0x80 - virtual void GetLightResult(LightAnmResult *, u32) = 0; // at 0x84 - virtual void GetFogResult(FogAnmResult *, u32) = 0; // at 0x88 - virtual void GetFogResult(CameraAnmResult *, u32) = 0; // at 0x8C +class AnmScn : G3dObj { +public: + AnmScn(MEMAllocator *); + virtual bool IsDerivedFrom(TypeObj other) const; // at 0x8 + virtual ~AnmScn(); // at 0x10 + virtual const TypeObj GetTypeObj() const; // at 0x14 + virtual const char *GetTypeName() const; // at 0x18 + virtual void SetFrame(f32) = 0; // at 0x1C + virtual f32 GetFrame() const = 0; // at 0x20 + virtual void SetUpdateRate(f32) = 0; // at 0x24 + virtual f32 GetUpdateRate() const = 0; // at 0x28 + virtual void UpdateFrame() = 0; // at 0x2C + virtual void Attach(int, AnmScnRes); // at 0x30 + virtual void Detach(); // at 0x34 + virtual int GetNumLightSet() const = 0; // at 0x38 + virtual int GetNumAmbLight() const = 0; // at 0x3C + virtual int GetNumDiffuseLight() const = 0; // at 0x40 + virtual int GetNumSpecularLight() const = 0; // at 0x44 + virtual int GetNumFog() const = 0; // at 0x48 + virtual int GetNumCamera() const = 0; // at 0x4C + virtual int GetLightSetMaxRefNumber() const = 0; // at 0x50 + virtual int GetAmbLightMaxRefNumber() const = 0; // at 0x54 + virtual int GetDiffuseLightMaxRefNumber() const = 0; // at 0x58 + virtual int GetFogMaxRefNumber() const = 0; // at 0x5C + virtual int GetCameraMaxRefNumber() const = 0; // at 0x60 + virtual void GetLightSet(LightSet, u32) = 0; // at 0x64 + virtual ut::Color GetAmbLightColor(u32) = 0; // at 0x68 + virtual void GetLight(LightObj *, LightObj *, u32) = 0; // at 0x6C + virtual void GetFog(Fog, u32) = 0; // at 0x70 + virtual void GetCamera(Camera, u32) = 0; // at 0x74 + virtual int GetSpecularLightID(u32) const = 0; // at 0x78 + virtual bool HasSpecularLight(u32) const = 0; // at 0x7C + virtual void GetAmbLightResult(AmbLightAnmResult *, u32) = 0; // at 0x80 + virtual void GetLightResult(LightAnmResult *, u32) = 0; // at 0x84 + virtual void GetFogResult(FogAnmResult *, u32) = 0; // at 0x88 + virtual void GetFogResult(CameraAnmResult *, u32) = 0; // at 0x8C - void GetLightSetting(LightSetting *); - }; - } -} + void GetLightSetting(LightSetting *); +}; +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_anmvis.h b/include/nw4r/g3d/g3d_anmvis.h index d7549f8a..26bffd4d 100644 --- a/include/nw4r/g3d/g3d_anmvis.h +++ b/include/nw4r/g3d/g3d_anmvis.h @@ -1,188 +1,170 @@ #ifndef NW4R_G3D_ANMVIS_H #define NW4R_G3D_ANMVIS_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_anmobj.h" #include "g3d_resanmvis.h" -namespace nw4r -{ - namespace g3d +namespace nw4r { +namespace g3d { +void ApplyVisAnmResult(ResMdl, AnmObjVis *); +void ApplyVisAnmResult(u8 *, ResMdl, AnmObjVis *); + +class AnmObjVis : public AnmObj { +public: + AnmObjVis(MEMAllocator *, u16 *, int); + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 { - void ApplyVisAnmResult(ResMdl, AnmObjVis *); - void ApplyVisAnmResult(u8 *, ResMdl, AnmObjVis *); - - class AnmObjVis : public AnmObj - { - public: - AnmObjVis(MEMAllocator *, u16 *, int); - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : AnmObj::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~AnmObjVis() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual void SetFrame(f32) = 0; // at 0x1C - virtual f32 GetFrame() const = 0; // at 0x20 - virtual void UpdateFrame() = 0; // at 0x24 - virtual void SetUpdateRate(f32) = 0; // at 0x28 - virtual f32 GetUpdateRate() const = 0; // at 0x2C - virtual bool Bind(ResMdl) = 0; // at 0x30 - virtual void Release(); // at 0x34 - virtual bool GetResult(u32) = 0; // at 0x38 - virtual AnmObjVisRes * Attach(int, AnmObjVisRes *); // at 0x3C - virtual AnmObjVisRes * Detach(int); // at 0x40 - - static const TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - bool TestDefined(u32 idx) const; - bool TestExistence(u32 idx) const; - void DetachAll(); - - protected: - static const int MAX_RESOURCES = 4; - - int mNumBinds; // at 0x10 - u16 *mBinds; // at 0x14 - - NW4R_G3D_TYPE_OBJ_DECL(AnmObjVis); - }; - - class AnmObjVisNode : public AnmObjVis - { - public: - AnmObjVisNode(MEMAllocator *allocator, u16 *bindBuffer, int numBinds) - : AnmObjVis(allocator, bindBuffer, numBinds) - { - mResources[0] = NULL; - mResources[1] = NULL; - mResources[2] = NULL; - mResources[3] = NULL; - } - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : AnmObjVis::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~AnmObjVisNode(); // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual void SetFrame(f32); // at 0x1C - virtual f32 GetFrame() const; // at 0x20 - virtual void UpdateFrame(); // at 0x24 - virtual void SetUpdateRate(f32); // at 0x28 - virtual f32 GetUpdateRate() const; // at 0x2C - virtual bool Bind(ResMdl); // at 0x30 - virtual void Release(); // at 0x34 - virtual bool GetResult(u32) = 0; // at 0x38 - virtual AnmObjVisRes * Attach(int, AnmObjVisRes *); // at 0x3C - virtual AnmObjVisRes * Detach(int); // at 0x40 - - static const TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - protected: - AnmObjVisRes *mResources[MAX_RESOURCES]; // at 0x18 - - NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisNode); - }; - - class AnmObjVisOR : public AnmObjVisNode - { - public: - AnmObjVisOR(MEMAllocator *allocator, u16 *bindBuffer, int numBinds) - : AnmObjVisNode(allocator, bindBuffer, numBinds) - { - } - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : AnmObjVisNode::IsDerivedFrom(other); - } - virtual ~AnmObjVisOR() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual bool GetResult(u32); // at 0x38 - - static const TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - static AnmObjVisOR * Construct(MEMAllocator *, u32 *, ResMdl); - - private: - NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisOR); - }; - - class AnmObjVisRes : public AnmObjVis, public FrameCtrl - { - public: - AnmObjVisRes(MEMAllocator *, ResAnmVis, u16 *, int); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : AnmObjVis::IsDerivedFrom(other); - } - virtual ~AnmObjVisRes() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual void SetFrame(f32); // at 0x1C - virtual f32 GetFrame() const; // at 0x20 - virtual void UpdateFrame(); // at 0x24 - virtual void SetUpdateRate(f32); // at 0x28 - virtual f32 GetUpdateRate() const; // at 0x2C - virtual bool Bind(ResMdl); // at 0x30 - virtual bool GetResult(u32); // at 0x38 - - static const TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - static AnmObjVisRes * Construct(MEMAllocator *, u32 *, ResAnmVis, ResMdl); - - private: - ResAnmVis mResAnmVis; // at 0x2C - - NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisRes); - }; + return (other == GetTypeObjStatic()) ? true : AnmObj::IsDerivedFrom(other); } -} + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~AnmObjVis() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual void SetFrame(f32) = 0; // at 0x1C + virtual f32 GetFrame() const = 0; // at 0x20 + virtual void UpdateFrame() = 0; // at 0x24 + virtual void SetUpdateRate(f32) = 0; // at 0x28 + virtual f32 GetUpdateRate() const = 0; // at 0x2C + virtual bool Bind(ResMdl) = 0; // at 0x30 + virtual void Release(); // at 0x34 + virtual bool GetResult(u32) = 0; // at 0x38 + virtual AnmObjVisRes *Attach(int, AnmObjVisRes *); // at 0x3C + virtual AnmObjVisRes *Detach(int); // at 0x40 -#endif \ No newline at end of file + static const TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + bool TestDefined(u32 idx) const; + bool TestExistence(u32 idx) const; + void DetachAll(); + +protected: + static const int MAX_RESOURCES = 4; + + int mNumBinds; // at 0x10 + u16 *mBinds; // at 0x14 + + NW4R_G3D_TYPE_OBJ_DECL(AnmObjVis); +}; + +class AnmObjVisNode : public AnmObjVis { +public: + AnmObjVisNode(MEMAllocator *allocator, u16 *bindBuffer, int numBinds) : AnmObjVis(allocator, bindBuffer, numBinds) { + mResources[0] = NULL; + mResources[1] = NULL; + mResources[2] = NULL; + mResources[3] = NULL; + } + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : AnmObjVis::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~AnmObjVisNode(); // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual void SetFrame(f32); // at 0x1C + virtual f32 GetFrame() const; // at 0x20 + virtual void UpdateFrame(); // at 0x24 + virtual void SetUpdateRate(f32); // at 0x28 + virtual f32 GetUpdateRate() const; // at 0x2C + virtual bool Bind(ResMdl); // at 0x30 + virtual void Release(); // at 0x34 + virtual bool GetResult(u32) = 0; // at 0x38 + virtual AnmObjVisRes *Attach(int, AnmObjVisRes *); // at 0x3C + virtual AnmObjVisRes *Detach(int); // at 0x40 + + static const TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + +protected: + AnmObjVisRes *mResources[MAX_RESOURCES]; // at 0x18 + + NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisNode); +}; + +class AnmObjVisOR : public AnmObjVisNode { +public: + AnmObjVisOR(MEMAllocator *allocator, u16 *bindBuffer, int numBinds) + : AnmObjVisNode(allocator, bindBuffer, numBinds) {} + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : AnmObjVisNode::IsDerivedFrom(other); + } + virtual ~AnmObjVisOR() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual bool GetResult(u32); // at 0x38 + + static const TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + static AnmObjVisOR *Construct(MEMAllocator *, u32 *, ResMdl); + +private: + NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisOR); +}; + +class AnmObjVisRes : public AnmObjVis, public FrameCtrl { +public: + AnmObjVisRes(MEMAllocator *, ResAnmVis, u16 *, int); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : AnmObjVis::IsDerivedFrom(other); + } + virtual ~AnmObjVisRes() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual void SetFrame(f32); // at 0x1C + virtual f32 GetFrame() const; // at 0x20 + virtual void UpdateFrame(); // at 0x24 + virtual void SetUpdateRate(f32); // at 0x28 + virtual f32 GetUpdateRate() const; // at 0x2C + virtual bool Bind(ResMdl); // at 0x30 + virtual bool GetResult(u32); // at 0x38 + + static const TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + static AnmObjVisRes *Construct(MEMAllocator *, u32 *, ResAnmVis, ResMdl); + +private: + ResAnmVis mResAnmVis; // at 0x2C + + NW4R_G3D_TYPE_OBJ_DECL(AnmObjVisRes); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_calcview.h b/include/nw4r/g3d/g3d_calcview.h index 9a705da4..8cb3a7c5 100644 --- a/include/nw4r/g3d/g3d_calcview.h +++ b/include/nw4r/g3d/g3d_calcview.h @@ -1,14 +1,12 @@ #ifndef NW4R_G3D_CALC_VIEW_H #define NW4R_G3D_CALC_VIEW_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - void CalcView(math::MTX34 *, math::MTX33 *, const math::MTX34 *, const u32 *, - u32, const math::MTX34 *, ResMdl, math::MTX34 *); - } +namespace nw4r { +namespace g3d { +void CalcView(math::MTX34 *, math::MTX33 *, const math::MTX34 *, const u32 *, u32, const math::MTX34 *, ResMdl, + math::MTX34 *); } +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_calcworld.h b/include/nw4r/g3d/g3d_calcworld.h index 70d052cb..f4968c2f 100644 --- a/include/nw4r/g3d/g3d_calcworld.h +++ b/include/nw4r/g3d/g3d_calcworld.h @@ -1,19 +1,15 @@ #ifndef NW4R_G3D_CALC_WORLD_H #define NW4R_G3D_CALC_WORLD_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - void CalcWorld(math::MTX34 *, u32 *, const u8 *, const math::MTX34 *, - ResMdl, AnmObjChr *, FuncObjCalcWorld *, u32); +namespace nw4r { +namespace g3d { +void CalcWorld(math::MTX34 *, u32 *, const u8 *, const math::MTX34 *, ResMdl, AnmObjChr *, FuncObjCalcWorld *, u32); - void CalcWorld(math::MTX34 *, u32 *, const u8 *, const math::MTX34 *, - ResMdl, AnmObjChr *, FuncObjCalcWorld *); +void CalcWorld(math::MTX34 *, u32 *, const u8 *, const math::MTX34 *, ResMdl, AnmObjChr *, FuncObjCalcWorld *); - void CalcSkinning(math::MTX34 *, u32 *, ResMdl, const u8 *); - } -} +void CalcSkinning(math::MTX34 *, u32 *, ResMdl, const u8 *); +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_camera.h b/include/nw4r/g3d/g3d_camera.h index 5c270db1..e5c58271 100644 --- a/include/nw4r/g3d/g3d_camera.h +++ b/include/nw4r/g3d/g3d_camera.h @@ -1,8 +1,8 @@ #ifndef NW4R_G3D_CAMERA_H #define NW4R_G3D_CAMERA_H +#include "common.h" #include "g3d_rescommon.h" #include "math_types.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_cpu.h b/include/nw4r/g3d/g3d_cpu.h index 8b159c85..07599a08 100644 --- a/include/nw4r/g3d/g3d_cpu.h +++ b/include/nw4r/g3d/g3d_cpu.h @@ -1,17 +1,14 @@ #ifndef NW4R_G3D_CPU_H #define NW4R_G3D_CPU_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - namespace detail - { - void Copy32ByteBlocks(void *, const void *, u32); - void ZeroMemory32ByteBlocks(void *, u32); - } - } -} +namespace nw4r { +namespace g3d { +namespace detail { +void Copy32ByteBlocks(void *, const void *, u32); +void ZeroMemory32ByteBlocks(void *, u32); +} // namespace detail +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_dcc.h b/include/nw4r/g3d/g3d_dcc.h index 570cdc81..56a009d8 100644 --- a/include/nw4r/g3d/g3d_dcc.h +++ b/include/nw4r/g3d/g3d_dcc.h @@ -1,15 +1,12 @@ #ifndef NW4R_G3D_DCC_H #define NW4R_G3D_DCC_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_anmtexsrt.h" -namespace nw4r -{ - namespace g3d - { - void CalcTexMtx(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag, - TexSrtTypedef::TexMatrixMode); - } +namespace nw4r { +namespace g3d { +void CalcTexMtx(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag, TexSrtTypedef::TexMatrixMode); } +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_draw.h b/include/nw4r/g3d/g3d_draw.h index d163bd8d..0d0956d7 100644 --- a/include/nw4r/g3d/g3d_draw.h +++ b/include/nw4r/g3d/g3d_draw.h @@ -1,19 +1,15 @@ #ifndef NW4R_G3D_DRAW_H #define NW4R_G3D_DRAW_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_resmdl.h" -namespace nw4r -{ - namespace g3d - { - struct DrawResMdlReplacement - { - }; +namespace nw4r { +namespace g3d { +struct DrawResMdlReplacement {}; - void DrawResMdlDirectly(ResMdl, const math::MTX34 *, const math::MTX33 *, - const math::MTX34 *, const u8 *, const u8 *, DrawResMdlReplacement *, u32); - } -} +void DrawResMdlDirectly(ResMdl, const math::MTX34 *, const math::MTX33 *, const math::MTX34 *, const u8 *, const u8 *, + DrawResMdlReplacement *, u32); +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_draw1mat1shp.h b/include/nw4r/g3d/g3d_draw1mat1shp.h index cad3e4a9..b442c9d1 100644 --- a/include/nw4r/g3d/g3d_draw1mat1shp.h +++ b/include/nw4r/g3d/g3d_draw1mat1shp.h @@ -1,20 +1,16 @@ #ifndef NW4R_G3D_DRAW1_MAT1_SHP_H #define NW4R_G3D_DRAW1_MAT1_SHP_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_resmat.h" #include "g3d_resshp.h" -namespace nw4r -{ - namespace g3d - { - struct Draw1Mat1ShpSwap - { - }; +namespace nw4r { +namespace g3d { +struct Draw1Mat1ShpSwap {}; - void Draw1Mat1ShpDirectly(ResMat, ResShp, const math::MTX34 *, - const math::MTX34 *, u32, Draw1Mat1ShpSwap *, G3DState::IndMtxOp *); - } -} +void Draw1Mat1ShpDirectly(ResMat, ResShp, const math::MTX34 *, const math::MTX34 *, u32, Draw1Mat1ShpSwap *, + G3DState::IndMtxOp *); +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_fog.h b/include/nw4r/g3d/g3d_fog.h index 240ffc9c..0c1932a7 100644 --- a/include/nw4r/g3d/g3d_fog.h +++ b/include/nw4r/g3d/g3d_fog.h @@ -1,8 +1,8 @@ #ifndef NW4R_G3D_FOG_H #define NW4R_G3D_FOG_H +#include "common.h" #include "g3d_rescommon.h" #include "math_types.h" -#include "types_nw4r.h" #include "ut_Color.h" #include diff --git a/include/nw4r/g3d/g3d_gpu.h b/include/nw4r/g3d/g3d_gpu.h index 760609fe..693af719 100644 --- a/include/nw4r/g3d/g3d_gpu.h +++ b/include/nw4r/g3d/g3d_gpu.h @@ -1,8 +1,8 @@ #ifndef NW4R_G3D_GPU_H #define NW4R_G3D_GPU_H +#include "common.h" #include "g3d_rescommon.h" #include "math_types.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_init.h b/include/nw4r/g3d/g3d_init.h index d8d39907..d6e9718a 100644 --- a/include/nw4r/g3d/g3d_init.h +++ b/include/nw4r/g3d/g3d_init.h @@ -1,6 +1,6 @@ #ifndef NW4R_G3D_INIT_H #define NW4R_G3D_INIT_H -#include "types_nw4r.h" +#include "common.h" #include namespace nw4r { diff --git a/include/nw4r/g3d/g3d_light.h b/include/nw4r/g3d/g3d_light.h index b1235377..a989dcf6 100644 --- a/include/nw4r/g3d/g3d_light.h +++ b/include/nw4r/g3d/g3d_light.h @@ -1,7 +1,7 @@ #ifndef NW4R_G3D_LIGHT_H #define NW4R_G3D_LIGHT_H +#include "common.h" #include "g3d_rescommon.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_maya.h b/include/nw4r/g3d/g3d_maya.h index b28becdb..ab10b53f 100644 --- a/include/nw4r/g3d/g3d_maya.h +++ b/include/nw4r/g3d/g3d_maya.h @@ -1,20 +1,16 @@ #ifndef NW4R_G3D_MAYA_H #define NW4R_G3D_MAYA_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_anmtexsrt.h" -namespace nw4r -{ - namespace g3d - { - namespace detail - { - namespace dcc - { - bool CalcTexMtx_Maya(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); - } - } - } +namespace nw4r { +namespace g3d { +namespace detail { +namespace dcc { +bool CalcTexMtx_Maya(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); } +} // namespace detail +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_obj.h b/include/nw4r/g3d/g3d_obj.h index e755ea47..6f596a11 100644 --- a/include/nw4r/g3d/g3d_obj.h +++ b/include/nw4r/g3d/g3d_obj.h @@ -1,6 +1,6 @@ #ifndef NW4R_G3D_G3DOBJ_H #define NW4R_G3D_G3DOBJ_H -#include "types_nw4r.h" +#include "common.h" #include #define NW4R_G3D_TYPE_OBJ_DECL(VAL) static const nw4r::g3d::G3dObj::ResNameDataT TYPE_NAME diff --git a/include/nw4r/g3d/g3d_resanm.h b/include/nw4r/g3d/g3d_resanm.h index 8e1205a6..f4c0335e 100644 --- a/include/nw4r/g3d/g3d_resanm.h +++ b/include/nw4r/g3d/g3d_resanm.h @@ -1,88 +1,83 @@ #ifndef NW4R_G3D_RESANM_H #define NW4R_G3D_RESANM_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - struct ResKeyFrameAnmFramesData - { - float mTime; // at 0x0 - float mValue; // at 0x4 - float mDerivative; // at 0x8 - }; - - struct ResKeyFrameAnmData - { - u16 mCount; // at 0x0 - float FLOAT_0x4; - ResKeyFrameAnmFramesData mFrames[]; // at 0x8 - }; - - struct ResColorAnmFramesData - { - u32 mColor; // at 0x0 - }; - - union ResColorAnmData - { - u32 mColor; - s32 mOffset; - }; - - struct ResBoolAnmFramesData - { - u32 mFlags; // at 0x0 - }; - - union ResAnmData - { - float mValue; - s32 mOffset; - }; - - namespace detail - { - float GetResKeyFrameAnmResult(const ResKeyFrameAnmData *, float); - - u32 GetResColorAnmResult(const ResColorAnmFramesData *, float); - - inline u32 GetResColorAnmResult(const ResColorAnmData * pData, float time, bool b) - { - if (b) return pData->mColor; - - return GetResColorAnmResult((const ResColorAnmFramesData *)((u8 *)pData + pData->mOffset), time); - } - - inline bool GetResBoolAnmFramesResult(const ResBoolAnmFramesData * pData, int i) - { - u32 index = i; - - u32 mask = 0x80000000 >> (index % 32); - u32 flags = pData[index / 32].mFlags; - - return flags & mask; - } - - template - inline float ClipFrame(T & info, float time) - { - if (time <= 0.0f) return 0.0f; - - if (info.mNumFrames <= time) return info.mNumFrames; - - return time; - } - - inline float GetResAnmResult(const ResAnmData * pData, float time, bool b) - { - if (b) return pData->mValue; - - return GetResKeyFrameAnmResult((const ResKeyFrameAnmData *)((u8 *)pData + pData->mOffset), time); - } - } - } +namespace nw4r { +namespace g3d { +struct ResKeyFrameAnmFramesData { + float mTime; // at 0x0 + float mValue; // at 0x4 + float mDerivative; // at 0x8 +}; + +struct ResKeyFrameAnmData { + u16 mCount; // at 0x0 + float FLOAT_0x4; + ResKeyFrameAnmFramesData mFrames[]; // at 0x8 +}; + +struct ResColorAnmFramesData { + u32 mColor; // at 0x0 +}; + +union ResColorAnmData { + u32 mColor; + s32 mOffset; +}; + +struct ResBoolAnmFramesData { + u32 mFlags; // at 0x0 +}; + +union ResAnmData { + float mValue; + s32 mOffset; +}; + +namespace detail { +float GetResKeyFrameAnmResult(const ResKeyFrameAnmData *, float); + +u32 GetResColorAnmResult(const ResColorAnmFramesData *, float); + +inline u32 GetResColorAnmResult(const ResColorAnmData *pData, float time, bool b) { + if (b) { + return pData->mColor; + } + + return GetResColorAnmResult((const ResColorAnmFramesData *)((u8 *)pData + pData->mOffset), time); } -#endif \ No newline at end of file +inline bool GetResBoolAnmFramesResult(const ResBoolAnmFramesData *pData, int i) { + u32 index = i; + + u32 mask = 0x80000000 >> (index % 32); + u32 flags = pData[index / 32].mFlags; + + return flags & mask; +} + +template +inline float ClipFrame(T &info, float time) { + if (time <= 0.0f) { + return 0.0f; + } + + if (info.mNumFrames <= time) { + return info.mNumFrames; + } + + return time; +} + +inline float GetResAnmResult(const ResAnmData *pData, float time, bool b) { + if (b) { + return pData->mValue; + } + + return GetResKeyFrameAnmResult((const ResKeyFrameAnmData *)((u8 *)pData + pData->mOffset), time); +} +} // namespace detail +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resanmcamera.h b/include/nw4r/g3d/g3d_resanmcamera.h index d3b00b17..0b1eb409 100644 --- a/include/nw4r/g3d/g3d_resanmcamera.h +++ b/include/nw4r/g3d/g3d_resanmcamera.h @@ -1,30 +1,28 @@ #ifndef NW4R_G3D_RESANMCAMERA_H #define NW4R_G3D_RESANMCAMERA_H -#include "types_nw4r.h" -#include "g3d_rescommon.h" +#include "common.h" #include "g3d_anmcamera.h" +#include "g3d_rescommon.h" -namespace nw4r -{ - namespace g3d - { - struct ResAnmCameraData - { - char UNK_0x0[0xC]; - u32 mID; // at 0xC - }; +namespace nw4r { +namespace g3d { +struct ResAnmCameraData { + char UNK_0x0[0xC]; + u32 mID; // at 0xC +}; - struct ResAnmCamera - { - ResCommon mAnmCamera; - - inline ResAnmCamera(void * vptr) : mAnmCamera(vptr) {} +struct ResAnmCamera { + ResCommon mAnmCamera; - bool IsValid() const { return mAnmCamera.IsValid(); } + inline ResAnmCamera(void *vptr) : mAnmCamera(vptr) {} - void GetAnmResult(CameraAnmResult *, f32) const; - }; + bool IsValid() const { + return mAnmCamera.IsValid(); } -} -#endif \ No newline at end of file + void GetAnmResult(CameraAnmResult *, f32) const; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resanmchr.h b/include/nw4r/g3d/g3d_resanmchr.h index f37edd22..fd6696f9 100644 --- a/include/nw4r/g3d/g3d_resanmchr.h +++ b/include/nw4r/g3d/g3d_resanmchr.h @@ -1,35 +1,27 @@ #ifndef NW4R_G3D_RESANMCHR_H #define NW4R_G3D_RESANMCHR_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_rescommon.h" -namespace nw4r -{ - namespace g3d - { - struct ResAnmChrData - { - char UNK_0x0[0x8]; - u32 mRevision; // at 0x8 - }; +namespace nw4r { +namespace g3d { +struct ResAnmChrData { + char UNK_0x0[0x8]; + u32 mRevision; // at 0x8 +}; - struct ResAnmChr - { - enum - { - REVISION = 4 - }; - - ResCommon mAnmChr; - - inline ResAnmChr(void * vptr) : mAnmChr(vptr) {} - - inline bool CheckRevision() const - { - return mAnmChr.ref().mRevision == REVISION; - } - }; - } -} +struct ResAnmChr { + enum { REVISION = 4 }; -#endif \ No newline at end of file + ResCommon mAnmChr; + + inline ResAnmChr(void *vptr) : mAnmChr(vptr) {} + + inline bool CheckRevision() const { + return mAnmChr.ref().mRevision == REVISION; + } +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resanmfog.h b/include/nw4r/g3d/g3d_resanmfog.h index 2aab7454..4cc933cc 100644 --- a/include/nw4r/g3d/g3d_resanmfog.h +++ b/include/nw4r/g3d/g3d_resanmfog.h @@ -1,30 +1,28 @@ #ifndef NW4R_G3D_RESANMFOG_H #define NW4R_G3D_RESANMFOG_H -#include "types_nw4r.h" -#include "g3d_rescommon.h" +#include "common.h" #include "g3d_anmfog.h" +#include "g3d_rescommon.h" -namespace nw4r -{ - namespace g3d - { - struct ResAnmFogData - { - char UNK_0x0[0xC]; - u32 mID; // at 0xC - }; +namespace nw4r { +namespace g3d { +struct ResAnmFogData { + char UNK_0x0[0xC]; + u32 mID; // at 0xC +}; - struct ResAnmFog - { - ResCommon mAnmFog; - - inline ResAnmFog(void * vptr) : mAnmFog(vptr) {} +struct ResAnmFog { + ResCommon mAnmFog; - void GetAnmResult(FogAnmResult *, f32) const; + inline ResAnmFog(void *vptr) : mAnmFog(vptr) {} - bool IsValid() const { return mAnmFog.IsValid(); } - }; + void GetAnmResult(FogAnmResult *, f32) const; + + bool IsValid() const { + return mAnmFog.IsValid(); } -} +}; +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_resanmscn.h b/include/nw4r/g3d/g3d_resanmscn.h index 86c5ffd8..5983b256 100644 --- a/include/nw4r/g3d/g3d_resanmscn.h +++ b/include/nw4r/g3d/g3d_resanmscn.h @@ -1,45 +1,41 @@ #ifndef NW4R_G3D_RESANMSCN_H #define NW4R_G3D_RESANMSCN_H -#include "types_nw4r.h" -#include "g3d_rescommon.h" -#include "g3d_resanmfog.h" +#include "common.h" #include "g3d_resanmcamera.h" +#include "g3d_resanmfog.h" +#include "g3d_rescommon.h" -namespace nw4r -{ - namespace g3d - { - struct ResAnmScnData - { - char UNK_0x0[0x8]; - u32 mRevision; // at 0x8 - char UNK_0xC[0x3E - 0xC]; - u16 mFogMaxRefNum; // at 0x3E - }; +namespace nw4r { +namespace g3d { +struct ResAnmScnData { + char UNK_0x0[0x8]; + u32 mRevision; // at 0x8 + char UNK_0xC[0x3E - 0xC]; + u16 mFogMaxRefNum; // at 0x3E +}; - struct ResAnmScn - { - enum - { - REVISION = 4 - }; - - ResCommon mAnmScn; - - ResAnmFog GetResAnmFogByRefNumber(u32) const; - ResAnmCamera GetResAnmCameraByRefNumber(u32) const; +struct ResAnmScn { + enum { REVISION = 4 }; - inline ResAnmScn(void * vptr) : mAnmScn(vptr) {} + ResCommon mAnmScn; - inline bool IsValid() const { return mAnmScn.IsValid(); } - inline bool CheckRevision() const - { - return mAnmScn.ref().mRevision == REVISION; - } + ResAnmFog GetResAnmFogByRefNumber(u32) const; + ResAnmCamera GetResAnmCameraByRefNumber(u32) const; - u16 GetResAnmFogMaxRefNumber() const { return mAnmScn.ref().mFogMaxRefNum; } - }; - } -} + inline ResAnmScn(void *vptr) : mAnmScn(vptr) {} -#endif \ No newline at end of file + inline bool IsValid() const { + return mAnmScn.IsValid(); + } + inline bool CheckRevision() const { + return mAnmScn.ref().mRevision == REVISION; + } + + u16 GetResAnmFogMaxRefNumber() const { + return mAnmScn.ref().mFogMaxRefNum; + } +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resanmshp.h b/include/nw4r/g3d/g3d_resanmshp.h index 96bce327..58c3452b 100644 --- a/include/nw4r/g3d/g3d_resanmshp.h +++ b/include/nw4r/g3d/g3d_resanmshp.h @@ -1,35 +1,27 @@ #ifndef NW4R_G3D_RESANMSHP_H #define NW4R_G3D_RESANMSHP_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_rescommon.h" -namespace nw4r -{ - namespace g3d - { - struct ResAnmShpData - { - char UNK_0x0[0x8]; - u32 mRevision; // at 0x8 - }; +namespace nw4r { +namespace g3d { +struct ResAnmShpData { + char UNK_0x0[0x8]; + u32 mRevision; // at 0x8 +}; - struct ResAnmShp - { - enum - { - REVISION = 3 - }; - - ResCommon mAnmShp; - - inline ResAnmShp(void * vptr) : mAnmShp(vptr) {} - - inline bool CheckRevision() const - { - return mAnmShp.ref().mRevision == REVISION; - } - }; - } -} +struct ResAnmShp { + enum { REVISION = 3 }; -#endif \ No newline at end of file + ResCommon mAnmShp; + + inline ResAnmShp(void *vptr) : mAnmShp(vptr) {} + + inline bool CheckRevision() const { + return mAnmShp.ref().mRevision == REVISION; + } +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_rescommon.h b/include/nw4r/g3d/g3d_rescommon.h index 6bbd814f..5ff29ff7 100644 --- a/include/nw4r/g3d/g3d_rescommon.h +++ b/include/nw4r/g3d/g3d_rescommon.h @@ -1,141 +1,134 @@ #ifndef NW4R_G3D_RESCOMMON_H #define NW4R_G3D_RESCOMMON_H -#include "types_nw4r.h" +#include "common.h" -#define NW4R_G3D_CREATE_RES_NAME_DATA(VAR,VAL) ResNameData ResNameData_##VAR = { sizeof(VAL) - 1, VAL } +#define NW4R_G3D_CREATE_RES_NAME_DATA(VAR, VAL) ResNameData ResNameData_##VAR = {sizeof(VAL) - 1, VAL} #define FIFO_ACCESS_BP 0x61 #define FIFO_ACCESS_CP 0x8 #define FIFO_ACCESS_XF 0x10 -namespace nw4r -{ - namespace g3d - { - template - class ResCommon - { - T * mPtr; - - public: - inline ResCommon(void * vptr) : mPtr(static_cast(vptr)) {} - inline ResCommon(const void * vptr) : mPtr(static_cast(vptr)) {} - - inline T & ref() const { return *mPtr; } - inline T * ptr() const { return mPtr; } - inline bool IsValid() const { return mPtr != NULL; } +namespace nw4r { +namespace g3d { +template +class ResCommon { + T *mPtr; - template - inline const TPtr * ofs_to_ptr_raw(s32 ofs) const - { - return (const TPtr *)((u8 *)mPtr + ofs); - } - - template - inline TPtr * ofs_to_ptr(s32 ofs) - { - if (ofs) return (TPtr *)((u8 *)mPtr + ofs); - - return NULL; - } - - template - inline const TPtr * ofs_to_ptr(s32 ofs) const - { - if (ofs) return (const TPtr *)((u8 *)mPtr + ofs); - - return NULL; - } - - template - inline TObj ofs_to_obj(s32 ofs) const - { - if (ofs) return (u8 *)mPtr + ofs; - - return NULL; - } - }; - - struct ResNameData - { - u32 mLength; - char mName[0x1C]; - }; +public: + inline ResCommon(void *vptr) : mPtr(static_cast(vptr)) {} + inline ResCommon(const void *vptr) : mPtr(static_cast(vptr)) {} - struct ResName - { - ResCommon mRes; - - inline ResName(const void *vptr) : mRes(vptr) {} + inline T &ref() const { + return *mPtr; + } + inline T *ptr() const { + return mPtr; + } + inline bool IsValid() const { + return mPtr != NULL; + } - inline u32 GetLength() const - { - return mRes.ref().mLength; - } - - inline const char * GetName() const - { - return mRes.ref().mName; - } - - bool operator==(ResName) const; - }; + template + inline const TPtr *ofs_to_ptr_raw(s32 ofs) const { + return (const TPtr *)((u8 *)mPtr + ofs); + } - namespace detail - { - typedef u8 CPCmd[6]; - typedef u8 BPCmd[5]; - - inline void ResWrite_u8(u8 *res, u8 arg) - { - *res = arg; - } + template + inline TPtr *ofs_to_ptr(s32 ofs) { + if (ofs) { + return (TPtr *)((u8 *)mPtr + ofs); + } - inline void ResWrite_u16(u8 *res, u16 arg) - { - ResWrite_u8(res + 0, arg >> 8); - ResWrite_u8(res + 1, arg >> 0); - } + return NULL; + } - inline void ResWrite_u32(u8 *res, u32 arg) - { - ResWrite_u8(res + 0, arg >> 24); - ResWrite_u8(res + 1, arg >> 16); - ResWrite_u8(res + 2, arg >> 8); - ResWrite_u8(res + 3, arg >> 0); - } + template + inline const TPtr *ofs_to_ptr(s32 ofs) const { + if (ofs) { + return (const TPtr *)((u8 *)mPtr + ofs); + } - inline u8 ResRead_u8(const u8 *res) - { - return *res; - } + return NULL; + } - inline u32 ResRead_u32(const u8 *res) - { - int ret = ResRead_u8(res) << 24; - ret |= ResRead_u8(res + 1) << 16; - ret |= ResRead_u8(res + 2) << 8; - ret |= ResRead_u8(res + 3); - return ret; - } - - inline void ResReadBPCmd(const u8 *res, u32 *out) - { - *out = ResRead_u32(res + 1); - } - - inline void ResReadCPCmd(const u8 *res, u32 *out) - { - *out = ResRead_u32(res + 2); - } - - void ResWriteBPCmd(u8 *, u32); - void ResWriteBPCmd(u8 *, u32, u32); - void ResWriteCPCmd(u8 *, u8, u32); - void ResWriteXFCmd(u8 *, u16, u32); - void ResWriteSSMask(u8 *, u32); - } - } + template + inline TObj ofs_to_obj(s32 ofs) const { + if (ofs) { + return (u8 *)mPtr + ofs; + } + + return NULL; + } +}; + +struct ResNameData { + u32 mLength; + char mName[0x1C]; +}; + +struct ResName { + ResCommon mRes; + + inline ResName(const void *vptr) : mRes(vptr) {} + + inline u32 GetLength() const { + return mRes.ref().mLength; + } + + inline const char *GetName() const { + return mRes.ref().mName; + } + + bool operator==(ResName) const; +}; + +namespace detail { +typedef u8 CPCmd[6]; +typedef u8 BPCmd[5]; + +inline void ResWrite_u8(u8 *res, u8 arg) { + *res = arg; } -#endif \ No newline at end of file +inline void ResWrite_u16(u8 *res, u16 arg) { + ResWrite_u8(res + 0, arg >> 8); + ResWrite_u8(res + 1, arg >> 0); +} + +inline void ResWrite_u32(u8 *res, u32 arg) { + ResWrite_u8(res + 0, arg >> 24); + ResWrite_u8(res + 1, arg >> 16); + ResWrite_u8(res + 2, arg >> 8); + ResWrite_u8(res + 3, arg >> 0); +} + +inline u8 ResRead_u8(const u8 *res) { + return *res; +} + +inline u32 ResRead_u32(const u8 *res) { + int ret = ResRead_u8(res) << 24; + ret |= ResRead_u8(res + 1) << 16; + ret |= ResRead_u8(res + 2) << 8; + ret |= ResRead_u8(res + 3); + return ret; +} + +inline void ResReadBPCmd(const u8 *res, u32 *out) { + *out = ResRead_u32(res + 1); +} + +inline void ResReadCPCmd(const u8 *res, u32 *out) { + *out = ResRead_u32(res + 2); +} + +void ResWriteBPCmd(u8 *, u32); +void ResWriteBPCmd(u8 *, u32, u32); +void ResWriteCPCmd(u8 *, u8, u32); +void ResWriteXFCmd(u8 *, u16, u32); +void ResWriteSSMask(u8 *, u32); +} // namespace detail +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resdict.h b/include/nw4r/g3d/g3d_resdict.h index c3fde06a..07ecc2e7 100644 --- a/include/nw4r/g3d/g3d_resdict.h +++ b/include/nw4r/g3d/g3d_resdict.h @@ -1,57 +1,54 @@ #ifndef NW4R_G3D_RESDICT_H #define NW4R_G3D_RESDICT_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_rescommon.h" #include -namespace nw4r -{ - namespace g3d - { - struct ResDicEntry - { - u16 INT_0x0; // at 0x0 - u16 INT_0x2; // at 0x2 - u16 unk_index; // at 0x4 - u16 unk_index2; // at 0x6 - u32 INT_0x8; // at 0x8 - u32 INT_0xC; // at 0xC - }; +namespace nw4r { +namespace g3d { +struct ResDicEntry { + u16 INT_0x0; // at 0x0 + u16 INT_0x2; // at 0x2 + u16 unk_index; // at 0x4 + u16 unk_index2; // at 0x6 + u32 INT_0x8; // at 0x8 + u32 INT_0xC; // at 0xC +}; - struct ResDicData - { - u32 mSize; // at 0x0 - u32 mNumData; // at 0x4 - ResDicEntry mEntries[]; // 0x8 - }; +struct ResDicData { + u32 mSize; // at 0x0 + u32 mNumData; // at 0x4 + ResDicEntry mEntries[]; // 0x8 +}; - struct ResDic - { - ResCommon mDict; +struct ResDic { + ResCommon mDict; - ResDicEntry * Get(ResName) const; - ResDicEntry * Get(const char *, u32) const; - void * operator[](const char *) const; - void * operator[](ResName) const; - s32 GetIndex(ResName) const; - - inline ResDic(void * vptr) : mDict(vptr) {} - - inline void * operator[](int i) const - { - if (mDict.IsValid()) return (void *)mDict.ofs_to_ptr(mDict.ref().mEntries[i + 1].INT_0xC); - - return NULL; - } - - inline u32 GetNumData() const - { - if (mDict.IsValid()) return mDict.ref().mNumData; - - return 0; - } - }; - } -} + ResDicEntry *Get(ResName) const; + ResDicEntry *Get(const char *, u32) const; + void *operator[](const char *) const; + void *operator[](ResName) const; + s32 GetIndex(ResName) const; -#endif \ No newline at end of file + inline ResDic(void *vptr) : mDict(vptr) {} + + inline void *operator[](int i) const { + if (mDict.IsValid()) { + return (void *)mDict.ofs_to_ptr(mDict.ref().mEntries[i + 1].INT_0xC); + } + + return NULL; + } + + inline u32 GetNumData() const { + if (mDict.IsValid()) { + return mDict.ref().mNumData; + } + + return 0; + } +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resfile.h b/include/nw4r/g3d/g3d_resfile.h index fceaf42c..597fec6c 100644 --- a/include/nw4r/g3d/g3d_resfile.h +++ b/include/nw4r/g3d/g3d_resfile.h @@ -1,92 +1,87 @@ #ifndef NW4R_G3D_RESFILE_H #define NW4R_G3D_RESFILE_H -#include "ut_binaryFileFormat.h" +#include "common.h" #include "g3d_rescommon.h" #include "g3d_resdict.h" -#include "types_nw4r.h" +#include "ut_binaryFileFormat.h" -namespace nw4r -{ - namespace g3d - { - - struct ResFileData - { - ut::BinaryFileHeader mHeader; // at 0x0 - - ut::BinaryBlockHeader mRootHeader; // at 0x10 - ResDicData mRootData; // at 0x18 - }; - - struct ResFile - { - ResCommon mFile; // at 0x0 - - inline ResFileData & ref() const - { - return mFile.ref(); - } - - ResMdl GetResMdl(const char *) const; - ResMdl GetResMdl(int) const; - ResMdl GetResMdl(u32) const; //inlined - - ResPltt GetResPltt(const char *) const; - ResPltt GetResPltt(ResName) const; - ResPltt GetResPltt(int) const; - ResPltt GetResPltt(u32) const; //inlined - - ResTex GetResTex(const char *) const; - ResTex GetResTex(ResName) const; - ResTex GetResTex(int) const; - ResTex GetResTex(u32) const; //inlined - - ResAnmChr GetResAnmChr(const char *) const; - ResAnmChr GetResAnmChr(int) const; - ResAnmChr GetResAnmChr(u32) const; //inlined - - ResAnmVis GetResAnmVis(const char *) const; - ResAnmVis GetResAnmVis(int) const; - ResAnmVis GetResAnmVis(u32) const; //inlined - - ResAnmClr GetResAnmClr(const char *) const; - ResAnmClr GetResAnmClr(int) const; - ResAnmClr GetResAnmClr(u32) const; //inlined - - ResAnmTexPat GetResAnmTexPat(const char *) const; - ResAnmTexPat GetResAnmTexPat(int) const; - ResAnmTexPat GetResAnmTexPat(u32) const; //inlined - - ResAnmTexSrt GetResAnmTexSrt(const char *) const; - ResAnmTexSrt GetResAnmTexSrt(int) const; - ResAnmTexSrt GetResAnmTexSrt(u32) const; //inlined - - ResAnmShp GetResAnmShp(const char *) const; - ResAnmShp GetResAnmShp(int) const; - ResAnmShp GetResAnmShp(u32) const; //inlined - - ResAnmScn GetResAnmScn(const char *) const; - ResAnmScn GetResAnmScn(int) const; - ResAnmScn GetResAnmScn(u32) const; //inlined - - u32 GetResMdlNumEntries() const; //inlined - u32 GetResPlttNumEntries() const; //inlined - u32 GetResTexNumEntries() const; //inlined - u32 GetResAnmChrNumEntries() const; //inlined - u32 GetResAnmVisNumEntries() const; //inlined - u32 GetResAnmClrNumEntries() const; //inlined - u32 GetResAnmTexPatNumEntries() const; //inlined - u32 GetResAnmTexSrtNumEntries() const; //inlined - u32 GetResAnmShpNumEntries() const; //inlined - u32 GetResAnmScnNumEntries() const; - - bool Bind(ResFile); - void Release(); - void Init(); - void Terminate(); - bool CheckRevision() const; - }; - } -} +namespace nw4r { +namespace g3d { -#endif \ No newline at end of file +struct ResFileData { + ut::BinaryFileHeader mHeader; // at 0x0 + + ut::BinaryBlockHeader mRootHeader; // at 0x10 + ResDicData mRootData; // at 0x18 +}; + +struct ResFile { + ResCommon mFile; // at 0x0 + + inline ResFileData &ref() const { + return mFile.ref(); + } + + ResMdl GetResMdl(const char *) const; + ResMdl GetResMdl(int) const; + ResMdl GetResMdl(u32) const; // inlined + + ResPltt GetResPltt(const char *) const; + ResPltt GetResPltt(ResName) const; + ResPltt GetResPltt(int) const; + ResPltt GetResPltt(u32) const; // inlined + + ResTex GetResTex(const char *) const; + ResTex GetResTex(ResName) const; + ResTex GetResTex(int) const; + ResTex GetResTex(u32) const; // inlined + + ResAnmChr GetResAnmChr(const char *) const; + ResAnmChr GetResAnmChr(int) const; + ResAnmChr GetResAnmChr(u32) const; // inlined + + ResAnmVis GetResAnmVis(const char *) const; + ResAnmVis GetResAnmVis(int) const; + ResAnmVis GetResAnmVis(u32) const; // inlined + + ResAnmClr GetResAnmClr(const char *) const; + ResAnmClr GetResAnmClr(int) const; + ResAnmClr GetResAnmClr(u32) const; // inlined + + ResAnmTexPat GetResAnmTexPat(const char *) const; + ResAnmTexPat GetResAnmTexPat(int) const; + ResAnmTexPat GetResAnmTexPat(u32) const; // inlined + + ResAnmTexSrt GetResAnmTexSrt(const char *) const; + ResAnmTexSrt GetResAnmTexSrt(int) const; + ResAnmTexSrt GetResAnmTexSrt(u32) const; // inlined + + ResAnmShp GetResAnmShp(const char *) const; + ResAnmShp GetResAnmShp(int) const; + ResAnmShp GetResAnmShp(u32) const; // inlined + + ResAnmScn GetResAnmScn(const char *) const; + ResAnmScn GetResAnmScn(int) const; + ResAnmScn GetResAnmScn(u32) const; // inlined + + u32 GetResMdlNumEntries() const; // inlined + u32 GetResPlttNumEntries() const; // inlined + u32 GetResTexNumEntries() const; // inlined + u32 GetResAnmChrNumEntries() const; // inlined + u32 GetResAnmVisNumEntries() const; // inlined + u32 GetResAnmClrNumEntries() const; // inlined + u32 GetResAnmTexPatNumEntries() const; // inlined + u32 GetResAnmTexSrtNumEntries() const; // inlined + u32 GetResAnmShpNumEntries() const; // inlined + u32 GetResAnmScnNumEntries() const; + + bool Bind(ResFile); + void Release(); + void Init(); + void Terminate(); + bool CheckRevision() const; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resmat.h b/include/nw4r/g3d/g3d_resmat.h index f9638af4..1c5a6358 100644 --- a/include/nw4r/g3d/g3d_resmat.h +++ b/include/nw4r/g3d/g3d_resmat.h @@ -1,8 +1,8 @@ #ifndef NW4R_G3D_RESMAT_H #define NW4R_G3D_RESMAT_H +#include "common.h" #include "g3d_rescommon.h" #include "math_types.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_resmdl.h b/include/nw4r/g3d/g3d_resmdl.h index 84975c47..bf865abf 100644 --- a/include/nw4r/g3d/g3d_resmdl.h +++ b/include/nw4r/g3d/g3d_resmdl.h @@ -1,100 +1,93 @@ #ifndef NW4R_G3D_RESMDL_H #define NW4R_G3D_RESMDL_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_rescommon.h" -#include "g3d_resnode.h" #include "g3d_resdict.h" +#include "g3d_resnode.h" -namespace nw4r -{ - namespace g3d - { - struct ResMdlData - { - char mMagic[4]; // "MDL0" - u32 INT_0x4; - u32 mRevision; // at 0x8 - s32 INT_0xC; - u32 mByteCodeDictOfs; // at 0x10 - u32 mNodeDictOfs; // at 0x14 - u32 mVtxPosDictOfs; // at 0x18 - u32 mVtxNrmDictOfs; // at 0x1C - u32 mVtxClrDictOfs; // at 0x20 - u32 mVtxTexCoordDictOfs; // at 0x24 - u32 mMatDictOfs; // at 0x28 - u32 mTevDictOfs; // at 0x2C - u32 mShpDictOfs; // at 0x30 - u32 mPlttTexInfoOfs; // at 0x34 - }; +namespace nw4r { +namespace g3d { +struct ResMdlData { + char mMagic[4]; // "MDL0" + u32 INT_0x4; + u32 mRevision; // at 0x8 + s32 INT_0xC; + u32 mByteCodeDictOfs; // at 0x10 + u32 mNodeDictOfs; // at 0x14 + u32 mVtxPosDictOfs; // at 0x18 + u32 mVtxNrmDictOfs; // at 0x1C + u32 mVtxClrDictOfs; // at 0x20 + u32 mVtxTexCoordDictOfs; // at 0x24 + u32 mMatDictOfs; // at 0x28 + u32 mTevDictOfs; // at 0x2C + u32 mShpDictOfs; // at 0x30 + u32 mPlttTexInfoOfs; // at 0x34 +}; - struct ResMdl - { - enum - { - REVISION = 9 - }; - - ResCommon mMdl; - - inline ResMdl(void * vptr) : mMdl(vptr) {} - bool IsValid() const { return mMdl.IsValid(); } - - u8 * GetResByteCode(const char *) const; +struct ResMdl { + enum { REVISION = 9 }; - ResNode GetResNode(const char *) const; - ResNode GetResNode(ResName) const; - ResNode GetResNode(int) const; - ResNode GetResNode(u32) const; - u32 GetResNodeNumEntries() const; + ResCommon mMdl; - ResVtxPos GetResVtxPos(ResName) const; - ResVtxPos GetResVtxPos(int) const; - ResVtxPos GetResVtxPos(u32) const; - u32 GetResVtxPosNumEntries() const; + inline ResMdl(void *vptr) : mMdl(vptr) {} + bool IsValid() const { + return mMdl.IsValid(); + } - ResVtxNrm GetResVtxNrm(ResName) const; - ResVtxNrm GetResVtxNrm(int) const; - ResVtxNrm GetResVtxNrm(u32) const; - u32 GetResVtxNrmNumEntries() const; + u8 *GetResByteCode(const char *) const; - ResVtxClr GetResVtxClr(ResName) const; - ResVtxClr GetResVtxClr(int) const; - ResVtxClr GetResVtxClr(u32) const; - u32 GetResVtxClrNumEntries() const; + ResNode GetResNode(const char *) const; + ResNode GetResNode(ResName) const; + ResNode GetResNode(int) const; + ResNode GetResNode(u32) const; + u32 GetResNodeNumEntries() const; - ResVtxTexCoord GetResVtxTexCoord(int) const; + ResVtxPos GetResVtxPos(ResName) const; + ResVtxPos GetResVtxPos(int) const; + ResVtxPos GetResVtxPos(u32) const; + u32 GetResVtxPosNumEntries() const; - ResMat GetResMat(const char *) const; - ResMat GetResMat(ResName) const; - ResMat GetResMat(int) const; - ResMat GetResMat(u32) const; - u32 GetResMatNumEntries() const; + ResVtxNrm GetResVtxNrm(ResName) const; + ResVtxNrm GetResVtxNrm(int) const; + ResVtxNrm GetResVtxNrm(u32) const; + u32 GetResVtxNrmNumEntries() const; - ResShp GetResShp(const char *) const; - ResShp GetResShp(int) const; - ResShp GetResShp(u32) const; - u32 GetResShpNumEntries() const; + ResVtxClr GetResVtxClr(ResName) const; + ResVtxClr GetResVtxClr(int) const; + ResVtxClr GetResVtxClr(u32) const; + u32 GetResVtxClrNumEntries() const; - ResTexPlttInfo GetResTexPlttInfoOffsetFromTexName(int) const; - u32 GetResTexPlttInfoOffsetFromTexNameNumEntries() const; + ResVtxTexCoord GetResVtxTexCoord(int) const; - bool Bind(ResFile); - void Release(); - void Init(); - void Terminate(); - - inline bool CheckRevision() const - { - return mMdl.ref().mRevision == REVISION; - } + ResMat GetResMat(const char *) const; + ResMat GetResMat(ResName) const; + ResMat GetResMat(int) const; + ResMat GetResMat(u32) const; + u32 GetResMatNumEntries() const; - inline u32 GetResVtxTexCoordNumEntries() const - { - ResMdlData& ref = mMdl.ref(); - return mMdl.ofs_to_obj(ref.mVtxTexCoordDictOfs).GetNumData(); - } - }; - } -} + ResShp GetResShp(const char *) const; + ResShp GetResShp(int) const; + ResShp GetResShp(u32) const; + u32 GetResShpNumEntries() const; -#endif \ No newline at end of file + ResTexPlttInfo GetResTexPlttInfoOffsetFromTexName(int) const; + u32 GetResTexPlttInfoOffsetFromTexNameNumEntries() const; + + bool Bind(ResFile); + void Release(); + void Init(); + void Terminate(); + + inline bool CheckRevision() const { + return mMdl.ref().mRevision == REVISION; + } + + inline u32 GetResVtxTexCoordNumEntries() const { + ResMdlData &ref = mMdl.ref(); + return mMdl.ofs_to_obj(ref.mVtxTexCoordDictOfs).GetNumData(); + } +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resnode.h b/include/nw4r/g3d/g3d_resnode.h index 54e1a0c5..4e080c9d 100644 --- a/include/nw4r/g3d/g3d_resnode.h +++ b/include/nw4r/g3d/g3d_resnode.h @@ -1,68 +1,62 @@ #ifndef NW4R_G3D_RESNODE_H #define NW4R_G3D_RESNODE_H -#include "types_nw4r.h" -#include "g3d_rescommon.h" +#include "common.h" #include "g3d_anmchr.h" +#include "g3d_rescommon.h" #include "math_types.h" -namespace nw4r -{ - namespace g3d - { - struct ResNodeData - { - u32 INT_0x0; - s32 INT_0x4; - u16 SHORT_0x8; - u16 SHORT_0xA; - UNKWORD WORD_0xC; - UNKWORD WORD_0x10; - u32 mFlags; // at 0x14 - UNKWORD WORD_0x18; - UNKWORD WORD_0x1C; - math::VEC3 VEC3_0x20; - math::VEC3 VEC3_0x2C; - f32 FLOAT_0x38; - f32 FLOAT_0x3C; - f32 FLOAT_0x40; - // . . . - }; +namespace nw4r { +namespace g3d { +struct ResNodeData { + u32 INT_0x0; + s32 INT_0x4; + u16 SHORT_0x8; + u16 SHORT_0xA; + UNKWORD WORD_0xC; + UNKWORD WORD_0x10; + u32 mFlags; // at 0x14 + UNKWORD WORD_0x18; + UNKWORD WORD_0x1C; + math::VEC3 VEC3_0x20; + math::VEC3 VEC3_0x2C; + f32 FLOAT_0x38; + f32 FLOAT_0x3C; + f32 FLOAT_0x40; + // . . . +}; - struct ResNode - { - enum ResNodeFlags - { - NODE_IS_VISIBLE = 0x100 - }; +struct ResNode { + enum ResNodeFlags { NODE_IS_VISIBLE = 0x100 }; - ResCommon mNode; + ResCommon mNode; - inline ResNode(void * vptr) : mNode(vptr) {} - - bool IsValid() const { return mNode.IsValid(); } + inline ResNode(void *vptr) : mNode(vptr) {} - UNKWORD GetID() const - { - if (IsValid()) - return mNode.ptr()->WORD_0xC; - return 0; - } - - void SetVisibility(bool visible) - { - if (IsValid()) - { - if (visible) - mNode.ptr()->mFlags |= NODE_IS_VISIBLE; - else - mNode.ptr()->mFlags &= ~NODE_IS_VISIBLE; - } - } - - void PatchChrAnmResult(ChrAnmResult *) const; - void CalcChrAnmResult(ChrAnmResult *) const; - }; + bool IsValid() const { + return mNode.IsValid(); } -} -#endif \ No newline at end of file + UNKWORD GetID() const { + if (IsValid()) { + return mNode.ptr()->WORD_0xC; + } + return 0; + } + + void SetVisibility(bool visible) { + if (IsValid()) { + if (visible) { + mNode.ptr()->mFlags |= NODE_IS_VISIBLE; + } else { + mNode.ptr()->mFlags &= ~NODE_IS_VISIBLE; + } + } + } + + void PatchChrAnmResult(ChrAnmResult *) const; + void CalcChrAnmResult(ChrAnmResult *) const; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_resshp.h b/include/nw4r/g3d/g3d_resshp.h index bf61cebb..55cd6f29 100644 --- a/include/nw4r/g3d/g3d_resshp.h +++ b/include/nw4r/g3d/g3d_resshp.h @@ -1,122 +1,110 @@ #ifndef NW4R_G3D_RESSHP_H #define NW4R_G3D_RESSHP_H -#include -#include "types_nw4r.h" #include "g3d_rescommon.h" #include "g3d_resmdl.h" #include "g3d_resvtx.h" +#include #include "common.h" -namespace nw4r -{ - namespace g3d - { - struct ResTagDLData - { - u32 mBufSize; // at 0x0 - u32 mCmdSize; // at 0x4 - u32 mOffset; // at 0x8 - }; - - struct ResPrePrimDL - { - char UNK_0x0[0xA]; - detail::CPCmd CP_CMD_0xA; - detail::CPCmd CP_CMD_0x10; - char UNK_0x16[0xA]; - detail::CPCmd CP_CMD_0x20; - detail::CPCmd CP_CMD_0x26; - detail::CPCmd CP_CMD_0x2C; - detail::CPCmd CP_CMD_PAIRS_0x32[GX_POS_MTX_ARRAY - GX_VA_POS][2]; - char UNK_0xC2[0x1E]; - }; - - struct ResShpData - { - char UNK_0x0[0x4]; - u32 mParentOffset; // at 0x4 - char UNK_0x8[0x10]; - ResTagDLData mPrePrimDLTag; // at 0x18 - ResTagDLData mPrimDLTag; // at 0x24 - char UNK_0x30[0x18]; - - s16 mVtxPosIndex; // at 0x48 - s16 mVtxNrmIndex; // at 0x4a - s16 mVtxClrIndices[GX_VA_TEX0 - GX_VA_CLR0]; // at 0x4c - s16 mVtxTexCoordIndices[GX_POS_MTX_ARRAY - GX_VA_TEX0]; // at 0x50 - }; - - struct ResTagDL - { - ResCommon mData; - - inline ResTagDL(void * vptr) : mData(vptr) {} - - inline u8 * GetDL() const - { - return const_cast(mData.ofs_to_ptr(mData.ref().mOffset)); - } - - inline u32 GetBufSize() const - { - return mData.ref().mBufSize; - } - - inline u32 GetCmdSize() const - { - return mData.ref().mCmdSize; - } - }; - - struct ResShpPrePrim - { - ResCommon mDL; - - inline ResShpPrePrim(void * vptr) : mDL(vptr) {} - - inline ResPrePrimDL & ref() const - { - return mDL.ref(); - } - }; - - struct ResShp - { - ResCommon mShp; - - inline ResShp(void * vptr) : mShp(vptr) {} - bool IsValid() const { return mShp.IsValid(); } - inline ResShpData & ref() const - { - return mShp.ref(); - } - - inline ResShpPrePrim GetResShpPrePrim() const - { - return ResTagDL(&ref().mPrePrimDLTag).GetDL(); - } - - bool GXGetVtxDescv(GXVtxDescList*) const; - bool GXGetVtxAttrFmtv(GXVtxAttrFmtList*) const; - - ResMdl GetParent() const; //inlined - - ResVtxPos GetResVtxPos() const; - ResVtxNrm GetResVtxNrm() const; - ResVtxClr GetResVtxClr(u32) const; - ResVtxTexCoord GetResVtxTexCoord(u32) const; //inlined - - void GXSetArray(GXAttr, const void *, u8); //inlined - - void Init(); - - void DisableSetArray(GXAttr); //inlined - void Terminate(); - - void CallPrePrimitiveDisplayList(bool, bool) const; - void CallPrimitiveDisplayList(bool) const; - }; - } -} +namespace nw4r { +namespace g3d { +struct ResTagDLData { + u32 mBufSize; // at 0x0 + u32 mCmdSize; // at 0x4 + u32 mOffset; // at 0x8 +}; -#endif \ No newline at end of file +struct ResPrePrimDL { + char UNK_0x0[0xA]; + detail::CPCmd CP_CMD_0xA; + detail::CPCmd CP_CMD_0x10; + char UNK_0x16[0xA]; + detail::CPCmd CP_CMD_0x20; + detail::CPCmd CP_CMD_0x26; + detail::CPCmd CP_CMD_0x2C; + detail::CPCmd CP_CMD_PAIRS_0x32[GX_POS_MTX_ARRAY - GX_VA_POS][2]; + char UNK_0xC2[0x1E]; +}; + +struct ResShpData { + char UNK_0x0[0x4]; + u32 mParentOffset; // at 0x4 + char UNK_0x8[0x10]; + ResTagDLData mPrePrimDLTag; // at 0x18 + ResTagDLData mPrimDLTag; // at 0x24 + char UNK_0x30[0x18]; + + s16 mVtxPosIndex; // at 0x48 + s16 mVtxNrmIndex; // at 0x4a + s16 mVtxClrIndices[GX_VA_TEX0 - GX_VA_CLR0]; // at 0x4c + s16 mVtxTexCoordIndices[GX_POS_MTX_ARRAY - GX_VA_TEX0]; // at 0x50 +}; + +struct ResTagDL { + ResCommon mData; + + inline ResTagDL(void *vptr) : mData(vptr) {} + + inline u8 *GetDL() const { + return const_cast(mData.ofs_to_ptr(mData.ref().mOffset)); + } + + inline u32 GetBufSize() const { + return mData.ref().mBufSize; + } + + inline u32 GetCmdSize() const { + return mData.ref().mCmdSize; + } +}; + +struct ResShpPrePrim { + ResCommon mDL; + + inline ResShpPrePrim(void *vptr) : mDL(vptr) {} + + inline ResPrePrimDL &ref() const { + return mDL.ref(); + } +}; + +struct ResShp { + ResCommon mShp; + + inline ResShp(void *vptr) : mShp(vptr) {} + bool IsValid() const { + return mShp.IsValid(); + } + + inline ResShpData &ref() const { + return mShp.ref(); + } + + inline ResShpPrePrim GetResShpPrePrim() const { + return ResTagDL(&ref().mPrePrimDLTag).GetDL(); + } + + bool GXGetVtxDescv(GXVtxDescList *) const; + bool GXGetVtxAttrFmtv(GXVtxAttrFmtList *) const; + + ResMdl GetParent() const; // inlined + + ResVtxPos GetResVtxPos() const; + ResVtxNrm GetResVtxNrm() const; + ResVtxClr GetResVtxClr(u32) const; + ResVtxTexCoord GetResVtxTexCoord(u32) const; // inlined + + void GXSetArray(GXAttr, const void *, u8); // inlined + + void Init(); + + void DisableSetArray(GXAttr); // inlined + void Terminate(); + + void CallPrePrimitiveDisplayList(bool, bool) const; + void CallPrimitiveDisplayList(bool) const; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_restex.h b/include/nw4r/g3d/g3d_restex.h index 15283910..9d85d355 100644 --- a/include/nw4r/g3d/g3d_restex.h +++ b/include/nw4r/g3d/g3d_restex.h @@ -1,7 +1,7 @@ #ifndef NW4R_G3D_RESTEX_H #define NW4R_G3D_RESTEX_H +#include "common.h" #include "g3d_rescommon.h" -#include "types_nw4r.h" #include diff --git a/include/nw4r/g3d/g3d_scnmdl.h b/include/nw4r/g3d/g3d_scnmdl.h index f1875981..5f1cb9e9 100644 --- a/include/nw4r/g3d/g3d_scnmdl.h +++ b/include/nw4r/g3d/g3d_scnmdl.h @@ -1,42 +1,39 @@ #ifndef NW4R_G3D_SCN_MDL_H #define NW4R_G3D_SCN_MDL_H -#include "types_nw4r.h" -#include "g3d_scnmdlsmpl.h" -#include "g3d_resmat.h" +#include "common.h" #include "g3d_draw.h" +#include "g3d_resmat.h" +#include "g3d_scnmdlsmpl.h" -namespace nw4r -{ - namespace g3d - { - class ScnMdl : public ScnMdlSimple - { - public: - class CopiedMatAccess - { - public: - CopiedMatAccess(ScnMdl *, u32); - ResTexSrt GetResTexSrtEx(); +namespace nw4r { +namespace g3d { +class ScnMdl : public ScnMdlSimple { +public: + class CopiedMatAccess { + public: + CopiedMatAccess(ScnMdl *, u32); + ResTexSrt GetResTexSrtEx(); - private: - char UNK_0x0[0x2C]; - }; + private: + char UNK_0x0[0x2C]; + }; - public: - static const G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - DrawResMdlReplacement * GetDrawResMdlReplacement() { return &mDrawMdlReplace; } - - private: - char UNK_0x118[0x144 - 0x118]; - DrawResMdlReplacement mDrawMdlReplace; // at 0x144 - - NW4R_G3D_TYPE_OBJ_DECL(ScnMdl); - }; +public: + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); } -} -#endif \ No newline at end of file + DrawResMdlReplacement *GetDrawResMdlReplacement() { + return &mDrawMdlReplace; + } + +private: + char UNK_0x118[0x144 - 0x118]; + DrawResMdlReplacement mDrawMdlReplace; // at 0x144 + + NW4R_G3D_TYPE_OBJ_DECL(ScnMdl); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnmdl1mat1shp.h b/include/nw4r/g3d/g3d_scnmdl1mat1shp.h index 1b55ece6..5e3d3dc9 100644 --- a/include/nw4r/g3d/g3d_scnmdl1mat1shp.h +++ b/include/nw4r/g3d/g3d_scnmdl1mat1shp.h @@ -1,32 +1,32 @@ #ifndef NW4R_G3D_SCN_MDL1_MAT1_SHP_H #define NW4R_G3D_SCN_MDL1_MAT1_SHP_H -#include "types_nw4r.h" -#include "g3d_scnobj.h" +#include "common.h" #include "g3d_resmat.h" #include "g3d_resshp.h" +#include "g3d_scnobj.h" -namespace nw4r -{ - namespace g3d - { - class ScnMdl1Mat1Shp : public ScnLeaf - { - public: - static const G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - ResMat GetResMat() { return mResMat; } - ResShp GetResShp() { return mResShp; } - - private: - ResMat mResMat; // at 0xE8 - ResShp mResShp; // at 0xEC - - NW4R_G3D_TYPE_OBJ_DECL(ScnMdl1Mat1Shp); - }; +namespace nw4r { +namespace g3d { +class ScnMdl1Mat1Shp : public ScnLeaf { +public: + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); } -} -#endif \ No newline at end of file + ResMat GetResMat() { + return mResMat; + } + ResShp GetResShp() { + return mResShp; + } + +private: + ResMat mResMat; // at 0xE8 + ResShp mResShp; // at 0xEC + + NW4R_G3D_TYPE_OBJ_DECL(ScnMdl1Mat1Shp); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnmdlsmpl.h b/include/nw4r/g3d/g3d_scnmdlsmpl.h index 56ae32c0..00ab12a0 100644 --- a/include/nw4r/g3d/g3d_scnmdlsmpl.h +++ b/include/nw4r/g3d/g3d_scnmdlsmpl.h @@ -1,73 +1,77 @@ #ifndef NW4R_G3D_SCN_MDL_SIMPLE_H #define NW4R_G3D_SCN_MDL_SIMPLE_H -#include "types_nw4r.h" -#include "g3d_scnobj.h" +#include "common.h" #include "g3d_resmdl.h" +#include "g3d_scnobj.h" -namespace nw4r -{ - namespace g3d +namespace nw4r { +namespace g3d { +class ScnMdlSimple : public ScnLeaf { +public: + enum ByteCodeType { + BYTE_CODE_CALC, + BYTE_CODE_MIX, + BYTE_CODE_DRAW_OPA, + BYTE_CODE_DRAW_XLU, + }; + +public: + ScnMdlSimple(MEMAllocator *, ResMdl, math::MTX34 *, u32 *, math::MTX34 *, math::MTX33 *, math::MTX34 *, int, int); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 { - class ScnMdlSimple : public ScnLeaf - { - public: - enum ByteCodeType - { - BYTE_CODE_CALC, - BYTE_CODE_MIX, - BYTE_CODE_DRAW_OPA, - BYTE_CODE_DRAW_XLU, - }; - - public: - ScnMdlSimple(MEMAllocator *, ResMdl, math::MTX34 *, u32 *, - math::MTX34 *, math::MTX33 *, math::MTX34 *, int, int); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : ScnLeaf::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~ScnMdlSimple(); // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - - const u8 * GetByteCode(ByteCodeType) const; - - const ResMdl GetResMdl() const { return mResMdl; } - ResMdl GetResMdl() { return mResMdl; } - - math::MTX34 * GetWldMtxArray() { return mWldMatrixArray; } - u32 * GetWldMtxAttribArray() { return mWldMtxAttribArray; } - - u16 GetNumViewMtx() const { return mNumViewMtx; } - - private: - ResMdl mResMdl; // at 0xE8 - math::MTX34 *mWldMatrixArray; // at 0xEC - u32 *mWldMtxAttribArray; // at 0xF0 - math::MTX34 *PTR_0xF4; - math::MTX33 *PTR_0xF8; - math::MTX34 *PTR_0xFC; - u8 BYTE_0x100; - u8 BYTE_0x101; - u16 mNumViewMtx; // at 0x102 - UNKWORD WORD_0x104; - void *mByteCodeCalc; // at 0x108 - void *mByteCodeMix; // at 0x10C - void *mByteCodeDrawOpa; // at 0x110 - void *mByteCodeDrawXlu; // at 0x114 - - NW4R_G3D_TYPE_OBJ_DECL(ScnMdlSimple); - }; + return (other == GetTypeObjStatic()) ? true : ScnLeaf::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~ScnMdlSimple(); // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); } -} -#endif \ No newline at end of file + const u8 *GetByteCode(ByteCodeType) const; + + const ResMdl GetResMdl() const { + return mResMdl; + } + ResMdl GetResMdl() { + return mResMdl; + } + + math::MTX34 *GetWldMtxArray() { + return mWldMatrixArray; + } + u32 *GetWldMtxAttribArray() { + return mWldMtxAttribArray; + } + + u16 GetNumViewMtx() const { + return mNumViewMtx; + } + +private: + ResMdl mResMdl; // at 0xE8 + math::MTX34 *mWldMatrixArray; // at 0xEC + u32 *mWldMtxAttribArray; // at 0xF0 + math::MTX34 *PTR_0xF4; + math::MTX33 *PTR_0xF8; + math::MTX34 *PTR_0xFC; + u8 BYTE_0x100; + u8 BYTE_0x101; + u16 mNumViewMtx; // at 0x102 + UNKWORD WORD_0x104; + void *mByteCodeCalc; // at 0x108 + void *mByteCodeMix; // at 0x10C + void *mByteCodeDrawOpa; // at 0x110 + void *mByteCodeDrawXlu; // at 0x114 + + NW4R_G3D_TYPE_OBJ_DECL(ScnMdlSimple); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnobj.h b/include/nw4r/g3d/g3d_scnobj.h index babda1f0..f10a037e 100644 --- a/include/nw4r/g3d/g3d_scnobj.h +++ b/include/nw4r/g3d/g3d_scnobj.h @@ -1,340 +1,278 @@ #ifndef NW4R_G3D_SCNOBJ_H #define NW4R_G3D_SCNOBJ_H -#include "types_nw4r.h" -#include "math_types.h" -#include "math_geometry.h" +#include "common.h" #include "g3d_obj.h" +#include "math_geometry.h" +#include "math_types.h" -namespace nw4r -{ - namespace g3d +namespace nw4r { +namespace g3d { +namespace { +static inline u32 align4(u32 x) { + return x + 3 & ~3; +} +} // namespace + +struct IScnObjGather { + virtual ~IScnObjGather(); + virtual UNKWORD Add(ScnObj *, bool, bool) = 0; +}; + +class ScnObj : public G3dObj { +public: + enum ForEachResult { FOREACH_RESULT_0, FOREACH_RESULT_1 }; + + enum ScnObjFlag { + FLAG_1 = 0x1, + FLAG_2 = 0x2, + FLAG_4 = 0x4, + FLAG_8 = 0x8, + FLAG_10 = 0x10, + FLAG_20 = 0x20, + FLAG_40 = 0x40, + FLAG_80 = 0x80, + FLAG_10000000 = 0x10000000, + FLAG_20000000 = 0x20000000, + FLAG_40000000 = 0x40000000, + FLAG_80000000 = 0x80000000, + + FLAG_60 = FLAG_40 | FLAG_20 + }; + + enum ScnObjMtxType { MTX_TYPE_0, MTX_TYPE_WORLD, MTX_TYPE_VIEW, MTX_TYPE_MAX }; + + enum Timing { TIMING_1 = 0x1, TIMING_2 = 0x2, TIMING_4 = 0x4 }; + + enum ExecOp { EXEC_OP_1 = 0x1, EXEC_OP_2 = 0x2, EXEC_OP_4 = 0x4 }; + + enum ScnObjBoundingVolumeType { BOUNDING_0, BOUNDING_1, BOUNDING_MAX }; + + enum ScnObjOption { OPTION_VISIBLE = (1 << 0) }; + + typedef ForEachResult (*ForEachAction)(ScnObj *, void *); + +public: + ScnObj(MEMAllocator *); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 { - namespace - { - static inline u32 align4(u32 x) { return x + 3 & ~3; } + return (other == GetTypeObjStatic()) ? true : G3dObj::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *) = 0; // at 0xC + virtual ~ScnObj(); // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual ForEachResult ForEach(ForEachAction, void *, bool) = 0; // at 0x1C + virtual bool SetScnObjOption(u32, u32); // at 0x20 + virtual bool GetScnObjOption(u32, u32 *) const; // at 0x24 + virtual f32 GetValueForSortOpa() const; // at 0x28 + virtual f32 GetValueForSortXlu() const; // at 0x2C + virtual void CalcWorldMtx(const math::MTX34 *, u32 *); // at 0x30 + + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + void CalcViewMtx(const math::MTX34 *); + bool SetMtx(ScnObjMtxType, const math::MTX34 *); + bool GetMtx(ScnObjMtxType, math::MTX34 *) const; + void SetPriorityDrawOpa(int); + void SetPriorityDrawXlu(int); + void EnableScnObjCallbackTiming(Timing); + void EnableScnObjCallbackExecOp(ExecOp); + bool SetBoundingVolume(ScnObjBoundingVolumeType, const math::AABB *); + bool GetBoundingVolume(ScnObjBoundingVolumeType, math::AABB *) const; + + const math::MTX34 *GetMtxPtr(ScnObjMtxType type) const { + return &mMatrices[type]; + } + + void SetScnObjFlag(ScnObjFlag f, u32 set) { + if (set) { + mFlags |= f; + } else { + mFlags &= ~f; } + } + bool TestScnObjFlag(ScnObjFlag f) const { + return mFlags & f; + } - struct IScnObjGather - { - virtual ~IScnObjGather(); - virtual UNKWORD Add(ScnObj *, bool, bool) = 0; - }; + inline void CheckCallback_CALC_VIEW(Timing timing, u32 r5, void *r6); + inline void CheckCallback_CALC_MAT(Timing timing, u32 r5, void *r6); + inline void CheckCallback_CALC_WORLD(Timing timing, u32 r5, void *r6); - class ScnObj : public G3dObj - { - public: - enum ForEachResult - { - FOREACH_RESULT_0, - FOREACH_RESULT_1 - }; - - enum ScnObjFlag - { - FLAG_1 = 0x1, - FLAG_2 = 0x2, - FLAG_4 = 0x4, - FLAG_8 = 0x8, - FLAG_10 = 0x10, - FLAG_20 = 0x20, - FLAG_40 = 0x40, - FLAG_80 = 0x80, - FLAG_10000000 = 0x10000000, - FLAG_20000000 = 0x20000000, - FLAG_40000000 = 0x40000000, - FLAG_80000000 = 0x80000000, - - FLAG_60 = FLAG_40 | FLAG_20 - }; - - enum ScnObjMtxType - { - MTX_TYPE_0, - MTX_TYPE_WORLD, - MTX_TYPE_VIEW, - MTX_TYPE_MAX - }; - - enum Timing - { - TIMING_1 = 0x1, - TIMING_2 = 0x2, - TIMING_4 = 0x4 - }; - - enum ExecOp - { - EXEC_OP_1 = 0x1, - EXEC_OP_2 = 0x2, - EXEC_OP_4 = 0x4 - }; - - enum ScnObjBoundingVolumeType - { - BOUNDING_0, - BOUNDING_1, - BOUNDING_MAX - }; - - enum ScnObjOption - { - OPTION_VISIBLE = (1 << 0) - }; - - typedef ForEachResult (* ForEachAction)(ScnObj *, void *); - - public: - ScnObj(MEMAllocator *); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : G3dObj::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *) = 0; // at 0xC - virtual ~ScnObj(); // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual ForEachResult ForEach(ForEachAction, void *, bool) = 0; // at 0x1C - virtual bool SetScnObjOption(u32, u32); // at 0x20 - virtual bool GetScnObjOption(u32, u32 *) const; // at 0x24 - virtual f32 GetValueForSortOpa() const; // at 0x28 - virtual f32 GetValueForSortXlu() const; // at 0x2C - virtual void CalcWorldMtx(const math::MTX34 *, u32 *); // at 0x30 - - static const G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - void CalcViewMtx(const math::MTX34 *); - bool SetMtx(ScnObjMtxType, const math::MTX34 *); - bool GetMtx(ScnObjMtxType, math::MTX34 *) const; - void SetPriorityDrawOpa(int); - void SetPriorityDrawXlu(int); - void EnableScnObjCallbackTiming(Timing); - void EnableScnObjCallbackExecOp(ExecOp); - bool SetBoundingVolume(ScnObjBoundingVolumeType, const math::AABB *); - bool GetBoundingVolume(ScnObjBoundingVolumeType, math::AABB *) const; - - const math::MTX34 * GetMtxPtr(ScnObjMtxType type) const - { - return &mMatrices[type]; - } - - void SetScnObjFlag(ScnObjFlag f, u32 set) - { - if (set) - { - mFlags |= f; - } - else - { - mFlags &= ~f; - } - } - bool TestScnObjFlag(ScnObjFlag f) const - { - return mFlags & f; - } - - inline void CheckCallback_CALC_VIEW(Timing timing, u32 r5, void *r6); - inline void CheckCallback_CALC_MAT(Timing timing, u32 r5, void *r6); - inline void CheckCallback_CALC_WORLD(Timing timing, u32 r5, void *r6); - - bool IsG3dProcDisabled(u32 task) const - { - if ((task < 9) && (1 << (task - 1) & mFlags)) return true; - return false; - } - - protected: - math::MTX34 mMatrices[MTX_TYPE_MAX]; // at 0xC - math::AABB mBounds[BOUNDING_MAX]; // at 0x9C - - u32 mFlags; // at 0xCC - u8 mPriorityDrawOpa; // at 0xD0 - u8 mPriorityDrawXlu; // at 0xD1 - u8 BYTE_0xD2; - u8 BYTE_0xD3; - IScnObjCallback *mCallback; // at 0xD4 - u8 mTiming; // at 0xD8 - u8 BYTE_0xD9; - u16 mExecOp; // at 0xDA - - NW4R_G3D_TYPE_OBJ_DECL(ScnObj); - }; - - struct IScnObjCallback - { - virtual ~IScnObjCallback() {} // at 0x8 - virtual void ExecCallback_CALC_WORLD(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0xC - virtual void ExecCallback_CALC_MAT(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0x10 - virtual void ExecCallback_CALC_VIEW(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0x14 - }; - - // Is there a better way of resolving this dependency? - void ScnObj::CheckCallback_CALC_VIEW(Timing timing, u32 r5, void *r6) - { - if (mCallback != NULL) - { - if ((mExecOp & EXEC_OP_4) && (mTiming & timing)) - { - mCallback->ExecCallback_CALC_VIEW(timing, this, r5, r6); - } - } + bool IsG3dProcDisabled(u32 task) const { + if ((task < 9) && (1 << (task - 1) & mFlags)) { + return true; } + return false; + } - void ScnObj::CheckCallback_CALC_MAT(Timing timing, u32 r5, void *r6) - { - if (mCallback != NULL) - { - if ((mExecOp & EXEC_OP_2) && (mTiming & timing)) - { - mCallback->ExecCallback_CALC_MAT(timing, this, r5, r6); - } - } +protected: + math::MTX34 mMatrices[MTX_TYPE_MAX]; // at 0xC + math::AABB mBounds[BOUNDING_MAX]; // at 0x9C + + u32 mFlags; // at 0xCC + u8 mPriorityDrawOpa; // at 0xD0 + u8 mPriorityDrawXlu; // at 0xD1 + u8 BYTE_0xD2; + u8 BYTE_0xD3; + IScnObjCallback *mCallback; // at 0xD4 + u8 mTiming; // at 0xD8 + u8 BYTE_0xD9; + u16 mExecOp; // at 0xDA + + NW4R_G3D_TYPE_OBJ_DECL(ScnObj); +}; + +struct IScnObjCallback { + virtual ~IScnObjCallback() {} // at 0x8 + virtual void ExecCallback_CALC_WORLD(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0xC + virtual void ExecCallback_CALC_MAT(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0x10 + virtual void ExecCallback_CALC_VIEW(ScnObj::Timing, ScnObj *, u32, void *) {} // at 0x14 +}; + +// Is there a better way of resolving this dependency? +void ScnObj::CheckCallback_CALC_VIEW(Timing timing, u32 r5, void *r6) { + if (mCallback != NULL) { + if ((mExecOp & EXEC_OP_4) && (mTiming & timing)) { + mCallback->ExecCallback_CALC_VIEW(timing, this, r5, r6); } - - void ScnObj::CheckCallback_CALC_WORLD(Timing timing, u32 r5, void *r6) - { - if (mCallback != NULL) - { - if ((mExecOp & EXEC_OP_1) && (mTiming & timing)) - { - mCallback->ExecCallback_CALC_WORLD(timing, this, r5, r6); - } - } - } - - class ScnLeaf : public ScnObj - { - public: - // Unofficial name, however GetScaleProperty needs to return an enum to match - enum ScaleProperty - { - SCALE_PROPERTY_0, - SCALE_PROPERTY_1, - SCALE_PROPERTY_2, - }; - - public: - ScnLeaf(MEMAllocator *allocator) : ScnObj(allocator), mScale(1.0f, 1.0f, 1.0f) {} - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : ScnObj::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *) = 0; // at 0xC - virtual ~ScnLeaf() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual ForEachResult ForEach(ForEachAction, void *, bool); // at 0x1C - virtual bool SetScnObjOption(u32, u32); // at 0x20 - virtual bool GetScnObjOption(u32, u32 *) const; // at 0x24 - virtual void CalcWorldMtx(const math::MTX34 *, u32 *); // at 0x30 - - static const G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - ScaleProperty GetScaleProperty() const; - void DefG3dProcScnLeaf(u32, u32, void *); - - private: - math::VEC3 mScale; - - NW4R_G3D_TYPE_OBJ_DECL(ScnLeaf); - }; - - class ScnGroup : public ScnObj - { - public: - ScnGroup(MEMAllocator *, ScnObj **, u32); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()) ? true - : ScnObj::IsDerivedFrom(other); - } - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~ScnGroup(); // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - virtual ForEachResult ForEach(ForEachAction, void *, bool); // at 0x1C - virtual bool Insert(u32, ScnObj *); // at 0x34 - virtual ScnObj * Remove(u32); // at 0x38 - virtual bool Remove(ScnObj *); // at 0x3C - - static const G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - bool Empty() const - { - return mSize == 0; - } - - u32 Size() const - { - return mSize; - } - - ScnObj * PopBack() - { - if (!Empty()) - { - return Remove(Size() - 1); - } - - return NULL; - } - - void Clear() - { - while (!Empty()) - { - PopBack(); - } - } - - void ScnGroup_G3DPROC_GATHER_SCNOBJ(u32, IScnObjGather *); - void ScnGroup_G3DPROC_CALC_WORLD(u32, const math::MTX34 *); - void ScnGroup_G3DPROC_CALC_MAT(u32, void *); - void ScnGroup_G3DPROC_CALC_VIEW(u32, const math::MTX34 *); - void DefG3dProcScnGroup(u32, u32, void *); - - bool PushBack(ScnObj *); - - ScnObj **mObjects; // at 0xDC - u32 mCapacity; // at 0xE0 - u32 mSize; // at 0xE4 - - private: - NW4R_G3D_TYPE_OBJ_DECL(ScnGroup); - }; } } -#endif \ No newline at end of file +void ScnObj::CheckCallback_CALC_MAT(Timing timing, u32 r5, void *r6) { + if (mCallback != NULL) { + if ((mExecOp & EXEC_OP_2) && (mTiming & timing)) { + mCallback->ExecCallback_CALC_MAT(timing, this, r5, r6); + } + } +} + +void ScnObj::CheckCallback_CALC_WORLD(Timing timing, u32 r5, void *r6) { + if (mCallback != NULL) { + if ((mExecOp & EXEC_OP_1) && (mTiming & timing)) { + mCallback->ExecCallback_CALC_WORLD(timing, this, r5, r6); + } + } +} + +class ScnLeaf : public ScnObj { +public: + // Unofficial name, however GetScaleProperty needs to return an enum to match + enum ScaleProperty { + SCALE_PROPERTY_0, + SCALE_PROPERTY_1, + SCALE_PROPERTY_2, + }; + +public: + ScnLeaf(MEMAllocator *allocator) : ScnObj(allocator), mScale(1.0f, 1.0f, 1.0f) {} + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : ScnObj::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *) = 0; // at 0xC + virtual ~ScnLeaf() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual ForEachResult ForEach(ForEachAction, void *, bool); // at 0x1C + virtual bool SetScnObjOption(u32, u32); // at 0x20 + virtual bool GetScnObjOption(u32, u32 *) const; // at 0x24 + virtual void CalcWorldMtx(const math::MTX34 *, u32 *); // at 0x30 + + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + ScaleProperty GetScaleProperty() const; + void DefG3dProcScnLeaf(u32, u32, void *); + +private: + math::VEC3 mScale; + + NW4R_G3D_TYPE_OBJ_DECL(ScnLeaf); +}; + +class ScnGroup : public ScnObj { +public: + ScnGroup(MEMAllocator *, ScnObj **, u32); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return (other == GetTypeObjStatic()) ? true : ScnObj::IsDerivedFrom(other); + } + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~ScnGroup(); // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + virtual ForEachResult ForEach(ForEachAction, void *, bool); // at 0x1C + virtual bool Insert(u32, ScnObj *); // at 0x34 + virtual ScnObj *Remove(u32); // at 0x38 + virtual bool Remove(ScnObj *); // at 0x3C + + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + bool Empty() const { + return mSize == 0; + } + + u32 Size() const { + return mSize; + } + + ScnObj *PopBack() { + if (!Empty()) { + return Remove(Size() - 1); + } + + return NULL; + } + + void Clear() { + while (!Empty()) { + PopBack(); + } + } + + void ScnGroup_G3DPROC_GATHER_SCNOBJ(u32, IScnObjGather *); + void ScnGroup_G3DPROC_CALC_WORLD(u32, const math::MTX34 *); + void ScnGroup_G3DPROC_CALC_MAT(u32, void *); + void ScnGroup_G3DPROC_CALC_VIEW(u32, const math::MTX34 *); + void DefG3dProcScnGroup(u32, u32, void *); + + bool PushBack(ScnObj *); + + ScnObj **mObjects; // at 0xDC + u32 mCapacity; // at 0xE0 + u32 mSize; // at 0xE4 + +private: + NW4R_G3D_TYPE_OBJ_DECL(ScnGroup); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnproc.h b/include/nw4r/g3d/g3d_scnproc.h index 0f01d175..45aa86b6 100644 --- a/include/nw4r/g3d/g3d_scnproc.h +++ b/include/nw4r/g3d/g3d_scnproc.h @@ -1,78 +1,76 @@ #ifndef NW4R_G3D_SCNPROC_H #define NW4R_G3D_SCNPROC_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_scnobj.h" -namespace nw4r -{ - namespace g3d - { - class ScnProc : public ScnLeaf - { - public: - typedef void (* DrawProc)(ScnProc *, bool opa); +namespace nw4r { +namespace g3d { +class ScnProc : public ScnLeaf { +public: + typedef void (*DrawProc)(ScnProc *, bool opa); - ScnProc(MEMAllocator *allocator, DrawProc proc, void *userdata, bool set1, bool set2) - : ScnLeaf(allocator), mFlags(0), mDrawProc(proc), mUserData(userdata) - { - if (set1) mFlags |= 0x1; - if (set2) mFlags |= 0x2; - } - - static ScnProc * Construct(MEMAllocator *, u32 *, DrawProc, bool, bool, u32); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return other == GetTypeObjStatic() ? true - : ScnLeaf::IsDerivedFrom(other); - }; - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~ScnProc() {} // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - - static const G3dObj::TypeObj GetTypeObjStatic() { return TypeObj(TYPE_NAME); } - - void * GetUserData() { return mUserData; } - void SetUserData(void *data) { mUserData = data; } - - void SetDrawProc(DrawProc proc, bool r5, bool r6) - { - mDrawProc = proc; - - if (r5) - { - mFlags |= 0x1; - } - else - { - mFlags &= ~0x1; - } - - if (r6) - { - mFlags |= 0x2; - } - else - { - mFlags &= ~0x2; - } - } - - private: - u32 mFlags; // at 0xE8 - DrawProc mDrawProc; // at 0xEC - void *mUserData; // at 0xF0 - - NW4R_G3D_TYPE_OBJ_DECL(ScnProc); - }; + ScnProc(MEMAllocator *allocator, DrawProc proc, void *userdata, bool set1, bool set2) + : ScnLeaf(allocator), mFlags(0), mDrawProc(proc), mUserData(userdata) { + if (set1) { + mFlags |= 0x1; + } + if (set2) { + mFlags |= 0x2; + } } -} -#endif \ No newline at end of file + static ScnProc *Construct(MEMAllocator *, u32 *, DrawProc, bool, bool, u32); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 + { + return other == GetTypeObjStatic() ? true : ScnLeaf::IsDerivedFrom(other); + }; + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~ScnProc() {} // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); + } + + static const G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + + void *GetUserData() { + return mUserData; + } + void SetUserData(void *data) { + mUserData = data; + } + + void SetDrawProc(DrawProc proc, bool r5, bool r6) { + mDrawProc = proc; + + if (r5) { + mFlags |= 0x1; + } else { + mFlags &= ~0x1; + } + + if (r6) { + mFlags |= 0x2; + } else { + mFlags &= ~0x2; + } + } + +private: + u32 mFlags; // at 0xE8 + DrawProc mDrawProc; // at 0xEC + void *mUserData; // at 0xF0 + + NW4R_G3D_TYPE_OBJ_DECL(ScnProc); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnrfl.h b/include/nw4r/g3d/g3d_scnrfl.h index 2ccba439..cca91279 100644 --- a/include/nw4r/g3d/g3d_scnrfl.h +++ b/include/nw4r/g3d/g3d_scnrfl.h @@ -1,56 +1,51 @@ #ifndef NW4R_G3D_SCNRFL_H #define NW4R_G3D_SCNRFL_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_scnleaf.h" -#include #include +#include -namespace nw4r -{ - namespace g3d +namespace nw4r { +namespace g3d { +class ScnRfl : public ScnLeaf { +public: + struct RflData { + bool SetupCharModel(RFLDataSource, u16, RFLMiddleDB *); + }; + +public: + static ScnRfl *Construct(MEMAllocator *, u32 *, RFLResolution, u32, u32); + ScnRfl(MEMAllocator *, ScnRfl *, RflData *, void *, u32); + + virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 { - class ScnRfl : public ScnLeaf - { - public: - struct RflData - { - bool SetupCharModel(RFLDataSource, u16, RFLMiddleDB *); - }; - - public: - static ScnRfl * Construct(MEMAllocator *, u32 *, RFLResolution, u32, u32); - ScnRfl(MEMAllocator *, ScnRfl *, RflData *, void *, u32); - - virtual bool IsDerivedFrom(TypeObj other) const // at 0x8 - { - return (other == GetTypeObjStatic()); - } - virtual void G3dProc(u32, u32, void *); // at 0xC - virtual ~ScnRfl(); // at 0x10 - virtual const TypeObj GetTypeObj() const // at 0x14 - { - return TypeObj(TYPE_NAME); - } - virtual const char * GetTypeName() const // at 0x18 - { - return GetTypeObj().GetTypeName(); - } - - bool GetExpression(RFLExpression *); - bool SetExpression(RFLExpression); - - void SetFogIdx(int); - void SetLightSetIdx(int); - - static const nw4r::g3d::G3dObj::TypeObj GetTypeObjStatic() - { - return TypeObj(TYPE_NAME); - } - - private: - NW4R_G3D_TYPE_OBJ_DECL(ScnRfl); - }; + return (other == GetTypeObjStatic()); + } + virtual void G3dProc(u32, u32, void *); // at 0xC + virtual ~ScnRfl(); // at 0x10 + virtual const TypeObj GetTypeObj() const // at 0x14 + { + return TypeObj(TYPE_NAME); + } + virtual const char *GetTypeName() const // at 0x18 + { + return GetTypeObj().GetTypeName(); } -} -#endif \ No newline at end of file + bool GetExpression(RFLExpression *); + bool SetExpression(RFLExpression); + + void SetFogIdx(int); + void SetLightSetIdx(int); + + static const nw4r::g3d::G3dObj::TypeObj GetTypeObjStatic() { + return TypeObj(TYPE_NAME); + } + +private: + NW4R_G3D_TYPE_OBJ_DECL(ScnRfl); +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_scnroot.h b/include/nw4r/g3d/g3d_scnroot.h index 8c3fb797..bfd9a9b3 100644 --- a/include/nw4r/g3d/g3d_scnroot.h +++ b/include/nw4r/g3d/g3d_scnroot.h @@ -1,41 +1,40 @@ #ifndef NW4R_G3D_SCNROOT_H #define NW4R_G3D_SCNROOT_H -#include "types_nw4r.h" -#include "g3d_scnobj.h" +#include "common.h" #include "g3d_camera.h" #include "g3d_fog.h" +#include "g3d_scnobj.h" -namespace nw4r -{ - namespace g3d - { - class ScnRoot : public ScnGroup - { - public: - Camera GetCamera(int); - Camera GetCurrentCamera(); - void SetCurrentCamera(int); - Fog GetFog(int); +namespace nw4r { +namespace g3d { +class ScnRoot : public ScnGroup { +public: + Camera GetCamera(int); + Camera GetCurrentCamera(); + void SetCurrentCamera(int); + Fog GetFog(int); - void UpdateFrame(); - void CalcWorld(); - void CalcMaterial(); - void CalcVtx(); - void CalcView(); - void GatherDrawScnObj(); - void ZSort(); - void DrawOpa(); - void DrawXlu(); + void UpdateFrame(); + void CalcWorld(); + void CalcMaterial(); + void CalcVtx(); + void CalcView(); + void GatherDrawScnObj(); + void ZSort(); + void DrawOpa(); + void DrawXlu(); - u8 GetCurrentCameraID() const { return mCameraId; } - - private: - UNKWORD WORD_0xE8; - UNKWORD WORD_0xEC; - UNKWORD WORD_0xF0; - u8 mCameraId; - }; + u8 GetCurrentCameraID() const { + return mCameraId; } -} -#endif \ No newline at end of file +private: + UNKWORD WORD_0xE8; + UNKWORD WORD_0xEC; + UNKWORD WORD_0xF0; + u8 mCameraId; +}; +} // namespace g3d +} // namespace nw4r + +#endif diff --git a/include/nw4r/g3d/g3d_state.h b/include/nw4r/g3d/g3d_state.h index 5b7b87e8..0f16769f 100644 --- a/include/nw4r/g3d/g3d_state.h +++ b/include/nw4r/g3d/g3d_state.h @@ -1,6 +1,6 @@ #ifndef NW4R_G3D_STATE_H #define NW4R_G3D_STATE_H -#include "types_nw4r.h" +#include "common.h" #include namespace nw4r { diff --git a/include/nw4r/g3d/g3d_tmem.h b/include/nw4r/g3d/g3d_tmem.h index 749156de..6ab71c9b 100644 --- a/include/nw4r/g3d/g3d_tmem.h +++ b/include/nw4r/g3d/g3d_tmem.h @@ -1,22 +1,15 @@ #ifndef NW4R_G3D_TMEM_H #define NW4R_G3D_TMEM_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace g3d - { - namespace tmem - { - enum TMemLayout - { - TMEM_LAYOUT_0, - TMEM_LAYOUT_1 - }; +namespace nw4r { +namespace g3d { +namespace tmem { +enum TMemLayout { TMEM_LAYOUT_0, TMEM_LAYOUT_1 }; - void SetTMemLayout(TMemLayout); - } - } -} +void SetTMemLayout(TMemLayout); +} // namespace tmem +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_workmem.h b/include/nw4r/g3d/g3d_workmem.h index 3f0ca444..0a03d1f2 100644 --- a/include/nw4r/g3d/g3d_workmem.h +++ b/include/nw4r/g3d/g3d_workmem.h @@ -1,26 +1,22 @@ #ifndef NW4R_G3D_WORKMEM_H #define NW4R_G3D_WORKMEM_H -#include "types_nw4r.h" +#include "common.h" #define G3D_WORKMEM_SIZE 0x18000 -namespace nw4r -{ - namespace g3d - { - namespace detail - { - namespace workmem - { - void * GetScaleTemporary(); - void * GetMtxIDTemporary(); - void * GetMdlZTemporary(); - void * GetSkinningMtxTemporary(); - void * GetBillboardMtxTemporary(); - void * GetShpAnmResultBufTemporary(); - } - } - } -} +namespace nw4r { +namespace g3d { +namespace detail { +namespace workmem { +void *GetScaleTemporary(); +void *GetMtxIDTemporary(); +void *GetMdlZTemporary(); +void *GetSkinningMtxTemporary(); +void *GetBillboardMtxTemporary(); +void *GetShpAnmResultBufTemporary(); +} // namespace workmem +} // namespace detail +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/g3d/g3d_xsi.h b/include/nw4r/g3d/g3d_xsi.h index 939e6a19..fb812e49 100644 --- a/include/nw4r/g3d/g3d_xsi.h +++ b/include/nw4r/g3d/g3d_xsi.h @@ -1,20 +1,16 @@ #ifndef NW4R_G3D_XSI_H #define NW4R_G3D_XSI_H -#include "types_nw4r.h" +#include "common.h" #include "g3d_anmtexsrt.h" -namespace nw4r -{ - namespace g3d - { - namespace detail - { - namespace dcc - { - bool CalcTexMtx_Xsi(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); - } - } - } +namespace nw4r { +namespace g3d { +namespace detail { +namespace dcc { +bool CalcTexMtx_Xsi(math::MTX34 *, bool, const TexSrt &, TexSrt::Flag); } +} // namespace detail +} // namespace g3d +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_animation.h b/include/nw4r/lyt/lyt_animation.h index a9303e03..fd26da01 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -1,82 +1,69 @@ #ifndef NW4R_LYT_ANIMATION_H #define NW4R_LYT_ANIMATION_H -#include "types_nw4r.h" -#include "ut_LinkList.h" -#include "lyt_resourceAccessor.h" -#include "lyt_common.h" +#include "common.h" +#include "nw4r/lyt/lyt_common.h" +#include "nw4r/lyt/lyt_resourceAccessor.h" +#include "nw4r/ut/ut_LinkList.h" -namespace nw4r -{ - namespace lyt - { - namespace res - { - struct AnimationBlock - { - - }; - } +namespace nw4r { +namespace lyt { +namespace res { +struct AnimationBlock {}; +} // namespace res - struct AnimationBlock - { - res::DataBlockHeader header; // at 0x0 - u16 frameSize; // at 0x8 - bool loop; // at 0xA - // . . . - }; +struct AnimationBlock { + res::DataBlockHeader header; // at 0x0 + u16 frameSize; // at 0x8 + bool loop; // at 0xA + // . . . +}; - struct AnimTransform - { - inline AnimTransform() : mNode(), mResource(NULL), mFrame(0.0f) {} +struct AnimTransform { + inline AnimTransform() : mNode(), mResource(NULL), mFrame(0.0f) {} - u16 GetFrameSize() const; - bool IsLoopData() const; + u16 GetFrameSize() const; + bool IsLoopData() const; - ut::LinkListNode mNode; // at 0x0 - AnimationBlock *mResource; // at 0xC - f32 mFrame; // at 0x10 - }; + ut::LinkListNode mNode; // at 0x0 + AnimationBlock *mResource; // at 0xC + f32 mFrame; // at 0x10 +}; - struct AnimTransformBasic : AnimTransform - { - AnimTransformBasic(); - virtual ~AnimTransformBasic(); - virtual UNKTYPE SetResource(const res::AnimationBlock *, ResourceAccessor *); - virtual UNKTYPE Bind(Pane *, bool); - virtual UNKTYPE Bind(Material *); - virtual UNKTYPE Animate(u32, Pane *); - virtual UNKTYPE Animate(u32, Material *); +struct AnimTransformBasic : AnimTransform { + AnimTransformBasic(); + virtual ~AnimTransformBasic(); + virtual UNKTYPE SetResource(const res::AnimationBlock *, ResourceAccessor *); + virtual UNKTYPE Bind(Pane *, bool); + virtual UNKTYPE Bind(Material *); + virtual UNKTYPE Animate(u32, Pane *); + virtual UNKTYPE Animate(u32, Material *); - u32 INT_0x14; - u32 INT_0x18; - u16 INT_0x1C; - }; + u32 INT_0x14; + u32 INT_0x18; + u16 INT_0x1C; +}; - struct AnimationLink - { - inline AnimationLink() : mNode() - { - Reset(); - } - - inline void Reset() - { - Set(NULL, 0, false); - } - - inline void Set(AnimTransform *pTransform, u16 us, bool b) - { - mTransform = pTransform; - SHORT_0xC = us; - BOOL_0xE = b; - } - - ut::LinkListNode mNode; // at 0x0 - AnimTransform *mTransform; // at 0x8 - u16 SHORT_0xC; - bool BOOL_0xE; - }; +struct AnimationLink { + inline AnimationLink() : mNode() { + Reset(); } -} -#endif \ No newline at end of file + inline void Reset() { + Set(NULL, 0, false); + } + + inline void Set(AnimTransform *pTransform, u16 us, bool b) { + mTransform = pTransform; + SHORT_0xC = us; + BOOL_0xE = b; + } + + ut::LinkListNode mNode; // at 0x0 + AnimTransform *mTransform; // at 0x8 + u16 SHORT_0xC; + bool BOOL_0xE; +}; +} // namespace lyt +} // namespace nw4r + +#endif diff --git a/include/nw4r/lyt/lyt_arcResourceAccessor.h b/include/nw4r/lyt/lyt_arcResourceAccessor.h index 7c5e86ae..505639b2 100644 --- a/include/nw4r/lyt/lyt_arcResourceAccessor.h +++ b/include/nw4r/lyt/lyt_arcResourceAccessor.h @@ -1,13 +1,12 @@ #ifndef NW4R_LYT_ARC_RESOURCE_ACCESSOR_H #define NW4R_LYT_ARC_RESOURCE_ACCESSOR_H +#include "common.h" #include "lyt_resourceAccessor.h" -#include "types_nw4r.h" -#include "ut_Font.h" -#include "ut_LinkList.h" +#include "nw4r/ut/ut_Font.h" +#include "nw4r/ut/ut_LinkList.h" #include #include - #define FONTNAMEBUF_MAX 127 namespace nw4r { diff --git a/include/nw4r/lyt/lyt_bounding.h b/include/nw4r/lyt/lyt_bounding.h index 7dcc2013..56740463 100644 --- a/include/nw4r/lyt/lyt_bounding.h +++ b/include/nw4r/lyt/lyt_bounding.h @@ -1,36 +1,26 @@ #ifndef NW4R_LYT_BOUNDING_H #define NW4R_LYT_BOUNDING_H -#include "types_nw4r.h" -#include "lyt_pane.h" -#include "lyt_drawInfo.h" +#include "common.h" +#include "nw4r/lyt/lyt_drawInfo.h" +#include "nw4r/lyt/lyt_pane.h" -namespace nw4r -{ - namespace lyt - { - namespace res - { - struct Bounding : Pane - { +namespace nw4r { +namespace lyt { +namespace res { +struct Bounding : Pane {}; +} // namespace res - }; - } +struct ResBlockSet {}; - struct ResBlockSet - { +struct Bounding : Pane { + Bounding(const res::Bounding *, const ResBlockSet &); + virtual ~Bounding(); + virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; + virtual void DrawSelf(const DrawInfo &); - }; + static ut::detail::RuntimeTypeInfo typeInfo; +}; +} // namespace lyt +} // namespace nw4r - struct Bounding : Pane - { - Bounding(const res::Bounding *, const ResBlockSet&); - virtual ~Bounding(); - virtual const ut::detail::RuntimeTypeInfo * GetRuntimeTypeInfo() const; - virtual void DrawSelf(const DrawInfo&); - - static ut::detail::RuntimeTypeInfo typeInfo; - }; - } -} - -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index af80950b..7b488f63 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -1,60 +1,53 @@ #ifndef NW4R_LYT_COMMON_H #define NW4R_LYT_COMMON_H -#include "types_nw4r.h" -#include "math_types.h" -#include "ut_binaryFileFormat.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 -namespace nw4r -{ - namespace lyt - { - namespace res - { - struct BinaryFileHeader : ut::BinaryFileHeader - { +namespace nw4r { +namespace lyt { +namespace res { +struct BinaryFileHeader : ut::BinaryFileHeader {}; - }; +struct DataBlockHeader { + u32 kind; // at 0x0 + u32 size; // at 0x4 +}; +} // namespace res - struct DataBlockHeader { - u32 kind; // at 0x0 - u32 size; // at 0x4 - }; - } +namespace detail { +typedef math::VEC2 TexCoordData[TEXCOORD_VTX_COUNT]; - namespace detail - { - typedef math::VEC2 TexCoordData[TEXCOORD_VTX_COUNT]; - - struct TexCoordAry - { - TexCoordAry(); - void Free(); - void Reserve(u8); - void SetSize(u8); - void Copy(const void *, u8); +struct TexCoordAry { + TexCoordAry(); + void Free(); + void Reserve(u8); + void SetSize(u8); + void Copy(const void *, u8); - u8 mCap; // at 0x0 - u8 mSize; // at 0x1 - TexCoordData *mTexCoords; // at 0x4 - }; + u8 mCap; // at 0x0 + u8 mNum; // at 0x1 + TexCoordData *mpData; // at 0x4 +}; - bool EqualsResName(const char *, const char *); - bool EqualsMaterialName(const char *, const char *); - bool TestFileHeader(const res::BinaryFileHeader&); - bool TestFileHeader(const res::BinaryFileHeader&, u32); - bool IsModulateVertexColor(ut::Color *, u8); - void MultipleAlpha(ut::Color *, const ut::Color *, u8); // Inlined - ut::Color MultipleAlpha(ut::Color, u8); - void SetVertexFormat(bool, u8); - void DrawQuad(const math::VEC2&, const Size&, u8, const TexCoordData *, const ut::Color *); - void DrawQuad(const math::VEC2&, const Size&, u8, const TexCoordData *, const ut::Color *, u8); - } - } -} +bool EqualsResName(const char *, const char *); +bool EqualsMaterialName(const char *, const char *); +bool TestFileHeader(const res::BinaryFileHeader &); +bool TestFileHeader(const res::BinaryFileHeader &, u32); +bool IsModulateVertexColor(ut::Color *, u8); +void MultipleAlpha(ut::Color *, const ut::Color *, u8); // Inlined +ut::Color MultipleAlpha(ut::Color, u8); +void SetVertexFormat(bool, u8); +void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const ut::Color *); +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); +} // namespace detail +} // namespace lyt +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_drawInfo.h b/include/nw4r/lyt/lyt_drawInfo.h index 8aab5fcc..636a1b4e 100644 --- a/include/nw4r/lyt/lyt_drawInfo.h +++ b/include/nw4r/lyt/lyt_drawInfo.h @@ -1,25 +1,22 @@ #ifndef NW4R_LYT_DRAWINFO_H #define NW4R_LYT_DRAWINFO_H -#include "types_nw4r.h" -#include "math_types.h" -#include "ut_Rect.h" +#include "common.h" +#include "nw4r/math/math_types.h" +#include "nw4r/ut/ut_Rect.h" -namespace nw4r -{ - namespace lyt - { - struct DrawInfo - { - virtual ~DrawInfo(); - DrawInfo(); +namespace nw4r { +namespace lyt { +struct DrawInfo { + virtual ~DrawInfo(); + DrawInfo(); - math::MTX34 mViewMtx; // at 0x0 - ut::Rect mViewRect; // at 0x34 - math::VEC2 mScale; // at 0x44 - f32 mGlobalAlpha; // at 0x48 - u8 mFlags; // at 0x50 - }; - } -} + math::MTX34 mViewMtx; // at 0x0 + ut::Rect mViewRect; // at 0x34 + math::VEC2 mScale; // at 0x44 + f32 mGlobalAlpha; // at 0x48 + u8 mFlags; // at 0x50 +}; +} // namespace lyt +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_group.h b/include/nw4r/lyt/lyt_group.h index efe17ac0..b12a8665 100644 --- a/include/nw4r/lyt/lyt_group.h +++ b/include/nw4r/lyt/lyt_group.h @@ -1,55 +1,47 @@ #ifndef NW4R_LYT_GROUP_H #define NW4R_LYT_GROUP_H -#include "types_nw4r.h" -#include "lyt_pane.h" -#include "lyt_common.h" -#include "ut_LinkList.h" +#include "common.h" +#include "nw4r/lyt/lyt_common.h" +#include "nw4r/lyt/lyt_pane.h" +#include "nw4r/ut/ut_LinkList.h" -namespace nw4r -{ - namespace lyt - { - namespace res - { - struct Group - { - char UNK_0x0[0x8]; - char mName[NW4R_RES_NAME_SIZE]; // at 0x8 - u16 SHORT_0x18; - }; - } +namespace nw4r { +namespace lyt { +namespace res { +struct Group { + char UNK_0x0[0x8]; + char mName[NW4R_RES_NAME_SIZE]; // at 0x8 + u16 SHORT_0x18; +}; +} // namespace res - namespace detail - { - struct PaneLink - { - ut::LinkListNode mNode; // at 0x0 - Pane *PANE_0x8; - }; - } +namespace detail { +struct PaneLink { + ut::LinkListNode mNode; // at 0x0 + Pane *PANE_0x8; +}; +} // namespace detail - struct Group - { - Group(const res::Group *, Pane *); - virtual ~Group(); - void AppendPane(Pane *); - void Init(); +struct Group { + Group(const res::Group *, Pane *); + virtual ~Group(); + void AppendPane(Pane *); + void Init(); - ut::LinkListNode mNode; // at 0x4 - ut::LinkList mPaneList; // at 0xC - char mName[NW4R_RES_NAME_SIZE]; // at 0x18 - bool mIsUserAllocated; // at 0x29 - }; + ut::LinkListNode mNode; // at 0x4 + ut::LinkList mPaneList; // at 0xC + char mName[NW4R_RES_NAME_SIZE]; // at 0x18 + bool mIsUserAllocated; // at 0x29 +}; - struct GroupContainer - { - ~GroupContainer(); - void AppendGroup(Group *); - Group * FindGroupByName(const char *); +struct GroupContainer { + ~GroupContainer(); + void AppendGroup(Group *); + Group *FindGroupByName(const char *); - ut::LinkList mGroups; // at 0x4 - }; - } -} + ut::LinkList mGroups; // at 0x4 +}; +} // namespace lyt +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 6f052a0b..156e13f3 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -1,7 +1,7 @@ #ifndef NW4R_LYT_LAYOUT_H #define NW4R_LYT_LAYOUT_H -#include "types_nw4r.h" -#include +#include "common.h" +#include #include namespace nw4r { @@ -19,11 +19,13 @@ struct Layout { template static void DeleteArray(T *p, size_t n) { - for (size_t i = 0; i < n; i++) { - p[i].~T(); - } + if (p) { + for (size_t i = 0; i < n; i++) { + p[i].~T(); + } - FreeMemory(p); + FreeMemory(p); + } } template diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index 4b2e76ac..fec6d500 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -1,10 +1,9 @@ #ifndef NW4R_LYT_MATERIAL_H #define NW4R_LYT_MATERIAL_H -#include "lyt_animation.h" -#include "ut_LinkList.h" +#include "nw4r/lyt/lyt_animation.h" +#include "nw4r/ut/ut_LinkList.h" #include - namespace nw4r { namespace lyt { // TO-DO diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index 28acbb6d..b31f2ccb 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -1,157 +1,139 @@ #ifndef NW4R_LYT_PANE_H #define NW4R_LYT_PANE_H -#include "types_nw4r.h" -#include "math_types.h" -#include "ut_LinkList.h" -#include "ut_RuntimeTypeInfo.h" -#include "ut_Color.h" -#include "ut_algorithm.h" -#include "lyt_animation.h" -#include +#include "common.h" +#include "nw4r/lyt/lyt_animation.h" +#include "nw4r/math/math_types.h" +#include "nw4r/ut/ut_Color.h" +#include "nw4r/ut/ut_LinkList.h" +#include "nw4r/ut/ut_RuntimeTypeInfo.h" +#include "nw4r/ut/ut_algorithm.h" +#include #define PANE_NAME_SIZE 17 #define PANE_USERDATA_SIZE 9 #define ANIMTARGET_PANE_MAX 10 -namespace nw4r -{ - namespace lyt - { - void LytInit(); +namespace nw4r { +namespace lyt { +void LytInit(); - struct Size - { - inline Size() : x(), y() {} +struct Size { + inline Size() : x(), y() {} - inline Size& operator=(const Size& rhs) - { - x = rhs.x; - y = rhs.y; - return *this; - } - - f32 x, y; - }; - - namespace detail - { - struct PaneBase - { - inline PaneBase() : mNode() {} - - virtual ~PaneBase(); - ut::LinkListNode mNode; // at 0x4 - }; - } - - namespace res - { - struct Pane - { - u32 mMagic; // "pan1", at 0x0 - u32 mLength; // at 0x4 - u8 BYTE_0x8; - u8 BYTE_0x9; - u8 BYTE_0xA; - u8 BYTE_0xB; // NO REFERENCES - char mName[PANE_NAME_SIZE]; // at 0xC - char mUserData[PANE_USERDATA_SIZE]; // at 0x1C - math::VEC3 VEC3_0x24; - math::VEC3 VEC3_0x30; - math::VEC2 VEC2_0x3C; - Size mSize; // at 0x44 - }; - } - - struct Pane : detail::PaneBase - { - // For use with TestBit - enum PaneBits - { - VISIBLE, - INFLUENCED_ALPHA, - LOCATION_ADJUST - }; - - inline void Init() - { - mParent = NULL; - mMaterial = NULL; - BYTE_0xD6 = 0; - INT_0xB4 = 0; - } - - inline void SetName(const char *pName) - { - strncpy(mName, pName, PANE_NAME_SIZE); - mName[PANE_NAME_SIZE - 1] = '\0'; - } - - inline void SetUserData(const char *pData) - { - strncpy(mUserData, pData, PANE_USERDATA_SIZE); - mUserData[PANE_USERDATA_SIZE - 1] = '\0'; - } - - inline void InsertChild(ut::LinkList::Iterator iter, lyt::Pane *pChild) - { - mChildren.Insert(iter, pChild); - pChild->mParent = this; - } - - Pane(const res::Pane *); - virtual ~Pane(); // at 0x8 - virtual const ut::detail::RuntimeTypeInfo * GetRuntimeTypeInfo() const; // at 0xC - virtual UNKTYPE CalculateMtx(const DrawInfo&); // at 0x10 - virtual UNKTYPE Draw(const DrawInfo&); // at 0x14 - virtual void DrawSelf(const DrawInfo&); // at 0x18 - virtual UNKTYPE Animate(u32); // at 0x1C - virtual UNKTYPE AnimateSelf(u32); // at 0x20 - virtual ut::Color GetVtxColor(u32) const; // at 0x24 - virtual void SetVtxColor(u32, ut::Color); // at 0x28 - virtual UNKTYPE GetColorElement(u32) const; // at 0x2C - virtual UNKTYPE SetColorElement(u32, u8); // at 0x30 - virtual u8 GetVtxColorElement(u32) const; // at 0x34 - virtual void SetVtxColorElement(u32, u8); // at 0x38 - virtual Pane * FindPaneByName(const char *, bool); // at 0x3C - virtual UNKTYPE FindMaterialByName(const char *, bool); // at 0x40 - virtual UNKTYPE BindAnimation(AnimTransform *, bool); // at 0x44 - virtual UNKTYPE UnbindAnimation(AnimTransform *, bool); // at 0x48 - virtual UNKTYPE UnbindAllAnimation(bool); // at 0x4C - virtual UNKTYPE UnbindAnimationSelf(AnimTransform *); // at 0x50 - virtual UNKTYPE FindAnimationLink(AnimTransform *); // at 0x54 - virtual UNKTYPE SetAnimationEnable(AnimTransform *, bool, bool); // at 0x58 - virtual UNKTYPE GetMaterial() const; // at 0x5C - virtual UNKTYPE LoadMtx(const DrawInfo&); // at 0x60 - void AppendChild(Pane *); - void RemoveChild(Pane *); - UNKTYPE GetPaneRect(const DrawInfo&) const; - UNKTYPE AddAnimationLink(AnimationLink *); - UNKTYPE GetVtxPos() const; - - ut::LinkListNode mNode; // at 0x4 - Pane *mParent; // at 0x8 - ut::LinkList mChildren; // at 0x14 - ut::LinkList mAnims; // at 0x20; - Material *mMaterial; // at 0x2C - math::VEC3 mTranslate; // at 0x30 - math::VEC3 VEC3_0x3C; - math::VEC2 mScale; // at 0x48 - Size mSize; // at 0x50 - math::MTX34 MTX34_0x58; - math::MTX34 mGlobalMtx; // at 0x84 - int INT_0xB4; - u8 mAlpha; // at 0xB8 - u8 BYTE_0xB9; - u8 BYTE_0xBA; - u8 mFlags; // at 0xBB - char mName[PANE_NAME_SIZE]; // at 0xBC - char mUserData[PANE_USERDATA_SIZE]; // at 0xCD - u8 BYTE_0xD6; - - static ut::detail::RuntimeTypeInfo typeInfo; - }; + inline Size &operator=(const Size &rhs) { + x = rhs.x; + y = rhs.y; + return *this; } -} -#endif \ No newline at end of file + f32 x, y; +}; + +namespace detail { +struct PaneBase { + inline PaneBase() : mNode() {} + + virtual ~PaneBase(); + ut::LinkListNode mNode; // at 0x4 +}; +} // namespace detail + +namespace res { +struct Pane { + u32 mMagic; // "pan1", at 0x0 + u32 mLength; // at 0x4 + u8 BYTE_0x8; + u8 BYTE_0x9; + u8 BYTE_0xA; + u8 BYTE_0xB; // NO REFERENCES + char mName[PANE_NAME_SIZE]; // at 0xC + char mUserData[PANE_USERDATA_SIZE]; // at 0x1C + math::VEC3 VEC3_0x24; + math::VEC3 VEC3_0x30; + math::VEC2 VEC2_0x3C; + Size mSize; // at 0x44 +}; +} // namespace res + +struct Pane : detail::PaneBase { + // For use with TestBit + enum PaneBits { VISIBLE, INFLUENCED_ALPHA, LOCATION_ADJUST }; + + inline void Init() { + mParent = NULL; + mMaterial = NULL; + BYTE_0xD6 = 0; + INT_0xB4 = 0; + } + + inline void SetName(const char *pName) { + strncpy(mName, pName, PANE_NAME_SIZE); + mName[PANE_NAME_SIZE - 1] = '\0'; + } + + inline void SetUserData(const char *pData) { + strncpy(mUserData, pData, PANE_USERDATA_SIZE); + mUserData[PANE_USERDATA_SIZE - 1] = '\0'; + } + + inline void InsertChild(ut::LinkList::Iterator iter, lyt::Pane *pChild) { + mChildren.Insert(iter, pChild); + pChild->mParent = this; + } + + Pane(const res::Pane *); + virtual ~Pane(); // at 0x8 + virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; // at 0xC + virtual UNKTYPE CalculateMtx(const DrawInfo &); // at 0x10 + virtual UNKTYPE Draw(const DrawInfo &); // at 0x14 + virtual void DrawSelf(const DrawInfo &); // at 0x18 + virtual UNKTYPE Animate(u32); // at 0x1C + virtual UNKTYPE AnimateSelf(u32); // at 0x20 + virtual ut::Color GetVtxColor(u32) const; // at 0x24 + virtual void SetVtxColor(u32, ut::Color); // at 0x28 + virtual UNKTYPE GetColorElement(u32) const; // at 0x2C + virtual UNKTYPE SetColorElement(u32, u8); // at 0x30 + virtual u8 GetVtxColorElement(u32) const; // at 0x34 + virtual void SetVtxColorElement(u32, u8); // at 0x38 + virtual Pane *FindPaneByName(const char *, bool); // at 0x3C + virtual UNKTYPE FindMaterialByName(const char *, bool); // at 0x40 + virtual UNKTYPE BindAnimation(AnimTransform *, bool); // at 0x44 + virtual UNKTYPE UnbindAnimation(AnimTransform *, bool); // at 0x48 + virtual UNKTYPE UnbindAllAnimation(bool); // at 0x4C + virtual UNKTYPE UnbindAnimationSelf(AnimTransform *); // at 0x50 + virtual UNKTYPE FindAnimationLink(AnimTransform *); // at 0x54 + virtual UNKTYPE SetAnimationEnable(AnimTransform *, bool, bool); // at 0x58 + virtual UNKTYPE GetMaterial() const; // at 0x5C + virtual UNKTYPE LoadMtx(const DrawInfo &); // at 0x60 + void AppendChild(Pane *); + void RemoveChild(Pane *); + UNKTYPE GetPaneRect(const DrawInfo &) const; + UNKTYPE AddAnimationLink(AnimationLink *); + UNKTYPE GetVtxPos() const; + + ut::LinkListNode mNode; // at 0x4 + Pane *mParent; // at 0x8 + ut::LinkList mChildren; // at 0x14 + ut::LinkList mAnims; // at 0x20; + Material *mMaterial; // at 0x2C + math::VEC3 mTranslate; // at 0x30 + math::VEC3 VEC3_0x3C; + math::VEC2 mScale; // at 0x48 + Size mSize; // at 0x50 + math::MTX34 MTX34_0x58; + math::MTX34 mGlobalMtx; // at 0x84 + int INT_0xB4; + u8 mAlpha; // at 0xB8 + u8 BYTE_0xB9; + u8 BYTE_0xBA; + u8 mFlags; // at 0xBB + char mName[PANE_NAME_SIZE]; // at 0xBC + char mUserData[PANE_USERDATA_SIZE]; // at 0xCD + u8 BYTE_0xD6; + + static ut::detail::RuntimeTypeInfo typeInfo; +}; +} // namespace lyt +} // namespace nw4r + +#endif diff --git a/include/nw4r/lyt/lyt_resourceAccessor.h b/include/nw4r/lyt/lyt_resourceAccessor.h index d8a10c8a..99e48765 100644 --- a/include/nw4r/lyt/lyt_resourceAccessor.h +++ b/include/nw4r/lyt/lyt_resourceAccessor.h @@ -1,21 +1,18 @@ #ifndef NW4R_LYT_RESOURCE_ACCESSOR_H #define NW4R_LYT_RESOURCE_ACCESSOR_H -#include "types_nw4r.h" -#include "ut_Font.h" +#include "common.h" +#include "nw4r/ut/ut_Font.h" -namespace nw4r -{ - namespace lyt - { - class ResourceAccessor - { - public: - ResourceAccessor(); - virtual ~ResourceAccessor(); // at 0x8 - virtual UNKTYPE * GetResource(u32, const char *, u32 *) = 0; // at 0xC - virtual ut::Font * GetFont(const char *); // at 0x10 - }; - } -} +namespace nw4r { +namespace lyt { +class ResourceAccessor { +public: + ResourceAccessor(); + virtual ~ResourceAccessor(); // at 0x8 + virtual UNKTYPE *GetResource(u32, const char *, u32 *) = 0; // at 0xC + virtual ut::Font *GetFont(const char *); // at 0x10 +}; +} // namespace lyt +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/lyt/lyt_texMap.h b/include/nw4r/lyt/lyt_texMap.h index e685602b..a277fa92 100644 --- a/include/nw4r/lyt/lyt_texMap.h +++ b/include/nw4r/lyt/lyt_texMap.h @@ -1,6 +1,6 @@ #ifndef NW4R_LYT_TEXMAP_H #define NW4R_LYT_TEXMAP_H -#include "types_nw4r.h" +#include "common.h" #include #include diff --git a/include/nw4r/snd/snd_BankFile.h b/include/nw4r/snd/snd_BankFile.h index 9286704f..b7bfacc1 100644 --- a/include/nw4r/snd/snd_BankFile.h +++ b/include/nw4r/snd/snd_BankFile.h @@ -1,102 +1,90 @@ #ifndef NW4R_SND_BANK_FILE_H #define NW4R_SND_BANK_FILE_H -#include "types_nw4r.h" -#include "ut_binaryFileFormat.h" -#include "ut_algorithm.h" +#include "common.h" #include "snd_Util.h" #include "snd_WaveFile.h" +#include "ut_algorithm.h" +#include "ut_binaryFileFormat.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct InstInfo - { - int WORD_0x0; - u8 mAttack; // at 0x4 - u8 mDecay; // at 0x5 - u8 mSustain; // at 0x6 - u8 mRelease; // at 0x7 - - u8 BYTE_0x8; - u8 BYTE_0x9; - u8 BYTE_0xA; - float FLOAT_0xC; - }; - - struct BankFile - { - struct InstParam - { - int WORD_0x0; - u8 mAttack; // at 0x4 - u8 mDecay; // at 0x5 - u8 mSustain; // at 0x6 - u8 mRelease; // at 0x7 - - char UNK_0x8[0x4]; - - char BYTE_0xC; - u8 BYTE_0xD; - char BYTE_0xE; - float FLOAT_0x10; - }; - - struct RangeTable - { - u8 BYTE_0x0; - u8 BYTES_0x1[]; - }; - - struct IndexTable - { - u8 BYTE_0x0; - u8 BYTE_0x1; - }; - - ut::BinaryFileHeader mHeader; // at 0x0 - u32 OFFSET_0x10; - char UNK_0x14[0x4]; - u32 OFFSET_0x18; - - typedef Util::DataRef Region; - }; - - struct BankFileReader - { - struct UNKBLOCK_DATA - { - ut::BinaryBlockHeader mHeader; // at 0x0 - int INT_0x8; - BankFile::Region ARR_0xC[]; - }; - - struct UNKBLOCK_WAVE - { - ut::BinaryBlockHeader mHeader; // at 0x0 - u32 INT_0x8; - WaveFile::Region ARR_0xC[]; - }; - - bool IsValidFileHeader(const void *); - BankFileReader(const void *); - bool ReadInstInfo(InstInfo *, int, int, int) const; - const BankFile::Region * GetReferenceToSubRegion(const BankFile::Region *, int) const; - bool ReadWaveParam(WaveData *, int, const void *) const; - - const BankFile * mFile; // at 0x0 - const UNKBLOCK_DATA * PTR_0x4; - const UNKBLOCK_WAVE * PTR_0x8; - }; - - inline u8 ReadByte(const void * ptr) - { - return *static_cast(ptr); - } - } - } +namespace nw4r { +namespace snd { +namespace detail { +struct InstInfo { + int WORD_0x0; + u8 mAttack; // at 0x4 + u8 mDecay; // at 0x5 + u8 mSustain; // at 0x6 + u8 mRelease; // at 0x7 + + u8 BYTE_0x8; + u8 BYTE_0x9; + u8 BYTE_0xA; + float FLOAT_0xC; +}; + +struct BankFile { + struct InstParam { + int WORD_0x0; + u8 mAttack; // at 0x4 + u8 mDecay; // at 0x5 + u8 mSustain; // at 0x6 + u8 mRelease; // at 0x7 + + char UNK_0x8[0x4]; + + char BYTE_0xC; + u8 BYTE_0xD; + char BYTE_0xE; + float FLOAT_0x10; + }; + + struct RangeTable { + u8 BYTE_0x0; + u8 BYTES_0x1[]; + }; + + struct IndexTable { + u8 BYTE_0x0; + u8 BYTE_0x1; + }; + + ut::BinaryFileHeader mHeader; // at 0x0 + u32 OFFSET_0x10; + char UNK_0x14[0x4]; + u32 OFFSET_0x18; + + typedef Util::DataRef Region; +}; + +struct BankFileReader { + struct UNKBLOCK_DATA { + ut::BinaryBlockHeader mHeader; // at 0x0 + int INT_0x8; + BankFile::Region ARR_0xC[]; + }; + + struct UNKBLOCK_WAVE { + ut::BinaryBlockHeader mHeader; // at 0x0 + u32 INT_0x8; + WaveFile::Region ARR_0xC[]; + }; + + bool IsValidFileHeader(const void *); + BankFileReader(const void *); + bool ReadInstInfo(InstInfo *, int, int, int) const; + const BankFile::Region *GetReferenceToSubRegion(const BankFile::Region *, int) const; + bool ReadWaveParam(WaveData *, int, const void *) const; + + const BankFile *mFile; // at 0x0 + const UNKBLOCK_DATA *PTR_0x4; + const UNKBLOCK_WAVE *PTR_0x8; +}; + +inline u8 ReadByte(const void *ptr) { + return *static_cast(ptr); } +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_Channel.h b/include/nw4r/snd/snd_Channel.h index 47fc74b2..ce5c8e35 100644 --- a/include/nw4r/snd/snd_Channel.h +++ b/include/nw4r/snd/snd_Channel.h @@ -1,161 +1,145 @@ #ifndef NW4R_SND_CHANNEL_H #define NW4R_SND_CHANNEL_H -#include "types_nw4r.h" -#include "ut_LinkList.h" -#include "snd_Voice.h" -#include "snd_Lfo.h" -#include "snd_InstancePool.h" -#include "snd_WaveFile.h" +#include "common.h" #include "snd_EnvGenerator.h" +#include "snd_InstancePool.h" +#include "snd_Lfo.h" #include "snd_MoveValue.h" +#include "snd_Voice.h" +#include "snd_WaveFile.h" +#include "ut_LinkList.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct Channel - { - enum ChannelCallbackStatus - { - CALLBACK_STATUS_0, - CALLBACK_STATUS_1, - CALLBACK_STATUS_2, - CALLBACK_STATUS_3 - }; - - typedef void (* ChannelCallback)(Channel *, ChannelCallbackStatus, u32); - - static void VoiceCallbackFunc(Voice *, Voice::VoiceCallbackStatus, void *); - - static Channel * AllocChannel(int, int, int, ChannelCallback, u32); - static void FreeChannel(Channel *); - Channel(); - - UNKTYPE InitParam(ChannelCallback, u32); - void Update(bool); - UNKTYPE Start(const WaveData &, int, u32); - UNKTYPE Release(); - UNKTYPE Stop(); - - float GetSweepValue() const; - void UpdateSweep(int); - void SetSweepParam(float, int, bool); - - EnvGenerator mEnvGenerator; // at 0x0 - Lfo mLfo; // at 0x18 - u8 BYTE_0x30; - bool mPauseFlag; // at 0x31 - bool mActiveFlag; // at 0x32 - bool BOOL_0x33; - bool mAutoUpdateSweepFlag; // at 0x34 - bool mReleasePriorityFixFlag; // at 0x35 - - float FLOAT_0x38; - float FLOAT_0x3C; - float FLOAT_0x40; - float FLOAT_0x44; - float FLOAT_0x48; - - int mRemoteFilter; // at 0x4c - int mOutputLine; // at 0x50 - - float FLOAT_0x54; - float FLOAT_0x58; - - float ARR_0x5C[3]; - - float mRemoteOutVolumes[4]; // at 0x68 - float ARR_0x78[4]; - float ARR_0x88[4]; - - float FLOAT_0x98; - float FLOAT_0x9C; - - int INT_0xA0; - int INT_0xA4; - - float FLOAT_0xA8; - float FLOAT_0xAC; - float FLOAT_0xB0; - float FLOAT_0xB4; - MoveValue MV_0xB8; - UNKWORD INT_0xC0; - UNKWORD INT_0xC4; - int mLength; // at 0xc8 - - PanMode mPanMode; // at 0xcc - PanCurve mPanCurve; // at 0xd0 - - ChannelCallback mCallback; // at 0xd4 - u32 INT_0xD8; - Voice * mVoice; // at 0xdc - Channel * mNext; // at 0xe0 - ut::LinkListNode mNode; // at 0xe4 - - inline bool IsActive() const - { - return mActiveFlag; - } - - inline void SetRelease(int release) - { - if (release >= 0) mEnvGenerator.SetRelease(release); - - Release(); - } - - inline bool IsAutoUpdateSweep() const - { - return mAutoUpdateSweepFlag; - } - - inline bool IsPause() const - { - return mPauseFlag; - } - - inline void Pause(bool flag) - { - mPauseFlag = flag; - - mVoice->Pause(flag); - } - - inline void SetLfoParam(const LfoParam & lfoParam) - { - mLfo.SetParam(lfoParam); - } - - inline void SetSilence(bool silentFlag, int time) - { - MV_0xB8.SetTarget(silentFlag ? 0 : 0xFF, time); - } - }; - - struct ChannelManager - { - ChannelManager(); - - u32 GetRequiredMemSize(); - void Setup(void *, u32); - void Shutdown(); - UNKTYPE UpdateAllChannel(); - static void Free(Channel *); //inlined - Channel * Alloc(); // inlined - static ChannelManager * GetInstance(); - - InstancePool mPool; // at 0x0 - ut::LinkList mList; // at 0x4 - - bool BOOL_0x10; - u32 INT_0x14; - UNKTYPE * PTR_0x18; - u32 INT_0x1C; - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct Channel { + enum ChannelCallbackStatus { CALLBACK_STATUS_0, CALLBACK_STATUS_1, CALLBACK_STATUS_2, CALLBACK_STATUS_3 }; -#endif \ No newline at end of file + typedef void (*ChannelCallback)(Channel *, ChannelCallbackStatus, u32); + + static void VoiceCallbackFunc(Voice *, Voice::VoiceCallbackStatus, void *); + + static Channel *AllocChannel(int, int, int, ChannelCallback, u32); + static void FreeChannel(Channel *); + Channel(); + + UNKTYPE InitParam(ChannelCallback, u32); + void Update(bool); + UNKTYPE Start(const WaveData &, int, u32); + UNKTYPE Release(); + UNKTYPE Stop(); + + float GetSweepValue() const; + void UpdateSweep(int); + void SetSweepParam(float, int, bool); + + EnvGenerator mEnvGenerator; // at 0x0 + Lfo mLfo; // at 0x18 + u8 BYTE_0x30; + bool mPauseFlag; // at 0x31 + bool mActiveFlag; // at 0x32 + bool BOOL_0x33; + bool mAutoUpdateSweepFlag; // at 0x34 + bool mReleasePriorityFixFlag; // at 0x35 + + float FLOAT_0x38; + float FLOAT_0x3C; + float FLOAT_0x40; + float FLOAT_0x44; + float FLOAT_0x48; + + int mRemoteFilter; // at 0x4c + int mOutputLine; // at 0x50 + + float FLOAT_0x54; + float FLOAT_0x58; + + float ARR_0x5C[3]; + + float mRemoteOutVolumes[4]; // at 0x68 + float ARR_0x78[4]; + float ARR_0x88[4]; + + float FLOAT_0x98; + float FLOAT_0x9C; + + int INT_0xA0; + int INT_0xA4; + + float FLOAT_0xA8; + float FLOAT_0xAC; + float FLOAT_0xB0; + float FLOAT_0xB4; + MoveValue MV_0xB8; + UNKWORD INT_0xC0; + UNKWORD INT_0xC4; + int mLength; // at 0xc8 + + PanMode mPanMode; // at 0xcc + PanCurve mPanCurve; // at 0xd0 + + ChannelCallback mCallback; // at 0xd4 + u32 INT_0xD8; + Voice *mVoice; // at 0xdc + Channel *mNext; // at 0xe0 + ut::LinkListNode mNode; // at 0xe4 + + inline bool IsActive() const { + return mActiveFlag; + } + + inline void SetRelease(int release) { + if (release >= 0) { + mEnvGenerator.SetRelease(release); + } + + Release(); + } + + inline bool IsAutoUpdateSweep() const { + return mAutoUpdateSweepFlag; + } + + inline bool IsPause() const { + return mPauseFlag; + } + + inline void Pause(bool flag) { + mPauseFlag = flag; + + mVoice->Pause(flag); + } + + inline void SetLfoParam(const LfoParam &lfoParam) { + mLfo.SetParam(lfoParam); + } + + inline void SetSilence(bool silentFlag, int time) { + MV_0xB8.SetTarget(silentFlag ? 0 : 0xFF, time); + } +}; + +struct ChannelManager { + ChannelManager(); + + u32 GetRequiredMemSize(); + void Setup(void *, u32); + void Shutdown(); + UNKTYPE UpdateAllChannel(); + static void Free(Channel *); // inlined + Channel *Alloc(); // inlined + static ChannelManager *GetInstance(); + + InstancePool mPool; // at 0x0 + ut::LinkList mList; // at 0x4 + + bool BOOL_0x10; + u32 INT_0x14; + UNKTYPE *PTR_0x18; + u32 INT_0x1C; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_ChannelManager.h b/include/nw4r/snd/snd_ChannelManager.h index 2b9fca7e..7bb2f56d 100644 --- a/include/nw4r/snd/snd_ChannelManager.h +++ b/include/nw4r/snd/snd_ChannelManager.h @@ -1,21 +1,17 @@ #ifndef NW4R_SND_CHANNEL_MANAGER_H #define NW4R_SND_CHANNEL_MANAGER_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct ChannelManager - { - static ChannelManager * GetInstance(); +namespace nw4r { +namespace snd { +namespace detail { +struct ChannelManager { + static ChannelManager *GetInstance(); - void UpdateAllChannel(); - }; - } - } -} + void UpdateAllChannel(); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_DisposeCallback.h b/include/nw4r/snd/snd_DisposeCallback.h index b76bfeed..69234cc5 100644 --- a/include/nw4r/snd/snd_DisposeCallback.h +++ b/include/nw4r/snd/snd_DisposeCallback.h @@ -1,24 +1,20 @@ #ifndef NW4R_SND_DISPOSE_CALLBACK_H #define NW4R_SND_DISPOSE_CALLBACK_H -#include "types_nw4r.h" +#include "common.h" #include "ut_LinkList.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct DisposeCallback - { - ut::LinkListNode mNode; // at 0x0 - - inline virtual ~DisposeCallback() {} // at 0x8 - virtual void InvalidateData(const void *, const void *) = 0; // at 0xc - virtual void InvalidateWaveData(const void *, const void *) = 0; // at 0x10 - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct DisposeCallback { + ut::LinkListNode mNode; // at 0x0 -#endif \ No newline at end of file + inline virtual ~DisposeCallback() {} // at 0x8 + virtual void InvalidateData(const void *, const void *) = 0; // at 0xc + virtual void InvalidateWaveData(const void *, const void *) = 0; // at 0x10 +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_DisposeCallbackManager.h b/include/nw4r/snd/snd_DisposeCallbackManager.h index 16c0a67e..26547a6a 100644 --- a/include/nw4r/snd/snd_DisposeCallbackManager.h +++ b/include/nw4r/snd/snd_DisposeCallbackManager.h @@ -1,29 +1,25 @@ #ifndef NW4R_SND_DISPOSE_CALLBACK_MANAGER_H #define NW4R_SND_DISPOSE_CALLBACK_MANAGER_H -#include "types_nw4r.h" +#include "common.h" #include "snd_DisposeCallback.h" #include "ut_LinkList.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct DisposeCallbackManager - { - static DisposeCallbackManager * GetInstance(); - - ut::LinkList mList; // at 0x0 - - UNKTYPE RegisterDisposeCallback(DisposeCallback *); - UNKTYPE UnregisterDisposeCallback(DisposeCallback *); - - UNKTYPE Dispose(void *, u32, void *); - UNKTYPE DisposeWave(void *, u32, void *); - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct DisposeCallbackManager { + static DisposeCallbackManager *GetInstance(); -#endif \ No newline at end of file + ut::LinkList mList; // at 0x0 + + UNKTYPE RegisterDisposeCallback(DisposeCallback *); + UNKTYPE UnregisterDisposeCallback(DisposeCallback *); + + UNKTYPE Dispose(void *, u32, void *); + UNKTYPE DisposeWave(void *, u32, void *); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_FrameHeap.h b/include/nw4r/snd/snd_FrameHeap.h index dec66053..fcab561b 100644 --- a/include/nw4r/snd/snd_FrameHeap.h +++ b/include/nw4r/snd/snd_FrameHeap.h @@ -1,90 +1,75 @@ #ifndef NW4R_SND_FRAME_HEAP_H #define NW4R_SND_FRAME_HEAP_H -#include "types_nw4r.h" +#include "common.h" #include "ut_LinkList.h" #include "ut_algorithm.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct FrameHeap - { - typedef void (* AllocCallback)(void *, u32, void *); - - struct Block - { - ut::LinkListNode mNode; // at 0x0 - u32 mSize; // at 0x8 - AllocCallback mCallback; // at 0xc - void * PTR_0x10; - - inline Block(u32 size, AllocCallback callback, void * ptr) - : - mSize(size), - mCallback(callback), - PTR_0x10(ptr) - {} - - inline void * GetBufferAddr() - { - return reinterpret_cast(this) + ut::RoundUp(sizeof(Block), 0x20); - } - - inline ~Block() - { - if (mCallback) mCallback(PTR_0x10, mSize, GetBufferAddr()); - } - }; - - struct Section - { - ut::LinkListNode mNode; // at 0x0 - ut::LinkList mList; // at 0x8 - - inline void AppendBlock(Block * pBlock) - { - mList.PushBack(pBlock); - } - - inline ~Section() - { - ut::LinkList::Iterator iter = mList.GetEndIter(); - - while (iter != mList.GetBeginIter()) - { - (--iter)->~Block(); - } - } - }; - - bool NewSection(); //inlined - UNKTYPE ClearSection(); //inlined - - FrameHeap(); - ~FrameHeap(); - - bool Create(void *, u32); - UNKTYPE Destroy(); - void Clear(); - void * Alloc(u32, AllocCallback, void *); - int SaveState(); - void LoadState(int); - int GetCurrentLevel() const; - u32 GetFreeSize() const; - - UNKTYPE * PTR_0x0; - ut::LinkList mList; // at 0x4 - - inline bool IsValid() const - { - return mList.GetSize(); - } - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct FrameHeap { + typedef void (*AllocCallback)(void *, u32, void *); -#endif \ No newline at end of file + struct Block { + ut::LinkListNode mNode; // at 0x0 + u32 mSize; // at 0x8 + AllocCallback mCallback; // at 0xc + void *PTR_0x10; + + inline Block(u32 size, AllocCallback callback, void *ptr) : mSize(size), mCallback(callback), PTR_0x10(ptr) {} + + inline void *GetBufferAddr() { + return reinterpret_cast(this) + ut::RoundUp(sizeof(Block), 0x20); + } + + inline ~Block() { + if (mCallback) { + mCallback(PTR_0x10, mSize, GetBufferAddr()); + } + } + }; + + struct Section { + ut::LinkListNode mNode; // at 0x0 + ut::LinkList mList; // at 0x8 + + inline void AppendBlock(Block *pBlock) { + mList.PushBack(pBlock); + } + + inline ~Section() { + ut::LinkList::Iterator iter = mList.GetEndIter(); + + while (iter != mList.GetBeginIter()) { + (--iter)->~Block(); + } + } + }; + + bool NewSection(); // inlined + UNKTYPE ClearSection(); // inlined + + FrameHeap(); + ~FrameHeap(); + + bool Create(void *, u32); + UNKTYPE Destroy(); + void Clear(); + void *Alloc(u32, AllocCallback, void *); + int SaveState(); + void LoadState(int); + int GetCurrentLevel() const; + u32 GetFreeSize() const; + + UNKTYPE *PTR_0x0; + ut::LinkList mList; // at 0x4 + + inline bool IsValid() const { + return mList.GetSize(); + } +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_FxBase.h b/include/nw4r/snd/snd_FxBase.h index d8a0725b..12d71cef 100644 --- a/include/nw4r/snd/snd_FxBase.h +++ b/include/nw4r/snd/snd_FxBase.h @@ -1,33 +1,24 @@ #ifndef NW4R_SND_FX_BASE_H #define NW4R_SND_FX_BASE_H -#include "types_nw4r.h" +#include "common.h" #include "snd_Common.h" #include "ut_LinkList.h" -namespace nw4r -{ - namespace snd - { - enum SampleFormat - { - SAMPLE_FORMAT_PCM_S32, - SAMPLE_FORMAT_PCM_S16, - SAMPLE_FORMAT_PCM_S8, - SAMPLE_FORMAT_DSP_ADPCM - }; - - struct FxBase - { - inline virtual ~FxBase() {} // at 0x8 - inline virtual bool StartUp() {} // at 0xc - inline virtual UNKTYPE Shutdown() {} // at 0x10 - inline virtual UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode) {} // at 0x14 - - NW4R_UT_LIST_NODE_DECL(); // at 0x4 - }; +namespace nw4r { +namespace snd { +enum SampleFormat { SAMPLE_FORMAT_PCM_S32, SAMPLE_FORMAT_PCM_S16, SAMPLE_FORMAT_PCM_S8, SAMPLE_FORMAT_DSP_ADPCM }; - NW4R_UT_LIST_TYPEDEF_DECL(FxBase); - } -} +struct FxBase { + inline virtual ~FxBase() {} // at 0x8 + inline virtual bool StartUp() {} // at 0xc + inline virtual UNKTYPE Shutdown() {} // at 0x10 + inline virtual UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode) {} // at 0x14 -#endif \ No newline at end of file + NW4R_UT_LIST_NODE_DECL(); // at 0x4 +}; + +NW4R_UT_LIST_TYPEDEF_DECL(FxBase); +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_FxChorus.h b/include/nw4r/snd/snd_FxChorus.h index 77af4857..d39be6be 100644 --- a/include/nw4r/snd/snd_FxChorus.h +++ b/include/nw4r/snd/snd_FxChorus.h @@ -1,47 +1,42 @@ #ifndef NW4R_SND_FX_CHORUS_H #define NW4R_SND_FX_CHORUS_H -#include -#include "types_nw4r.h" -#include "snd_FxBase.h" #include "snd_AxfxImpl.h" +#include "snd_FxBase.h" +#include #include "common.h" -namespace nw4r -{ - namespace snd - { - struct FxChorus : FxBase - { - //sizeof(ChorusParam) = 0xc - struct ChorusParam - { - float FLOAT_0x0; - float FLOAT_0x4; - float FLOAT_0x8; - }; - - FxChorus(); - - inline ~FxChorus() - { - Shutdown(); - ReleaseWorkBuffer(); - } - - u32 GetRequiredMemSize(); - virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 - virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c - - bool StartUp(); // at 0xc - UNKTYPE Shutdown(); // at 0x10 - bool SetParam(const ChorusParam &); - UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 - - detail::AxfxImpl mAxfxImpl; - - ChorusParam mParam; // at 0x18 - AXFX_CHORUS mAXFXChorus; // 0x24 - }; - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +struct FxChorus : FxBase { + // sizeof(ChorusParam) = 0xc + struct ChorusParam { + float FLOAT_0x0; + float FLOAT_0x4; + float FLOAT_0x8; + }; + + FxChorus(); + + inline ~FxChorus() { + Shutdown(); + ReleaseWorkBuffer(); + } + + u32 GetRequiredMemSize(); + virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 + virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c + + bool StartUp(); // at 0xc + UNKTYPE Shutdown(); // at 0x10 + bool SetParam(const ChorusParam &); + UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 + + detail::AxfxImpl mAxfxImpl; + + ChorusParam mParam; // at 0x18 + AXFX_CHORUS mAXFXChorus; // 0x24 +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_FxDelay.h b/include/nw4r/snd/snd_FxDelay.h index a054c39b..1ad7f26b 100644 --- a/include/nw4r/snd/snd_FxDelay.h +++ b/include/nw4r/snd/snd_FxDelay.h @@ -1,47 +1,42 @@ #ifndef NW4R_SND_FX_DELAY_H #define NW4R_SND_FX_DELAY_H -#include -#include "snd_FxBase.h" +#include "common.h" #include "snd_AxfxImpl.h" -#include "types_nw4r.h" +#include "snd_FxBase.h" +#include -namespace nw4r -{ - namespace snd - { - struct FxDelay : FxBase - { - //sizeof(FxDelayParam) = 0xc - struct DelayParam - { - float FLOAT_0x0; - float FLOAT_0x4; - float FLOAT_0x8; - }; - - FxDelay(); - - inline ~FxDelay() - { - Shutdown(); - ReleaseWorkBuffer(); - } - - u32 GetRequiredMemSize(); - virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 - virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c - - bool StartUp(); // at 0xc - UNKTYPE Shutdown(); // at 0x10 - bool SetParam(const DelayParam &); - UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 - - detail::AxfxImpl mAxfxImpl; // at 0xc - DelayParam mParam; // at 0x18 - - AXFX_DELAY mAXFXDelay; // at 0x24 - }; - } -} +namespace nw4r { +namespace snd { +struct FxDelay : FxBase { + // sizeof(FxDelayParam) = 0xc + struct DelayParam { + float FLOAT_0x0; + float FLOAT_0x4; + float FLOAT_0x8; + }; -#endif \ No newline at end of file + FxDelay(); + + inline ~FxDelay() { + Shutdown(); + ReleaseWorkBuffer(); + } + + u32 GetRequiredMemSize(); + virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 + virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c + + bool StartUp(); // at 0xc + UNKTYPE Shutdown(); // at 0x10 + bool SetParam(const DelayParam &); + UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 + + detail::AxfxImpl mAxfxImpl; // at 0xc + DelayParam mParam; // at 0x18 + + AXFX_DELAY mAXFXDelay; // at 0x24 +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_FxReverbHi.h b/include/nw4r/snd/snd_FxReverbHi.h index 2b472d05..fcbb0cf5 100644 --- a/include/nw4r/snd/snd_FxReverbHi.h +++ b/include/nw4r/snd/snd_FxReverbHi.h @@ -1,50 +1,45 @@ #ifndef NW4R_SND_FX_REVERB_HI_H #define NW4R_SND_FX_REVERB_HI_H -#include -#include "snd_FxBase.h" +#include "common.h" #include "snd_AxfxImpl.h" -#include "types_nw4r.h" +#include "snd_FxBase.h" +#include -namespace nw4r -{ - namespace snd - { - struct FxReverbHi : FxBase - { - //sizeof(ReverbHiParam) = 0x18 - struct ReverbHiParam - { - float FLOAT_0x0; - float FLOAT_0x4; - float FLOAT_0x8; - float FLOAT_0xC; - float FLOAT_0x10; - float FLOAT_0x14; - }; - - FxReverbHi(); - - inline ~FxReverbHi() - { - Shutdown(); - ReleaseWorkBuffer(); - } - - u32 GetRequiredMemSize(); - virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 - virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c - - bool StartUp(); // at 0xc - UNKTYPE Shutdown(); // at 0x10 - bool SetParam(const ReverbHiParam &); - UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 - - detail::AxfxImpl mAxfxImpl; // at 0xc - ReverbHiParam mParam; // at 0x18 - - AXFX_REVERBHI mAXFXReverbHi; // at 0x30 - }; - } -} +namespace nw4r { +namespace snd { +struct FxReverbHi : FxBase { + // sizeof(ReverbHiParam) = 0x18 + struct ReverbHiParam { + float FLOAT_0x0; + float FLOAT_0x4; + float FLOAT_0x8; + float FLOAT_0xC; + float FLOAT_0x10; + float FLOAT_0x14; + }; -#endif \ No newline at end of file + FxReverbHi(); + + inline ~FxReverbHi() { + Shutdown(); + ReleaseWorkBuffer(); + } + + u32 GetRequiredMemSize(); + virtual UNKTYPE AssignWorkBuffer(void *, u32); // at 0x18 + virtual UNKTYPE ReleaseWorkBuffer(); // at 0x1c + + bool StartUp(); // at 0xc + UNKTYPE Shutdown(); // at 0x10 + bool SetParam(const ReverbHiParam &); + UNKTYPE UpdateBuffer(int, void **, u32, SampleFormat, float, OutputMode); // at 0x14 + + detail::AxfxImpl mAxfxImpl; // at 0xc + ReverbHiParam mParam; // at 0x18 + + AXFX_REVERBHI mAXFXReverbHi; // at 0x30 +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_InstancePool.h b/include/nw4r/snd/snd_InstancePool.h index ad630a98..a074fe5e 100644 --- a/include/nw4r/snd/snd_InstancePool.h +++ b/include/nw4r/snd/snd_InstancePool.h @@ -1,9 +1,8 @@ #ifndef NW4R_SND_INSTANCE_POOL_H #define NW4R_SND_INSTANCE_POOL_H -#include "types_nw4r.h" +#include "common.h" #include - namespace nw4r { namespace snd { namespace detail { diff --git a/include/nw4r/snd/snd_MmlParser.h b/include/nw4r/snd/snd_MmlParser.h index 54398397..9abd7f0b 100644 --- a/include/nw4r/snd/snd_MmlParser.h +++ b/include/nw4r/snd/snd_MmlParser.h @@ -1,46 +1,40 @@ #ifndef NW4R_SND_MML_PARSER_H #define NW4R_SND_MML_PARSER_H -#include "types_nw4r.h" +#include "common.h" #include "snd_MmlSeqTrack.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct MmlParser - { - u16 Read16(const u8 **) const; //inlined - u32 Read24(const u8 **) const; //inlined - u32 ReadVar(const u8 **) const; //inlined - - volatile s16 * GetVariablePtr(SeqPlayer *, SeqTrack *, int) const; - - UNKWORD Parse(MmlSeqTrack *, bool) const; - virtual void CommandProc(MmlSeqTrack *, u32, s32, s32) const; // at 0x8 - virtual Channel * NoteOnCommandProc(MmlSeqTrack *, int, int, s32, bool) const; // at 0xc - - enum SeqArgType - { - SEQ_ARG_TYPE_IMMEDIATE_BYTE, - SEQ_ARG_TYPE_IMMEDIATE_16, - SEQ_ARG_TYPE_IMMEDIATE_VAR, - SEQ_ARG_TYPE_RANDOM, - SEQ_ARG_TYPE_VARIABLE - }; - - s32 ReadArg(const u8 **, SeqPlayer *, SeqTrack *, SeqArgType) const; - - inline u8 ReadByte(const u8 ** pPointer) const - { - return *(*pPointer)++; - } - - static bool mPrintVarEnabledFlag; - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct MmlParser { + u16 Read16(const u8 **) const; // inlined + u32 Read24(const u8 **) const; // inlined + u32 ReadVar(const u8 **) const; // inlined -#endif \ No newline at end of file + volatile s16 *GetVariablePtr(SeqPlayer *, SeqTrack *, int) const; + + UNKWORD Parse(MmlSeqTrack *, bool) const; + virtual void CommandProc(MmlSeqTrack *, u32, s32, s32) const; // at 0x8 + virtual Channel *NoteOnCommandProc(MmlSeqTrack *, int, int, s32, bool) const; // at 0xc + + enum SeqArgType { + SEQ_ARG_TYPE_IMMEDIATE_BYTE, + SEQ_ARG_TYPE_IMMEDIATE_16, + SEQ_ARG_TYPE_IMMEDIATE_VAR, + SEQ_ARG_TYPE_RANDOM, + SEQ_ARG_TYPE_VARIABLE + }; + + s32 ReadArg(const u8 **, SeqPlayer *, SeqTrack *, SeqArgType) const; + + inline u8 ReadByte(const u8 **pPointer) const { + return *(*pPointer)++; + } + + static bool mPrintVarEnabledFlag; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_MmlSeqTrack.h b/include/nw4r/snd/snd_MmlSeqTrack.h index a35646c7..0975a3a6 100644 --- a/include/nw4r/snd/snd_MmlSeqTrack.h +++ b/include/nw4r/snd/snd_MmlSeqTrack.h @@ -1,40 +1,33 @@ #ifndef NW4R_SND_MML_SEQ_TRACK_H #define NW4R_SND_MML_SEQ_TRACK_H +#include "common.h" #include "snd_SeqTrack.h" -#include "types_nw4r.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct MmlSeqTrack : SeqTrack - { - enum - { - STACK_FRAME_COUNT = 3 - }; - - struct MmlParserParam - { - bool mPredicate; // at 0x0 - bool BOOL_0x1; - bool BOOL_0x2; - u8 mLoopCounters[STACK_FRAME_COUNT]; // at 0x3 - u8 mStackIndex; // at 0x6 - const u8 * mReturnAddresses[STACK_FRAME_COUNT]; // at 0x8 - }; - - MmlParser * mParser; // at 0xc0 - MmlParserParam mMmlParserParam; // at 0xc4 - - MmlSeqTrack(); - - UNKWORD Parse(bool); // at 0xc - }; - } - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +namespace detail { +struct MmlSeqTrack : SeqTrack { + enum { STACK_FRAME_COUNT = 3 }; + + struct MmlParserParam { + bool mPredicate; // at 0x0 + bool BOOL_0x1; + bool BOOL_0x2; + u8 mLoopCounters[STACK_FRAME_COUNT]; // at 0x3 + u8 mStackIndex; // at 0x6 + const u8 *mReturnAddresses[STACK_FRAME_COUNT]; // at 0x8 + }; + + MmlParser *mParser; // at 0xc0 + MmlParserParam mMmlParserParam; // at 0xc4 + + MmlSeqTrack(); + + UNKWORD Parse(bool); // at 0xc +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_MmlSeqTrackAllocator.h b/include/nw4r/snd/snd_MmlSeqTrackAllocator.h index b8d5750b..f92b4043 100644 --- a/include/nw4r/snd/snd_MmlSeqTrackAllocator.h +++ b/include/nw4r/snd/snd_MmlSeqTrackAllocator.h @@ -1,31 +1,27 @@ #ifndef NW4R_SND_MML_SEQ_TRACK_ALLOCATOR_H #define NW4R_SND_MML_SEQ_TRACK_ALLOCATOR_H -#include "snd_MmlSeqTrack.h" -#include "snd_MmlParser.h" +#include "common.h" #include "snd_InstancePool.h" -#include "types_nw4r.h" +#include "snd_MmlParser.h" +#include "snd_MmlSeqTrack.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct MmlSeqTrackAllocator : SeqTrackAllocator - { - MmlParser * mParser; - InstancePool mPool; // at 0x8 - - SeqTrack * AllocTrack(SeqPlayer *); // at 0xc - void FreeTrack(SeqTrack *); // at 0x10 - - u32 Create(void *, u32); - void Destroy(void *, u32); - - int GetAllocatableTrackCount() const; // at 0x14 - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct MmlSeqTrackAllocator : SeqTrackAllocator { + MmlParser *mParser; + InstancePool mPool; // at 0x8 -#endif \ No newline at end of file + SeqTrack *AllocTrack(SeqPlayer *); // at 0xc + void FreeTrack(SeqTrack *); // at 0x10 + + u32 Create(void *, u32); + void Destroy(void *, u32); + + int GetAllocatableTrackCount() const; // at 0x14 +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_NoteOn.h b/include/nw4r/snd/snd_NoteOn.h index 474ed151..9e04ce8b 100644 --- a/include/nw4r/snd/snd_NoteOn.h +++ b/include/nw4r/snd/snd_NoteOn.h @@ -1,34 +1,29 @@ #ifndef NW4R_SND_NOTE_ON_H #define NW4R_SND_NOTE_ON_H -#include "types_nw4r.h" +#include "common.h" #include "snd_Channel.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct NoteOnInfo - { - int INT_0x0; - int INT_0x4; - int INT_0x8; - int INT_0xC; - int INT_0x10; - int INT_0x14; - int INT_0x18; - Channel::ChannelCallback mChannelCallback; // at 0x1c - u32 INT_0x20; - }; - - struct NoteOnCallback - { - virtual ~NoteOnCallback(); // at 0x8 - virtual bool NoteOn(SeqPlayer *, int, const NoteOnInfo &) = 0; // at 0xc - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct NoteOnInfo { + int INT_0x0; + int INT_0x4; + int INT_0x8; + int INT_0xC; + int INT_0x10; + int INT_0x14; + int INT_0x18; + Channel::ChannelCallback mChannelCallback; // at 0x1c + u32 INT_0x20; +}; -#endif \ No newline at end of file +struct NoteOnCallback { + virtual ~NoteOnCallback(); // at 0x8 + virtual bool NoteOn(SeqPlayer *, int, const NoteOnInfo &) = 0; // at 0xc +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_PlayerHeap.h b/include/nw4r/snd/snd_PlayerHeap.h index f29b1dd5..ef3874ea 100644 --- a/include/nw4r/snd/snd_PlayerHeap.h +++ b/include/nw4r/snd/snd_PlayerHeap.h @@ -1,21 +1,17 @@ #ifndef NW4R_SND_PLAYER_HEAP_H #define NW4R_SND_PLAYER_HEAP_H -#include "types_nw4r.h" +#include "common.h" #include "snd_SoundHeap.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct PlayerHeap : SoundHeap - { - ~PlayerHeap(); - UNKTYPE * Alloc(u32); - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct PlayerHeap : SoundHeap { + ~PlayerHeap(); + UNKTYPE *Alloc(u32); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_RemoteSpeaker.h b/include/nw4r/snd/snd_RemoteSpeaker.h index 2252a5e8..b63f3dc9 100644 --- a/include/nw4r/snd/snd_RemoteSpeaker.h +++ b/include/nw4r/snd/snd_RemoteSpeaker.h @@ -1,75 +1,69 @@ #ifndef NW4R_SND_REMOTE_SPEAKER_H #define NW4R_SND_REMOTE_SPEAKER_H #include -#include -#include "types_nw4r.h" +#include #include "common.h" -namespace nw4r -{ - namespace snd - { - struct RemoteSpeaker - { - typedef void (*RemoteSpeakerCallback)(s32, s32); - - enum SpeakerCommand - { - SpeakerCommand_None, - SpeakerCommand_On, - SpeakerCommand_Play, - SpeakerCommand_Off, - }; - - bool mPoweredFlag; // at 0x0 - bool BOOL_0x1; - bool mEnabledOutputFlag; // at 0x2 - bool BOOL_0x3; - bool BOOL_0x4; - bool BOOL_0x5; - bool BOOL_0x6; - bool BOOL_0x7; - volatile bool BOOL_0x8; - - UNKWORD WORD_0xC; - SpeakerCommand CMD_0x10; - SpeakerCommand CMD_0x14; - char UNK_0x18[0x20]; - s32 mChannelIndex; // at 0x38 - RemoteSpeakerCallback mCallback; // at 0x3c - OSAlarm ALARM_0x40; - OSAlarm ALARM_0x70; - s64 mTime; // at 0xa0 - - RemoteSpeaker(); - void ClearParam(); //inlined - void InitParam(); //inlined - - bool Setup(RemoteSpeakerCallback); - void Shutdown(RemoteSpeakerCallback); - - bool EnableOutput(bool); - bool IsEnabledOutput() const; - - void Update(); - void ExecCommand(SpeakerCommand); - - bool IsAllSampleZero(const s16 *); //inlined - void UpdateStreamData(const s16 *); - - void NotifyCallback(s32, s32); //inlined - static void SpeakerOnCallback(s32, s32); - static void SpeakerPlayCallback(s32, s32); - static void SpeakerOffCallback(s32, s32); - - static void ContinueAlarmHandler(OSAlarm *, OSContext *); - static void IntervalAlarmHandler(OSAlarm *, OSContext *); - - inline void SetChannelIndex(int channelIndex) - { - mChannelIndex = channelIndex; - } - }; - } -} +namespace nw4r { +namespace snd { +struct RemoteSpeaker { + typedef void (*RemoteSpeakerCallback)(s32, s32); -#endif \ No newline at end of file + enum SpeakerCommand { + SpeakerCommand_None, + SpeakerCommand_On, + SpeakerCommand_Play, + SpeakerCommand_Off, + }; + + bool mPoweredFlag; // at 0x0 + bool BOOL_0x1; + bool mEnabledOutputFlag; // at 0x2 + bool BOOL_0x3; + bool BOOL_0x4; + bool BOOL_0x5; + bool BOOL_0x6; + bool BOOL_0x7; + volatile bool BOOL_0x8; + + UNKWORD WORD_0xC; + SpeakerCommand CMD_0x10; + SpeakerCommand CMD_0x14; + char UNK_0x18[0x20]; + s32 mChannelIndex; // at 0x38 + RemoteSpeakerCallback mCallback; // at 0x3c + OSAlarm ALARM_0x40; + OSAlarm ALARM_0x70; + s64 mTime; // at 0xa0 + + RemoteSpeaker(); + void ClearParam(); // inlined + void InitParam(); // inlined + + bool Setup(RemoteSpeakerCallback); + void Shutdown(RemoteSpeakerCallback); + + bool EnableOutput(bool); + bool IsEnabledOutput() const; + + void Update(); + void ExecCommand(SpeakerCommand); + + bool IsAllSampleZero(const s16 *); // inlined + void UpdateStreamData(const s16 *); + + void NotifyCallback(s32, s32); // inlined + static void SpeakerOnCallback(s32, s32); + static void SpeakerPlayCallback(s32, s32); + static void SpeakerOffCallback(s32, s32); + + static void ContinueAlarmHandler(OSAlarm *, OSContext *); + static void IntervalAlarmHandler(OSAlarm *, OSContext *); + + inline void SetChannelIndex(int channelIndex) { + mChannelIndex = channelIndex; + } +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SeqFile.h b/include/nw4r/snd/snd_SeqFile.h index 0d72e344..f03e48c9 100644 --- a/include/nw4r/snd/snd_SeqFile.h +++ b/include/nw4r/snd/snd_SeqFile.h @@ -1,37 +1,31 @@ #ifndef NW4R_SND_SEQ_FILE_H #define NW4R_SND_SEQ_FILE_H -#include "types_nw4r.h" +#include "common.h" #include "ut_binaryFileFormat.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct SeqFile - { - ut::BinaryFileHeader mHeader; // at 0x0 - u32 OFFSET_0x10; // at 0x10 - }; - - struct SeqFileReader - { - struct UNKBLOCK - { - ut::BinaryBlockHeader mHeader; // at 0x0 - u32 OFFSET_0x8; - }; - - const SeqFile * mFile; // at 0x0 - const UNKBLOCK * PTR_0x4; - - bool IsValidFileHeader(const void *); - SeqFileReader(const void *); - const void * GetBaseAddress() const; - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct SeqFile { + ut::BinaryFileHeader mHeader; // at 0x0 + u32 OFFSET_0x10; // at 0x10 +}; -#endif \ No newline at end of file +struct SeqFileReader { + struct UNKBLOCK { + ut::BinaryBlockHeader mHeader; // at 0x0 + u32 OFFSET_0x8; + }; + + const SeqFile *mFile; // at 0x0 + const UNKBLOCK *PTR_0x4; + + bool IsValidFileHeader(const void *); + SeqFileReader(const void *); + const void *GetBaseAddress() const; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SeqPlayer.h b/include/nw4r/snd/snd_SeqPlayer.h index 12236216..7fda47b1 100644 --- a/include/nw4r/snd/snd_SeqPlayer.h +++ b/include/nw4r/snd/snd_SeqPlayer.h @@ -1,138 +1,121 @@ #ifndef NW4R_SND_SEQ_PLAYER_H #define NW4R_SND_SEQ_PLAYER_H -#include "types_nw4r.h" -#include "ut_lock.h" +#include "common.h" #include "snd_BasicPlayer.h" -#include "snd_InstancePool.h" #include "snd_DisposeCallback.h" -#include "snd_SoundThread.h" +#include "snd_InstancePool.h" #include "snd_NoteOn.h" +#include "snd_SoundThread.h" +#include "ut_lock.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - // Used an anonymous enum instead of a macro - // because I wanted the magic number to have - // namespace scope - enum - { - SEQ_TRACKS_PER_PLAYER = 0x10, - SEQ_VARIABLE_COUNT = 0x10 - }; - - //sizeof(SeqPlayer) = 0x11C - struct SeqPlayer : BasicPlayer, DisposeCallback, SoundThread::PlayerCallback - { - enum OffsetType - { - OFFSET_TYPE_0, - OFFSET_TYPE_1 - }; - - - bool Start(); // at 0xc - void Stop(); // at 0x10 - void Pause(bool); // at 0x14 - bool IsActive() const; // at 0x18 - bool IsStarted() const; // at 0x1c - bool IsPause() const; // at 0x20 - - void InvalidateData(const void *, const void *); - inline void InvalidateWaveData(const void *, const void *) {} - inline virtual void ChannelCallback(Channel *) {} - - bool mActiveFlag; // at 0x8c - bool mStartedFlag; // at 0x8d - bool mPauseFlag; // at 0x8e - - bool mReleasePriorityFixFlag; // at 0x8f - float FLOAT_0x90; - float mTempoRatio; // at 0x94 - float FLOAT_0x98; - int OFFSET_0x9C; - float OFFSET_0xA0; - int INT_0xA4; - char BYTE_0xA8; - u8 mChannelPriority; // at 0xa9 - u8 BYTE_0xAA; - u16 SHORT_0xAC; - - NoteOnCallback * mNoteOnCallback; // at 0xb0 - SeqTrackAllocator * mTrackAllocator; // at 0xb4 - SeqTrack * mPlayerTracks[SEQ_TRACKS_PER_PLAYER]; // at 0xb8 - volatile s16 mLocalVariables[SEQ_VARIABLE_COUNT]; // at 0xf8 - - int INT_0x118; - - SeqPlayer(); - ~SeqPlayer(); - - UNKTYPE InitParam(int, NoteOnCallback *); - void CloseTrack(int); - void FinishPlayer(); //inlined - - bool Setup(SeqTrackAllocator *, u32, int, NoteOnCallback *); - void SetSeqData(const void *, s32); - void Skip(OffsetType, int); - - void SetTempoRatio(float); - void SetChannelPriority(int); - void SetReleasePriorityFix(bool); - void SetLocalVariable(int, short); - static void InitGlobalVariable(); //inline - static void SetGlobalVariable(int, short); - - template - inline void SetTrackParam(u32 flags, void (SeqTrack::* pSetter)(T), T param) - { - ut::AutoInterruptLock lock; - - for (int i = 0; i < SEQ_TRACKS_PER_PLAYER && flags; flags >>= 1, i++) - { - if (flags & 1) - { - SeqTrack * pPlayerTrack = GetPlayerTrack(i); - - if (pPlayerTrack) (pPlayerTrack->*pSetter)(param); - } - } - } - - void SetTrackVolume(u32, float); - void SetTrackPitch(u32, float); - - void SetPlayerTrack(int, SeqTrack *); //inlined - SeqTrack * GetPlayerTrack(int); - bool ParseNextTick(bool); - volatile s16 * GetVariablePtr(int); - void UpdateChannelParam(); //inlined - void Update(); - void UpdateTick(); - void UpdateTick(int); - bool NoteOn(int, const NoteOnInfo &); - inline void OnUpdateFrameSoundThread() - { - Update(); - } - - inline void OnShutdownSoundThread() - { - Stop(); - } - - inline float GetBaseTempo() const - { - return mTempoRatio * (BYTE_0xAA * SHORT_0xAC) / 60000.0f; - } - - static volatile s16 mGlobalVariable[SEQ_VARIABLE_COUNT]; - static bool mGobalVariableInitialized; // typo - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +// Used an anonymous enum instead of a macro +// because I wanted the magic number to have +// namespace scope +enum { SEQ_TRACKS_PER_PLAYER = 0x10, SEQ_VARIABLE_COUNT = 0x10 }; -#endif \ No newline at end of file +// sizeof(SeqPlayer) = 0x11C +struct SeqPlayer : BasicPlayer, DisposeCallback, SoundThread::PlayerCallback { + enum OffsetType { OFFSET_TYPE_0, OFFSET_TYPE_1 }; + + bool Start(); // at 0xc + void Stop(); // at 0x10 + void Pause(bool); // at 0x14 + bool IsActive() const; // at 0x18 + bool IsStarted() const; // at 0x1c + bool IsPause() const; // at 0x20 + + void InvalidateData(const void *, const void *); + inline void InvalidateWaveData(const void *, const void *) {} + inline virtual void ChannelCallback(Channel *) {} + + bool mActiveFlag; // at 0x8c + bool mStartedFlag; // at 0x8d + bool mPauseFlag; // at 0x8e + + bool mReleasePriorityFixFlag; // at 0x8f + float FLOAT_0x90; + float mTempoRatio; // at 0x94 + float FLOAT_0x98; + int OFFSET_0x9C; + float OFFSET_0xA0; + int INT_0xA4; + char BYTE_0xA8; + u8 mChannelPriority; // at 0xa9 + u8 BYTE_0xAA; + u16 SHORT_0xAC; + + NoteOnCallback *mNoteOnCallback; // at 0xb0 + SeqTrackAllocator *mTrackAllocator; // at 0xb4 + SeqTrack *mPlayerTracks[SEQ_TRACKS_PER_PLAYER]; // at 0xb8 + volatile s16 mLocalVariables[SEQ_VARIABLE_COUNT]; // at 0xf8 + + int INT_0x118; + + SeqPlayer(); + ~SeqPlayer(); + + UNKTYPE InitParam(int, NoteOnCallback *); + void CloseTrack(int); + void FinishPlayer(); // inlined + + bool Setup(SeqTrackAllocator *, u32, int, NoteOnCallback *); + void SetSeqData(const void *, s32); + void Skip(OffsetType, int); + + void SetTempoRatio(float); + void SetChannelPriority(int); + void SetReleasePriorityFix(bool); + void SetLocalVariable(int, short); + static void InitGlobalVariable(); // inline + static void SetGlobalVariable(int, short); + + template + inline void SetTrackParam(u32 flags, void (SeqTrack::*pSetter)(T), T param) { + ut::AutoInterruptLock lock; + + for (int i = 0; i < SEQ_TRACKS_PER_PLAYER && flags; flags >>= 1, i++) { + if (flags & 1) { + SeqTrack *pPlayerTrack = GetPlayerTrack(i); + + if (pPlayerTrack) { + (pPlayerTrack->*pSetter)(param); + } + } + } + } + + void SetTrackVolume(u32, float); + void SetTrackPitch(u32, float); + + void SetPlayerTrack(int, SeqTrack *); // inlined + SeqTrack *GetPlayerTrack(int); + bool ParseNextTick(bool); + volatile s16 *GetVariablePtr(int); + void UpdateChannelParam(); // inlined + void Update(); + void UpdateTick(); + void UpdateTick(int); + bool NoteOn(int, const NoteOnInfo &); + inline void OnUpdateFrameSoundThread() { + Update(); + } + + inline void OnShutdownSoundThread() { + Stop(); + } + + inline float GetBaseTempo() const { + return mTempoRatio * (BYTE_0xAA * SHORT_0xAC) / 60000.0f; + } + + static volatile s16 mGlobalVariable[SEQ_VARIABLE_COUNT]; + static bool mGobalVariableInitialized; // typo +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SeqSound.h b/include/nw4r/snd/snd_SeqSound.h index 26a825a3..b1f8f72f 100644 --- a/include/nw4r/snd/snd_SeqSound.h +++ b/include/nw4r/snd/snd_SeqSound.h @@ -1,104 +1,95 @@ #ifndef NW4R_SND_SEQ_SOUND_H #define NW4R_SND_SEQ_SOUND_H -#include -#include "types_nw4r.h" #include "snd_BasicSound.h" +#include "snd_NoteOn.h" #include "snd_SeqPlayer.h" #include "snd_SoundInstanceManager.h" #include "snd_Task.h" -#include "snd_NoteOn.h" #include "ut_FileStream.h" +#include #include "common.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct SeqSound : BasicSound - { - typedef void (*SeqLoadCallback)(bool, const void *, void *); - - //sizeof(SeqLoadTask) = 0x24 - struct SeqLoadTask : Task - { - ut::FileStream * mFileStream; // at 0x10 - void * mData; // at 0x14 - int mSize; // at 0x18 - SeqLoadCallback mCallback; // at 0x1c - SeqSound * mSound; // at 0x20 - - inline SeqLoadTask() : mFileStream(NULL), mData(NULL), mCallback(NULL), mSound(NULL) {} - - void Execute(); - void Cancel(); - void OnCancel(); - }; - - static ut::detail::RuntimeTypeInfo typeInfo; - - SeqPlayer mPlayer; // at 0xd8 - SeqSoundHandle * mTempSpecialHandle; // at 0x1f4 - SoundInstanceManager * mManager; // at 0x1f8 - s32 INT_0x1FC; - SeqPlayer::OffsetType mOffsetType; // at 0x200 - int mOffset; // at 0x204 - bool mLoadingFlag; // at 0x208 - volatile bool mPreparedFlag; // at 0x209 - ut::FileStream * mFileStream; // at 0x20c - char UNK_0x210[0x200]; - SeqLoadTask mLoadTask; // at 0x410 - OSMutex MUTEX_0x434; // at 0x434 - - SeqSound(SoundInstanceManager *); - UNKTYPE InitParam(); - UNKTYPE Setup(SeqTrackAllocator *, u32, int, NoteOnCallback *); - - UNKTYPE Skip(SeqPlayer::OffsetType, int); //inlined - bool LoadData(SeqLoadCallback, void *); //inlined - void Prepare(const void *, s32, SeqPlayer::OffsetType, int); - void Prepare(ut::FileStream *, s32, SeqPlayer::OffsetType, int); - static void NotifyLoadAsyncEndSeqData(bool, const void *, void *); - - void Shutdown(); - - UNKTYPE SetTempoRatio(float); - UNKTYPE SetChannelPriority(int); - UNKTYPE SetReleasePriorityFix(bool); - - UNKTYPE SetPlayerPriority(int); - - UNKTYPE SetTrackVolume(u32, float); - UNKTYPE SetTrackPitch(u32, float); - - bool WriteVariable(int, short); - static bool WriteGlobalVariable(int, short); - - bool IsAttachedTempSpecialHandle(); - UNKTYPE DetachTempSpecialHandle(); - - inline const BasicPlayer * GetBasicPlayer() const - { - return &mPlayer; - } - - inline BasicPlayer * GetBasicPlayer() - { - return &mPlayer; - } - - inline bool IsPrepared() const - { - return mPreparedFlag; - } - - inline const ut::detail::RuntimeTypeInfo * GetRuntimeTypeInfo() const - { - return &typeInfo; - } - }; - } - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +namespace detail { +struct SeqSound : BasicSound { + typedef void (*SeqLoadCallback)(bool, const void *, void *); + + // sizeof(SeqLoadTask) = 0x24 + struct SeqLoadTask : Task { + ut::FileStream *mFileStream; // at 0x10 + void *mData; // at 0x14 + int mSize; // at 0x18 + SeqLoadCallback mCallback; // at 0x1c + SeqSound *mSound; // at 0x20 + + inline SeqLoadTask() : mFileStream(NULL), mData(NULL), mCallback(NULL), mSound(NULL) {} + + void Execute(); + void Cancel(); + void OnCancel(); + }; + + static ut::detail::RuntimeTypeInfo typeInfo; + + SeqPlayer mPlayer; // at 0xd8 + SeqSoundHandle *mTempSpecialHandle; // at 0x1f4 + SoundInstanceManager *mManager; // at 0x1f8 + s32 INT_0x1FC; + SeqPlayer::OffsetType mOffsetType; // at 0x200 + int mOffset; // at 0x204 + bool mLoadingFlag; // at 0x208 + volatile bool mPreparedFlag; // at 0x209 + ut::FileStream *mFileStream; // at 0x20c + char UNK_0x210[0x200]; + SeqLoadTask mLoadTask; // at 0x410 + OSMutex MUTEX_0x434; // at 0x434 + + SeqSound(SoundInstanceManager *); + UNKTYPE InitParam(); + UNKTYPE Setup(SeqTrackAllocator *, u32, int, NoteOnCallback *); + + UNKTYPE Skip(SeqPlayer::OffsetType, int); // inlined + bool LoadData(SeqLoadCallback, void *); // inlined + void Prepare(const void *, s32, SeqPlayer::OffsetType, int); + void Prepare(ut::FileStream *, s32, SeqPlayer::OffsetType, int); + static void NotifyLoadAsyncEndSeqData(bool, const void *, void *); + + void Shutdown(); + + UNKTYPE SetTempoRatio(float); + UNKTYPE SetChannelPriority(int); + UNKTYPE SetReleasePriorityFix(bool); + + UNKTYPE SetPlayerPriority(int); + + UNKTYPE SetTrackVolume(u32, float); + UNKTYPE SetTrackPitch(u32, float); + + bool WriteVariable(int, short); + static bool WriteGlobalVariable(int, short); + + bool IsAttachedTempSpecialHandle(); + UNKTYPE DetachTempSpecialHandle(); + + inline const BasicPlayer *GetBasicPlayer() const { + return &mPlayer; + } + + inline BasicPlayer *GetBasicPlayer() { + return &mPlayer; + } + + inline bool IsPrepared() const { + return mPreparedFlag; + } + + inline const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const { + return &typeInfo; + } +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SeqSoundHandle.h b/include/nw4r/snd/snd_SeqSoundHandle.h index 4f4c1b05..9580e45e 100644 --- a/include/nw4r/snd/snd_SeqSoundHandle.h +++ b/include/nw4r/snd/snd_SeqSoundHandle.h @@ -1,22 +1,19 @@ #ifndef NW4R_SND_SEQ_SOUND_HANDLE_H #define NW4R_SND_SEQ_SOUND_HANDLE_H -#include "types_nw4r.h" +#include "common.h" #include "snd_SoundHandle.h" -namespace nw4r -{ - namespace snd - { - using namespace detail; - - struct SeqSoundHandle - { - detail::SeqSound * mSound; // at 0x0 - - SeqSoundHandle(SoundHandle *); - void DetachSound(); - }; - } -} +namespace nw4r { +namespace snd { +using namespace detail; -#endif \ No newline at end of file +struct SeqSoundHandle { + detail::SeqSound *mSound; // at 0x0 + + SeqSoundHandle(SoundHandle *); + void DetachSound(); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SeqTrack.h b/include/nw4r/snd/snd_SeqTrack.h index 3040d00f..2e50ea01 100644 --- a/include/nw4r/snd/snd_SeqTrack.h +++ b/include/nw4r/snd/snd_SeqTrack.h @@ -1,129 +1,117 @@ #ifndef NW4R_SND_SEQ_TRACK_H #define NW4R_SND_SEQ_TRACK_H -#include "types_nw4r.h" -#include "snd_Lfo.h" +#include "common.h" #include "snd_Channel.h" +#include "snd_Lfo.h" -namespace nw4r -{ - namespace snd - { - enum SeqMute - { - SEQ_MUTE_0, - SEQ_MUTE_1, - SEQ_MUTE_2, - SEQ_MUTE_3 - }; - - namespace detail - { - struct SeqTrack - { - virtual ~SeqTrack(); - virtual UNKWORD Parse(bool) = 0; - - u8 mPlayerTrackNo; // at 0x4 - bool mOpenFlag; // at 0x5 - - float mVolume; // at 0x8 - float mPitch; // at 0xc - float FLOAT_0x10; - float FLOAT_0x14; - float FLOAT_0x18; - float FLOAT_0x1C; - float FLOAT_0x20; - float FLOATS_0x24[3]; - float FLOATS_0x30[4]; - float FLOATS_0x40[4]; - - const u8 * PTR_0x50; - const u8 * PTR_0x54; - - int TIMER_0x58; - - bool BOOL_0x5C; - char BYTE_0x5D; - bool BOOL_0x5E; - bool BOOL_0x5F; - bool BOOL_0x60; - - int INT_0x64; - UNKWORD WORD_0x68; - - LfoParam mLfoParam; // at 0x6c - - u8 BYTE_0x7C; - float FLOAT_0x80; - u8 BYTE_0x84; - u8 BYTE_0x85; - s8 BYTE_0x86; - u8 BYTE_0x87; - s8 BYTE_0x88; - s8 BYTE_0x89; - s8 BYTE_0x8A; - char BYTE_0x8B; - u8 BYTE_0x8C; - char BYTE_0x8D; - u8 BYTE_0x8E; - - u8 mAttack; // at 0x8f - u8 mDecay; // at 0x90 - u8 mSustain; // at 0x91 - u8 mRelease; // at 0x92 - - u8 BYTE_0x93; - u8 BYTES_0x94[3]; - char BYTE_0x97; - - s16 mVariables[0x10]; // at 0x98 - - SeqPlayer * mPlayer; // at 0xb8 - Channel * mChannel; // at 0xbc - - void SetPlayerTrackNo(int); - - SeqTrack(); - - UNKTYPE InitParam(); - - void SetSeqData(const void *, s32); - - void Open(); - void Close(); - - void UpdateChannelRelease(Channel *); //inlined - void UpdateChannelLength(); - UNKWORD ParseNextTick(bool); - void ReleaseAllChannel(int); - UNKTYPE PauseAllChannel(bool); - void UpdateChannelParam(); - UNKTYPE FreeAllChannel(); - - static void ChannelCallbackFunc(Channel *, Channel::ChannelCallbackStatus, u32); - - void StopAllChannel(); //inlined - void SetMute(SeqMute); - void SetVolume(float); - void SetPitch(float); - s16 * GetVariablePtr(int); - void AddChannel(Channel *); //inlined - Channel * NoteOn(int, int, s32, bool); - - inline bool IsOpened() const - { - return mOpenFlag; - } - }; - - struct SeqTrackAllocator - { - inline virtual ~SeqTrackAllocator() {} - virtual SeqTrack * AllocTrack(SeqPlayer *) = 0; - virtual void FreeTrack(SeqTrack *) = 0; - virtual int GetAllocatableTrackCount() const = 0; - }; - } - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +enum SeqMute { SEQ_MUTE_0, SEQ_MUTE_1, SEQ_MUTE_2, SEQ_MUTE_3 }; + +namespace detail { +struct SeqTrack { + virtual ~SeqTrack(); + virtual UNKWORD Parse(bool) = 0; + + u8 mPlayerTrackNo; // at 0x4 + bool mOpenFlag; // at 0x5 + + float mVolume; // at 0x8 + float mPitch; // at 0xc + float FLOAT_0x10; + float FLOAT_0x14; + float FLOAT_0x18; + float FLOAT_0x1C; + float FLOAT_0x20; + float FLOATS_0x24[3]; + float FLOATS_0x30[4]; + float FLOATS_0x40[4]; + + const u8 *PTR_0x50; + const u8 *PTR_0x54; + + int TIMER_0x58; + + bool BOOL_0x5C; + char BYTE_0x5D; + bool BOOL_0x5E; + bool BOOL_0x5F; + bool BOOL_0x60; + + int INT_0x64; + UNKWORD WORD_0x68; + + LfoParam mLfoParam; // at 0x6c + + u8 BYTE_0x7C; + float FLOAT_0x80; + u8 BYTE_0x84; + u8 BYTE_0x85; + s8 BYTE_0x86; + u8 BYTE_0x87; + s8 BYTE_0x88; + s8 BYTE_0x89; + s8 BYTE_0x8A; + char BYTE_0x8B; + u8 BYTE_0x8C; + char BYTE_0x8D; + u8 BYTE_0x8E; + + u8 mAttack; // at 0x8f + u8 mDecay; // at 0x90 + u8 mSustain; // at 0x91 + u8 mRelease; // at 0x92 + + u8 BYTE_0x93; + u8 BYTES_0x94[3]; + char BYTE_0x97; + + s16 mVariables[0x10]; // at 0x98 + + SeqPlayer *mPlayer; // at 0xb8 + Channel *mChannel; // at 0xbc + + void SetPlayerTrackNo(int); + + SeqTrack(); + + UNKTYPE InitParam(); + + void SetSeqData(const void *, s32); + + void Open(); + void Close(); + + void UpdateChannelRelease(Channel *); // inlined + void UpdateChannelLength(); + UNKWORD ParseNextTick(bool); + void ReleaseAllChannel(int); + UNKTYPE PauseAllChannel(bool); + void UpdateChannelParam(); + UNKTYPE FreeAllChannel(); + + static void ChannelCallbackFunc(Channel *, Channel::ChannelCallbackStatus, u32); + + void StopAllChannel(); // inlined + void SetMute(SeqMute); + void SetVolume(float); + void SetPitch(float); + s16 *GetVariablePtr(int); + void AddChannel(Channel *); // inlined + Channel *NoteOn(int, int, s32, bool); + + inline bool IsOpened() const { + return mOpenFlag; + } +}; + +struct SeqTrackAllocator { + inline virtual ~SeqTrackAllocator() {} + virtual SeqTrack *AllocTrack(SeqPlayer *) = 0; + virtual void FreeTrack(SeqTrack *) = 0; + virtual int GetAllocatableTrackCount() const = 0; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r +#endif diff --git a/include/nw4r/snd/snd_Sound3DListener.h b/include/nw4r/snd/snd_Sound3DListener.h index 2a61b8cd..4e12f717 100644 --- a/include/nw4r/snd/snd_Sound3DListener.h +++ b/include/nw4r/snd/snd_Sound3DListener.h @@ -1,23 +1,20 @@ #ifndef NW4R_SND_SOUND_3D_LISTENER_H #define NW4R_SND_SOUND_3D_LISTENER_H -#include "types_nw4r.h" +#include "common.h" #include "math_types.h" -namespace nw4r -{ - namespace snd - { - struct Sound3DListener - { - math::MTX34 mMatrix; // at 0x0 - - float mInteriorSize; // at 0x30 - float mMaxVolumeDistance; // at 0x34 - float mUnitDistance; // at 0x38 - - Sound3DListener(); - }; - } -} +namespace nw4r { +namespace snd { +struct Sound3DListener { + math::MTX34 mMatrix; // at 0x0 -#endif \ No newline at end of file + float mInteriorSize; // at 0x30 + float mMaxVolumeDistance; // at 0x34 + float mUnitDistance; // at 0x38 + + Sound3DListener(); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundArchive.h b/include/nw4r/snd/snd_SoundArchive.h index 3a3bd351..4745ab93 100644 --- a/include/nw4r/snd/snd_SoundArchive.h +++ b/include/nw4r/snd/snd_SoundArchive.h @@ -1,163 +1,147 @@ #ifndef NW4R_SND_SOUND_ARCHIVE_H #define NW4R_SND_SOUND_ARCHIVE_H +#include "common.h" #include "ut_FileStream.h" -#include "types_nw4r.h" -namespace nw4r -{ - namespace snd - { - struct SoundArchive - { - struct Sound3DParam - { - UNKWORD WORD_0x0; - u8 BYTE_0x4; - u8 BYTE_0x5; - }; - - struct SoundArchivePlayerInfo - { - u32 SIZE_0x0; - UNKWORD WORD_0x4; - u32 SIZE_0x8; - UNKWORD WORD_0xC; - UNKWORD WORD_0x10; - u32 SIZE_0x14; - UNKWORD WORD_0x18; - }; - - struct SoundInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - UNKWORD WORD_0x8; - UNKWORD WORD_0xC; - UNKWORD WORD_0x10; - UNKWORD WORD_0x14; - UNKWORD WORD_0x18; - }; - - struct SeqSoundInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - UNKWORD WORD_0x8; - UNKWORD WORD_0xC; - bool BOOL_0x10; - }; - - struct StrmSoundInfo - { - - }; - - struct WaveSoundInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - bool BOOL_0x8; - }; - - struct BankInfo - { - UNKWORD WORD_0x0; - }; - - struct PlayerInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - }; - - struct GroupInfo - { - u32 mCount; // at 0x0 - const char * mExternalFileName; // at 0x4 - u32 INT_0x8; - u32 INT_0xC; - u32 INT_0x10; - u32 INT_0x14; - }; - - struct GroupItemInfo - { - UNKWORD WORD_0x0; - u32 INT_0x4; - u32 INT_0x8; - u32 INT_0xC; - UNKWORD WORD_0x10; - }; - - struct FileInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - const char * mExternalFileName; // at 0x8 - u32 SIZE_0xC; - }; - - struct FilePos - { - u32 mGroupIndex; // at 0x0 - u32 mGroupItemIndex; // at 0x4 - }; - - virtual ~SoundArchive(); // at 0x8 - virtual const void * detail_GetFileAddress(u32) const = 0; // at 0xc - virtual const void * detail_GetWaveDataFileAddress(u32) const = 0; // at 0x10 - virtual int detail_GetRequiredStreamBufferSize() const = 0; // at 0x14 - virtual ut::FileStream * OpenStream(void *, int, u32, u32) const = 0; // at 0x18 - virtual ut::FileStream * OpenExtStream(void *, int, const char *, u32, u32) const = 0; // at 0x1c - - detail::SoundArchiveFileReader * mFileReader; // at 0x4 - char mExternalFileRoot[0x100]; // at 0x8 - - SoundArchive(); - - bool IsAvailable() const; - - void Setup(detail::SoundArchiveFileReader *); - void Shutdown(); - - u32 GetPlayerCount() const; - u32 GetGroupCount() const; - - const char * GetSoundLabelString(u32) const; - - u32 ConvertLabelStringToSoundId(const char *) const; - u32 ConvertLabelStringToPlayerId(const char *) const; - u32 ConvertLabelStringToGroupId(const char *) const; - - UNKWORD GetSoundUserParam(u32) const; - UNKWORD GetSoundType(u32) const; - - bool ReadSoundInfo(u32, SoundInfo *) const; - - bool detail_ReadSeqSoundInfo(u32, SeqSoundInfo *) const; - bool detail_ReadStrmSoundInfo(u32, StrmSoundInfo *) const; - bool detail_ReadWaveSoundInfo(u32, WaveSoundInfo *) const; - - bool ReadPlayerInfo(u32, PlayerInfo *) const; - - bool ReadSoundArchivePlayerInfo(SoundArchivePlayerInfo *) const; - - bool detail_ReadSound3DParam(u32, Sound3DParam *) const; - - bool detail_ReadBankInfo(u32, BankInfo *) const; - bool detail_ReadGroupInfo(u32, GroupInfo *) const; - bool detail_ReadGroupItemInfo(u32, u32, GroupItemInfo *) const; - bool detail_ReadFileInfo(u32, FileInfo *) const; - bool detail_ReadFilePos(u32, u32, FilePos *) const; - - ut::FileStream * OpenExtStreamImpl(void *, int, const char *, u32, u32) const; //inlined - ut::FileStream * detail_OpenFileStream(u32, void *, int) const; - ut::FileStream * detail_OpenGroupStream(u32, void *, int) const; - ut::FileStream * detail_OpenGroupWaveDataStream(u32, void *, int) const; - - UNKTYPE SetExternalFileRoot(const char *); - }; - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +struct SoundArchive { + struct Sound3DParam { + UNKWORD WORD_0x0; + u8 BYTE_0x4; + u8 BYTE_0x5; + }; + + struct SoundArchivePlayerInfo { + u32 SIZE_0x0; + UNKWORD WORD_0x4; + u32 SIZE_0x8; + UNKWORD WORD_0xC; + UNKWORD WORD_0x10; + u32 SIZE_0x14; + UNKWORD WORD_0x18; + }; + + struct SoundInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + UNKWORD WORD_0x8; + UNKWORD WORD_0xC; + UNKWORD WORD_0x10; + UNKWORD WORD_0x14; + UNKWORD WORD_0x18; + }; + + struct SeqSoundInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + UNKWORD WORD_0x8; + UNKWORD WORD_0xC; + bool BOOL_0x10; + }; + + struct StrmSoundInfo {}; + + struct WaveSoundInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + bool BOOL_0x8; + }; + + struct BankInfo { + UNKWORD WORD_0x0; + }; + + struct PlayerInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + }; + + struct GroupInfo { + u32 mCount; // at 0x0 + const char *mExternalFileName; // at 0x4 + u32 INT_0x8; + u32 INT_0xC; + u32 INT_0x10; + u32 INT_0x14; + }; + + struct GroupItemInfo { + UNKWORD WORD_0x0; + u32 INT_0x4; + u32 INT_0x8; + u32 INT_0xC; + UNKWORD WORD_0x10; + }; + + struct FileInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + const char *mExternalFileName; // at 0x8 + u32 SIZE_0xC; + }; + + struct FilePos { + u32 mGroupIndex; // at 0x0 + u32 mGroupItemIndex; // at 0x4 + }; + + virtual ~SoundArchive(); // at 0x8 + virtual const void *detail_GetFileAddress(u32) const = 0; // at 0xc + virtual const void *detail_GetWaveDataFileAddress(u32) const = 0; // at 0x10 + virtual int detail_GetRequiredStreamBufferSize() const = 0; // at 0x14 + virtual ut::FileStream *OpenStream(void *, int, u32, u32) const = 0; // at 0x18 + virtual ut::FileStream *OpenExtStream(void *, int, const char *, u32, u32) const = 0; // at 0x1c + + detail::SoundArchiveFileReader *mFileReader; // at 0x4 + char mExternalFileRoot[0x100]; // at 0x8 + + SoundArchive(); + + bool IsAvailable() const; + + void Setup(detail::SoundArchiveFileReader *); + void Shutdown(); + + u32 GetPlayerCount() const; + u32 GetGroupCount() const; + + const char *GetSoundLabelString(u32) const; + + u32 ConvertLabelStringToSoundId(const char *) const; + u32 ConvertLabelStringToPlayerId(const char *) const; + u32 ConvertLabelStringToGroupId(const char *) const; + + UNKWORD GetSoundUserParam(u32) const; + UNKWORD GetSoundType(u32) const; + + bool ReadSoundInfo(u32, SoundInfo *) const; + + bool detail_ReadSeqSoundInfo(u32, SeqSoundInfo *) const; + bool detail_ReadStrmSoundInfo(u32, StrmSoundInfo *) const; + bool detail_ReadWaveSoundInfo(u32, WaveSoundInfo *) const; + + bool ReadPlayerInfo(u32, PlayerInfo *) const; + + bool ReadSoundArchivePlayerInfo(SoundArchivePlayerInfo *) const; + + bool detail_ReadSound3DParam(u32, Sound3DParam *) const; + + bool detail_ReadBankInfo(u32, BankInfo *) const; + bool detail_ReadGroupInfo(u32, GroupInfo *) const; + bool detail_ReadGroupItemInfo(u32, u32, GroupItemInfo *) const; + bool detail_ReadFileInfo(u32, FileInfo *) const; + bool detail_ReadFilePos(u32, u32, FilePos *) const; + + ut::FileStream *OpenExtStreamImpl(void *, int, const char *, u32, u32) const; // inlined + ut::FileStream *detail_OpenFileStream(u32, void *, int) const; + ut::FileStream *detail_OpenGroupStream(u32, void *, int) const; + ut::FileStream *detail_OpenGroupWaveDataStream(u32, void *, int) const; + + UNKTYPE SetExternalFileRoot(const char *); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundArchiveFile.h b/include/nw4r/snd/snd_SoundArchiveFile.h index eff6e904..d3af2f18 100644 --- a/include/nw4r/snd/snd_SoundArchiveFile.h +++ b/include/nw4r/snd/snd_SoundArchiveFile.h @@ -1,278 +1,245 @@ #ifndef NW4R_SND_SOUND_ARCHIVE_FILE_H #define NW4R_SND_SOUND_ARCHIVE_FILE_H -#include "types_nw4r.h" -#include "ut_binaryFileFormat.h" -#include "snd_Util.h" +#include "common.h" #include "snd_SoundArchive.h" +#include "snd_Util.h" +#include "ut_binaryFileFormat.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - namespace SoundArchiveFile - { - struct Header - { - ut::BinaryFileHeader mHeader; // at 0x0 - u32 mLabelStringChunkOffset; // at 0x10 - u32 mLabelStringChunkSize; // at 0x14 - u32 mInfoChunkOffset; // at 0x18 - u32 mInfoChunkSize; // at 0x1c - UNKWORD UNK_0x20[0x8 / sizeof(UNKWORD)]; // at 0x20 - }; - - struct Sound3DParam - { - UNKWORD WORD_0x0; - u8 BYTE_0x4; - u8 BYTE_0x5; - }; - - struct SeqSoundInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - UNKWORD WORD_0x8; - u8 BYTE_0xC; - u8 BYTE_0xD; - }; - - struct StrmSoundInfo - { - - }; - - struct WaveSoundInfo - { - UNKWORD WORD_0x0; - char UNK_0x4[0x4]; - u8 BYTE_0x8; - u8 BYTE_0x9; - }; - - typedef Util::DataRef SoundInfoOffset; - - struct SoundCommonInfo - { - u32 mSoundStringId; // at 0x0 - UNKWORD WORD_0x4; - UNKWORD WORD_0x8; - Util::DataRef mSound3DParam; // at 0xc - u8 BYTE_0x14; - u8 BYTE_0x15; - u8 mType; // at 0x16 - u8 BYTE_0x17; - SoundInfoOffset mSoundInfoOffset; // at 0x18 - UNKWORD mSoundUserParam; // at 0x20 - char UNK_0x24[0x4]; - u8 BYTE_0x28; - u8 BYTE_0x29; - }; - - typedef Util::Table > SoundCommonTable; - - struct BankInfo - { - char UNK_0x0[0x4]; - UNKWORD WORD_0x4; - }; - - typedef Util::Table > BankTable; - - struct PlayerInfo - { - char UNK_0x0[0x4]; - u8 BYTE_0x4; - UNKWORD WORD_0x8; - }; - - typedef Util::Table > PlayerTable; - - struct GroupItemInfo - { - UNKWORD WORD_0x0; - u32 INT_0x4; - u32 INT_0x8; - u32 INT_0xC; - UNKWORD WORD_0x10; - }; - - typedef Util::Table > GroupItemTable; - - struct GroupInfo - { - char UNK_0x0[0x8]; - Util::DataRef mExternalFileName; // at 0x8 - u32 INT_0x10; - u32 INT_0x14; - u32 INT_0x18; - u32 INT_0x1C; - Util::DataRef mGroupItemTable; // at 0x20 - }; - - typedef Util::Table > GroupTable; - - struct SoundArchivePlayerInfo - { - u16 SIZE_0x0; - u16 SHORT_0x2; - u16 SIZE_0x4; - u16 SHORT_0x6; - u16 SHORT_0x8; - u16 SIZE_0xA; - u16 SHORT_0xC; - }; - - typedef Util::Table > FilePosTable; - - struct FileInfo - { - UNKWORD WORD_0x0; - UNKWORD WORD_0x4; - char UNK_0x8[0x4]; - Util::DataRef mExternalFileName; // at 0xc - Util::DataRef TABLE_0x14; - }; - - typedef Util::Table > FileTable; - - struct StringNode - { - enum - { - FLAG_LEAF = 0x0001 - }; - - u16 mFlags; // at 0x0 - u16 SHORT_0x2; - u32 mLeftIndex; // at 0x4 - u32 mRightIndex; // at 0x8 - u32 mStringId; // at 0xc - u32 mId; // at 0x10 - }; - - struct StringTree - { - u32 mRootIndex; // at 0x0 - u32 INT_0x4; - StringNode mNodes[]; // at 0x8 - }; - - struct StringChunk - { - u32 mTableOffset; // at 0x0 - u32 mSoundTreeOffset; // at 0x4 - u32 mPlayerTreeOffset; // at 0x8 - u32 mGroupTreeOffset; // at 0xc - u32 OFFSET_0x10; - }; - - struct InfoChunk - { - Util::DataRef mSoundCommonTable; // at 0x0 - Util::DataRef mBankTable; // at 0x8 - Util::DataRef mPlayerTable; // at 0x10 - Util::DataRef mFileTable; // at 0x18 - Util::DataRef mGroupTable; // at 0x20 - Util::DataRef mSoundArchivePlayerInfo; // at 0x28 - }; - }; - - struct SoundArchiveFileReader - { - struct StringBlock - { - ut::BinaryBlockHeader mHeader; // at 0x0 - SoundArchiveFile::StringChunk mChunk; // at 0x8 - }; - - struct InfoBlock - { - ut::BinaryBlockHeader mHeader; // at 0x0 - SoundArchiveFile::InfoChunk mChunk; // at 0x8 - }; - - SoundArchiveFile::Header mHeader; // at 0x0 - - const SoundArchiveFile::InfoChunk * mInfoChunk; // at 0x28 - const SoundArchiveFile::StringChunk * mStringChunk; // at 0x2c - const Util::Table * mStringTable; // at 0x30 - const SoundArchiveFile::StringTree * mSoundStringTree; // at 0x34 - const SoundArchiveFile::StringTree * mPlayerStringTree; // at 0x38 - const SoundArchiveFile::StringTree * mGroupStringTree; // at 0x3c - const UNKTYPE * PTR_0x40; - - SoundArchiveFileReader(); - - bool IsValidFileHeader(const void *); //inlined - void Init(const void *); - - const void * GetPtrConst(const void *, u32) const; //inlined - - void SetStringChunk(const void *, u32); - void SetInfoChunk(const void *, u32); - - UNKWORD GetSoundType(u32) const; - - const SoundArchiveFile::SoundCommonInfo * impl_GetSoundInfo(u32) const; //inlined - bool ReadSoundInfo(u32, SoundArchive::SoundInfo *) const; - bool ReadSound3DParam(u32, SoundArchive::Sound3DParam *) const; - bool ReadSeqSoundInfo(u32, SoundArchive::SeqSoundInfo *) const; - bool ReadStrmSoundInfo(u32, SoundArchive::StrmSoundInfo *) const; - bool ReadWaveSoundInfo(u32, SoundArchive::WaveSoundInfo *) const; - const SoundArchiveFile::BankInfo * impl_GetBankInfo(u32) const; //inlined - bool ReadBankInfo(u32, SoundArchive::BankInfo *) const; - const SoundArchiveFile::PlayerInfo * impl_GetPlayerInfo(u32) const; //inlined - bool ReadPlayerInfo(u32, SoundArchive::PlayerInfo *) const; - const SoundArchiveFile::GroupInfo * impl_GetGroupInfo(u32) const; //inlined - bool ReadGroupInfo(u32, SoundArchive::GroupInfo *) const; - bool ReadGroupItemInfo(u32, u32, SoundArchive::GroupItemInfo *) const; - bool ReadSoundArchivePlayerInfo(SoundArchive::SoundArchivePlayerInfo *) const; - - u32 GetPlayerCount() const; - u32 GetGroupCount() const; - - u32 GetSoundStringId(u32) const; //inlined - const char * GetString(u32) const; //inlined - const char * GetSoundLabelString(u32) const; - UNKWORD GetSoundUserParam(u32) const; - - bool ReadFileInfo(u32, SoundArchive::FileInfo *) const; - bool ReadFilePos(u32, u32, SoundArchive::FilePos *) const; - - u32 ConvertLabelStringToId(const SoundArchiveFile::StringTree *, const char *) const; - - SoundArchiveFile::SoundInfoOffset impl_GetSoundInfoOffset(u32) const; - - inline u16 GetVersion() const - { - return mHeader.mHeader.version; - } - - inline u32 GetLabelStringChunkOffset() const - { - return mHeader.mLabelStringChunkOffset; - } - - inline u32 GetLabelStringChunkSize() const - { - return mHeader.mLabelStringChunkSize; - } - - inline u32 GetInfoChunkOffset() const - { - return mHeader.mInfoChunkOffset; - } - - inline u32 GetInfoChunkSize() const - { - return mHeader.mInfoChunkSize; - } - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +namespace SoundArchiveFile { +struct Header { + ut::BinaryFileHeader mHeader; // at 0x0 + u32 mLabelStringChunkOffset; // at 0x10 + u32 mLabelStringChunkSize; // at 0x14 + u32 mInfoChunkOffset; // at 0x18 + u32 mInfoChunkSize; // at 0x1c + UNKWORD UNK_0x20[0x8 / sizeof(UNKWORD)]; // at 0x20 +}; -#endif \ No newline at end of file +struct Sound3DParam { + UNKWORD WORD_0x0; + u8 BYTE_0x4; + u8 BYTE_0x5; +}; + +struct SeqSoundInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + UNKWORD WORD_0x8; + u8 BYTE_0xC; + u8 BYTE_0xD; +}; + +struct StrmSoundInfo {}; + +struct WaveSoundInfo { + UNKWORD WORD_0x0; + char UNK_0x4[0x4]; + u8 BYTE_0x8; + u8 BYTE_0x9; +}; + +typedef Util::DataRef SoundInfoOffset; + +struct SoundCommonInfo { + u32 mSoundStringId; // at 0x0 + UNKWORD WORD_0x4; + UNKWORD WORD_0x8; + Util::DataRef mSound3DParam; // at 0xc + u8 BYTE_0x14; + u8 BYTE_0x15; + u8 mType; // at 0x16 + u8 BYTE_0x17; + SoundInfoOffset mSoundInfoOffset; // at 0x18 + UNKWORD mSoundUserParam; // at 0x20 + char UNK_0x24[0x4]; + u8 BYTE_0x28; + u8 BYTE_0x29; +}; + +typedef Util::Table> SoundCommonTable; + +struct BankInfo { + char UNK_0x0[0x4]; + UNKWORD WORD_0x4; +}; + +typedef Util::Table> BankTable; + +struct PlayerInfo { + char UNK_0x0[0x4]; + u8 BYTE_0x4; + UNKWORD WORD_0x8; +}; + +typedef Util::Table> PlayerTable; + +struct GroupItemInfo { + UNKWORD WORD_0x0; + u32 INT_0x4; + u32 INT_0x8; + u32 INT_0xC; + UNKWORD WORD_0x10; +}; + +typedef Util::Table> GroupItemTable; + +struct GroupInfo { + char UNK_0x0[0x8]; + Util::DataRef mExternalFileName; // at 0x8 + u32 INT_0x10; + u32 INT_0x14; + u32 INT_0x18; + u32 INT_0x1C; + Util::DataRef mGroupItemTable; // at 0x20 +}; + +typedef Util::Table> GroupTable; + +struct SoundArchivePlayerInfo { + u16 SIZE_0x0; + u16 SHORT_0x2; + u16 SIZE_0x4; + u16 SHORT_0x6; + u16 SHORT_0x8; + u16 SIZE_0xA; + u16 SHORT_0xC; +}; + +typedef Util::Table> FilePosTable; + +struct FileInfo { + UNKWORD WORD_0x0; + UNKWORD WORD_0x4; + char UNK_0x8[0x4]; + Util::DataRef mExternalFileName; // at 0xc + Util::DataRef TABLE_0x14; +}; + +typedef Util::Table> FileTable; + +struct StringNode { + enum { FLAG_LEAF = 0x0001 }; + + u16 mFlags; // at 0x0 + u16 SHORT_0x2; + u32 mLeftIndex; // at 0x4 + u32 mRightIndex; // at 0x8 + u32 mStringId; // at 0xc + u32 mId; // at 0x10 +}; + +struct StringTree { + u32 mRootIndex; // at 0x0 + u32 INT_0x4; + StringNode mNodes[]; // at 0x8 +}; + +struct StringChunk { + u32 mTableOffset; // at 0x0 + u32 mSoundTreeOffset; // at 0x4 + u32 mPlayerTreeOffset; // at 0x8 + u32 mGroupTreeOffset; // at 0xc + u32 OFFSET_0x10; +}; + +struct InfoChunk { + Util::DataRef mSoundCommonTable; // at 0x0 + Util::DataRef mBankTable; // at 0x8 + Util::DataRef mPlayerTable; // at 0x10 + Util::DataRef mFileTable; // at 0x18 + Util::DataRef mGroupTable; // at 0x20 + Util::DataRef mSoundArchivePlayerInfo; // at 0x28 +}; +}; // namespace SoundArchiveFile + +struct SoundArchiveFileReader { + struct StringBlock { + ut::BinaryBlockHeader mHeader; // at 0x0 + SoundArchiveFile::StringChunk mChunk; // at 0x8 + }; + + struct InfoBlock { + ut::BinaryBlockHeader mHeader; // at 0x0 + SoundArchiveFile::InfoChunk mChunk; // at 0x8 + }; + + SoundArchiveFile::Header mHeader; // at 0x0 + + const SoundArchiveFile::InfoChunk *mInfoChunk; // at 0x28 + const SoundArchiveFile::StringChunk *mStringChunk; // at 0x2c + const Util::Table *mStringTable; // at 0x30 + const SoundArchiveFile::StringTree *mSoundStringTree; // at 0x34 + const SoundArchiveFile::StringTree *mPlayerStringTree; // at 0x38 + const SoundArchiveFile::StringTree *mGroupStringTree; // at 0x3c + const UNKTYPE *PTR_0x40; + + SoundArchiveFileReader(); + + bool IsValidFileHeader(const void *); // inlined + void Init(const void *); + + const void *GetPtrConst(const void *, u32) const; // inlined + + void SetStringChunk(const void *, u32); + void SetInfoChunk(const void *, u32); + + UNKWORD GetSoundType(u32) const; + + const SoundArchiveFile::SoundCommonInfo *impl_GetSoundInfo(u32) const; // inlined + bool ReadSoundInfo(u32, SoundArchive::SoundInfo *) const; + bool ReadSound3DParam(u32, SoundArchive::Sound3DParam *) const; + bool ReadSeqSoundInfo(u32, SoundArchive::SeqSoundInfo *) const; + bool ReadStrmSoundInfo(u32, SoundArchive::StrmSoundInfo *) const; + bool ReadWaveSoundInfo(u32, SoundArchive::WaveSoundInfo *) const; + const SoundArchiveFile::BankInfo *impl_GetBankInfo(u32) const; // inlined + bool ReadBankInfo(u32, SoundArchive::BankInfo *) const; + const SoundArchiveFile::PlayerInfo *impl_GetPlayerInfo(u32) const; // inlined + bool ReadPlayerInfo(u32, SoundArchive::PlayerInfo *) const; + const SoundArchiveFile::GroupInfo *impl_GetGroupInfo(u32) const; // inlined + bool ReadGroupInfo(u32, SoundArchive::GroupInfo *) const; + bool ReadGroupItemInfo(u32, u32, SoundArchive::GroupItemInfo *) const; + bool ReadSoundArchivePlayerInfo(SoundArchive::SoundArchivePlayerInfo *) const; + + u32 GetPlayerCount() const; + u32 GetGroupCount() const; + + u32 GetSoundStringId(u32) const; // inlined + const char *GetString(u32) const; // inlined + const char *GetSoundLabelString(u32) const; + UNKWORD GetSoundUserParam(u32) const; + + bool ReadFileInfo(u32, SoundArchive::FileInfo *) const; + bool ReadFilePos(u32, u32, SoundArchive::FilePos *) const; + + u32 ConvertLabelStringToId(const SoundArchiveFile::StringTree *, const char *) const; + + SoundArchiveFile::SoundInfoOffset impl_GetSoundInfoOffset(u32) const; + + inline u16 GetVersion() const { + return mHeader.mHeader.version; + } + + inline u32 GetLabelStringChunkOffset() const { + return mHeader.mLabelStringChunkOffset; + } + + inline u32 GetLabelStringChunkSize() const { + return mHeader.mLabelStringChunkSize; + } + + inline u32 GetInfoChunkOffset() const { + return mHeader.mInfoChunkOffset; + } + + inline u32 GetInfoChunkSize() const { + return mHeader.mInfoChunkSize; + } +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundArchiveLoader.h b/include/nw4r/snd/snd_SoundArchiveLoader.h index 87f57846..ab33776e 100644 --- a/include/nw4r/snd/snd_SoundArchiveLoader.h +++ b/include/nw4r/snd/snd_SoundArchiveLoader.h @@ -1,52 +1,47 @@ #ifndef NW4R_SND_SOUND_ARCHIVE_LOADER_H #define NW4R_SND_SOUND_ARCHIVE_LOADER_H +#include "common.h" #include "snd_SoundMemoryAllocatable.h" #include "ut_FileStream.h" -#include "types_nw4r.h" #include -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct FileStreamHandle - { - ut::FileStream * mFileStream; - - inline FileStreamHandle(ut::FileStream * pFileStream) : mFileStream(pFileStream) {} - - inline ~FileStreamHandle() - { - if (mFileStream) mFileStream->Close(); - } - - inline operator bool() const - { - return mFileStream; - } - - inline ut::FileStream * operator->() - { - return mFileStream; - } - }; - - struct SoundArchiveLoader - { - OSMutex mMutex; // at 0x0 - const SoundArchive & mArchive; // at 0x18 - u8 mBuffer[0x200]; // at 0x1c - ut::FileStream * mFileStream; // at 0x21c - - SoundArchiveLoader(const SoundArchive &); - ~SoundArchiveLoader(); - - void * LoadGroup(u32, SoundMemoryAllocatable *, void **, u32); - }; - } - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +namespace detail { +struct FileStreamHandle { + ut::FileStream *mFileStream; + + inline FileStreamHandle(ut::FileStream *pFileStream) : mFileStream(pFileStream) {} + + inline ~FileStreamHandle() { + if (mFileStream) { + mFileStream->Close(); + } + } + + inline operator bool() const { + return mFileStream; + } + + inline ut::FileStream *operator->() { + return mFileStream; + } +}; + +struct SoundArchiveLoader { + OSMutex mMutex; // at 0x0 + const SoundArchive &mArchive; // at 0x18 + u8 mBuffer[0x200]; // at 0x1c + ut::FileStream *mFileStream; // at 0x21c + + SoundArchiveLoader(const SoundArchive &); + ~SoundArchiveLoader(); + + void *LoadGroup(u32, SoundMemoryAllocatable *, void **, u32); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundArchivePlayer.h b/include/nw4r/snd/snd_SoundArchivePlayer.h index 0070b4d4..50378b9c 100644 --- a/include/nw4r/snd/snd_SoundArchivePlayer.h +++ b/include/nw4r/snd/snd_SoundArchivePlayer.h @@ -1,53 +1,46 @@ #ifndef NW4R_SND_SOUND_ARCHIVE_PLAYER_H #define NW4R_SND_SOUND_ARCHIVE_PLAYER_H -#include "snd_SoundStartable.h" -#include "snd_SoundHandle.h" +#include "common.h" #include "snd_DisposeCallback.h" +#include "snd_SoundHandle.h" #include "snd_SoundMemoryAllocatable.h" -#include "types_nw4r.h" +#include "snd_SoundStartable.h" -namespace nw4r -{ - namespace snd - { - struct SoundArchivePlayer : detail::DisposeCallback, SoundStartable - { - SoundArchivePlayer(); - ~SoundArchivePlayer(); +namespace nw4r { +namespace snd { +struct SoundArchivePlayer : detail::DisposeCallback, SoundStartable { + SoundArchivePlayer(); + ~SoundArchivePlayer(); - bool IsAvailable() const; - bool Setup(const SoundArchive *, void *, u32, void *, u32); + bool IsAvailable() const; + bool Setup(const SoundArchive *, void *, u32, void *, u32); - void Shutdown(); - u32 GetRequiredMemSize(const SoundArchive *); - u32 GetRequiredStrmBufferSize(const SoundArchive *); + void Shutdown(); + u32 GetRequiredMemSize(const SoundArchive *); + u32 GetRequiredStrmBufferSize(const SoundArchive *); - void Update(); + void Update(); - SoundArchive * GetSoundArchive() const; - SoundPlayer * GetSoundPlayer(u32); + SoundArchive *GetSoundArchive() const; + SoundPlayer *GetSoundPlayer(u32); - UNKWORD detail_SetupSound(SoundHandle *, - u32, - detail::BasicSound::AmbientArgInfo *, - detail::ExternalSoundPlayer *, - bool, - const StartInfo *); + UNKWORD detail_SetupSound(SoundHandle *, u32, detail::BasicSound::AmbientArgInfo *, detail::ExternalSoundPlayer *, + bool, const StartInfo *); - UNKWORD LoadGroup(u32, SoundMemoryAllocatable *, u32); - UNKWORD LoadGroup(const char *, SoundMemoryAllocatable *, u32); + UNKWORD LoadGroup(u32, SoundMemoryAllocatable *, u32); + UNKWORD LoadGroup(const char *, SoundMemoryAllocatable *, u32); - virtual void InvalidateData(const void *, const void *); - virtual void InvalidateWaveData(const void *, const void *); - virtual UNKWORD detail_ConvertLabelStringToSoundId(const char *); + virtual void InvalidateData(const void *, const void *); + virtual void InvalidateWaveData(const void *, const void *); + virtual UNKWORD detail_ConvertLabelStringToSoundId(const char *); - char UNK_0x4[0x8]; - SoundHandle mHandle; // at 0xC - char UNK_0x1C[0x14]; - u32 WORD_0x30; - char UNK_0x34[0xAC]; - }; - } -} + char UNK_0x4[0x8]; + SoundHandle mHandle; // at 0xC + char UNK_0x1C[0x14]; + u32 WORD_0x30; + char UNK_0x34[0xAC]; +}; +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_SoundHandle.h b/include/nw4r/snd/snd_SoundHandle.h index b1071033..7ded3e2f 100644 --- a/include/nw4r/snd/snd_SoundHandle.h +++ b/include/nw4r/snd/snd_SoundHandle.h @@ -1,39 +1,42 @@ #ifndef NW4R_SND_SOUND_HANDLE_H #define NW4R_SND_SOUND_HANDLE_H -#include "types_nw4r.h" +#include "common.h" #include "snd_BasicSound.h" -namespace nw4r -{ - namespace snd - { - struct SoundHandle - { - detail::BasicSound * mSound; // at 0x0 - - void detail_AttachSound(detail::BasicSound *); - void detail_AttachSoundAsTempHandle(detail::BasicSound *); - void DetachSound(); - - inline SoundHandle() : mSound(NULL) {} - - inline ~SoundHandle() - { - DetachSound(); - } +namespace nw4r { +namespace snd { +struct SoundHandle { + detail::BasicSound *mSound; // at 0x0 - inline detail::BasicSound * detail_GetAttachedSound() { return mSound; } + void detail_AttachSound(detail::BasicSound *); + void detail_AttachSoundAsTempHandle(detail::BasicSound *); + void DetachSound(); - inline bool IsAttachedSound() const { return mSound != NULL; } + inline SoundHandle() : mSound(NULL) {} - inline void StartPrepared() - { - if (IsAttachedSound()) mSound->StartPrepared(); - } + inline ~SoundHandle() { + DetachSound(); + } - inline u32 GetId() const { return IsAttachedSound() ? mSound->GetId() : -1; } - }; - } -} + inline detail::BasicSound *detail_GetAttachedSound() { + return mSound; + } -#endif \ No newline at end of file + inline bool IsAttachedSound() const { + return mSound != NULL; + } + + inline void StartPrepared() { + if (IsAttachedSound()) { + mSound->StartPrepared(); + } + } + + inline u32 GetId() const { + return IsAttachedSound() ? mSound->GetId() : -1; + } +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundHeap.h b/include/nw4r/snd/snd_SoundHeap.h index 62987130..7c809994 100644 --- a/include/nw4r/snd/snd_SoundHeap.h +++ b/include/nw4r/snd/snd_SoundHeap.h @@ -1,33 +1,32 @@ #ifndef NW4R_SND_SOUND_HEAP_H #define NW4R_SND_SOUND_HEAP_H -#include "types_nw4r.h" +#include "common.h" #include "snd_FrameHeap.h" #include "snd_SoundMemoryAllocatable.h" #include -namespace nw4r -{ - namespace snd - { - struct SoundHeap : SoundMemoryAllocatable - { - SoundHeap(); - virtual ~SoundHeap(); // VMT 0x8 - bool Create(void *, u32); - void Destroy(); - virtual void * Alloc(u32); // VMT 0xC - void* Alloc(u32, detail::FrameHeap::AllocCallback, void *); - void Clear(); - int SaveState(); - void LoadState(int); - static void DisposeCallbackFunc(void *, u32, void *); +namespace nw4r { +namespace snd { +struct SoundHeap : SoundMemoryAllocatable { + SoundHeap(); + virtual ~SoundHeap(); // VMT 0x8 + bool Create(void *, u32); + void Destroy(); + virtual void *Alloc(u32); // VMT 0xC + void *Alloc(u32, detail::FrameHeap::AllocCallback, void *); + void Clear(); + int SaveState(); + void LoadState(int); + static void DisposeCallbackFunc(void *, u32, void *); - bool IsValid() { return mFrameHeap.PTR_0x0 != NULL; } + bool IsValid() { + return mFrameHeap.PTR_0x0 != NULL; + } - OSMutex mMutex; // 0x00 - detail::FrameHeap mFrameHeap; // 0x1C - }; - } -} + OSMutex mMutex; // 0x00 + detail::FrameHeap mFrameHeap; // 0x1C +}; +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_SoundInstanceManager.h b/include/nw4r/snd/snd_SoundInstanceManager.h index 3bb4a445..0786dbd2 100644 --- a/include/nw4r/snd/snd_SoundInstanceManager.h +++ b/include/nw4r/snd/snd_SoundInstanceManager.h @@ -1,61 +1,57 @@ #ifndef NW4R_SND_SOUND_INSTANCE_MANAGER_H #define NW4R_SND_SOUND_INSTANCE_MANAGER_H -#include -#include "types_nw4r.h" -#include "ut_lock.h" -#include "ut_LinkList.h" #include "snd_InstancePool.h" +#include "ut_LinkList.h" +#include "ut_lock.h" +#include #include "common.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - template - struct SoundInstanceManager - { - MemoryPool mPool; // at 0x0 - ut::LinkList mPriorityList; // at 0x4 - OSMutex mMutex; // at 0x10 - - inline void Free(T * pInstance) - { - ut::detail::AutoLock lock(mMutex); - - if (mPriorityList.IsEmpty()) return; - - mPriorityList.Erase(pInstance); - mPool.Free(pInstance); - } - - inline void InsertPriorityList(T * pInstance, int priority) - { - ut::LinkList::Iterator iter = mPriorityList.GetBeginIter(); - int curPriority; - - while (iter != mPriorityList.GetEndIter()) - { - curPriority = iter->CalcCurrentPlayerPriority(); - - if (priority < curPriority) break; - - iter++; - } - - mPriorityList.Insert(iter, pInstance); - } - - inline void UpdatePriority(T * pInstance, int priority) - { - ut::detail::AutoLock lock(mMutex); - - mPriorityList.Erase(pInstance); - InsertPriorityList(pInstance, priority); - } - }; - } - } -} -#endif \ No newline at end of file +namespace nw4r { +namespace snd { +namespace detail { +template +struct SoundInstanceManager { + MemoryPool mPool; // at 0x0 + ut::LinkList mPriorityList; // at 0x4 + OSMutex mMutex; // at 0x10 + + inline void Free(T *pInstance) { + ut::detail::AutoLock lock(mMutex); + + if (mPriorityList.IsEmpty()) { + return; + } + + mPriorityList.Erase(pInstance); + mPool.Free(pInstance); + } + + inline void InsertPriorityList(T *pInstance, int priority) { + ut::LinkList::Iterator iter = mPriorityList.GetBeginIter(); + int curPriority; + + while (iter != mPriorityList.GetEndIter()) { + curPriority = iter->CalcCurrentPlayerPriority(); + + if (priority < curPriority) { + break; + } + + iter++; + } + + mPriorityList.Insert(iter, pInstance); + } + + inline void UpdatePriority(T *pInstance, int priority) { + ut::detail::AutoLock lock(mMutex); + + mPriorityList.Erase(pInstance); + InsertPriorityList(pInstance, priority); + } +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundMemoryAllocatable.h b/include/nw4r/snd/snd_SoundMemoryAllocatable.h index 218df211..b9701464 100644 --- a/include/nw4r/snd/snd_SoundMemoryAllocatable.h +++ b/include/nw4r/snd/snd_SoundMemoryAllocatable.h @@ -1,17 +1,14 @@ #ifndef NW4R_SOUND_MEMORY_ALLOCATABLE_H #define NW4R_SOUND_MEMORY_ALLOCATABLE_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - struct SoundMemoryAllocatable - { - virtual ~SoundMemoryAllocatable() {} // at 0x8 - virtual void * Alloc(u32) = 0; // at 0xc - }; - } -} +namespace nw4r { +namespace snd { +struct SoundMemoryAllocatable { + virtual ~SoundMemoryAllocatable() {} // at 0x8 + virtual void *Alloc(u32) = 0; // at 0xc +}; +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_SoundPlayer.h b/include/nw4r/snd/snd_SoundPlayer.h index 24ceee98..ec55a461 100644 --- a/include/nw4r/snd/snd_SoundPlayer.h +++ b/include/nw4r/snd/snd_SoundPlayer.h @@ -1,36 +1,36 @@ #ifndef NW4R_SND_SOUND_PLAYER_H #define NW4R_SND_SOUND_PLAYER_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - class SoundPlayer - { - public: +namespace nw4r { +namespace snd { +class SoundPlayer { +public: + f32 GetVolume() const { + return mVolume; + } + f32 detail_GetMainOutVolume() const { + return mMainOutVolume; + } - f32 GetVolume() const { return mVolume; } - f32 detail_GetMainOutVolume() const { return mMainOutVolume; } + void StopAllSound(int); - void StopAllSound(int); + bool detail_IsEnabledOutputLine() const; + int detail_GetOutputLine() const; + f32 detail_GetRemoteOutVolume(int) const; + UNKTYPE detail_FreePlayerHeap(detail::BasicSound *); + UNKTYPE detail_InsertPriorityList(detail::BasicSound *); + UNKTYPE detail_RemoveSoundList(detail::BasicSound *); + UNKTYPE detail_RemovePriorityList(detail::BasicSound *); - bool detail_IsEnabledOutputLine() const; - int detail_GetOutputLine() const; - f32 detail_GetRemoteOutVolume(int) const; - UNKTYPE detail_FreePlayerHeap(detail::BasicSound *); - UNKTYPE detail_InsertPriorityList(detail::BasicSound *); - UNKTYPE detail_RemoveSoundList(detail::BasicSound *); - UNKTYPE detail_RemovePriorityList(detail::BasicSound *); +private: + char UNK_0x0[0x28]; + f32 mVolume; // at 0x28 + bool mEnableOutputLine; // at 0x2C + int mOutputLine; // at 0x30 + f32 mMainOutVolume; // at 0x34 +}; +} // namespace snd +} // namespace nw4r - private: - char UNK_0x0[0x28]; - f32 mVolume; // at 0x28 - bool mEnableOutputLine; // at 0x2C - int mOutputLine; // at 0x30 - f32 mMainOutVolume; // at 0x34 - }; - } -} - -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_SoundStartable.h b/include/nw4r/snd/snd_SoundStartable.h index 2868fd83..99c9f700 100644 --- a/include/nw4r/snd/snd_SoundStartable.h +++ b/include/nw4r/snd/snd_SoundStartable.h @@ -1,48 +1,31 @@ #ifndef NW4R_SND_SOUND_STARTABLE_H #define NW4R_SND_SOUND_STARTABLE_H +#include "common.h" #include "snd_BasicSound.h" -#include "types_nw4r.h" -namespace nw4r -{ - namespace snd - { - struct SoundStartable - { - struct StartInfo - { - - }; - - inline SoundStartable() {} - inline virtual ~SoundStartable() {} // at 0x8 - virtual UNKWORD detail_SetupSound(SoundHandle *, - u32, - detail::BasicSound::AmbientArgInfo *, - detail::ExternalSoundPlayer *, - bool, - const StartInfo *) = 0; // at 0xc - virtual UNKWORD detail_ConvertLabelStringToSoundId(const char *) = 0; // at 0x10 - UNKWORD detail_StartSound(SoundHandle *, - u32, - detail::BasicSound::AmbientArgInfo *, - detail::ExternalSoundPlayer *, - const StartInfo *); +namespace nw4r { +namespace snd { +struct SoundStartable { + struct StartInfo {}; - UNKWORD detail_HoldSound(SoundHandle *, - u32, - detail::BasicSound::AmbientArgInfo *, - detail::ExternalSoundPlayer *, - const StartInfo *); + inline SoundStartable() {} + inline virtual ~SoundStartable() {} // at 0x8 + virtual UNKWORD detail_SetupSound(SoundHandle *, u32, detail::BasicSound::AmbientArgInfo *, + detail::ExternalSoundPlayer *, bool, + const StartInfo *) = 0; // at 0xc + virtual UNKWORD detail_ConvertLabelStringToSoundId(const char *) = 0; // at 0x10 - UNKWORD detail_PrepareSound(SoundHandle *, - u32, - detail::BasicSound::AmbientArgInfo *, - detail::ExternalSoundPlayer *, - const StartInfo *); - }; - } -} + UNKWORD detail_StartSound(SoundHandle *, u32, detail::BasicSound::AmbientArgInfo *, detail::ExternalSoundPlayer *, + const StartInfo *); -#endif \ No newline at end of file + UNKWORD detail_HoldSound(SoundHandle *, u32, detail::BasicSound::AmbientArgInfo *, detail::ExternalSoundPlayer *, + const StartInfo *); + + UNKWORD detail_PrepareSound(SoundHandle *, u32, detail::BasicSound::AmbientArgInfo *, detail::ExternalSoundPlayer *, + const StartInfo *); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_SoundSystem.h b/include/nw4r/snd/snd_SoundSystem.h index c60affc9..4aa4da4c 100644 --- a/include/nw4r/snd/snd_SoundSystem.h +++ b/include/nw4r/snd/snd_SoundSystem.h @@ -1,36 +1,28 @@ #ifndef NW4R_SND_SOUND_SYSTEM_H #define NW4R_SND_SOUND_SYSTEM_H -#include "types_nw4r.h" +#include "common.h" #include "snd_AxManager.h" -namespace nw4r -{ - namespace snd - { - struct SoundSystem - { - struct SoundSystemParam - { +namespace nw4r { +namespace snd { +struct SoundSystem { + struct SoundSystemParam {}; - }; + static inline f32 GetMasterVolume() { + return detail::AxManager::GetInstance().GetMasterVolume(); + } - static inline f32 GetMasterVolume() - { - return detail::AxManager::GetInstance().GetMasterVolume(); - } + static inline void PrepareReset() { + detail::AxManager::GetInstance().PrepareReset(); + } - static inline void PrepareReset() - { - detail::AxManager::GetInstance().PrepareReset(); - } + void InitSoundSystem(s32, s32); + void InitSoundSystem(const SoundSystemParam &, void *, u32); + static void ShutdownSoundSystem(); + static void WaitForResetReady(); + UNKWORD GetRequiredMemSize(const SoundSystemParam &); +}; +} // namespace snd +} // namespace nw4r - void InitSoundSystem(s32, s32); - void InitSoundSystem(const SoundSystemParam&, void *, u32); - static void ShutdownSoundSystem(); - static void WaitForResetReady(); - UNKWORD GetRequiredMemSize(const SoundSystemParam &); - }; - } -} - -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_SoundThread.h b/include/nw4r/snd/snd_SoundThread.h index ca27746d..5e5699a9 100644 --- a/include/nw4r/snd/snd_SoundThread.h +++ b/include/nw4r/snd/snd_SoundThread.h @@ -1,7 +1,7 @@ #ifndef NW4R_SND_SOUND_THREAD_H #define NW4R_SND_SOUND_THREAD_H +#include "common.h" #include "snd_AxManager.h" -#include "types_nw4r.h" #include "ut_LinkList.h" #include #include diff --git a/include/nw4r/snd/snd_StrmChannel.h b/include/nw4r/snd/snd_StrmChannel.h index 20abdcc7..ab6e3fb0 100644 --- a/include/nw4r/snd/snd_StrmChannel.h +++ b/include/nw4r/snd/snd_StrmChannel.h @@ -1,31 +1,27 @@ #ifndef NW4R_SND_STRMCHANNEL_H #define NW4R_SND_STRMCHANNEL_H -#include "types_nw4r.h" +#include "common.h" #define BLOCK_MAX 0x20 -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct StrmBufferPool - { - void Setup(void *, u32, int); - void Shutdown(); - void * Alloc(); - void Free(void *); +namespace nw4r { +namespace snd { +namespace detail { +struct StrmBufferPool { + void Setup(void *, u32, int); + void Shutdown(); + void *Alloc(); + void Free(void *); - void *mBuffer; // at 0x0 - u32 mStrmBufferSize; // at 0x4 - u32 mBlockSize; // at 0x8 - s32 mBlockCount; // at 0xC (< BLOCK_MAX) - s32 mAllocCount; // at 0x10 - u8 mAllocFlags[4]; // at 0x14 (1 bit per block) - }; - } - } -} + void *mBuffer; // at 0x0 + u32 mStrmBufferSize; // at 0x4 + u32 mBlockSize; // at 0x8 + s32 mBlockCount; // at 0xC (< BLOCK_MAX) + s32 mAllocCount; // at 0x10 + u8 mAllocFlags[4]; // at 0x14 (1 bit per block) +}; +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_StrmPlayer.h b/include/nw4r/snd/snd_StrmPlayer.h index 1cd14dba..0bb90337 100644 --- a/include/nw4r/snd/snd_StrmPlayer.h +++ b/include/nw4r/snd/snd_StrmPlayer.h @@ -1,63 +1,58 @@ #ifndef NW4R_SND_STRMPLAYER_H #define NW4R_SND_STRMPLAYER_H -#include "types_nw4r.h" +#include "common.h" #include "snd_BasicPlayer.h" #include "snd_SoundThread.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct StrmPlayer : BasicPlayer, SoundThread::PlayerCallback - { - enum StartOffsetType - { +namespace nw4r { +namespace snd { +namespace detail { +struct StrmPlayer : BasicPlayer, SoundThread::PlayerCallback { + enum StartOffsetType { - }; + }; - virtual ~StrmPlayer(); // at 0x8 - virtual bool Start(); // at 0xc - virtual void Stop(); // at 0x10 - virtual void Pause(bool); // at 0x14 - virtual bool IsActive() const; // at 0x18 - virtual bool IsStarted() const; // at 0x1c - virtual bool IsPause() const; // at 0x20 + virtual ~StrmPlayer(); // at 0x8 + virtual bool Start(); // at 0xc + virtual void Stop(); // at 0x10 + virtual void Pause(bool); // at 0x14 + virtual bool IsActive() const; // at 0x18 + virtual bool IsStarted() const; // at 0x1c + virtual bool IsPause() const; // at 0x20 - virtual void OnUpdateFrameSoundThread(); // at 0xc - virtual void OnUpdateVoiceSoundThread(); // at 0x10 - virtual void OnShutdownSoundThread(); // at 0x14 + virtual void OnUpdateFrameSoundThread(); // at 0xc + virtual void OnUpdateVoiceSoundThread(); // at 0x10 + virtual void OnShutdownSoundThread(); // at 0x14 - struct StrmDataLoadTask - { - virtual ~StrmDataLoadTask(); - virtual UNKTYPE Execute(); - virtual UNKTYPE Cancel(); - virtual UNKTYPE OnCancel(); - }; + struct StrmDataLoadTask { + virtual ~StrmDataLoadTask(); + virtual UNKTYPE Execute(); + virtual UNKTYPE Cancel(); + virtual UNKTYPE OnCancel(); + }; - struct StrmHeaderLoadTask - { - virtual ~StrmHeaderLoadTask(); - virtual UNKTYPE Execute(); - virtual UNKTYPE Cancel(); - virtual UNKTYPE OnCancel(); - }; + struct StrmHeaderLoadTask { + virtual ~StrmHeaderLoadTask(); + virtual UNKTYPE Execute(); + virtual UNKTYPE Cancel(); + virtual UNKTYPE OnCancel(); + }; - bool IsPrepared() const { return mIsPrepared; } - - StrmPlayer(); - bool Setup(StrmBufferPool *); - bool Prepare(ut::FileStream *, int, StartOffsetType, int); - void Shutdown(); - - char UNK_D8[0x113 - 0xD8]; - bool mIsPrepared; // at 0x113 - char UNK_120[0x78C]; - }; - } + bool IsPrepared() const { + return mIsPrepared; } -} -#endif \ No newline at end of file + StrmPlayer(); + bool Setup(StrmBufferPool *); + bool Prepare(ut::FileStream *, int, StartOffsetType, int); + void Shutdown(); + + char UNK_D8[0x113 - 0xD8]; + bool mIsPrepared; // at 0x113 + char UNK_120[0x78C]; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_StrmSound.h b/include/nw4r/snd/snd_StrmSound.h index d77ca533..cb84045e 100644 --- a/include/nw4r/snd/snd_StrmSound.h +++ b/include/nw4r/snd/snd_StrmSound.h @@ -1,39 +1,35 @@ #ifndef NW4R_SND_STRMSOUND_H #define NW4R_SND_STRMSOUND_H -#include "types_nw4r.h" +#include "common.h" #include "snd_BasicSound.h" #include "snd_StrmPlayer.h" #include "ut_RuntimeTypeInfo.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct StrmSound : BasicSound - { - StrmPlayer mPlayer; // at 0xD8 - StrmSoundHandle *mTempSpecialHandle; // at 0x920 - SoundInstanceManager *mManager; // at 0x924 +namespace nw4r { +namespace snd { +namespace detail { +struct StrmSound : BasicSound { + StrmPlayer mPlayer; // at 0xD8 + StrmSoundHandle *mTempSpecialHandle; // at 0x920 + SoundInstanceManager *mManager; // at 0x924 - StrmSound(SoundInstanceManager *); - bool Prepare(StrmBufferPool *, StrmPlayer::StartOffsetType, s32, int, ut::FileStream *); + StrmSound(SoundInstanceManager *); + bool Prepare(StrmBufferPool *, StrmPlayer::StartOffsetType, s32, int, ut::FileStream *); - static ut::detail::RuntimeTypeInfo typeInfo; - - virtual const ut::detail::RuntimeTypeInfo * GetRuntimeTypeInfo() const; // at 0x8 - virtual ~StrmSound(); // at 0xc - virtual UNKTYPE Shutdown(); // at 0x28 - virtual bool IsPrepared() const; // at 0x2c - virtual void SetPlayerPriority(int); // at 0x4c - virtual bool IsAttachedTempSpecialHandle(); // at 0x5c - virtual UNKTYPE DetachTempSpecialHandle(); // at 0x60 - virtual BasicPlayer * GetBasicPlayer(); // at 0x68 - virtual const BasicPlayer * GetBasicPlayer() const; // at 0x6c - }; - } - } -} + static ut::detail::RuntimeTypeInfo typeInfo; -#endif \ No newline at end of file + virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; // at 0x8 + virtual ~StrmSound(); // at 0xc + virtual UNKTYPE Shutdown(); // at 0x28 + virtual bool IsPrepared() const; // at 0x2c + virtual void SetPlayerPriority(int); // at 0x4c + virtual bool IsAttachedTempSpecialHandle(); // at 0x5c + virtual UNKTYPE DetachTempSpecialHandle(); // at 0x60 + virtual BasicPlayer *GetBasicPlayer(); // at 0x68 + virtual const BasicPlayer *GetBasicPlayer() const; // at 0x6c +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_StrmSoundHandle.h b/include/nw4r/snd/snd_StrmSoundHandle.h index c64e61ee..dfafb738 100644 --- a/include/nw4r/snd/snd_StrmSoundHandle.h +++ b/include/nw4r/snd/snd_StrmSoundHandle.h @@ -1,24 +1,20 @@ #ifndef NW4R_SND_STRMSOUNDHANDLE_H #define NW4R_SND_STRMSOUNDHANDLE_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - struct StrmSoundHandle - { - detail::StrmSound *mStrmSound; // at 0x0 +namespace nw4r { +namespace snd { +struct StrmSoundHandle { + detail::StrmSound *mStrmSound; // at 0x0 - inline StrmSoundHandle() : mStrmSound(NULL) {} - inline bool IsAttachedSound() - { - return mStrmSound != NULL; - } - - void DetachSound(); - }; + inline StrmSoundHandle() : mStrmSound(NULL) {} + inline bool IsAttachedSound() { + return mStrmSound != NULL; } -} -#endif \ No newline at end of file + void DetachSound(); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_Task.h b/include/nw4r/snd/snd_Task.h index 688a2c99..6752b996 100644 --- a/include/nw4r/snd/snd_Task.h +++ b/include/nw4r/snd/snd_Task.h @@ -1,28 +1,24 @@ #ifndef NW4R_SND_TASK_H #define NW4R_SND_TASK_H -#include "types_nw4r.h" +#include "common.h" #include "ut_LinkList.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct Task - { - virtual ~Task(); // at 0x8 - virtual void Execute() = 0; // at 0xc - virtual void Cancel() = 0; // at 0x10 - virtual void OnCancel() = 0; // at 0x14 - - ut::LinkListNode mNode; // at 0x4 - char BYTE_0xC; - - inline Task() : BYTE_0xC() {} - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct Task { + virtual ~Task(); // at 0x8 + virtual void Execute() = 0; // at 0xc + virtual void Cancel() = 0; // at 0x10 + virtual void OnCancel() = 0; // at 0x14 -#endif \ No newline at end of file + ut::LinkListNode mNode; // at 0x4 + char BYTE_0xC; + + inline Task() : BYTE_0xC() {} +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_TaskManager.h b/include/nw4r/snd/snd_TaskManager.h index 978fe886..1ef6f72d 100644 --- a/include/nw4r/snd/snd_TaskManager.h +++ b/include/nw4r/snd/snd_TaskManager.h @@ -1,7 +1,7 @@ #ifndef NW4R_SND_TASK_MANAGER_H #define NW4R_SND_TASK_MANAGER_H +#include "common.h" #include "snd_Task.h" -#include "types_nw4r.h" #include "ut_LinkList.h" #include "ut_lock.h" #include diff --git a/include/nw4r/snd/snd_TaskThread.h b/include/nw4r/snd/snd_TaskThread.h index 6cb6e4df..b966af2a 100644 --- a/include/nw4r/snd/snd_TaskThread.h +++ b/include/nw4r/snd/snd_TaskThread.h @@ -1,6 +1,6 @@ #ifndef NW4R_SND_TASKTHREAD_H #define NW4R_SND_TASKTHREAD_H -#include "types_nw4r.h" +#include "common.h" #include namespace nw4r { diff --git a/include/nw4r/snd/snd_Util.h b/include/nw4r/snd/snd_Util.h index dd48ddf5..a3c086d7 100644 --- a/include/nw4r/snd/snd_Util.h +++ b/include/nw4r/snd/snd_Util.h @@ -1,78 +1,66 @@ #ifndef NW4R_SND_UTIL_H #define NW4R_SND_UTIL_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - namespace Util - { - enum RefType - { - REFTYPE_ADDRESS, - REFTYPE_OFFSET, - }; - - template - struct DataRef - { - u8 mType; // at 0x0 - u8 BYTE_0x1; - u32 INT_0x4; - }; - - template - struct Table - { - u32 mCount; // at 0x0 - T mEntries[]; // at 0x4 - }; - - struct PanInfo - { - u32 mPanTableID; // 0x0, (PanTableTable) - bool BOOL_0x4; - bool BOOL_0x5; - }; +namespace nw4r { +namespace snd { +namespace detail { +namespace Util { +enum RefType { + REFTYPE_ADDRESS, + REFTYPE_OFFSET, +}; - template - inline const T0 * GetDataRefAddress0(const DataRef & dataRef, const void * ptr) - { - return (const T0 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); - } - - template - inline const T1 * GetDataRefAddress1(const DataRef & dataRef, const void * ptr) - { - return (const T1 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); - } - - template - inline const T2 * GetDataRefAddress2(const DataRef & dataRef, const void * ptr) - { - return (const T2 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); - } - - template - inline const T3 * GetDataRefAddress3(const DataRef & dataRef, const void * ptr) - { - return (const T3 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); - } +template +struct DataRef { + u8 mType; // at 0x0 + u8 BYTE_0x1; + u32 INT_0x4; +}; - f32 CalcPitchRatio(int); - f32 CalcVolumeRatio(f32); - f32 CalcPanRatio(f32, const PanInfo&); - f32 CalcSurroundPanRatio(f32, const PanInfo&); - int CalcLpfFreq(f32); - void GetRemoteFilterCoefs(int, u16 *, u16 *, u16 *, u16 *, u16 *); - u16 CalcRandom(); - const void * GetDataRefAddressImpl(RefType, u32, const void *); - } - } - } +template +struct Table { + u32 mCount; // at 0x0 + T mEntries[]; // at 0x4 +}; + +struct PanInfo { + u32 mPanTableID; // 0x0, (PanTableTable) + bool BOOL_0x4; + bool BOOL_0x5; +}; + +template +inline const T0 *GetDataRefAddress0(const DataRef &dataRef, const void *ptr) { + return (const T0 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); } -#endif \ No newline at end of file +template +inline const T1 *GetDataRefAddress1(const DataRef &dataRef, const void *ptr) { + return (const T1 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); +} + +template +inline const T2 *GetDataRefAddress2(const DataRef &dataRef, const void *ptr) { + return (const T2 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); +} + +template +inline const T3 *GetDataRefAddress3(const DataRef &dataRef, const void *ptr) { + return (const T3 *)GetDataRefAddressImpl((RefType)dataRef.mType, dataRef.INT_0x4, ptr); +} + +f32 CalcPitchRatio(int); +f32 CalcVolumeRatio(f32); +f32 CalcPanRatio(f32, const PanInfo &); +f32 CalcSurroundPanRatio(f32, const PanInfo &); +int CalcLpfFreq(f32); +void GetRemoteFilterCoefs(int, u16 *, u16 *, u16 *, u16 *, u16 *); +u16 CalcRandom(); +const void *GetDataRefAddressImpl(RefType, u32, const void *); +} // namespace Util +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_Voice.h b/include/nw4r/snd/snd_Voice.h index f96b19d1..7052e7cf 100644 --- a/include/nw4r/snd/snd_Voice.h +++ b/include/nw4r/snd/snd_Voice.h @@ -1,67 +1,57 @@ #ifndef NW4R_SND_VOICE_H #define NW4R_SND_VOICE_H -#include "types_nw4r.h" +#include "common.h" #include "snd_AxManager.h" -#include "snd_WaveFile.h" #include "snd_Common.h" +#include "snd_WaveFile.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct Voice - { - enum VoiceCallbackStatus - { - STATUS_0, - STATUS_1, - STATUS_2, - STATUS_3 - }; +namespace nw4r { +namespace snd { +namespace detail { +struct Voice { + enum VoiceCallbackStatus { STATUS_0, STATUS_1, STATUS_2, STATUS_3 }; - enum VoiceSyncFlag { - SYNC_AX_SRC_INITIAL = (1 << 0), - SYNC_AX_VOICE = (1 << 1), - SYNC_AX_SRC = (1 << 2), - SYNC_AX_VE = (1 << 3), - SYNC_AX_MIX = (1 << 4), - SYNC_AX_LPF = (1 << 5), - SYNC_AX_REMOTE = (1 << 7), - SYNC_AX_BIQUAD = (1 << 8), - }; - - typedef void (* VoiceCallback)(Voice *, VoiceCallbackStatus, void *); - - UNKTYPE Start(); - UNKTYPE Setup(const WaveData &, u32); - UNKTYPE SetPriority(int); - UNKTYPE Stop(); - UNKTYPE Free(); - UNKTYPE SetPanMode(PanMode); - UNKTYPE SetPanCurve(PanCurve); - UNKTYPE SetVolume(float); - UNKTYPE SetVeVolume(float, float); - UNKTYPE SetPitch(float); - UNKTYPE SetPan(float); - UNKTYPE SetSurroundPan(float); - UNKTYPE SetLpfFreq(float); - UNKTYPE SetRemoteFilter(int); - UNKTYPE SetOutputLine(int); - UNKTYPE SetMainOutVolume(float); - UNKTYPE SetMainSend(float); - - UNKTYPE SetFxSend(AuxBus, float); - - UNKTYPE SetRemoteOutVolume(int, float); - UNKTYPE SetRemoteSend(int, float); - UNKTYPE SetRemoteFxSend(int, float); - - UNKTYPE Pause(bool); - }; - } - } -} + enum VoiceSyncFlag { + SYNC_AX_SRC_INITIAL = (1 << 0), + SYNC_AX_VOICE = (1 << 1), + SYNC_AX_SRC = (1 << 2), + SYNC_AX_VE = (1 << 3), + SYNC_AX_MIX = (1 << 4), + SYNC_AX_LPF = (1 << 5), + SYNC_AX_REMOTE = (1 << 7), + SYNC_AX_BIQUAD = (1 << 8), + }; -#endif \ No newline at end of file + typedef void (*VoiceCallback)(Voice *, VoiceCallbackStatus, void *); + + UNKTYPE Start(); + UNKTYPE Setup(const WaveData &, u32); + UNKTYPE SetPriority(int); + UNKTYPE Stop(); + UNKTYPE Free(); + UNKTYPE SetPanMode(PanMode); + UNKTYPE SetPanCurve(PanCurve); + UNKTYPE SetVolume(float); + UNKTYPE SetVeVolume(float, float); + UNKTYPE SetPitch(float); + UNKTYPE SetPan(float); + UNKTYPE SetSurroundPan(float); + UNKTYPE SetLpfFreq(float); + UNKTYPE SetRemoteFilter(int); + UNKTYPE SetOutputLine(int); + UNKTYPE SetMainOutVolume(float); + UNKTYPE SetMainSend(float); + + UNKTYPE SetFxSend(AuxBus, float); + + UNKTYPE SetRemoteOutVolume(int, float); + UNKTYPE SetRemoteSend(int, float); + UNKTYPE SetRemoteFxSend(int, float); + + UNKTYPE Pause(bool); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_VoiceManager.h b/include/nw4r/snd/snd_VoiceManager.h index 1706d975..36affe50 100644 --- a/include/nw4r/snd/snd_VoiceManager.h +++ b/include/nw4r/snd/snd_VoiceManager.h @@ -1,25 +1,21 @@ #ifndef NW4R_SND_VOICE_MANAGER_H #define NW4R_SND_VOICE_MANAGER_H -#include "types_nw4r.h" +#include "common.h" #include "snd_Voice.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct VoiceManager - { - static VoiceManager& GetInstance(); +namespace nw4r { +namespace snd { +namespace detail { +struct VoiceManager { + static VoiceManager &GetInstance(); - Voice * AllocVoice(int, int, int, Voice::VoiceCallback, void *); - void UpdateAllVoices(); - void NotifyVoiceUpdate(); - UNKTYPE UpdateAllVoicesSync(u32); - }; - } - } -} + Voice *AllocVoice(int, int, int, Voice::VoiceCallback, void *); + void UpdateAllVoices(); + void NotifyVoiceUpdate(); + UNKTYPE UpdateAllVoicesSync(u32); +}; +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/nw4r/snd/snd_WaveFile.h b/include/nw4r/snd/snd_WaveFile.h index 0bd32763..0ec8ceda 100644 --- a/include/nw4r/snd/snd_WaveFile.h +++ b/include/nw4r/snd/snd_WaveFile.h @@ -1,39 +1,30 @@ #ifndef NW4R_SND_WAVE_FILE_H #define NW4R_SND_WAVE_FILE_H -#include "types_nw4r.h" -#include "ut_binaryFileFormat.h" +#include "common.h" #include "snd_Util.h" +#include "ut_binaryFileFormat.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct WaveData - { - char UNK_0x0[0x2]; - u8 BYTE_0x2; - char UNK_0x4[0x90]; - }; - - struct WaveFile - { - struct WaveInfo - { - - }; - - typedef Util::DataRef Region; - }; - - struct WaveFileReader - { - WaveFileReader(const WaveFile::WaveInfo *); - bool ReadWaveParam(WaveData *, const void *) const; - }; - } - } -} +namespace nw4r { +namespace snd { +namespace detail { +struct WaveData { + char UNK_0x0[0x2]; + u8 BYTE_0x2; + char UNK_0x4[0x90]; +}; -#endif \ No newline at end of file +struct WaveFile { + struct WaveInfo {}; + + typedef Util::DataRef Region; +}; + +struct WaveFileReader { + WaveFileReader(const WaveFile::WaveInfo *); + bool ReadWaveParam(WaveData *, const void *) const; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_WaveSound.h b/include/nw4r/snd/snd_WaveSound.h index aa538ef8..2d588bea 100644 --- a/include/nw4r/snd/snd_WaveSound.h +++ b/include/nw4r/snd/snd_WaveSound.h @@ -1,8 +1,8 @@ #ifndef NW4R_SND_WAVESOUND_H #define NW4R_SND_WAVESOUND_H +#include "common.h" #include "snd_BasicSound.h" #include "snd_WsdPlayer.h" -#include "types_nw4r.h" #include "ut_RuntimeTypeInfo.h" diff --git a/include/nw4r/snd/snd_WaveSoundHandle.h b/include/nw4r/snd/snd_WaveSoundHandle.h index e9a150db..d6d178c8 100644 --- a/include/nw4r/snd/snd_WaveSoundHandle.h +++ b/include/nw4r/snd/snd_WaveSoundHandle.h @@ -1,24 +1,20 @@ #ifndef NW4R_SND_WAVESOUNDHANDLE_H #define NW4R_SND_WAVESOUNDHANDLE_H -#include "types_nw4r.h" +#include "common.h" -namespace nw4r -{ - namespace snd - { - struct WaveSoundHandle - { - detail::WaveSound *mWaveSound; // at 0x0 +namespace nw4r { +namespace snd { +struct WaveSoundHandle { + detail::WaveSound *mWaveSound; // at 0x0 - inline WaveSoundHandle() : mWaveSound(NULL) {} - inline bool IsAttachedSound() - { - return mWaveSound != NULL; - } - - void DetachSound(); - }; + inline WaveSoundHandle() : mWaveSound(NULL) {} + inline bool IsAttachedSound() { + return mWaveSound != NULL; } -} -#endif \ No newline at end of file + void DetachSound(); +}; +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_WsdPlayer.h b/include/nw4r/snd/snd_WsdPlayer.h index 80a2a0b5..67d94663 100644 --- a/include/nw4r/snd/snd_WsdPlayer.h +++ b/include/nw4r/snd/snd_WsdPlayer.h @@ -1,53 +1,47 @@ #ifndef NW4R_SND_WSDPLAYER_H #define NW4R_SND_WSDPLAYER_H -#include "types_nw4r.h" +#include "common.h" #include "snd_BasicPlayer.h" #include "snd_DisposeCallback.h" -#include "snd_SoundThread.h" #include "snd_Lfo.h" +#include "snd_SoundThread.h" -namespace nw4r -{ - namespace snd - { - namespace detail - { - struct WsdPlayer : BasicPlayer, DisposeCallback, SoundThread::PlayerCallback - { - enum StartOffsetType - { +namespace nw4r { +namespace snd { +namespace detail { +struct WsdPlayer : BasicPlayer, DisposeCallback, SoundThread::PlayerCallback { + enum StartOffsetType { - }; + }; - virtual ~WsdPlayer() {} // at 0x8 - virtual bool Start(); // at 0xc - virtual void Stop(); // at 0x10 - virtual void Pause(bool); // at 0x14 - virtual bool IsActive() const; // at 0x18 - virtual bool IsStarted() const; // at 0x1c - virtual bool IsPause() const; // at 0x20 + virtual ~WsdPlayer() {} // at 0x8 + virtual bool Start(); // at 0xc + virtual void Stop(); // at 0x10 + virtual void Pause(bool); // at 0x14 + virtual bool IsActive() const; // at 0x18 + virtual bool IsStarted() const; // at 0x1c + virtual bool IsPause() const; // at 0x20 - virtual void OnUpdateFrameSoundThread(); // at 0xc - virtual void OnUpdateVoiceSoundThread(); // at 0x10 - virtual void OnShutdownSoundThread(); // at 0x14 + virtual void OnUpdateFrameSoundThread(); // at 0xc + virtual void OnUpdateVoiceSoundThread(); // at 0x10 + virtual void OnShutdownSoundThread(); // at 0x14 - virtual void InvalidateData(const void *, const void *); // at 0xc - virtual void InvalidateWaveData(const void *, const void *); // at 0x10 + virtual void InvalidateData(const void *, const void *); // at 0xc + virtual void InvalidateWaveData(const void *, const void *); // at 0x10 - struct WsdCallback - { - virtual ~WsdCallback(); - }; + struct WsdCallback { + virtual ~WsdCallback(); + }; - WsdPlayer(); - bool Prepare(const void *, int, WsdPlayer::StartOffsetType, int, int, const WsdPlayer::WsdCallback *, u32); - void SetChannelPriority(int); - void SetReleasePriorityFix(bool); + WsdPlayer(); + bool Prepare(const void *, int, WsdPlayer::StartOffsetType, int, int, const WsdPlayer::WsdCallback *, u32); + void SetChannelPriority(int); + void SetReleasePriorityFix(bool); - char UNK_0xE4[0x4C]; - }; - } - } -} + char UNK_0xE4[0x4C]; +}; +} // namespace detail +} // namespace snd +} // namespace nw4r -#endif \ No newline at end of file +#endif diff --git a/include/rvl/ARC/arc.h b/include/rvl/ARC/arc.h index 33096322..3e012138 100644 --- a/include/rvl/ARC/arc.h +++ b/include/rvl/ARC/arc.h @@ -59,6 +59,13 @@ typedef struct ARCHandle { s32 entrynum; // at 0x18 } ARCHandle; +typedef struct ARCDir { + ARCHeader *handle; // at 0x0 + u32 entryNum; // at 0x4 + u32 location; // at 0x8 + u32 next; // at 0xC +} ARCDir; + typedef struct ARCFileInfo { ARCHandle *handle; // at 0x0 u32 offset; // at 0x4 diff --git a/include/rvl/GX/GXInternal.h b/include/rvl/GX/GXInternal.h index 40b05fb2..89507bfd 100644 --- a/include/rvl/GX/GXInternal.h +++ b/include/rvl/GX/GXInternal.h @@ -56,9 +56,13 @@ typedef struct _GXLightObjImpl { } GXLightObjImpl; typedef struct _GXTexObjImpl { - u8 todo; + u8 todo[0x20]; } GXTexObjImpl; +typedef struct _GXTlutObjImpl { + u8 todo[0xC]; +} GXTlutObjImpl; + #ifdef __cplusplus } #endif diff --git a/include/rvl/GX/GXTexture.h b/include/rvl/GX/GXTexture.h index 06e33a3b..8f826a2c 100644 --- a/include/rvl/GX/GXTexture.h +++ b/include/rvl/GX/GXTexture.h @@ -7,6 +7,7 @@ extern "C" { #endif GX_DECL_PUBLIC_STRUCT(GXTexObj, 32); +GX_DECL_PUBLIC_STRUCT(GXTlutObj, 12); void __GXSetSUTexRegs(void); diff --git a/src/nw4r/lyt/lyt_animation.cpp b/src/nw4r/lyt/lyt_animation.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_arcResourceAccessor.cpp b/src/nw4r/lyt/lyt_arcResourceAccessor.cpp new file mode 100644 index 00000000..5aab3607 --- /dev/null +++ b/src/nw4r/lyt/lyt_arcResourceAccessor.cpp @@ -0,0 +1,197 @@ +#include "nw4r/lyt/lyt_arcResourceAccessor.h" +#include "nw4r/ut/ut_Font.h" + +namespace { + +// FindNameResource__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCc +s32 FindResourcename(ARCHandle *pArcHandle, const char *resName) { + return 1; +} + +// GetResourceSub__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCcUlPCcPUl +void *GetResourceSub(ARCHandle *pArcHandle, const char *resRootDir, u32 resType, const char *name, u32 *pSize) {} + +} // namespace + +namespace nw4r { +namespace lyt { +// __ct__Q34nw4r3lyt11FontRefLinkFv +FontRefLink::FontRefLink() {} + +// Set__Q34nw4r3lyt11FontRefLinkFPCcPQ34nw4r2ut4Font +void FontRefLink::Set(const char *name, ut::Font *pFont) {} + +// __ct__Q34nw4r3lyt19ArcResourceAccessorFv +ArcResourceAccessor::ArcResourceAccessor() {} + +// Attach__Q34nw4r3lyt19ArcResourceAccessorFPvPCc +bool ArcResourceAccessor::Attach(void *archiveStart, const char *resourceRootDirectory) { + return false; +} + +// Detach__Q34nw4r3lyt19ArcResourceAccessorFv + +// GetResource__Q34nw4r3lyt19ArcResourceAccessorFUlPCcPUl + +// RegistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink + +// UnregistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink + +// GetFont__Q34nw4r3lyt19ArcResourceAccessorFPCc + +// __dt__Q34nw4r3lyt24MultiArcResourceAccessorFv + +} // namespace lyt +} // namespace nw4r + +// 29c03b: <88> TAG_global_subroutine +// AT_sibling(0x29c0dc) +// AT_name("Detach") +// AT_lo_user("Detach__Q34nw4r3lyt19ArcResourceAccessorFv") +// AT_member(0x16271) +// AT_fund_type(FT_pointer) +// AT_low_pc(0x802d50c8) +// AT_high_pc(0x802d5158) + +// 29c093: <38> TAG_formal_parameter +// AT_sibling(0x29c0b9) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) +// AT_location(<5>OP_REG(0x1f) ) + +// 29c0dc: <105> TAG_global_subroutine +// AT_sibling(0x29c1ec) +// AT_name("GetResource") +// AT_lo_user("GetResource__Q34nw4r3lyt19ArcResourceAccessorFUlPCcPUl") +// AT_member(0x16271) +// AT_fund_type(FT_pointer) +// AT_low_pc(0x802d5158) +// AT_high_pc(0x802d51a4) + +// 29c145: <38> TAG_formal_parameter +// AT_sibling(0x29c16b) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) +// AT_location(<5>OP_REG(0x1f) ) + +// 29c16b: <41> TAG_formal_parameter +// AT_sibling(0x29c194) +// AT_name("resType") +// AT_fund_type(FT_unsigned_long) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) + +// 29c194: <42> TAG_formal_parameter +// AT_sibling(0x29c1be) +// AT_name("name") +// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0xc) OP_ADD ) + +// 29c1be: <42> TAG_formal_parameter +// AT_sibling(0x29c1e8) +// AT_name("pSize") +// AT_mod_fund_type(<3>MOD_pointer_to FT_unsigned_long) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x10) OP_ADD ) +// 29c1e8: <4> + +// 29c1ec: <116> TAG_global_subroutine +// AT_sibling(0x29c2b6) +// AT_name("RegistFont") +// AT_lo_user("RegistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink") +// AT_member(0x16271) +// AT_low_pc(0x802d51a4) +// AT_high_pc(0x802d5228) + +// 29c260: <44> TAG_formal_parameter +// AT_sibling(0x29c28c) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) + +// 29c28c: <38> TAG_formal_parameter +// AT_sibling(0x29c2b2) +// AT_name("pLink") +// AT_mod_u_d_type(<5>MOD_pointer_to 0x1613f) +// AT_location(<5>OP_REG(0x1d) ) +// 29c2b2: <4> + +// 29c2b6: <120> TAG_global_subroutine +// AT_sibling(0x29c384) +// AT_name("UnregistFont") +// AT_lo_user("UnregistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink") +// AT_member(0x16271) +// AT_low_pc(0x802d5228) +// AT_high_pc(0x802d52ac) + +// 29c32e: <44> TAG_formal_parameter +// AT_sibling(0x29c35a) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) + +// 29c35a: <38> TAG_formal_parameter +// AT_sibling(0x29c380) +// AT_name("pLink") +// AT_mod_u_d_type(<5>MOD_pointer_to 0x1613f) +// AT_location(<5>OP_REG(0x1d) ) +// 29c380: <4> + +// 29c384: <97> TAG_global_subroutine +// AT_sibling(0x29c43f) +// AT_name("GetFont") +// AT_lo_user("GetFont__Q34nw4r3lyt19ArcResourceAccessorFPCc") +// AT_member(0x16271) +// AT_mod_u_d_type(<5>MOD_pointer_to 0x15c72) +// AT_low_pc(0x802d52ac) +// AT_high_pc(0x802d52e0) + +// 29c3e5: <44> TAG_formal_parameter +// AT_sibling(0x29c411) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) + +// 29c411: <42> TAG_formal_parameter +// AT_sibling(0x29c43b) +// AT_name("name") +// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) +// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0xc) OP_ADD ) +// 29c43b: <4> + +// 29c43f: <95> TAG_global_subroutine +// AT_sibling(0x29c4c8) +// AT_name("__dt") +// AT_lo_user("__dt__Q34nw4r3lyt24MultiArcResourceAccessorFv") +// AT_member(0x63219) +// AT_fund_type(FT_pointer) +// AT_low_pc(0x802d533c) +// AT_high_pc(0x802d53cc) +// (0x29c83e) + +// 29c49e: <38> TAG_formal_parameter +// AT_sibling(0x29c4c4) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x63219) +// AT_location(<5>OP_REG(0x1f) ) +// 29c4c4: <4> + +// AT_name("DetachAll") +// AT_lo_user("DetachAll__Q34nw4r3lyt24MultiArcResourceAccessorFv") + +// AT_name("GetResource") +// AT_lo_user("GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl") +// AT_fund_type(FT_pointer) +// AT_name("this") +// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x63219) +// AT_name("resType") +// AT_fund_type(FT_unsigned_long) +// AT_name("name") +// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) +// AT_name("pSize") +// AT_mod_fund_type(<3>MOD_pointer_to FT_unsigned_long) + +// AT_lo_user("GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc") +// AT_name("name") +// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) + +// "__vt__Q34nw4r3lyt24MultiArcResourceAccessor" +// "__vt__Q34nw4r3lyt19ArcResourceAccessor" diff --git a/src/nw4r/lyt/lyt_bounding.cpp b/src/nw4r/lyt/lyt_bounding.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_common.cpp b/src/nw4r/lyt/lyt_common.cpp new file mode 100644 index 00000000..c5cda80e --- /dev/null +++ b/src/nw4r/lyt/lyt_common.cpp @@ -0,0 +1,189 @@ +#include "nw4r/lyt/lyt_common.h" +#include "nw4r/lyt/lyt_layout.h" +#include "nw4r/lyt/lyt_pane.h" +#include "nw4r/ut/ut_Color.h" +#include "nw4r/ut/ut_algorithm.h" + +namespace nw4r { +namespace lyt { +using namespace math; +using namespace ut; + +// EqualsResName__Q34nw4r3lyt6detailFPCcPCc +bool detail::EqualsResName(const char *name1, const char *name2) { + return strncmp(name1, name2, NW4R_RES_NAME_SIZE) == 0; + ; +} + +// EqualsMaterialName__Q34nw4r3lyt6detailFPCcPCc +bool detail::EqualsMaterialName(const char *name1, const char *name2) { + return strncmp(name1, name2, NW4R_MAT_NAME_SIZE) == 0; +} + +// TestFileHeader__Q34nw4r3lyt6detailFRCQ44nw4r3lyt3res16BinaryFileHeaderUl +bool detail::TestFileHeader(const res::BinaryFileHeader &fileHeader, u32 testSig) { + return ((testSig == fileHeader.magic) && (fileHeader.byteOrder == NW4R_BYTEORDER_BIG)); +} + +namespace detail { +// __ct__Q44nw4r3lyt6detail11TexCoordAryFv +TexCoordAry::TexCoordAry() : mpData(nullptr), mCap(0), mNum(0) {} + +// Free__Q44nw4r3lyt6detail11TexCoordAryFv +void TexCoordAry::Free() { + if (this->mpData) { + Layout::DeleteArray(*this->mpData, this->mNum * TEXCOORD_VTX_COUNT); + this->mpData = nullptr; + this->mCap = 0; + this->mNum = 0; + } +} + +// Reserve__Q44nw4r3lyt6detail11TexCoordAryFUc +void TexCoordAry::Reserve(u8 num) { + if (mCap < num) { + Free(); + const TexCoordData *pData = (TexCoordData *)Layout::NewArray(num * TEXCOORD_VTX_COUNT); + this->mpData = pData ? const_cast(pData) : nullptr; + if (mpData != NULL) { + mCap = num; + } + } +} + +// SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc +void TexCoordAry::SetSize(u8 num) { + if (this->mpData != nullptr && num <= this->mCap) { + static TexCoordData texCoords = {VEC2(0.0f, 0.0f), VEC2(1.0f, 0.0f), VEC2(0.0f, 1.0f), VEC2(1.0f, 1.0f)}; + + for (int i = mNum; i < num; i++) { + for (int j = 0; j < TEXCOORD_VTX_COUNT; j++) { + this->mpData[i][j] = texCoords[j]; + } + } + this->mNum = num; + } +} + +// Copy__Q44nw4r3lyt6detail11TexCoordAryFPCvUc +void TexCoordAry::Copy(const void *pResTexCoord, u8 texCoordNum) { + mNum = Max(mNum, texCoordNum); + + const TexCoordData *src = static_cast(pResTexCoord); + for (int i = 0; i < texCoordNum; i++) { + for (int j = 0; j < TEXCOORD_VTX_COUNT; j++) { + mpData[i][j] = src[i][j]; + } + } +} + +} // namespace detail + +// IsModulateVertexColor__Q34nw4r3lyt6detailFPQ34nw4r2ut5ColorUc +bool detail::IsModulateVertexColor(ut::Color *vtxColors, u8 glbAlpha) { + if (glbAlpha != 0xFF) { + return true; + } + + if ((vtxColors != NULL) && + ((vtxColors[0] != 0xFFFFFFFF) || (vtxColors[1] != 0xFFFFFFFF) || (vtxColors[2] != 0xFFFFFFFF) || + (vtxColors[3] != 0xFFFFFFFF))) { + return true; + } else { + return false; + } +} + +// MultipleAlpha__Q34nw4r3lyt6detailFQ34nw4r2ut5ColorUc +ut::Color detail::MultipleAlpha(ut::Color col, u8 alpha) { + ut::Color ret = col; + if (alpha != 0xFF) { + ret.a = (col.a * alpha) / 0xFF; + } + return ret; +} + +// MultipleAlpha__Q34nw4r3lyt6detailFPQ34nw4r2ut5ColorPCQ34nw4r2ut5ColorUc +void detail::MultipleAlpha(ut::Color *dst, const ut::Color *src, u8 alpha) { + for (int i = 0; i < TEXCOORD_VTX_COUNT; i++) { + dst[i] = MultipleAlpha(src[i], alpha); + } +} + +// SetVertexFormat__Q34nw4r3lyt6detailFbUc +void detail::SetVertexFormat(bool bModulate, u8 textCoordNum) { + GXClearVtxDesc(); + + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + if (bModulate) { + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + } + + for (int i = 0; i < textCoordNum; i++) { + GXSetVtxDesc((GXAttr)(GX_VA_TEX0 + i), GX_DIRECT); + } + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); + if (bModulate) { + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + } + + for (int i = 0; i < textCoordNum; i++) { + GXSetVtxAttrFmt(GX_VTXFMT0, (GXAttr)(GX_VA_TEX0 + i), GX_TEX_ST, GX_F32, 0); + } +} + +// DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5Color +void detail::DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum, const TexCoordData *texCoords, + const ut::Color *vtxColors) { + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + + GXPosition2f32(basePt.x, basePt.y); + if (vtxColors != NULL) { + GXColor1u32(vtxColors[0]); + } + for (int i = 0; i < texCoordNum; i++) { + GXTexCoord2f32(texCoords[i][0].x, texCoords[i][0].y); + } + + GXPosition2f32(basePt.x + size.x, basePt.y); + if (vtxColors != NULL) { + GXColor1u32(vtxColors[1]); + } + for (int i = 0; i < texCoordNum; i++) { + GXTexCoord2f32(texCoords[i][1].x, texCoords[i][1].y); + } + + GXPosition2f32(basePt.x + size.x, basePt.y - size.y); + if (vtxColors != NULL) { + GXColor1u32(vtxColors[3]); + } + for (int i = 0; i < texCoordNum; i++) { + GXTexCoord2f32(texCoords[i][3].x, texCoords[i][3].y); + } + + GXPosition2f32(basePt.x, basePt.y - size.y); + if (vtxColors != NULL) { + GXColor1u32(vtxColors[2]); + } + for (int i = 0; i < texCoordNum; i++) { + GXTexCoord2f32(texCoords[i][2].x, texCoords[i][2].y); + } +} + +// DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5ColorUc +void detail::DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum, const TexCoordData *texCoords, + const ut::Color *vtxColors, u8 alpha) { + ut::Color wkVtxColors[4]; + if (vtxColors) { + MultipleAlpha(wkVtxColors, vtxColors, alpha); + } + DrawQuad(basePt, size, texCoordNum, texCoords, vtxColors ? wkVtxColors : nullptr); +} + +// DrawLine__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeQ34nw4r2ut5Color +void detail::DrawLine(const math::VEC2 &pos, const Size &size, ut::Color color) { + // Not Impl in SS +} +} // namespace lyt +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_drawInfo.cpp b/src/nw4r/lyt/lyt_drawInfo.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_group.cpp b/src/nw4r/lyt/lyt_group.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_init.cpp b/src/nw4r/lyt/lyt_init.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_layout.cpp b/src/nw4r/lyt/lyt_layout.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_picture.cpp b/src/nw4r/lyt/lyt_picture.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_resourceAccessor.cpp b/src/nw4r/lyt/lyt_resourceAccessor.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_texMap.cpp b/src/nw4r/lyt/lyt_texMap.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_textBox.cpp b/src/nw4r/lyt/lyt_textBox.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/lyt/lyt_util.cpp b/src/nw4r/lyt/lyt_util.cpp new file mode 100644 index 00000000..972ab47e --- /dev/null +++ b/src/nw4r/lyt/lyt_util.cpp @@ -0,0 +1,33 @@ + +#include +#include +#include +#include + +namespace nw4r { +namespace lyt { + +namespace { +// Contains__Q34nw4r3lyt22@unnamed@lyt_util_cpp@FRCQ34nw4r2ut4RectRCQ34nw4r4math4VEC2 +bool Contains(const ut::Rect &rect, const math::VEC2 &point) {} +} // namespace + +// BindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb +void BindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive, bool bDisable) {} + +// SetAnimationEnable__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb +void SetAnimationEnable(Group *pGroup, nw4r::lyt::AnimTransform *pAnimTrans, bool bEnable, bool bRecursive) {} + +// IsContain__Q24nw4r3lytFPQ34nw4r3lyt4PaneRCQ34nw4r4math4VEC2 +bool IsContain(Pane *pPane, const math::VEC2 &pos) { + return false; +} + +// FindHitPane__Q24nw4r3lytFPQ34nw4r3lyt4PaneRCQ34nw4r4math4VEC2 +Pane *FindHitPane(Pane *pPane, const math::VEC2 &pos) { + return nullptr; +} + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_window.cpp b/src/nw4r/lyt/lyt_window.cpp new file mode 100644 index 00000000..e69de29b From 230a7d20cec0fae4ad414191d5aa5efbca984a9f Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 18 May 2024 23:18:40 -0400 Subject: [PATCH 02/22] lyt_arcResourceAccessor --- config/SOUE01/config.yml | 9 +- config/SOUE01/splits.txt | 5 + config/SOUE01/symbols.txt | 66 ++--- configure.py | 8 +- include/nw4r/lyt/lyt_arcResourceAccessor.h | 83 ++++-- include/rvl/ARC/arc.h | 12 +- src/nw4r/lyt/lyt_arcResourceAccessor.cpp | 292 ++++++++++----------- 7 files changed, 245 insertions(+), 230 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 3615db70..8ad52f93 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -10,8 +10,15 @@ force_active: [ "ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", "ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", "ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", - # "RemoveResourceBuffer__Q44nw4r2ut6detail11ResFontBaseFv", "RemoveResource__Q34nw4r2ut7ResFontFv", + "Set__Q34nw4r3lyt15ArcResourceLinkFPvPCc", + "__ct__Q34nw4r3lyt24MultiArcResourceAccessorFv", + "__dt__Q34nw4r3lyt24MultiArcResourceAccessorFv", + "Attach__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt15ArcResourceLink", + "GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl", + "RegistFont__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt11FontRefLink", + "GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc", + ] # modules: # - object: orig/SOUE01/rels/d_a_asura_bulletNP.rel diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index cbff745b..ec781942 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -316,6 +316,11 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/lyt/lyt_arcResourceAccessor.cpp: + .text start:0x80492060 end:0x80492780 + .data start:0x8056E7F8 end:0x8056E820 + .sdata start:0x80574EC0 end:0x80574EC8 + nw4r/lyt/lyt_common.cpp: .text start:0x80492780 end:0x804932E0 .sbss start:0x80576720 end:0x80576728 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 33de0e69..cbfd0edc 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -3866,7 +3866,7 @@ fn_800B1630 = .text:0x800B1630; // type:function size:0x3C fn_800B1670 = .text:0x800B1670; // type:function size:0x134 fn_800B17B0 = .text:0x800B17B0; // type:function size:0x8 fn_800B17C0 = .text:0x800B17C0; // type:function size:0x58 -fn_800B1820 = .text:0x800B1820; // type:function size:0x6C +__dt__Q34nw4r3lyt19ArcResourceAccessorFv = .text:0x800B1820; // type:function size:0x6C scope:weak fn_800B1890 = .text:0x800B1890; // type:function size:0x40 fn_800B18D0 = .text:0x800B18D0; // type:function size:0x4D4 fn_800B1DB0 = .text:0x800B1DB0; // type:function size:0x15C @@ -17361,7 +17361,7 @@ searchBaseByGroupType__10fManager_cFUcPC7fBase_c = .text:0x802E2980; // type:fun mainLoop__10fManager_cFv = .text:0x802E29E0; // type:function size:0xC0 __sinit_\f_manager_cpp = .text:0x802E2AA0; // type:function size:0x138 scope:local __ct__9fLiMgBa_cFv = .text:0x802E2BE0; // type:function size:0x10 -__arraydtor$4110 = .text:0x802E2BF0; // type:function size:0x1C scope:local +fn_802E2BF0 = .text:0x802E2BF0; // type:function size:0x1C scope:local walkPack__11fTrMgPTMF_cFv = .text:0x802E2C10; // type:function size:0x84 searchNodeByProfName__9fTrMgBa_cCFUsPC9fTrNdBa_c = .text:0x802E2CA0; // type:function size:0x68 searchNodeByGroupType__9fTrMgBa_cCFUcPC9fTrNdBa_c = .text:0x802E2D10; // type:function size:0x68 @@ -21678,21 +21678,21 @@ fn_8039B0E0 = .text:0x8039B0E0; // type:function size:0x14 fn_8039B100 = .text:0x8039B100; // type:function size:0x180 fn_8039B280 = .text:0x8039B280; // type:function size:0xA8 fn_8039B330 = .text:0x8039B330; // type:function size:0x64 -fn_8039B3A0 = .text:0x8039B3A0; // type:function size:0x1CC -fn_8039B570 = .text:0x8039B570; // type:function size:0xA0 -fn_8039B610 = .text:0x8039B610; // type:function size:0x2AC -fn_8039B8C0 = .text:0x8039B8C0; // type:function size:0x50 -fn_8039B910 = .text:0x8039B910; // type:function size:0x27C -fn_8039BB90 = .text:0x8039BB90; // type:function size:0x1D0 -fn_8039BD60 = .text:0x8039BD60; // type:function size:0x14 -fn_8039BD80 = .text:0x8039BD80; // type:function size:0x8 -fn_8039BD90 = .text:0x8039BD90; // type:function size:0x8 -fn_8039BDA0 = .text:0x8039BDA0; // type:function size:0x8 -fn_8039BDB0 = .text:0x8039BDB0; // type:function size:0x58 -fn_8039BE10 = .text:0x8039BE10; // type:function size:0x7C -fn_8039BE90 = .text:0x8039BE90; // type:function size:0xBC -fn_8039BF50 = .text:0x8039BF50; // type:function size:0x8 -fn_8039BF60 = .text:0x8039BF60; // type:function size:0x54 +__AI_SRC_INIT = .text:0x8039B3A0; // type:function size:0x1CC +ARCInitHandle = .text:0x8039B570; // type:function size:0xA0 +ARCOpen = .text:0x8039B610; // type:function size:0x2AC +ARCFastOpen = .text:0x8039B8C0; // type:function size:0x50 +ARCConvertPathToEntrynum = .text:0x8039B910; // type:function size:0x27C +entryToPath = .text:0x8039BB90; // type:function size:0x1D0 scope:local +ARCGetStartAddrInMem = .text:0x8039BD60; // type:function size:0x14 +ARCGetStartOffset = .text:0x8039BD80; // type:function size:0x8 +ARCGetLength = .text:0x8039BD90; // type:function size:0x8 +ARCClose = .text:0x8039BDA0; // type:function size:0x8 +ARCChangeDir = .text:0x8039BDB0; // type:function size:0x58 +ARCOpenDir = .text:0x8039BE10; // type:function size:0x7C +ARCReadDir = .text:0x8039BE90; // type:function size:0xBC +ARCCloseDir = .text:0x8039BF50; // type:function size:0x8 +AXInit = .text:0x8039BF60; // type:function size:0x54 fn_8039BFC0 = .text:0x8039BFC0; // type:function size:0x8 fn_8039BFD0 = .text:0x8039BFD0; // type:function size:0x14 fn_8039BFF0 = .text:0x8039BFF0; // type:function size:0xAC @@ -22438,7 +22438,7 @@ DVDConvertPathToEntrynum = .text:0x803C3090; // type:function size:0x308 DVDFastOpen = .text:0x803C33A0; // type:function size:0x68 DVDOpen = .text:0x803C3410; // type:function size:0x120 DVDClose = .text:0x803C3530; // type:function size:0x24 -entryToPath = .text:0x803C3560; // type:function size:0x114 +entryToPath = .text:0x803C3560; // type:function size:0x114 scope:local DVDReadAsyncPrio = .text:0x803C3680; // type:function size:0xD0 cbForReadAsync = .text:0x803C3750; // type:function size:0x18 DVDReadPrio = .text:0x803C3770; // type:function size:0x128 @@ -26088,22 +26088,22 @@ __ct__Q34nw4r3lyt16ResourceAccessorFv = .text:0x80492040; // type:function size: GetFont__Q34nw4r3lyt16ResourceAccessorFPCc = .text:0x80492050; // type:function size:0x8 FindNameResource__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCc = .text:0x80492060; // type:function size:0xCC GetResourceSub__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCcUlPCcPUl = .text:0x80492130; // type:function size:0x140 -FUN_80492270 = .text:0x80492270; // type:function size:0x14 -FUN_80492290 = .text:0x80492290; // type:function size:0x40 +__ct__Q34nw4r3lyt11FontRefLinkFv = .text:0x80492270; // type:function size:0x14 +Set__Q34nw4r3lyt11FontRefLinkFPCcPQ34nw4r2ut4Font = .text:0x80492290; // type:function size:0x40 __ct__Q34nw4r3lyt19ArcResourceAccessorFv = .text:0x804922D0; // type:function size:0x54 Attach__Q34nw4r3lyt19ArcResourceAccessorFPvPCc = .text:0x80492330; // type:function size:0x7C Detach__Q34nw4r3lyt19ArcResourceAccessorFv = .text:0x804923B0; // type:function size:0x14 GetResource__Q34nw4r3lyt19ArcResourceAccessorFUlPCcPUl = .text:0x804923D0; // type:function size:0x20 -FUN_804923f0 = .text:0x804923F0; // type:function size:0x6C -FUN_80492460 = .text:0x80492460; // type:function size:0x34 -FUN_804924a0 = .text:0x804924A0; // type:function size:0x8 +Set__Q34nw4r3lyt15ArcResourceLinkFPvPCc = .text:0x804923F0; // type:function size:0x6C +RegistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink = .text:0x80492460; // type:function size:0x34 +UnregistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink = .text:0x804924A0; // type:function size:0x8 GetFont__Q34nw4r3lyt19ArcResourceAccessorFPCc = .text:0x804924B0; // type:function size:0x70 -__ct__Q34nw4r3lyt19MultiArcResourceAccessorFv = .text:0x80492520; // type:function size:0x60 -__dt__Q34nw4r3lyt19MultiArcResourceAccessorFv = .text:0x80492580; // type:function size:0x90 -Attach__Q34nw4r3lyt19MultiArcResourceAccessorFPQ34nw4r3lyt16ArcResourceLink_PCc = .text:0x80492610; // type:function size:0x34 -GetResource__Q34nw4r3lyt19MultiArcResourceAccessorFUlPCcPUl = .text:0x80492650; // type:function size:0x78 -RegistFont__Q34nw4r3lyt19MultiArcResourceAccessorFPQ34nw4r3lyt12FontRefLink_ = .text:0x804926D0; // type:function size:0x34 -GetFont__Q34nw4r3lyt19MultiArcResourceAccessorFPCc = .text:0x80492710; // type:function size:0x70 +__ct__Q34nw4r3lyt24MultiArcResourceAccessorFv = .text:0x80492520; // type:function size:0x60 +__dt__Q34nw4r3lyt24MultiArcResourceAccessorFv = .text:0x80492580; // type:function size:0x90 +Attach__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt15ArcResourceLink = .text:0x80492610; // type:function size:0x34 +GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl = .text:0x80492650; // type:function size:0x78 +RegistFont__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt11FontRefLink = .text:0x804926D0; // type:function size:0x34 +GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc = .text:0x80492710; // type:function size:0x70 EqualsResName__Q34nw4r3lyt6detailFPCcPCc = .text:0x80492780; // type:function size:0x2C EqualsMaterialName__Q34nw4r3lyt6detailFPCcPCc = .text:0x804927B0; // type:function size:0x2C TestFileHeader__Q34nw4r3lyt6detailFRCQ44nw4r3lyt3res16BinaryFileHeaderUl = .text:0x804927E0; // type:function size:0x28 @@ -37088,8 +37088,8 @@ lbl_8056E778 = .data:0x8056E778; // type:object size:0x30 lbl_8056E7A8 = .data:0x8056E7A8; // type:object size:0x10 lbl_8056E7B8 = .data:0x8056E7B8; // type:object size:0x28 lbl_8056E7E0 = .data:0x8056E7E0; // type:object size:0x18 -lbl_8056E7F8 = .data:0x8056E7F8; // type:object size:0x14 -lbl_8056E80C = .data:0x8056E80C; // type:object size:0x14 +__vt__Q34nw4r3lyt24MultiArcResourceAccessor = .data:0x8056E7F8; // type:object size:0x14 +__vt__Q34nw4r3lyt19ArcResourceAccessor = .data:0x8056E80C; // type:object size:0x14 lbl_8056E820 = .data:0x8056E820; // type:object size:0x10 lbl_8056E830 = .data:0x8056E830; // type:object size:0x28 lbl_8056E858 = .data:0x8056E858; // type:object size:0x18 @@ -39588,8 +39588,8 @@ lbl_80574EA0 = .sdata:0x80574EA0; // type:object size:0x8 data:4byte lbl_80574EA8 = .sdata:0x80574EA8; // type:object size:0x8 data:4byte lbl_80574EB0 = .sdata:0x80574EB0; // type:object size:0x8 data:4byte lbl_80574EB8 = .sdata:0x80574EB8; // type:object size:0x8 -lbl_80574EC0 = .sdata:0x80574EC0; // type:object size:0x4 -lbl_80574EC4 = .sdata:0x80574EC4; // type:object size:0x4 +lbl_80574EC0 = .sdata:0x80574EC0; // type:object size:0x2 data:string +lbl_80574EC4 = .sdata:0x80574EC4; // type:object size:0x3 data:string lbl_80574EC8 = .sdata:0x80574EC8; // type:object size:0x8 lbl_80574ED0 = .sdata:0x80574ED0; // type:object size:0x8 data:byte lbl_80574ED8 = .sdata:0x80574ED8; // type:object size:0x8 diff --git a/configure.py b/configure.py index 21bb27b7..3247adcc 100644 --- a/configure.py +++ b/configure.py @@ -203,6 +203,7 @@ cflags_nw4r = [ *cflags_base, "-ipa file", "-fp_contract off", + ] # REL flags @@ -248,11 +249,11 @@ def EGGLib(lib_name, objects): } -def nw4rLib(lib_name, objects): +def nw4rLib(lib_name, objects, extra_cflags=[]): return { "lib": lib_name, "mw_version": "Wii/1.1", # most seem to be around 1.2, snd is 1.6 - "cflags": cflags_nw4r, + "cflags": cflags_nw4r + extra_cflags, "host": False, "objects": objects, } @@ -351,8 +352,9 @@ config.libs = [ nw4rLib( "lyt", [ + Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), - ], + ], [""] ), # EGG EGGLib( diff --git a/include/nw4r/lyt/lyt_arcResourceAccessor.h b/include/nw4r/lyt/lyt_arcResourceAccessor.h index 505639b2..7755e260 100644 --- a/include/nw4r/lyt/lyt_arcResourceAccessor.h +++ b/include/nw4r/lyt/lyt_arcResourceAccessor.h @@ -1,13 +1,15 @@ #ifndef NW4R_LYT_ARC_RESOURCE_ACCESSOR_H #define NW4R_LYT_ARC_RESOURCE_ACCESSOR_H + #include "common.h" -#include "lyt_resourceAccessor.h" +#include "nw4r/lyt/lyt_resourceAccessor.h" #include "nw4r/ut/ut_Font.h" #include "nw4r/ut/ut_LinkList.h" -#include +#include #include -#define FONTNAMEBUF_MAX 127 +#define FONTNAMEBUF_MAX 128 +#define ROOTPATH_MAX 128 namespace nw4r { namespace lyt { @@ -16,7 +18,7 @@ public: FontRefLink(); ~FontRefLink() {} - void Set(const char *, ut::Font *); + void Set(const char *name, ut::Font *pFont); ut::Font *GetFont() const { return mFont; @@ -32,37 +34,61 @@ private: ut::Font *mFont; // at 0x88 }; -class ArcResourceAccessor : public ResourceAccessor { +class ArcResourceLink { public: - ArcResourceAccessor(); - virtual ~ArcResourceAccessor() {} // at 0x8 - virtual UNKTYPE *GetResource(u32, const char *, u32 *); // at 0xC - virtual ut::Font *GetFont(const char *); // at 0x10 + bool Set(void *pFile, const char *name); - bool Attach(void *, const char *); - void *Detach() { - void *old = mArchive; - mArchive = NULL; - - return old; + const char *GetResRootDir() const { + return mResRootDir; } - bool IsAttached() const { - return (mArchive != NULL); - } - - void RegistFont(FontRefLink *pLink) { - mRefList.PushBack(pLink); - } - void UnregistFont(FontRefLink *pLink) { - mRefList.Erase(pLink); + ARCHandle *GetArcHandle() { + return &mArcHandle; } private: - ARCHandle mHandle; // at 0x4 - void *mArchive; // at 0x8 - ut::LinkList mRefList; // at 0x24 - char mRootDir[FONTNAMEBUF_MAX]; // at 0x30 + ut::LinkListNode mLink; // at 0x00 + ARCHandle mArcHandle; // at 0x08 + char mResRootDir[ROOTPATH_MAX]; // at 0x24 +}; + +class ArcResourceAccessor : public ResourceAccessor { +public: + ArcResourceAccessor(); + virtual ~ArcResourceAccessor() {} // at 0x8 + virtual void *GetResource(u32, const char *, u32 *); // at 0xC + virtual ut::Font *GetFont(const char *); // at 0x10 + + bool Attach(void *pFile, const char *name); + void *Detach(); + + bool IsAttached() const { + return (mArcBuf != NULL); + } + + void RegistFont(FontRefLink *pLink); + + void UnregistFont(FontRefLink *pLink); + +private: + ARCHandle mArcHandle; // at 0x4 + void *mArcBuf; // at 0x8 + ut::LinkList mFontList; // at 0x24 + char mResRootDir[ROOTPATH_MAX]; // at 0x30 +}; + +class MultiArcResourceAccessor : ResourceAccessor { +public: + MultiArcResourceAccessor(); + virtual ~MultiArcResourceAccessor(); // at 0x8 + virtual void *GetResource(u32 resType, const char *name, u32 *pSize); // at 0xC + virtual ut::Font *GetFont(const char *); // at 0x10 + + void Attach(ArcResourceLink *pArcResource); + void RegistFont(FontRefLink *pLink); + + ut::LinkList mArcList; // at 0x4 + ut::LinkList mFontList; // at 0x10 }; namespace detail { @@ -76,6 +102,7 @@ static ut::Font *FindFont(ut::LinkList *pList, const char *name) return NULL; } + } // namespace detail } // namespace lyt } // namespace nw4r diff --git a/include/rvl/ARC/arc.h b/include/rvl/ARC/arc.h index 3e012138..11c2eb16 100644 --- a/include/rvl/ARC/arc.h +++ b/include/rvl/ARC/arc.h @@ -81,9 +81,9 @@ typedef struct ARCEntry { typedef struct ARCDirEntry { ARCHandle *handle; // at 0x0 - u32 path_begin; // at 0x4 - u32 path_it; // at 0x8 - u32 path_end; // at 0xC + u32 entryNum; // at 0x4 + BOOL isDir; // at 0x8 + const char *name; // at 0xC } ARCDirEntry; BOOL ARCGetCurrentDir(ARCHandle *handle, char *string, u32 maxlen); @@ -96,9 +96,9 @@ s32 ARCGetStartOffset(ARCFileInfo *info); u32 ARCGetLength(ARCFileInfo *info); BOOL ARCClose(ARCFileInfo *info); BOOL ARCChangeDir(ARCHandle *info, const char *path); -BOOL ARCOpenDir(ARCHandle *info, const char *path, ARCDirEntry *dir); -BOOL ARCReadDir(ARCDirEntry *dir, ARCEntry *entry); -BOOL ARCCloseDir(ARCDirEntry *dir); +BOOL ARCOpenDir(ARCHandle *info, const char *path, ARCDir *dir); +BOOL ARCReadDir(ARCDir *dir, ARCDirEntry *entry); +BOOL ARCCloseDir(ARCDir *dir); #ifdef __cplusplus } diff --git a/src/nw4r/lyt/lyt_arcResourceAccessor.cpp b/src/nw4r/lyt/lyt_arcResourceAccessor.cpp index 5aab3607..89cd84e5 100644 --- a/src/nw4r/lyt/lyt_arcResourceAccessor.cpp +++ b/src/nw4r/lyt/lyt_arcResourceAccessor.cpp @@ -1,197 +1,171 @@ + #include "nw4r/lyt/lyt_arcResourceAccessor.h" #include "nw4r/ut/ut_Font.h" namespace { // FindNameResource__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCc -s32 FindResourcename(ARCHandle *pArcHandle, const char *resName) { - return 1; +DECOMP_DONT_INLINE s32 FindNameResource(ARCHandle *pArcHandle, const char *resName) { + s32 entryNum = -1; + ARCDir dir; + ARCDirEntry dirEntry; + BOOL bSuccess = ARCOpenDir(pArcHandle, ".", &dir); + + while (ARCReadDir(&dir, &dirEntry)) { + if (dirEntry.isDir) { + ARCChangeDir(pArcHandle, dirEntry.name); + entryNum = FindNameResource(pArcHandle, resName); + ARCChangeDir(pArcHandle, ".."); + + if (entryNum != -1) { + break; + } + } else { + if (stricmp(resName, dirEntry.name) == 0) { + entryNum = dirEntry.entryNum; + break; + } + } + } + bSuccess = ARCCloseDir(&dir); + return entryNum; } // GetResourceSub__37@unnamed@lyt_arcResourceAccessor_cpp@FP9ARCHandlePCcUlPCcPUl -void *GetResourceSub(ARCHandle *pArcHandle, const char *resRootDir, u32 resType, const char *name, u32 *pSize) {} +void *GetResourceSub(ARCHandle *pArcHandle, const char *resRootDir, u32 resType, const char *name, u32 *pSize) { + s32 entryNum = -1; + if (ARCConvertPathToEntrynum(pArcHandle, resRootDir) != -1 && ARCChangeDir(pArcHandle, resRootDir)) { + if (resType == 0) { + entryNum = FindNameResource(pArcHandle, name); + } else { + char resTypeStr[5]; + resTypeStr[0] = resType >> 24; + resTypeStr[1] = resType >> 16; + resTypeStr[2] = resType >> 8; + resTypeStr[3] = resType; + resTypeStr[4] = '\0'; + + if (ARCConvertPathToEntrynum(pArcHandle, resTypeStr) != -1) { + if (ARCChangeDir(pArcHandle, resTypeStr)) { + entryNum = ARCConvertPathToEntrynum(pArcHandle, name); + ARCChangeDir(pArcHandle, ".."); + } + } + } + ARCChangeDir(pArcHandle, ".."); + } + if (entryNum != -1) { + ARCFileInfo arcFileInfo; + ARCFastOpen(pArcHandle, entryNum, &arcFileInfo); + void *resPointer = ARCGetStartAddrInMem(&arcFileInfo); + if (pSize != nullptr) { + *pSize = ARCGetLength(&arcFileInfo); + } + ARCClose(&arcFileInfo); + return resPointer; + } + return nullptr; +} } // namespace namespace nw4r { namespace lyt { // __ct__Q34nw4r3lyt11FontRefLinkFv -FontRefLink::FontRefLink() {} +FontRefLink::FontRefLink() : mFont(nullptr) {} // Set__Q34nw4r3lyt11FontRefLinkFPCcPQ34nw4r2ut4Font -void FontRefLink::Set(const char *name, ut::Font *pFont) {} +void FontRefLink::Set(const char *name, ut::Font *pFont) { + strcpy(this->mFontName, name); + this->mFont = pFont; +} // __ct__Q34nw4r3lyt19ArcResourceAccessorFv -ArcResourceAccessor::ArcResourceAccessor() {} +ArcResourceAccessor::ArcResourceAccessor() : mArcBuf(nullptr) {} // Attach__Q34nw4r3lyt19ArcResourceAccessorFPvPCc bool ArcResourceAccessor::Attach(void *archiveStart, const char *resourceRootDirectory) { - return false; + if (!ARCInitHandle(archiveStart, &this->mArcHandle)) { + return false; + } + this->mArcBuf = archiveStart; + strncpy(this->mResRootDir, resourceRootDirectory, ROOTPATH_MAX - 1); + this->mResRootDir[ROOTPATH_MAX - 1] = '\0'; + return true; } // Detach__Q34nw4r3lyt19ArcResourceAccessorFv +void *ArcResourceAccessor::Detach() { + void *ret = this->mArcBuf; + this->mArcBuf = nullptr; + return ret; +} // GetResource__Q34nw4r3lyt19ArcResourceAccessorFUlPCcPUl +void *ArcResourceAccessor::GetResource(u32 resType, const char *name, u32 *pSize) { + return GetResourceSub(&this->mArcHandle, this->mResRootDir, resType, name, pSize); +} + +// Set__Q34nw4r3lyt15ArcResourceLinkFPvPCc +bool ArcResourceLink::Set(void *pFile, const char *name) { + if (!ARCInitHandle(pFile, &this->mArcHandle)) { + return false; + } + strncpy(this->mResRootDir, name, ROOTPATH_MAX - 1); + this->mResRootDir[ROOTPATH_MAX - 1] = '\0'; + return true; +} // RegistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink +void ArcResourceAccessor::RegistFont(FontRefLink *pLink) { + mFontList.PushBack(pLink); +} // UnregistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink +void ArcResourceAccessor::UnregistFont(FontRefLink *pLink) { + mFontList.Erase(pLink); +} // GetFont__Q34nw4r3lyt19ArcResourceAccessorFPCc +ut::Font *ArcResourceAccessor::GetFont(const char *name) { + return detail::FindFont(&this->mFontList, name); +} + +// __ct__Q34nw4r3lyt24MultiArcResourceAccessorFv +MultiArcResourceAccessor::MultiArcResourceAccessor() {} // __dt__Q34nw4r3lyt24MultiArcResourceAccessorFv +MultiArcResourceAccessor::~MultiArcResourceAccessor() { + this->mArcList.Clear(); +} + +// Attach__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt15ArcResourceLink +void MultiArcResourceAccessor::Attach(ArcResourceLink *pArcResource) { + this->mArcList.PushBack(pArcResource); +} + +// GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl +void *MultiArcResourceAccessor::GetResource(u32 resType, const char *name, u32 *pSize) { + void *pResource; + ut::LinkList::Iterator it = this->mArcList.GetBeginIter(); + for (; it != mArcList.GetEndIter(); it++) { + pResource = GetResourceSub(it->GetArcHandle(), it->GetResRootDir(), resType, name, pSize); + if (pResource != nullptr) { + return pResource; + } + } + + return NULL; +} + +void MultiArcResourceAccessor::RegistFont(FontRefLink *pLink) { + this->mFontList.PushBack(pLink); +} + +// GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc +ut::Font *MultiArcResourceAccessor::GetFont(const char *name) { + return detail::FindFont(&this->mFontList, name); +} } // namespace lyt } // namespace nw4r - -// 29c03b: <88> TAG_global_subroutine -// AT_sibling(0x29c0dc) -// AT_name("Detach") -// AT_lo_user("Detach__Q34nw4r3lyt19ArcResourceAccessorFv") -// AT_member(0x16271) -// AT_fund_type(FT_pointer) -// AT_low_pc(0x802d50c8) -// AT_high_pc(0x802d5158) - -// 29c093: <38> TAG_formal_parameter -// AT_sibling(0x29c0b9) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) -// AT_location(<5>OP_REG(0x1f) ) - -// 29c0dc: <105> TAG_global_subroutine -// AT_sibling(0x29c1ec) -// AT_name("GetResource") -// AT_lo_user("GetResource__Q34nw4r3lyt19ArcResourceAccessorFUlPCcPUl") -// AT_member(0x16271) -// AT_fund_type(FT_pointer) -// AT_low_pc(0x802d5158) -// AT_high_pc(0x802d51a4) - -// 29c145: <38> TAG_formal_parameter -// AT_sibling(0x29c16b) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) -// AT_location(<5>OP_REG(0x1f) ) - -// 29c16b: <41> TAG_formal_parameter -// AT_sibling(0x29c194) -// AT_name("resType") -// AT_fund_type(FT_unsigned_long) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) - -// 29c194: <42> TAG_formal_parameter -// AT_sibling(0x29c1be) -// AT_name("name") -// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0xc) OP_ADD ) - -// 29c1be: <42> TAG_formal_parameter -// AT_sibling(0x29c1e8) -// AT_name("pSize") -// AT_mod_fund_type(<3>MOD_pointer_to FT_unsigned_long) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x10) OP_ADD ) -// 29c1e8: <4> - -// 29c1ec: <116> TAG_global_subroutine -// AT_sibling(0x29c2b6) -// AT_name("RegistFont") -// AT_lo_user("RegistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink") -// AT_member(0x16271) -// AT_low_pc(0x802d51a4) -// AT_high_pc(0x802d5228) - -// 29c260: <44> TAG_formal_parameter -// AT_sibling(0x29c28c) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) - -// 29c28c: <38> TAG_formal_parameter -// AT_sibling(0x29c2b2) -// AT_name("pLink") -// AT_mod_u_d_type(<5>MOD_pointer_to 0x1613f) -// AT_location(<5>OP_REG(0x1d) ) -// 29c2b2: <4> - -// 29c2b6: <120> TAG_global_subroutine -// AT_sibling(0x29c384) -// AT_name("UnregistFont") -// AT_lo_user("UnregistFont__Q34nw4r3lyt19ArcResourceAccessorFPQ34nw4r3lyt11FontRefLink") -// AT_member(0x16271) -// AT_low_pc(0x802d5228) -// AT_high_pc(0x802d52ac) - -// 29c32e: <44> TAG_formal_parameter -// AT_sibling(0x29c35a) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) - -// 29c35a: <38> TAG_formal_parameter -// AT_sibling(0x29c380) -// AT_name("pLink") -// AT_mod_u_d_type(<5>MOD_pointer_to 0x1613f) -// AT_location(<5>OP_REG(0x1d) ) -// 29c380: <4> - -// 29c384: <97> TAG_global_subroutine -// AT_sibling(0x29c43f) -// AT_name("GetFont") -// AT_lo_user("GetFont__Q34nw4r3lyt19ArcResourceAccessorFPCc") -// AT_member(0x16271) -// AT_mod_u_d_type(<5>MOD_pointer_to 0x15c72) -// AT_low_pc(0x802d52ac) -// AT_high_pc(0x802d52e0) - -// 29c3e5: <44> TAG_formal_parameter -// AT_sibling(0x29c411) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x16271) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0x8) OP_ADD ) - -// 29c411: <42> TAG_formal_parameter -// AT_sibling(0x29c43b) -// AT_name("name") -// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) -// AT_location(<11>OP_BASEREG(0x1) OP_CONST(0xc) OP_ADD ) -// 29c43b: <4> - -// 29c43f: <95> TAG_global_subroutine -// AT_sibling(0x29c4c8) -// AT_name("__dt") -// AT_lo_user("__dt__Q34nw4r3lyt24MultiArcResourceAccessorFv") -// AT_member(0x63219) -// AT_fund_type(FT_pointer) -// AT_low_pc(0x802d533c) -// AT_high_pc(0x802d53cc) -// (0x29c83e) - -// 29c49e: <38> TAG_formal_parameter -// AT_sibling(0x29c4c4) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x63219) -// AT_location(<5>OP_REG(0x1f) ) -// 29c4c4: <4> - -// AT_name("DetachAll") -// AT_lo_user("DetachAll__Q34nw4r3lyt24MultiArcResourceAccessorFv") - -// AT_name("GetResource") -// AT_lo_user("GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl") -// AT_fund_type(FT_pointer) -// AT_name("this") -// AT_mod_u_d_type(<6>MOD_const MOD_pointer_to 0x63219) -// AT_name("resType") -// AT_fund_type(FT_unsigned_long) -// AT_name("name") -// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) -// AT_name("pSize") -// AT_mod_fund_type(<3>MOD_pointer_to FT_unsigned_long) - -// AT_lo_user("GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc") -// AT_name("name") -// AT_mod_fund_type(<4>MOD_pointer_to MOD_const FT_char) - -// "__vt__Q34nw4r3lyt24MultiArcResourceAccessor" -// "__vt__Q34nw4r3lyt19ArcResourceAccessor" From d69b2b450c8b1bf3f926ce43cc909450f7941df4 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 18 May 2024 23:25:17 -0400 Subject: [PATCH 03/22] lyt_resourceAccessor --- config/SOUE01/splits.txt | 4 ++++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + src/nw4r/lyt/lyt_resourceAccessor.cpp | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index ec781942..e3515491 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -316,6 +316,10 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/lyt/lyt_resourceAccessor.cpp: + .text start:0x80492000 end:0x80492058 + .data start:0x8056E7E0 end:0x8056E7F8 + nw4r/lyt/lyt_arcResourceAccessor.cpp: .text start:0x80492060 end:0x80492780 .data start:0x8056E7F8 end:0x8056E820 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index cbfd0edc..b016ae35 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37087,7 +37087,7 @@ lbl_8056E758 = .data:0x8056E758; // type:object size:0x20 data:4byte lbl_8056E778 = .data:0x8056E778; // type:object size:0x30 lbl_8056E7A8 = .data:0x8056E7A8; // type:object size:0x10 lbl_8056E7B8 = .data:0x8056E7B8; // type:object size:0x28 -lbl_8056E7E0 = .data:0x8056E7E0; // type:object size:0x18 +__vt__Q34nw4r3lyt16ResourceAccessor = .data:0x8056E7E0; // type:object size:0x14 __vt__Q34nw4r3lyt24MultiArcResourceAccessor = .data:0x8056E7F8; // type:object size:0x14 __vt__Q34nw4r3lyt19ArcResourceAccessor = .data:0x8056E80C; // type:object size:0x14 lbl_8056E820 = .data:0x8056E820; // type:object size:0x10 diff --git a/configure.py b/configure.py index 3247adcc..d561bc3f 100644 --- a/configure.py +++ b/configure.py @@ -352,6 +352,7 @@ config.libs = [ nw4rLib( "lyt", [ + Object(Matching, "nw4r/lyt/lyt_resourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), ], [""] diff --git a/src/nw4r/lyt/lyt_resourceAccessor.cpp b/src/nw4r/lyt/lyt_resourceAccessor.cpp index e69de29b..1587a9b9 100644 --- a/src/nw4r/lyt/lyt_resourceAccessor.cpp +++ b/src/nw4r/lyt/lyt_resourceAccessor.cpp @@ -0,0 +1,15 @@ +#include "nw4r/lyt/lyt_resourceAccessor.h" + +namespace nw4r { +namespace lyt { + +ResourceAccessor::~ResourceAccessor() {} + +ResourceAccessor::ResourceAccessor() {} + +ut::Font *ResourceAccessor::GetFont(const char *name) { + return nullptr; +} + +} // namespace lyt +} // namespace nw4r From 08e0e57034cb1132c3f3427d8c4a8e52702223e4 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 23 May 2024 00:16:00 -0400 Subject: [PATCH 04/22] lyt_pane matching --- config/SOUE01/config.yml | 1 + config/SOUE01/splits.txt | 12 + config/SOUE01/symbols.txt | 30 +- configure.py | 2 + include/nw4r/lyt/lyt_animation.h | 67 ++-- include/nw4r/lyt/lyt_drawInfo.h | 79 ++++- include/nw4r/lyt/lyt_init.h | 10 + include/nw4r/lyt/lyt_layout.h | 6 +- include/nw4r/lyt/lyt_material.h | 60 +++- include/nw4r/lyt/lyt_pane.h | 194 ++++++----- include/nw4r/lyt/lyt_types.h | 20 ++ include/nw4r/ut/ut_Rect.h | 16 +- src/egg/math/eggMatrix.cpp | 2 +- src/nw4r/lyt/lyt_common.cpp | 6 +- src/nw4r/lyt/lyt_init.cpp | 14 + src/nw4r/lyt/lyt_pane.cpp | 536 +++++++++++++++++++++++++++++++ 16 files changed, 901 insertions(+), 154 deletions(-) create mode 100644 include/nw4r/lyt/lyt_init.h create mode 100644 include/nw4r/lyt/lyt_types.h diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 8ad52f93..bbe8cde0 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -18,6 +18,7 @@ force_active: [ "GetResource__Q34nw4r3lyt24MultiArcResourceAccessorFUlPCcPUl", "RegistFont__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt11FontRefLink", "GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc", + "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", ] # modules: diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index e3515491..fd9e79d7 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -316,6 +316,18 @@ nw4r/db/db_directPrint.cpp: .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 +nw4r/lyt/lyt_init.cpp: + .text start:0x80486A70 end:0x80486AC4 + .data start:0x8056E3E8 end:0x8056E430 + .sdata start:0x80574EB0 end:0x80574EB8 + +nw4r/lyt/lyt_pane.cpp: + .text start:0x80486AD0 end:0x80487EAC + .ctors start:0x804DB974 end:0x804DB978 + .data start:0x8056E430 end:0x8056E4A8 + .sbss start:0x805766F0 end:0x805766F8 + .sdata2 start:0x8057F220 end:0x8057F240 + 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 b016ae35..12d1ebfe 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2880,7 +2880,7 @@ fn_80065E70 = .text:0x80065E70; // type:function size:0xC4 fn_80065F40 = .text:0x80065F40; // type:function size:0x28 fn_80065F70 = .text:0x80065F70; // type:function size:0x328 fn_800662A0 = .text:0x800662A0; // type:function size:0xD4 -fn_80066380 = .text:0x80066380; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt4PaneCFv = .text:0x80066380; // type:function size:0x8 fn_80066390 = .text:0x80066390; // type:function size:0xE8 fn_80066480 = .text:0x80066480; // type:function size:0xC fn_80066490 = .text:0x80066490; // type:function size:0x40 @@ -17361,7 +17361,7 @@ searchBaseByGroupType__10fManager_cFUcPC7fBase_c = .text:0x802E2980; // type:fun mainLoop__10fManager_cFv = .text:0x802E29E0; // type:function size:0xC0 __sinit_\f_manager_cpp = .text:0x802E2AA0; // type:function size:0x138 scope:local __ct__9fLiMgBa_cFv = .text:0x802E2BE0; // type:function size:0x10 -fn_802E2BF0 = .text:0x802E2BF0; // type:function size:0x1C scope:local +__arraydtor = .text:0x802E2BF0; // type:function size:0x1C scope:local walkPack__11fTrMgPTMF_cFv = .text:0x802E2C10; // type:function size:0x84 searchNodeByProfName__9fTrMgBa_cCFUsPC9fTrNdBa_c = .text:0x802E2CA0; // type:function size:0x68 searchNodeByGroupType__9fTrMgBa_cCFUcPC9fTrNdBa_c = .text:0x802E2D10; // type:function size:0x68 @@ -25854,15 +25854,13 @@ LytInit__Q24nw4r3lytFv = .text:0x80486A70; // type:function size:0x54 __ct__Q34nw4r3lyt4PaneFPCQ44nw4r3lyt3res4Pane = .text:0x80486AD0; // type:function size:0x128 __dt__Q34nw4r3lyt4PaneFv = .text:0x80486C00; // type:function size:0x13C AppendChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4Pane = .text:0x80486D40; // type:function size:0x50 -RemoveChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4P = .text:0x80486D90; // type:function size:0x3C -FUN_80486dd0 = .text:0x80486DD0; // type:function size:0x110 -FUN_80486ee0 = .text:0x80486EE0; // type:function size:0x110 +RemoveChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4Pane = .text:0x80486D90; // type:function size:0x3C +GetPaneRect__Q34nw4r3lyt4PaneCFv = .text:0x80486DD0; // type:function size:0x110 +GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo = .text:0x80486EE0; // type:function size:0x110 GetVtxColor__Q34nw4r3lyt4PaneCFUl = .text:0x80486FF0; // type:function size:0xC SetVtxColor__Q34nw4r3lyt4PaneFUlQ34nw4r2ut5Color = .text:0x80487000; // type:function size:0x4 -GetColorElement__Q34nw4r3lyt4PaneCFUl = .text:0x80487010; // type:function size:0x20 -fn_80487030 = .text:0x80487030; // type:function size:0x4 -SetColorElement__Q34nw4r3lyt4PaneFUlUc = .text:0x80487040; // type:function size:0x20 -fn_80487060 = .text:0x80487060; // type:function size:0x4 +GetColorElement__Q34nw4r3lyt4PaneCFUl = .text:0x80487010; // type:function size:0x24 +SetColorElement__Q34nw4r3lyt4PaneFUlUc = .text:0x80487040; // type:function size:0x24 GetVtxColorElement__Q34nw4r3lyt4PaneCFUl = .text:0x80487070; // type:function size:0x8 SetVtxColorElement__Q34nw4r3lyt4PaneFUlUc = .text:0x80487080; // type:function size:0x4 FindPaneByName__Q34nw4r3lyt4PaneFPCcb = .text:0x80487090; // type:function size:0xA8 @@ -25886,10 +25884,10 @@ GetVtxPos__Q34nw4r3lyt4PaneCFv = .text:0x80487C80; // type:function size:0xC8 GetMaterialNum__Q34nw4r3lyt4PaneCFv = .text:0x80487D50; // type:function size:0x14 GetMaterial__Q34nw4r3lyt4PaneCFv = .text:0x80487D70; // type:function size:0x8 GetMaterial__Q34nw4r3lyt4PaneCFUl = .text:0x80487D80; // type:function size:0x20 -GetExtUserData__Q34nw4r3lyt4PaneCFv = .text:0x80487DA0; // type:function size:0x1C -GetExtUserDataNum__Q34nw4r3lyt4PaneCFv = .text:0x80487DC0; // type:function size:0x1C +GetExtUserDataNum__Q34nw4r3lyt4PaneCFv = .text:0x80487DA0; // type:function size:0x1C +GetExtUserData__Q34nw4r3lyt4PaneCFv = .text:0x80487DC0; // type:function size:0x1C FindExtUserDataByName__Q34nw4r3lyt4PaneFPCc = .text:0x80487DE0; // type:function size:0xBC -__sinit_lyt_pane_cpp = .text:0x80487EA0; // type:function size:0xC +__sinit_\lyt_pane_cpp = .text:0x80487EA0; // type:function size:0xC scope:local __ct__Q34nw4r3lyt5GroupFPCQ44nw4r3lyt3res5GroupPQ34nw4r3lyt4Pane = .text:0x80487EB0; // type:function size:0x114 __dt__Q34nw4r3lyt5GroupFv = .text:0x80487FD0; // type:function size:0xAC __dt__Q34nw4r3lyt14GroupContainerFv = .text:0x80488080; // type:function size:0xCC @@ -37073,8 +37071,8 @@ lbl_8056E32C = .data:0x8056E32C; // type:object size:0x14 lbl_8056E340 = .data:0x8056E340; // type:object size:0x10 lbl_8056E350 = .data:0x8056E350; // type:object size:0x38 lbl_8056E388 = .data:0x8056E388; // type:object size:0x60 -lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x48 -lbl_8056E430 = .data:0x8056E430; // type:object size:0x78 +lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x46 scope:local data:string +__vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 lbl_8056E4A8 = .data:0x8056E4A8; // type:object size:0x10 lbl_8056E4B8 = .data:0x8056E4B8; // type:object size:0x40 lbl_8056E4F8 = .data:0x8056E4F8; // type:object size:0x78 @@ -39586,7 +39584,7 @@ lbl_80574E94 = .sdata:0x80574E94; // type:object size:0x4 lbl_80574E98 = .sdata:0x80574E98; // type:object size:0x8 lbl_80574EA0 = .sdata:0x80574EA0; // type:object size:0x8 data:4byte lbl_80574EA8 = .sdata:0x80574EA8; // type:object size:0x8 data:4byte -lbl_80574EB0 = .sdata:0x80574EB0; // type:object size:0x8 data:4byte +NW4R_LYT_Version___22@unnamed@lyt_init_cpp@ = .sdata:0x80574EB0; // type:object size:0x4 scope:local data:4byte lbl_80574EB8 = .sdata:0x80574EB8; // type:object size:0x8 lbl_80574EC0 = .sdata:0x80574EC0; // type:object size:0x2 data:string lbl_80574EC4 = .sdata:0x80574EC4; // type:object size:0x3 data:string @@ -40877,7 +40875,7 @@ lbl_805766D0 = .sbss:0x805766D0; // type:object size:0x8 data:4byte lbl_805766D8 = .sbss:0x805766D8; // type:object size:0x8 data:byte lbl_805766E0 = .sbss:0x805766E0; // type:object size:0x8 data:byte lbl_805766E8 = .sbss:0x805766E8; // type:object size:0x8 data:4byte -lbl_805766F0 = .sbss:0x805766F0; // type:object size:0x8 data:4byte +typeInfo__Q34nw4r3lyt4Pane = .sbss:0x805766F0; // type:object size:0x4 data:4byte mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x8 data:4byte lbl_80576700 = .sbss:0x80576700; // type:object size:0x8 data:4byte lbl_80576708 = .sbss:0x80576708; // type:object size:0x8 data:4byte diff --git a/configure.py b/configure.py index d561bc3f..c46c9ec8 100644 --- a/configure.py +++ b/configure.py @@ -352,6 +352,8 @@ config.libs = [ nw4rLib( "lyt", [ + Object(Matching, "nw4r/lyt/lyt_init.cpp"), + Object(Matching, "nw4r/lyt/lyt_pane.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 fd26da01..c0d9f7cc 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -19,32 +19,25 @@ struct AnimationBlock { }; struct AnimTransform { - inline AnimTransform() : mNode(), mResource(NULL), mFrame(0.0f) {} + 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 mNode; // at 0x0 - AnimationBlock *mResource; // at 0xC - f32 mFrame; // at 0x10 -}; - -struct AnimTransformBasic : AnimTransform { - AnimTransformBasic(); - virtual ~AnimTransformBasic(); - virtual UNKTYPE SetResource(const res::AnimationBlock *, ResourceAccessor *); - virtual UNKTYPE Bind(Pane *, bool); - virtual UNKTYPE Bind(Material *); - virtual UNKTYPE Animate(u32, Pane *); - virtual UNKTYPE Animate(u32, Material *); - - u32 INT_0x14; - u32 INT_0x18; - u16 INT_0x1C; + ut::LinkListNode mLink; // at 0x0 + AnimationBlock *mpRes; // at 0xC + f32 mFrame; // at 0x10 }; struct AnimationLink { - inline AnimationLink() : mNode() { + inline AnimationLink() : mLink() { Reset(); } @@ -53,16 +46,38 @@ struct AnimationLink { } inline void Set(AnimTransform *pTransform, u16 us, bool b) { - mTransform = pTransform; - SHORT_0xC = us; - BOOL_0xE = b; + mAnimTrans = pTransform; + mIdx = us; + mbDisable = b; } - ut::LinkListNode mNode; // at 0x0 - AnimTransform *mTransform; // at 0x8 - u16 SHORT_0xC; - bool BOOL_0xE; + ut::LinkListNode mLink; // at 0x0 + AnimTransform *mAnimTrans; // at 0x8 + u16 mIdx; // at 0xC + bool mbDisable; // at 0xE }; +struct AnimTransformBasic : AnimTransform { + AnimTransformBasic(); + virtual ~AnimTransformBasic(); // at 0x08 + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor); // at 0x0C + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum); // at 0x10 + virtual void Bind(Pane *pPane, bool bRecursive); // at 0x14 + virtual void Bind(Material *pMaterial, bool bDisable); // at 0x18 + virtual void Animate(u32 idx, Pane *pPane); // at 0x1C + virtual void Animate(u32 idx, Material *pMaterial); // at 0x20 + + void *mpFileResAry; // at 0x14 + AnimationLink *mAnimLinkAry; // at 0x18 + u16 mAnimLinkNum; // at 0x1C +}; + +namespace detail { +void UnbindAnimationLink(ut::LinkList *, AnimTransform *); +AnimationLink *FindAnimationLink(ut::LinkList *, AnimTransform *); +AnimationLink *FindAnimationLink(ut::LinkList *, const AnimResource &); +void UnbindAnimationLink(ut::LinkList *, AnimTransform *); +} // namespace detail + } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_drawInfo.h b/include/nw4r/lyt/lyt_drawInfo.h index 636a1b4e..8aafd6e9 100644 --- a/include/nw4r/lyt/lyt_drawInfo.h +++ b/include/nw4r/lyt/lyt_drawInfo.h @@ -3,18 +3,93 @@ #include "common.h" #include "nw4r/math/math_types.h" #include "nw4r/ut/ut_Rect.h" - +#include namespace nw4r { namespace lyt { struct DrawInfo { virtual ~DrawInfo(); DrawInfo(); + bool isYAxisUp() const { + // NYI + } + // field accessors + const math::VEC2 &GetLocationAdjustScale() const { + return mScale; + } + void SetLocationAdjustScale(const math::VEC2 &scale) { + this->mScale = scale; + } + + const math::MTX34 &GetViewMtx() const { + return mViewMtx; + } + void SetViewMtx(const math::MTX34 &value) { + this->mViewMtx = value; + } + + f32 GetGlobalAlpha() const { + return mGlobalAlpha; + } + void SetGlobalAlpha(f32 alpha) { + this->mGlobalAlpha = alpha; + } + + const ut::Rect &GetViewRect() const { + return this->mViewRect; + } + void SetViewRect(const ut::Rect &value) { + this->mViewRect = value; + } + + // mFlags accessors + bool IsInvisiblePaneCalculateMtx() const { + return mFlags.invisiblePaneCalculateMtx; + } + void SetInvisiblePaneCalculateMtx(bool bEnable) { + this->mFlags.invisiblePaneCalculateMtx = bEnable; + } + + bool IsLocationAdjust() const { + return mFlags.locationAdjust; + } + void SetLocationAdjust(bool bEnable) { + this->mFlags.locationAdjust = bEnable; + } + + bool IsMultipleViewMtxOnDraw() const { + return mFlags.mulViewDraw; + } + void SetMultipleViewMtxOnDraw(bool bEnable) { + this->mFlags.mulViewDraw = bEnable; + } + + bool IsInfluencedAlpha() const { + return mFlags.influencedAlpha; + } + void SetInfluencedAlpha(bool bEnable) { + this->mFlags.influencedAlpha = bEnable; + } + + bool IsDebugDrawMode() const { + return mFlags.debugDrawMode; + } + void SetDebugDrawMode(bool bEnable) { + this->mFlags.debugDrawMode = bEnable; + } + +private: math::MTX34 mViewMtx; // at 0x0 ut::Rect mViewRect; // at 0x34 math::VEC2 mScale; // at 0x44 f32 mGlobalAlpha; // at 0x48 - u8 mFlags; // at 0x50 + struct { + u8 mulViewDraw : 1; + u8 influencedAlpha : 1; + u8 locationAdjust : 1; + u8 invisiblePaneCalculateMtx : 1; + u8 debugDrawMode : 1; + } mFlags; // at 0x50 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_init.h b/include/nw4r/lyt/lyt_init.h new file mode 100644 index 00000000..be28d65f --- /dev/null +++ b/include/nw4r/lyt/lyt_init.h @@ -0,0 +1,10 @@ +#ifndef NW4R_LYT_INIT_H +#define NW4R_LYT_INIT_H + +namespace nw4r { +namespace lyt { +void LytInit(); +} +} // namespace nw4r + +#endif diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 156e13f3..8bd38837 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -41,8 +41,10 @@ struct Layout { template static void DeleteObj(T *t) { - t->~T(); - FreeMemory(t); + if (t) { + t->~T(); + FreeMemory(t); + } } template diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index fec6d500..e6586c63 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -2,22 +2,60 @@ #define NW4R_LYT_MATERIAL_H #include "nw4r/lyt/lyt_animation.h" #include "nw4r/ut/ut_LinkList.h" +#include #include +#define MATERIAL_NAME_SIZE 20 + namespace nw4r { namespace lyt { -// TO-DO + +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 { - ut::LinkList mAnimLinks; // at 0x4 - // . . . - GXColorS10 COLOR_0x10; - GXColorS10 COLOR_0x18; - GXColorS10 COLOR_0x20; - // . . . - UNKWORD WORD_0x40; - // . . . - u8 BYTE_0x59; - // . . . + // SetupGX__Q34nw4r3lyt8MaterialFbUc + // BindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform + // UnbindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform + // UnbindAllAnimation__Q34nw4r3lyt8MaterialFv + // Animate__Q34nw4r3lyt8MaterialFv + // FindAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform + // FindAnimationLink__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResource + // SetAnimationEnable__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransformb + // SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb + + virtual ~Material(); // at 0x08 + virtual bool SetupGX(bool bModVtxCok, u8 alpha); // at 0x0C + virtual void BindAnimation(AnimTransform *pAnimTrans); // at 0x10 + virtual void UnbindAnimation(AnimTransform *pAnimTrans); // at 0x14 + virtual void UnbindAllAnimation(); // at 0x18 + virtual void Animate(); // at 0x1C + virtual AnimationLink *FindAnimationLink(AnimTransform *pAnimTrans); // at 0x20 + virtual AnimationLink *FindAnimationLink(const AnimResource &animRes); // at 0x24 + virtual void SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable); // at 0x28 + virtual void SetAnimationEnable(const AnimResource &animRes, bool bEnable); // at 0x2C + + ut::LinkList mAnimList; // at 0x4 + GXColorS10 mTevCols[3]; // at 0x10 + ut::Color mTevKCols[4]; // at 0x28 + BitGXNums mGXMemCap; // at 0x38 + BitGXNums mGXMemNum; // at 0x3C + void *mpGXMem; // at 0x40 + char mName[MATERIAL_NAME_SIZE + 1]; // at 0x44 + bool mbUserAllocated; // at 0x59 + u8 mPadding[2]; // at 0x5A }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index b31f2ccb..272e226d 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -7,51 +7,63 @@ #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 17 -#define PANE_USERDATA_SIZE 9 +#define PANE_NAME_SIZE 16 +#define PANE_USERDATA_SIZE 8 #define ANIMTARGET_PANE_MAX 10 namespace nw4r { namespace lyt { -void LytInit(); struct Size { - inline Size() : x(), y() {} + inline Size() : width(), height() {} inline Size &operator=(const Size &rhs) { - x = rhs.x; - y = rhs.y; + width = rhs.width; + height = rhs.height; return *this; } - f32 x, y; + f32 width, height; }; namespace detail { struct PaneBase { - inline PaneBase() : mNode() {} - + PaneBase(); virtual ~PaneBase(); - ut::LinkListNode mNode; // at 0x4 + ut::LinkListNode mLink; // at 0x4 }; + } // namespace detail +// TODO: Find proper place? +// GUESS: In the FindExtUserDataByName function it iterates through ExtUserData +struct ExtUserData { + u32 stringOffs; + u32 UNK_0x04; + u32 UNK_0x08; +}; namespace res { + +struct ExtUserDataList { + DataBlockHeader blockHeader; // at 0x00 + u16 num; // at 0x08 + u16 padding; // at 0x0A +}; struct Pane { - u32 mMagic; // "pan1", at 0x0 - u32 mLength; // at 0x4 - u8 BYTE_0x8; - u8 BYTE_0x9; - u8 BYTE_0xA; - u8 BYTE_0xB; // NO REFERENCES - char mName[PANE_NAME_SIZE]; // at 0xC + 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 VEC3_0x24; - math::VEC3 VEC3_0x30; - math::VEC2 VEC2_0x3C; - Size mSize; // at 0x44 + math::VEC3 translate; // at 0x24 + math::VEC3 rotate; // at 0x30 + math::VEC2 scale; // at 0x3C + Size size; // at 0x44 }; } // namespace res @@ -59,77 +71,81 @@ struct Pane : detail::PaneBase { // For use with TestBit enum PaneBits { VISIBLE, INFLUENCED_ALPHA, LOCATION_ADJUST }; - inline void Init() { - mParent = NULL; - mMaterial = NULL; - BYTE_0xD6 = 0; - INT_0xB4 = 0; + bool IsVisible() const { + return detail::TestBit(mFlag, VISIBLE); + } + bool IsInfluencedAlpha() const { + return detail::TestBit(mFlag, INFLUENCED_ALPHA); + } + bool IsLocationAdjust() const { + return detail::TestBit(mFlag, LOCATION_ADJUST); } - inline void SetName(const char *pName) { - strncpy(mName, pName, PANE_NAME_SIZE); - mName[PANE_NAME_SIZE - 1] = '\0'; - } + Pane(const res::Pane *pBlock); + void Init(); + void SetName(const char *pName); + void SetUserData(const char *pData); + void AppendChild(Pane *pChild); + void PrependChild(Pane *pChild); + void InsertChild(Pane *at, Pane *pChild); + void InsertChild(ut::LinkList::Iterator next, Pane *pChild); + void RemoveChild(Pane *pChild); + ut::Rect GetPaneRect() const; + ut::Rect GetPaneRect(const DrawInfo &) const; + void AddAnimationLink(AnimationLink *pAnimationLink); + math::VEC2 GetVtxPos() const; + void CalculateMtxChild(const DrawInfo &drawInfo); + u16 GetExtUserDataNum() const; + ExtUserData *GetExtUserData() const; + ExtUserData *FindExtUserDataByName(const char *name); - inline void SetUserData(const char *pData) { - strncpy(mUserData, pData, PANE_USERDATA_SIZE); - mUserData[PANE_USERDATA_SIZE - 1] = '\0'; - } + virtual ~Pane(); // at 0x8 + virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; // at 0xC + virtual void CalculateMtx(const DrawInfo &drawInfo); // at 0x10 + virtual void Draw(const DrawInfo &); // at 0x14 + 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 void SetVtxColor(u32, ut::Color); // at 0x28 + virtual u8 GetColorElement(u32 idx) const; // at 0x2C + virtual void SetColorElement(u32 idx, u8 value); // at 0x30 + virtual u8 GetVtxColorElement(u32 idx) const; // at 0x34 + virtual void SetVtxColorElement(u32 idx, u8 value); // at 0x38 + virtual Pane *FindPaneByName(const char *findName, bool bRecursive); // at 0x3C + virtual Material *FindMaterialByName(const char *findName, bool bRecursive); // at 0x40 + virtual void BindAnimation(AnimTransform *pAnimTrans, bool bRecursive, bool bDisable); // at 0x44 + virtual void UnbindAnimation(AnimTransform *pAnimTrans, bool bRecusive); // at 0x48 + virtual void UnbindAllAnimation(bool bRecursive); // at 0x4C + virtual void UnbindAnimationSelf(AnimTransform *pAnimTrans); // at 0x50 + virtual AnimationLink *FindAnimationLinkSelf(AnimTransform *pAnimTrans); // at 0x54 + virtual AnimationLink *FindAnimationLinkSelf(const AnimResource &animRes); // at 0x58 + virtual void SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable, bool bRecursive); // at 0x5C + virtual void SetAnimationEnable(const AnimResource &animRes, bool bEnable, bool bRecursive); // at 0x60 + virtual u8 GetMaterialNum() const; // at 0x64 + virtual Material *GetMaterial() const; // at 0x68 + virtual Material *GetMaterial(u32 idx) const; // at 0x6C + virtual void LoadMtx(const DrawInfo &drawInfo); // at 0x70 - inline void InsertChild(ut::LinkList::Iterator iter, lyt::Pane *pChild) { - mChildren.Insert(iter, pChild); - pChild->mParent = this; - } - - Pane(const res::Pane *); - virtual ~Pane(); // at 0x8 - virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; // at 0xC - virtual UNKTYPE CalculateMtx(const DrawInfo &); // at 0x10 - virtual UNKTYPE Draw(const DrawInfo &); // at 0x14 - virtual void DrawSelf(const DrawInfo &); // at 0x18 - virtual UNKTYPE Animate(u32); // at 0x1C - virtual UNKTYPE AnimateSelf(u32); // at 0x20 - virtual ut::Color GetVtxColor(u32) const; // at 0x24 - virtual void SetVtxColor(u32, ut::Color); // at 0x28 - virtual UNKTYPE GetColorElement(u32) const; // at 0x2C - virtual UNKTYPE SetColorElement(u32, u8); // at 0x30 - virtual u8 GetVtxColorElement(u32) const; // at 0x34 - virtual void SetVtxColorElement(u32, u8); // at 0x38 - virtual Pane *FindPaneByName(const char *, bool); // at 0x3C - virtual UNKTYPE FindMaterialByName(const char *, bool); // at 0x40 - virtual UNKTYPE BindAnimation(AnimTransform *, bool); // at 0x44 - virtual UNKTYPE UnbindAnimation(AnimTransform *, bool); // at 0x48 - virtual UNKTYPE UnbindAllAnimation(bool); // at 0x4C - virtual UNKTYPE UnbindAnimationSelf(AnimTransform *); // at 0x50 - virtual UNKTYPE FindAnimationLink(AnimTransform *); // at 0x54 - virtual UNKTYPE SetAnimationEnable(AnimTransform *, bool, bool); // at 0x58 - virtual UNKTYPE GetMaterial() const; // at 0x5C - virtual UNKTYPE LoadMtx(const DrawInfo &); // at 0x60 - void AppendChild(Pane *); - void RemoveChild(Pane *); - UNKTYPE GetPaneRect(const DrawInfo &) const; - UNKTYPE AddAnimationLink(AnimationLink *); - UNKTYPE GetVtxPos() const; - - ut::LinkListNode mNode; // at 0x4 - Pane *mParent; // at 0x8 - ut::LinkList mChildren; // at 0x14 - ut::LinkList mAnims; // at 0x20; - Material *mMaterial; // at 0x2C - math::VEC3 mTranslate; // at 0x30 - math::VEC3 VEC3_0x3C; - math::VEC2 mScale; // at 0x48 - Size mSize; // at 0x50 - math::MTX34 MTX34_0x58; - math::MTX34 mGlobalMtx; // at 0x84 - int INT_0xB4; - u8 mAlpha; // at 0xB8 - u8 BYTE_0xB9; - u8 BYTE_0xBA; - u8 mFlags; // at 0xBB - char mName[PANE_NAME_SIZE]; // at 0xBC - char mUserData[PANE_USERDATA_SIZE]; // at 0xCD - u8 BYTE_0xD6; + Pane *mpParent; // at 0x0C + ut::LinkList mChildList; // at 0x10 + ut::LinkList mAnimList; // at 0x1C; + Material *mpMaterial; // at 0x28 + math::VEC3 mTranslate; // at 0x2C + math::VEC3 mRotate; // at 0x38 + math::VEC2 mScale; // at 0x44 + Size mSize; // at 0x4C + math::MTX34 mMtx; // at 0x54 + math::MTX34 mGlbMtx; // at 0x84 + res::ExtUserDataList *mpExtUserDataList; // at 0xB4 + u8 mAlpha; // at 0xB8 + u8 mGlbAlpha; // at 0xB9 + u8 mBasePosition; // at 0xBA + u8 mFlag; // at 0xBB + char mName[PANE_NAME_SIZE + 1]; // at 0xBC + char mUserData[PANE_USERDATA_SIZE + 1]; // at 0xCD + bool mbUserAllocated; // at 0xD6 + u8 mPadding; // at 0xD7 static ut::detail::RuntimeTypeInfo typeInfo; }; diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h new file mode 100644 index 00000000..e9ece89e --- /dev/null +++ b/include/nw4r/lyt/lyt_types.h @@ -0,0 +1,20 @@ +#ifndef NW4R_LYT_TYPES_H +#define NW4R_LYT_TYPES_H + +#include + +namespace nw4r { +namespace lyt { +namespace detail { +template +inline bool TestBit(T bits, int index) { + T mask = 1 << index; + return bits & mask; +} +} // namespace detail + +} // namespace lyt + +} // namespace nw4r + +#endif diff --git a/include/nw4r/ut/ut_Rect.h b/include/nw4r/ut/ut_Rect.h index 3a4ec1e2..4b9bd9b3 100644 --- a/include/nw4r/ut/ut_Rect.h +++ b/include/nw4r/ut/ut_Rect.h @@ -16,11 +16,19 @@ struct Rect { Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) {} ~Rect() {} - void SetWidth(f32 width) { right = left + width; } - f32 GetWidth() const { return right - left; } + void SetWidth(f32 width) { + right = left + width; + } + f32 GetWidth() const { + return right - left; + } - void SetHeight(f32 height) { bottom = top + height; } - f32 GetHeight() const { return bottom - top; } + void SetHeight(f32 height) { + bottom = top - height; + } + f32 GetHeight() const { + return bottom - top; + } void Normalize() { f32 l = left; diff --git a/src/egg/math/eggMatrix.cpp b/src/egg/math/eggMatrix.cpp index 68f0049f..9fef71b7 100644 --- a/src/egg/math/eggMatrix.cpp +++ b/src/egg/math/eggMatrix.cpp @@ -239,7 +239,7 @@ void Matrix34f::makeT(const Vector3f &t) { } void Matrix34f::fromQuat(const Quatf &q) { - m[0][0] = 1.0f - (2.0f * q.y * q.y) - (2.0f * q.z * q.z); + m[0][0] = 1.0f - (2 * q.y * q.y) - (2.0f * q.z * q.z); m[0][1] = (2.0f * q.x * q.y) - (2.0f * q.w * q.z); m[0][2] = (2.0f * q.x * q.z) + (2.0f * q.w * q.y); diff --git a/src/nw4r/lyt/lyt_common.cpp b/src/nw4r/lyt/lyt_common.cpp index c5cda80e..795a908f 100644 --- a/src/nw4r/lyt/lyt_common.cpp +++ b/src/nw4r/lyt/lyt_common.cpp @@ -146,7 +146,7 @@ void detail::DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum GXTexCoord2f32(texCoords[i][0].x, texCoords[i][0].y); } - GXPosition2f32(basePt.x + size.x, basePt.y); + GXPosition2f32(basePt.x + size.width, basePt.y); if (vtxColors != NULL) { GXColor1u32(vtxColors[1]); } @@ -154,7 +154,7 @@ void detail::DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum GXTexCoord2f32(texCoords[i][1].x, texCoords[i][1].y); } - GXPosition2f32(basePt.x + size.x, basePt.y - size.y); + GXPosition2f32(basePt.x + size.width, basePt.y - size.height); if (vtxColors != NULL) { GXColor1u32(vtxColors[3]); } @@ -162,7 +162,7 @@ void detail::DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum GXTexCoord2f32(texCoords[i][3].x, texCoords[i][3].y); } - GXPosition2f32(basePt.x, basePt.y - size.y); + GXPosition2f32(basePt.x, basePt.y - size.height); if (vtxColors != NULL) { GXColor1u32(vtxColors[2]); } diff --git a/src/nw4r/lyt/lyt_init.cpp b/src/nw4r/lyt/lyt_init.cpp index e69de29b..9acb89c0 100644 --- a/src/nw4r/lyt/lyt_init.cpp +++ b/src/nw4r/lyt/lyt_init.cpp @@ -0,0 +1,14 @@ +#include +namespace { +const char *NW4R_LYT_Version_ = "<< NW4R - LYT \tfinal build: Mar 15 2010 02:17:33 (0x4302_158) >>"; +} + +namespace nw4r { +namespace lyt { +void LytInit() { + OSRegisterVersion(NW4R_LYT_Version_); + OSInitFastCast(); +} +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index e69de29b..0b60a834 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -0,0 +1,536 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +// ReverseYAxis__22@unnamed@lyt_pane_cpp@FPQ34nw4r4math5MTX34 + +void float_order() { + 0.0f; + 1.0f; +} + +namespace nw4r { + +namespace lyt { +namespace detail { +// __ct__Q44nw4r3lyt6detail8PaneBaseFv +PaneBase::PaneBase() : mLink() {} + +// __dt__Q44nw4r3lyt6detail8PaneBaseFv +PaneBase::~PaneBase() {} + +} // namespace detail + +NW4R_UT_RTTI_DEF_BASE(Pane); + +// 80486a70 +// __ct__Q34nw4r3lyt4PaneFv + +// __dt__Q34nw4r2ut38LinkListFv + +// __dt__Q34nw4r2ut28LinkListFv + +// __ct__Q34nw4r3lyt4PaneFPCQ44nw4r3lyt3res4Pane +Pane::Pane(const res::Pane *pBlock) : mChildList(), mAnimList(), mSize() { + this->mpParent = nullptr; + this->mpMaterial = nullptr; + this->mbUserAllocated = false; + this->mpExtUserDataList = nullptr; + this->mBasePosition = pBlock->basePosition; + strncpy(this->mName, pBlock->name, PANE_NAME_SIZE); + this->mName[PANE_NAME_SIZE] = '\0'; + strncpy(this->mUserData, pBlock->mUserData, PANE_USERDATA_SIZE); + this->mUserData[PANE_USERDATA_SIZE] = '\0'; + this->mTranslate = pBlock->translate; + this->mRotate = pBlock->rotate; + this->mScale = pBlock->scale; + this->mSize = pBlock->size; + this->mGlbAlpha = this->mAlpha = pBlock->alpha; + this->mFlag = pBlock->flag; +} + +// Init__Q34nw4r3lyt4PaneFv +void Pane::Init() { + this->mpParent = NULL; + this->mpMaterial = NULL; + this->mbUserAllocated = false; + this->mpExtUserDataList = NULL; +} + +// __dt__Q34nw4r3lyt4PaneFv +Pane::~Pane() { + ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); + while (it != this->mChildList.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + mChildList.Erase(currIt); + if (!currIt->mbUserAllocated) { + Layout::DeleteObj(&*currIt); + } + } + this->UnbindAnimationSelf(nullptr); + if (this->mpMaterial && !this->mpMaterial->mbUserAllocated) { + Layout::DeleteObj(this->mpMaterial); + } +} + +// SetName__Q34nw4r3lyt4PaneFPCc +void Pane::SetName(const char *pName) { + strncpy(this->mName, pName, PANE_NAME_SIZE); + this->mName[PANE_NAME_SIZE - 1] = '\0'; +} + +// SetUserData__Q34nw4r3lyt4PaneFPCc +void Pane::SetUserData(const char *pData) { + strncpy(this->mUserData, pData, PANE_USERDATA_SIZE); + this->mUserData[PANE_USERDATA_SIZE - 1] = '\0'; +} + +// AppendChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4Pane +void Pane::AppendChild(Pane *pChild) { + InsertChild(this->mChildList.GetEndIter(), pChild); +} + +// PrependChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4Pane +void Pane::PrependChild(Pane *pChild) { + InsertChild(this->mChildList.GetBeginIter(), pChild); +} + +// InsertChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4PanePQ34nw4r3lyt4Pane +void Pane::InsertChild(Pane *at, Pane *pChild) { + this->mChildList.Insert(mChildList.GetIteratorFromPointer(&at->mLink), pChild); + pChild->mpParent = this; +} + +// InsertChild__Q34nw4r3lyt4PaneFQ44nw4r2ut28LinkList8IteratorPQ34nw4r3lyt4Pane +// Guess for now. Not in SS +void Pane::InsertChild(ut::LinkList::Iterator next, Pane *pChild) { + this->mChildList.Insert(next, pChild); + pChild->mpParent = this; +} + +// RemoveChild__Q34nw4r3lyt4PaneFPQ34nw4r3lyt4Pane +void Pane::RemoveChild(Pane *pChild) { + this->mChildList.Erase(pChild); + pChild->mpParent = nullptr; +} +// GetPaneRect__Q34nw4r3lyt4PaneCFv +ut::Rect Pane::GetPaneRect() const { + ut::Rect ret; + math::VEC2 basePt = GetVtxPos(); + + ret.left = basePt.x; + ret.top = basePt.y; + ret.right = basePt.x + mSize.width; + ret.bottom = basePt.y - mSize.height; + + return ret; +} + +// GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo +ut::Rect Pane::GetPaneRect(const DrawInfo &) const { + return GetPaneRect(); +} + +// GetVtxColor__Q34nw4r3lyt4PaneCFUl +ut::Color Pane::GetVtxColor(u32) const { + return ut::Color(); +} + +// SetVtxColor__Q34nw4r3lyt4PaneFUlQ34nw4r2ut5Color +void Pane::SetVtxColor(u32, ut::Color) {} + +// GetColorElement__Q34nw4r3lyt4PaneCFUl +u8 Pane::GetColorElement(u32 idx) const { + if (idx == 0x10) { + return this->mAlpha; + } else { + return GetVtxColorElement(idx); + } +} + +// SetColorElement__Q34nw4r3lyt4PaneFUlUc +void Pane::SetColorElement(u32 idx, u8 value) { + if (idx == 0x10) { + this->mAlpha = value; + } else { + return SetVtxColorElement(idx, value); + } +} + +// GetVtxColorElement__Q34nw4r3lyt4PaneCFUl +u8 Pane::GetVtxColorElement(u32 idx) const { + return 0xFF; +} + +// SetVtxColorElement__Q34nw4r3lyt4PaneFUlUc +void Pane::SetVtxColorElement(u32 idx, u8 value) {} + +// FindPaneByName__Q34nw4r3lyt4PaneFPCcb +Pane *Pane::FindPaneByName(const char *findName, bool bRecursive) { + if (detail::EqualsResName(this->mName, findName)) { + return this; + } + if (bRecursive) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + Pane *pPane = it->FindPaneByName(findName, bRecursive); + if (pPane != nullptr) { + return pPane; + } + } + } + return nullptr; +} + +// FindMaterialByName__Q34nw4r3lyt4PaneFPCcb +Material *Pane::FindMaterialByName(const char *findName, bool bRecursive) { + if (this->mpMaterial && detail::EqualsMaterialName(this->mpMaterial->mName, findName)) { + return this->mpMaterial; + } + if (bRecursive) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + Material *pPane = it->FindMaterialByName(findName, bRecursive); + if (pPane != nullptr) { + return pPane; + } + } + } + return nullptr; +} + +// CalculateMtx__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +void Pane::CalculateMtx(const DrawInfo &drawInfo) { + if (!IsVisible() && !drawInfo.IsInvisiblePaneCalculateMtx()) { + return; + } + + math::VEC2 scale = this->mScale; + + if (drawInfo.IsLocationAdjust() && IsLocationAdjust()) { + scale.x *= drawInfo.GetLocationAdjustScale().x; + scale.y *= drawInfo.GetLocationAdjustScale().y; + } + if (mRotate.x != 0.0f || mRotate.y != 0.0f) { + f32 sinx, siny, sinz; + f32 cosx, cosy, cosz; + + math::SinCosDeg(&sinx, &cosx, mRotate.x); + math::SinCosDeg(&siny, &cosy, mRotate.y); + math::SinCosDeg(&sinz, &cosz, mRotate.z); + const f32 cosz_cosx = cosz * cosx; + const f32 siny_sinx = siny * sinx; + const f32 sinz_cosx = sinz * cosx; + this->mMtx._00 = cosz * cosy * scale.x; + this->mMtx._10 = (sinz * cosy) * scale.x; + this->mMtx._20 = (-siny) * scale.x; + this->mMtx._01 = (-sinz_cosx + cosz * siny_sinx) * scale.y; + this->mMtx._11 = (cosz_cosx + sinz * siny_sinx) * scale.y; + this->mMtx._21 = (cosy * sinx) * scale.y; + this->mMtx._02 = (sinz * sinx) + (cosz_cosx * siny); + this->mMtx._12 = (-cosz * sinx) + (sinz_cosx * siny); + this->mMtx._22 = (cosy * cosx); + + } else if (mRotate.z != 0.0f) { + f32 sinz; + f32 cosz; + math::SinCosDeg(&sinz, &cosz, mRotate.z); + this->mMtx._00 = cosz * scale.x; + this->mMtx._01 = -sinz * scale.y; + this->mMtx._02 = 0.0f; + this->mMtx._10 = sinz * scale.x; + this->mMtx._11 = cosz * scale.y; + this->mMtx._12 = 0.0f; + this->mMtx._20 = 0.0f; + this->mMtx._21 = 0.0f; + this->mMtx._22 = 1.0f; + } else { + this->mMtx._00 = scale.x; + this->mMtx._01 = 0.0f; + this->mMtx._02 = 0.0f; + this->mMtx._10 = 0.0f; + this->mMtx._11 = scale.y; + this->mMtx._12 = 0.0f; + this->mMtx._20 = 0.0f; + this->mMtx._21 = 0.0f; + this->mMtx._22 = 1.0f; + } + this->mMtx._03 = this->mTranslate.x; + this->mMtx._13 = this->mTranslate.y; + this->mMtx._23 = this->mTranslate.z; + if (this->mpParent) { + PSMTXConcat(this->mpParent->mGlbMtx, this->mMtx, this->mGlbMtx); + } else { + if (drawInfo.IsMultipleViewMtxOnDraw()) { + this->mGlbMtx = this->mMtx; + } else { + PSMTXConcat(drawInfo.GetViewMtx(), this->mMtx, this->mGlbMtx); + } + } + + u8 alpha; + bool b = drawInfo.IsInfluencedAlpha() && this->mpParent; + if (b) { + alpha = this->mAlpha * drawInfo.GetGlobalAlpha(); + } else { + alpha = this->mAlpha; + } + this->mGlbAlpha = alpha; + + if (IsInfluencedAlpha() && this->mAlpha != 0xFF) { + DrawInfo &mtDrawInfo = const_cast(drawInfo); + const f32 crGlobalAlpha = drawInfo.GetGlobalAlpha(); + const bool bCdInfluenced = drawInfo.IsInfluencedAlpha(); + mtDrawInfo.SetGlobalAlpha(crGlobalAlpha * mAlpha * (1.0f / 0xFF)); + mtDrawInfo.SetInfluencedAlpha(true); + CalculateMtxChild(drawInfo); + mtDrawInfo.SetGlobalAlpha(crGlobalAlpha); + mtDrawInfo.SetInfluencedAlpha(bCdInfluenced); + } else { + CalculateMtxChild(drawInfo); + } +} + +// CalculateMtxChild__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +// Guess but makes sense +void Pane::CalculateMtxChild(const DrawInfo &drawInfo) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->CalculateMtx(drawInfo); + } +} + +// Draw__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +void Pane::Draw(const DrawInfo &drawInfo) { + if (IsVisible()) { + this->DrawSelf(drawInfo); + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->Draw(drawInfo); + } + } +} + +// DrawSelf__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +void Pane::DrawSelf(const DrawInfo &drawInfo) {} + +// Animate__Q34nw4r3lyt4PaneFUl +void Pane::Animate(u32 option) { + this->AnimateSelf(option); + if (IsVisible() || !(option & 1)) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->Animate(option); + } + } +} + +// AnimateSelf__Q34nw4r3lyt4PaneFUl +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 (IsVisible() || !(option & 1)) { + if (this->mpMaterial) { + mpMaterial->Animate(); + } + } +} + +// BindAnimation__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransformbb +void Pane::BindAnimation(AnimTransform *pAnimTrans, bool bRecursive, bool bDisable) { + pAnimTrans->Bind(this, bRecursive); +} + +// UnbindAnimation__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransformb +void Pane::UnbindAnimation(AnimTransform *pAnimTrans, bool bRecusive) { + this->UnbindAnimationSelf(pAnimTrans); + if (bRecusive) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->UnbindAnimation(pAnimTrans, bRecusive); + } + } +} + +// UnbindAllAnimation__Q34nw4r3lyt4PaneFb +void Pane::UnbindAllAnimation(bool bRecursive) { + UnbindAnimation(nullptr, bRecursive); +} + +// UnbindAnimationSelf__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransform +void Pane::UnbindAnimationSelf(AnimTransform *pAnimTrans) { + if (this->mpMaterial) { + this->mpMaterial->UnbindAnimation(pAnimTrans); + } + detail::UnbindAnimationLink(&this->mAnimList, pAnimTrans); +} + +// AddAnimationLink__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimationLink +void Pane::AddAnimationLink(AnimationLink *pAnimationLink) { + this->mAnimList.PushBack(pAnimationLink); +} + +// FindAnimationLinkSelf__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransform +AnimationLink *Pane::FindAnimationLinkSelf(AnimTransform *pAnimTrans) { + return detail::FindAnimationLink(&this->mAnimList, pAnimTrans); +} + +// FindAnimationLinkSelf__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt12AnimResource +AnimationLink *Pane::FindAnimationLinkSelf(const AnimResource &animRes) { + return detail::FindAnimationLink(&this->mAnimList, animRes); +} + +// SetAnimationEnable__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransformbb +void Pane::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable, bool bRecursive) { + AnimationLink *pAnimLink = FindAnimationLinkSelf(pAnimTrans); + if (pAnimLink) { + pAnimLink->mbDisable = !bEnable; + } + + u8 materialNum = GetMaterialNum(); + for (u8 i = 0; i < materialNum; i++) { + GetMaterial(i)->SetAnimationEnable(pAnimTrans, bEnable); + } + if (bRecursive) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->SetAnimationEnable(pAnimTrans, bEnable, bRecursive); + } + } +} + +// SetAnimationEnable__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt12AnimResourcebb +void Pane::SetAnimationEnable(const AnimResource &animRes, bool bEnable, bool bRecursive) { + AnimationLink *pAnimLink = FindAnimationLinkSelf(animRes); + if (pAnimLink) { + pAnimLink->mbDisable = !bEnable; + } + + u8 materialNum = GetMaterialNum(); + for (u8 i = 0; i < materialNum; i++) { + GetMaterial(i)->SetAnimationEnable(animRes, bEnable); + } + if (bRecursive) { + for (ut::LinkList::Iterator it = this->mChildList.GetBeginIter(); it != this->mChildList.GetEndIter(); + it++) { + it->SetAnimationEnable(animRes, bEnable, bRecursive); + } + } +} + +// LoadMtx__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +void Pane::LoadMtx(const DrawInfo &drawInfo) { + math::MTX34 mtx; + math::MTX34 *mtxPtr; + if (drawInfo.IsMultipleViewMtxOnDraw()) { + PSMTXConcat(drawInfo.GetViewMtx(), this->mGlbMtx, mtx); + mtxPtr = &mtx; + } else { + mtxPtr = &this->mGlbMtx; + } + GXLoadPosMtxImm(*mtxPtr, GX_PNMTX0); + GXSetCurrentMtx(GX_PNMTX0); +} + +// GetVtxPos__Q34nw4r3lyt4PaneCFv +math::VEC2 Pane::GetVtxPos() const { + math::VEC2 basePt(0.0f, 0.0f); + + switch (this->mBasePosition % 3) { + default: + basePt.x = 0.0f; + break; + case 1: + basePt.x = -this->mSize.width / 2; + break; + case 2: + basePt.x = -this->mSize.width; + break; + } + switch (this->mBasePosition / 3) { + default: + basePt.y = 0.0f; + break; + case 1: + basePt.y = this->mSize.height / 2; + break; + case 2: + basePt.y = this->mSize.height; + break; + } + return basePt; +} + +// GetMaterialNum__Q34nw4r3lyt4PaneCFv +u8 Pane::GetMaterialNum() const { + if (this->mpMaterial) { + return 1; + } else { + return 0; + } +} + +// GetMaterial__Q34nw4r3lyt4PaneCFv +Material *Pane::GetMaterial() const { + return this->mpMaterial; +} + +// GetMaterial__Q34nw4r3lyt4PaneCFUl +Material *Pane::GetMaterial(u32 idx) const { + if (idx == 0) { + return GetMaterial(); + } + return nullptr; +} + +u16 Pane::GetExtUserDataNum() const { + if (this->mpExtUserDataList) { + return this->mpExtUserDataList->num; + } + return 0; +} +ExtUserData *Pane::GetExtUserData() const { + if (this->mpExtUserDataList) { + return (ExtUserData *)(this->mpExtUserDataList + 1); + } + return nullptr; +} + +ExtUserData *Pane::FindExtUserDataByName(const char *name) { + ExtUserData *pUserData = GetExtUserData(); + + if (!pUserData) { + return nullptr; + } + int i = 0; + for (int i = 0; i < this->mpExtUserDataList->num;) { + u32 offset = pUserData->stringOffs; + const char *str = 0; + if (offset != 0) { + str = (const char *)(pUserData) + offset; + } else { + str = 0; + } + + if (strcmp(name, str) == 0) { + return pUserData; + }; + i++; + pUserData++; + } + return nullptr; +} + +} // namespace lyt + +} // namespace nw4r From 752f760c3222193089a605a1824fe7cfdbb20577 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 23 May 2024 01:05:22 -0400 Subject: [PATCH 05/22] lyt_group matching --- config/SOUE01/splits.txt | 4 ++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + include/nw4r/lyt/lyt_drawInfo.h | 1 + include/nw4r/lyt/lyt_group.h | 30 +++++++------ include/nw4r/lyt/lyt_layout.h | 6 ++- src/nw4r/lyt/lyt_group.cpp | 76 +++++++++++++++++++++++++++++++++ src/nw4r/lyt/lyt_pane.cpp | 4 +- 8 files changed, 107 insertions(+), 17 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index fd9e79d7..5376ea1d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -328,6 +328,10 @@ nw4r/lyt/lyt_pane.cpp: .sbss start:0x805766F0 end:0x805766F8 .sdata2 start:0x8057F220 end:0x8057F240 +nw4r/lyt/lyt_group.cpp: + .text start:0x80487EB0 end:0x8048820C + .data start:0x8056E4A8 end:0x8056E4B4 + 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 12d1ebfe..764dea4d 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37073,7 +37073,7 @@ lbl_8056E350 = .data:0x8056E350; // type:object size:0x38 lbl_8056E388 = .data:0x8056E388; // type:object size:0x60 lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x46 scope:local data:string __vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 -lbl_8056E4A8 = .data:0x8056E4A8; // type:object size:0x10 +__vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC lbl_8056E4B8 = .data:0x8056E4B8; // type:object size:0x40 lbl_8056E4F8 = .data:0x8056E4F8; // type:object size:0x78 lbl_8056E570 = .data:0x8056E570; // type:object size:0x88 diff --git a/configure.py b/configure.py index c46c9ec8..7d5a6fdb 100644 --- a/configure.py +++ b/configure.py @@ -354,6 +354,7 @@ config.libs = [ [ Object(Matching, "nw4r/lyt/lyt_init.cpp"), Object(Matching, "nw4r/lyt/lyt_pane.cpp"), + Object(Matching, "nw4r/lyt/lyt_group.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_drawInfo.h b/include/nw4r/lyt/lyt_drawInfo.h index 8aafd6e9..a3cc03b9 100644 --- a/include/nw4r/lyt/lyt_drawInfo.h +++ b/include/nw4r/lyt/lyt_drawInfo.h @@ -12,6 +12,7 @@ struct DrawInfo { bool isYAxisUp() const { // NYI + return false; } // field accessors const math::VEC2 &GetLocationAdjustScale() const { diff --git a/include/nw4r/lyt/lyt_group.h b/include/nw4r/lyt/lyt_group.h index b12a8665..71f429b2 100644 --- a/include/nw4r/lyt/lyt_group.h +++ b/include/nw4r/lyt/lyt_group.h @@ -9,37 +9,39 @@ namespace nw4r { namespace lyt { namespace res { struct Group { - char UNK_0x0[0x8]; - char mName[NW4R_RES_NAME_SIZE]; // at 0x8 - u16 SHORT_0x18; + 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 { - ut::LinkListNode mNode; // at 0x0 - Pane *PANE_0x8; + ut::LinkListNode mLink; // at 0x0 + Pane *mTarget; // at 0x08 }; } // namespace detail struct Group { - Group(const res::Group *, Pane *); + Group(const res::Group *pResGroup, Pane *pRootPane); virtual ~Group(); - void AppendPane(Pane *); + void AppendPane(Pane *pPane); void Init(); - ut::LinkListNode mNode; // at 0x4 - ut::LinkList mPaneList; // at 0xC - char mName[NW4R_RES_NAME_SIZE]; // at 0x18 - bool mIsUserAllocated; // at 0x29 + ut::LinkListNode mLink; // at 0x04 + ut::LinkList mPaneListLink; // at 0x0C + char mName[NW4R_RES_NAME_SIZE + 1]; // at 0x18 + bool mbUserAllocated; // at 0x29 + u8 mPadding[2]; // at 0x2A }; struct GroupContainer { ~GroupContainer(); - void AppendGroup(Group *); - Group *FindGroupByName(const char *); + void AppendGroup(Group *pGroup); + Group *FindGroupByName(const char *findName); - ut::LinkList mGroups; // at 0x4 + ut::LinkList mGroupList; // at 0x4 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 8bd38837..87ce0f67 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -50,7 +50,11 @@ struct Layout { template static T *NewObj() { T *obj = (T *)AllocMemory(sizeof(T)); - return new (obj) T(); + if (obj) { + return new (obj) T(); + } else { + return nullptr; + } } static MEMAllocator *mspAllocator; diff --git a/src/nw4r/lyt/lyt_group.cpp b/src/nw4r/lyt/lyt_group.cpp index e69de29b..493c25fc 100644 --- a/src/nw4r/lyt/lyt_group.cpp +++ b/src/nw4r/lyt/lyt_group.cpp @@ -0,0 +1,76 @@ +#include +#include + +namespace nw4r { + +namespace lyt { + +// __ct__Q34nw4r3lyt5GroupFPCQ44nw4r3lyt3res5GroupPQ34nw4r3lyt4Pane +Group::Group(const res::Group *pResGroup, Pane *pRootPane) : mLink(), mPaneListLink() { + Init(); + strncpy(this->mName, pResGroup->mName, NW4R_RES_NAME_SIZE); + this->mName[NW4R_RES_NAME_SIZE] = '\0'; + const char *paneNameBase = (char *)(&pResGroup[1]); + for (int i = 0; i < pResGroup->paneNum; i++) { + Pane *pFindPane = pRootPane->FindPaneByName(paneNameBase + i * NW4R_RES_NAME_SIZE, true); + if (pFindPane) { + AppendPane(pFindPane); + } + } +} + +// Init__Q34nw4r3lyt5GroupFv +void Group::Init() { + this->mbUserAllocated = false; +} + +// __dt__Q34nw4r3lyt5GroupFv +Group::~Group() { + ut::LinkList::Iterator it = this->mPaneListLink.GetBeginIter(); + while (it != this->mPaneListLink.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + this->mPaneListLink.Erase(currIt); + Layout::DeleteObj(&*currIt); + } +} + +// AppendPane__Q34nw4r3lyt5GroupFPQ34nw4r3lyt4Pane +void Group::AppendPane(Pane *pPane) { + detail::PaneLink *pPaneLink = Layout::NewObj(); + if (pPaneLink) { + pPaneLink->mTarget = pPane; + this->mPaneListLink.PushBack(pPaneLink); + } +} + +//__dt__Q34nw4r3lyt14GroupContainerFv +GroupContainer::~GroupContainer() { + ut::LinkList::Iterator it = this->mGroupList.GetBeginIter(); + while (it != this->mGroupList.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + this->mGroupList.Erase(currIt); + if (!currIt->mbUserAllocated) { + Layout::DeleteObj(&*currIt); + } + } +} + +// AppendGroup__Q34nw4r3lyt14GroupContainerFPQ34nw4r3lyt5Group +void GroupContainer::AppendGroup(Group *pGroup) { + this->mGroupList.PushBack(pGroup); +} + +// FindGroupByName__Q34nw4r3lyt14GroupContainerFPCc +Group *GroupContainer::FindGroupByName(const char *findName) { + for (ut::LinkList::Iterator it = this->mGroupList.GetBeginIter(); it != this->mGroupList.GetEndIter(); + it++) { + if (detail::EqualsResName(it->mName, findName)) { + return &*it; + } + } + return nullptr; +} + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 0b60a834..043beb87 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -28,13 +28,13 @@ PaneBase::~PaneBase() {} NW4R_UT_RTTI_DEF_BASE(Pane); -// 80486a70 // __ct__Q34nw4r3lyt4PaneFv // __dt__Q34nw4r2ut38LinkListFv // __dt__Q34nw4r2ut28LinkListFv +// 80486a70 // __ct__Q34nw4r3lyt4PaneFPCQ44nw4r3lyt3res4Pane Pane::Pane(const res::Pane *pBlock) : mChildList(), mAnimList(), mSize() { this->mpParent = nullptr; @@ -205,6 +205,8 @@ Material *Pane::FindMaterialByName(const char *findName, bool bRecursive) { } // CalculateMtx__Q34nw4r3lyt4PaneFRCQ34nw4r3lyt8DrawInfo +// Matches for SS, applying the rotation and scale seems to be different accross versions. +// Also look out for the Bottom CalculateMtxChild section. In other version this is actually seperated differently void Pane::CalculateMtx(const DrawInfo &drawInfo) { if (!IsVisible() && !drawInfo.IsInvisiblePaneCalculateMtx()) { return; From 467e1a61ce87458428e23a38de5052177bd90ad3 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 24 May 2024 15:55:55 -0400 Subject: [PATCH 06/22] lyt_layout progress --- config/SOUE01/splits.txt | 32 ++- config/SOUE01/symbols.txt | 8 +- configure.py | 1 + include/nw4r/ef/ef_animcurve.h | 11 - include/nw4r/ef/ef_creationqueue.h | 38 --- include/nw4r/ef/ef_cube.h | 16 -- include/nw4r/ef/ef_cylinder.h | 16 -- include/nw4r/ef/ef_disc.h | 16 -- include/nw4r/ef/ef_drawbillboardstrategy.h | 19 -- include/nw4r/ef/ef_drawdirectionalstrategy.h | 19 -- include/nw4r/ef/ef_drawfreestrategy.h | 18 -- include/nw4r/ef/ef_drawinfo.h | 11 - include/nw4r/ef/ef_drawlinestrategy.h | 18 -- include/nw4r/ef/ef_draworder.h | 17 -- include/nw4r/ef/ef_draworderbase.h | 18 -- include/nw4r/ef/ef_drawpointstrategy.h | 19 -- include/nw4r/ef/ef_drawsmoothstripestrategy.h | 19 -- include/nw4r/ef/ef_drawstrategy.h | 14 - include/nw4r/ef/ef_drawstrategybuilder.h | 23 -- include/nw4r/ef/ef_drawstrategyimpl.h | 40 --- include/nw4r/ef/ef_drawstripestrategy.h | 19 -- include/nw4r/ef/ef_effect.h | 56 ---- include/nw4r/ef/ef_effectsystem.h | 53 ---- include/nw4r/ef/ef_emform.h | 23 -- include/nw4r/ef/ef_emitter.h | 247 ------------------ include/nw4r/ef/ef_emitterform.h | 17 -- include/nw4r/ef/ef_handle.h | 25 -- include/nw4r/ef/ef_line.h | 16 -- include/nw4r/ef/ef_list.h | 57 ---- include/nw4r/ef/ef_memorymanager.h | 16 -- include/nw4r/ef/ef_memorymanagerbase.h | 40 --- include/nw4r/ef/ef_particle.h | 21 -- include/nw4r/ef/ef_particlemanager.h | 83 ------ include/nw4r/ef/ef_point.h | 16 -- include/nw4r/ef/ef_rand.h | 31 --- include/nw4r/ef/ef_ref.h | 45 ---- include/nw4r/ef/ef_resource.h | 15 -- include/nw4r/ef/ef_sphere.h | 16 -- include/nw4r/ef/ef_torus.h | 16 -- include/nw4r/ef/ef_util.h | 20 -- include/nw4r/lyt/lyt_animation.h | 80 +++++- include/nw4r/lyt/lyt_bounding.h | 15 +- include/nw4r/lyt/lyt_common.h | 20 +- include/nw4r/lyt/lyt_group.h | 15 +- include/nw4r/lyt/lyt_layout.h | 62 ++++- include/nw4r/lyt/lyt_material.h | 39 ++- include/nw4r/lyt/lyt_pane.h | 123 ++++++--- include/nw4r/lyt/lyt_picture.h | 32 +++ include/nw4r/lyt/lyt_textBox.h | 55 ++++ include/nw4r/lyt/lyt_types.h | 65 +++++ include/nw4r/lyt/lyt_window.h | 69 +++++ include/nw4r/ut/ut_RuntimeTypeInfo.h | 33 +-- include/nw4r/ut/ut_algorithm.h | 57 ++-- src/nw4r/lyt/lyt_common.cpp | 3 +- src/nw4r/lyt/lyt_group.cpp | 7 +- src/nw4r/lyt/lyt_layout.cpp | 244 +++++++++++++++++ src/nw4r/lyt/lyt_material.cpp | 10 + src/nw4r/lyt/lyt_pane.cpp | 49 ++-- 58 files changed, 866 insertions(+), 1317 deletions(-) delete mode 100644 include/nw4r/ef/ef_animcurve.h delete mode 100644 include/nw4r/ef/ef_creationqueue.h delete mode 100644 include/nw4r/ef/ef_cube.h delete mode 100644 include/nw4r/ef/ef_cylinder.h delete mode 100644 include/nw4r/ef/ef_disc.h delete mode 100644 include/nw4r/ef/ef_drawbillboardstrategy.h delete mode 100644 include/nw4r/ef/ef_drawdirectionalstrategy.h delete mode 100644 include/nw4r/ef/ef_drawfreestrategy.h delete mode 100644 include/nw4r/ef/ef_drawinfo.h delete mode 100644 include/nw4r/ef/ef_drawlinestrategy.h delete mode 100644 include/nw4r/ef/ef_draworder.h delete mode 100644 include/nw4r/ef/ef_draworderbase.h delete mode 100644 include/nw4r/ef/ef_drawpointstrategy.h delete mode 100644 include/nw4r/ef/ef_drawsmoothstripestrategy.h delete mode 100644 include/nw4r/ef/ef_drawstrategy.h delete mode 100644 include/nw4r/ef/ef_drawstrategybuilder.h delete mode 100644 include/nw4r/ef/ef_drawstrategyimpl.h delete mode 100644 include/nw4r/ef/ef_drawstripestrategy.h delete mode 100644 include/nw4r/ef/ef_effect.h delete mode 100644 include/nw4r/ef/ef_effectsystem.h delete mode 100644 include/nw4r/ef/ef_emform.h delete mode 100644 include/nw4r/ef/ef_emitter.h delete mode 100644 include/nw4r/ef/ef_emitterform.h delete mode 100644 include/nw4r/ef/ef_handle.h delete mode 100644 include/nw4r/ef/ef_line.h delete mode 100644 include/nw4r/ef/ef_list.h delete mode 100644 include/nw4r/ef/ef_memorymanager.h delete mode 100644 include/nw4r/ef/ef_memorymanagerbase.h delete mode 100644 include/nw4r/ef/ef_particle.h delete mode 100644 include/nw4r/ef/ef_particlemanager.h delete mode 100644 include/nw4r/ef/ef_point.h delete mode 100644 include/nw4r/ef/ef_rand.h delete mode 100644 include/nw4r/ef/ef_ref.h delete mode 100644 include/nw4r/ef/ef_resource.h delete mode 100644 include/nw4r/ef/ef_sphere.h delete mode 100644 include/nw4r/ef/ef_torus.h delete mode 100644 include/nw4r/ef/ef_util.h create mode 100644 include/nw4r/lyt/lyt_picture.h create mode 100644 include/nw4r/lyt/lyt_textBox.h create mode 100644 include/nw4r/lyt/lyt_window.h diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 5376ea1d..77753f30 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -1,17 +1,17 @@ Sections: - .init type:code - extab type:rodata - extabindex type:rodata - .text type:code - .ctors type:rodata - .dtors type:rodata - .rodata type:rodata - .data type:data - .sdata type:data - .sbss type:bss - .sdata2 type:rodata - .sbss2 type:bss - .bss type:bss + .init type:code align:4 + extab type:rodata align:8 + extabindex type:rodata align:4 + .text type:code align:32 + .ctors type:rodata align:16 + .dtors type:rodata align:32 + .rodata type:rodata align:32 + .data type:data align:32 + .sdata type:data align:32 + .sbss type:bss align:16 + .sdata2 type:rodata align:8 + .sbss2 type:bss align:16 + .bss type:bss align:64 toBeSorted/save_file.cpp: .text start:0x800099B0 end:0x80009D28 @@ -332,6 +332,12 @@ nw4r/lyt/lyt_group.cpp: .text start:0x80487EB0 end:0x8048820C .data start:0x8056E4A8 end:0x8056E4B4 +nw4r/lyt/lyt_layout.cpp: + .text start:0x80488210 end:0x80489268 + .data start:0x8056E4B8 end:0x8056E4F8 + .sbss start:0x805766F8 end:0x805766FC + .sdata2 start:0x8057F240 end:0x8057F248 + 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 764dea4d..2f635c49 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37074,7 +37074,7 @@ lbl_8056E388 = .data:0x8056E388; // type:object size:0x60 lbl_8056E3E8 = .data:0x8056E3E8; // type:object size:0x46 scope:local data:string __vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 __vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC -lbl_8056E4B8 = .data:0x8056E4B8; // type:object size:0x40 +__vt__Q34nw4r3lyt6Layout = .data:0x8056E4B8; // type:object size:0x40 lbl_8056E4F8 = .data:0x8056E4F8; // type:object size:0x78 lbl_8056E570 = .data:0x8056E570; // type:object size:0x88 lbl_8056E5F8 = .data:0x8056E5F8; // type:object size:0x3C @@ -40876,9 +40876,9 @@ lbl_805766D8 = .sbss:0x805766D8; // type:object size:0x8 data:byte lbl_805766E0 = .sbss:0x805766E0; // type:object size:0x8 data:byte lbl_805766E8 = .sbss:0x805766E8; // type:object size:0x8 data:4byte typeInfo__Q34nw4r3lyt4Pane = .sbss:0x805766F0; // type:object size:0x4 data:4byte -mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x8 data:4byte -lbl_80576700 = .sbss:0x80576700; // type:object size:0x8 data:4byte -lbl_80576708 = .sbss:0x80576708; // type:object size:0x8 data:4byte +mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x4 data:4byte +typeInfo__Q34nw4r3lyt7Picture = .sbss:0x80576700; // type:object size:0x4 data:4byte +typeInfo__Q34nw4r3lyt7TextBox = .sbss:0x80576708; // type:object size:0x4 data:4byte lbl_80576710 = .sbss:0x80576710; // type:object size:0x8 data:4byte lbl_80576718 = .sbss:0x80576718; // type:object size:0x8 data:4byte @GUARD@SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc@texCoords = .sbss:0x80576720; // type:object size:0x1 data:byte diff --git a/configure.py b/configure.py index 7d5a6fdb..cc6aa06d 100644 --- a/configure.py +++ b/configure.py @@ -355,6 +355,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_init.cpp"), Object(Matching, "nw4r/lyt/lyt_pane.cpp"), Object(Matching, "nw4r/lyt/lyt_group.cpp"), + Object(NonMatching, "nw4r/lyt/lyt_layout.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/ef/ef_animcurve.h b/include/nw4r/ef/ef_animcurve.h deleted file mode 100644 index b5b4efca..00000000 --- a/include/nw4r/ef/ef_animcurve.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NW4R_EF_ANIMCURVE_H -#define NW4R_EF_ANIMCURVE_H -#include "common.h" - -namespace nw4r { -namespace ef { -UNKTYPE AnimCurveExecuteF32(u8 *, float *, u32, u16, u32); -} -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_creationqueue.h b/include/nw4r/ef/ef_creationqueue.h deleted file mode 100644 index 0a544783..00000000 --- a/include/nw4r/ef/ef_creationqueue.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef NW4R_EF_CREATIONQUEUE -#define NW4R_EF_CREATIONQUEUE -#include "common.h" -#include "ef_emitter.h" - - -namespace nw4r { -namespace ef { -enum CreationType { CreationType_Particle, CreationType_Emitter }; - -// sizeof(UNK_CREATIONQUEUE) = 0x14 -struct Creation { - u8 mType; // at 0x0 - u16 SHORT_0x2; - EmitterInheritSetting mInheritSetting; // at 0x4 - Particle *mParticle; // at 0x8 - EmitterResource *mResource; // at 0xc -}; - -struct CreationQueue { - CreationQueue(); - void AddParticleCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); - void AddEmitterCreation(const EmitterInheritSetting *, Particle *, EmitterResource *, u16); - - int mSize; - - Creation mCreations[0x400]; - - inline bool IsEmpty() { - return mSize == 0; - } - - void Execute(); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_cube.h b/include/nw4r/ef/ef_cube.h deleted file mode 100644 index 8e091e71..00000000 --- a/include/nw4r/ef/ef_cube.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_CUBE_H -#define NW4R_EF_CUBE_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormCube : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_cylinder.h b/include/nw4r/ef/ef_cylinder.h deleted file mode 100644 index ac27d4e7..00000000 --- a/include/nw4r/ef/ef_cylinder.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_CYLINDER_H -#define NW4R_EF_CYLINDER_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormCylinder : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_disc.h b/include/nw4r/ef/ef_disc.h deleted file mode 100644 index 98d37cb6..00000000 --- a/include/nw4r/ef/ef_disc.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_DISC_H -#define NW4R_EF_DISC_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormDisc : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_drawbillboardstrategy.h b/include/nw4r/ef/ef_drawbillboardstrategy.h deleted file mode 100644 index 291f53e4..00000000 --- a/include/nw4r/ef/ef_drawbillboardstrategy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef NW4R_EF_DRAW_BILLBOARD_STRATEGY_H -#define NW4R_EF_DRAW_BILLBOARD_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawBillboardStrategy : public DrawStrategyImpl { -public: - DrawBillboardStrategy(); - virtual ~DrawBillboardStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - void Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawdirectionalstrategy.h b/include/nw4r/ef/ef_drawdirectionalstrategy.h deleted file mode 100644 index a88630e9..00000000 --- a/include/nw4r/ef/ef_drawdirectionalstrategy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef NW4R_EF_DRAW_DIRECTIONAL_STRATEGY_H -#define NW4R_EF_DRAW_DIRECTIONAL_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawDirectionalStrategy : public DrawStrategyImpl { -public: - DrawDirectionalStrategy(); - virtual ~DrawDirectionalStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - void Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawfreestrategy.h b/include/nw4r/ef/ef_drawfreestrategy.h deleted file mode 100644 index 6de764a9..00000000 --- a/include/nw4r/ef/ef_drawfreestrategy.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef NW4R_EF_DRAW_FREE_STRATEGY_H -#define NW4R_EF_DRAW_FREE_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawFreeStrategy : public DrawStrategyImpl { -public: - DrawFreeStrategy(); - virtual ~DrawFreeStrategy() {} // at 0x8 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawinfo.h b/include/nw4r/ef/ef_drawinfo.h deleted file mode 100644 index 4bbb83b3..00000000 --- a/include/nw4r/ef/ef_drawinfo.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NW4R_EF_DRAWINFO -#define NW4R_EF_DRAWINFO -#include "common.h" - -namespace nw4r { -namespace ef { -struct DrawInfo {}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawlinestrategy.h b/include/nw4r/ef/ef_drawlinestrategy.h deleted file mode 100644 index 46a40d6b..00000000 --- a/include/nw4r/ef/ef_drawlinestrategy.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef NW4R_EF_DRAW_LINE_STRATEGY_H -#define NW4R_EF_DRAW_LINE_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawLineStrategy : public DrawStrategyImpl { -public: - DrawLineStrategy(); - virtual ~DrawLineStrategy() {} // at 0x8 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_draworder.h b/include/nw4r/ef/ef_draworder.h deleted file mode 100644 index b72c51bb..00000000 --- a/include/nw4r/ef/ef_draworder.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NW4R_EF_DRAWORDER -#define NW4R_EF_DRAWORDER -#include "common.h" -#include "ef_draworderbase.h" -#include "ef_particlemanager.h" - -namespace nw4r { -namespace ef { -struct DrawOrder : DrawOrderBase { - void Draw(Effect *, const DrawInfo &); - void Add(Effect *, ParticleManager *); - void Remove(Effect *, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_draworderbase.h b/include/nw4r/ef/ef_draworderbase.h deleted file mode 100644 index ba42be89..00000000 --- a/include/nw4r/ef/ef_draworderbase.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef NW4R_EF_DRAWORDERBASE -#define NW4R_EF_DRAWORDERBASE -#include "ef_particlemanager.h" -#include "ut_list.h" -#include - - -namespace nw4r { -namespace ef { -struct DrawOrderBase { - virtual void Add(Effect *, ParticleManager *) = 0; - virtual void Remove(Effect *, ParticleManager *) = 0; - virtual void Draw(Effect *, const DrawInfo &) = 0; -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawpointstrategy.h b/include/nw4r/ef/ef_drawpointstrategy.h deleted file mode 100644 index 8b037377..00000000 --- a/include/nw4r/ef/ef_drawpointstrategy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef NW4R_EF_DRAW_POINT_STRATEGY_H -#define NW4R_EF_DRAW_POINT_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawPointStrategy : public DrawStrategyImpl { -public: - DrawPointStrategy(); - virtual ~DrawPointStrategy() {} // at 0x8 - - void Draw(const DrawInfo &, ParticleManager *); - void InitGraphics(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawsmoothstripestrategy.h b/include/nw4r/ef/ef_drawsmoothstripestrategy.h deleted file mode 100644 index d76971c4..00000000 --- a/include/nw4r/ef/ef_drawsmoothstripestrategy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef NW4R_EF_DRAW_SMOOTH_STRIPE_STRATEGY_H -#define NW4R_EF_DRAW_SMOOTH_STRIPE_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawSmoothStripeStrategy : public DrawStrategyImpl { -public: - DrawSmoothStripeStrategy(); - virtual ~DrawSmoothStripeStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawstrategy.h b/include/nw4r/ef/ef_drawstrategy.h deleted file mode 100644 index 34d3c38c..00000000 --- a/include/nw4r/ef/ef_drawstrategy.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef NW4R_EF_DRAWSTRATEGY_H -#define NW4R_EF_DRAWSTRATEGY_H -#include "common.h" - -namespace nw4r { -namespace ef { -struct DrawStrategy { - inline virtual ~DrawStrategy() {} - virtual UNKTYPE Draw(const DrawInfo &, ParticleManager *) = 0; -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawstrategybuilder.h b/include/nw4r/ef/ef_drawstrategybuilder.h deleted file mode 100644 index f2de9d2e..00000000 --- a/include/nw4r/ef/ef_drawstrategybuilder.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NW4R_EF_DRAWSTRATEGYBUILDER_H -#define NW4R_EF_DRAWSTRATEGYBUILDER_H -#include "common.h" - -namespace nw4r { -namespace ef { -enum DrawStrategyType { - DrawStratType_Point, - DrawStratType_Line, - DrawStratType_Free, - DrawStratType_Billboard, - DrawStratType_Directional, - DrawStratType_Stripe, - DrawStratType_SmoothStripe -}; - -struct DrawStrategyBuilder { - virtual DrawStrategy *Create(u32); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawstrategyimpl.h b/include/nw4r/ef/ef_drawstrategyimpl.h deleted file mode 100644 index 2a88e87b..00000000 --- a/include/nw4r/ef/ef_drawstrategyimpl.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef NW4R_EF_DRAW_STRATEGY_IMPL_H -#define NW4R_EF_DRAW_STRATEGY_IMPL_H -#include "common.h" -#include "ef_drawstrategy.h" -#include "math_types.h" - -namespace nw4r { -namespace ef { -class DrawStrategyImpl : public DrawStrategy { -public: - struct PrevTexture { - UNKWORD WORD_0x0; - f32 FLOAT_0x4; - f32 FLOAT_0x8; - f32 FLOAT_0xC; - f32 FLOAT_0x10; - UNKWORD WORD_0x14; - UNKWORD WORD_0x18; - math::VEC2 VEC2_0x1C; - f32 FLOAT_0x24; - math::VEC2 VEC2_0x28; - }; - -public: - DrawStrategyImpl(); - virtual UNKTYPE GetGetFirstDrawParticleFunc(int); - virtual UNKTYPE GetGetNextDrawParticleFunc(int); - - void InitTexture(const EmitterDrawSetting &); - void InitTev(const EmitterDrawSetting &, const DrawInfo &); - void InitColor(ParticleManager *, const EmitterDrawSetting &, const DrawInfo &); - -private: - PrevTexture mPrevTextures[3]; // at 0x4 - char UNK_0x94[0xBC - 0x94]; -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_drawstripestrategy.h b/include/nw4r/ef/ef_drawstripestrategy.h deleted file mode 100644 index 2edf9238..00000000 --- a/include/nw4r/ef/ef_drawstripestrategy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef NW4R_EF_DRAW_STRIPE_STRATEGY_H -#define NW4R_EF_DRAW_STRIPE_STRATEGY_H -#include "common.h" -#include "ef_drawstrategyimpl.h" - -namespace nw4r { -namespace ef { -class DrawStripeStrategy : public DrawStrategyImpl { -public: - DrawStripeStrategy(); - virtual ~DrawStripeStrategy() {} // at 0x8 - virtual UNKTYPE GetCalcAheadFunc(ParticleManager *); // at 0x18 - - UNKTYPE Draw(const DrawInfo &, ParticleManager *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_effect.h b/include/nw4r/ef/ef_effect.h deleted file mode 100644 index bed4ac26..00000000 --- a/include/nw4r/ef/ef_effect.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef NW4R_EF_EFFECT -#define NW4R_EF_EFFECT -#include "common.h" -#include "ef_list.h" -#include "ef_ref.h" -#include "ef_util.h" -#include "math_types.h" -#include "ut_list.h" - -namespace nw4r { -namespace ef { -struct Effect : ReferencedObject { - EffectSystem *mSystem; // at 0x20 - ActivityList mEmitters; // at 0x24 - u32 INDEX_0x40; - - void (*mEmissionPrologue)(Emitter *, ParticleManager *, int *, u32 *, float *, u16 *, float *, - math::MTX34 *); // at 0x44 - - UNKWORD WORD_0x48; - UNKWORD WORD_0x4C; - u32 mFlags; // at 0x50 - math::MTX34 mRootMtx; // at 0x54 - math::VEC3 VEC_0x84; - ut::List UTLIST_0x90; - DrawOrder *mDrawOrder; // at 0x9c - - Effect(); - ~Effect(); - - virtual bool Initialize(EffectSystem *, EmitterResource *, u16); - virtual Emitter *CreateEmitter(ResEmitter, u8, u16); - virtual void Calc(bool); - virtual void Draw(const DrawInfo &); - - bool SendClosing(); - UNKTYPE DestroyFunc(); - bool Closing(Emitter *); - Emitter *CreateEmitter(EmitterResource *, u8, u16); - bool RetireEmitter(Emitter *); - u16 RetireEmitterAll(); - u16 RetireParticleAll(); - u16 GetNumEmitter() const; - Emitter *GetEmitter(u16); - u16 ForeachParticleManager(Action, u32, bool); - u16 ForeachEmitterFrom(Action, u32, bool, Emitter *); - UNKTYPE SetRootMtx(const math::MTX34 &); - - inline bool GetFlagDisableDraw() { - return mFlags & 2; - } -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_effectsystem.h b/include/nw4r/ef/ef_effectsystem.h deleted file mode 100644 index 68177a21..00000000 --- a/include/nw4r/ef/ef_effectsystem.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef NW4R_EF_EFFECTSYSTEM -#define NW4R_EF_EFFECTSYSTEM -#include "common.h" -#include "ef_creationqueue.h" -#include "ef_list.h" -#include "ef_rand.h" -#include "ef_ref.h" - -namespace nw4r { -namespace ef { -struct EffectSystem { - static bool mDisplayVersion; - - static EffectSystem instance; - - MemoryManager *mMemoryManager; // at 0x0 - DrawOrder *mDrawOrder; // at 0x4 - DrawStrategyBuilder *mDrawStrategyBuilder; // at 0x8 - EmitFormBuilder *mEmitFormBuilder; // at 0xc - CreationQueue mCreationQueue; // at 0x10 - u32 mNumGroup; - ActivityList *ARR_0x5018; - Random mRandom; // at 0x501C - math::VEC3 VEC_0x5020; - math::MTX34 MTX_0x502C; - float FLOAT_0x505C; - float FLOAT_0x5060; - char BYTE_0x5064; - - inline MemoryManager *GetMemoryManager() const { - return mMemoryManager; - } - - EffectSystem(); - ~EffectSystem(); - - static EffectSystem *GetInstance(); - - bool Initialize(u32); - bool Closing(Effect *); - Effect *CreateEffect(const char *, u32, u16); - bool RetireEffect(Effect *); - u16 RetireEffectAll(u32); - u16 RetireEmitterAll(u32); - u16 RetireParticleAll(u32); - - void Calc(u32, bool); - void Draw(const DrawInfo &, u32); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_emform.h b/include/nw4r/ef/ef_emform.h deleted file mode 100644 index c0d00924..00000000 --- a/include/nw4r/ef/ef_emform.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NW4R_EF_EMFORM_H -#define NW4R_EF_EMFORM_H -#include "common.h" - -namespace nw4r { -namespace ef { -enum EmitFormType { - EmitForm_Disc, - EmitForm_Line, - EmitForm_Cube = 5, - EmitForm_Cylinder = 7, - EmitForm_Sphere, - EmitForm_Point, - EmitForm_Torus -}; - -struct EmitFormBuilder { - virtual EmitterForm *Create(EmitFormType); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_emitter.h b/include/nw4r/ef/ef_emitter.h deleted file mode 100644 index 386eba51..00000000 --- a/include/nw4r/ef/ef_emitter.h +++ /dev/null @@ -1,247 +0,0 @@ -#ifndef NW4R_EF_EMITTER -#define NW4R_EF_EMITTER -#include "ef_animcurve.h" -#include "ef_list.h" -#include "ef_rand.h" -#include "ef_ref.h" -#include "ef_util.h" -#include "ut_list.h" -#include #include "common.h" - - -namespace nw4r { -namespace ef { -struct ResEmitter { - EmitterResource *mPtr; - - inline EmitterResource *ptr() { - return mPtr; - } -}; - -struct EmitterInheritSetting { - s16 SHORT_0x0; - u8 BYTE_0x2; - u8 BYTE_0x3; - u8 BYTE_0x4; - u8 BYTE_0x5; - u8 BYTE_0x6; - u8 BYTE_0x7; -}; - -struct EmitterDesc { - UNKWORD FLAGS_0x0; // at 0x0/0x8 - UNKWORD EMFORMTYPE_0x4; // at 0x4/0xc - u16 SHORT_0x8; // at 0x8/0x10 - u16 SHORT_0xA; // at 0xa/0x12 - s8 SBYTE_0xC; // at 0xc/0x14 - s8 SBYTE_0xD; // at 0xd/0x15 - s8 SBYTE_0xE; // at 0xe/0x16 - s8 SBYTE_0xF; // at 0xf/0x17 - float FLOAT_0x10; // at 0x10/0x18 - u16 SHORT_0x14; // at 0x14/0x1c - u16 SHORT_0x16; // at 0x16/0x1e - u16 SHORT_0x18; // at 0x18/0x20 - s8 BYTE_0x1A; // at 0x1a/0x22 - s8 BYTE_0x1B; // at 0x1b/0x23 - float FLOAT_0x1C; - float FLOAT_0x20; - float FLOAT_0x24; - float FLOAT_0x28; - float FLOAT_0x2C; - float FLOAT_0x30; - u16 SHORT_0x34; - u8 BYTE_0x36; - u8 BYTE_0x37; - float FLOAT_0x38; - float FLOAT_0x3C; - float FLOAT_0x40; - float FLOAT_0x44; - float FLOAT_0x48; - float FLOAT_0x4C; - float FLOAT_0x50; - float FLOAT_0x54; - float FLOAT_0x58; - float FLOAT_0x5C; - - float FLOAT_0x60; - float FLOAT_0x64; - float FLOAT_0x68; - float FLOAT_0x6C; - float FLOAT_0x70; - float FLOAT_0x74; - - float FLOAT_0x78; - float FLOAT_0x7C; - float FLOAT_0x80; - - u8 BYTE_0x84; // at 0x84/0x8c - u8 BYTE_0x85; // at 0x85/0x8d - u8 BYTE_0x86; // at 0x86/0x8e - UNKWORD WORD_0x88; -}; - -struct EmitTrack { - u8 BYTE_0x0; - u8 BYTE_0x1; - u16 SHORT_0x2; - - u8 BYTE_0x4; -}; - -struct EmitterResource { - char UNK_0x0[0x4]; - u32 OFFSET_0x4; - - EmitterDesc STRUCT_0x8; - - inline UNKTYPE *SkipEmitterDesc() { - return (char *)&STRUCT_0x8 + OFFSET_0x4; - } - - inline UNKTYPE *SkipParticleParameterDesc() { - char *particleDesc = (char *)SkipEmitterDesc(); - - return particleDesc + *(int *)particleDesc; - } - - inline u16 NumEmitInitTrack() { - u16 *ptr = (u16 *)SkipParticleParameterDesc(); - - return ptr[(4 * *(ptr += 2)) + 3]; - } - - inline u16 NumEmitTrack() { - u16 *ptr = (u16 *)SkipParticleParameterDesc(); - - return ptr[(4 * *(ptr += 2)) + 2]; - } - - inline EmitTrack *GetEmitTrack(u16 i) { - u16 *ptr = (u16 *)SkipParticleParameterDesc(); - - return reinterpret_cast(ptr)[(2 * *(ptr += 1)) + 1 + i]; - } -}; - -struct Emitter : ReferencedObject { - virtual bool Initialize(Effect *, EmitterResource *, u8); // at 0x10 - virtual Emitter *CreateEmitter(EmitterResource *, EmitterInheritSetting *, Particle *, u16); // at 0x14 - virtual void CalcEmitter(); // at 0x18 - virtual void CalcParticle(); // at 0x1c - virtual void CalcEmission(); // at 0x20 - virtual void CalcBillboard(); // at 0x24 - - u32 mFlags; - UNKWORD WORD_0x24; - - // char UNK_0x28[0x8C]; - float FLOAT_0x28; - float FLOAT_0x2C; - short SHORT_0x30; - short SHORT_0x32; - float FLOAT_0x34; - float FLOAT_0x38; - short SHORT_0x3C; - float FLOAT_0x40; - float FLOAT_0x44; - float FLOAT_0x48; - float FLOAT_0x4C; - float FLOAT_0x50; - float FLOAT_0x54; - float FLOAT_0x58; - float FLOAT_0x5C; - float FLOAT_0x60; - - u8 BYTE_0x64; - s8 BYTE_0x65; - u8 BYTE_0x66; - s8 BYTE_0x67; - - float FLOAT_0x68; - float FLOAT_0x6C; - float FLOAT_0x70; - float FLOAT_0x74; - float FLOAT_0x78; - float FLOAT_0x7C; - float FLOAT_0x80; - float FLOAT_0x84; - float FLOAT_0x88; - float FLOAT_0x8C; - /* - float FLOAT_0x90; - float FLOAT_0x94; - float FLOAT_0x98; - */ - math::VEC3 VEC_0x90; - /* - float FLOAT_0x9C; - float FLOAT_0xA0; - float FLOAT_0xA4; - */ - math::VEC3 VEC_0x9C; - /* - float FLOAT_0xA8; - float FLOAT_0xAC; - float FLOAT_0xB0; - */ - math::VEC3 VEC_0xA8; - - UNKWORD WORD_0xB4; - EmitterResource *mResource; // at 0xb8 - Effect *mEffect; // at 0xbc - ActivityList mManagers; // at 0xc0 - char UNK_0xDA[0x2]; - u8 BYTE_0xDC; - u16 SHORT_0xDE; - u16 SHORT_0xE0; - UNKWORD WORD_0xE4; - u16 SHORT_0xE8; - u16 SHORT_0xEA; - Random mRandom; // at 0xec - EmitterForm *mForm; // at 0xf0 - Emitter *mParent; // at 0xf4 - Particle *REF_0xF8; // at 0xf8 - - EmitterInheritSetting mInheritSettings; // at 0xfc - - bool mMtxDirtyFlag; // at 0x104 - - math::MTX34 mGlobalMtx; // at 0x108 - - Emitter(); - ~Emitter(); - - u16 RetireParticleAll(); - bool SendClosing(); - void DestroyFunc(); - bool Closing(ParticleManager *); - bool RetireParticleManager(ParticleManager *); - u16 RetireParticleManagerAll(); - bool InitializeDatas(EmitterResource *, Effect *); - - ParticleManager *FindParticleManager(EmitterResource *, bool, bool, s8, u8); - UNKTYPE CreateEmitterTmp(EmitterResource *, EmitterInheritSetting *, Particle *, u16); - - float GetLODratio(math::VEC3 &, math::VEC3 &, float, float, float, float); - - u16 ForeachParticleManager(Action, u32, bool, bool); - - UNKTYPE Emission(ParticleManager *, const math::MTX34 *); - - math::MTX34 *CalcGlobalMtx(math::MTX34 *); - UNKTYPE SetMtxDirty(); - - static math::MTX34 *RestructMatrix(math::MTX34 *, math::MTX34 *, bool, bool, s8); - - u16 GetNumParticleManager() const; - ParticleManager *GetParticleManager(u16); - - inline bool GetFlagDisableCalc() const { - return mFlags & 0x200; - } -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_emitterform.h b/include/nw4r/ef/ef_emitterform.h deleted file mode 100644 index 67ba51e0..00000000 --- a/include/nw4r/ef/ef_emitterform.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NW4R_EF_EMITTERFORM_H -#define NW4R_EF_EMITTERFORM_H -#include "common.h" - -namespace nw4r { -namespace ef { -struct EmitterForm { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *) = 0; - - UNKTYPE CalcVelocity(math::VEC3 *, Emitter *, const math::VEC3 &, const math::VEC3 &, const math::VEC3 &, - const math::VEC3 &) const; - u16 CalcLife(u16, float, Emitter *); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_handle.h b/include/nw4r/ef/ef_handle.h deleted file mode 100644 index 34b4e1d2..00000000 --- a/include/nw4r/ef/ef_handle.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef NW4R_EF_HANDLE_H -#define NW4R_EF_HANDLE_H -#include "common.h" - -namespace nw4r { -namespace ef { -struct LinkedObject { - char UNK_0x0[8]; - LinkedObject *PTR_0x8; -}; - -struct HandleBase { - LinkedObject *PTR_0x0; - LinkedObject *mPtr; - - HandleBase(); - HandleBase &operator=(const HandleBase &); - HandleBase &operator=(LinkedObject *); - bool IsValid() const; - LinkedObject *GetPtr() const; -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_line.h b/include/nw4r/ef/ef_line.h deleted file mode 100644 index ed8067d9..00000000 --- a/include/nw4r/ef/ef_line.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_LINE_H -#define NW4R_EF_LINE_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormLine : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_list.h b/include/nw4r/ef/ef_list.h deleted file mode 100644 index 09efa06e..00000000 --- a/include/nw4r/ef/ef_list.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef NW4R_EF_LIST -#define NW4R_EF_LIST -#include "common.h" -#include "ut_list.h" - -namespace nw4r { -namespace ef { -// sizeof(ActivityList) = 0x1C -struct ActivityList { - ut::List mActive; - ut::List mClosing; - u16 mNumActive; - - inline void SetOffset(u16 offset) { - ut::List_Init(&mActive, offset); - ut::List_Init(&mClosing, offset); - mNumActive = 0; - } - - inline ActivityList(u16 offset) { - SetOffset(offset); - } - - inline ActivityList() { - SetOffset(0); - } - - inline void Initialize() { - mActive.first = NULL; - mActive.size = 0; - mActive.last = NULL; - - mClosing.first = NULL; - mClosing.size = 0; - mClosing.last = NULL; - - mNumActive = 0; - } - - inline void ToActive(void *pNode) { - ut::List_Append(&mActive, pNode); - mNumActive++; - } - - inline void ToClosing(void *pNode) { - ut::List_Remove(&mActive, pNode); - ut::List_Append(&mClosing, pNode); - } - - inline void ToWait(void *pNode) { - mNumActive--; - } -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_memorymanager.h b/include/nw4r/ef/ef_memorymanager.h deleted file mode 100644 index 198778d3..00000000 --- a/include/nw4r/ef/ef_memorymanager.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_MEMORYMANAGER -#define NW4R_EF_MEMORYMANAGER -#include "ef_memorymanagerbase.h" - -namespace nw4r -{ - namespace ef - { - struct MemoryManager : MemoryManagerBase - { - - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_memorymanagerbase.h b/include/nw4r/ef/ef_memorymanagerbase.h deleted file mode 100644 index 61c67bbe..00000000 --- a/include/nw4r/ef/ef_memorymanagerbase.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef NW4R_EF_MEMORYMANAGERBASE -#define NW4R_EF_MEMORYMANAGERBASE -#include "common.h" - -namespace nw4r { -namespace ef { -struct MemoryManagerBase { - virtual ~MemoryManagerBase(); // at 0x8 - virtual UNKTYPE GarbageCollection() = 0; // at 0xc - - virtual Effect *AllocEffect() = 0; // at 0x10 - virtual UNKTYPE FreeEffect(void *) = 0; // at 0x14 - virtual UNKWORD GetNumAllocEffect() const = 0; // at 0x18 - virtual UNKWORD GetNumActiveEffect() const = 0; // at 0x1c - virtual UNKWORD GetNumFreeEffect() const = 0; // at 0x20 - - virtual Emitter *AllocEmitter() = 0; // at 0x24 - virtual UNKTYPE FreeEmitter(void *) = 0; // at 0x28 - virtual UNKWORD GetNumAllocEmitter() const = 0; // at 0x2c - virtual UNKWORD GetNumActiveEmitter() const = 0; // at 0x30 - virtual UNKWORD GetNumFreeEmitter() const = 0; // at 0x34 - - virtual ParticleManager *AllocParticleManager() = 0; // at 0x38 - virtual UNKTYPE FreeParticleManager(void *) = 0; // at 0x3c - virtual UNKWORD GetNumAllocParticleManager() const = 0; // at 0x40 - virtual UNKWORD GetNumActiveParticleManager() const = 0; // at 0x44 - virtual UNKWORD GetNumFreeParticleManager() const = 0; // at 0x48 - - virtual Particle *AllocParticle() = 0; // at 0x4c - virtual UNKTYPE FreeParticle(void *) = 0; // at 0x50 - virtual UNKWORD GetNumAllocParticle() const = 0; // at 0x54 - virtual UNKWORD GetNumActiveParticle() const = 0; // at 0x58 - virtual UNKWORD GetNumFreeParticle() const = 0; // at 0x5c - - virtual void *AllocHeap(u32) = 0; // at 0x60 -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_particle.h b/include/nw4r/ef/ef_particle.h deleted file mode 100644 index f0c36aaf..00000000 --- a/include/nw4r/ef/ef_particle.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef NW4R_EF_PARTICLE_H -#define NW4R_EF_PARTICLE_H -#include "common.h" -#include "ef_ref.h" - -namespace nw4r { -namespace ef { -struct Particle : ReferencedObject { - char UNK_0x20[0x8C]; - - math::VEC3 VEC_0xAC; - math::VEC3 VEC_0xB8; - - char UNK_0xC4[0x4]; - - ParticleManager *mManager; // at 0xc8 -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_particlemanager.h b/include/nw4r/ef/ef_particlemanager.h deleted file mode 100644 index f4fd3b20..00000000 --- a/include/nw4r/ef/ef_particlemanager.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef NW4R_EF_PARTICLEMANAGER -#define NW4R_EF_PARTICLEMANAGER -#include "common.h" -#include "ef_list.h" -#include "ef_ref.h" -#include "math_types.h" -#include "ut_Color.h" - -namespace nw4r { -namespace ef { -struct ParticleManager : ReferencedObject { - struct ParticleModifier { - math::VEC2 mScale; // at 0x0 - math::VEC3 mRotate; // at 0x8 - - struct SimpleLight { - u8 mType; // at 0x0 - ut::Color mAmbColor; // at 0x1 - } mLight; - }; - - UNKTYPE BeginDraw(); - UNKTYPE EndDraw(); - UNKTYPE BeginCalc(bool); - UNKTYPE EndCalc(); - - bool SendClosing(); - UNKTYPE DestroyFunc(); - virtual bool Initialize(Emitter *, EmitterResource *); - virtual UNKTYPE CreateParticle(u16, math::VEC3, math::VEC3, const math::MTX34 *, float, - const EmitterInheritSetting *, Particle *, u16); - virtual UNKTYPE Calc(); - virtual UNKTYPE Draw(const DrawInfo &); - - Emitter *mEmitter; // at 0x20 - EmitterResource *mResource; // at 0x24 - UNKWORD FLAGS_0x28; - char UNK_0x2C[0xC]; - ActivityList EFLIST_0x38; - char UNK_0x54[0x4]; - - ParticleModifier mMod; // at 0x58 - - char UNK_0x74[0x14]; - - s8 BYTE_0x88; - u8 BYTE_0x89; - bool BOOL_0x8A; - - UNKWORD FLAGS_0xB4; - - u16 RetireParticleAll(); - - UNKTYPE CalcGlobalMtx(math::MTX34 *); - - static void ModifierTravFunc_SetSimpleLightType(void *p, u32 payload) { - ParticleManager *mgr = (ParticleManager *)p; - u8 type = (u8)payload; - mgr->mMod.mLight.mType = type; - } - - static void ModifierTravFunc_SetSimpleLightAmbient(void *p, u32 payload) { - ParticleManager *mgr = (ParticleManager *)p; - ut::Color *color = (ut::Color *)payload; - mgr->mMod.mLight.mAmbColor = *color; - } - - static void ModifierTravFunc_SetScale(void *p, u32 payload) { - ParticleManager *mgr = (ParticleManager *)p; - math::VEC2 *scale = (math::VEC2 *)payload; - mgr->mMod.mScale = *scale; - } - - static void ModifierTravFunc_SetRotate(void *p, u32 payload) { - ParticleManager *mgr = (ParticleManager *)p; - math::VEC3 *rot = (math::VEC3 *)payload; - mgr->mMod.mRotate = *rot; - } -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_point.h b/include/nw4r/ef/ef_point.h deleted file mode 100644 index 3fdebae6..00000000 --- a/include/nw4r/ef/ef_point.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_POINT_H -#define NW4R_EF_POINT_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormPoint : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_rand.h b/include/nw4r/ef/ef_rand.h deleted file mode 100644 index 18741a1a..00000000 --- a/include/nw4r/ef/ef_rand.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef NW4R_EF_RAND_H -#define NW4R_EF_RAND_H -#include "common.h" - -namespace nw4r { -namespace ef { -struct Random { - u32 mSeed; // at 0x0 - - inline u32 MixRandomSeed() { - return mSeed = mSeed * 0x343fd + 0x269ec3; - } - - inline void Srand(u32 seed) { - mSeed = seed; - } - - inline u32 Rand() { - // WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE - return MixRandomSeed() >> 0x10; - } - - inline float RandFloat() { - // WARNING: THIS INLINE FUNCTION MAY NOT BE ACCURATE - return (float)Rand() / 0xFFFF; - } -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_ref.h b/include/nw4r/ef/ef_ref.h deleted file mode 100644 index 4f71969f..00000000 --- a/include/nw4r/ef/ef_ref.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef NW4R_EF_REF -#define NW4R_EF_REF -#include "common.h" -#include "math_types.h" - -namespace nw4r { -namespace ef { -struct ReferencedObject { - char UNK_0x0[0xC]; - UNKWORD WORD_0xC; - u32 mRefCount; // at 0x10 - char UNK_0x14[0x8]; - - virtual bool SendClosing(); - virtual UNKTYPE DestroyFunc(); - - inline void Initialize() { - mRefCount = 0; - WORD_0xC = 1; - } - - inline void Ref() { - mRefCount++; - } - - inline void UnRef() { - if (--mRefCount == 0 && WORD_0xC == 2) { - SendClosing(); - } - } - - inline void Destroy() { - DestroyFunc(); - WORD_0xC = 2; - if (mRefCount == 0) { - SendClosing(); - } - } -}; - -typedef ReferencedObject UNKREF; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_resource.h b/include/nw4r/ef/ef_resource.h deleted file mode 100644 index ac461516..00000000 --- a/include/nw4r/ef/ef_resource.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef NW4R_EF_RESOURCE -#define NW4R_EF_RESOURCE -#include "common.h" - -namespace nw4r { -namespace ef { -struct Resource { - EmitterResource *_FindEmitter(const char *, EffectProject *) const; - - static Resource *GetInstance(); -}; -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/ef/ef_sphere.h b/include/nw4r/ef/ef_sphere.h deleted file mode 100644 index 88aa9ca2..00000000 --- a/include/nw4r/ef/ef_sphere.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_SPHERE_H -#define NW4R_EF_SPHERE_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormSphere : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_torus.h b/include/nw4r/ef/ef_torus.h deleted file mode 100644 index e9521c19..00000000 --- a/include/nw4r/ef/ef_torus.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef NW4R_EF_TORUS_H -#define NW4R_EF_TORUS_H -#include "ef_emitterform.h" - -namespace nw4r -{ - namespace ef - { - struct EmitterFormTorus : EmitterForm - { - virtual UNKTYPE Emission(Emitter *, ParticleManager *, int, u32, float *, u16, float, const math::MTX34 *); - }; - } -} - -#endif \ No newline at end of file diff --git a/include/nw4r/ef/ef_util.h b/include/nw4r/ef/ef_util.h deleted file mode 100644 index 81ca35ef..00000000 --- a/include/nw4r/ef/ef_util.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef NW4R_EF_UTIL -#define NW4R_EF_UTIL -#include "common.h" -#include "ut_list.h" - -namespace nw4r { -namespace ef { -typedef void (*Action)(void *, u32); - -u16 UtlistToArray(const ut::List *, void **, int); - -UNKTYPE GetDirMtxY(math::MTX34 *, const math::VEC3 &); -UNKTYPE MtxGetRotation(const math::MTX34 &, math::VEC3 *); -UNKTYPE MtxGetTranslate(const math::MTX34 &, math::VEC3 *); -UNKTYPE MtxGetRotationMtx(const math::MTX34 &, math::MTX34 *); -UNKTYPE MtxGetScale(const math::MTX34 &, math::VEC3 *); -} // namespace ef -} // namespace nw4r - -#endif diff --git a/include/nw4r/lyt/lyt_animation.h b/include/nw4r/lyt/lyt_animation.h index c0d9f7cc..90ee30c0 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -1,21 +1,77 @@ #ifndef NW4R_LYT_ANIMATION_H #define NW4R_LYT_ANIMATION_H #include "common.h" -#include "nw4r/lyt/lyt_common.h" -#include "nw4r/lyt/lyt_resourceAccessor.h" -#include "nw4r/ut/ut_LinkList.h" +#include +#include +#include +#include namespace nw4r { namespace lyt { namespace res { -struct AnimationBlock {}; +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 AnimationBlock { - res::DataBlockHeader header; // at 0x0 - u16 frameSize; // at 0x8 - bool loop; // at 0xA - // . . . +struct AnimResource { + AnimResource(const void *anmResBuf) { + // TODO + } + + const res::BinaryFileHeader *mpFileHeader; // at 0x00 + const res::AnimationBlock *mpResBlock; // at 0x04 + const res::AnimationTagBlock *mpTagBlock; // at 0x08 + const res::AnimationShareBlock *mpShareBlock; // at 0x0C +}; + +namespace detail { +struct AnimPaneTree { + AnimPaneTree(Pane *pTargetPane, const AnimResource &animRes) : mAnimRes(animRes) { + // TODO + } + + bool IsEnabled() const { + // TODO + return false; + } + + AnimResource mAnimRes; // at 0x00 + u16 mAnimPaneIdx; // at 0x10 + u16 mLinkNum; // at 0x12 + u16 mAnimMatIdx[9]; // at 0x14 + u8 mAnimMatCnt; // at 0x26 +}; +} // namespace detail +struct AnimationGroupRef { + char name[17]; // at 0x00 + u8 flag; // at 0x11 + u8 padding[2]; // at 0x12 }; struct AnimTransform { @@ -31,9 +87,9 @@ struct AnimTransform { virtual void Animate(u32 idx, Pane *pPane) = 0; virtual void Animate(u32 idx, Material *pMaterial) = 0; - ut::LinkListNode mLink; // at 0x0 - AnimationBlock *mpRes; // at 0xC - f32 mFrame; // at 0x10 + ut::LinkListNode mLink; // at 0x4 + res::AnimationBlock *mpRes; // at 0xC + f32 mFrame; // at 0x10 }; struct AnimationLink { diff --git a/include/nw4r/lyt/lyt_bounding.h b/include/nw4r/lyt/lyt_bounding.h index 56740463..0131c016 100644 --- a/include/nw4r/lyt/lyt_bounding.h +++ b/include/nw4r/lyt/lyt_bounding.h @@ -2,6 +2,7 @@ #define NW4R_LYT_BOUNDING_H #include "common.h" #include "nw4r/lyt/lyt_drawInfo.h" +#include "nw4r/lyt/lyt_material.h" #include "nw4r/lyt/lyt_pane.h" namespace nw4r { @@ -10,15 +11,19 @@ namespace res { struct Bounding : Pane {}; } // namespace res -struct ResBlockSet {}; +struct ResBlockSet { + const res::TextureList *pTextureList; // at 0x00 + const res::FontList *pFontList; // at 0x04 + const res::MaterialList *pMaterialList; // at 0x08 + ResourceAccessor *pResAccessor; // at 0x0C +}; -struct Bounding : Pane { +class Bounding : public Pane { +public: Bounding(const res::Bounding *, const ResBlockSet &); virtual ~Bounding(); - virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; + NW4R_UT_RTTI_DECL(Bounding); virtual void DrawSelf(const DrawInfo &); - - static ut::detail::RuntimeTypeInfo typeInfo; }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index 7b488f63..c84d0065 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -12,7 +12,14 @@ namespace nw4r { namespace lyt { namespace res { -struct BinaryFileHeader : ut::BinaryFileHeader {}; +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 @@ -46,6 +53,17 @@ void SetVertexFormat(bool, u8); void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const ut::Color *); 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); + +s32 GetSignatureInt(const char *sig) { + return *((s32 *)sig); +} +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 71f429b2..9c732c2b 100644 --- a/include/nw4r/lyt/lyt_group.h +++ b/include/nw4r/lyt/lyt_group.h @@ -23,12 +23,25 @@ struct PaneLink { }; } // namespace detail -struct Group { +class Group { +public: Group(const res::Group *pResGroup, Pane *pRootPane); + virtual ~Group(); void AppendPane(Pane *pPane); void Init(); + ut::LinkList *GetPaneList() { + return &mPaneListLink; + } + bool IsUserAllocated() const { + return mbUserAllocated; + } + const char *GetName() const { + return mName; + } + +private: ut::LinkListNode mLink; // at 0x04 ut::LinkList mPaneListLink; // at 0x0C char mName[NW4R_RES_NAME_SIZE + 1]; // at 0x18 diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 87ce0f67..39714af4 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -2,13 +2,45 @@ #define NW4R_LYT_LAYOUT_H #include "common.h" #include +#include +#include #include namespace nw4r { namespace lyt { -struct Layout { - // TO-DO: Class members +namespace res { +struct Layout { + DataBlockHeader blockheader; // at 0x00 + u8 originType; // at 0x08 + u8 padding[3]; // at 0x09 + Size layoutSize; // at 0x0C +}; + +} // namespace res + +class Layout { +public: + ut::Rect GetLayoutRect() const; + static Pane *BuildPaneObj(s32 kind, const void *dataPtr, const ResBlockSet &ResBlockSet); + + Layout(); + virtual ~Layout(); // at 0x08 + virtual bool Build(const void *lytResBuf, ResourceAccessor *pResAcsr); // at 0x0C + virtual AnimTransform *CreateAnimTransform(); // at 0x10 + virtual AnimTransform *CreateAnimTransform(const void *animResBuf, ResourceAccessor *pResAcsr); // at 0x14 + virtual AnimTransform *CreateAnimTransform(const AnimResource &animRes, ResourceAccessor *pResAcsr); // at 0x18 + virtual void BindAnimation(AnimTransform *pAnimTrans); // at 0x1C + virtual void UnbindAnimation(AnimTransform *pAnimTrans); // at 0x20 + virtual void UnbindAllAnimation(); // at 0x24 + virtual bool BindAnimationAuto(const AnimResource &animRes, ResourceAccessor *pResAcsr); // at 0x28 + virtual void SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable); // at 0x2C + virtual void CalculateMtx(const DrawInfo &drawInfo); // at 0x30 + virtual void Draw(const DrawInfo &drawInfo); // at 0x34 + virtual void Animate(u32 option); // at 0x38 + virtual void SetTagProcessor(ut::TagProcessorBase *pTagProcessor); // at 0x3C + + // STATICS static void FreeMemory(void *p) { MEMFreeToAllocator(mspAllocator, p); } @@ -57,6 +89,32 @@ struct Layout { } } + template + static T *NewObj(T2 p2) { + T *obj = (T *)AllocMemory(sizeof(T)); + if (obj) { + return new (obj) T(p2); + } 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); + } else { + return nullptr; + } + } + +private: + ut::LinkList mAnimTransList; // at 0x04 + Pane *mpRootPane; // at 0x10 + GroupContainer *mpGroupContainer; // at 0x14 + Size mLayoutSize; // at 0x18 + static MEMAllocator *mspAllocator; }; } // namespace lyt diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index e6586c63..7a8d986c 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -10,6 +10,15 @@ 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; @@ -26,15 +35,26 @@ struct BitGXNums { }; struct Material { - // SetupGX__Q34nw4r3lyt8MaterialFbUc - // BindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform - // UnbindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform - // UnbindAllAnimation__Q34nw4r3lyt8MaterialFv - // Animate__Q34nw4r3lyt8MaterialFv - // FindAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform - // FindAnimationLink__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResource - // SetAnimationEnable__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransformb - // SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb + // IsBlendModeCap__Q34nw4r3lyt8MaterialCFv + // IsAlphaCompareCap__Q34nw4r3lyt8MaterialCFv + // IsTevSwapCap__Q34nw4r3lyt8MaterialCFv + // IsMatColorCap__Q34nw4r3lyt8MaterialCFv + // IsChanCtrlCap__Q34nw4r3lyt8MaterialCFv + // SetTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf + // GetTexturePtr__Q34nw4r3lyt8MaterialFUc + // GetTexSRTCap__Q34nw4r3lyt8MaterialCFv + // GetIndTexSRTCap__Q34nw4r3lyt8MaterialCFv + // SetIndTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf + + ut::LinkList *GetAnimationList() { + return &mAnimList; + } + bool IsUserAllocated() const { + return mbUserAllocated; + } + const char *GetName() const { + return mName; + } virtual ~Material(); // at 0x08 virtual bool SetupGX(bool bModVtxCok, u8 alpha); // at 0x0C @@ -47,6 +67,7 @@ struct Material { virtual void SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable); // at 0x28 virtual void SetAnimationEnable(const AnimResource &animRes, bool bEnable); // at 0x2C +private: ut::LinkList mAnimList; // at 0x4 GXColorS10 mTevCols[3]; // at 0x10 ut::Color mTevKCols[4]; // at 0x28 diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index 272e226d..d7a83067 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -16,19 +16,6 @@ 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 detail { struct PaneBase { PaneBase(); @@ -38,14 +25,17 @@ struct PaneBase { } // namespace detail +namespace res { + // TODO: Find proper place? // GUESS: In the FindExtUserDataByName function it iterates through ExtUserData struct ExtUserData { - u32 stringOffs; - u32 UNK_0x04; - u32 UNK_0x08; + u32 nameOffs; // at 0x00 + u32 datOffs; // at 0x04 + u16 numEntries; // at 0x08 + u8 type; // at 0x0A + u8 padding; // at 0x0B }; -namespace res { struct ExtUserDataList { DataBlockHeader blockHeader; // at 0x00 @@ -67,20 +57,70 @@ struct Pane { }; } // namespace res -struct Pane : detail::PaneBase { +class Pane : detail::PaneBase { +public: // For use with TestBit enum PaneBits { VISIBLE, INFLUENCED_ALPHA, LOCATION_ADJUST }; bool IsVisible() const { return detail::TestBit(mFlag, VISIBLE); } + void SetVisible(bool bVisible) { + detail::SetBit(&mFlag, VISIBLE, bVisible); + } bool IsInfluencedAlpha() const { return detail::TestBit(mFlag, INFLUENCED_ALPHA); } bool IsLocationAdjust() const { return detail::TestBit(mFlag, LOCATION_ADJUST); } + bool IsUserAllocated() const { + return mbUserAllocated; + } + ut::LinkList *GetChildList() { + return &mChildList; + } + ut::LinkList *GetAnimationList() { + return &mAnimList; + } + + const math::MTX34 *GetGlobalMtx() const { + return &mGlbMtx; + } + Pane *GetParent() const { + return mpParent; + } + + const math::VEC2 *GetScale() const { + return &mScale; + } + void SetScale(const math::VEC2 &value) { + mScale = value; + } + + u8 GetAlpha() const { + return mAlpha; + } + void SetAlpha(u8 value) { + mAlpha = value; + } + + const Size *GetSize() const { + return &mSize; + } + void SetSize(const Size &value) { + mSize = value; + } + + const res::ExtUserDataList *GetExtUserDataList() const { + return mpExtUserDataList; + } + void SetExtUserDataList(const res::ExtUserDataList *pBlock) { + mpExtUserDataList = pBlock; + } + + Pane(); Pane(const res::Pane *pBlock); void Init(); void SetName(const char *pName); @@ -96,11 +136,11 @@ struct Pane : detail::PaneBase { math::VEC2 GetVtxPos() const; void CalculateMtxChild(const DrawInfo &drawInfo); u16 GetExtUserDataNum() const; - ExtUserData *GetExtUserData() const; - ExtUserData *FindExtUserDataByName(const char *name); + res::ExtUserData *GetExtUserData() const; + res::ExtUserData *FindExtUserDataByName(const char *name); virtual ~Pane(); // at 0x8 - virtual const ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const; // at 0xC + NW4R_UT_RTTI_DECL(Pane); // at 0x0C virtual void CalculateMtx(const DrawInfo &drawInfo); // at 0x10 virtual void Draw(const DrawInfo &); // at 0x14 virtual void DrawSelf(const DrawInfo &); // at 0x18 @@ -127,27 +167,26 @@ struct Pane : detail::PaneBase { virtual Material *GetMaterial(u32 idx) const; // at 0x6C virtual void LoadMtx(const DrawInfo &drawInfo); // at 0x70 - Pane *mpParent; // at 0x0C - ut::LinkList mChildList; // at 0x10 - ut::LinkList mAnimList; // at 0x1C; - Material *mpMaterial; // at 0x28 - math::VEC3 mTranslate; // at 0x2C - math::VEC3 mRotate; // at 0x38 - math::VEC2 mScale; // at 0x44 - Size mSize; // at 0x4C - math::MTX34 mMtx; // at 0x54 - math::MTX34 mGlbMtx; // at 0x84 - res::ExtUserDataList *mpExtUserDataList; // at 0xB4 - u8 mAlpha; // at 0xB8 - u8 mGlbAlpha; // at 0xB9 - u8 mBasePosition; // at 0xBA - u8 mFlag; // at 0xBB - char mName[PANE_NAME_SIZE + 1]; // at 0xBC - char mUserData[PANE_USERDATA_SIZE + 1]; // at 0xCD - bool mbUserAllocated; // at 0xD6 - u8 mPadding; // at 0xD7 - - static ut::detail::RuntimeTypeInfo typeInfo; +private: + Pane *mpParent; // at 0x0C + ut::LinkList mChildList; // at 0x10 + ut::LinkList mAnimList; // at 0x1C; + Material *mpMaterial; // at 0x28 + math::VEC3 mTranslate; // at 0x2C + math::VEC3 mRotate; // at 0x38 + math::VEC2 mScale; // at 0x44 + Size mSize; // at 0x4C + math::MTX34 mMtx; // at 0x54 + math::MTX34 mGlbMtx; // at 0x84 + const res::ExtUserDataList *mpExtUserDataList; // at 0xB4 + u8 mAlpha; // at 0xB8 + u8 mGlbAlpha; // at 0xB9 + u8 mBasePosition; // at 0xBA + u8 mFlag; // at 0xBB + char mName[PANE_NAME_SIZE + 1]; // at 0xBC + char mUserData[PANE_USERDATA_SIZE + 1]; // at 0xCD + bool mbUserAllocated; // at 0xD6 + u8 mPadding; // at 0xD7 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_picture.h b/include/nw4r/lyt/lyt_picture.h new file mode 100644 index 00000000..8df1e561 --- /dev/null +++ b/include/nw4r/lyt/lyt_picture.h @@ -0,0 +1,32 @@ +#ifndef NW4R_LYT_PICTURE_H +#define NW4R_LYT_PICTURE_H + +#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); + +private: + ut::Color mVtxColors[4]; // at 0xD8 + detail::TexCoordAry mTexCoordAry; // at 0xE8 +}; + +} // namespace lyt + +} // namespace nw4r + +#endif diff --git a/include/nw4r/lyt/lyt_textBox.h b/include/nw4r/lyt/lyt_textBox.h new file mode 100644 index 00000000..4eefc5b4 --- /dev/null +++ b/include/nw4r/lyt/lyt_textBox.h @@ -0,0 +1,55 @@ +#ifndef LYT_TEXT_BOX_H +#define LYT_TEXT_BOX_H + +#include + +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) { + mpTagProcessor = pTagProcessor; + } + + TextBox(const res::TextBox *, const ResBlockSet &resBlockSet); + virtual ~TextBox(); + NW4R_UT_RTTI_DECL(TextBox); + + wchar_t *mTextBuf; // at 0xD8 // ptr to is Guess + ut::Color mTextColors[2]; // at 0xDC + ut::Font *mpFont; // at 0xE4 + Size mFontSize; // at 0xE8 + f32 mLineSpace; // at 0xF0 + f32 mCharSpace; // at 0xF4 + ut::TagProcessorBase *mpTagProcessor; // at 0xF8 + u16 mTextBufBytes; // at 0xFC + u16 mTextLen; // at 0xFE + u8 mTextPosition; // at 0x100 + struct { // + u8 bAllocFont : 1; // + u8 textAligntment : 1; // + } mBits; // at 0x101 +}; + +} // namespace lyt +} // namespace nw4r +#endif diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index e9ece89e..97e5890d 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -1,16 +1,81 @@ #ifndef NW4R_LYT_TYPES_H #define NW4R_LYT_TYPES_H +#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 + +struct AnimationShareInfo { + const char *GetSrcPaneName() const { + return srcPaneName; + } + + char srcPaneName[17]; // at 0x00 + char targetGroupName[17]; // at 0x11 + u8 padding[2]; // at 0x12 +}; namespace detail { template inline bool TestBit(T bits, int index) { T mask = 1 << index; return bits & mask; } +template +inline bool SetBit(T *bits, int pos, bool val) { + T mask = T(1 << pos); + *bits = T((*bits & ~mask)) | (val << pos); +} + +template +T *ConvertOffsetToPtr(const void *baseAddress, unsigned int offset) { + return (T *)((u32)baseAddress + offset); +} + } // namespace detail } // namespace lyt diff --git a/include/nw4r/lyt/lyt_window.h b/include/nw4r/lyt/lyt_window.h new file mode 100644 index 00000000..4a3c304a --- /dev/null +++ b/include/nw4r/lyt/lyt_window.h @@ -0,0 +1,69 @@ +#ifndef NW4R_LYT_WINDOW_H +#define NW4R_LYT_WINDOW_H + +#include +#include +#include +#include + +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 +}; + +struct Frame { + bool textureFlip; // at 0x00 + Material *pMaterial; // at 0x04 +}; + +struct WindowFramSize { + f32 l; // at 0x00 + f32 r; // at 0x04 + f32 t; // at 0x08 + f32 b; // at 0x0C +}; + +class Window : public Pane { +public: + Window(const res::Window *, const ResBlockSet &ResBlockSet); + virtual ~Window(); + NW4R_UT_RTTI_DECL(Window); + +private: + res::InflationLRTB mContentInflation; // at 0x0D8 + Content mContent; // at 0x0E8 + Frame *mFrams; // at 0x100 + u8 mFrameNum; // 0x104 +}; + +} // namespace lyt + +} // namespace nw4r + +#endif diff --git a/include/nw4r/ut/ut_RuntimeTypeInfo.h b/include/nw4r/ut/ut_RuntimeTypeInfo.h index 43c7f3d0..83ac5d85 100644 --- a/include/nw4r/ut/ut_RuntimeTypeInfo.h +++ b/include/nw4r/ut/ut_RuntimeTypeInfo.h @@ -3,30 +3,27 @@ #include // Declare type RTTI and accessor function -#define NW4R_UT_RTTI_DECL(T) \ - static nw4r::ut::detail::RuntimeTypeInfo typeInfo; \ - virtual const nw4r::ut::detail::RuntimeTypeInfo* GetRuntimeTypeInfo() \ - const { \ - return &typeInfo; \ +#define NW4R_UT_RTTI_DECL(T) \ + static nw4r::ut::detail::RuntimeTypeInfo typeInfo; \ + virtual const nw4r::ut::detail::RuntimeTypeInfo *GetRuntimeTypeInfo() const { \ + return &typeInfo; \ } // Define type RTTI (base type) -#define NW4R_UT_RTTI_DEF_BASE(T) \ - nw4r::ut::detail::RuntimeTypeInfo T::typeInfo(NULL) +#define NW4R_UT_RTTI_DEF_BASE(T) nw4r::ut::detail::RuntimeTypeInfo T::typeInfo(NULL) // Define type RTTI (derived type) -#define NW4R_UT_RTTI_DEF_DERIVED(T, BASE) \ - nw4r::ut::detail::RuntimeTypeInfo T::typeInfo(&BASE::typeInfo) +#define NW4R_UT_RTTI_DEF_DERIVED(T, BASE) nw4r::ut::detail::RuntimeTypeInfo T::typeInfo(&BASE::typeInfo) namespace nw4r { namespace ut { namespace detail { struct RuntimeTypeInfo { - RuntimeTypeInfo(const RuntimeTypeInfo* base) : mBase(base) {} + RuntimeTypeInfo(const RuntimeTypeInfo *base) : mBase(base) {} - bool IsDerivedFrom(const RuntimeTypeInfo* base) const { - for (const RuntimeTypeInfo* it = this; it != NULL; it = it->mBase) { + bool IsDerivedFrom(const RuntimeTypeInfo *base) const { + for (const RuntimeTypeInfo *it = this; it != NULL; it = it->mBase) { if (it == base) { return true; } @@ -35,24 +32,22 @@ struct RuntimeTypeInfo { return false; } - const RuntimeTypeInfo* mBase; // at 0x0 + const RuntimeTypeInfo *mBase; // at 0x0 }; template -inline const RuntimeTypeInfo* GetTypeInfoFromPtr_(T* ptr) { +inline const RuntimeTypeInfo *GetTypeInfoFromPtr_(T *ptr) { return &ptr->typeInfo; } } // namespace detail template -inline TDerived DynamicCast(TBase* ptr) { +inline TDerived DynamicCast(TBase *ptr) { // Derived type info - const detail::RuntimeTypeInfo* derivedTypeInfo = - detail::GetTypeInfoFromPtr_(static_cast(NULL)); - + const detail::RuntimeTypeInfo *derivedTypeInfo = detail::GetTypeInfoFromPtr_(static_cast(NULL)); // Downcast if possible - if (ptr->GetRuntimeTypeInfo()->IsDerivedFrom(derivedTypeInfo)) { + if (ptr && ptr->GetRuntimeTypeInfo()->IsDerivedFrom(derivedTypeInfo)) { return static_cast(ptr); } diff --git a/include/nw4r/ut/ut_algorithm.h b/include/nw4r/ut/ut_algorithm.h index 38aa38ab..802d086f 100644 --- a/include/nw4r/ut/ut_algorithm.h +++ b/include/nw4r/ut/ut_algorithm.h @@ -9,20 +9,29 @@ namespace { /** * Value operations */ -template inline T Max(T t1, T t2) { return (t1 < t2) ? t2 : t1; } +template +inline T Max(T t1, T t2) { + return (t1 < t2) ? t2 : t1; +} -template inline T Min(T t1, T t2) { return (t1 > t2) ? t2 : t1; } +template +inline T Min(T t1, T t2) { + return (t1 > t2) ? t2 : t1; +} -template inline T Clamp(T value, T min, T max) { +template +inline T Clamp(T value, T min, T max) { return value > max ? max : (value < min ? min : value); } -template inline T Abs(T x) { +template +inline T Abs(T x) { // Static cast needed to break abs optimization during instruction selection return x < 0 ? static_cast(-x) : static_cast(x); } -template <> f32 inline Abs(register f32 x) { +template <> +f32 inline Abs(register f32 x) { register f32 ax; // clang-format off @@ -37,54 +46,62 @@ template <> f32 inline Abs(register f32 x) { /** * Bit operations */ -template inline T BitExtract(T bits, int pos, int len) { +template +inline T BitExtract(T bits, int pos, int len) { T mask = (1 << len) - 1; return (bits >> pos) & mask; } -template inline bool TestBit(T t, int bitIndexLSB) { +template +inline bool TestBit(T t, int bitIndexLSB) { return BitExtract(t, sizeof(T), bitIndexLSB); } /** * Pointer operations */ -inline u32 GetIntPtr(const void* ptr) { return reinterpret_cast(ptr); } - -template -inline const void* AddOffsetToPtr(const void* ptr, T offset) { - return reinterpret_cast(GetIntPtr(ptr) + offset); +inline u32 GetIntPtr(const void *ptr) { + return reinterpret_cast(ptr); } -inline s32 GetOffsetFromPtr(const void* start, const void* end) { +template +inline const void *AddOffsetToPtr(const void *ptr, T offset) { + return reinterpret_cast(GetIntPtr(ptr) + offset); +} + +inline s32 GetOffsetFromPtr(const void *start, const void *end) { return static_cast(GetIntPtr(end) - GetIntPtr(start)); } -inline int ComparePtr(const void* p1, const void* p2) { +inline int ComparePtr(const void *p1, const void *p2) { return static_cast(GetIntPtr(p1) - GetIntPtr(p2)); } /** * Rounding */ -template inline T RoundUp(T t, unsigned int alignment) { +template +inline T RoundUp(T t, unsigned int alignment) { return (alignment + t - 1) & ~(alignment - 1); } -template inline void* RoundUp(T* t, unsigned int alignment) { +template +inline void *RoundUp(T *t, unsigned int alignment) { u32 value = reinterpret_cast(t); u32 rounded = (alignment + value - 1) & ~(alignment - 1); - return reinterpret_cast(rounded); + return reinterpret_cast(rounded); } -template inline T RoundDown(T t, unsigned int alignment) { +template +inline T RoundDown(T t, unsigned int alignment) { return t & ~(alignment - 1); } -template inline void* RoundDown(T* t, unsigned int alignment) { +template +inline void *RoundDown(T *t, unsigned int alignment) { u32 value = reinterpret_cast(t); u32 rounded = value & ~(alignment - 1); - return reinterpret_cast(rounded); + return reinterpret_cast(rounded); } } // namespace diff --git a/src/nw4r/lyt/lyt_common.cpp b/src/nw4r/lyt/lyt_common.cpp index 795a908f..922cf77b 100644 --- a/src/nw4r/lyt/lyt_common.cpp +++ b/src/nw4r/lyt/lyt_common.cpp @@ -12,7 +12,6 @@ using namespace ut; // EqualsResName__Q34nw4r3lyt6detailFPCcPCc bool detail::EqualsResName(const char *name1, const char *name2) { return strncmp(name1, name2, NW4R_RES_NAME_SIZE) == 0; - ; } // EqualsMaterialName__Q34nw4r3lyt6detailFPCcPCc @@ -22,7 +21,7 @@ bool detail::EqualsMaterialName(const char *name1, const char *name2) { // TestFileHeader__Q34nw4r3lyt6detailFRCQ44nw4r3lyt3res16BinaryFileHeaderUl bool detail::TestFileHeader(const res::BinaryFileHeader &fileHeader, u32 testSig) { - return ((testSig == fileHeader.magic) && (fileHeader.byteOrder == NW4R_BYTEORDER_BIG)); + return ((testSig == detail::GetSignatureInt(fileHeader.signature)) && (fileHeader.byteOrder == NW4R_BYTEORDER_BIG)); } namespace detail { diff --git a/src/nw4r/lyt/lyt_group.cpp b/src/nw4r/lyt/lyt_group.cpp index 493c25fc..82433fdf 100644 --- a/src/nw4r/lyt/lyt_group.cpp +++ b/src/nw4r/lyt/lyt_group.cpp @@ -10,7 +10,8 @@ Group::Group(const res::Group *pResGroup, Pane *pRootPane) : mLink(), mPaneListL Init(); strncpy(this->mName, pResGroup->mName, NW4R_RES_NAME_SIZE); this->mName[NW4R_RES_NAME_SIZE] = '\0'; - const char *paneNameBase = (char *)(&pResGroup[1]); + const char *paneNameBase = detail::ConvertOffsetToPtr(pResGroup, sizeof(res::Group)); + for (int i = 0; i < pResGroup->paneNum; i++) { Pane *pFindPane = pRootPane->FindPaneByName(paneNameBase + i * NW4R_RES_NAME_SIZE, true); if (pFindPane) { @@ -49,7 +50,7 @@ GroupContainer::~GroupContainer() { while (it != this->mGroupList.GetEndIter()) { ut::LinkList::Iterator currIt = it++; this->mGroupList.Erase(currIt); - if (!currIt->mbUserAllocated) { + if (!currIt->IsUserAllocated()) { Layout::DeleteObj(&*currIt); } } @@ -64,7 +65,7 @@ void GroupContainer::AppendGroup(Group *pGroup) { Group *GroupContainer::FindGroupByName(const char *findName) { for (ut::LinkList::Iterator it = this->mGroupList.GetBeginIter(); it != this->mGroupList.GetEndIter(); it++) { - if (detail::EqualsResName(it->mName, findName)) { + if (detail::EqualsResName(it->GetName(), findName)) { return &*it; } } diff --git a/src/nw4r/lyt/lyt_layout.cpp b/src/nw4r/lyt/lyt_layout.cpp index e69de29b..75f8a4ee 100644 --- a/src/nw4r/lyt/lyt_layout.cpp +++ b/src/nw4r/lyt/lyt_layout.cpp @@ -0,0 +1,244 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace nw4r { + +namespace lyt { + +// mspAllocator__Q34nw4r3lyt6Layout +MEMAllocator *Layout::mspAllocator; + +namespace { + +// SetTagProcessorImpl__Q34nw4r3lyt24@unnamed@lyt_layout_cpp@FPQ34nw4r3lyt4PanePQ34nw4r2ut19TagProcessorBase +void SetTagProcessorImpl(Pane *pPane, ut::TagProcessorBase *pTagProcessor) { + TextBox *pTextBox = ut::DynamicCast(pPane); + if (pTextBox) { + pTextBox->SetTagProcessor(pTagProcessor); + } + for (ut::LinkList::Iterator it = pPane->GetChildList()->GetBeginIter(); + it != pPane->GetChildList()->GetEndIter(); ++it) { + SetTagProcessorImpl(&*it, pTagProcessor); + } +} + +// IsIncludeAnimationGroupRef__Q34nw4r3lyt24@unnamed@lyt_layout_cpp@FPQ34nw4r3lyt14GroupContainerPCQ34nw4r3lyt17AnimationGroupRefUsbPQ34nw4r3lyt4Pane +// Doesnt match DWARF Vars, but matches +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); + for (ut::LinkList::Iterator paneList = pGroup->GetPaneList()->GetBeginIter(); + paneList != pGroup->GetPaneList()->GetEndIter(); paneList++) { + const Pane *t = paneList->mTarget; + if (t == pTargetPane) { + return true; + } + if (bDescendingBind) { + for (const Pane *pParentPane = pTargetPane->GetParent(); pParentPane != nullptr; + pParentPane = pParentPane->GetParent()) { + if (t == pParentPane) { + return true; + } + } + } + } + } + return false; +} + +} // namespace + +// __ct__Q34nw4r3lyt6LayoutFv +Layout::Layout() : mAnimTransList(), mpRootPane(nullptr), mpGroupContainer(nullptr) {} + +// __dt__Q34nw4r3lyt6LayoutFv +Layout::~Layout() { + DeleteObj(mpGroupContainer); + if (mpRootPane && !mpRootPane->IsUserAllocated()) { + DeleteObj(mpRootPane); + } + ut::LinkList::Iterator it = mAnimTransList.GetBeginIter(); + while (it != mAnimTransList.GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + mAnimTransList.Erase(currIt); + DeleteObj(&*currIt); + } +} + +// Build__Q34nw4r3lyt6LayoutFPCvPQ34nw4r3lyt16ResourceAccessor +bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { + const res::BinaryFileHeader *pFileHead = (const res::BinaryFileHeader *)(lytResBuf); + if (!detail::TestFileHeader(*pFileHead, 'RLYT')) { + return false; + } + if (!detail::TestFileVersion(*pFileHead)) { + return false; + } + + ResBlockSet resBlockSet = {nullptr, nullptr, nullptr, pResAcsr}; + Pane *pParentPane = nullptr; + Pane *pLastPane = nullptr; + bool bReadRootGroup = false; + int groupNestLevel = 0; + + const void *dataPtr = ((u8 *)lytResBuf + pFileHead->headerSize); + for (int i = 0; i < pFileHead->dataBlocks; i++) { + 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; + case 'txl1': // Texture List + resBlockSet.pTextureList = (const res::TextureList *)dataPtr; + break; + case 'fnl1': // Font List + resBlockSet.pFontList = (const res::FontList *)dataPtr; + break; + case 'mat1': // Material + resBlockSet.pMaterialList = (const res::MaterialList *)dataPtr; + break; + case 'wnd1': // Window + case 'pan1': // Pane + case 'pic1': // Picture + case 'txt1': // Text Box + case 'bnd1': // Boundary Pane + Pane *pPane = BuildPaneObj(pDataBlockHead->kind, dataPtr, resBlockSet); + if (pPane) { + if (mpRootPane == nullptr) { + mpRootPane = pPane; + } + if (pParentPane) { + pParentPane->AppendChild(pPane); + } + pLastPane = pPane; + } + break; + case 'usd1': // User Data + pLastPane->SetExtUserDataList((const res::ExtUserDataList *)dataPtr); + break; + case 'pas1': // PaneChildren Start + pParentPane = pLastPane; + break; + case 'pae1': // PaneChildren End + pLastPane = pParentPane; + pParentPane = pLastPane->GetParent(); + break; + case 'grp1': // Group + if (!bReadRootGroup) { + bReadRootGroup = true; + mpGroupContainer = NewObj(); + } else { + if (mpGroupContainer && groupNestLevel == 1) { + Group *pGroup = NewObj((const res::Group *)dataPtr, mpRootPane); + if (pGroup) { + mpGroupContainer->AppendGroup(pGroup); + } + } + } + break; + case 'grs1': // Group Children Start + groupNestLevel++; + break; + case 'gre1': // Group Children End + groupNestLevel--; + break; + default: + break; + } + dataPtr = ((u8 *)dataPtr + pDataBlockHead->size); + } + return true; +} + +// CreateAnimTransform__Q34nw4r3lyt6LayoutFv +AnimTransform *Layout::CreateAnimTransform() { + return nullptr; +} + +// CreateAnimTransform__Q34nw4r3lyt6LayoutFPCvPQ34nw4r3lyt16ResourceAccessor +AnimTransform *Layout::CreateAnimTransform(const void *animResBuf, ResourceAccessor *pResAcsr) { + return nullptr; +} + +// CreateAnimTransform__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt12AnimResourcePQ34nw4r3lyt16ResourceAccessor +AnimTransform *Layout::CreateAnimTransform(const AnimResource &animRes, ResourceAccessor *pResAcsr) { + return nullptr; +} + +// BindAnimation__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransform +void Layout::BindAnimation(AnimTransform *pAnimTrans) {} + +// UnbindAnimation__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransform +void Layout::UnbindAnimation(AnimTransform *pAnimTrans) {} + +// UnbindAllAnimation__Q34nw4r3lyt6LayoutFv +void Layout::UnbindAllAnimation() {} + +// BindAnimationAuto__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt12AnimResourcePQ34nw4r3lyt16ResourceAccessor +bool Layout::BindAnimationAuto(const AnimResource &animRes, ResourceAccessor *pResAcsr) { + return IsIncludeAnimationGroupRef(nullptr, nullptr, 0, 0, nullptr); +} + +// SetAnimationEnable__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransformb +void Layout::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) {} + +// CalculateMtx__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt8DrawInfo +void Layout::CalculateMtx(const DrawInfo &drawInfo) {} + +// Draw__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt8DrawInfo +void Layout::Draw(const DrawInfo &drawInfo) {} + +// Animate__Q34nw4r3lyt6LayoutFUl +void Layout::Animate(u32 option) {} + +// GetLayoutRect__Q34nw4r3lyt6LayoutCFv +ut::Rect Layout::GetLayoutRect() const {} + +// SetTagProcessor__Q34nw4r3lyt6LayoutFPQ34nw4r2ut19TagProcessorBase +void Layout::SetTagProcessor(ut::TagProcessorBase *pTagProcessor) { + SetTagProcessorImpl(this->mpRootPane, pTagProcessor); +} + +// BuildPaneObj__Q34nw4r3lyt6LayoutFlPCvRCQ34nw4r3lyt11ResBlockSet +Pane *Layout::BuildPaneObj(s32 kind, const void *dataPtr, const ResBlockSet &resBlockSet) { + // Oddly enough the breaks are required here to not inline the function??? + // Had them as left over from editing and somehow when removing them it just broke Build. + // Probably some analysis depth as 3 break statements do it + switch (kind) { + case 'pan1': { + const res::Pane *pResPane = (const res::Pane *)dataPtr; + return NewObj(pResPane); + } break; + case 'pic1': { + const res::Picture *pResPic = (const res::Picture *)dataPtr; + return NewObj(pResPic, resBlockSet); + } break; + case 'txt1': { + const res::TextBox *pBlock = (const res::TextBox *)dataPtr; + return NewObj(pBlock, resBlockSet); + } break; + case 'wnd1': { + const res::Window *pBlock = (const res::Window *)dataPtr; + return NewObj(pBlock, resBlockSet); + } break; + case 'bnd1': { + const res::Bounding *pResBounding = (const res::Bounding *)dataPtr; + return NewObj(pResBounding, resBlockSet); + } break; + default: + return nullptr; + } +} + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp index e69de29b..9546dd49 100644 --- a/src/nw4r/lyt/lyt_material.cpp +++ b/src/nw4r/lyt/lyt_material.cpp @@ -0,0 +1,10 @@ + +// SetupGX__Q34nw4r3lyt8MaterialFbUc +// BindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +// UnbindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +// UnbindAllAnimation__Q34nw4r3lyt8MaterialFv +// Animate__Q34nw4r3lyt8MaterialFv +// FindAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +// FindAnimationLink__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResource +// SetAnimationEnable__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransformb +// SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 043beb87..9dd360ef 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -8,12 +8,6 @@ #include // ReverseYAxis__22@unnamed@lyt_pane_cpp@FPQ34nw4r4math5MTX34 - -void float_order() { - 0.0f; - 1.0f; -} - namespace nw4r { namespace lyt { @@ -29,6 +23,23 @@ PaneBase::~PaneBase() {} NW4R_UT_RTTI_DEF_BASE(Pane); // __ct__Q34nw4r3lyt4PaneFv +// Guess pulled from BBA/slight modified +Pane::Pane() : mChildList(), mAnimList(), mSize() { + this->mpParent = nullptr; + this->mpMaterial = nullptr; + this->mbUserAllocated = false; + this->mpExtUserDataList = nullptr; + this->mBasePosition = 4; + memset(this->mName, 0, PANE_NAME_SIZE + 1); + memset(this->mUserData, 0, PANE_USERDATA_SIZE + 1); + this->mTranslate = math::VEC3(0.0f, 0.0f, 0.0f); + this->mRotate = math::VEC3(0.0f, 0.0f, 0.0f); + this->mScale = math::VEC2(1.0f, 1.0f); + this->mSize = Size(); + this->mAlpha = 0xFF; + this->mGlbAlpha = 0xFF; + SetVisible(true); +} // __dt__Q34nw4r2ut38LinkListFv @@ -69,12 +80,12 @@ Pane::~Pane() { ut::LinkList::Iterator currIt = it++; mChildList.Erase(currIt); if (!currIt->mbUserAllocated) { - Layout::DeleteObj(&*currIt); + Layout::DeleteObj(&*currIt); } } this->UnbindAnimationSelf(nullptr); - if (this->mpMaterial && !this->mpMaterial->mbUserAllocated) { - Layout::DeleteObj(this->mpMaterial); + if (this->mpMaterial && !this->mpMaterial->IsUserAllocated()) { + Layout::DeleteObj(this->mpMaterial); } } @@ -189,7 +200,7 @@ Pane *Pane::FindPaneByName(const char *findName, bool bRecursive) { // FindMaterialByName__Q34nw4r3lyt4PaneFPCcb Material *Pane::FindMaterialByName(const char *findName, bool bRecursive) { - if (this->mpMaterial && detail::EqualsMaterialName(this->mpMaterial->mName, findName)) { + if (this->mpMaterial && detail::EqualsMaterialName(this->mpMaterial->GetName(), findName)) { return this->mpMaterial; } if (bRecursive) { @@ -501,34 +512,32 @@ u16 Pane::GetExtUserDataNum() const { } return 0; } -ExtUserData *Pane::GetExtUserData() const { +res::ExtUserData *Pane::GetExtUserData() const { if (this->mpExtUserDataList) { - return (ExtUserData *)(this->mpExtUserDataList + 1); + return detail::ConvertOffsetToPtr(this->mpExtUserDataList, sizeof(res::ExtUserDataList)); } return nullptr; } -ExtUserData *Pane::FindExtUserDataByName(const char *name) { - ExtUserData *pUserData = GetExtUserData(); +res::ExtUserData *Pane::FindExtUserDataByName(const char *name) { + res::ExtUserData *pUserData = GetExtUserData(); if (!pUserData) { return nullptr; } int i = 0; - for (int i = 0; i < this->mpExtUserDataList->num;) { - u32 offset = pUserData->stringOffs; + for (int i = 0; i < this->mpExtUserDataList->num; i++, pUserData++) { + u32 offset = pUserData->nameOffs; const char *str = 0; if (offset != 0) { - str = (const char *)(pUserData) + offset; + str = detail::ConvertOffsetToPtr(pUserData, offset); } else { - str = 0; + str = nullptr; } if (strcmp(name, str) == 0) { return pUserData; }; - i++; - pUserData++; } return nullptr; } From 47eaa04f7da8abad100eaebd0e47d5ad1d409817 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 25 May 2024 22:44:07 -0400 Subject: [PATCH 07/22] lyt_layout matching --- config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- include/nw4r/lyt/lyt_animation.h | 85 ++++++++++++++++----- include/nw4r/lyt/lyt_common.h | 4 +- include/nw4r/lyt/lyt_layout.h | 13 ++-- include/nw4r/lyt/lyt_types.h | 11 +-- include/nw4r/lyt/lyt_utils.h | 16 ++++ src/nw4r/lyt/lyt_layout.cpp | 126 ++++++++++++++++++++++++++++--- 8 files changed, 209 insertions(+), 50 deletions(-) create mode 100644 include/nw4r/lyt/lyt_utils.h diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 2f635c49..829dfb90 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26115,7 +26115,7 @@ MultipleAlpha__Q34nw4r3lyt6detailFQ34nw4r2ut5ColorUc = .text:0x80492B20; // type SetVertexFormat__Q34nw4r3lyt6detailFbUc = .text:0x80492B60; // type:function size:0xE4 DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5Color = .text:0x80492C50; // type:function size:0x560 DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5ColorUc = .text:0x804931B0; // type:function size:0x130 -FUN_804932e0 = .text:0x804932E0; // type:function size:0x70 +BindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb = .text:0x804932E0; // type:function size:0x70 FUN_80493350 = .text:0x80493350; // type:function size:0x78 FUN_804933d0 = .text:0x804933D0; // type:function size:0x70 FUN_80493440 = .text:0x80493440; // type:function size:0xCC diff --git a/configure.py b/configure.py index cc6aa06d..f8306211 100644 --- a/configure.py +++ b/configure.py @@ -355,7 +355,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_init.cpp"), Object(Matching, "nw4r/lyt/lyt_pane.cpp"), Object(Matching, "nw4r/lyt/lyt_group.cpp"), - Object(NonMatching, "nw4r/lyt/lyt_layout.cpp"), + Object(Matching, "nw4r/lyt/lyt_layout.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 90ee30c0..dbb5af4a 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -39,11 +39,55 @@ struct AnimationShareBlock { }; } // namespace res -struct AnimResource { - AnimResource(const void *anmResBuf) { - // TODO +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: + AnimResource(); + AnimResource(const void *anmResBuf) { + Set(anmResBuf); + } + void Set(const void *anmResBuf); + void Init(); + u16 GetGroupNum() const; + const AnimationGroupRef *GetGroupArray() const; + bool IsDescendingBind() const; + u16 GetAnimationShareInfoNum() const; + AnimationShareInfo *GetAnimationShareInfoArray() const; + u16 CalcAnimationNum(Pane *pPane, bool bRecursive) const; + u16 CalcAnimationNum(Group *pGroup, bool bRecursive) const; + + const res::AnimationBlock *GetResourceBlock() const { + return mpResBlock; + } + const res::AnimationTagBlock *GetTagBlock() const { + return mpTagBlock; + } + const res::AnimationShareBlock *GetShareBlock() const { + return mpShareBlock; + } + +private: const res::BinaryFileHeader *mpFileHeader; // at 0x00 const res::AnimationBlock *mpResBlock; // at 0x04 const res::AnimationTagBlock *mpTagBlock; // at 0x08 @@ -51,29 +95,32 @@ struct AnimResource { }; namespace detail { -struct AnimPaneTree { - AnimPaneTree(Pane *pTargetPane, const AnimResource &animRes) : mAnimRes(animRes) { - // TODO - } - - bool IsEnabled() const { - // TODO - return false; +class AnimPaneTree { +public: + AnimPaneTree(Pane *pTargetPane, const AnimResource &animRes) : mAnimRes() { + Init(); + Set(pTargetPane, animRes); + } + bool IsEnabled() const; + static u16 FindAnimContent(const res::AnimationBlock *pAnimBlock, const char *animContName, u8 animContType); + void Init(); + void Set(Pane *pTargetPane, const AnimResource &animRes); + AnimTransform *Bind(Layout *pLayout, Pane *pTargetPane, ResourceAccessor *pResAccessor) const; + + // Inline Names Guess + u16 GetLinkNum() const { + return mLinkNum; } +private: AnimResource mAnimRes; // at 0x00 u16 mAnimPaneIdx; // at 0x10 u16 mLinkNum; // at 0x12 u16 mAnimMatIdx[9]; // at 0x14 u8 mAnimMatCnt; // at 0x26 }; -} // namespace detail -struct AnimationGroupRef { - char name[17]; // at 0x00 - u8 flag; // at 0x11 - u8 padding[2]; // at 0x12 -}; +} // namespace detail struct AnimTransform { inline AnimTransform() : mLink(), mpRes(NULL), mFrame(0.0f) {} @@ -112,7 +159,8 @@ struct AnimationLink { u16 mIdx; // at 0xC bool mbDisable; // at 0xE }; -struct AnimTransformBasic : AnimTransform { +class AnimTransformBasic : public AnimTransform { +public: AnimTransformBasic(); virtual ~AnimTransformBasic(); // at 0x08 virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor); // at 0x0C @@ -122,6 +170,7 @@ struct AnimTransformBasic : AnimTransform { virtual void Animate(u32 idx, Pane *pPane); // at 0x1C virtual void Animate(u32 idx, Material *pMaterial); // at 0x20 +private: void *mpFileResAry; // at 0x14 AnimationLink *mAnimLinkAry; // at 0x18 u16 mAnimLinkNum; // at 0x1C diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index c84d0065..f546e652 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -54,10 +54,10 @@ 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); -s32 GetSignatureInt(const char *sig) { +inline s32 GetSignatureInt(const char *sig) { return *((s32 *)sig); } -bool TestFileVersion(const res::BinaryFileHeader &fileHeader) { +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); diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 39714af4..ebe0f6c7 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -40,6 +40,13 @@ public: virtual void Animate(u32 option); // at 0x38 virtual void SetTagProcessor(ut::TagProcessorBase *pTagProcessor); // at 0x3C +private: + ut::LinkList mAnimTransList; // at 0x04 + Pane *mpRootPane; // at 0x10 + GroupContainer *mpGroupContainer; // at 0x14 + Size mLayoutSize; // at 0x18 + +public: // STATICS static void FreeMemory(void *p) { MEMFreeToAllocator(mspAllocator, p); @@ -109,12 +116,6 @@ public: } } -private: - ut::LinkList mAnimTransList; // at 0x04 - Pane *mpRootPane; // at 0x10 - GroupContainer *mpGroupContainer; // at 0x14 - Size mLayoutSize; // at 0x18 - static MEMAllocator *mspAllocator; }; } // namespace lyt diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 97e5890d..3cd60079 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -50,15 +50,6 @@ struct StepKey {}; } // namespace res -struct AnimationShareInfo { - const char *GetSrcPaneName() const { - return srcPaneName; - } - - char srcPaneName[17]; // at 0x00 - char targetGroupName[17]; // at 0x11 - u8 padding[2]; // at 0x12 -}; namespace detail { template inline bool TestBit(T bits, int index) { @@ -66,7 +57,7 @@ inline bool TestBit(T bits, int index) { return bits & mask; } template -inline bool SetBit(T *bits, int pos, bool val) { +inline void SetBit(T *bits, int pos, bool val) { T mask = T(1 << pos); *bits = T((*bits & ~mask)) | (val << pos); } diff --git a/include/nw4r/lyt/lyt_utils.h b/include/nw4r/lyt/lyt_utils.h new file mode 100644 index 00000000..3c5a72fd --- /dev/null +++ b/include/nw4r/lyt/lyt_utils.h @@ -0,0 +1,16 @@ +#ifndef NW4R_LYT_UTIL_H +#define NW4R_LYT_UTIL_H + +#include +#include + +namespace nw4r { +namespace lyt { + +void BindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive, bool bDisable); + +} // namespace lyt + +} // namespace nw4r + +#endif diff --git a/src/nw4r/lyt/lyt_layout.cpp b/src/nw4r/lyt/lyt_layout.cpp index 75f8a4ee..11573c27 100644 --- a/src/nw4r/lyt/lyt_layout.cpp +++ b/src/nw4r/lyt/lyt_layout.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -161,47 +162,148 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { // CreateAnimTransform__Q34nw4r3lyt6LayoutFv AnimTransform *Layout::CreateAnimTransform() { - return nullptr; + AnimTransform *pAnimTrans = NewObj(); + if (pAnimTrans) { + mAnimTransList.PushBack(pAnimTrans); + } + return pAnimTrans; } // CreateAnimTransform__Q34nw4r3lyt6LayoutFPCvPQ34nw4r3lyt16ResourceAccessor AnimTransform *Layout::CreateAnimTransform(const void *animResBuf, ResourceAccessor *pResAcsr) { - return nullptr; + return CreateAnimTransform(AnimResource(animResBuf), pResAcsr); } // CreateAnimTransform__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt12AnimResourcePQ34nw4r3lyt16ResourceAccessor AnimTransform *Layout::CreateAnimTransform(const AnimResource &animRes, ResourceAccessor *pResAcsr) { - return nullptr; + const res::AnimationBlock *pAnimBlock = animRes.GetResourceBlock(); + if (!pAnimBlock) { + return nullptr; + } + + AnimTransform *pAnimTrans = CreateAnimTransform(); + if (pAnimTrans) { + pAnimTrans->SetResource(pAnimBlock, pResAcsr); + } + + return pAnimTrans; } // BindAnimation__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransform -void Layout::BindAnimation(AnimTransform *pAnimTrans) {} +void Layout::BindAnimation(AnimTransform *pAnimTrans) { + if (!mpRootPane) { + return; + } + mpRootPane->BindAnimation(pAnimTrans, true, false); +} // UnbindAnimation__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransform -void Layout::UnbindAnimation(AnimTransform *pAnimTrans) {} +void Layout::UnbindAnimation(AnimTransform *pAnimTrans) { + if (!mpRootPane) { + return; + } + mpRootPane->UnbindAnimation(pAnimTrans, true); +} // UnbindAllAnimation__Q34nw4r3lyt6LayoutFv -void Layout::UnbindAllAnimation() {} +void Layout::UnbindAllAnimation() { + UnbindAnimation(nullptr); +} // BindAnimationAuto__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt12AnimResourcePQ34nw4r3lyt16ResourceAccessor bool Layout::BindAnimationAuto(const AnimResource &animRes, ResourceAccessor *pResAcsr) { - return IsIncludeAnimationGroupRef(nullptr, nullptr, 0, 0, nullptr); + // Ensure Root pane and Resource Block Exists + if (!mpRootPane) { + return false; + } + if (!animRes.GetResourceBlock()) { + return false; + } + + AnimTransform *pAnimTrans = CreateAnimTransform(); + u16 bindGroupNum = animRes.GetGroupNum(); + u16 animNum = 0; + if (bindGroupNum == 0) { + // No Groups to bind with, only bind to root pane + pAnimTrans->SetResource(animRes.GetResourceBlock(), pResAcsr, animRes.GetResourceBlock()->animContNum); + mpRootPane->BindAnimation(pAnimTrans, true, true); + } else { + // Bind to all Groups + const AnimationGroupRef *groupRefs = animRes.GetGroupArray(); + for (int grpIdx = 0; grpIdx < bindGroupNum; grpIdx++) { + Group *pGroup = mpGroupContainer->FindGroupByName(groupRefs[grpIdx].GetName()); + animNum += animRes.CalcAnimationNum(pGroup, animRes.IsDescendingBind()); + } + pAnimTrans->SetResource(animRes.GetResourceBlock(), pResAcsr, animNum); + for (int grpIdx = 0; grpIdx < bindGroupNum; grpIdx++) { + Group *pGroup = mpGroupContainer->FindGroupByName(groupRefs[grpIdx].GetName()); + lyt::BindAnimation(pGroup, pAnimTrans, animRes.IsDescendingBind(), true); + } + } + u16 animSharInfoNum = animRes.GetAnimationShareInfoNum(); + if (animSharInfoNum != 0) { + const AnimationShareInfo *animSharInfoAry = animRes.GetAnimationShareInfoArray(); + for (int i = 0; i < animSharInfoNum; i++) { + Pane *pSrcPane = mpRootPane->FindPaneByName(animSharInfoAry[i].GetSrcPaneName(), true); + detail::AnimPaneTree animPaneTree = detail::AnimPaneTree(pSrcPane, animRes); + if (animPaneTree.GetLinkNum()) { + Group *pGroup = mpGroupContainer->FindGroupByName(animSharInfoAry[i].GetTargetGroupName()); + ut::LinkList *paneList = pGroup->GetPaneList(); + for (ut::LinkList::Iterator it = paneList->GetBeginIter(); + it != paneList->GetEndIter(); it++) { + if (it->mTarget != pSrcPane) { + if (bindGroupNum != 0) { + bool bInclude = IsIncludeAnimationGroupRef(mpGroupContainer, animRes.GetGroupArray(), + bindGroupNum, animRes.IsDescendingBind(), it->mTarget); + if (!bInclude) { + continue; + } + } + animPaneTree.Bind(this, it->mTarget, pResAcsr); + } + } + } + } + } + return true; } // SetAnimationEnable__Q34nw4r3lyt6LayoutFPQ34nw4r3lyt13AnimTransformb -void Layout::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) {} +void Layout::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) { + if (!mpRootPane) { + return; + } + mpRootPane->SetAnimationEnable(pAnimTrans, bEnable, true); +} // CalculateMtx__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt8DrawInfo -void Layout::CalculateMtx(const DrawInfo &drawInfo) {} +void Layout::CalculateMtx(const DrawInfo &drawInfo) { + if (!mpRootPane) { + return; + } + mpRootPane->CalculateMtx(drawInfo); +} // Draw__Q34nw4r3lyt6LayoutFRCQ34nw4r3lyt8DrawInfo -void Layout::Draw(const DrawInfo &drawInfo) {} +void Layout::Draw(const DrawInfo &drawInfo) { + if (!mpRootPane) { + return; + } + mpRootPane->Draw(drawInfo); +} // Animate__Q34nw4r3lyt6LayoutFUl -void Layout::Animate(u32 option) {} +void Layout::Animate(u32 option) { + if (!mpRootPane) { + return; + } + mpRootPane->Animate(option); +} // GetLayoutRect__Q34nw4r3lyt6LayoutCFv -ut::Rect Layout::GetLayoutRect() const {} +ut::Rect Layout::GetLayoutRect() const { + return ut::Rect(-mLayoutSize.width / 2, mLayoutSize.height / 2, mLayoutSize.width / 2, -mLayoutSize.height / 2); +} // SetTagProcessor__Q34nw4r3lyt6LayoutFPQ34nw4r2ut19TagProcessorBase void Layout::SetTagProcessor(ut::TagProcessorBase *pTagProcessor) { From 489a69b6f5765eab70590727fa7097509f6917c5 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 26 May 2024 04:21:52 -0400 Subject: [PATCH 08/22] 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 From 484d0be7ea8600947bc09f9fec545276842628ff Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Mon, 27 May 2024 15:02:09 -0400 Subject: [PATCH 09/22] lyt_textBox matching --- config/SOUE01/config.yml | 1 + config/SOUE01/splits.txt | 8 + config/SOUE01/symbols.txt | 22 +- configure.py | 2 +- include/nw4r/lyt/lyt_common.h | 13 + include/nw4r/lyt/lyt_layout.h | 11 + include/nw4r/lyt/lyt_material.h | 8 + include/nw4r/lyt/lyt_resources.h | 7 + include/nw4r/lyt/lyt_textBox.h | 64 +++- include/nw4r/lyt/lyt_types.h | 2 +- include/nw4r/ut/ut_Color.h | 3 + src/nw4r/lyt/lyt_common.cpp | 4 +- src/nw4r/lyt/lyt_group.cpp | 2 +- src/nw4r/lyt/lyt_pane.cpp | 4 +- src/nw4r/lyt/lyt_picture.cpp | 4 +- src/nw4r/lyt/lyt_textBox.cpp | 509 +++++++++++++++++++++++++++++++ 16 files changed, 641 insertions(+), 23 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index bbe8cde0..74626e27 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -19,6 +19,7 @@ force_active: [ "RegistFont__Q34nw4r3lyt24MultiArcResourceAccessorFPQ34nw4r3lyt11FontRefLink", "GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc", "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", + "SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font", ] # modules: diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f9938f3d..5c8a14e5 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -345,6 +345,14 @@ nw4r/lyt/lyt_picture.cpp: .sbss start:0x80576700 end:0x80576704 .sdata2 start:0x8057F248 end:0x8057F250 +nw4r/lyt/lyt_textBox.cpp: + .text start:0x80489800 end:0x8048B16C + .ctors start:0x804DB97C end:0x804DB980 + .data start:0x8056E570 end:0x8056E5F4 + .sdata start:0x80574EB8 end:0x80574EBC + .sbss start:0x80576708 end:0x8057670C + .sdata2 start:0x8057F250 end:0x8057F268 + 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 164e97b6..b97b3b4a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -3860,7 +3860,7 @@ fn_800B0F40 = .text:0x800B0F40; // type:function size:0x240 fn_800B1180 = .text:0x800B1180; // type:function size:0x3F0 fn_800B1570 = .text:0x800B1570; // type:function size:0x14 fn_800B1590 = .text:0x800B1590; // type:function size:0x14 -fn_800B15B0 = .text:0x800B15B0; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt7TextBoxCFv = .text:0x800B15B0; // type:function size:0x8 scope:weak fn_800B15C0 = .text:0x800B15C0; // type:function size:0x68 fn_800B1630 = .text:0x800B1630; // type:function size:0x3C fn_800B1670 = .text:0x800B1670; // type:function size:0x134 @@ -25941,10 +25941,10 @@ SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font = .text:0x8048A9E0; // type:funct LoadMtx__Q34nw4r3lyt7TextBoxFRCQ34nw4r3lyt8DrawInfo = .text:0x8048AB10; // type:function size:0x84 GetTextDrawRect__Q34nw4r3lyt7TextBoxCFPQ34nw4r2ut17TextWriterBase = .text:0x8048ABA0; // type:function size:0x2A4 CalcStringRectImpl__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPQ34nw4r2ut4RectPQ34nw4r2ut17TextWriterBasePCwif_v = .text:0x8048AE50; // type:function size:0x1D4 -FUN_8048b030 = .text:0x8048B030; // type:function size:0x4C -FUN_8048b080 = .text:0x8048B080; // type:function size:0x44 -FUN_8048b0d0 = .text:0x8048B0D0; // type:function size:0x84 -__sinit_lyt_textBox_cpp = .text:0x8048B160; // type:function size:0xC +GetTextMagH__Q34nw4r3lyt7TextBoxCFv = .text:0x8048B030; // type:function size:0x4C +GetTextMagV__Q34nw4r3lyt7TextBoxCFv = .text:0x8048B080; // type:function size:0x44 +GetTextAlignMag__Q34nw4r3lyt7TextBoxCFv = .text:0x8048B0D0; // type:function size:0x84 +__sinit_\lyt_textBox_cpp = .text:0x8048B160; // type:function size:0xC scope:local __ct__Q34nw4r3lyt6WindowFPCQ44nw4r3lyt3res6WindowRCQ34nw4r3lyt11ResBlockSet = .text:0x8048B170; // type:function size:0x284 __dt__Q34nw4r3lyt6WindowFv = .text:0x8048B400; // type:function size:0x144 FindMaterialByName__Q34nw4r3lyt6WindowFPCcb = .text:0x8048B550; // type:function size:0xFC @@ -37076,7 +37076,7 @@ __vt__Q34nw4r3lyt4Pane = .data:0x8056E430; // type:object size:0x74 __vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC __vt__Q34nw4r3lyt6Layout = .data:0x8056E4B8; // type:object size:0x40 __vt__Q34nw4r3lyt7Picture = .data:0x8056E4F8; // type:object size:0x78 -lbl_8056E570 = .data:0x8056E570; // type:object size:0x88 +__vt__Q34nw4r3lyt7TextBox = .data:0x8056E570; // type:object size:0x84 lbl_8056E5F8 = .data:0x8056E5F8; // type:object size:0x3C lbl_8056E634 = .data:0x8056E634; // type:object size:0x8C lbl_8056E6C0 = .data:0x8056E6C0; // type:object size:0x78 @@ -39585,7 +39585,7 @@ lbl_80574E98 = .sdata:0x80574E98; // type:object size:0x8 lbl_80574EA0 = .sdata:0x80574EA0; // type:object size:0x8 data:4byte lbl_80574EA8 = .sdata:0x80574EA8; // type:object size:0x8 data:4byte NW4R_LYT_Version___22@unnamed@lyt_init_cpp@ = .sdata:0x80574EB0; // type:object size:0x4 scope:local data:4byte -lbl_80574EB8 = .sdata:0x80574EB8; // type:object size:0x8 +lbl_80574EB8 = .sdata:0x80574EB8; // type:object size:0x4 data:string lbl_80574EC0 = .sdata:0x80574EC0; // type:object size:0x2 data:string lbl_80574EC4 = .sdata:0x80574EC4; // type:object size:0x3 data:string lbl_80574EC8 = .sdata:0x80574EC8; // type:object size:0x8 @@ -47567,10 +47567,10 @@ 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: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 -lbl_8057F264 = .sdata2:0x8057F264; // type:object size:0x4 data:float +lbl_8057F250 = .sdata2:0x8057F250; // type:object size:0x4 scope:local data:float +lbl_8057F258 = .sdata2:0x8057F258; // type:object size:0x8 scope:local data:double +lbl_8057F260 = .sdata2:0x8057F260; // type:object size:0x4 scope:local data:float +lbl_8057F264 = .sdata2:0x8057F264; // type:object size:0x4 scope:local data:float lbl_8057F268 = .sdata2:0x8057F268; // type:object size:0x4 data:float lbl_8057F270 = .sdata2:0x8057F270; // type:object size:0x8 data:double lbl_8057F278 = .sdata2:0x8057F278; // type:object size:0x8 data:double diff --git a/configure.py b/configure.py index 63abe94c..ab74faa9 100644 --- a/configure.py +++ b/configure.py @@ -203,7 +203,6 @@ cflags_nw4r = [ *cflags_base, "-ipa file", "-fp_contract off", - ] # REL flags @@ -357,6 +356,7 @@ config.libs = [ 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_textBox.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_common.h b/include/nw4r/lyt/lyt_common.h index 3023d73b..81b40ae5 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -28,6 +28,19 @@ inline void SetVtxColElement(ut::Color *cols, u32 idx, u8 value) { ((u8 *)cols)[(idx & ~3) + (idx & 3)] = value; } +inline u8 GetHorizontalPosition(u8 var) { + return var % 3; +} +inline u8 GetVerticalPosition(u8 var) { + return var / 3; +} +inline void SetHorizontalPosition(u8 *pVar, u8 newVal) { + *pVar = newVal + GetVerticalPosition(*pVar) * 3; +} +inline void SetVerticalPosition(u8 *pVar, u8 newVal) { + *pVar = newVal * 3 + GetHorizontalPosition(*pVar); +} + typedef math::VEC2 TexCoordData[TEXCOORD_VTX_COUNT]; class TexCoordAry { diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 3eebfff9..b7d801c7 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace nw4r { @@ -70,6 +71,9 @@ public: template static T *NewArray(size_t n) { T *array = (T *)AllocMemory(n * sizeof(T)); + if (!array) { + return nullptr; + } for (size_t i = 0; i < n; i++) { new (&array[i]) T(); @@ -86,6 +90,13 @@ public: } } + template + static void DeletePrimArray(T *objAry) { + if (objAry) { + FreeMemory(objAry); + } + } + template static T *NewObj() { T *pMem = (T *)AllocMemory(sizeof(T)); diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index b0566173..970fe84f 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -81,6 +81,14 @@ public: TexMap *GetTexMapAry(); TexCoordGen *GetTexCoordGenAry(); + GXColorS10 GetTevColor(u32 idx) const { + return mTevCols[idx]; + } + + ut::Color GetTevKColor(u32 idx) const { + return mTevKCols[idx]; + } + void SetTexture(u32 texMapIdx, const TexMap &texMap) { GetTexMapAry()[texMapIdx] = texMap; } diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index d4cb6a76..03c6ea73 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -110,6 +110,12 @@ struct FontList { u8 padding[2]; // at 0x0A }; +struct Font { + u32 nameStrOffset; // at 0x0 + u8 type; // at 0x4 + u8 padding[3]; // at 0x5 +}; + struct TextureList { DataBlockHeader blockHeader; // at 0x00 u16 texNum; // at 0x08 @@ -117,6 +123,7 @@ struct TextureList { }; struct TextBox : public Pane { u16 textBufBytes; // at 0x4C + u16 textStrBytes; // at 0x4E u16 materialIdx; // at 0x50 u16 fontIdx; // at 0x52 u8 textPosition; // at 0x54 diff --git a/include/nw4r/lyt/lyt_textBox.h b/include/nw4r/lyt/lyt_textBox.h index f2fab1ba..6a56a0fc 100644 --- a/include/nw4r/lyt/lyt_textBox.h +++ b/include/nw4r/lyt/lyt_textBox.h @@ -8,17 +8,75 @@ namespace nw4r { namespace lyt { class TextBox : public Pane { public: + TextBox(u16 allocStrLen); + TextBox(const wchar_t *str, const ut::Font *pFont); + TextBox(u16, const wchar_t *str, u16, const ut::Font *pFont); + TextBox(const res::TextBox *pBlock, const ResBlockSet &resBlockSet); + + void Init(u16 allocStrLen); + + ut::Rect GetTextDrawRect() const; + ut::Rect GetTextDrawRect(const DrawInfo &drawInfo) const; + u16 GetStringBufferLength() const; + u16 SetStringImpl(const wchar_t *str, u16 dstIdx, u32 strLen); + const ut::Font *GetFont() const; + void SetFont(const ut::Font *pFont); + ut::Rect GetTextDrawRect(ut::TextWriterBase *pWriter) const; + f32 GetTextMagH() const; + f32 GetTextMagV() const; + f32 GetTextAlignMag() const; + UNKTYPE MakeDrawFlag() const; + + ut::Color GetTextColor(u32 type) const { + return mTextColors[type / 2]; + } + void SetTextColor(u32 type, ut::Color value) { + mTextColors[type] = value; + } + u8 GetTextPositionH() const { + return detail::GetHorizontalPosition(mTextPosition); + } + void SetTextPositionH(u8 val) { + detail::SetHorizontalPosition(&mTextPosition, val); + } + u8 GetTextPositionV() const { + return detail::GetVerticalPosition(mTextPosition); + } + void SetTextPositionV(u8 val) { + detail::SetVerticalPosition(&mTextPosition, val); + } + + const Size &GetFontSize() const { + return mFontSize; + } + + void SetFontSize(const Size &fontSize) { + mFontSize = fontSize; + } + ut::TagProcessorBase *GetTagProcessor() const { + return mpTagProcessor; + } void SetTagProcessor(ut::TagProcessorBase *pTagProcessor) { mpTagProcessor = pTagProcessor; } - TextBox(const res::TextBox *, const ResBlockSet &resBlockSet); virtual ~TextBox(); NW4R_UT_RTTI_DECL(TextBox); + 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 LoadMtx(const DrawInfo &drawInfo); // at 0x70 + virtual void AllocStringBuffer(u16 minLen); // at 0x + virtual void FreeStringBuffer(); // at 0x + virtual u16 SetString(const wchar_t *str, u16 dstIdx); // at 0x + virtual u16 SetString(const wchar_t *str, u16 dstIdx, u16 strLen); // at 0x +protected: wchar_t *mTextBuf; // at 0xD8 // ptr to is Guess ut::Color mTextColors[2]; // at 0xDC - ut::Font *mpFont; // at 0xE4 + const ut::Font *mpFont; // at 0xE4 Size mFontSize; // at 0xE8 f32 mLineSpace; // at 0xF0 f32 mCharSpace; // at 0xF4 @@ -28,7 +86,7 @@ public: u8 mTextPosition; // at 0x100 struct { // u8 bAllocFont : 1; // - u8 textAligntment : 1; // + u8 textAlignment : 2; // } mBits; // at 0x101 }; diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 1acade59..31f75a7f 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -20,7 +20,7 @@ inline void SetBit(T *bits, int pos, bool val) { } template -T *ConvertOffsetToPtr(const void *baseAddress, unsigned int offset) { +T *ConvertOffsToPtr(const void *baseAddress, unsigned int offset) { return (T *)((u32)baseAddress + offset); } } // namespace detail diff --git a/include/nw4r/ut/ut_Color.h b/include/nw4r/ut/ut_Color.h index b9112d10..b9616f14 100644 --- a/include/nw4r/ut/ut_Color.h +++ b/include/nw4r/ut/ut_Color.h @@ -17,6 +17,9 @@ public: Color(int red, int green, int blue, int alpha) { Set(red, green, blue, alpha); } + Color(const GXColor &clr) { + *this = *(u32 *)&clr; + } ~Color() {} void Set(int red, int green, int blue, int alpha) { diff --git a/src/nw4r/lyt/lyt_common.cpp b/src/nw4r/lyt/lyt_common.cpp index 922cf77b..d5fc6b8b 100644 --- a/src/nw4r/lyt/lyt_common.cpp +++ b/src/nw4r/lyt/lyt_common.cpp @@ -42,8 +42,8 @@ void TexCoordAry::Free() { void TexCoordAry::Reserve(u8 num) { if (mCap < num) { Free(); - const TexCoordData *pData = (TexCoordData *)Layout::NewArray(num * TEXCOORD_VTX_COUNT); - this->mpData = pData ? const_cast(pData) : nullptr; + TexCoordData *pData = (TexCoordData *)Layout::NewArray(num * TEXCOORD_VTX_COUNT); + this->mpData = pData; if (mpData != NULL) { mCap = num; } diff --git a/src/nw4r/lyt/lyt_group.cpp b/src/nw4r/lyt/lyt_group.cpp index 82433fdf..75876728 100644 --- a/src/nw4r/lyt/lyt_group.cpp +++ b/src/nw4r/lyt/lyt_group.cpp @@ -10,7 +10,7 @@ Group::Group(const res::Group *pResGroup, Pane *pRootPane) : mLink(), mPaneListL Init(); strncpy(this->mName, pResGroup->mName, NW4R_RES_NAME_SIZE); this->mName[NW4R_RES_NAME_SIZE] = '\0'; - const char *paneNameBase = detail::ConvertOffsetToPtr(pResGroup, sizeof(res::Group)); + const char *paneNameBase = detail::ConvertOffsToPtr(pResGroup, sizeof(res::Group)); for (int i = 0; i < pResGroup->paneNum; i++) { Pane *pFindPane = pRootPane->FindPaneByName(paneNameBase + i * NW4R_RES_NAME_SIZE, true); diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index e0ef53f8..58ad61a2 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -514,7 +514,7 @@ u16 Pane::GetExtUserDataNum() const { } res::ExtUserData *Pane::GetExtUserData() const { if (this->mpExtUserDataList) { - return detail::ConvertOffsetToPtr(this->mpExtUserDataList, sizeof(res::ExtUserDataList)); + return detail::ConvertOffsToPtr(this->mpExtUserDataList, sizeof(res::ExtUserDataList)); } return nullptr; } @@ -530,7 +530,7 @@ res::ExtUserData *Pane::FindExtUserDataByName(const char *name) { u32 offset = pUserData->nameOffs; const char *str = 0; if (offset != 0) { - str = detail::ConvertOffsetToPtr(pUserData, offset); + str = detail::ConvertOffsToPtr(pUserData, offset); } else { str = nullptr; } diff --git a/src/nw4r/lyt/lyt_picture.cpp b/src/nw4r/lyt/lyt_picture.cpp index 83e567d3..e6a7c581 100644 --- a/src/nw4r/lyt/lyt_picture.cpp +++ b/src/nw4r/lyt/lyt_picture.cpp @@ -30,9 +30,9 @@ Picture::Picture(const res::Picture *pResPic, const ResBlockSet &resBlockSet) if (texCoordNum != 0 && !mTexCoordAry.IsEmpty()) { mTexCoordAry.Copy((void *)&pResPic[1], texCoordNum); } - const u32 *matOffsTbl = detail::ConvertOffsetToPtr(resBlockSet.pMaterialList, sizeof(res::MaterialList)); + const u32 *matOffsTbl = detail::ConvertOffsToPtr(resBlockSet.pMaterialList, sizeof(res::MaterialList)); const res::Material *pResMaterial = - detail::ConvertOffsetToPtr(resBlockSet.pMaterialList, matOffsTbl[pResPic->materialIdx]); + detail::ConvertOffsToPtr(resBlockSet.pMaterialList, matOffsTbl[pResPic->materialIdx]); mpMaterial = Layout::NewObj(pResMaterial, resBlockSet); } diff --git a/src/nw4r/lyt/lyt_textBox.cpp b/src/nw4r/lyt/lyt_textBox.cpp index e69de29b..6ce2e7fc 100644 --- a/src/nw4r/lyt/lyt_textBox.cpp +++ b/src/nw4r/lyt/lyt_textBox.cpp @@ -0,0 +1,509 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace nw4r { +namespace lyt { + +NW4R_UT_RTTI_DEF_DERIVED(TextBox, Pane); + +namespace { +// ReverseYAxis__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPQ34nw4r4math5MTX34 +void ReverseYAxis(math::MTX34 *pMtx) { + // Based on impl in LoadMtx + pMtx->_01 = -pMtx->_01; + pMtx->_11 = -pMtx->_11; + pMtx->_21 = -pMtx->_21; +} + +// ClampColor__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@Fs +u8 ClampColor(s16 colVal) { + // The CLAMP macro was reversed for this -_- + return colVal < 0 ? 0 : (colVal > 0xFF ? 0xFF : colVal); +} + +// GetColor__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FRC11_GXColorS10 +ut::Color GetColor(const GXColorS10 &src) { + GXColor dst; + dst.r = ClampColor(src.r); + dst.g = ClampColor(src.g); + dst.b = ClampColor(src.b); + dst.a = ClampColor(src.a); + return dst; +} + +template +void CalcStringRect(ut::Rect *pRect, ut::TextWriterBase *pTextWriter, const T *str, int length, f32 maxWidth) { + ut::TextWriterBase myCopy = *pTextWriter; + CalcStringRectImpl(pRect, &myCopy, str, length, maxWidth); +} + +template +int CalcLineStrNum(f32 *pWidth, ut::TextWriterBase *pTextWriter, const T *str, int length, f32 maxWidth, + bool *pbOver) { + ut::Rect rect; + ut::TextWriterBase myCopy = *pTextWriter; + myCopy.SetCursor(0.0f, 0.0f); + int ret = CalcLineRectImpl(&rect, &myCopy, str, length, maxWidth, pbOver); + + *pWidth = rect.GetWidth(); + return ret; +} + +template +int CalcLineRectImpl(ut::Rect *pRect, ut::TextWriterBase *pTextWriter, const T *str, int length, f32 maxWidth, + bool *pbOver) { + ut::PrintContext context = {pTextWriter, str, 0.0f, 0.0f, 0}; + f32 x = 0.0f; + + const ut::Font *font = pTextWriter->GetFont(); + bool bCharSpace = false; + ut::CharStrmReader reader = font->GetCharStrmReader(); + + const T *prStrPos = (const T *)reader.GetCurrentPos(); + + pRect->left = 0.0f; + pRect->right = 0.0f; + pRect->top = ut::Min(0.0f, pTextWriter->GetLineHeight()); + pRect->bottom = ut::Max(0.0f, pTextWriter->GetLineHeight()); + + *pbOver = false; + + reader.Set(str); + ut::Rect prMaxRect = *pRect; + u16 code = reader.Next(); + while (((const T *)reader.GetCurrentPos() - str) <= length) { + if (code < ' ') { + ut::Operation operation; + ut::Rect rect(x, 0.0f, 0.0f, 0.0f); + + context.str = (const T *)reader.GetCurrentPos(); + context.flags = !bCharSpace; + + pTextWriter->SetCursorX(x); + operation = pTextWriter->GetTagProcessor()->CalcRect(&rect, code, &context); + reader.Set(context.str); + + pRect->left = ut::Min(pRect->left, rect.left); + pRect->top = ut::Min(pRect->top, rect.top); + pRect->right = ut::Max(pRect->right, rect.right); + pRect->bottom = ut::Max(pRect->bottom, rect.bottom); + + x = pTextWriter->GetCursorX(); + + if (pRect->GetWidth() > maxWidth) { + *pbOver = true; + break; + } + if (operation == ut::OPERATION_END_DRAW) { + return length; + } else if (operation == ut::OPERATION_NO_CHAR_SPACE) { + bCharSpace = false; + } else if (operation == ut::OPERATION_CHAR_SPACE) { + bCharSpace = true; + } else if (operation == ut::OPERATION_NEXT_LINE) { + break; + } + + } else { + if (bCharSpace) { + x += pTextWriter->GetCharSpace(); + } + bCharSpace = true; + if (pTextWriter->IsWidthFixed()) { + x += pTextWriter->GetFixedWidth(); + } else { + x += pTextWriter->GetFont()->GetCharWidth(code) * pTextWriter->GetScaleH(); + } + pRect->left = ut::Min(pRect->left, x); + pRect->right = ut::Max(pRect->right, x); + + if (pRect->GetWidth() > maxWidth) { + *pbOver = true; + break; + } + } + prStrPos = (const T *)reader.GetCurrentPos(); + code = reader.Next(); + prMaxRect = *pRect; + } + + if (*pbOver) { + if (prStrPos) { + *pRect = prMaxRect; + return (prStrPos - str); + } + } + return ((const T *)reader.GetCurrentPos() - str); +} +template +void CalcStringRectImpl(ut::Rect *pRect, ut::TextWriterBase *pTextWriter, const T *str, int length, f32 maxWidth) { + pRect->left = 0.0f; + pRect->right = 0.0f; + pRect->top = 0.0f; + pRect->bottom = 0.0f; + pTextWriter->SetCursor(0.0f, 0.0f); + int remain = length; + const T *pos = str; + do { + ut::Rect rect; + bool bOver; + int read = CalcLineRectImpl(&rect, pTextWriter, pos, remain, maxWidth, &bOver); + pos += read; + remain -= read; + pRect->left = ut::Min(pRect->left, rect.left); + pRect->top = ut::Min(pRect->top, rect.top); + pRect->right = ut::Max(pRect->right, rect.right); + pRect->bottom = ut::Max(pRect->bottom, rect.bottom); + if (bOver) { + CalcLineRectImpl(&rect, pTextWriter, L"\n", 1, maxWidth, &bOver); + pRect->left = ut::Min(pRect->left, rect.left); + pRect->top = ut::Min(pRect->top, rect.top); + pRect->right = ut::Max(pRect->right, rect.right); + pRect->bottom = ut::Max(pRect->bottom, rect.bottom); + } + } while (remain > 0); +} +} // namespace + +// __ct__Q34nw4r3lyt7TextBoxFUs +TextBox::TextBox(u16 allocStrLen) { + // TODO: Not in SS +} + +// __ct__Q34nw4r3lyt7TextBoxFUsPCwPCQ34nw4r2ut4Font +TextBox::TextBox(const wchar_t *str, const ut::Font *pFont) { + // TODO: Not in SS +} + +// __ct__Q34nw4r3lyt7TextBoxFUsPCwUsPCQ34nw4r2ut4Font +TextBox::TextBox(u16, const wchar_t *str, u16, const ut::Font *pFont) { + // TODO: Not in SS +} + +// __ct__Q34nw4r3lyt7TextBoxFPCQ44nw4r3lyt3res7TextBoxRCQ34nw4r3lyt11ResBlockSet +TextBox::TextBox(const res::TextBox *pBlock, const ResBlockSet &resBlockSet) + : Pane(pBlock), mTextColors(), mFontSize() { + u16 allocStrBufferLen = pBlock->textBufBytes / 2; + if (allocStrBufferLen > 0) { + allocStrBufferLen -= 1; + } + Init(allocStrBufferLen); + if (pBlock->textStrBytes >= 2 && mTextBuf) { + u16 resStringLen = pBlock->textStrBytes / 2 - 1; + const wchar_t *pBlockText = detail::ConvertOffsToPtr(pBlock, pBlock->textStrOffset); + SetString(pBlockText, 0, resStringLen); + } + mTextColors[0] = pBlock->textCols[0]; + mTextColors[1] = pBlock->textCols[1]; + mFontSize = pBlock->fontSize; + mTextPosition = pBlock->textPosition; + mBits.textAlignment = pBlock->textAlignment; + mCharSpace = pBlock->charSpace; + mLineSpace = pBlock->lineSpace; + + int i = pBlock->fontIdx; + const res::Font *fonts = detail::ConvertOffsToPtr(resBlockSet.pFontList, sizeof(res::FontList)); + const char *fontName = detail::ConvertOffsToPtr(fonts, fonts[i].nameStrOffset); + ut::Font *pFont = resBlockSet.pResAccessor->GetFont(fontName); + if (pFont) { + mpFont = pFont; + } else { + void *fontRes = resBlockSet.pResAccessor->GetResource('font', fontName, nullptr); + if (fontRes) { + ut::ResFont *pResFont = Layout::NewObj(); + if (pResFont) { + bool bSucces = pResFont->SetResource(fontRes); + mpFont = pResFont; + mBits.bAllocFont = true; + } + } + } + const u32 *matOffsTbl = detail::ConvertOffsToPtr(resBlockSet.pMaterialList, sizeof(res::MaterialList)); + const res::Material *pResMaterial = + detail::ConvertOffsToPtr(resBlockSet.pMaterialList, matOffsTbl[pBlock->materialIdx]); + mpMaterial = Layout::NewObj(pResMaterial, resBlockSet); +} + +// Init__Q34nw4r3lyt7TextBoxFUs +void TextBox::Init(u16 allocStrLen) { + mTextBuf = nullptr; + mTextBufBytes = 0; + mTextLen = 0; + mpFont = nullptr; + mFontSize = Size(0.0f, 0.0f); + mLineSpace = 0.0f; + mCharSpace = 0.0f; + mpTagProcessor = nullptr; + SetTextPositionH(1); + SetTextPositionV(1); + memset(&mBits, 0, sizeof(mBits)); + if (allocStrLen != 0) { + AllocStringBuffer(allocStrLen); + } +} + +// __dt__Q34nw4r3lyt7TextBoxFv +TextBox::~TextBox() { + SetFont(nullptr); + if (mpMaterial && !mpMaterial->IsUserAllocated()) { + Layout::DeleteObj(mpMaterial); + mpMaterial = nullptr; + } + FreeStringBuffer(); +} + +// GetVtxColor__Q34nw4r3lyt7TextBoxCFUl +ut::Color TextBox::GetVtxColor(u32 idx) const { + return GetTextColor(idx); +} + +// SetVtxColor__Q34nw4r3lyt7TextBoxFUlQ34nw4r2ut5Color +void TextBox::SetVtxColor(u32 idx, ut::Color value) { + SetTextColor(idx / 2, value); +} + +// GetVtxColorElement__Q34nw4r3lyt7TextBoxCFUl +u8 TextBox::GetVtxColorElement(u32 idx) const { + return ((u8 *)mTextColors)[((idx / 2) & ~3) + (idx & 3)]; +} + +// SetVtxColorElement__Q34nw4r3lyt7TextBoxFUlUc +void TextBox::SetVtxColorElement(u32 idx, u8 value) { + ((u8 *)mTextColors)[((idx / 2) & ~3) + (idx & 3)] = value; +} + +// 1] IDK which one is accurate, both symbols exist +// GetTextDrawRect__Q34nw4r3lyt7TextBoxCFv +ut::Rect TextBox::GetTextDrawRect() const { + return GetTextDrawRect(&ut::TextWriterBase()); +} + +// 2] IDK which one is accurate, both symbols exist +// GetTextDrawRect__Q34nw4r3lyt7TextBoxCFRCQ34nw4r3lyt8DrawInfo +ut::Rect TextBox::GetTextDrawRect(const DrawInfo &drawInfo) const { + // Not in SS + return GetTextDrawRect(); +} + +// DrawSelf__Q34nw4r3lyt7TextBoxFRCQ34nw4r3lyt8DrawInfo +void TextBox::DrawSelf(const DrawInfo &drawInfo) { + if (!mTextBuf || !mpFont || !mpMaterial) { + return; + } + LoadMtx(drawInfo); + ut::TextWriterBase writer; + ut::Rect textRect = GetTextDrawRect(&writer); + ut::Color topCol = detail::MultipleAlpha(mTextColors[0], mGlbAlpha); + ut::Color btmCol = detail::MultipleAlpha(mTextColors[1], mGlbAlpha); + writer.SetGradationMode(topCol != btmCol ? ut::CharWriter::GRADMODE_V : ut::CharWriter::GRADMODE_NONE); + writer.SetTextColor(topCol, btmCol); + + ut::Color minCol = GetColor(mpMaterial->GetTevColor(0)); + ut::Color maxCol = GetColor(mpMaterial->GetTevColor(1)); + writer.SetColorMapping(minCol, maxCol); + writer.SetupGX(); + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); + f32 hMag = GetTextAlignMag(); + + const wchar_t *strPos = mTextBuf; + writer.SetCursor(textRect.left, -textRect.top); + f32 texWidth = textRect.GetWidth(); + int remain = mTextLen; + + while (remain > 0) { + bool bOver; + f32 lineWidth; + int lineStrNum = CalcLineStrNum(&lineWidth, &writer, strPos, remain, mSize.width, &bOver); + f32 textPosX = textRect.left + hMag * (texWidth - lineWidth); + writer.SetCursorX(textPosX); + writer.PrintMutable(strPos, lineStrNum); + if (bOver) { + writer.PrintMutable(L"\n", 1); + } + strPos += lineStrNum; + remain -= lineStrNum; + } +} + +// CalcLineStrNum__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPfPQ34nw4r2ut17TextWriterBasePCwifPb_i +// CalcLineRectImpl__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPQ34nw4r2ut4RectPQ34nw4r2ut17TextWriterBasePCwifPb_i + +// GetStringBufferLength__Q34nw4r3lyt7TextBoxCFv +u16 TextBox::GetStringBufferLength() const { + if (mTextBufBytes == 0) { + return 0; + } + return mTextBufBytes / sizeof(wchar_t) - 1; +} + +// AllocStringBuffer__Q34nw4r3lyt7TextBoxFUs +void TextBox::AllocStringBuffer(u16 minLen) { + if (minLen == 0) { + return; + } + + u32 allocLen = minLen; + u32 texBufBytes = (minLen + 1) * sizeof(wchar_t); + + if (texBufBytes > mTextBufBytes) { + FreeStringBuffer(); + mTextBuf = Layout::NewArray(allocLen + 1); + if (mTextBuf) { + mTextBufBytes = texBufBytes; + } + } +} + +// FreeStringBuffer__Q34nw4r3lyt7TextBoxFv +void TextBox::FreeStringBuffer() { + if (mTextBuf) { + Layout::DeletePrimArray(mTextBuf); + mTextBuf = nullptr; + mTextBufBytes = 0; + } +} + +// SetString__Q34nw4r3lyt7TextBoxFPCwUs +u16 TextBox::SetString(const wchar_t *str, u16 dstIdx) { + return SetStringImpl(str, dstIdx, wcslen(str)); +} + +// SetString__Q34nw4r3lyt7TextBoxFPCwUsUs +u16 TextBox::SetString(const wchar_t *str, u16 dstIdx, u16 strLen) { + return SetStringImpl(str, dstIdx, strLen); +} + +// SetStringImpl__Q34nw4r3lyt7TextBoxFPCwUsUl +u16 TextBox::SetStringImpl(const wchar_t *str, u16 dstIdx, u32 strLen) { + if (!mTextBuf) { + return 0; + } + u16 bufLen = GetStringBufferLength(); + if (dstIdx >= bufLen) { + return 0; + } + u32 cpLen = ut::Min(strLen, bufLen - dstIdx); + memcpy(&mTextBuf[dstIdx], str, cpLen * sizeof(wchar_t)); + mTextLen = dstIdx + cpLen; + mTextBuf[mTextLen] = L'\0'; + return cpLen; +} + +// GetFont__Q34nw4r3lyt7TextBoxCFv +const ut::Font *TextBox::GetFont() const { + return mpFont; +} + +// SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font +void TextBox::SetFont(const ut::Font *pFont) { + if (mBits.bAllocFont) { + Layout::DeleteObj(const_cast(mpFont)); + mBits.bAllocFont = false; + } + mpFont = pFont; + if (mpFont) { + SetFontSize(Size(mpFont->GetWidth(), mpFont->GetHeight())); + } else { + SetFontSize(Size(0.0f, 0.0f)); + } +} + +// LoadMtx__Q34nw4r3lyt7TextBoxFRCQ34nw4r3lyt8DrawInfo +void TextBox::LoadMtx(const DrawInfo &drawInfo) { + math::MTX34 mtx; + if (drawInfo.IsMultipleViewMtxOnDraw()) { + PSMTXConcat(drawInfo.GetViewMtx(), mGlbMtx, mtx); + } else { + PSMTXCopy(mGlbMtx, mtx); + } + + ReverseYAxis(&mtx); + + GXLoadPosMtxImm(mtx, GX_PNMTX0); + GXSetCurrentMtx(GX_PNMTX0); +} + +// GetTextDrawRect__Q34nw4r3lyt7TextBoxCFPQ34nw4r2ut17TextWriterBase +// BBA map failed me here xD, probably different impl +ut::Rect TextBox::GetTextDrawRect(ut::TextWriterBase *pWriter) const { + ut::Rect textRect; + pWriter->SetCursor(0.0f, 0.0f); + pWriter->SetFont(*mpFont); + pWriter->SetFontSize(mFontSize.width, mFontSize.height); + pWriter->SetLineSpace(mLineSpace); + pWriter->SetCharSpace(mCharSpace); + if (mpTagProcessor) { + pWriter->SetTagProcessor(mpTagProcessor); + } + CalcStringRect(&textRect, pWriter, mTextBuf, mTextLen, mSize.width); + + Size textSize(textRect.GetWidth(), textRect.GetHeight()); + math::VEC2 ltPos = GetVtxPos(); + + // Adjust for Alignment (left, center, right) + ltPos.x += (mSize.width - textSize.width) * GetTextMagH(); + ltPos.y -= (mSize.height - textSize.height) * GetTextMagV(); + + // Apply the new pos + textRect.left = ltPos.x; + textRect.top = ltPos.y; + textRect.right = ltPos.x + textSize.width; + textRect.bottom = ltPos.y - textSize.height; + + return textRect; +} + +// CalcStringRect__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPQ34nw4r2ut4RectPQ34nw4r2ut17TextWriterBasePCwif_v +// CalcStringRectImpl__Q34nw4r3lyt25@unnamed@lyt_textBox_cpp@FPQ34nw4r2ut4RectPQ34nw4r2ut17TextWriterBasePCwif_v + +// GetTextMagH__Q34nw4r3lyt7TextBoxCFv +f32 TextBox::GetTextMagH() const { + switch (GetTextPositionH()) { + default: + return 0.0f; + case 1: + return 0.5f; + case 2: + return 1.0f; + } +} + +// GetTextMagV__Q34nw4r3lyt7TextBoxCFv +f32 TextBox::GetTextMagV() const { + switch (GetTextPositionV()) { + default: + return 0.0f; + case 1: + return 0.5f; + case 2: + return 1.0f; + } +} + +// GetTextAlignMag__Q34nw4r3lyt7TextBoxCFv +f32 TextBox::GetTextAlignMag() const { + switch (mBits.textAlignment) { + default: + return GetTextMagH(); + case 1: + return 0.0f; + case 2: + return 0.5f; + case 3: + return 1.0f; + } +} + +// MakeDrawFlag__Q34nw4r3lyt7TextBoxCFv +UNKTYPE TextBox::MakeDrawFlag() const { + // TODO: Not In SS + // Calls GetTextPositionH() +} + +} // namespace lyt +} // namespace nw4r From 5829b09fbbf9aab0332421180ebd047045c2a43f Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Mon, 27 May 2024 17:22:36 -0400 Subject: [PATCH 10/22] lyt_window templated --- config/SOUE01/splits.txt | 7 + config/SOUE01/symbols.txt | 20 +-- configure.py | 1 + include/nw4r/lyt/lyt_pane.h | 4 +- include/nw4r/lyt/lyt_resources.h | 13 ++ include/nw4r/lyt/lyt_window.h | 57 ++++++-- src/nw4r/lyt/lyt_window.cpp | 231 +++++++++++++++++++++++++++++++ 7 files changed, 307 insertions(+), 26 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 5c8a14e5..bb8bd418 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -353,6 +353,13 @@ nw4r/lyt/lyt_textBox.cpp: .sbss start:0x80576708 end:0x8057670C .sdata2 start:0x8057F250 end:0x8057F268 +nw4r/lyt/lyt_window.cpp: + .text start:0x8048B170 end:0x8048D6FC + .ctors start:0x804DB980 end:0x804DB984 + .data start:0x8056E5F8 end:0x8056E6C0 + .sbss start:0x80576710 end:0x80576714 + .sdata2 start:0x8057F268 end:0x8057F280 + 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 b97b3b4a..71a2567a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2880,7 +2880,7 @@ fn_80065E70 = .text:0x80065E70; // type:function size:0xC4 fn_80065F40 = .text:0x80065F40; // type:function size:0x28 fn_80065F70 = .text:0x80065F70; // type:function size:0x328 fn_800662A0 = .text:0x800662A0; // type:function size:0xD4 -GetRuntimeTypeInfo__Q34nw4r3lyt4PaneCFv = .text:0x80066380; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt4PaneCFv = .text:0x80066380; // type:function size:0x8 scope:weak fn_80066390 = .text:0x80066390; // type:function size:0xE8 fn_80066480 = .text:0x80066480; // type:function size:0xC fn_80066490 = .text:0x80066490; // type:function size:0x40 @@ -25162,7 +25162,7 @@ DetachGeneralHandle__Q44nw4r3snd6detail10BasicSoundFv = .text:0x8046A2B0; // typ DetachTempGeneralHandle__Q44nw4r3snd6detail10BasicSoundFv = .text:0x8046A2C0; // type:function size:0x8 SetId__Q44nw4r3snd6detail10BasicSoundFUl = .text:0x8046A2D0; // type:function size:0x40 __dt__Q44nw4r3snd6detail10BasicSoundFv = .text:0x8046A310; // type:function size:0x40 -GetRuntimeTypeInfo__Q44nw4r3snd6detail10BasicSoundCFv = .text:0x8046A350; // type:function size:0x8 +GetRuntimeTypeInfo__Q44nw4r3snd6detail10BasicSoundCFv = .text:0x8046A350; // type:function size:0x8 scope:weak __sinit_\snd_BasicSound_cpp = .text:0x8046A360; // type:function size:0xC scope:local GetCoef__Q44nw4r3snd6detail15BiquadFilterLpfCFifPQ44nw4r3snd20BiquadFilterCallback10BiquadCoef = .text:0x8046A370; // type:function size:0x88 GetCoef__Q44nw4r3snd6detail15BiquadFilterHpfCFifPQ44nw4r3snd20BiquadFilterCallback10BiquadCoef = .text:0x8046A400; // type:function size:0x88 @@ -25411,7 +25411,7 @@ OnCancel__Q54nw4r3snd6detail8SeqSound11SeqLoadTaskFv = .text:0x804730F0; // type GetBasicPlayer__Q44nw4r3snd6detail8SeqSoundFv = .text:0x80473120; // type:function size:0x8 GetBasicPlayer__Q44nw4r3snd6detail8SeqSoundCFv = .text:0x80473130; // type:function size:0x8 IsPrepared__Q44nw4r3snd6detail8SeqSoundCFv = .text:0x80473140; // type:function size:0x8 -GetRuntimeTypeInfo__Q44nw4r3snd6detail8SeqSoundCFv = .text:0x80473150; // type:function size:0x8 +GetRuntimeTypeInfo__Q44nw4r3snd6detail8SeqSoundCFv = .text:0x80473150; // type:function size:0x8 scope:weak __sinit_snd_SeqSound_cpp = .text:0x80473160; // type:function size:0xC __ct__Q34nw4r3snd14SeqSoundHandleFPQ34nw4r3snd11SoundHandle = .text:0x80473170; // type:function size:0xF4 DetachSound__Q34nw4r3snd14SeqSoundHandleFv = .text:0x80473270; // type:function size:0x38 @@ -25711,7 +25711,7 @@ DetachTempSpecialHandle__Q44nw4r3snd6detail9StrmSoundFv = .text:0x80480D30; // t GetBasicPlayer__Q44nw4r3snd6detail9StrmSoundFv = .text:0x80480D40; // type:function size:0x8 GetBasicPlayer__Q44nw4r3snd6detail9StrmSoundCFv = .text:0x80480D50; // type:function size:0x8 IsPrepared__Q44nw4r3snd6detail9StrmSoundCFv = .text:0x80480D60; // type:function size:0x8 -GetRuntimeTypeInfo__Q44nw4r3snd6detail9StrmSoundCFv = .text:0x80480D70; // type:function size:0x8 +GetRuntimeTypeInfo__Q44nw4r3snd6detail9StrmSoundCFv = .text:0x80480D70; // type:function size:0x8 scope:weak __sinit_snd_StrmSound_cpp = .text:0x80480D80; // type:function size:0xC __ct__Q34nw4r3snd15StrmSoundHandleFPQ34nw4r3snd11SoundHandle = .text:0x80480D90; // type:function size:0xF4 DetachSound__Q34nw4r3snd15StrmSoundHandleFv = .text:0x80480E90; // type:function size:0x38 @@ -25814,7 +25814,7 @@ DetachTempSpecialHandle__Q44nw4r3snd6detail9WaveSoundFv = .text:0x804852C0; // t GetBasicPlayer__Q44nw4r3snd6detail9WaveSoundFv = .text:0x804852D0; // type:function size:0x8 GetBasicPlayer__Q44nw4r3snd6detail9WaveSoundCFv = .text:0x804852E0; // type:function size:0x8 IsPrepared__Q44nw4r3snd6detail9WaveSoundCFv = .text:0x804852F0; // type:function size:0x8 -GetRuntimeTypeInfo__Q44nw4r3snd6detail9WaveSoundCFv = .text:0x80485300; // type:function size:0x8 +GetRuntimeTypeInfo__Q44nw4r3snd6detail9WaveSoundCFv = .text:0x80485300; // type:function size:0x8 scope:weak __sinit_snd_WaveSound_cpp = .text:0x80485310; // type:function size:0xC detail_AttachSoundAsTempHandle__Q34nw4r3snd15WaveSoundHandleFPQ44nw4r3snd6detail9WaveSound = .text:0x80485320; // type:function size:0xF4 DetachSound__Q34nw4r3snd15WaveSoundHandleFv = .text:0x80485420; // type:function size:0x38 @@ -25921,7 +25921,7 @@ SetVtxColor__Q34nw4r3lyt7PictureFUlQ34nw4r2ut5Color = .text:0x80489690; // type: GetVtxColorElement__Q34nw4r3lyt7PictureCFUl = .text:0x804896C0; // type:function size:0x18 SetVtxColorElement__Q34nw4r3lyt7PictureFUlUc = .text:0x804896E0; // type:function size:0x18 DrawSelf__Q34nw4r3lyt7PictureFRCQ34nw4r3lyt8DrawInfo = .text:0x80489700; // type:function size:0xDC -GetRuntimeTypeInfo__Q34nw4r3lyt7PictureCFv = .text:0x804897E0; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt7PictureCFv = .text:0x804897E0; // type:function size:0x8 scope:weak __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 @@ -25963,11 +25963,11 @@ GetMaterialNum__Q34nw4r3lyt6WindowCFv = .text:0x8048D670; // type:function size: GetMaterial__Q34nw4r3lyt6WindowCFUl = .text:0x8048D680; // type:function size:0x2C GetFrameMaterial__Q34nw4r3lyt6WindowCFUl = .text:0x8048D6B0; // type:function size:0x28 GetContentMaterial__Q34nw4r3lyt6WindowCFv = .text:0x8048D6E0; // type:function size:0x10 -__sinit_lyt_window_cpp = .text:0x8048D6F0; // type:function size:0xC +__sinit_\lyt_window_cpp = .text:0x8048D6F0; // type:function size:0xC scope:local __ct__Q34nw4r3lyt8BoundingFPCQ44nw4r3lyt3res8BoundingRCQ34nw4r3lyt11ResBlockSet = .text:0x8048D700; // type:function size:0x3C __dt__Q34nw4r3lyt8BoundingFv = .text:0x8048D740; // type:function size:0x58 DrawSelf__Q34nw4r3lyt8BoundingFRCQ34nw4r3lyt8DrawInfo = .text:0x8048D7A0; // type:function size:0x4 -GetRuntimeTypeInfo__Q34nw4r3lyt8BoundingCFv = .text:0x8048D7B0; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt8BoundingCFv = .text:0x8048D7B0; // type:function size:0x8 scope:weak __sinit_lyt_bounding_cpp = .text:0x8048D7C0; // type:function size:0xC CalcTextureMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r4math5MTX34RCQ34nw4r3lyt6TexSRT = .text:0x8048D7D0; // type:function size:0x108 SetIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@F14_GXIndTexMtxIDPA3_Cf = .text:0x8048D8E0; // type:function size:0x200 @@ -40879,8 +40879,8 @@ typeInfo__Q34nw4r3lyt4Pane = .sbss:0x805766F0; // type:object size:0x4 data:4byt mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x4 data:4byte typeInfo__Q34nw4r3lyt7Picture = .sbss:0x80576700; // type:object size:0x4 data:4byte typeInfo__Q34nw4r3lyt7TextBox = .sbss:0x80576708; // type:object size:0x4 data:4byte -lbl_80576710 = .sbss:0x80576710; // type:object size:0x8 data:4byte -lbl_80576718 = .sbss:0x80576718; // type:object size:0x8 data:4byte +typeInfo__Q34nw4r3lyt6Window = .sbss:0x80576710; // type:object size:0x4 data:4byte +lbl_80576718 = .sbss:0x80576718; // type:object size:0x4 data:4byte @GUARD@SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc@texCoords = .sbss:0x80576720; // type:object size:0x1 data:byte lbl_80576728 = .sbss:0x80576728; // type:object size:0x8 data:byte lbl_80576730 = .sbss:0x80576730; // type:object size:0x8 data:byte diff --git a/configure.py b/configure.py index ab74faa9..caea4da1 100644 --- a/configure.py +++ b/configure.py @@ -357,6 +357,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_layout.cpp"), Object(Matching, "nw4r/lyt/lyt_picture.cpp"), Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), + Object(NonMatching, "nw4r/lyt/lyt_window.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_pane.h b/include/nw4r/lyt/lyt_pane.h index 37d9dbaf..cdbce93c 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -107,8 +107,8 @@ public: virtual ~Pane(); // at 0x8 NW4R_UT_RTTI_DECL(Pane); // at 0x0C virtual void CalculateMtx(const DrawInfo &drawInfo); // at 0x10 - virtual void Draw(const DrawInfo &); // at 0x14 - virtual void DrawSelf(const DrawInfo &); // at 0x18 + virtual void Draw(const DrawInfo &drawInfo); // at 0x14 + virtual void DrawSelf(const DrawInfo &drawInfo); // at 0x18 virtual void Animate(u32); // at 0x1C virtual void AnimateSelf(u32); // at 0x20 virtual ut::Color GetVtxColor(u32 idx) const; // at 0x24 diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index 03c6ea73..a5687948 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -155,6 +155,19 @@ struct Window : Pane { u32 frameOffsetTableOffset; // at 0x64 }; +struct WindowFrame { + u16 materialIdx; // at 0x0 + u8 textureFlip; // at 0x2 + u8 padding1; // at 0x3 +}; + +struct WindowContent { + u32 vtxCols[4]; // at 0x00 + u16 materialIdx; // at 0x10 + u8 texCoordNum; // at 0x12 + u8 padding[1]; // at 0x13 +}; + struct AnimationBlock { DataBlockHeader blockHeader; // at 0x00 u16 frameSize; // at 0x08 diff --git a/include/nw4r/lyt/lyt_window.h b/include/nw4r/lyt/lyt_window.h index 3b41dad8..a13133d6 100644 --- a/include/nw4r/lyt/lyt_window.h +++ b/include/nw4r/lyt/lyt_window.h @@ -10,17 +10,7 @@ namespace nw4r { namespace lyt { -struct Content { - ut::Color vtxColors[4]; // at 0x00 - detail::TexCoordAry texCoordAry; // at 0x10 -}; - -struct Frame { - bool textureFlip; // at 0x00 - Material *pMaterial; // at 0x04 -}; - -struct WindowFramSize { +struct WindowFrameSize { f32 l; // at 0x00 f32 r; // at 0x04 f32 t; // at 0x08 @@ -29,9 +19,48 @@ struct WindowFramSize { class Window : public Pane { public: - Window(const res::Window *, const ResBlockSet &ResBlockSet); - virtual ~Window(); - NW4R_UT_RTTI_DECL(Window); + struct Content { + Content() {} + + ut::Color vtxColors[4]; // at 0x00 + detail::TexCoordAry texCoordAry; // at 0x10 + }; + struct Frame { + bool textureFlip; // at 0x00 + Material *pMaterial; // at 0x04 + }; + + Window(const res::Window *pBlock, const ResBlockSet &ResBlockSet); + + void InitContent(u8 texNum); + void InitFrame(u8 frameNum); + void ReserveTexCoord(u8 num); + AnimationLink *FindAnimationLink(AnimTransform *pAnimTrans); + void SetAnimationEnable(AnimTransform *pAnimTrans, bool, bool); + + static WindowFrameSize GetFrameSize(u8 frameNum, const Frame *frames); + Material *GetFrameMaterial(u32 frameIdx) const; + Material *GetContentMaterial() const; + + virtual ~Window(); // at 0x08 + NW4R_UT_RTTI_DECL(Window); // at 0x0C + virtual void DrawSelf(const DrawInfo &drawInfo); // at 0x18 + virtual void AnimateSelf(u32 option); // at 0x20 + 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 Material *FindMaterialByName(const char *findName, bool bRecursive); // at 0x40 + virtual void UnbindAnimationSelf(AnimTransform *pAnimTrans); // at 0x50 + virtual u8 GetMaterialNum() const; // at 0x64 + virtual Material *GetMaterial(u32 idx) const; // at 0x6C + virtual void DrawContent(const math::VEC2 &basePt, const WindowFrameSize &frameSize, u8 alpha); // at 0x74 + virtual void DrawFrame(const math::VEC2 &basePt, const Frame &frame, const WindowFrameSize &frameSize, // + u8 alpha); // at 0x78 + virtual void DrawFrame4(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // + u8 alpha); // at 0x7C + virtual void DrawFrame8(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // + u8 alpha); // at 0x80 private: res::InflationLRTB mContentInflation; // at 0x0D8 diff --git a/src/nw4r/lyt/lyt_window.cpp b/src/nw4r/lyt/lyt_window.cpp index e69de29b..728c461d 100644 --- a/src/nw4r/lyt/lyt_window.cpp +++ b/src/nw4r/lyt/lyt_window.cpp @@ -0,0 +1,231 @@ +#include +#include + +namespace nw4r { +namespace lyt { + +// TODO: Find Place +struct TextureFlipInfo { + u8 coords[2][4]; // at 0x00 + u8 idx[2]; // at 0x8 +}; + +TextureFlipInfo flipInfos[6] = {}; + +namespace { +// GetTexutreFlipInfo__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FUc +// GetTexutreFlipInfo__24@unnamed@lyt_window_cpp@FUc +TextureFlipInfo &GetTextureFlipInfo(u8 textureFlip) {} + +// GetLTFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +// GetLTFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +void GetLTFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, + const WindowFrameSize &frameSize) {} + +// GetLTTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +// GetLTTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +void GetLTTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { + const TextureFlipInfo &flipInfo = flipInfo; + int ix; + int iy; + math::VEC2 tSz; +} + +// GetRTFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +// GetRTFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +void GetRTFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, + const WindowFrameSize &frameSize) {} + +// GetRTTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +// GetRTTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +void GetRTTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { + const TextureFlipInfo &flipInfo = flipInfo; + int ix; + int iy; + math::VEC2 tSz; +} + +// GetLBFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +// GetLBFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +void GetLBFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, + const WindowFrameSize &frameSize) {} + +// GetLBTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +// GetLBTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +void GetLBTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { + const TextureFlipInfo &flipInfo = flipInfo; + int ix; + int iy; + math::VEC2 tSz; +} + +// GetRBFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +// GetRBFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize +void GetRBFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, + const WindowFrameSize &frameSize) {} + +// GetRBTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +// GetRBTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc +void GetRBTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { + const TextureFlipInfo &flipInfo = flipInfo; + int ix; + int iy; + math::VEC2 tSz; +} +} // namespace + +NW4R_UT_RTTI_DEF_DERIVED(Window, Pane); + +// __dt__Q44nw4r3lyt6Window5FrameFv + +// __ct__Q34nw4r3lyt6WindowFPCQ44nw4r3lyt3res6WindowRCQ34nw4r3lyt11ResBlockSet +Window::Window(const res::Window *pBlock, const ResBlockSet &ResBlockSet) { + const res::WindowContent *pResContent; + u8 texCoordNum; + const u32 *matOffsTbl; + { + int i; + const res::Material *pResMaterial; + } + + const u32 *frameOffsetTable; + { + int i; + const res::WindowFrame *pResWindowFrame; + } +} + +// InitContent__Q34nw4r3lyt6WindowFUc +void Window::InitContent(u8 texNum) {} + +// InitFrame__Q34nw4r3lyt6WindowFUc +void Window::InitFrame(u8 frameNum) {} + +// __dt__Q44nw4r3lyt6Window7ContentFv + +// __dt__Q34nw4r3lyt6WindowFv +Window::~Window() {} + +// ReserveTexCoord__Q34nw4r3lyt6WindowFUc +void Window::ReserveTexCoord(u8 num) {} + +// FindMaterialByName__Q34nw4r3lyt6WindowFPCcb +Material *Window::FindMaterialByName(const char *findName, bool bRecursive) { + int i; + // ut::LinkList<>::Iterator it + Material *pMat; +} + +// FindAnimationLink__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransform +AnimationLink *Window::FindAnimationLink(AnimTransform *pAnimTrans) { + // TOOD +} + +// SetAnimationEnable__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransformbb +void Window::SetAnimationEnable(AnimTransform *pAnimTrans, bool, bool) { + // TOOD +} + +// GetVtxColor__Q34nw4r3lyt6WindowCFUl +ut::Color Window::GetVtxColor(u32 idx) const {} + +// SetVtxColor__Q34nw4r3lyt6WindowFUlQ34nw4r2ut5Color +void Window::SetVtxColor(u32, ut::Color) {} + +// GetVtxColorElement__Q34nw4r3lyt6WindowCFUl +u8 Window::GetVtxColorElement(u32 idx) const {} + +// SetVtxColorElement__Q34nw4r3lyt6WindowFUlUc +void Window::SetVtxColorElement(u32 idx, u8 value) {} + +// DrawSelf__Q34nw4r3lyt6WindowFRCQ34nw4r3lyt8DrawInfo +void Window::DrawSelf(const DrawInfo &drawInfo) { + WindowFrameSize frameSize; + math::VEC2 bastPt; +} + +// AnimateSelf__Q34nw4r3lyt6WindowFUl +void Window::AnimateSelf(u32 option) { + int i; +} + +// UnbindAnimationSelf__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransform +void Window::UnbindAnimationSelf(AnimTransform *pAnimTrans) { + int i; +} + +// DrawContent__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt15WindowFrameSizeUc +void Window::DrawContent(const math::VEC2 &basePt, const WindowFrameSize &frameSize, u8 alpha) { + bool bUseVtxCol; +} + +// DrawFrame__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2RCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc +void Window::DrawFrame(const math::VEC2 &basePt, const Frame &frame, const WindowFrameSize &frameSize, u8 alpha) { + bool bUseVtxCol; + Size texSize; + ut::Color vtxColors[4]; + detail::TexCoordData texCds[1]; + math::VEC2 polPt; + Size polSize; +} + +// DrawFrame4__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2PCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc +void Window::DrawFrame4(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, u8 alpha) { + ut::Color vtxColors[4]; + detail::TexCoordData texCds[1]; + math::VEC2 polPt; + Size polSize; + bool bModVtxCol; + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } +} + +// DrawFrame8__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2PCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc +void Window::DrawFrame8(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, u8 alpha) { + ut::Color vtxColors[4]; + detail::TexCoordData texCds[1]; + math::VEC2 polPt; + Size polSize; + bool bModVtxCol; + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } + { bool bUseVtxCol; } +} + +// GetFrameSize__Q34nw4r3lyt6WindowFUcPCQ44nw4r3lyt6Window5Frame +WindowFrameSize Window::GetFrameSize(u8 frameNum, const Frame *frames) { + { Size texSize; } + { Size texSize; } +} + +// GetMaterialNum__Q34nw4r3lyt6WindowCFv +u8 Window::GetMaterialNum() const {} + +// GetMaterial__Q34nw4r3lyt6WindowCFUl +Material *Window::GetMaterial(u32 idx) const {} + +// GetFrameMaterial__Q34nw4r3lyt6WindowCFUl +Material *Window::GetFrameMaterial(u32 frameIdx) const {} + +// GetContentMaterial__Q34nw4r3lyt6WindowCFv +Material *Window::GetContentMaterial() const {} + +} // namespace lyt + +} // namespace nw4r + +// HEADER STUFF +// ConvertOffsToPtr +// ConvertOffsToPtr +// __as__Q34nw4r3lyt13InflationLRTBFRCQ34nw4r3lyt13InflationLRTB + +// texCoordNum .sdata +// flipInfos . data +// ut::Min From 217c03e5b8cd4621db27d43aa4b38dee071b87e3 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Wed, 29 May 2024 01:26:44 -0400 Subject: [PATCH 11/22] lyt_window matching --- config/SOUE01/symbols.txt | 6 +- configure.py | 3 +- include/nw4r/lyt/lyt_bounding.h | 7 - include/nw4r/lyt/lyt_common.h | 11 +- include/nw4r/lyt/lyt_layout.h | 1 + include/nw4r/lyt/lyt_window.h | 40 ++- src/nw4r/lyt/lyt_window.cpp | 547 +++++++++++++++++++++++++++----- 7 files changed, 506 insertions(+), 109 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 71a2567a..a4c11e15 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -3864,7 +3864,7 @@ GetRuntimeTypeInfo__Q34nw4r3lyt7TextBoxCFv = .text:0x800B15B0; // type:function fn_800B15C0 = .text:0x800B15C0; // type:function size:0x68 fn_800B1630 = .text:0x800B1630; // type:function size:0x3C fn_800B1670 = .text:0x800B1670; // type:function size:0x134 -fn_800B17B0 = .text:0x800B17B0; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r3lyt6WindowCFv = .text:0x800B17B0; // type:function size:0x8 scope:weak fn_800B17C0 = .text:0x800B17C0; // type:function size:0x58 __dt__Q34nw4r3lyt19ArcResourceAccessorFv = .text:0x800B1820; // type:function size:0x6C scope:weak fn_800B1890 = .text:0x800B1890; // type:function size:0x40 @@ -37077,8 +37077,8 @@ __vt__Q34nw4r3lyt5Group = .data:0x8056E4A8; // type:object size:0xC __vt__Q34nw4r3lyt6Layout = .data:0x8056E4B8; // type:object size:0x40 __vt__Q34nw4r3lyt7Picture = .data:0x8056E4F8; // type:object size:0x78 __vt__Q34nw4r3lyt7TextBox = .data:0x8056E570; // type:object size:0x84 -lbl_8056E5F8 = .data:0x8056E5F8; // type:object size:0x3C -lbl_8056E634 = .data:0x8056E634; // type:object size:0x8C +@LOCAL@GetTextureFlipInfo__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FUc@flipInfos = .data:0x8056E5F8; // type:object size:0x3C +__vt__Q34nw4r3lyt6Window = .data:0x8056E634; // type:object size:0x8C lbl_8056E6C0 = .data:0x8056E6C0; // type:object size:0x78 lbl_8056E738 = .data:0x8056E738; // type:object size:0x20 data:4byte lbl_8056E758 = .data:0x8056E758; // type:object size:0x20 data:4byte diff --git a/configure.py b/configure.py index caea4da1..e81a6cdc 100644 --- a/configure.py +++ b/configure.py @@ -203,6 +203,7 @@ cflags_nw4r = [ *cflags_base, "-ipa file", "-fp_contract off", + "" ] # REL flags @@ -357,7 +358,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_layout.cpp"), Object(Matching, "nw4r/lyt/lyt_picture.cpp"), Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), - Object(NonMatching, "nw4r/lyt/lyt_window.cpp"), + Object(Matching, "nw4r/lyt/lyt_window.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_bounding.h b/include/nw4r/lyt/lyt_bounding.h index 56fe12d2..323e768a 100644 --- a/include/nw4r/lyt/lyt_bounding.h +++ b/include/nw4r/lyt/lyt_bounding.h @@ -8,13 +8,6 @@ namespace nw4r { namespace lyt { -struct ResBlockSet { - const res::TextureList *pTextureList; // at 0x00 - const res::FontList *pFontList; // at 0x04 - const res::MaterialList *pMaterialList; // at 0x08 - ResourceAccessor *pResAccessor; // at 0x0C -}; - class Bounding : public Pane { public: Bounding(const res::Bounding *, const ResBlockSet &); diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index 81b40ae5..bd09aae9 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -75,10 +75,19 @@ void MultipleAlpha(ut::Color *, const ut::Color *, u8); // Inlined ut::Color MultipleAlpha(ut::Color, u8); void SetVertexFormat(bool, u8); void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const ut::Color *); -void DrawQuad(const math::VEC2 &, const Size &, u8, const TexCoordData *, const ut::Color *, u8); +void DrawQuad(const math::VEC2 &basePt, const Size &size, u8 texCoordNum, const TexCoordData *texCoords, + const ut::Color *vtxColors, u8 alpha); void DrawLine(const math::VEC2 &pos, const Size &size, ut::Color color); } // namespace detail + +struct ResBlockSet { + const res::TextureList *pTextureList; // at 0x00 + const res::FontList *pFontList; // at 0x04 + const res::MaterialList *pMaterialList; // at 0x08 + ResourceAccessor *pResAccessor; // at 0x0C +}; + } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index b7d801c7..13689a32 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -3,6 +3,7 @@ #include "common.h" #include #include +#include #include #include #include diff --git a/include/nw4r/lyt/lyt_window.h b/include/nw4r/lyt/lyt_window.h index a13133d6..89c6d9e4 100644 --- a/include/nw4r/lyt/lyt_window.h +++ b/include/nw4r/lyt/lyt_window.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -10,6 +11,19 @@ namespace nw4r { namespace lyt { +// NOT OFFICAL +// Pulled from https://wiki.tockdom.com/wiki/BRLYT_(File_Format)#Window_Frames +enum TextureFlip { + TEXFLIP_NONE, + TEXFLIP_HORIZONTAL, + TEXFLIP_VERTICAL, + TEXFLIP_ROTATE_90, + TEXFLIP_ROTATE_180, + TEXFLIP_ROTATE_270, +}; + +enum TextureCoord { TopL, TopR, BotL, BotR }; + struct WindowFrameSize { f32 l; // at 0x00 f32 r; // at 0x04 @@ -20,13 +34,17 @@ struct WindowFrameSize { class Window : public Pane { public: struct Content { - Content() {} + Content() : vtxColors(), texCoordAry() {} ut::Color vtxColors[4]; // at 0x00 detail::TexCoordAry texCoordAry; // at 0x10 }; struct Frame { - bool textureFlip; // at 0x00 + Frame() : textureFlip(false), pMaterial(nullptr) {} + ~Frame() { + Layout::DeleteObj(pMaterial); + } + u8 textureFlip; // at 0x00 Material *pMaterial; // at 0x04 }; @@ -35,12 +53,8 @@ public: void InitContent(u8 texNum); void InitFrame(u8 frameNum); void ReserveTexCoord(u8 num); - AnimationLink *FindAnimationLink(AnimTransform *pAnimTrans); - void SetAnimationEnable(AnimTransform *pAnimTrans, bool, bool); static WindowFrameSize GetFrameSize(u8 frameNum, const Frame *frames); - Material *GetFrameMaterial(u32 frameIdx) const; - Material *GetContentMaterial() const; virtual ~Window(); // at 0x08 NW4R_UT_RTTI_DECL(Window); // at 0x0C @@ -54,18 +68,20 @@ public: virtual void UnbindAnimationSelf(AnimTransform *pAnimTrans); // at 0x50 virtual u8 GetMaterialNum() const; // at 0x64 virtual Material *GetMaterial(u32 idx) const; // at 0x6C - virtual void DrawContent(const math::VEC2 &basePt, const WindowFrameSize &frameSize, u8 alpha); // at 0x74 + virtual Material *GetContentMaterial() const; // at 0x74 + virtual Material *GetFrameMaterial(u32 frameIdx) const; // at 0x78 + virtual void DrawContent(const math::VEC2 &basePt, const WindowFrameSize &frameSize, u8 alpha); // at 0x7C virtual void DrawFrame(const math::VEC2 &basePt, const Frame &frame, const WindowFrameSize &frameSize, // - u8 alpha); // at 0x78 - virtual void DrawFrame4(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // - u8 alpha); // at 0x7C - virtual void DrawFrame8(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // u8 alpha); // at 0x80 + virtual void DrawFrame4(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // + u8 alpha); // at 0x84 + virtual void DrawFrame8(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, // + u8 alpha); // at 0x88 private: res::InflationLRTB mContentInflation; // at 0x0D8 Content mContent; // at 0x0E8 - Frame *mFrams; // at 0x100 + Frame *mFrames; // at 0x100 u8 mFrameNum; // 0x104 }; diff --git a/src/nw4r/lyt/lyt_window.cpp b/src/nw4r/lyt/lyt_window.cpp index 728c461d..93bb2ed7 100644 --- a/src/nw4r/lyt/lyt_window.cpp +++ b/src/nw4r/lyt/lyt_window.cpp @@ -1,76 +1,179 @@ #include +#include +#include #include namespace nw4r { namespace lyt { - // TODO: Find Place struct TextureFlipInfo { - u8 coords[2][4]; // at 0x00 + u8 coords[4][2]; // at 0x00 u8 idx[2]; // at 0x8 }; -TextureFlipInfo flipInfos[6] = {}; - namespace { // GetTexutreFlipInfo__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FUc // GetTexutreFlipInfo__24@unnamed@lyt_window_cpp@FUc -TextureFlipInfo &GetTextureFlipInfo(u8 textureFlip) {} +// look at TextureFlip enum in lyt_window.h +TextureFlipInfo &GetTextureFlipInfo(u8 textureFlip) { + static TextureFlipInfo flipInfos[6] = { + // TopL TopR BotL BotR idx + {{{0, 0}, {1, 0}, {0, 1}, {1, 1}}, {0, 1}}, // Normal + {{{1, 0}, {0, 0}, {1, 1}, {0, 1}}, {0, 1}}, // Horizontal Flip + {{{0, 1}, {1, 1}, {0, 0}, {1, 0}}, {0, 1}}, // Vertical Flip + {{{0, 1}, {0, 0}, {1, 1}, {1, 0}}, {1, 0}}, // Rotate 90 + {{{1, 1}, {0, 1}, {1, 0}, {0, 0}}, {0, 1}}, // Rotate 180 + {{{1, 0}, {1, 1}, {0, 0}, {0, 1}}, {1, 0}}, // Rotate 270 + }; + return flipInfos[textureFlip]; +} + +/** +----> +x + * LT RT | + * v v v + * +-------+-----------------+-------+ ^ -y + * | ^ | | | + * | t | | | VTX: (x, y) + * | v | | | base = (x, y) + * LB->+-------+-----------------+ + | LT = ( x , y ) + * | | | | | RT = ( x + w - r , y ) + * | | | | | LB = ( x , y - t ) + * |<- l ->| |<- r ->| h RB = ( x + l , y - h + b ) + * | | | | | SIZE: (w, h) + * | | RB (at +) | | | LT = ( w - r , t ) + * | | V | | | RT = ( r , h - b ) + * + +-----------------+-------+ | LB = ( l , h - t ) + * | | ^ | | RB = ( w - l , b ) + * | | b | | + * | | v | | + * +-------+-----------------+-------+ v + * <--------------- w ---------------> + */ + +// The below functions were started with +// https://github.com/Treeki/LayoutStudio/blob/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/layoutgl/widget.cpp#L162 Really +// helped read the awful Ghidra output xD // GetLTFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize // GetLTFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize void GetLTFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, - const WindowFrameSize &frameSize) {} + const WindowFrameSize &frameSize) { + *pPt = basePt; + // pPt->x = basePt.x; + // pPt->y = basePt.y; + pSize->width = windSize.width - frameSize.r; + pSize->height = frameSize.t; + // *pSize = Size(windSize.width - frameSize.r, frameSize.t); +} // GetLTTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc // GetLTTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc void GetLTTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { - const TextureFlipInfo &flipInfo = flipInfo; - int ix; - int iy; - math::VEC2 tSz; + const TextureFlipInfo &flipInfo = GetTextureFlipInfo(textureFlip); + + int ix = flipInfo.idx[0]; + int iy = flipInfo.idx[1]; + math::VEC2 tSz(texSize.width, texSize.height); + + // clang-format off + // Again no temp vars used here + texCds[TopL][ix] = texCds[BotL][ix] = flipInfo.coords[TopL][ix]; + texCds[TopL][iy] = texCds[TopR][iy] = flipInfo.coords[TopL][iy]; + + texCds[BotR][ix] = texCds[TopR][ix] = flipInfo.coords[TopL][ix] + polSize.width / ((flipInfo.coords[TopR][ix] - flipInfo.coords[TopL][ix]) * tSz[ix]); + texCds[BotR][iy] = texCds[BotL][iy] = flipInfo.coords[TopL][iy] + polSize.height / ((flipInfo.coords[BotL][iy] - flipInfo.coords[TopL][iy]) * tSz[iy]); + // clang-format on } // GetRTFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize // GetRTFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize void GetRTFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, - const WindowFrameSize &frameSize) {} + const WindowFrameSize &frameSize) { + *pPt = math::VEC2(basePt.x + windSize.width - frameSize.r, basePt.y); + // pPt->x = basePt.x + windSize.width - frameSize.r; + // pPt->y = basePt.y + // *pSize = Size(frameSize.r, windSize.height - frameSize.b); + pSize->width = frameSize.r; + pSize->height = windSize.height - frameSize.b; +} // GetRTTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc // GetRTTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc void GetRTTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { - const TextureFlipInfo &flipInfo = flipInfo; - int ix; - int iy; - math::VEC2 tSz; + const TextureFlipInfo &flipInfo = GetTextureFlipInfo(textureFlip); + int ix = flipInfo.idx[0]; + int iy = flipInfo.idx[1]; + + math::VEC2 tSz(texSize.width, texSize.height); + // clang-format off + // Again no temp vars used here + texCds[TopR][ix] = texCds[BotR][ix] = flipInfo.coords[TopR][ix]; + texCds[TopR][iy] = texCds[TopL][iy] = flipInfo.coords[TopR][iy]; + + texCds[BotL][ix] = texCds[TopL][ix] = flipInfo.coords[TopR][ix] + polSize.width / ((flipInfo.coords[TopL][ix] - flipInfo.coords[TopR][ix]) * tSz[ix]); + texCds[BotL][iy] = texCds[BotR][iy] = flipInfo.coords[TopR][iy] + polSize.height / ((flipInfo.coords[BotR][iy] - flipInfo.coords[TopR][iy]) * tSz[iy]); + // clang-format on } // GetLBFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize // GetLBFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize void GetLBFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, - const WindowFrameSize &frameSize) {} + const WindowFrameSize &frameSize) { + *pPt = math::VEC2(basePt.x, basePt.y - frameSize.t); + // pPt->x = basePt.x; + // pPt->y = basePt.y - frameSize.t; + + // *pSize = Size(frameSize.l, windSize.height - frameSize.t); + pSize->width = frameSize.l; + pSize->height = windSize.height - frameSize.t; +} // GetLBTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc // GetLBTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc void GetLBTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { - const TextureFlipInfo &flipInfo = flipInfo; - int ix; - int iy; - math::VEC2 tSz; + const TextureFlipInfo &flipInfo = GetTextureFlipInfo(textureFlip); + int ix = flipInfo.idx[0]; + int iy = flipInfo.idx[1]; + + math::VEC2 tSz(texSize.width, texSize.height); + // clang-format off + // Again no temp vars used here + texCds[BotL][ix] = texCds[TopL][ix] = flipInfo.coords[BotL][ix]; + texCds[BotL][iy] = texCds[BotR][iy] = flipInfo.coords[BotL][iy]; + + texCds[TopR][ix] = texCds[BotR][ix] = flipInfo.coords[BotL][ix] + polSize.width / ((flipInfo.coords[BotR][ix] - flipInfo.coords[BotL][ix]) * tSz[ix]); + texCds[TopR][iy] = texCds[TopL][iy] = flipInfo.coords[BotL][iy] + polSize.height / ((flipInfo.coords[TopL][iy] - flipInfo.coords[BotL][iy]) * tSz[iy]); + + // clang-format on } // GetRBFrameSize__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize // GetRBFrameSize__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2PQ34nw4r3lyt4SizeRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt15WindowFrameSize void GetRBFrameSize(math::VEC2 *pPt, Size *pSize, const math::VEC2 &basePt, const Size &windSize, - const WindowFrameSize &frameSize) {} + const WindowFrameSize &frameSize) { + *pPt = math::VEC2(basePt.x + frameSize.l, basePt.y - windSize.height + frameSize.b); + // pPt->x = basePt.x + frameSize.l; + // pPt->y = basePt.y - windSize.height + frameSize.b; + // *pSize = Size(windSize.width - frameSize.l, frameSize.b); + pSize->width = windSize.width - frameSize.l; + pSize->height = frameSize.b; +} // GetRBTexCoord__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc // GetRBTexCoord__24@unnamed@lyt_window_cpp@FPQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeRCQ34nw4r3lyt4SizeUc void GetRBTexCoord(math::VEC2 *texCds, const Size &polSize, const Size &texSize, u8 textureFlip) { - const TextureFlipInfo &flipInfo = flipInfo; - int ix; - int iy; - math::VEC2 tSz; + const TextureFlipInfo &flipInfo = GetTextureFlipInfo(textureFlip); + int ix = flipInfo.idx[0]; + int iy = flipInfo.idx[1]; + math::VEC2 tSz(texSize.width, texSize.height); + + // clang-format off + texCds[BotR][ix] = texCds[TopR][ix] = flipInfo.coords[BotR][ix]; + texCds[BotR][iy] = texCds[BotL][iy] = flipInfo.coords[BotR][iy]; + + texCds[TopL][ix] = texCds[BotL][ix] = flipInfo.coords[BotR][ix] + polSize.width / ((flipInfo.coords[BotL][ix] - flipInfo.coords[BotR][ix]) * tSz[ix]); + texCds[TopL][iy] = texCds[TopR][iy] = flipInfo.coords[BotR][iy] + polSize.height / ((flipInfo.coords[TopR][iy] - flipInfo.coords[BotR][iy]) * tSz[iy]); + // clang-format on } } // namespace @@ -79,94 +182,222 @@ NW4R_UT_RTTI_DEF_DERIVED(Window, Pane); // __dt__Q44nw4r3lyt6Window5FrameFv // __ct__Q34nw4r3lyt6WindowFPCQ44nw4r3lyt3res6WindowRCQ34nw4r3lyt11ResBlockSet -Window::Window(const res::Window *pBlock, const ResBlockSet &ResBlockSet) { - const res::WindowContent *pResContent; - u8 texCoordNum; - const u32 *matOffsTbl; - { - int i; - const res::Material *pResMaterial; +Window::Window(const res::Window *pBlock, const ResBlockSet &resBlockSet) : Pane(pBlock), mContent() { + const res::WindowContent *pResContent = + detail::ConvertOffsToPtr(pBlock, pBlock->contentOffset); + + u8 texCoordNum = ut::Min(pResContent->texCoordNum, 8); + + InitContent(texCoordNum); + + const u32 *matOffsTbl = detail::ConvertOffsToPtr(resBlockSet.pMaterialList, sizeof(res::MaterialList)); + + mContentInflation = pBlock->inflation; + for (int i = 0; i < TEXCOORD_VTX_COUNT; i++) { + mContent.vtxColors[i] = pResContent->vtxCols[i]; } - const u32 *frameOffsetTable; - { - int i; - const res::WindowFrame *pResWindowFrame; + if (texCoordNum && !mContent.texCoordAry.IsEmpty()) { + mContent.texCoordAry.Copy(&pResContent[1], texCoordNum); + } + + const res::Material *pResMaterial = + detail::ConvertOffsToPtr(resBlockSet.pMaterialList, matOffsTbl[pResContent->materialIdx]); + mpMaterial = Layout::NewObj(pResMaterial, resBlockSet); + + mFrameNum = 0; + mFrames = nullptr; + if (pBlock->frameNum) { + InitFrame(pBlock->frameNum); + const u32 *frameOffsetTable = detail::ConvertOffsToPtr(pBlock, pBlock->frameOffsetTableOffset); + for (int i = 0; i < mFrameNum; i++) { + const res::WindowFrame *pResWindowFrame = + detail::ConvertOffsToPtr(pBlock, frameOffsetTable[i]); + mFrames[i].textureFlip = pResWindowFrame->textureFlip; + const res::Material *pResMaterial = detail::ConvertOffsToPtr(resBlockSet.pMaterialList, + matOffsTbl[pResWindowFrame->materialIdx]); + mFrames[i].pMaterial = Layout::NewObj(pResMaterial, resBlockSet); + } } } // InitContent__Q34nw4r3lyt6WindowFUc -void Window::InitContent(u8 texNum) {} +void Window::InitContent(u8 texNum) { + // Guess based of of usual Init Patterns + // not needed to match ¯\_(ツ)_/¯ + if (texNum) { + ReserveTexCoord(texNum); + } +} // InitFrame__Q34nw4r3lyt6WindowFUc -void Window::InitFrame(u8 frameNum) {} +void Window::InitFrame(u8 frameNum) { + mFrameNum = 0; + mFrames = Layout::NewArray(frameNum); + if (mFrames) { + mFrameNum = frameNum; + } +} // __dt__Q44nw4r3lyt6Window7ContentFv // __dt__Q34nw4r3lyt6WindowFv -Window::~Window() {} +Window::~Window() { + Layout::DeleteArray(mFrames, mFrameNum); + if (mpMaterial && !mpMaterial->IsUserAllocated()) { + Layout::DeleteObj(mpMaterial); + mpMaterial = nullptr; + } + mContent.texCoordAry.Free(); +} // ReserveTexCoord__Q34nw4r3lyt6WindowFUc -void Window::ReserveTexCoord(u8 num) {} +void Window::ReserveTexCoord(u8 num) { + // Inline Guess + mContent.texCoordAry.Reserve(num); +} // FindMaterialByName__Q34nw4r3lyt6WindowFPCcb Material *Window::FindMaterialByName(const char *findName, bool bRecursive) { - int i; - // ut::LinkList<>::Iterator it - Material *pMat; + if (mpMaterial && detail::EqualsMaterialName(mpMaterial->GetName(), findName)) { + return mpMaterial; + } + + for (int i = 0; i < mFrameNum; i++) { + if (detail::EqualsMaterialName(mFrames[i].pMaterial->GetName(), findName)) { + return mFrames[i].pMaterial; + } + } + + if (bRecursive) { + for (ut::LinkList::Iterator it = mChildList.GetBeginIter(); it != mChildList.GetEndIter(); it++) { + Material *pMat = it->FindMaterialByName(findName, bRecursive); + if (pMat) { + return pMat; + } + } + } + return nullptr; } // FindAnimationLink__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransform -AnimationLink *Window::FindAnimationLink(AnimTransform *pAnimTrans) { - // TOOD -} +// AnimationLink *Window::FindAnimationLink(AnimTransform *pAnimTrans) { +// // Not In SS - Part of Vtable in Pane +// } // SetAnimationEnable__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransformbb -void Window::SetAnimationEnable(AnimTransform *pAnimTrans, bool, bool) { - // TOOD -} +// void Window::SetAnimationEnable(AnimTransform *pAnimTrans, bool, bool) { +// // Not In SS - Part of Vtable in Pane +// } // GetVtxColor__Q34nw4r3lyt6WindowCFUl -ut::Color Window::GetVtxColor(u32 idx) const {} +ut::Color Window::GetVtxColor(u32 idx) const { + return mContent.vtxColors[idx]; +} // SetVtxColor__Q34nw4r3lyt6WindowFUlQ34nw4r2ut5Color -void Window::SetVtxColor(u32, ut::Color) {} +void Window::SetVtxColor(u32 idx, ut::Color value) { + mContent.vtxColors[idx] = value; +} // GetVtxColorElement__Q34nw4r3lyt6WindowCFUl -u8 Window::GetVtxColorElement(u32 idx) const {} +u8 Window::GetVtxColorElement(u32 idx) const { + return detail::GetVtxColorElement(mContent.vtxColors, idx); +} // SetVtxColorElement__Q34nw4r3lyt6WindowFUlUc -void Window::SetVtxColorElement(u32 idx, u8 value) {} +void Window::SetVtxColorElement(u32 idx, u8 value) { + detail::SetVtxColElement(mContent.vtxColors, idx, value); +} // DrawSelf__Q34nw4r3lyt6WindowFRCQ34nw4r3lyt8DrawInfo void Window::DrawSelf(const DrawInfo &drawInfo) { - WindowFrameSize frameSize; - math::VEC2 bastPt; + LoadMtx(drawInfo); + WindowFrameSize frameSize = GetFrameSize(mFrameNum, mFrames); + math::VEC2 basePt = GetVtxPos(); + DrawContent(basePt, frameSize, mGlbAlpha); + switch (mFrameNum) { + case 1: + DrawFrame(basePt, mFrames[0], frameSize, mGlbAlpha); + break; + case 4: + DrawFrame4(basePt, mFrames, frameSize, mGlbAlpha); + break; + case 8: + DrawFrame8(basePt, mFrames, frameSize, mGlbAlpha); + break; + } } // AnimateSelf__Q34nw4r3lyt6WindowFUl void Window::AnimateSelf(u32 option) { - int i; + Pane::AnimateSelf(option); + if (IsVisible() || !(option & 1)) { + for (int i = 0; i < mFrameNum; i++) { + mFrames[i].pMaterial->Animate(); + } + } } // UnbindAnimationSelf__Q34nw4r3lyt6WindowFPQ34nw4r3lyt13AnimTransform void Window::UnbindAnimationSelf(AnimTransform *pAnimTrans) { - int i; + for (int i = 0; i < mFrameNum; i++) { + mFrames[i].pMaterial->UnbindAnimation(pAnimTrans); + } + Pane::UnbindAnimationSelf(pAnimTrans); } // DrawContent__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt15WindowFrameSizeUc void Window::DrawContent(const math::VEC2 &basePt, const WindowFrameSize &frameSize, u8 alpha) { - bool bUseVtxCol; + bool bUseVtxCol = detail::IsModulateVertexColor(mContent.vtxColors, alpha); + bUseVtxCol = mpMaterial->SetupGX(bUseVtxCol, alpha); + detail::SetVertexFormat(bUseVtxCol, mContent.texCoordAry.GetSize()); + + // Why not use temps wtf. only bUseVtxCol is defined in DWARF and I cant find evidence of an inline + detail::DrawQuad( + math::VEC2(basePt.x + frameSize.l - mContentInflation.l, basePt.y - frameSize.t + mContentInflation.t), + Size(mSize.width - frameSize.l + mContentInflation.l - frameSize.r + mContentInflation.r, + mSize.height - frameSize.t + mContentInflation.t - frameSize.b + mContentInflation.b), + mContent.texCoordAry.GetSize(), mContent.texCoordAry.GetArray(), bUseVtxCol ? mContent.vtxColors : nullptr, + alpha); } // DrawFrame__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2RCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc void Window::DrawFrame(const math::VEC2 &basePt, const Frame &frame, const WindowFrameSize &frameSize, u8 alpha) { - bool bUseVtxCol; - Size texSize; - ut::Color vtxColors[4]; - detail::TexCoordData texCds[1]; - math::VEC2 polPt; - Size polSize; + if (frame.pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = detail::IsModulateVertexColor(nullptr, alpha); + bUseVtxCol = frame.pMaterial->SetupGX(bUseVtxCol, alpha); + + detail::SetVertexFormat(bUseVtxCol, 1); + Size texSize = detail::GetTextureSize(frame.pMaterial, 0); + + ut::Color vtxColors[4]; + detail::TexCoordData texCds[1]; + math::VEC2 polPt; + Size polSize; + + // Splits Frame into 4 Corners (repeats frame for each part (texture is quartered)) + // Not sure if just edges or Quadrants + // (Top Left Quadrant) + GetLTFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetLTTexCoord(texCds[0], polSize, texSize, TEXFLIP_NONE); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + + // (Top Right Quadrant) + GetRTFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetRTTexCoord(texCds[0], polSize, texSize, TEXFLIP_HORIZONTAL); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + + // (Bottom Right Quadrant) + GetRBFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetRBTexCoord(texCds[0], polSize, texSize, TEXFLIP_ROTATE_180); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + + // (Bottom Left Quadrant) + GetLBFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetLBTexCoord(texCds[0], polSize, texSize, TEXFLIP_VERTICAL); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } } // DrawFrame4__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2PCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc @@ -175,47 +406,193 @@ void Window::DrawFrame4(const math::VEC2 &basePt, const Frame *frame, const Wind detail::TexCoordData texCds[1]; math::VEC2 polPt; Size polSize; - bool bModVtxCol; - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } + + bool bModVtxCol = detail::IsModulateVertexColor(nullptr, alpha); + if (frame[0].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[0].pMaterial->SetupGX(bModVtxCol, alpha); + GetLTFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetLTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[0].pMaterial, 0), frame[0].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } + + if (frame[1].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[1].pMaterial->SetupGX(bModVtxCol, alpha); + GetRTFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetRTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[1].pMaterial, 0), frame[1].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } + + if (frame[3].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[3].pMaterial->SetupGX(bModVtxCol, alpha); + GetRBFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetRBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[3].pMaterial, 0), frame[3].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } + + if (frame[2].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[2].pMaterial->SetupGX(bModVtxCol, alpha); + GetLBFrameSize(&polPt, &polSize, basePt, mSize, frameSize); + GetLBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[2].pMaterial, 0), frame[2].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(polPt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } } +/** +----> +x + * LT T RT | + * v v v v + * +-------+-----------------+-------+ ^ -y + * | | ^ | | | VTX: (x, y) + * | | t | | | base = (x, y) + * | | v | | | LT = ( x , y ) | L = ( x , y - t ) + * L->+-------+-----------------+-------+ | RT = ( x + w - r , y ) | R = ( x + w - r , y - t ) + * | | ^| | | LB = ( y - h + b , y - h + b ) | T = ( x + l , y ) + * | | R| | | RB = ( x + w - r , y - h + b ) | B = ( x + l , y - h + b ) + * |<- l ->| |<- r ->| h + * | | | | | SIZE: (w, h) + * | |B RB| | | LT = ( l , t ) | L = ( l , h - t - b ) + * | |V V| | | RT = ( r , t ) | R = ( r , h - t - b ) + * LB->+-------+-----------------+-------+ | LB = ( l , b ) | T = ( w - l - r , t ) + * | | ^ | | | RB = ( r , b ) | B = ( w - l - r , b ) + * | | b | | | + * | | v | | | + * +-------+-----------------+-------+ v + * <--------------- w ---------------> + */ + // DrawFrame8__Q34nw4r3lyt6WindowFRCQ34nw4r4math4VEC2PCQ44nw4r3lyt6Window5FrameRCQ34nw4r3lyt15WindowFrameSizeUc void Window::DrawFrame8(const math::VEC2 &basePt, const Frame *frame, const WindowFrameSize &frameSize, u8 alpha) { ut::Color vtxColors[4]; detail::TexCoordData texCds[1]; - math::VEC2 polPt; Size polSize; - bool bModVtxCol; - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } - { bool bUseVtxCol; } + + bool bModVtxCol = detail::IsModulateVertexColor(nullptr, alpha); + // TOP LEFT + if (frame[0].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[0].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.l, frameSize.t); + GetLTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[0].pMaterial, 0), frame[0].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(basePt, polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } + // TOP + if (frame[6].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[6].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(mSize.width - frameSize.l - frameSize.r, frameSize.t); + GetLTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[6].pMaterial, 0), frame[6].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x + frameSize.l, basePt.y), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } + // TOP RIGHT + if (frame[1].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[1].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.r, frameSize.t); + GetRTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[1].pMaterial, 0), frame[1].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x + mSize.width - frameSize.r, basePt.y), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } + // RIGHT + if (frame[5].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[5].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.r, mSize.height - frameSize.t - frameSize.b); + GetRTTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[5].pMaterial, 0), frame[5].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x + mSize.width - frameSize.r, basePt.y - frameSize.t), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } + // BOTTOM RIGHT + if (frame[3].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[3].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.r, frameSize.b); + GetRBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[3].pMaterial, 0), frame[3].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x + mSize.width - frameSize.r, basePt.y - mSize.height + frameSize.b), + polSize, 1, texCds, bUseVtxCol ? vtxColors : nullptr, alpha); + } + // BOTTOM + if (frame[7].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[7].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(mSize.width - frameSize.l - frameSize.r, frameSize.b); + GetRBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[7].pMaterial, 0), frame[7].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x + frameSize.l, basePt.y - mSize.height + frameSize.b), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } + // BOTTOM LEFT + if (frame[2].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[2].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.l, frameSize.b); + GetLBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[2].pMaterial, 0), frame[2].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x, basePt.y - mSize.height + frameSize.b), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } + // LEFT + if (frame[4].pMaterial->GetTextureNum() != 0) { + bool bUseVtxCol = frame[4].pMaterial->SetupGX(bModVtxCol, alpha); + polSize = Size(frameSize.l, mSize.height - frameSize.t - frameSize.b); + GetLBTexCoord(texCds[0], polSize, detail::GetTextureSize(frame[4].pMaterial, 0), frame[4].textureFlip); + detail::SetVertexFormat(bUseVtxCol, 1); + detail::DrawQuad(math::VEC2(basePt.x, basePt.y - frameSize.t), polSize, 1, texCds, + bUseVtxCol ? vtxColors : nullptr, alpha); + } } // GetFrameSize__Q34nw4r3lyt6WindowFUcPCQ44nw4r3lyt6Window5Frame WindowFrameSize Window::GetFrameSize(u8 frameNum, const Frame *frames) { - { Size texSize; } - { Size texSize; } + WindowFrameSize ret = {0.0f, 0.0f, 0.0f, 0.0f}; + switch (frameNum) { + case 1: { + Size texSize = detail::GetTextureSize(frames[0].pMaterial, 0); + ret.l = texSize.width; + ret.t = texSize.height; + ret.r = texSize.width; + ret.b = texSize.height; + } break; + case 4: + case 8: { + Size texSize = detail::GetTextureSize(frames[0].pMaterial, 0); + ret.l = texSize.width; + ret.t = texSize.height; + texSize = detail::GetTextureSize(frames[3].pMaterial, 0); + ret.r = texSize.width; + ret.b = texSize.height; + } break; + } + return ret; } // GetMaterialNum__Q34nw4r3lyt6WindowCFv -u8 Window::GetMaterialNum() const {} +u8 Window::GetMaterialNum() const { + return mFrameNum + 1; +} // GetMaterial__Q34nw4r3lyt6WindowCFUl -Material *Window::GetMaterial(u32 idx) const {} +Material *Window::GetMaterial(u32 idx) const { + if (idx == 0) { + return GetContentMaterial(); + } else { + return GetFrameMaterial(idx - 1); + } +} // GetFrameMaterial__Q34nw4r3lyt6WindowCFUl -Material *Window::GetFrameMaterial(u32 frameIdx) const {} +Material *Window::GetFrameMaterial(u32 frameIdx) const { + if (frameIdx >= mFrameNum) { + return nullptr; + } + return mFrames[frameIdx].pMaterial; +} // GetContentMaterial__Q34nw4r3lyt6WindowCFv -Material *Window::GetContentMaterial() const {} +Material *Window::GetContentMaterial() const { + return reinterpret_cast(this)->GetMaterial(); +} } // namespace lyt From b9b7f68da78eedf1bdd7e174425cd4642da3af0e Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Fri, 31 May 2024 20:28:32 -0400 Subject: [PATCH 12/22] lyt_bounding OK --- config/SOUE01/splits.txt | 6 ++++++ config/SOUE01/symbols.txt | 6 +++--- configure.py | 1 + include/nw4r/lyt/lyt_bounding.h | 4 ++-- src/nw4r/lyt/lyt_bounding.cpp | 22 ++++++++++++++++++++++ src/nw4r/lyt/lyt_textBox.cpp | 3 ++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index bb8bd418..80040998 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -360,6 +360,12 @@ nw4r/lyt/lyt_window.cpp: .sbss start:0x80576710 end:0x80576714 .sdata2 start:0x8057F268 end:0x8057F280 +nw4r/lyt/lyt_bounding.cpp: + .text start:0x8048D700 end:0x8048D7CC + .ctors start:0x804DB984 end:0x804DB988 + .data start:0x8056E6C0 end:0x8056E734 + .sbss start:0x80576718 end:0x8057671C + 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 a4c11e15..fa3fc80e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -25968,7 +25968,7 @@ __ct__Q34nw4r3lyt8BoundingFPCQ44nw4r3lyt3res8BoundingRCQ34nw4r3lyt11ResBlockSet __dt__Q34nw4r3lyt8BoundingFv = .text:0x8048D740; // type:function size:0x58 DrawSelf__Q34nw4r3lyt8BoundingFRCQ34nw4r3lyt8DrawInfo = .text:0x8048D7A0; // type:function size:0x4 GetRuntimeTypeInfo__Q34nw4r3lyt8BoundingCFv = .text:0x8048D7B0; // type:function size:0x8 scope:weak -__sinit_lyt_bounding_cpp = .text:0x8048D7C0; // type:function size:0xC +__sinit_\lyt_bounding_cpp = .text:0x8048D7C0; // type:function size:0xC scope:local CalcTextureMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r4math5MTX34RCQ34nw4r3lyt6TexSRT = .text:0x8048D7D0; // type:function size:0x108 SetIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@F14_GXIndTexMtxIDPA3_Cf = .text:0x8048D8E0; // type:function size:0x200 __as__Q34nw4r4math4VEC2FRCQ34nw4r4math4VEC2 = .text:0x8048DAE0; // type:function size:0x14 @@ -37079,7 +37079,7 @@ __vt__Q34nw4r3lyt7Picture = .data:0x8056E4F8; // type:object size:0x78 __vt__Q34nw4r3lyt7TextBox = .data:0x8056E570; // type:object size:0x84 @LOCAL@GetTextureFlipInfo__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FUc@flipInfos = .data:0x8056E5F8; // type:object size:0x3C __vt__Q34nw4r3lyt6Window = .data:0x8056E634; // type:object size:0x8C -lbl_8056E6C0 = .data:0x8056E6C0; // type:object size:0x78 +__vt__Q34nw4r3lyt8Bounding = .data:0x8056E6C0; // type:object size:0x74 lbl_8056E738 = .data:0x8056E738; // type:object size:0x20 data:4byte lbl_8056E758 = .data:0x8056E758; // type:object size:0x20 data:4byte lbl_8056E778 = .data:0x8056E778; // type:object size:0x30 @@ -40880,7 +40880,7 @@ mspAllocator__Q34nw4r3lyt6Layout = .sbss:0x805766F8; // type:object size:0x4 dat typeInfo__Q34nw4r3lyt7Picture = .sbss:0x80576700; // type:object size:0x4 data:4byte typeInfo__Q34nw4r3lyt7TextBox = .sbss:0x80576708; // type:object size:0x4 data:4byte typeInfo__Q34nw4r3lyt6Window = .sbss:0x80576710; // type:object size:0x4 data:4byte -lbl_80576718 = .sbss:0x80576718; // type:object size:0x4 data:4byte +typeInfo__Q34nw4r3lyt8Bounding = .sbss:0x80576718; // type:object size:0x4 data:4byte @GUARD@SetSize__Q44nw4r3lyt6detail11TexCoordAryFUc@texCoords = .sbss:0x80576720; // type:object size:0x1 data:byte lbl_80576728 = .sbss:0x80576728; // type:object size:0x8 data:byte lbl_80576730 = .sbss:0x80576730; // type:object size:0x8 data:byte diff --git a/configure.py b/configure.py index e81a6cdc..1cef6782 100644 --- a/configure.py +++ b/configure.py @@ -359,6 +359,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_picture.cpp"), Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), Object(Matching, "nw4r/lyt/lyt_window.cpp"), + Object(Matching, "nw4r/lyt/lyt_bounding.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_bounding.h b/include/nw4r/lyt/lyt_bounding.h index 323e768a..3e334bc0 100644 --- a/include/nw4r/lyt/lyt_bounding.h +++ b/include/nw4r/lyt/lyt_bounding.h @@ -10,10 +10,10 @@ namespace lyt { class Bounding : public Pane { public: - Bounding(const res::Bounding *, const ResBlockSet &); + Bounding(const res::Bounding *pBlock, const ResBlockSet &); virtual ~Bounding(); NW4R_UT_RTTI_DECL(Bounding); - virtual void DrawSelf(const DrawInfo &); + virtual void DrawSelf(const DrawInfo &drawInfo); }; } // namespace lyt } // namespace nw4r diff --git a/src/nw4r/lyt/lyt_bounding.cpp b/src/nw4r/lyt/lyt_bounding.cpp index e69de29b..296d22f4 100644 --- a/src/nw4r/lyt/lyt_bounding.cpp +++ b/src/nw4r/lyt/lyt_bounding.cpp @@ -0,0 +1,22 @@ +#include + +namespace nw4r { + +namespace lyt { + +NW4R_UT_RTTI_DEF_DERIVED(Bounding, Pane); + +// __ct__Q34nw4r3lyt8BoundingFPCQ44nw4r3lyt3res8BoundingRCQ34nw4r3lyt11ResBlockSet +Bounding::Bounding(const res::Bounding *pBlock, const ResBlockSet &) : Pane(pBlock) {} + +// __dt__Q34nw4r3lyt8BoundingFv +Bounding::~Bounding() {} + +// DrawSelf__Q34nw4r3lyt8BoundingFRCQ34nw4r3lyt8DrawInfo +void Bounding::DrawSelf(const DrawInfo &drawInfo) { + return; +} + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_textBox.cpp b/src/nw4r/lyt/lyt_textBox.cpp index 6ce2e7fc..3dba86db 100644 --- a/src/nw4r/lyt/lyt_textBox.cpp +++ b/src/nw4r/lyt/lyt_textBox.cpp @@ -280,7 +280,8 @@ void TextBox::SetVtxColorElement(u32 idx, u8 value) { // 1] IDK which one is accurate, both symbols exist // GetTextDrawRect__Q34nw4r3lyt7TextBoxCFv ut::Rect TextBox::GetTextDrawRect() const { - return GetTextDrawRect(&ut::TextWriterBase()); + ut::TextWriterBase temp; + return GetTextDrawRect(&temp); } // 2] IDK which one is accurate, both symbols exist From fa4ce249a19c6d82280f712aa8aed142801148de Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 1 Jun 2024 02:09:53 -0400 Subject: [PATCH 13/22] Templated out lyt_material --- config/SOUE01/splits.txt | 4 + config/SOUE01/symbols.txt | 2 +- configure.py | 1 + include/nw4r/lyt/lyt_material.h | 39 ++- include/nw4r/lyt/lyt_resources.h | 124 +++++++-- include/nw4r/lyt/lyt_types.h | 371 ++++++++++++++++++++++++-- src/nw4r/lyt/lyt_material.cpp | 429 +++++++++++++++++++++++++++++++ 7 files changed, 920 insertions(+), 50 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 80040998..f0672a3f 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -366,6 +366,10 @@ nw4r/lyt/lyt_bounding.cpp: .data start:0x8056E6C0 end:0x8056E734 .sbss start:0x80576718 end:0x8057671C +nw4r/lyt/lyt_material.cpp: + .text start:0x8048D7D0 end:0x804905D0 + .data start:0x8056E738 end:0x8056E7A8 + 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 fa3fc80e..e08f5331 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -25997,7 +25997,7 @@ __as__Q34nw4r3lyt11TexCoordGenFRCQ34nw4r3lyt11TexCoordGen = .text:0x8048E320; // __as__Q34nw4r3lyt8ChanCtrlFRCQ34nw4r3lyt8ChanCtrl = .text:0x8048E350; // type:function size:0x24 __as__Q34nw4r2ut5ColorFRCQ34nw4r2ut5Color = .text:0x8048E380; // type:function size:0x24 __as__Q34nw4r3lyt11TevSwapModeFRCQ34nw4r3lyt11TevSwapMode = .text:0x8048E3B0; // type:function size:0xC -__as__Q34nw4r3lyt6TexSRTFRCQ34nw4r3lyt6TexSR = .text:0x8048E3C0; // type:function size:0x2C +__as__Q34nw4r3lyt6TexSRTFRCQ34nw4r3lyt6TexSRT = .text:0x8048E3C0; // type:function size:0x2C __as__Q34nw4r3lyt13IndirectStageFRCQ34nw4r3lyt13IndirectStage = .text:0x8048E3F0; // type:function size:0x24 __as__Q34nw4r3lyt8TevStageFRCQ34nw4r3lyt8TevStage = .text:0x8048E420; // type:function size:0x64 __as__Q34nw4r3lyt12AlphaCompareFRCQ34nw4r3lyt12AlphaCompare = .text:0x8048E490; // type:function size:0x24 diff --git a/configure.py b/configure.py index 1cef6782..8f362118 100644 --- a/configure.py +++ b/configure.py @@ -360,6 +360,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), Object(Matching, "nw4r/lyt/lyt_window.cpp"), Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), + Object(NonMatching, "nw4r/lyt/lyt_material.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_material.h b/include/nw4r/lyt/lyt_material.h index 970fe84f..94b2110f 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -12,7 +12,35 @@ namespace lyt { class Material { public: - Material(const res::Material *pResMat, const ResBlockSet &ResBlockSet); + Material(const res::Material *pRes, const ResBlockSet &resBlockSet); + + void Init(); + static void InitBitGXNums(detail::BitGXNums *ptr); + void ReserveGXMem(u8 texMapNum, u8 texSRTNum, u8 texCoordGenNum, u8 tevStageNum, bool allocTevSwap, u8 indStageNum, + u8 indSRTNum, bool allocChanCtrl, bool allocMatCol, bool allocAlpComp, bool allocBlendMode); + + TexMap *GetTexMapAry() const; + TexMap *GetTexMapAry(); + TexSRT *GetTexSRTAry() const; + TexSRT *GetTexSRTAry(); + TexCoordGen *GetTexCoordGenAry() const; + TexCoordGen *GetTexCoordGenAry(); + ChanCtrl *GetChanCtrlAry(); + ut::Color *GetMatColAry(); + TevSwapMode *GetTevSwapAry(); + AlphaCompare *GetAlphaComparePtr(); + BlendMode *GetBlendModePtr(); + IndirectStage *GetIndirectStageAry(); + TexSRT *GetIndTexSRTAry(); + TevStage *GetTevStageAry(); + void SetName(const char *name); + void SetTextureNum(u8 val); + void SetTexCoordGenNum(u8 val); + void SetTevStageNum(u8 val); + void SetIndStageNum(u8 val); + void SetColorElement(u32 colorType, s16 value); + void AddAnimationLink(AnimationLink *pAnimationLink); + // IsBlendModeCap__Q34nw4r3lyt8MaterialCFv bool IsBlendModeCap() const { return mGXMemCap.blendMode; @@ -75,11 +103,6 @@ public: u8 GetTextureNum() const { return mGXMemNum.texMap; } - void SetTextureNum(u8 val); - void SetTexCoordGenNum(u8 val); - TexMap *GetTexMapAry() const; - TexMap *GetTexMapAry(); - TexCoordGen *GetTexCoordGenAry(); GXColorS10 GetTevColor(u32 idx) const { return mTevCols[idx]; @@ -112,8 +135,8 @@ private: ut::LinkList mAnimList; // at 0x4 GXColorS10 mTevCols[3]; // at 0x10 ut::Color mTevKCols[4]; // at 0x28 - BitGXNums mGXMemCap; // at 0x38 - BitGXNums mGXMemNum; // at 0x3C + detail::BitGXNums mGXMemCap; // at 0x38 + detail::BitGXNums mGXMemNum; // at 0x3C void *mpGXMem; // at 0x40 char mName[MATERIAL_NAME_SIZE + 1]; // at 0x44 bool mbUserAllocated; // at 0x59 diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index a5687948..168503da 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -33,36 +33,108 @@ struct DataBlockHeader { 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 TexSRT { + math::VEC2 translate; // at 0x00 + f32 rotate; // at 0x08 + math::VEC2 scale; // at 0x0C +}; + +struct TexMap { + // GetWarpModeS__Q44nw4r3lyt3res6TexMapCFv + GXTexWrapMode GetWarpModeS() const { + return (GXTexWrapMode)wrapSflt; // TODO + } + + // GetWarpModeT__Q44nw4r3lyt3res6TexMapCFv + GXTexWrapMode GetWarpModeT() const { + return (GXTexWrapMode)wrapTflt; // TODO + } + + // GetMinFilter__Q44nw4r3lyt3res6TexMapCFv + GXTexFilter GetMinFilter() const { + u8 bitData; + return (GXTexFilter)bitData; // TODO + } + + // GetMagFilter__Q44nw4r3lyt3res6TexMapCFv + GXTexFilter GetMagFilter() const { + u8 bitData; + return (GXTexFilter)bitData; // TODO + } + u16 texIdx; // at 0x0 + u8 wrapSflt; // at 0x2 + u8 wrapTflt; // at 0x3 +}; + +struct MaterialResourceNum { + // GetTevStageNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetTevStageNum() const { + return (bits >> 18) & 0x1F; + } + + // GetIndTexStageNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetIndTexStageNum() const { + return (bits >> 15) & 0x7; + } + // GetIndTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetIndTexSRTNum() const { + return (bits >> 4) & 0xF; + } + + // HasBlendMode__Q44nw4r3lyt3res19MaterialResourceNumCFv + bool HasBlendMode() const { + return (bits >> 24) & 1; + } + + // HasAlphaCompare__Q44nw4r3lyt3res19MaterialResourceNumCFv + bool HasAlphaCompare() const { + return (bits >> 23) & 1; + } + + // HasTevSwapTable__Q44nw4r3lyt3res19MaterialResourceNumCFv + bool HasTevSwapTable() const { + return (bits >> 12) & 1; + } + + // GetMatColNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetMatColNum() const { + return (bits >> 27) & 1; + } + + // GetChanCtrlNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetChanControlNum() const { + return (bits >> 25) & 1; + } + + // GetTexCoordGenNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetTexCoordGenNum() const { + return (bits >> 8) & 0xF; + } + + // GetTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetTexSRTNum() const { + return (bits >> 13) & 0x3; + } + + // GetTexMapNum__Q44nw4r3lyt3res19MaterialResourceNumCFv + u8 GetTexMapNum() const { + return (bits >> 0) & 0xF; + } + + u32 bits; +}; +struct Material { + char name[20]; // at 0x00 + GXColorS10 tevCols[3]; // at 0x14 + GXColorS10 tevKCols[3]; // at 0x2C + MaterialResourceNum resNum; // at 0x3C }; -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" @@ -116,6 +188,12 @@ struct Font { u8 padding[3]; // at 0x5 }; +struct Texture { + u32 nameStrOffset; // at 0x0 + u8 type; // at 0x4 + u8 padding[3]; // at 0x5 +}; + struct TextureList { DataBlockHeader blockHeader; // at 0x00 u16 texNum; // at 0x08 diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 31f75a7f..563b0689 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -8,6 +8,20 @@ namespace nw4r { namespace lyt { namespace detail { +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; +}; + template inline bool TestBit(T bits, int index) { T mask = 1 << index; @@ -19,10 +33,17 @@ inline void SetBit(T *bits, int pos, bool val) { *bits = T((*bits & ~mask)) | (val << pos); } +template +T GetBits(T bits, int pos, int len) { + u32 mask = T(1 << pos); + return bits & mask; +} + template T *ConvertOffsToPtr(const void *baseAddress, unsigned int offset) { return (T *)((u32)baseAddress + offset); } + } // namespace detail struct Size { Size() : width(), height() {} @@ -135,17 +156,17 @@ struct TexCoordGen { } // GetTexGenType__Q34nw4r3lyt11TexCoordGenCFv - u8 GetTexGenType() const { - return texGenType; + GXTexGenType GetTexGenType() const { + return (GXTexGenType)texGenType; } // GetTexGenSrc__Q34nw4r3lyt11TexCoordGenCFv - u8 GetTexGenSrc() const { - return texGenSrc; + GXTexGenSrc GetTexGenSrc() const { + return (GXTexGenSrc)texGenSrc; } // GetTexMtx__Q34nw4r3lyt11TexCoordGenCFv - u8 GetTexMtx() const { + u32 GetTexMtx() const { return texMtx; } @@ -156,9 +177,23 @@ struct TexCoordGen { }; struct ChanCtrl { // 17552 // __ct__Q34nw4r3lyt8ChanCtrlFv + ChanCtrl() {} + // Set__Q34nw4r3lyt8ChanCtrlF11_GXColorSrc11_GXColorSrc + void Set(GXColorSrc colSrc, GXColorSrc alpSrc) { + matSrcCol = colSrc; + matSrcAlp = alpSrc; + } + // GetColorSrc__Q34nw4r3lyt8ChanCtrlCFv + GXColorSrc GetColorSrc() const { + return (GXColorSrc)matSrcCol; + } + // GetAlphaSrc__Q34nw4r3lyt8ChanCtrlCFv + GXColorSrc GetAlphaSrc() const { + return (GXColorSrc)matSrcAlp; + } u8 matSrcCol; // at 0x0 u8 matSrcAlp; // at 0x1 @@ -166,26 +201,37 @@ struct ChanCtrl { // 17552 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 + BlendMode() {} + // Set__Q34nw4r3lyt9BlendModeF12_GXBlendMode14_GXBlendFactor14_GXBlendFactor10_GXLogicOp + void Set(GXBlendMode aType, GXBlendFactor srcFactor, GXBlendFactor destFactor, GXLogicOp aOp) { + type = aType; + srcFactor = srcFactor; + dstFactor = destFactor; + op = aOp; + } + // GetType__Q34nw4r3lyt9BlendModeCFv + GXBlendMode GetType() const { + return GXBlendMode(type); + } + // GetSrcFactor__Q34nw4r3lyt9BlendModeCFv + GXBlendFactor GetSrcFactor() const { + return (GXBlendFactor)srcFactor; + } + // GetDstFactor__Q34nw4r3lyt9BlendModeCFv + GXBlendFactor GetDstFactor() const { + return (GXBlendFactor)dstFactor; + } + // GetOp__Q34nw4r3lyt9BlendModeCFv + GXLogicOp GetOp() const { + return (GXLogicOp)op; + } u8 type; // at 0x0 u8 srcFactor; // at 0x1 @@ -195,12 +241,35 @@ struct BlendMode { // 10c41 struct AlphaCompare { // 17457 // __ct__Q34nw4r3lyt12AlphaCompareFv + AlphaCompare() {} + // Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc + void Set(GXCompare aComp0, u8 aRef0, GXAlphaOp aOp, GXCompare aComp1, u8 aRef1) {} + // GetComp0__Q34nw4r3lyt12AlphaCompareCFv + GXCompare GetComp0() const { + // return (GXCompare) + } + // GetRef0__Q34nw4r3lyt12AlphaCompareCFv + u8 GetRef0() const { + return ref0; + } + // GetOp__Q34nw4r3lyt12AlphaCompareCFv + GXAlphaOp GetOp() const { + return (GXAlphaOp)op; + } + // GetComp1__Q34nw4r3lyt12AlphaCompareCFv + GXCompare GetComp1() const { + // return (GXCompare) + } + // GetRef1__Q34nw4r3lyt12AlphaCompareCFv + u8 GetRef1() const { + return ref1; + } u8 comp; // at 0x0 u8 op; // at 0x1 @@ -209,11 +278,35 @@ struct AlphaCompare { // 17457 }; struct IndirectStage { // 172da // __ct__Q34nw4r3lyt13IndirectStageFv + IndirectStage() {} + // Set__Q34nw4r3lyt13IndirectStageF13_GXTexCoordID11_GXTexMapID14_GXIndTexScale14_GXIndTexScale + void Set(GXTexCoordID aTexCoordGen, GXTexMapID aTexMap, GXIndTexScale aScaleS, GXIndTexScale aScaleT) { + texCoordGen = aTexCoordGen; + texMap = aTexMap; + scaleS = aScaleS; + scaleT = aScaleT; + } + // GetTexCoordGen__Q34nw4r3lyt13IndirectStageCFv + GXTexCoordID GetTexCoordGen() const { + return (GXTexCoordID)texCoordGen; + } + // GetTexMap__Q34nw4r3lyt13IndirectStageCFv + GXTexMapID GetTexMap() const { + return (GXTexMapID)texMap; + } + // GetScaleS__Q34nw4r3lyt13IndirectStageCFv + GXIndTexScale GetScaleS() const { + return (GXIndTexScale)scaleS; + } + // GetScaleT__Q34nw4r3lyt13IndirectStageCFv + GXIndTexScale GetScaleT() const { + return (GXIndTexScale)scaleT; + } u8 texCoordGen; // at 0x0 u8 texMap; // at 0x1 @@ -230,64 +323,284 @@ struct TexSRT { // 17243 struct TevStageInOp { // 16fe7 // GetA__Q34nw4r3lyt12TevStageInOpCFv + u8 GetA() const { + return ab; // TODO + } + // GetB__Q34nw4r3lyt12TevStageInOpCFv + u8 GetB() const { + return ab; // TODO + } + // GetC__Q34nw4r3lyt12TevStageInOpCFv + u8 GetC() const { + return cd; // TODO + } + // GetD__Q34nw4r3lyt12TevStageInOpCFv + u8 GetD() const { + return cd; // TODO + } + // GetOp__Q34nw4r3lyt12TevStageInOpCFv + u8 GetOp() const { + return op; // TODO + } + // GetBias__Q34nw4r3lyt12TevStageInOpCFv + u8 GetBias() const { + return op; // TODO + } + // GetScale__Q34nw4r3lyt12TevStageInOpCFv + u8 GetScale() const { + return op; // TODO + } + // IsClamp__Q34nw4r3lyt12TevStageInOpCFv + bool IsClamp() const { + return cl; // TODO + } + // GetOutReg__Q34nw4r3lyt12TevStageInOpCFv + u8 GetOutReg() const { + return op; // TODO + } + // GetKSel__Q34nw4r3lyt12TevStageInOpCFv + u8 GetKSel() const { + return cl; // TODO + } + + // SetIn__Q34nw4r3lyt12TevStageInOpFUcUcUcUc + void SetIn(u8 a, u8 b, u8 c, u8 d) {} + // SetOp__Q34nw4r3lyt12TevStageInOpFUcUcUcbUcUc + void SetOp(u8 aOp, u8 bias, u8 scale, bool clamp, u8 outReg, u8 kSel) {} u8 ab; // at 0x0 u8 cd; // at 0x1 u8 op; // at 0x2 u8 cl; // at 0x3 }; + struct TevStage { // 17094 // __ct__Q34nw4r3lyt8TevStageFv + TevStage() {} + // GetTexCoordGen__Q34nw4r3lyt8TevStageCFv + GXTexCoordID GetTexCoordGen() const { + return (GXTexCoordID)texCoordGen; + } + // GetTexMap__Q34nw4r3lyt8TevStageCFv + GXTexMapID GetTexMap() const { + return (GXTexMapID)texMap; + } + // GetColorChan__Q34nw4r3lyt8TevStageCFv + GXChannelID GetColorChan() const { + return (GXChannelID)colChan; + } + // GetRasSwapSel__Q34nw4r3lyt8TevStageCFv + GXTevSwapSel GetRasSwapSel() const { + return (GXTevSwapSel)swapSel; // TODO + } + // GetTexSwapSel__Q34nw4r3lyt8TevStageCFv + GXTevSwapSel GetTexSwapSel() const { + return (GXTevSwapSel)swapSel; // TODO + } + // GetColorInA__Q34nw4r3lyt8TevStageCFv + GXTevColorArg GetColorInA() const { + return (GXTevColorArg)colIn.GetA(); + } + // GetColorInB__Q34nw4r3lyt8TevStageCFv + GXTevColorArg GetColorInB() const { + return (GXTevColorArg)colIn.GetB(); + } + // GetColorInC__Q34nw4r3lyt8TevStageCFv + GXTevColorArg GetColorInC() const { + return (GXTevColorArg)colIn.GetC(); + } + // GetColorInD__Q34nw4r3lyt8TevStageCFv + GXTevColorArg GetColorInD() const { + return (GXTevColorArg)colIn.GetD(); + } + // GetColorOp__Q34nw4r3lyt8TevStageCFv + GXTevOp GetColorOp() const { + return (GXTevOp)colIn.GetOp(); + } + // GetColorBias__Q34nw4r3lyt8TevStageCFv + GXTevBias GetColorBias() const { + return (GXTevBias)colIn.GetBias(); + } + // GetColorScale__Q34nw4r3lyt8TevStageCFv + GXTevScale GetColorScale() const { + return (GXTevScale)colIn.GetScale(); + } + // IsColorClamp__Q34nw4r3lyt8TevStageCFv + bool IsColorClamp() const { + return colIn.IsClamp(); + } + // GetColorOutReg__Q34nw4r3lyt8TevStageCFv + GXTevRegID GetColorOutReg() const { + return (GXTevRegID)colIn.GetOutReg(); + } + // GetKColorSel__Q34nw4r3lyt8TevStageCFv + GXTevKColorSel GetKColorSel() const { + return (GXTevKColorSel)colIn.GetKSel(); + } + // GetAlphaInA__Q34nw4r3lyt8TevStageCFv + GXTevAlphaArg GetAlphaInA() const { + return (GXTevAlphaArg)alpIn.GetA(); + } + // GetAlphaInB__Q34nw4r3lyt8TevStageCFv + GXTevAlphaArg GetAlphaInB() const { + return (GXTevAlphaArg)alpIn.GetB(); + } + // GetAlphaInC__Q34nw4r3lyt8TevStageCFv + GXTevAlphaArg GetAlphaInC() const { + return (GXTevAlphaArg)alpIn.GetC(); + } + // GetAlphaInD__Q34nw4r3lyt8TevStageCFv + GXTevAlphaArg GetAlphaInD() const { + return (GXTevAlphaArg)alpIn.GetD(); + } + // GetAlphaOp__Q34nw4r3lyt8TevStageCFv + GXTevOp GetAlphaOp() const { + return (GXTevOp)alpIn.GetOp(); + } + // GetAlphaBias__Q34nw4r3lyt8TevStageCFv + GXTevBias GetAlphaBias() const { + return (GXTevBias)alpIn.GetBias(); + } + // GetAlphaScale__Q34nw4r3lyt8TevStageCFv + GXTevScale GetAlphaScale() const { + return (GXTevScale)alpIn.GetScale(); + } + // IsAlphaClamp__Q34nw4r3lyt8TevStageCFv + bool IsAlphaClamp() const { + return alpIn.IsClamp(); + } + // GetAlphaOutReg__Q34nw4r3lyt8TevStageCFv + GXTevRegID GetAlphaOutReg() const { + return (GXTevRegID)alpIn.GetOutReg(); + } + // GetKAlphaSel__Q34nw4r3lyt8TevStageCFv + GXTevKAlphaSel GetKAlphaSel() const { + return (GXTevKAlphaSel)alpIn.GetKSel(); + } + // GetIndMtxSel__Q34nw4r3lyt8TevStageCFv + GXIndTexMtxID GetIndMtxSel() const { + return (GXIndTexMtxID)inBiMt; // TODO + } + // GetIndStage__Q34nw4r3lyt8TevStageCFv + GXIndTexStageID GetIndStage() const { + return (GXIndTexStageID)indStage; + } + // GetIndFormat__Q34nw4r3lyt8TevStageCFv + GXIndTexFormat GetIndFormat() const { + return (GXIndTexFormat)indFoAdUtAl; // TODO + } + // GetIndBiasSel__Q34nw4r3lyt8TevStageCFv + GXIndTexBiasSel GetIndBiasSel() const { + return (GXIndTexBiasSel)inBiMt; // TODO + } + // GetIndWrapS__Q34nw4r3lyt8TevStageCFv + GXIndTexWrap GetIndWrapS() const { + return (GXIndTexWrap)indWrap; // TODO + } + // GetIndWrapT__Q34nw4r3lyt8TevStageCFv + GXIndTexWrap GetIndWrapT() const { + return (GXIndTexWrap)indWrap; // TODO + } + // IsIndAddPrev__Q34nw4r3lyt8TevStageCFv + bool IsIndAddPrev() const { + return indFoAdUtAl; // TODO + } + // IsIndUtcLod__Q34nw4r3lyt8TevStageCFv + bool IsIndUtcLod() const { + return indFoAdUtAl; // TODO + } + // GetIndAlphaSel__Q34nw4r3lyt8TevStageCFv + GXIndTexAlphaSel GetIndAlphaSel() const { + return (GXIndTexAlphaSel)indFoAdUtAl; // TODO + } + // SetOrder__Q34nw4r3lyt8TevStageF13_GXTexCoordID11_GXTexMapID12_GXChannelID13_GXTevSwapSel13_GXTevSwapSel + void SetOrder(GXTexCoordID aTexCoordGen, GXTexMapID aTexMap, GXChannelID aColChan, GXTevSwapSel rasSel, + GXTevSwapSel texSel) { + texCoordGen = aTexCoordGen; + colChan = aColChan; + texMap = aTexMap; + swapSel = rasSel; // TODO + swapSel = texSel; // TODO + } + // SetColorIn__Q34nw4r3lyt8TevStageF14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg + void SetColorIn(GXTevColorArg a, GXTevColorArg b, GXTevColorArg c, GXTevColorArg d) { + colIn.SetIn(a, b, c, d); + } + // SetAlphaIn__Q34nw4r3lyt8TevStageF14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg + void SetAlphaIn(GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c, GXTevAlphaArg d) { + alpIn.SetIn(a, b, c, d); + } + // SetColorOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKColorSel + void SetColorOp(GXTevOp op, GXTevBias bias, GXTevScale scale, bool clamp, GXTevRegID outReg, GXTevKColorSel kSel) { + colIn.SetOp(op, bias, scale, clamp, outReg, kSel); + } + // SetAlphaOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKAlphaSel + void SetAlphaOp(GXTevOp op, GXTevBias bias, GXTevScale scale, bool clamp, GXTevRegID outReg, GXTevKAlphaSel kSel) { + alpIn.SetOp(op, bias, scale, clamp, outReg, kSel); + } + // SetIndirect__Q34nw4r3lyt8TevStageF16_GXIndTexStageID15_GXIndTexFormat16_GXIndTexBiasSel14_GXIndTexMtxID13_GXIndTexWrap13_GXIndTexWrapbb17_GXIndTexAlphaSel + void SetIndirect(GXIndTexStageID stage, GXIndTexFormat format, GXIndTexBiasSel bias, GXIndTexMtxID mtxSel, + GXIndTexWrap wrapS, GXIndTexWrap wrapT, bool addPrev, bool utcLod, GXIndTexAlphaSel alphaSel) { + indStage = stage; + indFoAdUtAl = format; // TODO + inBiMt = bias; // TODO + inBiMt = mtxSel; // TODO + indWrap = wrapS; // TODO + indWrap = wrapT; // TODO + indFoAdUtAl = addPrev; // TODO + indFoAdUtAl = utcLod; // TODO + indFoAdUtAl = alphaSel; // TODO + } u8 texCoordGen; // at 0x0 u8 colChan; // at 0x1 @@ -304,10 +617,32 @@ struct TevStage { // 17094 struct TevSwapMode { // 1750a // GetR__Q34nw4r3lyt11TevSwapModeCFv + GXTevColorChan GetR() const { + return (GXTevColorChan)swap; // TODO + } + // GetG__Q34nw4r3lyt11TevSwapModeCFv + GXTevColorChan GetG() const { + return (GXTevColorChan)swap; // TODO + } + // GetB__Q34nw4r3lyt11TevSwapModeCFv + GXTevColorChan GetB() const { + return (GXTevColorChan)swap; // TODO + } + // GetA__Q34nw4r3lyt11TevSwapModeCFv + GXTevColorChan GetA() const { + return (GXTevColorChan)swap; // TODO + } + // Set__Q34nw4r3lyt11TevSwapModeF15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan + void Set(GXTevColorChan r, GXTevColorChan g, GXTevColorChan b, GXTevColorChan a) { + swap = r; // TODO + swap = g; // TODO + swap = b; // TODO + swap = a; // TODO + } u8 swap; // at 0x0 }; diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp index 9546dd49..f151de6d 100644 --- a/src/nw4r/lyt/lyt_material.cpp +++ b/src/nw4r/lyt/lyt_material.cpp @@ -1,10 +1,439 @@ +#include + +// DefaultBlackColor +// DefaultWhiteColor + +// __eq__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRC11_GXColorS10RC11_GXColorS10 +inline bool operator==(const GXColorS10 &a, const GXColorS10 &b) { + return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a); +} + +inline bool operator!=(const GXColorS10 &a, const GXColorS10 &b) { + return (a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a); +} +namespace nw4r { +namespace lyt { + +namespace { + +// CalcTextureMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r4math5MTX34RCQ34nw4r3lyt6TexSRT +void CalcTextureMtx(math::MTX34 *pMtx, const TexSRT &texSRT) { + math::VEC2 center; + f32 cosR; + f32 sinR; + f32 a0; + f32 a1; +} + +// CalcIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPA3_fRCQ34nw4r3lyt6TexSRT +void CalcIndTexMtx(f32 (*mtx)[3], const TexSRT &texSRT) { + f32 cosR; + f32 sinR; +} + +// SetColorComponentValue__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r2ut5ColorUls +void SetColorComponentValue(ut::Color *pCol, u32 compIdx, s16 value) { + u8 u8Val; +} + +// SetIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@F14_GXIndTexMtxIDPA3_Cf +void SetIndTexMtx(GXIndTexMtxID id, const f32 (*mtx)[3]) { + f32 m00, m01, m02, m10, m11, m12, a00, a01, a02, a10, a11, a12; + s8 scaleExp; + f32 outMtx[3]; +} + +// InitTexSRT__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r3lyt6TexSRTUl +void InitTexSRT(TexSRT *texSRTs, u32 num) { + u32 i; +} + +// CalcOffsetTexSRTAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetTexSRTAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetTexCoordGenAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetTexCoordGenAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetChanCtrlAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetChanCtrlAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetMatColAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetMatColAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetTevSwapAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetTevSwapAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetGetAlphaCompare__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetGetAlphaCompare(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetBlendMode__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetBlendMode(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetIndirectStageAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetIndirectStageAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetIndTexSRTAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetIndTexSRTAry(const detail::BitGXNums &bitGXNums) {} + +// CalcOffsetTevStageAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums +u32 CalcOffsetTevStageAry(const detail::BitGXNums &bitGXNums) {} + +} // namespace + +// __ct__Q34nw4r3lyt8MaterialFPCQ44nw4r3lyt3res8MaterialRCQ34nw4r3lyt11ResBlockSet +Material::Material(const res::Material *pRes, const ResBlockSet &resBlockSet) { + { int i; } + { int i; } + u32 resOffs; + const res::TexMap *pResTexMap; + const res::TexSRT *pResTexSRTs; + const TexCoordGen *resTexCoordGen; + u8 texMapNum; + u8 texSRTNum; + u8 texCoordGenNum; + bool allocChanCtrl; + bool allocMatCol; + bool allocTevSwap; + bool allocAlpComp; + bool allocBlendMode; + u8 indTexSRTNum; + u8 indStageNum; + u8 tevStageNum; + const res::Texture *textures; + const TexMap *texMaps; + u8 di, si; + const char *fileName; + void *pTplRes; + res::TexSRT *texSRTs; + { int i; } + TexCoordGen *texCoordGens; + { int i; } + const ChanCtrl *pResChanCtrl; + ut::Color *pResMatCol; + const TevSwapMode *pResTevSwap; + const TevSwapMode *tevSwaps; + { int i; } + const TexSRT *indTexSRTs; + const TexSRT *pResIndMtx; + { int i; } + IndirectStage *indirectStages; + const IndirectStage *pResIndStg; + { int i; } + const TevStage *tevStages; + const TevStage *pResTevStg; + { int i; } + const AlphaCompare *pResAlphaCompare; + const BlendMode *pResBlendMode; +} + +// Init__Q34nw4r3lyt8MaterialFv +void Material::Init() {} + +// __dt__Q34nw4r3lyt8MaterialFv +Material::~Material() {} + +// InitBitGXNums__Q34nw4r3lyt8MaterialFPQ44nw4r3lyt6detail9BitGXNums +void Material::InitBitGXNums(detail::BitGXNums *ptr) {} + +// ReserveGXMem__Q34nw4r3lyt8MaterialFUcUcUcUcbUcUcbbbb +void Material::ReserveGXMem(u8 texMapNum, u8 texSRTNum, u8 texCoordGenNum, u8 tevStageNum, bool allocTevSwap, + u8 indStageNum, u8 indSRTNum, bool allocChanCtrl, bool allocMatCol, bool allocAlpComp, bool allocBlendMode) { + int tevSwapNum; + int chanCtrlNum; + int matColNum; + int alpCompNum; + int blendModeNum; + const TevSwapMode *tevSwaps; +} + +// GetTexMapAry__Q34nw4r3lyt8MaterialCFv +TexMap *Material::GetTexMapAry() const {} + +// GetTexMapAry__Q34nw4r3lyt8MaterialFv +TexMap *Material::GetTexMapAry() {} + +// GetTexSRTAry__Q34nw4r3lyt8MaterialFv +TexSRT *Material::GetTexSRTAry() {} + +// GetTexCoordGenAry__Q34nw4r3lyt8MaterialFv +TexCoordGen *Material::GetTexCoordGenAry() {} + +// GetChanCtrlAry__Q34nw4r3lyt8MaterialFv +ChanCtrl *Material::GetChanCtrlAry() {} + +// GetMatColAry__Q34nw4r3lyt8MaterialFv +ut::Color *Material::GetMatColAry() {} + +// GetTevSwapAry__Q34nw4r3lyt8MaterialFv +TevSwapMode *Material::GetTevSwapAry() {} + +// GetAlphaComparePtr__Q34nw4r3lyt8MaterialFv +AlphaCompare *Material::GetAlphaComparePtr() {} + +// GetBlendModePtr__Q34nw4r3lyt8MaterialFv +BlendMode *Material::GetBlendModePtr() {} + +// GetIndirectStageAry__Q34nw4r3lyt8MaterialFv +IndirectStage *Material::GetIndirectStageAry() {} + +// GetIndTexSRTAry__Q34nw4r3lyt8MaterialFv +TexSRT *Material::GetIndTexSRTAry() {} + +// GetTevStageAry__Q34nw4r3lyt8MaterialFv +TevStage *Material::GetTevStageAry() {} + +// SetName__Q34nw4r3lyt8MaterialFPCc +void Material::SetName(const char *name) {} + +// SetTextureNum__Q34nw4r3lyt8MaterialFUc +void Material::SetTextureNum(u8 num) { + TexMap *texMaps; + u32 i; +} + +// SetTexCoordGenNum__Q34nw4r3lyt8MaterialFUc +void Material::SetTexCoordGenNum(u8 num) { + TexCoordGen *texCoordGens; + u32 i; +} + +// SetTevStageNum__Q34nw4r3lyt8MaterialFUc +void Material::SetTevStageNum(u8 num) { + TevStage *tevStages; + u32 i; +} + +// SetIndStageNum__Q34nw4r3lyt8MaterialFUc +void Material::SetIndStageNum(u8 num) { + IndirectStage *indStages; + u32 i; +} + +// SetColorElement__Q34nw4r3lyt8MaterialFUls +void Material::SetColorElement(u32 colorType, s16 value) { + ut::Color *matCols; + { u32 regIdx; } + { u32 regIdx; } + GXTevKColorSel kColSels[8]; + GXTevKAlphaSel kAlpSels[8]; +} // SetupGX__Q34nw4r3lyt8MaterialFbUc +bool Material::SetupGX(bool bModVtxCol, u8 alpha) { + bool bUseVtxCol; + bool bUseMatCol; + const ChanCtrl *chanCtrls; + bool bUseRasStage; + ut::Color matCol; + bool bSetTexMtx; + bool bUseTexMtxl; + { int i; } + const TexCoordGen *texCoordGens; + { int i; } + u32 texMtx; + const TexSRT *texSRTs; + { int i; } + { math::MTX34 texMtx; } + u32 tlutID; + u32 bigTlutID; + const TexMap *texMaps; + { int i; } + // TexMap & texMap; + GXTexObj texObj; + u32 tlutName; + GXTlutObj tlutObj; + const TevSwapMode *tevSwaps; + { int i; } + bool bSetIndTexMtx; + bool bUseIndTexMtx; + { int i; } + const TevStage *tevStages; + { int i; } + GXTevStageID tevStage; + GXIndTexMtxID indMtxSel; + u8 tevStageID; + { GXTevStageID tevStage; } + { GXTevStageID tevStage; } + { GXTevStageID tevStage; } + { int i; } + { GXTevStageID tevStage; } + GXTevColorArg colDIn; + GXTevAlphaArg alpDIn; + { GXTevStageID tevStage; } + { GXTevStageID tevStage; } + u8 tevStageNum; + u8 id; + { GXTevStageID tevStage; } + const TexSRT *indTexSRTs; + { int i; } + f32 mtx[2][3]; + const IndirectStage *indirectStages; + { int i; } + GXIndTexStageID indStage; + const AlphaCompare *pAlpComp; + const BlendMode *pBlendMode; +} + +namespace { +// GetTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl +u32 GetTexMtx(u32 texMtxIdx) {} + +// GetTexMtxIdx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl +u32 GetTexMtxIdx(u32 texMtx) {} + +} // namespace + // BindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +void Material::BindAnimation(AnimTransform *pAnimTrans) {} + // UnbindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +void Material::UnbindAnimation(AnimTransform *pAnimTrans) {} + // UnbindAllAnimation__Q34nw4r3lyt8MaterialFv +void Material::UnbindAllAnimation() {} + // Animate__Q34nw4r3lyt8MaterialFv +void Material::Animate() { + ut::LinkList::Iterator it; + AnimTransform *animTrans; +} + +// AddAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimationLink +void Material::AddAnimationLink(AnimationLink *pAnimationLink) {} + // FindAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform +AnimationLink *Material::FindAnimationLink(AnimTransform *pAnimTrans) {} + // FindAnimationLink__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResource +AnimationLink *Material::FindAnimationLink(const AnimResource &animRes) {} + // SetAnimationEnable__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransformb +void Material::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) {} + // SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb +void Material::SetAnimationEnable(const AnimResource &animRes, bool bEnable) { + AnimationLink *pAnimLink; +} + +namespace detail { + +// GetTextureSize__Q34nw4r3lyt6detailFPQ34nw4r3lyt8MaterialUc +Size GetTextureSize(Material *pMaterial, u8 texMapIdx) {} + +} // namespace detail + +} // namespace lyt + +} // namespace nw4r + +// INLINED FROM OTHER FILES +// ut_inlines.h +// Min__Q34nw4r2ut26@unnamed@lyt_material_cpp@Fss_s +// Max__Q34nw4r2ut26@unnamed@lyt_material_cpp@Fss_s +// Min__Q34nw4r2ut26@unnamed@lyt_material_cpp@FUcUc_Uc + +// lyt_types.h +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt9BlendMode +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt12AlphaCompare +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt8TevStage +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt13IndirectStage +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt11TevSwapMode +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r2ut5Color +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt8ChanCtrl +// GetBits__Q34nw4r3lyt6detailFiii_i +// GetBits__Q34nw4r3lyt6detailFUcii_Uc +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ44nw4r3lyt3res7Texture +// GetBits
    __Q34nw4r3lyt6detailFUlii_Ul +// TestBit
      __Q34nw4r3lyt6detailFUli_b +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt11TexCoordGen +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt6TexSRT +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ44nw4r3lyt3res6TexMap +// __ct__Q34nw4r3lyt9BlendModeFv +// Set__Q34nw4r3lyt9BlendModeF12_GXBlendMode14_GXBlendFactor14_GXBlendFactor10_GXLogicOp +// __ct__Q34nw4r3lyt12AlphaCompareFv +// Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc +// Set__Q34nw4r3lyt11TevSwapModeF15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan +// __ct__Q34nw4r3lyt8ChanCtrlFv +// Set__Q34nw4r3lyt8ChanCtrlF11_GXColorSrc11_GXColorSrc +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt6TexMap +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt6TexSRT +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt11TexCoordGen +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt8ChanCtrl +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r2ut5Color +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt11TevSwapMode +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt12AlphaCompare +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt9BlendMode +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt13IndirectStage +// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt8TevStage +// __ct__Q34nw4r3lyt8TevStageFv +// SetIndirect__Q34nw4r3lyt8TevStageF16_GXIndTexStageID15_GXIndTexFormat16_GXIndTexBiasSel14_GXIndTexMtxID13_GXIndTexWrap13_GXIndTexWrapbb17_GXIndTexAlphaSel +// SetAlphaOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKAlphaSel +// SetOp__Q34nw4r3lyt12TevStageInOpFUcUcUcbUcUc +// SetColorOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKColorSel +// SetAlphaIn__Q34nw4r3lyt8TevStageF14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg +// SetIn__Q34nw4r3lyt12TevStageInOpFUcUcUcUc +// SetColorIn__Q34nw4r3lyt8TevStageF14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg +// SetOrder__Q34nw4r3lyt8TevStageF13_GXTexCoordID11_GXTexMapID12_GXChannelID13_GXTevSwapSel13_GXTevSwapSel +// __ct__Q34nw4r3lyt13IndirectStageFv +// Set__Q34nw4r3lyt13IndirectStageF13_GXTexCoordID11_GXTexMapID14_GXIndTexScale14_GXIndTexScale +// GetOp__Q34nw4r3lyt9BlendModeCFv +// GetDstFactor__Q34nw4r3lyt9BlendModeCFv +// GetSrcFactor__Q34nw4r3lyt9BlendModeCFv +// GetType__Q34nw4r3lyt9BlendModeCFv +// GetRef1__Q34nw4r3lyt12AlphaCompareCFv +// GetComp1__Q34nw4r3lyt12AlphaCompareCFv +// GetOp__Q34nw4r3lyt12AlphaCompareCFv +// GetRef0__Q34nw4r3lyt12AlphaCompareCFv +// GetComp0__Q34nw4r3lyt12AlphaCompareCFv +// GetScaleT__Q34nw4r3lyt13IndirectStageCFv +// GetScaleS__Q34nw4r3lyt13IndirectStageCFv +// GetTexMap__Q34nw4r3lyt13IndirectStageCFv +// GetTexCoordGen__Q34nw4r3lyt13IndirectStageCFv +// GetIndAlphaSel__Q34nw4r3lyt8TevStageCFv +// IsIndUtcLod__Q34nw4r3lyt8TevStageCFv +// IsIndAddPrev__Q34nw4r3lyt8TevStageCFv +// GetIndWrapT__Q34nw4r3lyt8TevStageCFv +// GetIndWrapS__Q34nw4r3lyt8TevStageCFv +// GetIndBiasSel__Q34nw4r3lyt8TevStageCFv +// GetIndFormat__Q34nw4r3lyt8TevStageCFv +// GetIndStage__Q34nw4r3lyt8TevStageCFv +// GetIndMtxSel__Q34nw4r3lyt8TevStageCFv +// GetKAlphaSel__Q34nw4r3lyt8TevStageCFv +// GetKSel__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaOutReg__Q34nw4r3lyt8TevStageCFv +// GetOutReg__Q34nw4r3lyt12TevStageInOpCFv +// IsAlphaClamp__Q34nw4r3lyt8TevStageCFv +// IsClamp__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaScale__Q34nw4r3lyt8TevStageCFv +// GetScale__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaBias__Q34nw4r3lyt8TevStageCFv +// GetBias__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaOp__Q34nw4r3lyt8TevStageCFv +// GetOp__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaInD__Q34nw4r3lyt8TevStageCFv +// GetD__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaInC__Q34nw4r3lyt8TevStageCFv +// GetC__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaInB__Q34nw4r3lyt8TevStageCFv +// GetB__Q34nw4r3lyt12TevStageInOpCFv +// GetAlphaInA__Q34nw4r3lyt8TevStageCFv +// GetA__Q34nw4r3lyt12TevStageInOpCFv +// GetKColorSel__Q34nw4r3lyt8TevStageCFv +// GetColorOutReg__Q34nw4r3lyt8TevStageCFv +// IsColorClamp__Q34nw4r3lyt8TevStageCFv +// GetColorScale__Q34nw4r3lyt8TevStageCFv +// GetColorBias__Q34nw4r3lyt8TevStageCFv +// GetColorOp__Q34nw4r3lyt8TevStageCFv +// GetColorInD__Q34nw4r3lyt8TevStageCFv +// GetColorInC__Q34nw4r3lyt8TevStageCFv +// GetColorInB__Q34nw4r3lyt8TevStageCFv +// GetColorInA__Q34nw4r3lyt8TevStageCFv +// GetTexSwapSel__Q34nw4r3lyt8TevStageCFv +// GetRasSwapSel__Q34nw4r3lyt8TevStageCFv +// GetColorChan__Q34nw4r3lyt8TevStageCFv +// GetTexMap__Q34nw4r3lyt8TevStageCFv +// GetTexCoordGen__Q34nw4r3lyt8TevStageCFv +// GetA__Q34nw4r3lyt11TevSwapModeCFv +// GetB__Q34nw4r3lyt11TevSwapModeCFv +// GetG__Q34nw4r3lyt11TevSwapModeCFv +// GetR__Q34nw4r3lyt11TevSwapModeCFv From c2040790a068171facb75fa980718b541205f25d Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Tue, 4 Jun 2024 22:22:44 -0400 Subject: [PATCH 14/22] lyt_material weirdness --- .vscode/settings.json | 3 +- config/SOUE01/splits.txt | 2 + config/SOUE01/symbols.txt | 10 +- include/nw4r/lyt/lyt_layout.h | 2 + include/nw4r/lyt/lyt_material.h | 18 +- include/nw4r/lyt/lyt_pane.h | 4 +- include/nw4r/lyt/lyt_resources.h | 21 +- include/nw4r/lyt/lyt_texMap.h | 97 ++- include/nw4r/lyt/lyt_types.h | 237 ++++--- include/nw4r/ut/ut_Color.h | 4 + include/rvl/GX/GXTev.h | 2 +- include/rvl/GX/GXTexture.h | 2 + include/rvl/GX/GXTypes.h | 23 + src/nw4r/lyt/lyt_material.cpp | 1118 ++++++++++++++++++++++-------- src/nw4r/lyt/lyt_pane.cpp | 6 +- 15 files changed, 1091 insertions(+), 458 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4cc6a08a..000066a6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,6 +28,7 @@ "limits": "cpp", "utility": "cpp", "initializer_list": "cpp", - "new": "cpp" + "new": "cpp", + "cstdlib": "cpp" } } diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f0672a3f..939fd8f0 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -369,6 +369,8 @@ nw4r/lyt/lyt_bounding.cpp: nw4r/lyt/lyt_material.cpp: .text start:0x8048D7D0 end:0x804905D0 .data start:0x8056E738 end:0x8056E7A8 + .sdata2 start:0x8057F280 end:0x8057F2A0 + .sbss2 start:0x8057FFB8 end:0x8057FFC0 nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index e08f5331..543d738a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26051,7 +26051,7 @@ Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj = .text:0x804905D0; // type:function size:0 Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj = .text:0x804906C0; // type:function size:0x1C Set__Q34nw4r3lyt6TexMapFPCQ34nw4r3lyt6TexMap = .text:0x804906E0; // type:function size:0x14C Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor = .text:0x80490830; // type:function size:0x74 -ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUlPCc = .text:0x804908B0; // type:function size:0xD0 +ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl = .text:0x804908B0; // type:function size:0xD0 __ct__Q34nw4r3lyt8DrawInfoFv = .text:0x80490980; // type:function size:0x74 __dt__Q34nw4r3lyt8DrawInfoFv = .text:0x80490A00; // type:function size:0x40 GetStepCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl = .text:0x80490A40; // type:function size:0xE8 @@ -37080,9 +37080,9 @@ __vt__Q34nw4r3lyt7TextBox = .data:0x8056E570; // type:object size:0x84 @LOCAL@GetTextureFlipInfo__Q34nw4r3lyt24@unnamed@lyt_window_cpp@FUc@flipInfos = .data:0x8056E5F8; // type:object size:0x3C __vt__Q34nw4r3lyt6Window = .data:0x8056E634; // type:object size:0x8C __vt__Q34nw4r3lyt8Bounding = .data:0x8056E6C0; // type:object size:0x74 -lbl_8056E738 = .data:0x8056E738; // type:object size:0x20 data:4byte -lbl_8056E758 = .data:0x8056E758; // type:object size:0x20 data:4byte -lbl_8056E778 = .data:0x8056E778; // type:object size:0x30 +@LOCAL@SetupGX__Q34nw4r3lyt8MaterialFbUc@kColSels = .data:0x8056E738; // type:object size:0x20 data:4byte +@LOCAL@SetupGX__Q34nw4r3lyt8MaterialFbUc@kAlpSels = .data:0x8056E758; // type:object size:0x20 data:4byte +__vt__Q34nw4r3lyt8Material = .data:0x8056E778; // type:object size:0x30 lbl_8056E7A8 = .data:0x8056E7A8; // type:object size:0x10 lbl_8056E7B8 = .data:0x8056E7B8; // type:object size:0x28 __vt__Q34nw4r3lyt16ResourceAccessor = .data:0x8056E7E0; // type:object size:0x14 @@ -48085,7 +48085,7 @@ lbl_8057FF90 = .sdata2:0x8057FF90; // type:object size:0x4 lbl_8057FFA0 = .sbss2:0x8057FFA0; // type:object size:0x8 data:4byte lbl_8057FFA8 = .sbss2:0x8057FFA8; // type:object size:0x8 lbl_8057FFB0 = .sbss2:0x8057FFB0; // type:object size:0x8 -lbl_8057FFB8 = .sbss2:0x8057FFB8; // type:object size:0x8 data:2byte +DefaultBlackColor = .sbss2:0x8057FFB8; // type:object size:0x8 scope:local data:2byte lbl_8057FFC0 = .sbss2:0x8057FFC0; // type:object size:0x8 data:byte lbl_8057FFC8 = .sbss2:0x8057FFC8; // type:object size:0x4 lbl_80580000 = .bss:0x80580000; // type:object size:0x14 data:4byte diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 13689a32..9cbeb585 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -1,5 +1,6 @@ #ifndef NW4R_LYT_LAYOUT_H #define NW4R_LYT_LAYOUT_H + #include "common.h" #include #include @@ -8,6 +9,7 @@ #include #include + namespace nw4r { namespace lyt { diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index 94b2110f..05a574f1 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -12,6 +12,7 @@ namespace lyt { class Material { public: + Material(); Material(const res::Material *pRes, const ResBlockSet &resBlockSet); void Init(); @@ -19,25 +20,35 @@ public: void ReserveGXMem(u8 texMapNum, u8 texSRTNum, u8 texCoordGenNum, u8 tevStageNum, bool allocTevSwap, u8 indStageNum, u8 indSRTNum, bool allocChanCtrl, bool allocMatCol, bool allocAlpComp, bool allocBlendMode); - TexMap *GetTexMapAry() const; + const TexMap *GetTexMapAry() const; TexMap *GetTexMapAry(); - TexSRT *GetTexSRTAry() const; + const TexSRT *GetTexSRTAry() const; TexSRT *GetTexSRTAry(); - TexCoordGen *GetTexCoordGenAry() const; + const TexCoordGen *GetTexCoordGenAry() const; TexCoordGen *GetTexCoordGenAry(); + const ChanCtrl *GetChanCtrlAry() const; ChanCtrl *GetChanCtrlAry(); + const ut::Color *GetMatColAry() const; ut::Color *GetMatColAry(); + const TevSwapMode *GetTevSwapAry() const; TevSwapMode *GetTevSwapAry(); + const AlphaCompare *GetAlphaComparePtr() const; AlphaCompare *GetAlphaComparePtr(); + const BlendMode *GetBlendModePtr() const; BlendMode *GetBlendModePtr(); + const IndirectStage *GetIndirectStageAry() const; IndirectStage *GetIndirectStageAry(); + const TexSRT *GetIndTexSRTAry() const; TexSRT *GetIndTexSRTAry(); + const TevStage *GetTevStageAry() const; TevStage *GetTevStageAry(); + void SetName(const char *name); void SetTextureNum(u8 val); void SetTexCoordGenNum(u8 val); void SetTevStageNum(u8 val); void SetIndStageNum(u8 val); + s16 GetColorElement(u32 colorType); void SetColorElement(u32 colorType, s16 value); void AddAnimationLink(AnimationLink *pAnimationLink); @@ -67,6 +78,7 @@ public: } // SetTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf + // GetTexturePtr__Q34nw4r3lyt8MaterialFUc // GetTexSRTCap__Q34nw4r3lyt8MaterialCFv diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index cdbce93c..54e16eea 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -101,8 +101,8 @@ public: math::VEC2 GetVtxPos() const; void CalculateMtxChild(const DrawInfo &drawInfo); u16 GetExtUserDataNum() const; - res::ExtUserData *GetExtUserData() const; - res::ExtUserData *FindExtUserDataByName(const char *name); + const res::ExtUserData *GetExtUserData() const; + const res::ExtUserData *FindExtUserDataByName(const char *name); virtual ~Pane(); // at 0x8 NW4R_UT_RTTI_DECL(Pane); // at 0x0C diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index 168503da..851c6641 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -4,6 +4,7 @@ #include #include #include +#include #define PANE_NAME_SIZE 16 #define PANE_USERDATA_SIZE 8 @@ -42,24 +43,24 @@ struct TexSRT { struct TexMap { // GetWarpModeS__Q44nw4r3lyt3res6TexMapCFv GXTexWrapMode GetWarpModeS() const { - return (GXTexWrapMode)wrapSflt; // TODO + return (GXTexWrapMode)(wrapSflt & 3); } // GetWarpModeT__Q44nw4r3lyt3res6TexMapCFv GXTexWrapMode GetWarpModeT() const { - return (GXTexWrapMode)wrapTflt; // TODO + return (GXTexWrapMode)(wrapTflt & 3); } // GetMinFilter__Q44nw4r3lyt3res6TexMapCFv GXTexFilter GetMinFilter() const { - u8 bitData; - return (GXTexFilter)bitData; // TODO + u8 bitData = (wrapSflt >> 2) & 7; + return (GXTexFilter)((bitData + 1) & 7); } // GetMagFilter__Q44nw4r3lyt3res6TexMapCFv GXTexFilter GetMagFilter() const { - u8 bitData; - return (GXTexFilter)bitData; // TODO + u8 bitData = (wrapTflt >> 2) & 1; + return (GXTexFilter)((bitData + 1) & 1); } u16 texIdx; // at 0x0 u8 wrapSflt; // at 0x2 @@ -78,7 +79,7 @@ struct MaterialResourceNum { } // GetIndTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv u8 GetIndTexSRTNum() const { - return (bits >> 4) & 0xF; + return (bits >> 13) & 0x3; } // HasBlendMode__Q44nw4r3lyt3res19MaterialResourceNumCFv @@ -102,7 +103,7 @@ struct MaterialResourceNum { } // GetChanCtrlNum__Q44nw4r3lyt3res19MaterialResourceNumCFv - u8 GetChanControlNum() const { + u8 GetChanCtrlNum() const { return (bits >> 25) & 1; } @@ -113,7 +114,7 @@ struct MaterialResourceNum { // GetTexSRTNum__Q44nw4r3lyt3res19MaterialResourceNumCFv u8 GetTexSRTNum() const { - return (bits >> 13) & 0x3; + return (bits >> 4) & 0xF; } // GetTexMapNum__Q44nw4r3lyt3res19MaterialResourceNumCFv @@ -126,7 +127,7 @@ struct MaterialResourceNum { struct Material { char name[20]; // at 0x00 GXColorS10 tevCols[3]; // at 0x14 - GXColorS10 tevKCols[3]; // at 0x2C + GXColor tevKCols[4]; // at 0x2C MaterialResourceNum resNum; // at 0x3C }; diff --git a/include/nw4r/lyt/lyt_texMap.h b/include/nw4r/lyt/lyt_texMap.h index 38a78a40..5a6609a7 100644 --- a/include/nw4r/lyt/lyt_texMap.h +++ b/include/nw4r/lyt/lyt_texMap.h @@ -14,7 +14,34 @@ inline bool IsCITexelFormat(GXTexFmt fmt) { class TexMap { public: - TexMap() {} + TexMap(TPLPalette *pTPLPalette, u32 id) { + Set(pTPLPalette, id); + } + + TexMap() { + mpImage = nullptr; + mWidth = 0; + mHeight = 0; + + mBits.textureFormat = 0; + mBits.mipmap = 0; + + mBits.wrapS = 0; + mBits.wrapT = 0; + mBits.minFilter = 1; + mBits.magFilter = 1; + + mMinLOD = 0.0f; + mMaxLOD = 0.0f; + mLODBias = 0; + mBits.biasClampEnable = 0; + mBits.edgeLODEnable = 0; + + mpPalette = nullptr; + mBits.anisotropy = 0; + mBits.paletteFormat = 0; + mPaletteEntryNum = 0; + } void Get(GXTexObj *) const; void Get(GXTlutObj *) const; @@ -79,69 +106,74 @@ public: } GXTexFmt GetTexelFormat() const { - return (GXTexFmt)mBits.mTexelFormat; + return (GXTexFmt)mBits.textureFormat; } void SetTexelFormat(GXTexFmt fmt) { - mBits.mTexelFormat = fmt; + mBits.textureFormat = fmt; } bool IsMipMap() const { - return mBits.mIsMipMap; + return mBits.mipmap; } void SetMipMap(bool b) { - mBits.mIsMipMap = b; + mBits.mipmap = b; } GXTexWrapMode GetWrapModeS() const { - return (GXTexWrapMode)mBits.mWrapModeS; + return (GXTexWrapMode)mBits.wrapS; } GXTexWrapMode GetWrapModeT() const { - return (GXTexWrapMode)mBits.mWrapModeT; + return (GXTexWrapMode)mBits.wrapT; } void SetWrapMode(GXTexWrapMode wrapS, GXTexWrapMode wrapT) { - mBits.mWrapModeS = wrapS; - mBits.mWrapModeT = wrapT; + mBits.wrapS = wrapS; + mBits.wrapT = wrapT; } GXTexFilter GetMinFilter() const { - return (GXTexFilter)mBits.mMinFilter; + return (GXTexFilter)mBits.minFilter; } GXTexFilter GetMagFilter() const { - return (GXTexFilter)mBits.mMagFilter; + return (GXTexFilter)mBits.magFilter; } void SetFilter(GXTexFilter minFlt, GXTexFilter magFlt) { - mBits.mMinFilter = minFlt; - mBits.mMagFilter = magFlt; + mBits.minFilter = minFlt; + mBits.magFilter = magFlt; } bool IsBiasClampEnable() const { - return mBits.mIsBiasClampEnable; + return mBits.biasClampEnable; } void SetBiasClampEnable(bool b) { - mBits.mIsBiasClampEnable = b; + mBits.biasClampEnable = b; } bool IsEdgeLODEnable() const { - return mBits.mIsEdgeLODEnable; + return mBits.edgeLODEnable; } void SetEdgeLODEnable(bool b) { - mBits.mIsEdgeLODEnable = b; + mBits.edgeLODEnable = b; } GXAnisotropy GetAnisotropy() const { - return (GXAnisotropy)mBits.mAnisotropy; + return (GXAnisotropy)mBits.anisotropy; } void SetAnisotropy(GXAnisotropy a) { - mBits.mAnisotropy = a; + mBits.anisotropy = a; } GXTlutFmt GetPaletteFormat() const { - return (GXTlutFmt)mBits.mPaletteFormat; + return (GXTlutFmt)mBits.paletteFormat; } void SetPaletteFormat(GXTlutFmt fmt) { - mBits.mPaletteFormat = fmt; + mBits.paletteFormat = fmt; } + // ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl + void ReplaceImage(TPLPalette *pal, u32 id); + // ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor + void ReplaceImage(TPLDescriptor *pTPLDesc); + private: void *mpImage; // at 0x00 void *mpPalette; // at 0x04 @@ -152,18 +184,17 @@ private: 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 - - } mBits; // at 0x18 + u32 textureFormat : 4; // (>> 28) & 0xF : GXTexFmt + u32 mipmap : 1; // (>> 27) & 0x1 : bool + u32 wrapS : 2; // (>> 25) & 0x3 : GXTexWrapMode + u32 wrapT : 2; // (>> 23) & 0x3 : GXTexWrapMode + u32 minFilter : 3; // (>> 20) & 0x7 : GXTexFilter + u32 magFilter : 1; // (>> 19) & 0x1 : GXTexFilter + u32 biasClampEnable : 1; // (>> 18) & 0x1 : bool + u32 edgeLODEnable : 1; // (>> 17) & 0x1 : bool + u32 anisotropy : 2; // (>> 15) & 0x3 : GXAnisotropy + u32 paletteFormat : 2; // (>> 13) & 0x3 : GXTlutFmt + } mBits; // at 0x18 }; } // namespace lyt } // namespace nw4r diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 563b0689..3f676c68 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -9,17 +9,17 @@ namespace lyt { namespace detail { 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; + u32 texMap : 4; // ( >> 28 ) & F + u32 texSRT : 4; // ( >> 24 ) & F + u32 texCoordGen : 4; // ( >> 20 ) & F + u32 indSRT : 2; // ( >> 18 ) & 3 + u32 indStage : 3; // ( >> 15 ) & 7 + u32 tevSwap : 1; // ( >> 14 ) & 1 + u32 tevStage : 5; // ( >> 9 ) & 1F + u32 chanCtrl : 1; // ( >> 8 ) & 1 + u32 matCol : 1; // ( >> 7 ) & 1 + u32 alpComp : 1; // ( >> 6 ) & 1 + u32 blendMode : 1; // ( >> 5 ) & 1 }; template @@ -40,10 +40,15 @@ T GetBits(T bits, int pos, int len) { } template -T *ConvertOffsToPtr(const void *baseAddress, unsigned int offset) { +T *ConvertOffsToPtr(void *baseAddress, unsigned int offset) { return (T *)((u32)baseAddress + offset); } +template +const T *ConvertOffsToPtr(const void *baseAddress, unsigned int offset) { + return (const T *)((u32)baseAddress + offset); +} + } // namespace detail struct Size { Size() : width(), height() {} @@ -66,13 +71,14 @@ struct AnimTransform { 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; + virtual ~AnimTransform() = 0; // at 0x08 + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) = 0; // at 0x0C + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, // + u16 animNum) = 0; // at 0x10 + virtual void Bind(Pane *pPane, bool bRecursive) = 0; // at 0x14 + virtual void Bind(Material *pMaterial, bool bDisable) = 0; // at 0x18 + virtual void Animate(u32 idx, Pane *pPane) = 0; // at 0x1C + virtual void Animate(u32 idx, Material *pMaterial) = 0; // at 0x20 ut::LinkListNode mLink; // at 0x4 res::AnimationBlock *mpRes; // at 0xC @@ -177,7 +183,9 @@ struct TexCoordGen { }; struct ChanCtrl { // 17552 // __ct__Q34nw4r3lyt8ChanCtrlFv - ChanCtrl() {} + ChanCtrl() : reserve1(0), reserve2(0) { + Set(GX_SRC_VTX, GX_SRC_VTX); + } // Set__Q34nw4r3lyt8ChanCtrlF11_GXColorSrc11_GXColorSrc void Set(GXColorSrc colSrc, GXColorSrc alpSrc) { @@ -201,15 +209,62 @@ struct ChanCtrl { // 17552 u8 reserve2; // at 0x3 }; +struct AlphaCompare { // 17457 + // __ct__Q34nw4r3lyt12AlphaCompareFv + AlphaCompare() { + Set(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); + } + + // Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc + void Set(GXCompare aComp0, u8 aRef0, GXAlphaOp aOp, GXCompare aComp1, u8 aRef1) { + comp = (aComp0 & 0x7) | ((aComp1 & 0x7) << 4); + op = aOp; + ref0 = aRef0; + ref1 = aRef1; + } + + // GetComp0__Q34nw4r3lyt12AlphaCompareCFv + GXCompare GetComp0() const { + return (GXCompare)((comp >> 0) & 0xF); + } + + // GetRef0__Q34nw4r3lyt12AlphaCompareCFv + u8 GetRef0() const { + return ref0; + } + + // GetOp__Q34nw4r3lyt12AlphaCompareCFv + GXAlphaOp GetOp() const { + return (GXAlphaOp)op; + } + + // GetComp1__Q34nw4r3lyt12AlphaCompareCFv + GXCompare GetComp1() const { + return (GXCompare)((comp >> 4) & 0xF); + } + + // GetRef1__Q34nw4r3lyt12AlphaCompareCFv + u8 GetRef1() const { + return ref1; + } + + u8 comp; // at 0x0 + u8 op; // at 0x1 + u8 ref0; // at 0x2 + u8 ref1; // at 0x3 +}; + struct BlendMode { // 10c41 // __ct__Q34nw4r3lyt9BlendModeFv - BlendMode() {} + BlendMode() { + Set(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + } // Set__Q34nw4r3lyt9BlendModeF12_GXBlendMode14_GXBlendFactor14_GXBlendFactor10_GXLogicOp - void Set(GXBlendMode aType, GXBlendFactor srcFactor, GXBlendFactor destFactor, GXLogicOp aOp) { + void Set(GXBlendMode aType, GXBlendFactor aSrcFactor, GXBlendFactor aDestFactor, GXLogicOp aOp) { type = aType; - srcFactor = srcFactor; - dstFactor = destFactor; + srcFactor = aSrcFactor; + dstFactor = aDestFactor; op = aOp; } @@ -239,46 +294,11 @@ struct BlendMode { // 10c41 u8 op; // at 0x3 }; -struct AlphaCompare { // 17457 - // __ct__Q34nw4r3lyt12AlphaCompareFv - AlphaCompare() {} - - // Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc - void Set(GXCompare aComp0, u8 aRef0, GXAlphaOp aOp, GXCompare aComp1, u8 aRef1) {} - - // GetComp0__Q34nw4r3lyt12AlphaCompareCFv - GXCompare GetComp0() const { - // return (GXCompare) - } - - // GetRef0__Q34nw4r3lyt12AlphaCompareCFv - u8 GetRef0() const { - return ref0; - } - - // GetOp__Q34nw4r3lyt12AlphaCompareCFv - GXAlphaOp GetOp() const { - return (GXAlphaOp)op; - } - - // GetComp1__Q34nw4r3lyt12AlphaCompareCFv - GXCompare GetComp1() const { - // return (GXCompare) - } - - // GetRef1__Q34nw4r3lyt12AlphaCompareCFv - u8 GetRef1() const { - return ref1; - } - - u8 comp; // at 0x0 - u8 op; // at 0x1 - u8 ref0; // at 0x2 - u8 ref1; // at 0x3 -}; struct IndirectStage { // 172da // __ct__Q34nw4r3lyt13IndirectStageFv - IndirectStage() {} + IndirectStage() { + Set(GX_TEXCOORD0, GX_TEXMAP0, GX_ITS_1, GX_ITS_1); + } // Set__Q34nw4r3lyt13IndirectStageF13_GXTexCoordID11_GXTexMapID14_GXIndTexScale14_GXIndTexScale void Set(GXTexCoordID aTexCoordGen, GXTexMapID aTexMap, GXIndTexScale aScaleS, GXIndTexScale aScaleT) { @@ -324,59 +344,65 @@ struct TexSRT { // 17243 struct TevStageInOp { // 16fe7 // GetA__Q34nw4r3lyt12TevStageInOpCFv u8 GetA() const { - return ab; // TODO + return (ab >> 0) & 0xF; } // GetB__Q34nw4r3lyt12TevStageInOpCFv u8 GetB() const { - return ab; // TODO + return (ab >> 4) & 0xF; } // GetC__Q34nw4r3lyt12TevStageInOpCFv u8 GetC() const { - return cd; // TODO + return (cd >> 0) & 0xF; } // GetD__Q34nw4r3lyt12TevStageInOpCFv u8 GetD() const { - return cd; // TODO + return (cd >> 4) & 0xF; } // GetOp__Q34nw4r3lyt12TevStageInOpCFv u8 GetOp() const { - return op; // TODO + return (op >> 0) & 0xF; } // GetBias__Q34nw4r3lyt12TevStageInOpCFv u8 GetBias() const { - return op; // TODO + return (op >> 4) & 0x3; } // GetScale__Q34nw4r3lyt12TevStageInOpCFv u8 GetScale() const { - return op; // TODO + return (op >> 6) & 0x3; } // IsClamp__Q34nw4r3lyt12TevStageInOpCFv bool IsClamp() const { - return cl; // TODO + return (cl >> 0) & 1; } // GetOutReg__Q34nw4r3lyt12TevStageInOpCFv u8 GetOutReg() const { - return op; // TODO + return (cl >> 1) & 0x3; } // GetKSel__Q34nw4r3lyt12TevStageInOpCFv u8 GetKSel() const { - return cl; // TODO + return (cl >> 3) & 0x1F; } // SetIn__Q34nw4r3lyt12TevStageInOpFUcUcUcUc - void SetIn(u8 a, u8 b, u8 c, u8 d) {} + void SetIn(u8 a, u8 b, u8 c, u8 d) { + ab = (a & 0xF) | ((b & 0xF) << 4); + cd = (c & 0xF) | ((d & 0xF) << 4); + } // SetOp__Q34nw4r3lyt12TevStageInOpFUcUcUcbUcUc - void SetOp(u8 aOp, u8 bias, u8 scale, bool clamp, u8 outReg, u8 kSel) {} + void SetOp(u8 aOp, u8 bias, u8 scale, bool clamp, u8 outReg, u8 kSel) { + op = (aOp & 0xF) | ((bias & 3) << 4) | ((scale & 0x3) << 6); + cl = (clamp & 1) | ((outReg & 0x3) << 1) | ((kSel & 0x1F) << 3); + } u8 ab; // at 0x0 u8 cd; // at 0x1 @@ -386,7 +412,15 @@ struct TevStageInOp { // 16fe7 struct TevStage { // 17094 // __ct__Q34nw4r3lyt8TevStageFv - TevStage() {} + TevStage() { + SetOrder(GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0, GX_TEV_SWAP0, GX_TEV_SWAP0); + SetColorIn(GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC); + SetAlphaIn(GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA); + SetColorOp(GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV, GX_TEV_KCSEL_K0); + SetAlphaOp(GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV, GX_TEV_KASEL_K0_R); + SetIndirect(GX_INDTEXSTAGE0, GX_ITF_8, GX_ITB_NONE, GX_ITM_OFF, GX_ITW_OFF, GX_ITW_OFF, false, false, + GX_ITBA_OFF); + } // GetTexCoordGen__Q34nw4r3lyt8TevStageCFv GXTexCoordID GetTexCoordGen() const { @@ -395,7 +429,7 @@ struct TevStage { // 17094 // GetTexMap__Q34nw4r3lyt8TevStageCFv GXTexMapID GetTexMap() const { - return (GXTexMapID)texMap; + return (GXTexMapID)(texMap | (swapSel & 1) << 8); } // GetColorChan__Q34nw4r3lyt8TevStageCFv @@ -405,12 +439,12 @@ struct TevStage { // 17094 // GetRasSwapSel__Q34nw4r3lyt8TevStageCFv GXTevSwapSel GetRasSwapSel() const { - return (GXTevSwapSel)swapSel; // TODO + return (GXTevSwapSel)((swapSel >> 1) & 3); } // GetTexSwapSel__Q34nw4r3lyt8TevStageCFv GXTevSwapSel GetTexSwapSel() const { - return (GXTevSwapSel)swapSel; // TODO + return (GXTevSwapSel)((swapSel >> 3) & 3); } // GetColorInA__Q34nw4r3lyt8TevStageCFv @@ -515,7 +549,7 @@ struct TevStage { // 17094 // GetIndMtxSel__Q34nw4r3lyt8TevStageCFv GXIndTexMtxID GetIndMtxSel() const { - return (GXIndTexMtxID)inBiMt; // TODO + return (GXIndTexMtxID)((inBiMt >> 3) & 0xF); } // GetIndStage__Q34nw4r3lyt8TevStageCFv @@ -525,37 +559,37 @@ struct TevStage { // 17094 // GetIndFormat__Q34nw4r3lyt8TevStageCFv GXIndTexFormat GetIndFormat() const { - return (GXIndTexFormat)indFoAdUtAl; // TODO + return (GXIndTexFormat)((indFoAdUtAl >> 0) & 0x3); } // GetIndBiasSel__Q34nw4r3lyt8TevStageCFv GXIndTexBiasSel GetIndBiasSel() const { - return (GXIndTexBiasSel)inBiMt; // TODO + return (GXIndTexBiasSel)((inBiMt >> 0) & 0x7); } // GetIndWrapS__Q34nw4r3lyt8TevStageCFv GXIndTexWrap GetIndWrapS() const { - return (GXIndTexWrap)indWrap; // TODO + return (GXIndTexWrap)((indWrap >> 0) & 0x7); } // GetIndWrapT__Q34nw4r3lyt8TevStageCFv GXIndTexWrap GetIndWrapT() const { - return (GXIndTexWrap)indWrap; // TODO + return (GXIndTexWrap)((indWrap >> 3) & 0x7); } // IsIndAddPrev__Q34nw4r3lyt8TevStageCFv - bool IsIndAddPrev() const { - return indFoAdUtAl; // TODO + u8 IsIndAddPrev() const { + return ((indFoAdUtAl >> 2) & 1); } // IsIndUtcLod__Q34nw4r3lyt8TevStageCFv - bool IsIndUtcLod() const { - return indFoAdUtAl; // TODO + u8 IsIndUtcLod() const { + return ((indFoAdUtAl >> 3) & 1); } // GetIndAlphaSel__Q34nw4r3lyt8TevStageCFv GXIndTexAlphaSel GetIndAlphaSel() const { - return (GXIndTexAlphaSel)indFoAdUtAl; // TODO + return (GXIndTexAlphaSel)((indFoAdUtAl >> 4) & 3); } // SetOrder__Q34nw4r3lyt8TevStageF13_GXTexCoordID11_GXTexMapID12_GXChannelID13_GXTevSwapSel13_GXTevSwapSel @@ -564,8 +598,7 @@ struct TevStage { // 17094 texCoordGen = aTexCoordGen; colChan = aColChan; texMap = aTexMap; - swapSel = rasSel; // TODO - swapSel = texSel; // TODO + swapSel = ((rasSel & 3) << 1) | ((texSel & 3) << 3); } // SetColorIn__Q34nw4r3lyt8TevStageF14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg @@ -592,14 +625,9 @@ struct TevStage { // 17094 void SetIndirect(GXIndTexStageID stage, GXIndTexFormat format, GXIndTexBiasSel bias, GXIndTexMtxID mtxSel, GXIndTexWrap wrapS, GXIndTexWrap wrapT, bool addPrev, bool utcLod, GXIndTexAlphaSel alphaSel) { indStage = stage; - indFoAdUtAl = format; // TODO - inBiMt = bias; // TODO - inBiMt = mtxSel; // TODO - indWrap = wrapS; // TODO - indWrap = wrapT; // TODO - indFoAdUtAl = addPrev; // TODO - indFoAdUtAl = utcLod; // TODO - indFoAdUtAl = alphaSel; // TODO + inBiMt = (bias & 0x7) | ((mtxSel & 0xF) << 4); + indWrap = (wrapS & 0x7) | ((wrapT & 0x7) << 3); + indFoAdUtAl = (format & 3) | (addPrev << 2) | (utcLod << 3) | ((alphaSel & 0x3) << 4); } u8 texCoordGen; // at 0x0 @@ -618,30 +646,27 @@ struct TevSwapMode { // 1750a // GetR__Q34nw4r3lyt11TevSwapModeCFv GXTevColorChan GetR() const { - return (GXTevColorChan)swap; // TODO + return (GXTevColorChan)((swap >> 0) & 0x3); } // GetG__Q34nw4r3lyt11TevSwapModeCFv GXTevColorChan GetG() const { - return (GXTevColorChan)swap; // TODO + return (GXTevColorChan)((swap >> 2) & 0x3); } // GetB__Q34nw4r3lyt11TevSwapModeCFv GXTevColorChan GetB() const { - return (GXTevColorChan)swap; // TODO + return (GXTevColorChan)((swap >> 4) & 0x3); } // GetA__Q34nw4r3lyt11TevSwapModeCFv GXTevColorChan GetA() const { - return (GXTevColorChan)swap; // TODO + return (GXTevColorChan)((swap >> 6) & 0x3); } // Set__Q34nw4r3lyt11TevSwapModeF15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan void Set(GXTevColorChan r, GXTevColorChan g, GXTevColorChan b, GXTevColorChan a) { - swap = r; // TODO - swap = g; // TODO - swap = b; // TODO - swap = a; // TODO + swap = (r << 0) | (g << 2) | (b << 4) | (a << 6); } u8 swap; // at 0x0 diff --git a/include/nw4r/ut/ut_Color.h b/include/nw4r/ut/ut_Color.h index b9616f14..f41e9dbe 100644 --- a/include/nw4r/ut/ut_Color.h +++ b/include/nw4r/ut/ut_Color.h @@ -34,6 +34,10 @@ public: return *this; } + Color &operator=(const GXColor &c) { + *(u32 *)this = *(u32 *)&c; // TODO -> This Seems Maybe Wrong + } + Color operator|(u32 color) { return Color(ToU32() | color); } diff --git a/include/rvl/GX/GXTev.h b/include/rvl/GX/GXTev.h index 5e4438b0..cdd651f0 100644 --- a/include/rvl/GX/GXTev.h +++ b/include/rvl/GX/GXTev.h @@ -13,7 +13,7 @@ void GXSetTevColorOp(GXTevStageID, GXTevOp, GXTevBias, GXTevScale, u8, GXTevRegI void GXSetTevAlphaOp(GXTevStageID, GXTevOp, GXTevBias, GXTevScale, u8, GXTevRegID); void GXSetTevColor(GXTevRegID, GXColor); - +void GXSetTevColorS10(GXTevRegID, GXColorS10); void GXSetTevKColor(GXTevKColorID, GXColor); void GXSetTevKColorSel(GXTevStageID, GXTevKColorSel); void GXSetTevKAlphaSel(GXTevStageID, GXTevKAlphaSel); diff --git a/include/rvl/GX/GXTexture.h b/include/rvl/GX/GXTexture.h index 8f826a2c..d6554e19 100644 --- a/include/rvl/GX/GXTexture.h +++ b/include/rvl/GX/GXTexture.h @@ -13,7 +13,9 @@ void __GXSetSUTexRegs(void); void GXInitTexObj(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8); void GXInitTexObjLOD(GXTexObj *, GXTexFilter, GXTexFilter, f32, f32, f32, u8, u8, GXAnisotropy); +void GXInitTexObjTlut(GXTexObj *, u32); +void GXLoadTlut(GXTlutObj *, u32); void GXLoadTexObj(GXTexObj *, GXTexMapID); #ifdef __cplusplus diff --git a/include/rvl/GX/GXTypes.h b/include/rvl/GX/GXTypes.h index 99094c37..745cbda6 100644 --- a/include/rvl/GX/GXTypes.h +++ b/include/rvl/GX/GXTypes.h @@ -801,6 +801,29 @@ typedef enum _GXTexWrapMode { GX_MAX_TEXWRAPMODE } GXTexWrapMode; +typedef enum GXTlut { + GX_TLUT0, + GX_TLUT1, + GX_TLUT2, + GX_TLUT3, + GX_TLUT4, + GX_TLUT5, + GX_TLUT6, + GX_TLUT7, + GX_TLUT8, + GX_TLUT9, + GX_TLUT10, + GX_TLUT11, + GX_TLUT12, + GX_TLUT13, + GX_TLUT14, + GX_TLUT15, + GX_BIGTLUT0, + GX_BIGTLUT1, + GX_BIGTLUT2, + GX_BIGTLUT3, +} GXTlut; + typedef enum _GXTlutFmt { GX_TL_IA8, GX_TL_RGB565, diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp index f151de6d..82525b90 100644 --- a/src/nw4r/lyt/lyt_material.cpp +++ b/src/nw4r/lyt/lyt_material.cpp @@ -1,439 +1,969 @@ + +#include #include +#include -// DefaultBlackColor -// DefaultWhiteColor +void float_ordering(u16 a) { + 0.5f; + 256.0f / 360.0f; + 0.0f; + 1.0f; + 2.0f; + (f32) a; +} +// All 0 intialization puts it in sbss2?? +static const GXColorS10 DefaultBlackColor = {0, 0, 0, 0}; +static const GXColorS10 DefaultWhiteColor = {0xFF, 0xFF, 0xFF, 0xFF}; + +namespace nw4r { +namespace lyt { +namespace { // __eq__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRC11_GXColorS10RC11_GXColorS10 -inline bool operator==(const GXColorS10 &a, const GXColorS10 &b) { +bool operator==(const GXColorS10 &a, const GXColorS10 &b) { return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a); } -inline bool operator!=(const GXColorS10 &a, const GXColorS10 &b) { - return (a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a); +bool operator!=(const GXColorS10 &a, const GXColorS10 &b) { + return !(a == b); } -namespace nw4r { -namespace lyt { - -namespace { // CalcTextureMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r4math5MTX34RCQ34nw4r3lyt6TexSRT void CalcTextureMtx(math::MTX34 *pMtx, const TexSRT &texSRT) { - math::VEC2 center; - f32 cosR; - f32 sinR; - f32 a0; - f32 a1; + math::VEC2 center(0.5f, 0.5f); + f32 cosR = math::CosDeg(texSRT.rotate); + f32 sinR = math::SinDeg(texSRT.rotate); + f32 a0, a1; + + a0 = cosR * texSRT.scale.x; + a1 = -sinR * texSRT.scale.y; + pMtx->_00 = a0; + pMtx->_01 = a1; + pMtx->_02 = 0.0f; + pMtx->_03 = texSRT.translate.x + center.x + a0 * -center.x + a1 * -center.y; + + a0 = sinR * texSRT.scale.x; + a1 = cosR * texSRT.scale.y; + pMtx->_10 = a0; + pMtx->_11 = a1; + pMtx->_12 = 0.0f; + pMtx->_13 = texSRT.translate.y + center.y + a0 * -center.x + a1 * -center.y; + + pMtx->_20 = 0.0f; + pMtx->_21 = 0.0f; + pMtx->_22 = 1.0f; + pMtx->_23 = 0.0f; } // CalcIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPA3_fRCQ34nw4r3lyt6TexSRT void CalcIndTexMtx(f32 (*mtx)[3], const TexSRT &texSRT) { - f32 cosR; - f32 sinR; + f32 cosR = math::CosDeg(texSRT.rotate); + f32 sinR = math::SinDeg(texSRT.rotate); + + mtx[0][0] = cosR * texSRT.scale.x; + mtx[0][1] = -sinR * texSRT.scale.y; + mtx[0][2] = texSRT.translate.x; + mtx[1][0] = sinR * texSRT.scale.x; + mtx[1][1] = cosR * texSRT.scale.y; + mtx[1][2] = texSRT.translate.y; } // SetColorComponentValue__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r2ut5ColorUls void SetColorComponentValue(ut::Color *pCol, u32 compIdx, s16 value) { - u8 u8Val; + u8 u8Val = ut::Min(ut::Max(value, 0), 0xFF); + switch (compIdx % 4) { + case 0: + pCol->r = u8Val; + break; + case 1: + pCol->g = u8Val; + break; + case 2: + pCol->b = u8Val; + break; + case 3: + pCol->a = u8Val; + break; + default: + break; + } } // SetIndTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@F14_GXIndTexMtxIDPA3_Cf void SetIndTexMtx(GXIndTexMtxID id, const f32 (*mtx)[3]) { - f32 m00, m01, m02, m10, m11, m12, a00, a01, a02, a10, a11, a12; - s8 scaleExp; - f32 outMtx[3]; + f32 m00 = mtx[0][0]; + f32 m01 = mtx[0][1]; + f32 m02 = mtx[0][2]; + f32 m10 = mtx[1][0]; + f32 m11 = mtx[1][1]; + f32 m12 = mtx[1][2]; + f32 a00 = math::FAbs(m00); + f32 a01 = math::FAbs(m01); + f32 a02 = math::FAbs(m02); + f32 a10 = math::FAbs(m10); + f32 a11 = math::FAbs(m11); + f32 a12 = math::FAbs(m12); + s8 scaleExp = 0; + + if ((a00 >= 1.0f || a01 >= 1.0f || a02 >= 1.0f || a10 >= 1.0f || a11 >= 1.0f || a12 >= 1.0f)) { + do { + if (scaleExp >= 46) { + break; + } + m00 *= 0.5f; + m01 *= 0.5f; + m02 *= 0.5f; + m10 *= 0.5f; + m11 *= 0.5f; + m12 *= 0.5f; + a00 *= 0.5f; + a01 *= 0.5f; + a02 *= 0.5f; + a10 *= 0.5f; + a11 *= 0.5f; + a12 *= 0.5f; + scaleExp++; + } while ((a00 >= 1.0f || a01 >= 1.0f || a02 >= 1.0f || a10 >= 1.0f || a11 >= 1.0f || a12 >= 1.0f)); + } else if (a00 < 0.5f && a01 < 0.5f && a02 < 0.5f && a10 < 0.5f && a11 < 0.5f && a12 < 0.5f) { + do { + a00 *= 2.0f; + m00 *= 2.0f; + m01 *= 2.0f; + m02 *= 2.0f; + m10 *= 2.0f; + m11 *= 2.0f; + m12 *= 2.0f; + a01 *= 2.0f; + a02 *= 2.0f; + a10 *= 2.0f; + a11 *= 2.0f; + a12 *= 2.0f; + scaleExp--; + } while (a00 < 0.5f && a01 < 0.5f && a02 < 0.5f && a10 < 0.5f && a11 < 0.5f && a12 < 0.5f && scaleExp > -17); + } + f32 outMtx[2][3] = {m00, m01, m02, m10, m11, m12}; + GXSetIndTexMtx(id, outMtx, scaleExp); +} +// GetTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl +u32 GetTexMtx(u32 texMtxIdx) { + return 30 + 3 * texMtxIdx; +} + +// GetTexMtxIdx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl +u32 GetTexMtxIdx(u32 texMtx) { + return (texMtx - 30) / 3; } // InitTexSRT__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FPQ34nw4r3lyt6TexSRTUl void InitTexSRT(TexSRT *texSRTs, u32 num) { - u32 i; + for (u32 i = 0; i < num; i++) { + texSRTs[i].translate = math::VEC2(0.0f, 0.0f); + texSRTs[i].rotate = 0.0f; + texSRTs[i].scale = math::VEC2(1.0f, 1.0f); + } } // CalcOffsetTexSRTAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetTexSRTAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetTexSRTAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.texMap * sizeof(TexMap); +} // CalcOffsetTexCoordGenAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetTexCoordGenAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetTexCoordGenAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.texSRT * ROUND_UP(sizeof(TexSRT), 4) + CalcOffsetTexSRTAry(bitGXNums); +} // CalcOffsetChanCtrlAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetChanCtrlAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetChanCtrlAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.texCoordGen * ROUND_UP(sizeof(TexCoordGen), 4) + CalcOffsetTexCoordGenAry(bitGXNums); +} // CalcOffsetMatColAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetMatColAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetMatColAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.chanCtrl * ROUND_UP(sizeof(ChanCtrl), 4) + CalcOffsetChanCtrlAry(bitGXNums); +} // CalcOffsetTevSwapAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetTevSwapAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetTevSwapAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.matCol * ROUND_UP(sizeof(ut::Color), 4) + CalcOffsetMatColAry(bitGXNums); +} // CalcOffsetGetAlphaCompare__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetGetAlphaCompare(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetGetAlphaCompare(const detail::BitGXNums &bitGXNums) { + // just sizeof(TevSwapMode)] doesnt work here. Assuming its aligned to 4 for a ptr purposeD + return bitGXNums.tevSwap * ROUND_UP(sizeof(TevSwapMode), 4) + CalcOffsetTevSwapAry(bitGXNums); +} // CalcOffsetBlendMode__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetBlendMode(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetBlendMode(const detail::BitGXNums &bitGXNums) { + return bitGXNums.alpComp * ROUND_UP(sizeof(AlphaCompare), 4) + CalcOffsetGetAlphaCompare(bitGXNums); +} // CalcOffsetIndirectStageAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetIndirectStageAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetIndirectStageAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.blendMode * ROUND_UP(sizeof(BlendMode), 4) + CalcOffsetBlendMode(bitGXNums); +} // CalcOffsetIndTexSRTAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetIndTexSRTAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetIndTexSRTAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.indStage * ROUND_UP(sizeof(IndirectStage), 4) + CalcOffsetIndirectStageAry(bitGXNums); +} // CalcOffsetTevStageAry__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FRCQ44nw4r3lyt6detail9BitGXNums -u32 CalcOffsetTevStageAry(const detail::BitGXNums &bitGXNums) {} +u32 CalcOffsetTevStageAry(const detail::BitGXNums &bitGXNums) { + return bitGXNums.indSRT * ROUND_UP(sizeof(TexSRT), 4) + CalcOffsetIndTexSRTAry(bitGXNums); +} } // namespace -// __ct__Q34nw4r3lyt8MaterialFPCQ44nw4r3lyt3res8MaterialRCQ34nw4r3lyt11ResBlockSet -Material::Material(const res::Material *pRes, const ResBlockSet &resBlockSet) { - { int i; } - { int i; } - u32 resOffs; - const res::TexMap *pResTexMap; - const res::TexSRT *pResTexSRTs; - const TexCoordGen *resTexCoordGen; - u8 texMapNum; - u8 texSRTNum; - u8 texCoordGenNum; - bool allocChanCtrl; - bool allocMatCol; - bool allocTevSwap; - bool allocAlpComp; - bool allocBlendMode; - u8 indTexSRTNum; - u8 indStageNum; - u8 tevStageNum; - const res::Texture *textures; - const TexMap *texMaps; - u8 di, si; - const char *fileName; - void *pTplRes; - res::TexSRT *texSRTs; - { int i; } - TexCoordGen *texCoordGens; - { int i; } - const ChanCtrl *pResChanCtrl; - ut::Color *pResMatCol; - const TevSwapMode *pResTevSwap; - const TevSwapMode *tevSwaps; - { int i; } - const TexSRT *indTexSRTs; - const TexSRT *pResIndMtx; - { int i; } - IndirectStage *indirectStages; - const IndirectStage *pResIndStg; - { int i; } - const TevStage *tevStages; - const TevStage *pResTevStg; - { int i; } - const AlphaCompare *pResAlphaCompare; - const BlendMode *pResBlendMode; +// __ct__Q34nw4r3lyt8MaterialFv +Material::Material() { + /* Exists, not in SS. Needed for some function ordering */ } +#pragma dont_inline on +// __ct__Q34nw4r3lyt8MaterialFPCQ44nw4r3lyt3res8MaterialRCQ34nw4r3lyt11ResBlockSet +Material::Material(const res::Material *pRes, const ResBlockSet &resBlockSet) : mAnimList(), mTevKCols() { + Init(); + SetName(pRes->name); + for (int i = 0; i < 3; i++) { + mTevCols[i] = pRes->tevCols[i]; + } + for (int i = 0; i < 4; i++) { + mTevKCols[i] = pRes->tevKCols[i]; + } + + u32 resOffs = sizeof(res::Material); + const res::TexMap *pResTexMap = detail::ConvertOffsToPtr(pRes, resOffs); + resOffs += pRes->resNum.GetTexMapNum() * sizeof(res::TexMap); + + const TexSRT *pResTexSRTs = detail::ConvertOffsToPtr(pRes, resOffs); + resOffs += pRes->resNum.GetTexSRTNum() * sizeof(TexSRT); + + const TexCoordGen *resTexCoordGen = detail::ConvertOffsToPtr(pRes, resOffs); + resOffs += pRes->resNum.GetTexCoordGenNum() * sizeof(TexCoordGen); + + u8 texMapNum = ut::Min(pRes->resNum.GetTexMapNum(), 8); + u8 texSRTNum = ut::Min(pRes->resNum.GetTexSRTNum(), 10); + u8 texCoordGenNum = ut::Min(pRes->resNum.GetTexCoordGenNum(), 8); + bool allocChanCtrl = pRes->resNum.GetChanCtrlNum() != 0; + bool allocMatCol = pRes->resNum.GetMatColNum() != 0; + bool allocTevSwap = pRes->resNum.HasTevSwapTable(); + bool allocAlpComp = pRes->resNum.HasAlphaCompare(); + bool allocBlendMode = pRes->resNum.HasBlendMode(); + u8 indTexSRTNum = ut::Min(pRes->resNum.GetIndTexSRTNum(), 3); + u8 indStageNum = ut::Min(pRes->resNum.GetIndTexStageNum(), 4); + u8 tevStageNum = ut::Min(pRes->resNum.GetTevStageNum(), 16); + + ReserveGXMem(texMapNum, texSRTNum, texCoordGenNum, tevStageNum, allocTevSwap, indStageNum, indTexSRTNum, + allocChanCtrl, allocMatCol, allocAlpComp, allocBlendMode); + + if (mpGXMem) { + SetTextureNum(texMapNum); + if (texMapNum != 0) { + const res::Texture *textures = + detail::ConvertOffsToPtr(resBlockSet.pTextureList, sizeof(res::TextureList)); + TexMap *texMaps = GetTexMapAry(); + u8 di = 0; + for (u8 si = 0; si < texMapNum; di++, si++) { + const char *fileName = + detail::ConvertOffsToPtr(textures, textures[pResTexMap[si].texIdx].nameStrOffset); + void *pTplRes = resBlockSet.pResAccessor->GetResource('timg', fileName, nullptr); + texMaps[di].ReplaceImage((TPLPalette *)pTplRes, 0); + texMaps[di].SetWrapMode(pResTexMap[si].GetWarpModeS(), pResTexMap[si].GetWarpModeT()); + texMaps[di].SetFilter(pResTexMap[si].GetMinFilter(), pResTexMap[si].GetMagFilter()); + } + SetTextureNum(di); + } + } + TexSRT *texSRTs = GetTexSRTAry(); + for (int i = 0; i < texSRTNum; i++) { + texSRTs[i].translate = pResTexSRTs[i].translate; + texSRTs[i].rotate = pResTexSRTs[i].rotate; + texSRTs[i].scale = pResTexSRTs[i].scale; + } + + TexCoordGen *texCoordGens = GetTexCoordGenAry(); + SetTexCoordGenNum(texCoordGenNum); + for (int i = 0; i < mGXMemNum.texCoordGen; i++) { + texCoordGens[i] = resTexCoordGen[i]; + } + + if (allocChanCtrl) { + const ChanCtrl *pResChanCtrl = detail::ConvertOffsToPtr(pRes, resOffs); + GetChanCtrlAry()[0] = *pResChanCtrl; + resOffs += sizeof(ChanCtrl); + } + + if (allocMatCol) { + const ut::Color *pResMatCol = detail::ConvertOffsToPtr(pRes, resOffs); + GetMatColAry()[0] = *pResMatCol; + resOffs += sizeof(ut::Color); + } + + if (allocTevSwap) { + const TevSwapMode *tevSwaps = detail::ConvertOffsToPtr(pRes, resOffs); + TevSwapMode *pResTevSwap = GetTevSwapAry(); + for (int i = 0; i < 4; i++) { + pResTevSwap[i] = tevSwaps[i]; + } + resOffs += 4 * sizeof(TevSwapMode); + } + + if (indTexSRTNum != 0) { + TexSRT *indTexSRTs = GetIndTexSRTAry(); + const TexSRT *pResIndMtx = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indTexSRTNum; i++) { + indTexSRTs[i] = pResIndMtx[i]; + } + } + resOffs += pRes->resNum.GetIndTexSRTNum() * sizeof(TexSRT); + + if (indStageNum != 0) { + SetIndStageNum(indStageNum); + IndirectStage *indirectStages = GetIndirectStageAry(); + const IndirectStage *pResIndStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indStageNum; i++) { + indirectStages[i] = pResIndStg[i]; + } + } + resOffs += pRes->resNum.GetIndTexStageNum() * sizeof(IndirectStage); + + if (tevStageNum != 0) { + SetTevStageNum(tevStageNum); + TevStage *tevStages = GetTevStageAry(); + const TevStage *pResTevStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < tevStageNum; i++) { + tevStages[i] = pResTevStg[i]; + } + } + resOffs += pRes->resNum.GetTevStageNum() * sizeof(TevStage); + + if (allocAlpComp) { + const AlphaCompare *pResAlphaCompare = detail::ConvertOffsToPtr(pRes, resOffs); + *GetAlphaComparePtr() = *pResAlphaCompare; + resOffs += sizeof(AlphaCompare); + } + if (allocBlendMode) { + const BlendMode *pResBlendMode = detail::ConvertOffsToPtr(pRes, resOffs); + *GetBlendModePtr() = *pResBlendMode; + } +} +#pragma dont_inline reset + // Init__Q34nw4r3lyt8MaterialFv -void Material::Init() {} +void Material::Init() { + mTevCols[0] = DefaultBlackColor; + mTevCols[1] = DefaultWhiteColor; + mTevCols[2] = DefaultWhiteColor; + InitBitGXNums(&mGXMemCap); + InitBitGXNums(&mGXMemNum); + mbUserAllocated = false; + mpGXMem = nullptr; +} // __dt__Q34nw4r3lyt8MaterialFv -Material::~Material() {} +Material::~Material() { + UnbindAllAnimation(); + if (mpGXMem) { + Layout::FreeMemory(mpGXMem); + mpGXMem = nullptr; + } +} // InitBitGXNums__Q34nw4r3lyt8MaterialFPQ44nw4r3lyt6detail9BitGXNums -void Material::InitBitGXNums(detail::BitGXNums *ptr) {} +void Material::InitBitGXNums(detail::BitGXNums *ptr) { + ptr->texMap = 0; + ptr->texSRT = 0; + ptr->texCoordGen = 0; + ptr->indSRT = 0; + ptr->indStage = 0; + ptr->tevSwap = 0; + ptr->tevStage = 0; + ptr->chanCtrl = 0; + ptr->matCol = 0; + ptr->alpComp = 0; + ptr->blendMode = 0; +} // ReserveGXMem__Q34nw4r3lyt8MaterialFUcUcUcUcbUcUcbbbb void Material::ReserveGXMem(u8 texMapNum, u8 texSRTNum, u8 texCoordGenNum, u8 tevStageNum, bool allocTevSwap, u8 indStageNum, u8 indSRTNum, bool allocChanCtrl, bool allocMatCol, bool allocAlpComp, bool allocBlendMode) { - int tevSwapNum; - int chanCtrlNum; - int matColNum; - int alpCompNum; - int blendModeNum; - const TevSwapMode *tevSwaps; + int tevSwapNum = allocTevSwap; + int chanCtrlNum = allocChanCtrl; + int matColNum = allocMatCol; + int alpCompNum = allocAlpComp; + int blendModeNum = allocBlendMode; + if (mGXMemCap.texMap < texMapNum || mGXMemCap.texSRT < texSRTNum || mGXMemCap.texCoordGen < texCoordGenNum || + mGXMemCap.tevStage < tevStageNum || mGXMemCap.tevSwap < tevSwapNum || mGXMemCap.indStage < indStageNum || + mGXMemCap.indSRT < indSRTNum || mGXMemCap.chanCtrl < chanCtrlNum || mGXMemCap.matCol < matColNum || + mGXMemCap.alpComp < alpCompNum || mGXMemCap.blendMode < blendModeNum) { + if (mpGXMem) { + Layout::FreeMemory(mpGXMem); + mpGXMem = nullptr; + InitBitGXNums(&mGXMemCap); + InitBitGXNums(&mGXMemNum); + } + mpGXMem = Layout::AllocMemory( + (texCoordGenNum + chanCtrlNum + matColNum + tevSwapNum + alpCompNum + blendModeNum + indStageNum) * 4 + + texMapNum * sizeof(TexMap) + tevStageNum * sizeof(TevStage) + texSRTNum * sizeof(TexSRT) + + indSRTNum * sizeof(TexSRT)); + + if (mpGXMem) { + mGXMemCap.texMap = texMapNum; + mGXMemCap.texSRT = texSRTNum; + mGXMemCap.texCoordGen = texCoordGenNum; + mGXMemCap.indSRT = indSRTNum; + mGXMemCap.indStage = indStageNum; + mGXMemCap.tevSwap = tevSwapNum; + mGXMemCap.tevStage = tevStageNum; + mGXMemCap.chanCtrl = chanCtrlNum; + mGXMemCap.matCol = matColNum; + mGXMemCap.alpComp = alpCompNum; + mGXMemCap.blendMode = blendModeNum; + + mGXMemNum.texSRT = mGXMemCap.texSRT; + InitTexSRT(GetTexSRTAry(), mGXMemNum.texSRT); + + mGXMemNum.indSRT = mGXMemCap.indSRT; + InitTexSRT(GetIndTexSRTAry(), mGXMemNum.indSRT); + + mGXMemNum.chanCtrl = mGXMemCap.chanCtrl; + if (mGXMemNum.chanCtrl != 0) { + GetChanCtrlAry()[0] = ChanCtrl(); + } + + mGXMemNum.matCol = mGXMemCap.matCol; + if (mGXMemNum.matCol != 0) { + GetMatColAry()[0] = 0xFFFFFFFF; + } + + mGXMemNum.tevSwap = mGXMemCap.tevSwap; + if (mGXMemNum.tevSwap != 0) { + TevSwapMode *tevSwaps = GetTevSwapAry(); + tevSwaps[0].Set(GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA); + tevSwaps[1].Set(GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA); + tevSwaps[2].Set(GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA); + tevSwaps[3].Set(GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA); + } + + mGXMemNum.alpComp = mGXMemCap.alpComp; + if (mGXMemNum.alpComp != 0) { + *GetAlphaComparePtr() = AlphaCompare(); + } + + mGXMemNum.blendMode = mGXMemCap.blendMode; + if (mGXMemNum.blendMode != 0) { + *GetBlendModePtr() = BlendMode(); + } + } + } } // GetTexMapAry__Q34nw4r3lyt8MaterialCFv -TexMap *Material::GetTexMapAry() const {} +const TexMap *Material::GetTexMapAry() const { + return detail::ConvertOffsToPtr(mpGXMem, 0); // Might not use the function? +} // GetTexMapAry__Q34nw4r3lyt8MaterialFv -TexMap *Material::GetTexMapAry() {} +TexMap *Material::GetTexMapAry() { + return (detail::ConvertOffsToPtr(mpGXMem, 0)); +} + +// GetTexSRTAry__Q34nw4r3lyt8MaterialCFv +const TexSRT *Material::GetTexSRTAry() const { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetTexSRTAry(mGXMemCap)); +} // GetTexSRTAry__Q34nw4r3lyt8MaterialFv -TexSRT *Material::GetTexSRTAry() {} +TexSRT *Material::GetTexSRTAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetTexSRTAry(mGXMemCap)); +} // GetTexCoordGenAry__Q34nw4r3lyt8MaterialFv -TexCoordGen *Material::GetTexCoordGenAry() {} +TexCoordGen *Material::GetTexCoordGenAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetTexCoordGenAry(mGXMemCap)); +} // GetChanCtrlAry__Q34nw4r3lyt8MaterialFv -ChanCtrl *Material::GetChanCtrlAry() {} +ChanCtrl *Material::GetChanCtrlAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetChanCtrlAry(mGXMemCap)); +} // GetMatColAry__Q34nw4r3lyt8MaterialFv -ut::Color *Material::GetMatColAry() {} +ut::Color *Material::GetMatColAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetMatColAry(mGXMemCap)); +} // GetTevSwapAry__Q34nw4r3lyt8MaterialFv -TevSwapMode *Material::GetTevSwapAry() {} +TevSwapMode *Material::GetTevSwapAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetTevSwapAry(mGXMemCap)); +} // GetAlphaComparePtr__Q34nw4r3lyt8MaterialFv -AlphaCompare *Material::GetAlphaComparePtr() {} +AlphaCompare *Material::GetAlphaComparePtr() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetGetAlphaCompare(mGXMemCap)); +} // GetBlendModePtr__Q34nw4r3lyt8MaterialFv -BlendMode *Material::GetBlendModePtr() {} +BlendMode *Material::GetBlendModePtr() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetBlendMode(mGXMemCap)); +} // GetIndirectStageAry__Q34nw4r3lyt8MaterialFv -IndirectStage *Material::GetIndirectStageAry() {} +IndirectStage *Material::GetIndirectStageAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetIndirectStageAry(mGXMemCap)); +} // GetIndTexSRTAry__Q34nw4r3lyt8MaterialFv -TexSRT *Material::GetIndTexSRTAry() {} +TexSRT *Material::GetIndTexSRTAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetIndTexSRTAry(mGXMemCap)); +} // GetTevStageAry__Q34nw4r3lyt8MaterialFv -TevStage *Material::GetTevStageAry() {} +TevStage *Material::GetTevStageAry() { + return detail::ConvertOffsToPtr(mpGXMem, CalcOffsetTevStageAry(mGXMemCap)); +} // SetName__Q34nw4r3lyt8MaterialFPCc -void Material::SetName(const char *name) {} +void Material::SetName(const char *name) { + strncpy(mName, name, 20); + mName[20] = '\0'; +} // SetTextureNum__Q34nw4r3lyt8MaterialFUc void Material::SetTextureNum(u8 num) { - TexMap *texMaps; - u32 i; + if (num != 0) { + TexMap *texMaps = GetTexMapAry(); + for (u32 i = mGXMemNum.texMap; i < num; i++) { + new (&texMaps[i]) TexMap(); // Placement operator required + // texMaps[i] = TexMap(); + } + } + mGXMemNum.texMap = num; } // SetTexCoordGenNum__Q34nw4r3lyt8MaterialFUc void Material::SetTexCoordGenNum(u8 num) { - TexCoordGen *texCoordGens; - u32 i; + if (num != 0) { + TexCoordGen *texCoordGens = GetTexCoordGenAry(); + for (u32 i = mGXMemNum.texCoordGen; i < num; i++) { + new (&texCoordGens[i]) TexCoordGen(); + } + } + mGXMemNum.texCoordGen = num; } // SetTevStageNum__Q34nw4r3lyt8MaterialFUc void Material::SetTevStageNum(u8 num) { - TevStage *tevStages; - u32 i; + if (num != 0) { + TevStage *tevStages = GetTevStageAry(); + for (u32 i = mGXMemNum.tevStage; i < num; i++) { + new (&tevStages[i]) TevStage(); + } + } + mGXMemNum.tevStage = num; } // SetIndStageNum__Q34nw4r3lyt8MaterialFUc void Material::SetIndStageNum(u8 num) { - IndirectStage *indStages; - u32 i; + if (num != 0) { + IndirectStage *indStages = GetIndirectStageAry(); + for (u32 i = mGXMemNum.indStage; i < num; i++) { + new (&indStages[i]) IndirectStage(); + } + } + mGXMemNum.indStage = num; } +// GetColorElement__Q34nw4r3lyt8MaterialCFUl + // SetColorElement__Q34nw4r3lyt8MaterialFUls void Material::SetColorElement(u32 colorType, s16 value) { - ut::Color *matCols; - { u32 regIdx; } - { u32 regIdx; } - GXTevKColorSel kColSels[8]; - GXTevKAlphaSel kAlpSels[8]; + // Some sort of Enum ? + // 0:[ MatCol->r] 1:[ MatCol->g] 2:[ MatCol->b] 3:[ MatCol->a + // 4:[ TevCol->r] 5:[ TevCol->g] 6:[ TevCol->b] 7:[ TevCol->a] + // 8:[ TevCol->r] 9:[ TevCol->g] 10:[ TevCol->b] 11:[ TevCol->a] + // 12:[ TevCol->r] 13:[ TevCol->g] 14:[ TevCol->b] 15:[ TevCol->a] + // 16:[TevKCol->r] 17:[TevKCol->g] 18:[TevKCol->b] 19:[TevKCol->a] + // 20:[TevKCol->r] 21:[TevKCol->g] 22:[TevKCol->b] 23:[TevKCol->a] + // 24:[TevKCol->r] 25:[TevKCol->g] 26:[TevKCol->b] 27:[TevKCol->a] + // 28:[TevKCol->r] 29:[TevKCol->g] 30:[TevKCol->b] 31:[TevKCol->a] + // clang-format off + switch (colorType) { + case 0: case 1: case 2: case 3: + if (mGXMemNum.matCol < 1 ) { + break; + } + ut::Color *matCols = GetMatColAry(); + SetColorComponentValue(matCols, colorType , value); + break; + case 4: case 5: case 6: case 7: case 8: case 9: + case 10: case 11: case 12: case 13: case 14: case 15: { + u32 regIdx = (colorType - 4) / 4; + switch ((colorType - 4) % 4) { + case 0: + mTevCols[regIdx].r = value; + break; + case 1: + mTevCols[regIdx].g = value; + break; + case 2: + mTevCols[regIdx].b = value; + break; + case 3: + mTevCols[regIdx].a = value; + break; + } + } break; + case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: + case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: { + u32 regIdx = (colorType - 16) / 4; + SetColorComponentValue(&mTevKCols[regIdx], (colorType - 16) , value); + } break; + } + // clang-format on } // SetupGX__Q34nw4r3lyt8MaterialFbUc bool Material::SetupGX(bool bModVtxCol, u8 alpha) { - bool bUseVtxCol; - bool bUseMatCol; - const ChanCtrl *chanCtrls; - bool bUseRasStage; - ut::Color matCol; - bool bSetTexMtx; - bool bUseTexMtxl; - { int i; } - const TexCoordGen *texCoordGens; - { int i; } - u32 texMtx; - const TexSRT *texSRTs; - { int i; } - { math::MTX34 texMtx; } - u32 tlutID; - u32 bigTlutID; - const TexMap *texMaps; - { int i; } - // TexMap & texMap; - GXTexObj texObj; - u32 tlutName; - GXTlutObj tlutObj; - const TevSwapMode *tevSwaps; - { int i; } - bool bSetIndTexMtx; - bool bUseIndTexMtx; - { int i; } - const TevStage *tevStages; - { int i; } - GXTevStageID tevStage; - GXIndTexMtxID indMtxSel; - u8 tevStageID; - { GXTevStageID tevStage; } - { GXTevStageID tevStage; } - { GXTevStageID tevStage; } - { int i; } - { GXTevStageID tevStage; } - GXTevColorArg colDIn; - GXTevAlphaArg alpDIn; - { GXTevStageID tevStage; } - { GXTevStageID tevStage; } - u8 tevStageNum; - u8 id; - { GXTevStageID tevStage; } - const TexSRT *indTexSRTs; - { int i; } - f32 mtx[2][3]; - const IndirectStage *indirectStages; - { int i; } - GXIndTexStageID indStage; - const AlphaCompare *pAlpComp; - const BlendMode *pBlendMode; + bool bUseVtxCol = true; + bool bUseMatCol = false; + GXSetNumChans(1); + if (IsChanCtrlCap()) { + const ChanCtrl *chanCtrls = GetChanCtrlAry(); + GXSetChanCtrl(GX_COLOR0, false, GX_SRC_REG, chanCtrls->GetColorSrc(), GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + GXSetChanCtrl(GX_ALPHA0, false, GX_SRC_REG, chanCtrls->GetAlphaSrc(), GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + + bUseVtxCol = chanCtrls->GetColorSrc() == GX_SRC_VTX || chanCtrls->GetAlphaSrc() == GX_SRC_VTX; + bUseMatCol = chanCtrls->GetColorSrc() == GX_SRC_REG || chanCtrls->GetAlphaSrc() == GX_SRC_REG; + } else { + GXSetChanCtrl(GX_COLOR0A0, FALSE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + } + + // Why set to false and then check if true? + bool bUseRasStage = false; + if (bUseVtxCol) { + bUseRasStage = bUseRasStage || bModVtxCol; + } + + if (bUseMatCol) { + ut::Color matCol = 0xFFFFFFFF; + if (IsMatColorCap()) { + matCol = GetMatColAry()[0]; + } + matCol = detail::MultipleAlpha(matCol, alpha); + GXSetChanMatColor(GX_COLOR0A0, matCol); + bUseRasStage = bUseRasStage || matCol != 0xFFFFFFFF; + } + bool bSetTexMtx = false; + bool bUseTexMtx[10]; + for (int i = 0; i < 10; i++) { + bUseTexMtx[i] = false; + } + GXSetNumTexGens(mGXMemNum.texCoordGen); + if (mGXMemNum.texCoordGen != 0) { + const TexCoordGen *texCoordGens = GetTexCoordGenAry(); + for (int i = 0; i < mGXMemNum.texCoordGen; i++) { + u32 texMtx = texCoordGens[i].GetTexMtx(); + if (texCoordGens[i].GetTexGenType() == GX_TEXMAP1 && texMtx != 0x3C) { + bUseTexMtx[GetTexMtxIdx(texMtx)] = true; + bSetTexMtx = true; + } + GXSetTexCoordGen2((GXTexCoordID)i, texCoordGens[i].GetTexGenType(), texCoordGens[i].GetTexGenSrc(), texMtx, + FALSE, 0x7D); + } + } + if (bSetTexMtx) { + const TexSRT *texSRTs = GetTexSRTAry(); + + for (u8 i = 0; i < mGXMemNum.texSRT; i++) { + if (bUseTexMtx[i]) { + math::MTX34 texMtx; + CalcTextureMtx(&texMtx, texSRTs[i]); + GXLoadTexMtxImm(texMtx, GetTexMtx(i), GX_MTX_2x4); + } + } + } + + if (mGXMemNum.texMap) { + u32 tlutID = 0; + u32 bigTlutID = 16; + + const TexMap *texMaps = GetTexMapAry(); + for (int i = 0; i < mGXMemNum.texMap; i++) { + const TexMap &texMap = texMaps[i]; + GXTexObj texObj; + texMap.Get(&texObj); + if (detail::IsCITexelFormat(texMap.GetTexelFormat())) { + u32 tlutName; + if (texMap.GetTexelFormat() == 10) { + tlutName = bigTlutID++; + } else { + tlutName = tlutID++; + } + GXInitTexObjTlut(&texObj, tlutName); + GXTlutObj tlutObj; + texMap.Get(&tlutObj); + GXLoadTlut(&tlutObj, tlutName); + } + GXLoadTexObj(&texObj, (GXTexMapID)i); + } + } + + GXSetTevColorS10(GX_TEVREG0, mTevCols[0]); + GXSetTevColorS10(GX_TEVREG1, mTevCols[1]); + GXSetTevColorS10(GX_TEVREG2, mTevCols[2]); + GXSetTevKColor(GX_KCOLOR0, mTevKCols[0]); + GXSetTevKColor(GX_KCOLOR1, mTevKCols[1]); + GXSetTevKColor(GX_KCOLOR2, mTevKCols[2]); + GXSetTevKColor(GX_KCOLOR3, mTevKCols[3]); + + if (IsTevSwapCap()) { + const TevSwapMode *tevSwaps = GetTevSwapAry(); + for (int i = 0; i < 4; i++) { + GXSetTevSwapModeTable((GXTevSwapSel)i, tevSwaps[i].GetR(), tevSwaps[i].GetG(), tevSwaps[i].GetB(), + tevSwaps[i].GetA()); + } + } else { + GXSetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA); + GXSetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA); + GXSetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA); + GXSetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA); + } + + bool bSetIndTexMtx = false; + bool bUseIndTexMtx[3]; + for (int i = 0; i < 3; i++) { + bUseIndTexMtx[i] = false; + } + if (mGXMemNum.tevStage != 0) { + GXSetNumTevStages(mGXMemNum.tevStage); + const TevStage *tevStages = GetTevStageAry(); + for (int i = 0; i < mGXMemNum.tevStage; i++) { + GXTevStageID tevStage = (GXTevStageID)i; + GXSetTevOrder(tevStage, tevStages[i].GetTexCoordGen(), tevStages[i].GetTexMap(), + tevStages[i].GetColorChan()); + GXSetTevSwapMode(tevStage, tevStages[i].GetRasSwapSel(), tevStages[i].GetTexSwapSel()); + GXSetTevColorIn(tevStage, tevStages[i].GetColorInA(), tevStages[i].GetColorInB(), + tevStages[i].GetColorInC(), tevStages[i].GetColorInD()); + GXSetTevColorOp(tevStage, tevStages[i].GetColorOp(), tevStages[i].GetColorBias(), + tevStages[i].GetColorScale(), tevStages[i].IsColorClamp(), tevStages[i].GetColorOutReg()); + GXSetTevKColorSel(tevStage, tevStages[i].GetKColorSel()); + GXSetTevAlphaIn(tevStage, tevStages[i].GetAlphaInA(), tevStages[i].GetAlphaInB(), + tevStages[i].GetAlphaInC(), tevStages[i].GetAlphaInD()); + GXSetTevAlphaOp(tevStage, tevStages[i].GetAlphaOp(), tevStages[i].GetAlphaBias(), + tevStages[i].GetAlphaScale(), tevStages[i].IsAlphaClamp(), tevStages[i].GetAlphaOutReg()); + GXSetTevKAlphaSel(tevStage, tevStages[i].GetKAlphaSel()); + GXIndTexMtxID indMtxSel = tevStages[i].GetIndMtxSel(); + GXSetTevIndirect(tevStage, tevStages[i].GetIndStage(), tevStages[i].GetIndFormat(), + tevStages[i].GetIndBiasSel(), indMtxSel, tevStages[i].GetIndWrapS(), tevStages[i].GetIndWrapT(), + tevStages[i].IsIndAddPrev(), tevStages[i].IsIndUtcLod(), tevStages[i].GetIndAlphaSel()); + if (1 <= indMtxSel && indMtxSel <= 3) { + bUseIndTexMtx[indMtxSel - 1] = true; + bSetIndTexMtx = true; + } + } + bUseRasStage = true; + } else { + static GXTevKColorSel kColSels[8] = { + GX_TEV_KCSEL_K3_A, + GX_TEV_KCSEL_K3_B, + GX_TEV_KCSEL_K3_G, + GX_TEV_KCSEL_K3_R, + GX_TEV_KCSEL_K2_A, + GX_TEV_KCSEL_K2_B, + GX_TEV_KCSEL_K2_G, + GX_TEV_KCSEL_K2_R, + }; + static GXTevKAlphaSel kAlpSels[8] = { + GX_TEV_KASEL_K3_A, + GX_TEV_KASEL_K3_B, + GX_TEV_KASEL_K3_G, + GX_TEV_KASEL_K3_R, + GX_TEV_KASEL_K2_A, + GX_TEV_KASEL_K2_B, + GX_TEV_KASEL_K2_G, + GX_TEV_KASEL_K2_R, + }; + u8 tevStageID = 0; + if (mGXMemNum.texMap == 0) { + GXTevStageID tevStage = GX_TEVSTAGE0; + GXSetTevOrder(tevStage, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevColorIn(tevStage, GX_CC_ZERO, GX_CC_C1, GX_CC_RASC, GX_CC_ZERO); + GXSetTevAlphaIn(tevStage, GX_CA_ZERO, GX_CA_A1, GX_CA_RASA, GX_CA_ZERO); + bUseRasStage = true; + tevStageID = 1; + } else { + if (mGXMemNum.texMap == 1) { + GXTevStageID tevStage = GX_TEVSTAGE0; + GXSetTevOrder(tevStage, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(tevStage, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevAlphaIn(tevStage, GX_CA_A0, GX_CA_A1, GX_CA_TEXA, GX_CA_ZERO); + tevStageID = 1; + } else { + if (mGXMemNum.texMap == 2) { + GXTevStageID tevStage = GX_TEVSTAGE0; + GXSetTevOrder(tevStage, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(tevStage, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_TEXC); + GXSetTevAlphaIn(tevStage, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); + + tevStage = GX_TEVSTAGE1; + GXSetTevOrder(tevStage, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR_NULL); + GXSetTevColorIn(tevStage, GX_CC_TEXC, GX_CC_CPREV, GX_CC_KONST, GX_CC_ZERO); + GXSetTevAlphaIn(tevStage, GX_CA_TEXA, GX_CA_APREV, GX_CA_KONST, GX_CA_ZERO); + GXSetTevKColorSel(tevStage, kColSels[0]); + GXSetTevKAlphaSel(tevStage, kAlpSels[0]); + tevStageID = 2; + + } else { + for (int i = 0; i < mGXMemNum.texMap; i++) { + GXTevStageID tevStage = (GXTevStageID)tevStageID; + GXSetTevOrder(tevStage, (GXTexCoordID)i, (GXTexMapID)i, GX_COLOR_NULL); + GXTevColorArg colDIn = i == 0 ? GX_CC_ZERO : GX_CC_CPREV; + GXTevAlphaArg alpDIn = i == 0 ? GX_CA_ZERO : GX_CA_APREV; + GXSetTevColorIn(tevStage, GX_CC_ZERO, GX_CC_TEXC, GX_CC_KONST, colDIn); + GXSetTevAlphaIn(tevStage, GX_CA_ZERO, GX_CA_TEXA, GX_CA_KONST, alpDIn); + GXSetTevKColorSel(tevStage, kColSels[i]); + GXSetTevKAlphaSel(tevStage, kAlpSels[i]); + tevStageID++; + } + } + if (mTevCols[0] != DefaultBlackColor || mTevCols[1] != DefaultWhiteColor) { + GXTevStageID tevStage = (GXTevStageID)tevStageID; + GXSetTevOrder(tevStage, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL); + GXSetTevColorIn(tevStage, GX_CC_C0, GX_CC_C1, GX_CC_CPREV, GX_CC_ZERO); + GXSetTevAlphaIn(tevStage, GX_CA_A0, GX_CA_A1, GX_CA_APREV, GX_CA_ZERO); + tevStageID++; + } + } + if (bUseRasStage) { + GXTevStageID tevStage = (GXTevStageID)tevStageID; + GXSetTevOrder(tevStage, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevColorIn(tevStage, GX_CC_ZERO, GX_CC_CPREV, GX_CC_RASC, GX_CC_ZERO); + GXSetTevAlphaIn(tevStage, GX_CA_ZERO, GX_CA_APREV, GX_CA_RASA, GX_CA_ZERO); + tevStageID++; + } + } + + const u8 tevStageNum = tevStageID; + + for (u8 id = 0; id < tevStageNum; id++) { + GXTevStageID tevStage = (GXTevStageID)id; + GXSetTevColorOp(tevStage, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, TRUE, GX_TEVPREV); + GXSetTevAlphaOp(tevStage, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, TRUE, GX_TEVPREV); + GXSetTevDirect(tevStage); + GXSetTevSwapMode(tevStage, GX_TEV_SWAP0, GX_TEV_SWAP0); + } + GXSetNumTevStages(tevStageNum); + } + if (bSetIndTexMtx) { + const TexSRT *indTexSRTs = GetIndTexSRTAry(); + for (int i = 0; i < mGXMemNum.indSRT; i++) { + if (bUseIndTexMtx[i]) { + f32 mtx[2][3]; + CalcIndTexMtx(mtx, indTexSRTs[i]); + SetIndTexMtx((GXIndTexMtxID)(i + 1), mtx); + } + } + } + + GXSetNumIndStages(mGXMemNum.indStage); + if (mGXMemNum.indStage != 0) { + const IndirectStage *indirectStages = GetIndirectStageAry(); + for (int i = 0; i < mGXMemNum.indStage; i++) { + GXIndTexStageID indStage = (GXIndTexStageID)i; + GXSetIndTexOrder(indStage, indirectStages[i].GetTexCoordGen(), indirectStages[i].GetTexMap()); + GXSetIndTexCoordScale(indStage, indirectStages[i].GetScaleS(), indirectStages[i].GetScaleT()); + } + } + if (IsAlphaCompareCap()) { + const AlphaCompare *pAlpComp = GetAlphaComparePtr(); + GXSetAlphaCompare(pAlpComp->GetComp0(), pAlpComp->GetRef0(), pAlpComp->GetOp(), pAlpComp->GetComp1(), + pAlpComp->GetRef1()); + } else { + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); + } + if (IsBlendModeCap()) { + const BlendMode *pBlendMode = GetBlendModePtr(); + GXSetBlendMode(pBlendMode->GetType(), pBlendMode->GetSrcFactor(), pBlendMode->GetDstFactor(), + pBlendMode->GetOp()); + + } else { + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + } + return bUseRasStage && bUseVtxCol; } -namespace { -// GetTexMtx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl -u32 GetTexMtx(u32 texMtxIdx) {} - -// GetTexMtxIdx__Q34nw4r3lyt26@unnamed@lyt_material_cpp@FUl -u32 GetTexMtxIdx(u32 texMtx) {} - -} // namespace - // BindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform -void Material::BindAnimation(AnimTransform *pAnimTrans) {} +void Material::BindAnimation(AnimTransform *pAnimTrans) { + pAnimTrans->Bind(this, false); +} // UnbindAnimation__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform -void Material::UnbindAnimation(AnimTransform *pAnimTrans) {} +void Material::UnbindAnimation(AnimTransform *pAnimTrans) { + detail::UnbindAnimationLink(GetAnimationList(), pAnimTrans); +} // UnbindAllAnimation__Q34nw4r3lyt8MaterialFv -void Material::UnbindAllAnimation() {} +void Material::UnbindAllAnimation() { + UnbindAnimation(nullptr); +} // Animate__Q34nw4r3lyt8MaterialFv void Material::Animate() { - ut::LinkList::Iterator it; - AnimTransform *animTrans; + for (ut::LinkList::Iterator it = mAnimList.GetBeginIter(); it != mAnimList.GetEndIter(); it++) { + if (it->IsEnable()) { + AnimTransform *pAnimTrans = it->GetAnimTransform(); + pAnimTrans->Animate(it->GetIndex(), this); + } + } } // AddAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimationLink -void Material::AddAnimationLink(AnimationLink *pAnimationLink) {} +void Material::AddAnimationLink(AnimationLink *pAnimationLink) { + mAnimList.PushBack(pAnimationLink); +} // FindAnimationLink__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransform -AnimationLink *Material::FindAnimationLink(AnimTransform *pAnimTrans) {} +AnimationLink *Material::FindAnimationLink(AnimTransform *pAnimTrans) { + return detail::FindAnimationLink(&mAnimList, pAnimTrans); +} // FindAnimationLink__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResource -AnimationLink *Material::FindAnimationLink(const AnimResource &animRes) {} +AnimationLink *Material::FindAnimationLink(const AnimResource &animRes) { + return detail::FindAnimationLink(&mAnimList, animRes); +} // SetAnimationEnable__Q34nw4r3lyt8MaterialFPQ34nw4r3lyt13AnimTransformb -void Material::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) {} +void Material::SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable) { + AnimationLink *pAnimLink = FindAnimationLink(pAnimTrans); + if (pAnimLink) { + pAnimLink->SetEnable(bEnable); + } +} // SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb void Material::SetAnimationEnable(const AnimResource &animRes, bool bEnable) { - AnimationLink *pAnimLink; + AnimationLink *pAnimLink = FindAnimationLink(animRes); + if (pAnimLink) { + pAnimLink->SetEnable(bEnable); + } } namespace detail { // GetTextureSize__Q34nw4r3lyt6detailFPQ34nw4r3lyt8MaterialUc -Size GetTextureSize(Material *pMaterial, u8 texMapIdx) {} +Size GetTextureSize(Material *pMaterial, u8 texMapIdx) { + if (texMapIdx >= pMaterial->GetTextureNum()) { + return Size(); + } + const TexMap &texMap = pMaterial->GetTexMapAry()[texMapIdx]; + return Size(texMap.GetWidth(), texMap.GetHeight()); +} } // namespace detail } // namespace lyt } // namespace nw4r - -// INLINED FROM OTHER FILES -// ut_inlines.h -// Min__Q34nw4r2ut26@unnamed@lyt_material_cpp@Fss_s -// Max__Q34nw4r2ut26@unnamed@lyt_material_cpp@Fss_s -// Min__Q34nw4r2ut26@unnamed@lyt_material_cpp@FUcUc_Uc - -// lyt_types.h -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt9BlendMode -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt12AlphaCompare -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt8TevStage -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt13IndirectStage -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt11TevSwapMode -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r2ut5Color -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt8ChanCtrl -// GetBits__Q34nw4r3lyt6detailFiii_i -// GetBits__Q34nw4r3lyt6detailFUcii_Uc -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ44nw4r3lyt3res7Texture -// GetBits
        __Q34nw4r3lyt6detailFUlii_Ul -// TestBit
          __Q34nw4r3lyt6detailFUli_b -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt11TexCoordGen -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ34nw4r3lyt6TexSRT -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPCvUi_PCQ44nw4r3lyt3res6TexMap -// __ct__Q34nw4r3lyt9BlendModeFv -// Set__Q34nw4r3lyt9BlendModeF12_GXBlendMode14_GXBlendFactor14_GXBlendFactor10_GXLogicOp -// __ct__Q34nw4r3lyt12AlphaCompareFv -// Set__Q34nw4r3lyt12AlphaCompareF10_GXCompareUc10_GXAlphaOp10_GXCompareUc -// Set__Q34nw4r3lyt11TevSwapModeF15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan15_GXTevColorChan -// __ct__Q34nw4r3lyt8ChanCtrlFv -// Set__Q34nw4r3lyt8ChanCtrlF11_GXColorSrc11_GXColorSrc -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt6TexMap -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt6TexSRT -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt11TexCoordGen -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt8ChanCtrl -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r2ut5Color -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt11TevSwapMode -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt12AlphaCompare -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt9BlendMode -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt13IndirectStage -// ConvertOffsToPtr__Q34nw4r3lyt6detailFPvUi_PQ34nw4r3lyt8TevStage -// __ct__Q34nw4r3lyt8TevStageFv -// SetIndirect__Q34nw4r3lyt8TevStageF16_GXIndTexStageID15_GXIndTexFormat16_GXIndTexBiasSel14_GXIndTexMtxID13_GXIndTexWrap13_GXIndTexWrapbb17_GXIndTexAlphaSel -// SetAlphaOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKAlphaSel -// SetOp__Q34nw4r3lyt12TevStageInOpFUcUcUcbUcUc -// SetColorOp__Q34nw4r3lyt8TevStageF8_GXTevOp10_GXTevBias11_GXTevScaleb11_GXTevRegID15_GXTevKColorSel -// SetAlphaIn__Q34nw4r3lyt8TevStageF14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg14_GXTevAlphaArg -// SetIn__Q34nw4r3lyt12TevStageInOpFUcUcUcUc -// SetColorIn__Q34nw4r3lyt8TevStageF14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg14_GXTevColorArg -// SetOrder__Q34nw4r3lyt8TevStageF13_GXTexCoordID11_GXTexMapID12_GXChannelID13_GXTevSwapSel13_GXTevSwapSel -// __ct__Q34nw4r3lyt13IndirectStageFv -// Set__Q34nw4r3lyt13IndirectStageF13_GXTexCoordID11_GXTexMapID14_GXIndTexScale14_GXIndTexScale -// GetOp__Q34nw4r3lyt9BlendModeCFv -// GetDstFactor__Q34nw4r3lyt9BlendModeCFv -// GetSrcFactor__Q34nw4r3lyt9BlendModeCFv -// GetType__Q34nw4r3lyt9BlendModeCFv -// GetRef1__Q34nw4r3lyt12AlphaCompareCFv -// GetComp1__Q34nw4r3lyt12AlphaCompareCFv -// GetOp__Q34nw4r3lyt12AlphaCompareCFv -// GetRef0__Q34nw4r3lyt12AlphaCompareCFv -// GetComp0__Q34nw4r3lyt12AlphaCompareCFv -// GetScaleT__Q34nw4r3lyt13IndirectStageCFv -// GetScaleS__Q34nw4r3lyt13IndirectStageCFv -// GetTexMap__Q34nw4r3lyt13IndirectStageCFv -// GetTexCoordGen__Q34nw4r3lyt13IndirectStageCFv -// GetIndAlphaSel__Q34nw4r3lyt8TevStageCFv -// IsIndUtcLod__Q34nw4r3lyt8TevStageCFv -// IsIndAddPrev__Q34nw4r3lyt8TevStageCFv -// GetIndWrapT__Q34nw4r3lyt8TevStageCFv -// GetIndWrapS__Q34nw4r3lyt8TevStageCFv -// GetIndBiasSel__Q34nw4r3lyt8TevStageCFv -// GetIndFormat__Q34nw4r3lyt8TevStageCFv -// GetIndStage__Q34nw4r3lyt8TevStageCFv -// GetIndMtxSel__Q34nw4r3lyt8TevStageCFv -// GetKAlphaSel__Q34nw4r3lyt8TevStageCFv -// GetKSel__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaOutReg__Q34nw4r3lyt8TevStageCFv -// GetOutReg__Q34nw4r3lyt12TevStageInOpCFv -// IsAlphaClamp__Q34nw4r3lyt8TevStageCFv -// IsClamp__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaScale__Q34nw4r3lyt8TevStageCFv -// GetScale__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaBias__Q34nw4r3lyt8TevStageCFv -// GetBias__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaOp__Q34nw4r3lyt8TevStageCFv -// GetOp__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaInD__Q34nw4r3lyt8TevStageCFv -// GetD__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaInC__Q34nw4r3lyt8TevStageCFv -// GetC__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaInB__Q34nw4r3lyt8TevStageCFv -// GetB__Q34nw4r3lyt12TevStageInOpCFv -// GetAlphaInA__Q34nw4r3lyt8TevStageCFv -// GetA__Q34nw4r3lyt12TevStageInOpCFv -// GetKColorSel__Q34nw4r3lyt8TevStageCFv -// GetColorOutReg__Q34nw4r3lyt8TevStageCFv -// IsColorClamp__Q34nw4r3lyt8TevStageCFv -// GetColorScale__Q34nw4r3lyt8TevStageCFv -// GetColorBias__Q34nw4r3lyt8TevStageCFv -// GetColorOp__Q34nw4r3lyt8TevStageCFv -// GetColorInD__Q34nw4r3lyt8TevStageCFv -// GetColorInC__Q34nw4r3lyt8TevStageCFv -// GetColorInB__Q34nw4r3lyt8TevStageCFv -// GetColorInA__Q34nw4r3lyt8TevStageCFv -// GetTexSwapSel__Q34nw4r3lyt8TevStageCFv -// GetRasSwapSel__Q34nw4r3lyt8TevStageCFv -// GetColorChan__Q34nw4r3lyt8TevStageCFv -// GetTexMap__Q34nw4r3lyt8TevStageCFv -// GetTexCoordGen__Q34nw4r3lyt8TevStageCFv -// GetA__Q34nw4r3lyt11TevSwapModeCFv -// GetB__Q34nw4r3lyt11TevSwapModeCFv -// GetG__Q34nw4r3lyt11TevSwapModeCFv -// GetR__Q34nw4r3lyt11TevSwapModeCFv diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 58ad61a2..02b26c4f 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -512,15 +512,15 @@ u16 Pane::GetExtUserDataNum() const { } return 0; } -res::ExtUserData *Pane::GetExtUserData() const { +const res::ExtUserData *Pane::GetExtUserData() const { if (this->mpExtUserDataList) { return detail::ConvertOffsToPtr(this->mpExtUserDataList, sizeof(res::ExtUserDataList)); } return nullptr; } -res::ExtUserData *Pane::FindExtUserDataByName(const char *name) { - res::ExtUserData *pUserData = GetExtUserData(); +const res::ExtUserData *Pane::FindExtUserDataByName(const char *name) { + const res::ExtUserData *pUserData = GetExtUserData(); if (!pUserData) { return nullptr; From afbcb57c6270464d781206c562f680b91b4660f7 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Wed, 5 Jun 2024 23:05:18 -0400 Subject: [PATCH 15/22] lyt_material OK - Thanks robojumper for pointing out weak function order from header uses --- config/SOUE01/config.yml | 1 + configure.py | 2 +- include/nw4r/lyt/lyt_material.h | 38 ++++++++++ src/nw4r/lyt/lyt_material.cpp | 128 ++++++++++++++++---------------- 4 files changed, 104 insertions(+), 65 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 74626e27..6b4d9eb2 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -20,6 +20,7 @@ force_active: [ "GetFont__Q34nw4r3lyt24MultiArcResourceAccessorFPCc", "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", "SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font", + "GetTexMapAry__Q34nw4r3lyt8MaterialCFv", ] # modules: diff --git a/configure.py b/configure.py index 8f362118..8c4247ed 100644 --- a/configure.py +++ b/configure.py @@ -360,7 +360,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_textBox.cpp"), Object(Matching, "nw4r/lyt/lyt_window.cpp"), Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), - Object(NonMatching, "nw4r/lyt/lyt_material.cpp"), + Object(Matching, "nw4r/lyt/lyt_material.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_material.h b/include/nw4r/lyt/lyt_material.h index 05a574f1..3a1d4dce 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -132,6 +132,44 @@ public: GetTexCoordGenAry()[idx] = value; } + // Begin Functions not found in DWARF, but assumed from BBA map and required for weak func ordering + void SetTevColor(u32 idx, const GXColorS10 &color) { + mTevCols[idx] = color; + } + + void SetAlphaCompare(const AlphaCompare &alphaComp) { + *GetAlphaComparePtr() = alphaComp; + } + + void SetChanControl(u32 idx, const ChanCtrl &chanCtrl) { + GetChanCtrlAry()[idx] = chanCtrl; + } + + void SetTevKColor(u32 idx, const ut::Color &color) { + mTevKCols[idx] = color; + } + + void SetTevSwapMode(u32 idx, const TevSwapMode &tevSwapMode) { + GetTevSwapAry()[idx] = tevSwapMode; + } + + void SetTexSRT(u32 idx, const TexSRT &texSRT) { + GetTexSRTAry()[idx] = texSRT; + } + + void SetIndirectStage(u32 idx, const IndirectStage &indStage) { + GetIndirectStageAry()[idx] = indStage; + } + + void SetBlendMode(const BlendMode &blendMode) { + *GetBlendModePtr() = blendMode; + } + + void SetTevStage(u32 idx, const TevStage &tevStage) { + GetTevStageAry()[idx] = tevStage; + } + // End Functions not found in DWARF, but assumed from BBA map and required for weak func ordering + virtual ~Material(); // at 0x08 virtual bool SetupGX(bool bModVtxCol, u8 alpha); // at 0x0C virtual void BindAnimation(AnimTransform *pAnimTrans); // at 0x10 diff --git a/src/nw4r/lyt/lyt_material.cpp b/src/nw4r/lyt/lyt_material.cpp index 82525b90..cf8fe4df 100644 --- a/src/nw4r/lyt/lyt_material.cpp +++ b/src/nw4r/lyt/lyt_material.cpp @@ -275,78 +275,78 @@ Material::Material(const res::Material *pRes, const ResBlockSet &resBlockSet) : } SetTextureNum(di); } - } - TexSRT *texSRTs = GetTexSRTAry(); - for (int i = 0; i < texSRTNum; i++) { - texSRTs[i].translate = pResTexSRTs[i].translate; - texSRTs[i].rotate = pResTexSRTs[i].rotate; - texSRTs[i].scale = pResTexSRTs[i].scale; - } - - TexCoordGen *texCoordGens = GetTexCoordGenAry(); - SetTexCoordGenNum(texCoordGenNum); - for (int i = 0; i < mGXMemNum.texCoordGen; i++) { - texCoordGens[i] = resTexCoordGen[i]; - } - - if (allocChanCtrl) { - const ChanCtrl *pResChanCtrl = detail::ConvertOffsToPtr(pRes, resOffs); - GetChanCtrlAry()[0] = *pResChanCtrl; - resOffs += sizeof(ChanCtrl); - } - - if (allocMatCol) { - const ut::Color *pResMatCol = detail::ConvertOffsToPtr(pRes, resOffs); - GetMatColAry()[0] = *pResMatCol; - resOffs += sizeof(ut::Color); - } - - if (allocTevSwap) { - const TevSwapMode *tevSwaps = detail::ConvertOffsToPtr(pRes, resOffs); - TevSwapMode *pResTevSwap = GetTevSwapAry(); - for (int i = 0; i < 4; i++) { - pResTevSwap[i] = tevSwaps[i]; + TexSRT *texSRTs = GetTexSRTAry(); + for (int i = 0; i < texSRTNum; i++) { + texSRTs[i].translate = pResTexSRTs[i].translate; + texSRTs[i].rotate = pResTexSRTs[i].rotate; + texSRTs[i].scale = pResTexSRTs[i].scale; } - resOffs += 4 * sizeof(TevSwapMode); - } - if (indTexSRTNum != 0) { - TexSRT *indTexSRTs = GetIndTexSRTAry(); - const TexSRT *pResIndMtx = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < indTexSRTNum; i++) { - indTexSRTs[i] = pResIndMtx[i]; + TexCoordGen *texCoordGens = GetTexCoordGenAry(); + SetTexCoordGenNum(texCoordGenNum); + for (int i = 0; i < mGXMemNum.texCoordGen; i++) { + texCoordGens[i] = resTexCoordGen[i]; } - } - resOffs += pRes->resNum.GetIndTexSRTNum() * sizeof(TexSRT); - if (indStageNum != 0) { - SetIndStageNum(indStageNum); - IndirectStage *indirectStages = GetIndirectStageAry(); - const IndirectStage *pResIndStg = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < indStageNum; i++) { - indirectStages[i] = pResIndStg[i]; + if (allocChanCtrl) { + const ChanCtrl *pResChanCtrl = detail::ConvertOffsToPtr(pRes, resOffs); + GetChanCtrlAry()[0] = *pResChanCtrl; + resOffs += sizeof(ChanCtrl); } - } - resOffs += pRes->resNum.GetIndTexStageNum() * sizeof(IndirectStage); - if (tevStageNum != 0) { - SetTevStageNum(tevStageNum); - TevStage *tevStages = GetTevStageAry(); - const TevStage *pResTevStg = detail::ConvertOffsToPtr(pRes, resOffs); - for (int i = 0; i < tevStageNum; i++) { - tevStages[i] = pResTevStg[i]; + if (allocMatCol) { + const ut::Color *pResMatCol = detail::ConvertOffsToPtr(pRes, resOffs); + GetMatColAry()[0] = *pResMatCol; + resOffs += sizeof(ut::Color); } - } - resOffs += pRes->resNum.GetTevStageNum() * sizeof(TevStage); - if (allocAlpComp) { - const AlphaCompare *pResAlphaCompare = detail::ConvertOffsToPtr(pRes, resOffs); - *GetAlphaComparePtr() = *pResAlphaCompare; - resOffs += sizeof(AlphaCompare); - } - if (allocBlendMode) { - const BlendMode *pResBlendMode = detail::ConvertOffsToPtr(pRes, resOffs); - *GetBlendModePtr() = *pResBlendMode; + if (allocTevSwap) { + const TevSwapMode *tevSwaps = detail::ConvertOffsToPtr(pRes, resOffs); + TevSwapMode *pResTevSwap = GetTevSwapAry(); + for (int i = 0; i < 4; i++) { + pResTevSwap[i] = tevSwaps[i]; + } + resOffs += 4 * sizeof(TevSwapMode); + } + + if (indTexSRTNum != 0) { + TexSRT *indTexSRTs = GetIndTexSRTAry(); + const TexSRT *pResIndMtx = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indTexSRTNum; i++) { + indTexSRTs[i] = pResIndMtx[i]; + } + } + resOffs += pRes->resNum.GetIndTexSRTNum() * sizeof(TexSRT); + + if (indStageNum != 0) { + SetIndStageNum(indStageNum); + IndirectStage *indirectStages = GetIndirectStageAry(); + const IndirectStage *pResIndStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < indStageNum; i++) { + indirectStages[i] = pResIndStg[i]; + } + } + resOffs += pRes->resNum.GetIndTexStageNum() * sizeof(IndirectStage); + + if (tevStageNum != 0) { + SetTevStageNum(tevStageNum); + TevStage *tevStages = GetTevStageAry(); + const TevStage *pResTevStg = detail::ConvertOffsToPtr(pRes, resOffs); + for (int i = 0; i < tevStageNum; i++) { + tevStages[i] = pResTevStg[i]; + } + } + resOffs += pRes->resNum.GetTevStageNum() * sizeof(TevStage); + + if (allocAlpComp) { + const AlphaCompare *pResAlphaCompare = detail::ConvertOffsToPtr(pRes, resOffs); + *GetAlphaComparePtr() = *pResAlphaCompare; + resOffs += sizeof(AlphaCompare); + } + if (allocBlendMode) { + const BlendMode *pResBlendMode = detail::ConvertOffsToPtr(pRes, resOffs); + *GetBlendModePtr() = *pResBlendMode; + } } } #pragma dont_inline reset From b0b02bbedf460a7305c91f6befaf054323c8d0cd Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 6 Jun 2024 23:24:25 -0400 Subject: [PATCH 16/22] lyt_texMap OK --- config/SOUE01/config.yml | 1 + config/SOUE01/splits.txt | 4 + config/SOUE01/symbols.txt | 10 +- configure.py | 1 + include/nw4r/lyt/lyt_texMap.h | 21 +++- include/rvl/GX/GXInternal.h | 22 +++- include/rvl/GX/GXTexture.h | 14 ++- src/nw4r/lyt/lyt_texMap.cpp | 205 ++++++++++++++++++++++++++++++++++ 8 files changed, 265 insertions(+), 13 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 6b4d9eb2..1058c731 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -21,6 +21,7 @@ force_active: [ "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", "SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font", "GetTexMapAry__Q34nw4r3lyt8MaterialCFv", + "Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj", ] # modules: diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 939fd8f0..7e9b5639 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -372,6 +372,10 @@ nw4r/lyt/lyt_material.cpp: .sdata2 start:0x8057F280 end:0x8057F2A0 .sbss2 start:0x8057FFB8 end:0x8057FFC0 +nw4r/lyt/lyt_texMap.cpp: + .text start:0x804905D0 end:0x80490980 + .sdata2 start:0x8057F2A0 end:0x8057F2B4 + 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 543d738a..99bac2dd 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23909,8 +23909,8 @@ fn_804292D0 = .text:0x804292D0; // type:function size:0xFC fn_804293D0 = .text:0x804293D0; // type:function size:0x48 fn_80429420 = .text:0x80429420; // type:function size:0x230 fn_80429650 = .text:0x80429650; // type:function size:0x2D8 -fn_80429930 = .text:0x80429930; // type:function size:0x118 -fn_80429A50 = .text:0x80429A50; // type:function size:0x20 +TPLBind = .text:0x80429930; // type:function size:0x118 +TPLGet = .text:0x80429A50; // type:function size:0x20 fn_80429A70 = .text:0x80429A70; // type:function size:0x24 fn_80429A94 = .text:0x80429A94; // type:function size:0x24 fn_80429AB8 = .text:0x80429AB8; // type:function size:0x5C @@ -26049,8 +26049,8 @@ SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb = .text:0x GetTextureSize__Q34nw4r3lyt6detailFPQ34nw4r3lyt8MaterialUc = .text:0x80490560; // type:function size:0x70 Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj = .text:0x804905D0; // type:function size:0xEC Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj = .text:0x804906C0; // type:function size:0x1C -Set__Q34nw4r3lyt6TexMapFPCQ34nw4r3lyt6TexMap = .text:0x804906E0; // type:function size:0x14C -Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor = .text:0x80490830; // type:function size:0x74 +Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj = .text:0x804906E0; // type:function size:0x14C +ReplaceImage__Q34nw4r3lyt6TexMapFRC9_GXTexObj = .text:0x80490830; // type:function size:0x74 ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl = .text:0x804908B0; // type:function size:0xD0 __ct__Q34nw4r3lyt8DrawInfoFv = .text:0x80490980; // type:function size:0x74 __dt__Q34nw4r3lyt8DrawInfoFv = .text:0x80490A00; // type:function size:0x40 @@ -47582,7 +47582,7 @@ lbl_8057F290 = .sdata2:0x8057F290; // type:object size:0x4 data:float lbl_8057F298 = .sdata2:0x8057F298; // type:object size:0x8 data:double lbl_8057F2A0 = .sdata2:0x8057F2A0; // type:object size:0x4 data:float lbl_8057F2A8 = .sdata2:0x8057F2A8; // type:object size:0x8 data:double -lbl_8057F2B0 = .sdata2:0x8057F2B0; // type:object size:0x8 data:float +lbl_8057F2B0 = .sdata2:0x8057F2B0; // type:object size:0x4 data:float lbl_8057F2B8 = .sdata2:0x8057F2B8; // type:object size:0x4 data:float lbl_8057F2BC = .sdata2:0x8057F2BC; // type:object size:0x4 data:float lbl_8057F2C0 = .sdata2:0x8057F2C0; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 8c4247ed..94e25745 100644 --- a/configure.py +++ b/configure.py @@ -361,6 +361,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_window.cpp"), Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), Object(Matching, "nw4r/lyt/lyt_material.cpp"), + Object(Matching, "nw4r/lyt/lyt_texMap.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_texMap.h b/include/nw4r/lyt/lyt_texMap.h index 5a6609a7..17898f4a 100644 --- a/include/nw4r/lyt/lyt_texMap.h +++ b/include/nw4r/lyt/lyt_texMap.h @@ -49,12 +49,28 @@ public: void Set(const TexMap &t) { *this = t; } + + // IDK how many of these Sets/ReplaceImage/SetNoWrap actually exist due to version changes + void Set(const GXTexObj &); + void Set(const GXTlutObj &); void Set(TPLPalette *, u32); void Set(const TPLDescriptor *); + void ReplaceImage(const TexMap &); + // guess, between set and replace image which just does the same thing as Set by only Image, Width, Height, and + // format + void ReplaceImage(const GXTexObj &); + void ReplaceImage(TPLPalette *, u32); + void ReplaceImage(const TPLDescriptor *); + void SetNoWrap(const TexMap &); + void SetNoWrap(const GXTexObj &); + void SetNoWrap(TPLPalette *, u32); void SetNoWrap(const TPLDescriptor *); + void SetTexParam(void *pImage, u16 width, u16 height, GXTexFmt format, GXTexWrapMode wrapS, GXTexWrapMode wrapT, + bool); + void *GetImage() const { return mpImage; } @@ -169,11 +185,6 @@ public: mBits.paletteFormat = fmt; } - // ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl - void ReplaceImage(TPLPalette *pal, u32 id); - // ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor - void ReplaceImage(TPLDescriptor *pTPLDesc); - private: void *mpImage; // at 0x00 void *mpPalette; // at 0x04 diff --git a/include/rvl/GX/GXInternal.h b/include/rvl/GX/GXInternal.h index 89507bfd..8d115a80 100644 --- a/include/rvl/GX/GXInternal.h +++ b/include/rvl/GX/GXInternal.h @@ -56,7 +56,27 @@ typedef struct _GXLightObjImpl { } GXLightObjImpl; typedef struct _GXTexObjImpl { - u8 todo[0x20]; + u32 dummy0; // at 0x00 + // -> 0x0x000003 | wrapS + // -> 0x0x00000C | wrapT + // -> 0x00000010 | magFilt + // -> 0x000000E0 | minFilt + // -> 0x00000100 | edgeLODEnable + // -> 0x0001FE00 | lodBias * 32 + // -> 0x00180000 | anisotropy + // -> 0x00200000 | biasClampEn + u32 dummy1; // at 0x04 + // -> 0x000000FF | minLOD * 16 + // -> 0x0000FF00 | maxLOD * 16 + u32 dummy2; // at 0x08 + // -> 0x000003FF | width - 1 + // -> 0x000FFC00 | height - 1 + u32 dummy3; // at 0x0C (( & 0xFFFFFF) << 5 -> ObjData) + u32 userData; // at 0x10 + u32 format; // at 0x14 + u32 tlutName; // at 0x18 + u32 dummy7; // at 0x1C + // -> 0x01000000 | MipMap } GXTexObjImpl; typedef struct _GXTlutObjImpl { diff --git a/include/rvl/GX/GXTexture.h b/include/rvl/GX/GXTexture.h index d6554e19..fa82a9e4 100644 --- a/include/rvl/GX/GXTexture.h +++ b/include/rvl/GX/GXTexture.h @@ -11,13 +11,23 @@ GX_DECL_PUBLIC_STRUCT(GXTlutObj, 12); void __GXSetSUTexRegs(void); -void GXInitTexObj(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8); -void GXInitTexObjLOD(GXTexObj *, GXTexFilter, GXTexFilter, f32, f32, f32, u8, u8, GXAnisotropy); +void GXInitTexObj(GXTexObj *pTexObj, void *pImage, u16 width, u16 height, GXTexFmt format, GXTexWrapMode wrapS, + GXTexWrapMode wrapT, u8 mipmap); +void GXInitTexObjLOD(GXTexObj *pTexObj, GXTexFilter minFilter, GXTexFilter magFilter, f32 minLOD, f32 maxLOD, + f32 LODBias, u8 biasClampEnable, u8 edgeLODEnable, GXAnisotropy anisotropy); void GXInitTexObjTlut(GXTexObj *, u32); +void GXInitTexObjCI(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8, u32); +void GXInitTlutObj(GXTlutObj *, void *, GXTlutFmt, u16); void GXLoadTlut(GXTlutObj *, u32); void GXLoadTexObj(GXTexObj *, GXTexMapID); +void GXGetTexObjAll(const GXTexObj *pTexObj, void **pImage, u16 *width, u16 *height, GXTexFmt *format, + GXTexWrapMode *wrapS, GXTexWrapMode *wrapT, u8 *mipmap); +void GXGetTexObjLODAll(const GXTexObj *pTexObj, GXTexFilter *minFilter, GXTexFilter *magFilter, f32 *minLOD, + f32 *maxLOD, f32 *LODBias, u8 *biasClampEnable, u8 *edgeLODEnable, GXAnisotropy *anisotropy); +u32 GXGetTexObjTlut(GXTexObj *); + #ifdef __cplusplus } #endif diff --git a/src/nw4r/lyt/lyt_texMap.cpp b/src/nw4r/lyt/lyt_texMap.cpp index e69de29b..6b65164a 100644 --- a/src/nw4r/lyt/lyt_texMap.cpp +++ b/src/nw4r/lyt/lyt_texMap.cpp @@ -0,0 +1,205 @@ +#include + +// NOTICE: This file seems to have been reworked. Not sure if all functions exist anymore, ReplaceImage doesnt even +// appear stripped in BBA, but is in tokyo friend park 2 DWARF. In NSMBW there seems to be more parameters for +// ReplaceImage as well. BBA map also shows calls to SetNoWrap from Set (GXTexObj variant), but the actual function +// shows no sign + +namespace nw4r { +namespace lyt { + +namespace { + +// CountLeadingZeros__24@unnamed@lyt_texMap_cpp@FUl + +} // namespace + +// Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj +void TexMap::Get(GXTexObj *pTexObj) const { + if (detail::IsCITexelFormat(GetTexelFormat())) { + u32 tlutName = GXGetTexObjTlut(pTexObj); + GXInitTexObjCI(pTexObj, GetImage(), GetWidth(), GetHeight(), GetTexelFormat(), GetWrapModeS(), GetWrapModeT(), + IsMipMap(), tlutName); + } else { + GXInitTexObj(pTexObj, GetImage(), GetWidth(), GetHeight(), GetTexelFormat(), GetWrapModeS(), GetWrapModeT(), + IsMipMap()); + } + + GXInitTexObjLOD(pTexObj, GetMinFilter(), GetMagFilter(), GetMinLOD(), GetMaxLOD(), GetLODBias(), + IsBiasClampEnable(), IsEdgeLODEnable(), GetAnisotropy()); +} + +// Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj +void TexMap::Get(GXTlutObj *pTLUTObj) const { + GXInitTlutObj(pTLUTObj, GetPalette(), GetPaletteFormat(), GetPaletteEntryNum()); +} + +// Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj +void TexMap::Set(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); + SetWrapMode(wrapS, wrapT); + SetMipMap(mipmap); + + GXTexFilter minFilter, magFilter; + f32 minLOD, maxLOD, LODBias; + u8 biasClampEnable, edgeLODEnable; + GXAnisotropy anisotropy; + GXGetTexObjLODAll(&pTexObj, &minFilter, &magFilter, &minLOD, &maxLOD, &LODBias, &biasClampEnable, &edgeLODEnable, + &anisotropy); + SetFilter(minFilter, magFilter); + SetLOD(minLOD, maxLOD); + SetLODBias(LODBias); + SetBiasClampEnable(biasClampEnable); + SetEdgeLODEnable(edgeLODEnable); + SetAnisotropy(anisotropy); +} + +// Set__Q34nw4r3lyt6TexMapFRC10_GXTlutObj + +// Set__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::Set(TPLPalette *pal, u32 id) { + // Not yet converted from offset to pointer (unbound) + if ((unsigned int)pal->descriptors < 0x80000000) { + TPLBind(pal); + } + + Set(TPLGet(pal, id)); +} + +// Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::Set(const TPLDescriptor *pTPLDesc) { + TPLHeader *tplHead = pTPLDesc->texHeader; + SetImage(tplHead->data); + SetSize(tplHead->width, tplHead->height); + SetTexelFormat(static_cast(tplHead->format)); + + bool bMipMap = (tplHead->minLod != tplHead->maxLod); + SetMipMap(bMipMap); + + SetFilter(tplHead->minFilt, tplHead->magFilt); + SetLOD(tplHead->minLod, tplHead->maxLod); + SetLODBias(tplHead->lodBias); + SetEdgeLODEnable(tplHead->edgeLodEnable); + + TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader; + if (pTPLCLUTHeader != NULL) { + SetPalette(pTPLCLUTHeader->data); + SetPaletteFormat(pTPLCLUTHeader->format); + SetPaletteEntryNum(pTPLCLUTHeader->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFRC10_GXTlutObj +void TexMap::ReplaceImage(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::ReplaceImage(TPLPalette *pal, u32 id) { + // Not yet converted from offset to pointer (unbound) + if ((unsigned int)pal->descriptors < 0x80000000) { + TPLBind(pal); + } + + ReplaceImage(TPLGet(pal, id)); +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::ReplaceImage(const TPLDescriptor *pTPLDesc) { + TPLHeader *tplHead = pTPLDesc->texHeader; + SetImage(tplHead->data); + SetSize(tplHead->width, tplHead->height); + SetTexelFormat(static_cast(tplHead->format)); + + TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader; + if (pTPLCLUTHeader != NULL) { + SetPalette(pTPLCLUTHeader->data); + SetPaletteFormat(pTPLCLUTHeader->format); + SetPaletteEntryNum(pTPLCLUTHeader->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFRCQ34nw4r3lyt6TexMap +void TexMap::SetNoWrap(const TexMap &map) { + GXTexWrapMode wrapS = GetWrapModeS(); + GXTexWrapMode wrapT = GetWrapModeT(); + + Set(map); + SetWrapMode(wrapS, wrapT); +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFRC9_GXTexObj +void TexMap::SetNoWrap(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::SetNoWrap(TPLPalette *pal, u32 id) {} + +// SetNoWrap__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::SetNoWrap(const TPLDescriptor *pDescriptor) { + TPLHeader *tex = pDescriptor->texHeader; + SetImage(tex->data); + SetSize(tex->width, tex->height); + SetTexelFormat(static_cast(tex->format)); + + bool bMipMap = (tex->minLod != tex->maxLod); + SetMipMap(bMipMap); + + SetFilter(tex->minFilt, tex->magFilt); + SetLOD(tex->minLod, tex->maxLod); + SetLODBias(tex->lodBias); + SetEdgeLODEnable(tex->edgeLodEnable); + + TPLClutHeader *clut = pDescriptor->clutHeader; + if (clut != NULL) { + SetPalette(clut->data); + SetPaletteFormat(clut->format); + SetPaletteEntryNum(clut->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// SetTexParam__Q34nw4r3lyt6TexMapFPvUsUs9_GXTexFmt14_GXTexWrapMode14_GXTexWrapModeb + +// SetLODParam__Q34nw4r3lyt6TexMapF12_GXTexFilter12_GXTexFilterfffbb13_GXAnisotropy + +// SetPaletteParam__Q34nw4r3lyt6TexMapFPv10_GXTlutFmtUs + +} // namespace lyt +} // namespace nw4r From 60f795a9d6626a9bd1ba7b82675c34d736c4d6c7 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 6 Jun 2024 23:30:50 -0400 Subject: [PATCH 17/22] lyt_drawInfo OK --- config/SOUE01/splits.txt | 5 +++++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + src/nw4r/lyt/lyt_drawInfo.cpp | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 7e9b5639..829df06b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -376,6 +376,11 @@ nw4r/lyt/lyt_texMap.cpp: .text start:0x804905D0 end:0x80490980 .sdata2 start:0x8057F2A0 end:0x8057F2B4 +nw4r/lyt/lyt_drawInfo.cpp: + .text start:0x80490980 end:0x80490A40 + .data start:0x8056E7A8 end:0x8056E7B4 + .sdata2 start:0x8057F2B8 end:0x8057F2C0 + 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 99bac2dd..5ec068cc 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37083,7 +37083,7 @@ __vt__Q34nw4r3lyt8Bounding = .data:0x8056E6C0; // type:object size:0x74 @LOCAL@SetupGX__Q34nw4r3lyt8MaterialFbUc@kColSels = .data:0x8056E738; // type:object size:0x20 data:4byte @LOCAL@SetupGX__Q34nw4r3lyt8MaterialFbUc@kAlpSels = .data:0x8056E758; // type:object size:0x20 data:4byte __vt__Q34nw4r3lyt8Material = .data:0x8056E778; // type:object size:0x30 -lbl_8056E7A8 = .data:0x8056E7A8; // type:object size:0x10 +__vt__Q34nw4r3lyt8DrawInfo = .data:0x8056E7A8; // type:object size:0xC lbl_8056E7B8 = .data:0x8056E7B8; // type:object size:0x28 __vt__Q34nw4r3lyt16ResourceAccessor = .data:0x8056E7E0; // type:object size:0x14 __vt__Q34nw4r3lyt24MultiArcResourceAccessor = .data:0x8056E7F8; // type:object size:0x14 diff --git a/configure.py b/configure.py index 94e25745..4cea6302 100644 --- a/configure.py +++ b/configure.py @@ -362,6 +362,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), Object(Matching, "nw4r/lyt/lyt_material.cpp"), Object(Matching, "nw4r/lyt/lyt_texMap.cpp"), + Object(Matching, "nw4r/lyt/lyt_drawInfo.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/src/nw4r/lyt/lyt_drawInfo.cpp b/src/nw4r/lyt/lyt_drawInfo.cpp index e69de29b..83b25d92 100644 --- a/src/nw4r/lyt/lyt_drawInfo.cpp +++ b/src/nw4r/lyt/lyt_drawInfo.cpp @@ -0,0 +1,17 @@ +#include +#include + +namespace nw4r { +namespace lyt { + +// __ct__Q34nw4r3lyt8DrawInfoFv +DrawInfo::DrawInfo() : mViewRect(), mScale(1.0f, 1.0f), mGlobalAlpha(1.0f) { + memset(&mFlags, 0, 1); + PSMTXIdentity(mViewMtx); +} + +// __dt__Q34nw4r3lyt8DrawInfoFv +DrawInfo::~DrawInfo() {} + +} // namespace lyt +} // namespace nw4r From f7e702e159da9b3b27acd76c535be10677f30e94 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 8 Jun 2024 15:11:13 -0400 Subject: [PATCH 18/22] template out lyt_animation --- config/SOUE01/splits.txt | 3 + configure.py | 1 + include/nw4r/lyt/lyt_animation.h | 77 +++++--- include/nw4r/lyt/lyt_layout.h | 1 - include/nw4r/lyt/lyt_resources.h | 37 +++- include/nw4r/lyt/lyt_types.h | 18 -- include/nw4r/ut/ut_Color.h | 5 +- src/nw4r/lyt/lyt_animation.cpp | 292 +++++++++++++++++++++++++++++++ src/nw4r/lyt/lyt_pane.cpp | 2 +- 9 files changed, 387 insertions(+), 49 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 829df06b..1f087339 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -381,6 +381,9 @@ nw4r/lyt/lyt_drawInfo.cpp: .data start:0x8056E7A8 end:0x8056E7B4 .sdata2 start:0x8057F2B8 end:0x8057F2C0 +nw4r/lyt/lyt_animation.cpp: + .text start:0x80490A40 end:0x80491FF4 + nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 .data start:0x8056E7E0 end:0x8056E7F8 diff --git a/configure.py b/configure.py index 4cea6302..88f585b2 100644 --- a/configure.py +++ b/configure.py @@ -363,6 +363,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_material.cpp"), Object(Matching, "nw4r/lyt/lyt_texMap.cpp"), Object(Matching, "nw4r/lyt/lyt_drawInfo.cpp"), + Object(NonMatching, "nw4r/lyt/lyt_animation.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 fe11a440..4db537ea 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -2,12 +2,38 @@ #define NW4R_LYT_ANIMATION_H #include "common.h" #include +#include +#include #include #include #include namespace nw4r { namespace lyt { +class AnimTransform { +public: + AnimTransform(); + + u16 GetFrameSize() const; + bool IsLoopData() const; + virtual ~AnimTransform() = 0; // at 0x08 + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) = 0; // at 0x0C + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, // + u16 animNum) = 0; // at 0x10 + virtual void Bind(Pane *pPane, bool bRecursive, bool bDisable) = 0; // at 0x14 + virtual void Bind(Material *pMaterial, bool bDisable) = 0; // at 0x18 + virtual void Animate(u32 idx, Pane *pPane) = 0; // at 0x1C + virtual void Animate(u32 idx, Material *pMaterial) = 0; // at 0x20 + + res::AnimationBlock *GetAnimResource() const { + return mpRes; + } + + ut::LinkListNode mLink; // at 0x4 +protected: + res::AnimationBlock *mpRes; // at 0xC + f32 mFrame; // at 0x10 +}; class AnimResource { public: @@ -18,7 +44,7 @@ public: void Set(const void *anmResBuf); void Init(); u16 GetGroupNum() const; - const AnimationGroupRef *GetGroupArray() const; + AnimationGroupRef *GetGroupArray() const; bool IsDescendingBind() const; u16 GetAnimationShareInfoNum() const; AnimationShareInfo *GetAnimationShareInfoArray() const; @@ -42,6 +68,28 @@ private: const res::AnimationShareBlock *mpShareBlock; // at 0x0C }; +class AnimTransformBasic : public AnimTransform { +public: + AnimTransformBasic(); + AnimationLink *FindUnbindLink(AnimationLink *pLink); + + virtual ~AnimTransformBasic(); // at 0x08 + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor); // at 0x0C + virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum); // at 0x10 + virtual void Bind(Pane *pPane, bool bRecursive, bool bDisable); // at 0x14 + virtual void Bind(Material *pMaterial, bool bDisable); // at 0x18 + virtual void Animate(u32 idx, Pane *pPane); // at 0x1C + virtual void Animate(u32 idx, Material *pMaterial); // at 0x20 + + template + AnimationLink *Bind(T *pTarget, AnimationLink *pAnimLink, u16 idx, bool bDisable); + +private: + void *mpFileResAry; // at 0x14 + AnimationLink *mAnimLinkAry; // at 0x18 + u16 mAnimLinkNum; // at 0x1C +}; + namespace detail { class AnimPaneTree { public: @@ -68,30 +116,11 @@ private: u8 mAnimMatCnt; // at 0x26 }; -} // namespace detail +AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans); +AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes); +void UnbindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans); +void UnbindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes); -class AnimTransformBasic : public AnimTransform { -public: - AnimTransformBasic(); - virtual ~AnimTransformBasic(); // at 0x08 - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor); // at 0x0C - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum); // at 0x10 - virtual void Bind(Pane *pPane, bool bRecursive); // at 0x14 - virtual void Bind(Material *pMaterial, bool bDisable); // at 0x18 - virtual void Animate(u32 idx, Pane *pPane); // at 0x1C - virtual void Animate(u32 idx, Material *pMaterial); // at 0x20 - -private: - void *mpFileResAry; // at 0x14 - AnimationLink *mAnimLinkAry; // at 0x18 - u16 mAnimLinkNum; // at 0x1C -}; - -namespace detail { -void UnbindAnimationLink(ut::LinkList *, AnimTransform *); -AnimationLink *FindAnimationLink(ut::LinkList *, AnimTransform *); -AnimationLink *FindAnimationLink(ut::LinkList *, const AnimResource &); -void UnbindAnimationLink(ut::LinkList *, AnimTransform *); } // namespace detail } // namespace lyt diff --git a/include/nw4r/lyt/lyt_layout.h b/include/nw4r/lyt/lyt_layout.h index 9cbeb585..74b970ad 100644 --- a/include/nw4r/lyt/lyt_layout.h +++ b/include/nw4r/lyt/lyt_layout.h @@ -9,7 +9,6 @@ #include #include - namespace nw4r { namespace lyt { diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index 851c6641..b90e101f 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -276,9 +276,40 @@ struct AnimationShareBlock { u8 padding[2]; // at 0x0E }; -// TODO -struct HermiteKey {}; -struct StepKey {}; +struct HermiteKey { + f32 frame; // at 0x0 + f32 value; // at 0x4 + f32 slope; // at 0x8 +}; + +struct StepKey { + f32 frame; // at 0x0 + u16 value; // at 0x4 + u16 padding; // at 0x6 +}; + +struct AnimationInfo { + u32 kind; // at 0x0 + u8 num; // at 0x4 + u8 padding[3]; // at 0x5 +}; + +struct AnimationTarget { + u8 id; // at 0x0 + u8 target; // at 0x1 + u8 curveType; // at 0x2 + u8 padding1; // at 0x3 + u16 keyNum; // at 0x4 + u16 padding2[2]; // at 0x6 + u32 keyOffset; // at 0x8 +}; + +struct AnimationContent { + char name[20]; // at 0x00 + u8 num; // at 0x14 + u8 type; // at 0x15 + u8 padding[2]; // at 0x17 +}; } // namespace res } // namespace lyt diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index 3f676c68..9648fde0 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -66,24 +66,6 @@ struct Size { 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; // at 0x08 - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) = 0; // at 0x0C - virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, // - u16 animNum) = 0; // at 0x10 - virtual void Bind(Pane *pPane, bool bRecursive) = 0; // at 0x14 - virtual void Bind(Material *pMaterial, bool bDisable) = 0; // at 0x18 - virtual void Animate(u32 idx, Pane *pPane) = 0; // at 0x1C - virtual void Animate(u32 idx, Material *pMaterial) = 0; // at 0x20 - - ut::LinkListNode mLink; // at 0x4 - res::AnimationBlock *mpRes; // at 0xC - f32 mFrame; // at 0x10 -}; struct AnimationShareInfo { const char *GetTargetGroupName() const { return targetGroupName; diff --git a/include/nw4r/ut/ut_Color.h b/include/nw4r/ut/ut_Color.h index f41e9dbe..77b63b36 100644 --- a/include/nw4r/ut/ut_Color.h +++ b/include/nw4r/ut/ut_Color.h @@ -18,7 +18,7 @@ public: Set(red, green, blue, alpha); } Color(const GXColor &clr) { - *this = *(u32 *)&clr; + ToU32ref() = *(u32 *)&clr; } ~Color() {} @@ -35,7 +35,8 @@ public: } Color &operator=(const GXColor &c) { - *(u32 *)this = *(u32 *)&c; // TODO -> This Seems Maybe Wrong + ToU32ref() = *(u32 *)&c; // TODO -> This Seems Maybe Wrong + return *this; } Color operator|(u32 color) { diff --git a/src/nw4r/lyt/lyt_animation.cpp b/src/nw4r/lyt/lyt_animation.cpp index e69de29b..31c7e9ae 100644 --- a/src/nw4r/lyt/lyt_animation.cpp +++ b/src/nw4r/lyt/lyt_animation.cpp @@ -0,0 +1,292 @@ +#include +#include +#include + +namespace nw4r { +namespace lyt { +namespace { + +// GetStepCurveValue__27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl +// GetStepCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl +u16 GetStepCurveValue(f32 frame, const res::StepKey *keyArray, u32 keySize) { + int ikeyL, ikeyR, ikeyCenter; + + const res::StepKey ¢erKey = keyArray[0]; +} + +// RIsSame__27@unnamed@lyt_animation_cpp@Ffff +// RIsSame__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@Ffff +bool RIsSame(f32 a, f32 b, f32 tolerance) { + f32 c; +} + +// GetHermiteCurveValue__27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res10HermiteKeyUl +// GetHermiteCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res10HermiteKeyUl +f32 GetHermiteCurveValue(f32 frame, const res::HermiteKey *keyArray, u32 keySize) { + int ikeyL, ikeyR, ikeyCenter; + const res::HermiteKey &key0 = keyArray[0]; + const res::HermiteKey &key1 = keyArray[0]; + f32 t1, t2; + f32 v0, v1; + f32 s0, s1; + f32 t1t1t2; + f32 t1t1t2t2; + f32 t1t1t1t2t2; + f32 t1t1t1t2t2t2; +} + +// AnimatePainSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimatePaneSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimatePaneSRT(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::HermiteKey *keys; +} + +// AnimateVisibility__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimateVisibility__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimateVisibility(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::StepKey *keys; +} + +// AnimateVertexColor__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimateVertexColor__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimateVertexColor(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::HermiteKey *keys; + f32 value; + u8 u8Val; +} + +// AnimateMaterialColor__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimateMaterialColor__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimateMaterialColor(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, + f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::HermiteKey *keys; + f32 value; + s16 s16Val; +} + +// AnimateTextureSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimateTextureSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimateTextureSRT(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, + f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::HermiteKey *keys; +} + +// AnimateTexturePattern__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlfPPv +// AnimateTexturePattern__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlfPPv +void AnimateTexturePattern(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, + f32 frame, void **tpls) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::StepKey *keys; + u16 fileIdx; +} + +// AnimateIndTexSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +// AnimateIndTexSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf +void AnimateIndTexSRT(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, + f32 frame) { + int i; + const res::AnimationTarget *pAnimTarget; + const res::HermiteKey *keys; +} + +// IsBindAnimation__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPQ34nw4r3lyt13AnimTransform +bool IsBindAnimation(Material *pMaterial, AnimTransform *pAnimTrans) {} + +// IsBindAnimation__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePQ34nw4r3lyt13AnimTransform +bool IsBindAnimation(Pane *pPane, AnimTransform *pAnimTrans) {} + +} // namespace + +// __ct__Q34nw4r3lyt13AnimTransformFv +AnimTransform::AnimTransform() : mLink(), mpRes(NULL), mFrame(0.0f) {} + +// __dt__Q34nw4r3lyt13AnimTransformFv +AnimTransform::~AnimTransform() {} + +// GetFrameSize__Q34nw4r3lyt13AnimTransformCFv +u16 AnimTransform::GetFrameSize() const {} + +// IsLoopData__Q34nw4r3lyt13AnimTransformCFv +bool AnimTransform::IsLoopData() const {} + +// __ct__Q34nw4r3lyt18AnimTransformBasicFv +AnimTransformBasic::AnimTransformBasic() : AnimTransform() {} + +// __dt__Q34nw4r3lyt18AnimTransformBasicFv +AnimTransformBasic::~AnimTransformBasic() {} + +// SetResource__Q34nw4r3lyt18AnimTransformBasicFPCQ44nw4r3lyt3res14AnimationBlockPQ34nw4r3lyt16ResourceAccessor +void AnimTransformBasic::SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) {} + +// SetResource__Q34nw4r3lyt18AnimTransformBasicFPCQ44nw4r3lyt3res14AnimationBlockPQ34nw4r3lyt16ResourceAccessorUs +void AnimTransformBasic::SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum) { + const u32 *fineNameOffsets; + int i; + const char *fileName; +} + +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4Paneb +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4Panebb +void AnimTransformBasic::Bind(Pane *pPane, bool bRecursive, bool bDisable) { + AnimationLink *pCrAnimLink; + const u32 *animContOffsets; + u16 i; + // const res::AnimationContent &animCont; + Pane *pFindPane; + Material *pFindMat; +} + +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8Material +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8Materialb +void AnimTransformBasic::Bind(Material *pMaterial, bool bDisable) { + AnimationLink *pCrAnimLink; + const u32 *animContOffsets; + u16 i; + // const res::AnimationContent &animCont; +} + +// Animate__Q34nw4r3lyt18AnimTransformBasicFUlPQ34nw4r3lyt4Pane +void AnimTransformBasic::Animate(u32 idx, Pane *pPane) { + u32 animContOffsets; + res::AnimationContent *pAnimCont; + const u32 *animInfoOffsets; + int i; + res::AnimationInfo *pAnimInfo; + const u32 *animTargetOffsets; +} + +// Animate__Q34nw4r3lyt18AnimTransformBasicFUlPQ34nw4r3lyt8Material +void AnimTransformBasic::Animate(u32 idx, Material *pMaterial) { + u32 animContOffsets; + res::AnimationContent *pAnimCont; + const u32 *animInfoOffsets; + int i; + res::AnimationInfo *pAnimInfo; + const u32 *animTargetOffsets; +} + +// FindUnbindLink__Q34nw4r3lyt18AnimTransformBasicCFPQ34nw4r3lyt13AnimationLink +AnimationLink *AnimTransformBasic::FindUnbindLink(AnimationLink *pLink) {} + +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4PanePQ34nw4r3lyt13AnimationLinkUsb_PQ34nw4r3lyt13AnimationLink +// Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8MaterialPQ34nw4r3lyt13AnimationLinkUsb_PQ34nw4r3lyt13AnimationLink +template +AnimationLink *AnimTransformBasic::Bind(T *pTarget, AnimationLink *pAnimLink, u16 idx, bool bDisable) {} + +// __ct__Q34nw4r3lyt12AnimResourceFv +AnimResource::AnimResource() {} + +// Set__Q34nw4r3lyt12AnimResourceFPCv +void AnimResource::Set(const void *animResBuf) { + const res::BinaryFileHeader *pFileHeader; + const res::DataBlockHeader *pDataBlockHead; + int i; +} + +// Init__Q34nw4r3lyt12AnimResourceFv +void AnimResource::Init() {} + +// GetGroupNum__Q34nw4r3lyt12AnimResourceCFv +u16 AnimResource::GetGroupNum() const {} + +// GetGroupArray__Q34nw4r3lyt12AnimResourceCFv +AnimationGroupRef *AnimResource::GetGroupArray() const { + const AnimationGroupRef *groups; +} + +// IsDescendingBind__Q34nw4r3lyt12AnimResourceCFv +bool AnimResource::IsDescendingBind() const {} + +// GetAnimationShareInfoNum__Q34nw4r3lyt12AnimResourceCFv +u16 AnimResource::GetAnimationShareInfoNum() const {} + +// GetAnimationShareInfoArray__Q34nw4r3lyt12AnimResourceCFv +AnimationShareInfo *AnimResource::GetAnimationShareInfoArray() const {} + +// CalcAnimationNum__Q34nw4r3lyt12AnimResourceCFPQ34nw4r3lyt4Paneb +u16 AnimResource::CalcAnimationNum(Pane *pPane, bool bRecursive) const { + u16 linkNum; + const u32 *animContOffsets; + u16 i; + // const res::AnimationContent &animCont; + Pane *pFindPane; + Material *pFindMat; +} + +// CalcAnimationNum__Q34nw4r3lyt12AnimResourceCFPQ34nw4r3lyt5Groupb +u16 AnimResource::CalcAnimationNum(Group *pGroup, bool bRecursive) const { + u16 linkNum; + ut::LinkList paneList; + ut::LinkList::Iterator it; +} + +namespace detail { + +// FindAnimContent__Q44nw4r3lyt6detail12AnimPaneTreeFPCQ44nw4r3lyt3res14AnimationBlockPCcUc +u16 AnimPaneTree::FindAnimContent(const res::AnimationBlock *pAnimBlock, const char *animContName, u8 animContType) { + const u32 *animContOffsets; + u16 i; + const res::AnimationContent *pAnimCont; +} + +// Init__Q44nw4r3lyt6detail12AnimPaneTreeFv +void AnimPaneTree::Init() { + u8 i; +} + +// Set__Q44nw4r3lyt6detail12AnimPaneTreeFPQ34nw4r3lyt4PaneRCQ34nw4r3lyt12AnimResource +void AnimPaneTree::Set(Pane *pTargetPane, const AnimResource &animRes) { + u16 linkNum; + const res::AnimationBlock *pAnimBlock; + u16 animContIdx; + u8 animMatCnt; + u16 animMatIdxs[9]; + for (u8 i;;) {} + for (u8 i;;) {} +} + +// Bind__Q44nw4r3lyt6detail12AnimPaneTreeCFPQ34nw4r3lyt6LayoutPQ34nw4r3lyt4PanePQ34nw4r3lyt16ResourceAccessor +AnimTransform *AnimPaneTree::Bind(Layout *pLayout, Pane *pTargetPane, ResourceAccessor *pResAccessor) const { + AnimTransform *pAnimTrans; + AnimationLink *pCrAnimLink; + u8 animMatMax; + u8 i; + Material *pMaterial; +} + +// FindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListPQ34nw4r3lyt13AnimTransform +AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans) { + // it +} + +// FindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListRCQ34nw4r3lyt12AnimResource +AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes) { + // it +} + +// UnbindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListPQ34nw4r3lyt13AnimTransform +void UnbindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans) { + // it, currIt +} + +// UnbindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListRCQ34nw4r3lyt12AnimResource +void UnbindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes) { + // it, currIt +} + +} // namespace detail + +} // namespace lyt + +} // namespace nw4r diff --git a/src/nw4r/lyt/lyt_pane.cpp b/src/nw4r/lyt/lyt_pane.cpp index 02b26c4f..31364e9c 100644 --- a/src/nw4r/lyt/lyt_pane.cpp +++ b/src/nw4r/lyt/lyt_pane.cpp @@ -361,7 +361,7 @@ void Pane::AnimateSelf(u32 option) { // BindAnimation__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransformbb void Pane::BindAnimation(AnimTransform *pAnimTrans, bool bRecursive, bool bDisable) { - pAnimTrans->Bind(this, bRecursive); + pAnimTrans->Bind(this, bRecursive, bDisable); } // UnbindAnimation__Q34nw4r3lyt4PaneFPQ34nw4r3lyt13AnimTransformb From 53aa4e2efa0f5e2d662857ebdb593d33099b86bf Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 9 Jun 2024 21:04:42 -0400 Subject: [PATCH 19/22] lyt_animation *ALMOST* --- config/SOUE01/splits.txt | 2 + config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- include/nw4r/lyt/lyt_animation.h | 35 +- include/nw4r/lyt/lyt_common.h | 5 + include/nw4r/lyt/lyt_material.h | 12 + include/nw4r/lyt/lyt_pane.h | 8 + include/nw4r/lyt/lyt_resources.h | 8 +- include/rvl/OS/OSFastCast.h | 16 + src/nw4r/lyt/lyt_animation.cpp | 584 ++++++++++++++++++++++++------- src/nw4r/lyt/lyt_layout.cpp | 6 +- 11 files changed, 544 insertions(+), 136 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1f087339..5428e745 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -383,6 +383,8 @@ nw4r/lyt/lyt_drawInfo.cpp: nw4r/lyt/lyt_animation.cpp: .text start:0x80490A40 end:0x80491FF4 + .data start:0x8056E7B8 end:0x8056E7DC + .sdata2 start:0x8057F2C0 end:0x8057F2E0 nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 5ec068cc..f309f30a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37084,7 +37084,7 @@ __vt__Q34nw4r3lyt8Bounding = .data:0x8056E6C0; // type:object size:0x74 @LOCAL@SetupGX__Q34nw4r3lyt8MaterialFbUc@kAlpSels = .data:0x8056E758; // type:object size:0x20 data:4byte __vt__Q34nw4r3lyt8Material = .data:0x8056E778; // type:object size:0x30 __vt__Q34nw4r3lyt8DrawInfo = .data:0x8056E7A8; // type:object size:0xC -lbl_8056E7B8 = .data:0x8056E7B8; // type:object size:0x28 +__vt__Q34nw4r3lyt18AnimTransformBasic = .data:0x8056E7B8; // type:object size:0x24 __vt__Q34nw4r3lyt16ResourceAccessor = .data:0x8056E7E0; // type:object size:0x14 __vt__Q34nw4r3lyt24MultiArcResourceAccessor = .data:0x8056E7F8; // type:object size:0x14 __vt__Q34nw4r3lyt19ArcResourceAccessor = .data:0x8056E80C; // type:object size:0x14 diff --git a/configure.py b/configure.py index 88f585b2..80b5fc29 100644 --- a/configure.py +++ b/configure.py @@ -252,7 +252,7 @@ def EGGLib(lib_name, objects): def nw4rLib(lib_name, objects, extra_cflags=[]): return { "lib": lib_name, - "mw_version": "Wii/1.1", # most seem to be around 1.2, snd is 1.6 + "mw_version": "Wii/1.3", # most seem to be around 1.2, snd is 1.6 "cflags": cflags_nw4r + extra_cflags, "host": False, "objects": objects, diff --git a/include/nw4r/lyt/lyt_animation.h b/include/nw4r/lyt/lyt_animation.h index 4db537ea..64e6195c 100644 --- a/include/nw4r/lyt/lyt_animation.h +++ b/include/nw4r/lyt/lyt_animation.h @@ -25,14 +25,24 @@ public: virtual void Animate(u32 idx, Pane *pPane) = 0; // at 0x1C virtual void Animate(u32 idx, Material *pMaterial) = 0; // at 0x20 - res::AnimationBlock *GetAnimResource() const { + f32 GetFrameMax() const { + return mFrame; // TOOD + } + + const res::AnimationBlock *GetAnimResource() const { return mpRes; } + f32 GetFrame() const { + return mFrame; + } + void SetFrame(f32 frame) { + mFrame = frame; + } ut::LinkListNode mLink; // at 0x4 protected: - res::AnimationBlock *mpRes; // at 0xC - f32 mFrame; // at 0x10 + const res::AnimationBlock *mpRes; // at 0xC + f32 mFrame; // at 0x10 }; class AnimResource { @@ -44,10 +54,10 @@ public: void Set(const void *anmResBuf); void Init(); u16 GetGroupNum() const; - AnimationGroupRef *GetGroupArray() const; + const AnimationGroupRef *GetGroupArray() const; bool IsDescendingBind() const; u16 GetAnimationShareInfoNum() const; - AnimationShareInfo *GetAnimationShareInfoArray() const; + const AnimationShareInfo *GetAnimationShareInfoArray() const; u16 CalcAnimationNum(Pane *pPane, bool bRecursive) const; u16 CalcAnimationNum(Group *pGroup, bool bRecursive) const; @@ -71,7 +81,7 @@ private: class AnimTransformBasic : public AnimTransform { public: AnimTransformBasic(); - AnimationLink *FindUnbindLink(AnimationLink *pLink); + AnimationLink *FindUnbindLink(AnimationLink *pLink) const; virtual ~AnimTransformBasic(); // at 0x08 virtual void SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor); // at 0x0C @@ -84,8 +94,12 @@ public: template AnimationLink *Bind(T *pTarget, AnimationLink *pAnimLink, u16 idx, bool bDisable); -private: - void *mpFileResAry; // at 0x14 + AnimationLink *GetAnimLinkAry() const { + return mAnimLinkAry; + } + +protected: + void **mpFileResAry; // at 0x14 AnimationLink *mAnimLinkAry; // at 0x18 u16 mAnimLinkNum; // at 0x1C }; @@ -97,7 +111,10 @@ public: Init(); Set(pTargetPane, animRes); } - bool IsEnabled() const; + bool IsEnabled() const { + // TODO + return false; + } static u16 FindAnimContent(const res::AnimationBlock *pAnimBlock, const char *animContName, u8 animContType); void Init(); void Set(Pane *pTargetPane, const AnimResource &animRes); diff --git a/include/nw4r/lyt/lyt_common.h b/include/nw4r/lyt/lyt_common.h index bd09aae9..ffee8317 100644 --- a/include/nw4r/lyt/lyt_common.h +++ b/include/nw4r/lyt/lyt_common.h @@ -41,6 +41,11 @@ inline void SetVerticalPosition(u8 *pVar, u8 newVal) { *pVar = newVal * 3 + GetHorizontalPosition(*pVar); } +inline const char *GetStrTableStr(const void *pStrTable, int index) { + const u32 *offsets = (u32 *)pStrTable; + const char *stringPool = (char *)pStrTable; + return &stringPool[offsets[index]]; +} typedef math::VEC2 TexCoordData[TEXCOORD_VTX_COUNT]; class TexCoordAry { diff --git a/include/nw4r/lyt/lyt_material.h b/include/nw4r/lyt/lyt_material.h index 3a1d4dce..ec2c924e 100644 --- a/include/nw4r/lyt/lyt_material.h +++ b/include/nw4r/lyt/lyt_material.h @@ -78,8 +78,15 @@ public: } // SetTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf + void SetTexSRTElement(u32 texSRTIdx, u32 eleIdx, f32 value) { + f32 *srtAry = (f32 *)&(GetTexSRTAry()[texSRTIdx]); + srtAry[eleIdx] = value; + } // GetTexturePtr__Q34nw4r3lyt8MaterialFUc + TexMap *GetTexturePtr(u8 idx) { + return &GetTexMapAry()[idx]; + } // GetTexSRTCap__Q34nw4r3lyt8MaterialCFv u8 GetTexSRTCap() const { @@ -90,7 +97,12 @@ public: u8 GetIndTexSRTCap() const { return mGXMemCap.indSRT; } + // SetIndTexSRTElement__Q34nw4r3lyt8MaterialFUlUlf + void SetIndTexSRTElement(u32 texSRTIdx, u32 eleIdx, f32 value) { + f32 *srtAry = (f32 *)&(GetIndTexSRTAry()[texSRTIdx]); + srtAry[eleIdx] = value; + } ut::LinkList *GetAnimationList() { return &mAnimList; diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index 54e16eea..b73d8d30 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -78,6 +78,10 @@ public: mSize = value; } + void SetSRTElement(u32 idx, f32 f) { + ((f32 *)&mTranslate)[idx] = f; + } + const res::ExtUserDataList *GetExtUserDataList() const { return mpExtUserDataList; } @@ -85,6 +89,10 @@ public: mpExtUserDataList = pBlock; } + const char *GetName() const { + return mName; + } + Pane(); Pane(const res::Pane *pBlock); void Init(); diff --git a/include/nw4r/lyt/lyt_resources.h b/include/nw4r/lyt/lyt_resources.h index b90e101f..dcdd27d4 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -30,8 +30,8 @@ struct BinaryFileHeader { }; struct DataBlockHeader { - u32 kind; // at 0x0 - u32 size; // at 0x4 + char kind[4]; // at 0x0 + u32 size; // at 0x4 }; struct TexSRT { @@ -250,7 +250,7 @@ struct WindowContent { struct AnimationBlock { DataBlockHeader blockHeader; // at 0x00 u16 frameSize; // at 0x08 - bool loop; // at 0x0A + u8 loop; // at 0x0A u8 padding1; // at 0x0B u16 fileNum; // at 0x0C u16 animContNum; // at 0x0E @@ -308,7 +308,7 @@ struct AnimationContent { char name[20]; // at 0x00 u8 num; // at 0x14 u8 type; // at 0x15 - u8 padding[2]; // at 0x17 + u8 padding[2]; // at 0x67 }; } // namespace res diff --git a/include/rvl/OS/OSFastCast.h b/include/rvl/OS/OSFastCast.h index 5791018a..8db17517 100644 --- a/include/rvl/OS/OSFastCast.h +++ b/include/rvl/OS/OSFastCast.h @@ -57,11 +57,27 @@ static inline u16 __OSf32tou16(register f32 arg) { r = *(u16 *)ptr; return r; } +static inline u8 __OSf32tou8(register f32 arg) { + f32 a; + register f32 *ptr = &a; + register u8 r; + // clang-format off + asm { + psq_st arg, 0(ptr), 1, 2 + lbz r, 0(ptr) + } + // clang-format on + + return r; +} static inline void OSf32tou16(const f32 *in, u16 *out) { *out = __OSf32tou16(*in); } +static inline void OSf32tou8(const f32 *in, u8 *out) { + *out = __OSf32tou8(*in); +} static inline f32 __OSs16tof32(register const s16 *arg) { register f32 ret; diff --git a/src/nw4r/lyt/lyt_animation.cpp b/src/nw4r/lyt/lyt_animation.cpp index 31c7e9ae..0767b4a9 100644 --- a/src/nw4r/lyt/lyt_animation.cpp +++ b/src/nw4r/lyt/lyt_animation.cpp @@ -1,110 +1,219 @@ #include #include +#include #include namespace nw4r { namespace lyt { namespace { -// GetStepCurveValue__27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl -// GetStepCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl -u16 GetStepCurveValue(f32 frame, const res::StepKey *keyArray, u32 keySize) { - int ikeyL, ikeyR, ikeyCenter; - - const res::StepKey ¢erKey = keyArray[0]; -} - // RIsSame__27@unnamed@lyt_animation_cpp@Ffff // RIsSame__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@Ffff bool RIsSame(f32 a, f32 b, f32 tolerance) { - f32 c; + f32 c = a - b; + return (-tolerance < c && c < tolerance); +} + +// GetStepCurveValue__27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl +// GetStepCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res7StepKeyUl +u16 GetStepCurveValue(f32 frame, const res::StepKey *keyArray, u32 keySize) { + if (keySize == 1 || frame <= keyArray[0].frame) { + return keyArray[0].value; + } + if (frame >= keyArray[keySize - 1].frame) { + return keyArray[keySize - 1].value; + } + + int ikeyL = 0; + int ikeyR = keySize - 1; + while (ikeyL != ikeyR - 1 && ikeyL != ikeyR) { + int ikeyCenter = (ikeyL + ikeyR) / 2; + const res::StepKey ¢erKey = keyArray[ikeyCenter]; + if (frame < centerKey.frame) { + ikeyR = ikeyCenter; + } else { + ikeyL = ikeyCenter; + } + } + + if (RIsSame(frame, keyArray[ikeyR].frame, 0.001f)) { + return keyArray[ikeyR].value; + } else { + return keyArray[ikeyL].value; + } } // GetHermiteCurveValue__27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res10HermiteKeyUl // GetHermiteCurveValue__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FfPCQ44nw4r3lyt3res10HermiteKeyUl f32 GetHermiteCurveValue(f32 frame, const res::HermiteKey *keyArray, u32 keySize) { - int ikeyL, ikeyR, ikeyCenter; - const res::HermiteKey &key0 = keyArray[0]; - const res::HermiteKey &key1 = keyArray[0]; - f32 t1, t2; - f32 v0, v1; - f32 s0, s1; - f32 t1t1t2; - f32 t1t1t2t2; - f32 t1t1t1t2t2; - f32 t1t1t1t2t2t2; + if (keySize == 1 || frame <= keyArray[0].frame) { + return keyArray[0].value; + } + if (frame >= keyArray[keySize - 1].frame) { + return keyArray[keySize - 1].value; + } + + int ikeyL = 0; + int ikeyR = keySize - 1; + while (ikeyL != ikeyR - 1 && ikeyL != ikeyR) { + int ikeyCenter = (ikeyL + ikeyR) / 2; + if (frame <= keyArray[ikeyCenter].frame) { + ikeyR = ikeyCenter; + } else { + ikeyL = ikeyCenter; + } + } + const res::HermiteKey &key0 = keyArray[ikeyL]; + const res::HermiteKey &key1 = keyArray[ikeyR]; + + if (RIsSame(frame, key1.frame, 0.001f)) { + if (ikeyR < keySize - 1 && key1.frame == keyArray[ikeyR + 1].frame) { + return keyArray[ikeyR + 1].value; + } else { + return key1.value; + } + } + + f32 t1 = frame - key0.frame; + f32 t2 = 1.0f / (key1.frame - key0.frame); + + f32 v0 = key0.value; + f32 v1 = key1.value; + f32 s0 = key0.slope; + f32 s1 = key1.slope; + + f32 t1t1t2 = t1 * t1 * t2; + f32 t1t1t2t2 = t1t1t2 * t2; + f32 t1t1t1t2t2 = t1 * t1t1t2t2; + f32 t1t1t1t2t2t2 = t1t1t1t2t2 * t2; + + return v0 * (2.0f * t1t1t1t2t2t2 - 3.0f * t1t1t2t2 + 1.0f) + v1 * (-2.0f * t1t1t1t2t2t2 + 3.0f * t1t1t2t2) + + s0 * (t1 + (t1t1t1t2t2 - 2.0f * t1t1t2)) + s1 * (t1t1t1t2t2 - t1t1t2); } // AnimatePainSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimatePaneSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimatePaneSRT(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::HermiteKey *keys; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + const res::HermiteKey *keys = detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + pPane->SetSRTElement(pAnimTarget->target, GetHermiteCurveValue(frame, keys, pAnimTarget->keyNum)); + } } // AnimateVisibility__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimateVisibility__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimateVisibility(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::StepKey *keys; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + const res::StepKey *keys = detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + pPane->SetVisible(GetStepCurveValue(frame, keys, pAnimTarget->keyNum) != 0); + } } // AnimateVertexColor__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimateVertexColor__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimateVertexColor(Pane *pPane, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::HermiteKey *keys; - f32 value; - u8 u8Val; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + const res::HermiteKey *keys = detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + f32 value = GetHermiteCurveValue(frame, keys, pAnimTarget->keyNum); + value += 0.5f; + u8 u8Val; + OSf32tou8(&value, &u8Val); + pPane->SetColorElement(pAnimTarget->target, u8Val); + } } // AnimateMaterialColor__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimateMaterialColor__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimateMaterialColor(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::HermiteKey *keys; - f32 value; - s16 s16Val; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + const res::HermiteKey *keys = detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + f32 value = GetHermiteCurveValue(frame, keys, pAnimTarget->keyNum); + value += 0.5f; + s16 s16Val; + OSf32tos16(&value, &s16Val); + s16Val = ut::Min(ut::Max(s16Val, -0x400), 1023); + pMaterial->SetColorElement(pAnimTarget->target, s16Val); + } } // AnimateTextureSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimateTextureSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimateTextureSRT(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::HermiteKey *keys; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + if (pAnimTarget->id < pMaterial->GetTexSRTCap()) { + const res::HermiteKey *keys = + detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + + pMaterial->SetTexSRTElement(pAnimTarget->id, pAnimTarget->target, + GetHermiteCurveValue(frame, keys, pAnimTarget->keyNum)); + } + } } // AnimateTexturePattern__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlfPPv // AnimateTexturePattern__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlfPPv void AnimateTexturePattern(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame, void **tpls) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::StepKey *keys; - u16 fileIdx; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + if (pAnimTarget->id < pMaterial->GetTextureNum()) { + const res::StepKey *keys = detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + u16 fileIdx = GetStepCurveValue(frame, keys, pAnimTarget->keyNum); + if (tpls[fileIdx] != nullptr) { + pMaterial->GetTexturePtr(pAnimTarget->id)->ReplaceImage((TPLPalette *)tpls[fileIdx], 0); + } + } + } } // AnimateIndTexSRT__27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf // AnimateIndTexSRT__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPCQ44nw4r3lyt3res13AnimationInfoPCUlf void AnimateIndTexSRT(Material *pMaterial, const res::AnimationInfo *pAnimInfo, const u32 *animTargetOffsets, f32 frame) { - int i; - const res::AnimationTarget *pAnimTarget; - const res::HermiteKey *keys; + for (int i = 0; i < pAnimInfo->num; i++) { + const res::AnimationTarget *pAnimTarget = + detail::ConvertOffsToPtr(pAnimInfo, animTargetOffsets[i]); + if (pAnimTarget->id < pMaterial->GetIndTexSRTCap()) { + const res::HermiteKey *keys = + detail::ConvertOffsToPtr(pAnimTarget, pAnimTarget->keyOffset); + pMaterial->SetIndTexSRTElement(pAnimTarget->id, pAnimTarget->target, + GetHermiteCurveValue(frame, keys, pAnimTarget->keyNum)); + } + } } // IsBindAnimation__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt8MaterialPQ34nw4r3lyt13AnimTransform -bool IsBindAnimation(Material *pMaterial, AnimTransform *pAnimTrans) {} +bool IsBindAnimation(Material *pMaterial, AnimTransform *pAnimTrans) { + return false; // Early return in release builds, no call to FindAnimationLink in SS, exists in tfp2 + + if (pMaterial->FindAnimationLink(pAnimTrans)) { + return true; + } + return false; +} // IsBindAnimation__Q34nw4r3lyt27@unnamed@lyt_animation_cpp@FPQ34nw4r3lyt4PanePQ34nw4r3lyt13AnimTransform -bool IsBindAnimation(Pane *pPane, AnimTransform *pAnimTrans) {} +bool IsBindAnimation(Pane *pPane, AnimTransform *pAnimTrans) { + return false; // Early return in release builds, no call to FindAnimationLink in SS, exists in tfp2 + + if (pPane->FindAnimationLinkSelf(pAnimTrans)) { + return true; + } + return false; +} } // namespace @@ -115,174 +224,413 @@ AnimTransform::AnimTransform() : mLink(), mpRes(NULL), mFrame(0.0f) {} AnimTransform::~AnimTransform() {} // GetFrameSize__Q34nw4r3lyt13AnimTransformCFv -u16 AnimTransform::GetFrameSize() const {} +u16 AnimTransform::GetFrameSize() const { + return mpRes->frameSize; +} // IsLoopData__Q34nw4r3lyt13AnimTransformCFv -bool AnimTransform::IsLoopData() const {} +bool AnimTransform::IsLoopData() const { + return mpRes->loop; +} // __ct__Q34nw4r3lyt18AnimTransformBasicFv -AnimTransformBasic::AnimTransformBasic() : AnimTransform() {} +AnimTransformBasic::AnimTransformBasic() : mpFileResAry(nullptr), mAnimLinkAry(nullptr), mAnimLinkNum(0) {} // __dt__Q34nw4r3lyt18AnimTransformBasicFv -AnimTransformBasic::~AnimTransformBasic() {} +AnimTransformBasic::~AnimTransformBasic() { + Layout::DeletePrimArray(mAnimLinkAry); + Layout::DeletePrimArray(mpFileResAry); +} // SetResource__Q34nw4r3lyt18AnimTransformBasicFPCQ44nw4r3lyt3res14AnimationBlockPQ34nw4r3lyt16ResourceAccessor -void AnimTransformBasic::SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) {} +void AnimTransformBasic::SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor) { + SetResource(pRes, pResAccessor, pRes->animContNum); +} // SetResource__Q34nw4r3lyt18AnimTransformBasicFPCQ44nw4r3lyt3res14AnimationBlockPQ34nw4r3lyt16ResourceAccessorUs void AnimTransformBasic::SetResource(const res::AnimationBlock *pRes, ResourceAccessor *pResAccessor, u16 animNum) { - const u32 *fineNameOffsets; - int i; - const char *fileName; + mpRes = pRes; + mpFileResAry = nullptr; + if (mpRes->fileNum != 0) { + mpFileResAry = Layout::NewArray(mpRes->fileNum); + if (mpFileResAry) { + const u32 *fileNameOffsets = detail::ConvertOffsToPtr(mpRes, sizeof(*mpRes)); + for (int i = 0; i < mpRes->fileNum; i++) { + const char *fileName = detail::GetStrTableStr(fileNameOffsets, i); + mpFileResAry[i] = pResAccessor->GetResource('timg', fileName, nullptr); + } + } + } + + mAnimLinkAry = Layout::NewArray(animNum); + if (mAnimLinkAry) { + mAnimLinkNum = animNum; + } } // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4Paneb // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4Panebb void AnimTransformBasic::Bind(Pane *pPane, bool bRecursive, bool bDisable) { - AnimationLink *pCrAnimLink; - const u32 *animContOffsets; - u16 i; - // const res::AnimationContent &animCont; - Pane *pFindPane; - Material *pFindMat; + AnimationLink *pCrAnimLink = nullptr; + const u32 *animContOffsets = detail::ConvertOffsToPtr(mpRes, mpRes->animContOffsetsOffset); + for (u16 i = 0; i < mpRes->animContNum; i++) { + const res::AnimationContent &animCont = + *detail::ConvertOffsToPtr(mpRes, animContOffsets[i]); + if (animCont.type == 0) { + Pane *pFindPane = pPane->FindPaneByName(animCont.name, bRecursive); + if (pFindPane && !IsBindAnimation(pFindPane, this)) { + pCrAnimLink = Bind(pFindPane, pCrAnimLink, i, bDisable); + if (pCrAnimLink == nullptr) { + break; + } + } + } else { + Material *pFindMat = pPane->FindMaterialByName(animCont.name, bRecursive); + if (pFindMat && !IsBindAnimation(pFindMat, this)) { + pCrAnimLink = Bind(pFindMat, pCrAnimLink, i, bDisable); + if (pCrAnimLink == nullptr) { + break; + } + } + } + } } // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8Material // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8Materialb void AnimTransformBasic::Bind(Material *pMaterial, bool bDisable) { - AnimationLink *pCrAnimLink; - const u32 *animContOffsets; - u16 i; - // const res::AnimationContent &animCont; + AnimationLink *pCrAnimLink = nullptr; + const u32 *animContOffsets = detail::ConvertOffsToPtr(mpRes, mpRes->animContOffsetsOffset); + for (u16 i = 0; i < mpRes->animContNum; i++) { + const res::AnimationContent &animCont = + *detail::ConvertOffsToPtr(mpRes, animContOffsets[i]); + if (animCont.type == 1) { + if (detail::EqualsMaterialName(pMaterial->GetName(), animCont.name) && !IsBindAnimation(pMaterial, this)) { + pCrAnimLink = Bind(pMaterial, pCrAnimLink, i, bDisable); + if (pCrAnimLink == nullptr) { + break; + } + } + } + } } // Animate__Q34nw4r3lyt18AnimTransformBasicFUlPQ34nw4r3lyt4Pane void AnimTransformBasic::Animate(u32 idx, Pane *pPane) { - u32 animContOffsets; - res::AnimationContent *pAnimCont; - const u32 *animInfoOffsets; - int i; - res::AnimationInfo *pAnimInfo; - const u32 *animTargetOffsets; + u32 animContOffsets = detail::ConvertOffsToPtr(mpRes, mpRes->animContOffsetsOffset)[idx]; + const res::AnimationContent *pAnimCont = detail::ConvertOffsToPtr(mpRes, animContOffsets); + const u32 *animInfoOffsets = detail::ConvertOffsToPtr(pAnimCont, sizeof(res::AnimationContent)); + + for (int i = 0; i < pAnimCont->num; i++) { + const res::AnimationInfo *pAnimInfo = + detail::ConvertOffsToPtr(pAnimCont, animInfoOffsets[i]); + const u32 *animTargetOffsets = detail::ConvertOffsToPtr(pAnimInfo, sizeof(res::AnimationInfo)); + switch (pAnimInfo->kind) { + case 'RLPA': + AnimatePaneSRT(pPane, pAnimInfo, animTargetOffsets, mFrame); + break; + case 'RLVI': + AnimateVisibility(pPane, pAnimInfo, animTargetOffsets, mFrame); + break; + case 'RLVC': + AnimateVertexColor(pPane, pAnimInfo, animTargetOffsets, mFrame); + break; + } + } } // Animate__Q34nw4r3lyt18AnimTransformBasicFUlPQ34nw4r3lyt8Material void AnimTransformBasic::Animate(u32 idx, Material *pMaterial) { - u32 animContOffsets; - res::AnimationContent *pAnimCont; - const u32 *animInfoOffsets; - int i; - res::AnimationInfo *pAnimInfo; - const u32 *animTargetOffsets; + u32 animContOffsets = detail::ConvertOffsToPtr(mpRes, mpRes->animContOffsetsOffset)[idx]; + const res::AnimationContent *pAnimCont = detail::ConvertOffsToPtr(mpRes, animContOffsets); + const u32 *animInfoOffsets = detail::ConvertOffsToPtr(pAnimCont, sizeof(res::AnimationContent)); + + for (int i = 0; i < pAnimCont->num; i++) { + const res::AnimationInfo *pAnimInfo = + detail::ConvertOffsToPtr(pAnimCont, animInfoOffsets[i]); + const u32 *animTargetOffsets = detail::ConvertOffsToPtr(pAnimInfo, sizeof(res::AnimationInfo)); + switch (pAnimInfo->kind) { + case 'RLMC': + AnimateMaterialColor(pMaterial, pAnimInfo, animTargetOffsets, mFrame); + break; + case 'RLTS': + AnimateTextureSRT(pMaterial, pAnimInfo, animTargetOffsets, mFrame); + break; + case 'RLTP': + if (mpFileResAry) { + AnimateTexturePattern(pMaterial, pAnimInfo, animTargetOffsets, mFrame, mpFileResAry); + } + break; + case 'RLIM': + AnimateIndTexSRT(pMaterial, pAnimInfo, animTargetOffsets, mFrame); + break; + } + } } // FindUnbindLink__Q34nw4r3lyt18AnimTransformBasicCFPQ34nw4r3lyt13AnimationLink -AnimationLink *AnimTransformBasic::FindUnbindLink(AnimationLink *pLink) {} +AnimationLink *AnimTransformBasic::FindUnbindLink(AnimationLink *pLink) const { + if (pLink == nullptr) { + pLink = mAnimLinkAry; + } + + while (pLink < &mAnimLinkAry[mAnimLinkNum]) { + if (pLink->GetAnimTransform() == nullptr) { + return pLink; + } + pLink++; + } + + return nullptr; +} // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt4PanePQ34nw4r3lyt13AnimationLinkUsb_PQ34nw4r3lyt13AnimationLink // Bind__Q34nw4r3lyt18AnimTransformBasicFPQ34nw4r3lyt8MaterialPQ34nw4r3lyt13AnimationLinkUsb_PQ34nw4r3lyt13AnimationLink template -AnimationLink *AnimTransformBasic::Bind(T *pTarget, AnimationLink *pAnimLink, u16 idx, bool bDisable) {} +AnimationLink *AnimTransformBasic::Bind(T *pTarget, AnimationLink *pAnimLink, u16 idx, bool bDisable) { + pAnimLink = FindUnbindLink(pAnimLink); + if (!pAnimLink) { + return nullptr; + } + pAnimLink->Set(this, idx, bDisable); + pTarget->AddAnimationLink(pAnimLink); + pAnimLink++; + return pAnimLink; +} // __ct__Q34nw4r3lyt12AnimResourceFv -AnimResource::AnimResource() {} +AnimResource::AnimResource() { + Init(); +} // Set__Q34nw4r3lyt12AnimResourceFPCv void AnimResource::Set(const void *animResBuf) { - const res::BinaryFileHeader *pFileHeader; - const res::DataBlockHeader *pDataBlockHead; - int i; + Init(); + const res::BinaryFileHeader *pFileHeader = (res::BinaryFileHeader *)animResBuf; + if (detail::TestFileHeader(*pFileHeader, 'RLAN')) { + if (detail::TestFileVersion(*pFileHeader)) { + mpFileHeader = pFileHeader; + const res::DataBlockHeader *pDataBlockHead = + detail::ConvertOffsToPtr(mpFileHeader, mpFileHeader->headerSize); + for (int i = 0; i < mpFileHeader->dataBlocks; i++) { + switch (detail::GetSignatureInt(pDataBlockHead->kind)) { + case 'pat1': + mpTagBlock = (res::AnimationTagBlock *)pDataBlockHead; + break; + case 'pah1': + mpShareBlock = (res::AnimationShareBlock *)pDataBlockHead; + break; + case 'pai1': + mpResBlock = (res::AnimationBlock *)pDataBlockHead; + break; + } + pDataBlockHead = detail::ConvertOffsToPtr(pDataBlockHead, pDataBlockHead->size); + } + } + } } // Init__Q34nw4r3lyt12AnimResourceFv -void AnimResource::Init() {} +void AnimResource::Init() { + mpFileHeader = nullptr; + mpResBlock = nullptr; + mpTagBlock = nullptr; + mpShareBlock = nullptr; +} // GetGroupNum__Q34nw4r3lyt12AnimResourceCFv -u16 AnimResource::GetGroupNum() const {} +u16 AnimResource::GetGroupNum() const { + if (mpTagBlock) { + return mpTagBlock->groupNum; + } + return 0; +} // GetGroupArray__Q34nw4r3lyt12AnimResourceCFv -AnimationGroupRef *AnimResource::GetGroupArray() const { - const AnimationGroupRef *groups; +const AnimationGroupRef *AnimResource::GetGroupArray() const { + if (mpTagBlock) { + const AnimationGroupRef *groups = + detail::ConvertOffsToPtr(mpTagBlock, mpTagBlock->groupsOffset); + return groups; + } + return nullptr; } // IsDescendingBind__Q34nw4r3lyt12AnimResourceCFv -bool AnimResource::IsDescendingBind() const {} +bool AnimResource::IsDescendingBind() const { + if (mpTagBlock) { + return detail::TestBit(mpTagBlock->flag, 0); + } + return false; +} // GetAnimationShareInfoNum__Q34nw4r3lyt12AnimResourceCFv -u16 AnimResource::GetAnimationShareInfoNum() const {} +u16 AnimResource::GetAnimationShareInfoNum() const { + if (mpShareBlock) { + return mpShareBlock->shareNum; + } + return 0; +} // GetAnimationShareInfoArray__Q34nw4r3lyt12AnimResourceCFv -AnimationShareInfo *AnimResource::GetAnimationShareInfoArray() const {} +const AnimationShareInfo *AnimResource::GetAnimationShareInfoArray() const { + if (mpShareBlock) { + return detail::ConvertOffsToPtr(mpShareBlock, mpShareBlock->animShareInfoOffset); + } + return 0; +} // CalcAnimationNum__Q34nw4r3lyt12AnimResourceCFPQ34nw4r3lyt4Paneb u16 AnimResource::CalcAnimationNum(Pane *pPane, bool bRecursive) const { - u16 linkNum; - const u32 *animContOffsets; - u16 i; - // const res::AnimationContent &animCont; - Pane *pFindPane; - Material *pFindMat; + u16 linkNum = 0; + const u32 *animContOffsets = detail::ConvertOffsToPtr(mpResBlock, mpResBlock->animContOffsetsOffset); + for (u16 i = 0; i < mpResBlock->animContNum; i++) { + const res::AnimationContent &animCont = + *detail::ConvertOffsToPtr(mpResBlock, animContOffsets[i]); + if (animCont.type == 0) { + Pane *pFindPane = pPane->FindPaneByName(animCont.name, bRecursive); + if (pFindPane) { + linkNum++; + } + } else { + Material *pFindMat = pPane->FindMaterialByName(animCont.name, bRecursive); + if (pFindMat) { + linkNum++; + } + } + } + return linkNum; } // CalcAnimationNum__Q34nw4r3lyt12AnimResourceCFPQ34nw4r3lyt5Groupb u16 AnimResource::CalcAnimationNum(Group *pGroup, bool bRecursive) const { - u16 linkNum; - ut::LinkList paneList; - ut::LinkList::Iterator it; + u16 linkNum = 0; + ut::LinkList *paneList = pGroup->GetPaneList(); + for (ut::LinkList::Iterator it = paneList->GetBeginIter(); it != paneList->GetEndIter(); + it++) { + linkNum += CalcAnimationNum(it->mTarget, bRecursive); + } + return linkNum; } namespace detail { // FindAnimContent__Q44nw4r3lyt6detail12AnimPaneTreeFPCQ44nw4r3lyt3res14AnimationBlockPCcUc u16 AnimPaneTree::FindAnimContent(const res::AnimationBlock *pAnimBlock, const char *animContName, u8 animContType) { - const u32 *animContOffsets; - u16 i; - const res::AnimationContent *pAnimCont; + const u32 *animContOffsets = detail::ConvertOffsToPtr(pAnimBlock, pAnimBlock->animContOffsetsOffset); + for (u16 i = 0; i < pAnimBlock->animContNum; i++) { + const res::AnimationContent *pAnimCont = + detail::ConvertOffsToPtr(pAnimBlock, animContOffsets[i]); + if (pAnimCont->type == animContType && EqualsMaterialName(pAnimCont->name, animContName)) { + return i; + } + } + return -1; } // Init__Q44nw4r3lyt6detail12AnimPaneTreeFv void AnimPaneTree::Init() { - u8 i; + mLinkNum = 0; + mAnimPaneIdx = 0; + mAnimMatCnt = 0; + for (u8 i = 0; i < 9; i++) { + mAnimMatIdx[i] = 0; + } } // Set__Q44nw4r3lyt6detail12AnimPaneTreeFPQ34nw4r3lyt4PaneRCQ34nw4r3lyt12AnimResource void AnimPaneTree::Set(Pane *pTargetPane, const AnimResource &animRes) { - u16 linkNum; - const res::AnimationBlock *pAnimBlock; - u16 animContIdx; - u8 animMatCnt; + u16 linkNum = 0; + const res::AnimationBlock *pAnimBlock = animRes.GetResourceBlock(); + + u16 animContIdx = FindAnimContent(pAnimBlock, pTargetPane->GetName(), 0); + if (animContIdx != 0xFFFF) { + linkNum++; + } + + u8 animMatCnt = pTargetPane->GetMaterialNum(); u16 animMatIdxs[9]; - for (u8 i;;) {} - for (u8 i;;) {} + for (u8 i = 0; i < animMatCnt; i++) { + animMatIdxs[i] = FindAnimContent(pAnimBlock, pTargetPane->GetMaterial(i)->GetName(), 1); + if (animMatIdxs[i] != 0xFFFF) { + linkNum++; + } + } + if (linkNum != 0) { + mAnimRes = animRes; + mAnimPaneIdx = animContIdx; + mAnimMatCnt = animMatCnt; + for (u8 i = 0; i < animMatCnt; i++) { + mAnimMatIdx[i] = animMatIdxs[i]; + } + mLinkNum = linkNum; + } } // Bind__Q44nw4r3lyt6detail12AnimPaneTreeCFPQ34nw4r3lyt6LayoutPQ34nw4r3lyt4PanePQ34nw4r3lyt16ResourceAccessor AnimTransform *AnimPaneTree::Bind(Layout *pLayout, Pane *pTargetPane, ResourceAccessor *pResAccessor) const { - AnimTransform *pAnimTrans; - AnimationLink *pCrAnimLink; - u8 animMatMax; - u8 i; - Material *pMaterial; + AnimTransformBasic *pAnimTrans = (AnimTransformBasic *)pLayout->CreateAnimTransform(); + pAnimTrans->SetResource(mAnimRes.GetResourceBlock(), pResAccessor, mLinkNum); + + AnimationLink *pCrAnimLink = nullptr; + if (mAnimPaneIdx != 0xFFFF) { + pCrAnimLink = pAnimTrans->Bind(pTargetPane, nullptr, mAnimPaneIdx, true); + } + + u8 animMatMax = ut::Min(mAnimMatCnt, pTargetPane->GetMaterialNum()); + for (u8 i = 0; i < animMatMax; i++) { + if (mAnimMatIdx[i] != 0xFFFF) { + Material *pMaterial = pTargetPane->GetMaterial(i); + pCrAnimLink = pAnimTrans->Bind(pMaterial, pCrAnimLink, mAnimMatIdx[i], true); + } + } + + return pAnimTrans; } // FindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListPQ34nw4r3lyt13AnimTransform AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans) { - // it + for (ut::LinkList::Iterator it = pAnimList->GetBeginIter(); it != pAnimList->GetEndIter(); it++) { + if (pAnimTrans == it->GetAnimTransform()) { + return &*it; + } + } + return nullptr; } // FindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListRCQ34nw4r3lyt12AnimResource AnimationLink *FindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes) { - // it + for (ut::LinkList::Iterator it = pAnimList->GetBeginIter(); it != pAnimList->GetEndIter(); it++) { + if (animRes.GetResourceBlock() == it->GetAnimTransform()->GetAnimResource()) { + return &*it; + } + } + return nullptr; } // UnbindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListPQ34nw4r3lyt13AnimTransform void UnbindAnimationLink(ut::LinkList *pAnimList, AnimTransform *pAnimTrans) { - // it, currIt + ut::LinkList::Iterator it = pAnimList->GetBeginIter(); + while (it != pAnimList->GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + if (pAnimTrans == nullptr || currIt->GetAnimTransform() == pAnimTrans) { + pAnimList->Erase(currIt); + currIt->Reset(); + } + } } +// Guess, Unused // UnbindAnimationLink__Q34nw4r3lyt6detailFPQ34nw4r2ut38LinkListRCQ34nw4r3lyt12AnimResource void UnbindAnimationLink(ut::LinkList *pAnimList, const AnimResource &animRes) { - // it, currIt + ut::LinkList::Iterator it = pAnimList->GetBeginIter(); + while (it != pAnimList->GetEndIter()) { + ut::LinkList::Iterator currIt = it++; + if (currIt->GetAnimTransform()->GetAnimResource() == animRes.GetResourceBlock()) { + pAnimList->Erase(currIt); + currIt->Reset(); + } + } } } // namespace detail diff --git a/src/nw4r/lyt/lyt_layout.cpp b/src/nw4r/lyt/lyt_layout.cpp index 71a78288..9897363f 100644 --- a/src/nw4r/lyt/lyt_layout.cpp +++ b/src/nw4r/lyt/lyt_layout.cpp @@ -93,7 +93,7 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { const void *dataPtr = ((u8 *)lytResBuf + pFileHead->headerSize); for (int i = 0; i < pFileHead->dataBlocks; i++) { const res::DataBlockHeader *pDataBlockHead = (const res::DataBlockHeader *)dataPtr; - switch (pDataBlockHead->kind) { + switch (detail::GetSignatureInt(pDataBlockHead->kind)) { case 'lyt1': // Main Layout { const res::Layout *pResLyt = ((const res::Layout *)dataPtr); @@ -114,7 +114,7 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { case 'txt1': // Text Box case 'bnd1': // Boundary Pane { - Pane *pPane = BuildPaneObj(pDataBlockHead->kind, dataPtr, resBlockSet); + Pane *pPane = BuildPaneObj(detail::GetSignatureInt(pDataBlockHead->kind), dataPtr, resBlockSet); if (pPane) { if (mpRootPane == nullptr) { mpRootPane = pPane; @@ -164,7 +164,7 @@ bool Layout::Build(const void *lytResBuf, ResourceAccessor *pResAcsr) { // CreateAnimTransform__Q34nw4r3lyt6LayoutFv AnimTransform *Layout::CreateAnimTransform() { - AnimTransform *pAnimTrans = NewObj(); + AnimTransformBasic *pAnimTrans = NewObj(); if (pAnimTrans) { mAnimTransList.PushBack(pAnimTrans); } From 9be76bae31c52a25bc09af65736ff350245669ef Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 9 Jun 2024 21:48:26 -0400 Subject: [PATCH 20/22] adding volatile fixed 1% xD --- include/rvl/OS/OSFastCast.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rvl/OS/OSFastCast.h b/include/rvl/OS/OSFastCast.h index 8db17517..8aa2e04a 100644 --- a/include/rvl/OS/OSFastCast.h +++ b/include/rvl/OS/OSFastCast.h @@ -71,11 +71,11 @@ static inline u8 __OSf32tou8(register f32 arg) { return r; } -static inline void OSf32tou16(const f32 *in, u16 *out) { +static inline void OSf32tou16(const f32 *in, volatile u16 *out) { *out = __OSf32tou16(*in); } -static inline void OSf32tou8(const f32 *in, u8 *out) { +static inline void OSf32tou8(const f32 *in, volatile u8 *out) { *out = __OSf32tou8(*in); } static inline f32 __OSs16tof32(register const s16 *arg) { @@ -109,7 +109,7 @@ static inline s16 __OSf32tos16(register f32 arg) { return r; } -static inline void OSf32tos16(const f32 *in, s16 *out) { +static inline void OSf32tos16(const f32 *in, volatile s16 *out) { *out = __OSf32tos16(*in); } From 793f36d58e8b733f4e1d8084b9a3161cd503a2eb Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 9 Jun 2024 21:56:21 -0400 Subject: [PATCH 21/22] lyt_animation OK --- configure.py | 2 +- include/nw4r/lyt/lyt_resources.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/configure.py b/configure.py index 80b5fc29..08bdcd94 100644 --- a/configure.py +++ b/configure.py @@ -363,7 +363,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_material.cpp"), Object(Matching, "nw4r/lyt/lyt_texMap.cpp"), Object(Matching, "nw4r/lyt/lyt_drawInfo.cpp"), - Object(NonMatching, "nw4r/lyt/lyt_animation.cpp"), + Object(Matching, "nw4r/lyt/lyt_animation.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_resources.h b/include/nw4r/lyt/lyt_resources.h index dcdd27d4..644e6c3f 100644 --- a/include/nw4r/lyt/lyt_resources.h +++ b/include/nw4r/lyt/lyt_resources.h @@ -295,13 +295,13 @@ struct AnimationInfo { }; struct AnimationTarget { - u8 id; // at 0x0 - u8 target; // at 0x1 - u8 curveType; // at 0x2 - u8 padding1; // at 0x3 - u16 keyNum; // at 0x4 - u16 padding2[2]; // at 0x6 - u32 keyOffset; // at 0x8 + u8 id; // at 0x0 + u8 target; // at 0x1 + u8 curveType; // at 0x2 + u8 padding1; // at 0x3 + u16 keyNum; // at 0x4 + u8 padding2[2]; // at 0x6 + u32 keyOffset; // at 0x8 }; struct AnimationContent { From ac1bfd45c6c8eed42ad5038733b3e8271e584a30 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 9 Jun 2024 22:32:39 -0400 Subject: [PATCH 22/22] lyt_util OK --- config/SOUE01/splits.txt | 4 +++ config/SOUE01/symbols.txt | 8 +++--- configure.py | 1 + include/nw4r/lyt/lyt_pane.h | 4 +-- include/nw4r/lyt/lyt_utils.h | 6 ++++ include/nw4r/math/math_types.h | 4 +-- src/nw4r/lyt/lyt_util.cpp | 51 ++++++++++++++++++++++++++++++---- 7 files changed, 64 insertions(+), 14 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 5428e745..d5a1d558 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -401,6 +401,10 @@ nw4r/lyt/lyt_common.cpp: .sdata2 start:0x8057F2E0 end:0x8057F2E8 .bss start:0x80673AA8 end:0x80673AC8 +nw4r/lyt/lyt_util.cpp: + .text start:0x804932E0 end:0x8049350C + .sdata2 start:0x8057F2E8 end:0x8057F2EC + egg/core/eggArchive.cpp: .text start:0x80493510 end:0x80494254 .data start:0x8056E820 end:0x8056E830 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f309f30a..50b4e003 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26116,9 +26116,9 @@ SetVertexFormat__Q34nw4r3lyt6detailFbUc = .text:0x80492B60; // type:function siz DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5Color = .text:0x80492C50; // type:function size:0x560 DrawQuad__Q34nw4r3lyt6detailFRCQ34nw4r4math4VEC2RCQ34nw4r3lyt4SizeUcPA4_CQ34nw4r4math4VEC2PCQ34nw4r2ut5ColorUc = .text:0x804931B0; // type:function size:0x130 BindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb = .text:0x804932E0; // type:function size:0x70 -FUN_80493350 = .text:0x80493350; // type:function size:0x78 -FUN_804933d0 = .text:0x804933D0; // type:function size:0x70 -FUN_80493440 = .text:0x80493440; // type:function size:0xCC +UnbindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformb = .text:0x80493350; // type:function size:0x78 +SetAnimationEnable__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb = .text:0x804933D0; // type:function size:0x70 +IsContain__Q24nw4r3lytFPQ34nw4r3lyt4PaneRCQ34nw4r4math4VEC2 = .text:0x80493440; // type:function size:0xCC readNand__Q23EGG7ArchiveFP12NANDFileInfoPvUll = .text:0x80493510; // type:function size:0x70 __ct__Q23EGG7ArchiveFv = .text:0x80493580; // type:function size:0x70 __dt__Q23EGG7ArchiveFv = .text:0x804935F0; // type:function size:0x6C @@ -47595,7 +47595,7 @@ lbl_8057F2D8 = .sdata2:0x8057F2D8; // type:object size:0x4 data:float lbl_8057F2DC = .sdata2:0x8057F2DC; // type:object size:0x4 data:float lbl_8057F2E0 = .sdata2:0x8057F2E0; // type:object size:0x4 data:float lbl_8057F2E4 = .sdata2:0x8057F2E4; // type:object size:0x4 data:float -lbl_8057F2E8 = .sdata2:0x8057F2E8; // type:object size:0x8 data:float +lbl_8057F2E8 = .sdata2:0x8057F2E8; // type:object size:0x4 data:float eggAllocatorFuncs = .sdata2:0x8057F2F0; // type:object size:0x8 scope:local lbl_8057F2F8 = .sdata2:0x8057F2F8; // type:object size:0x4 data:float lbl_8057F300 = .sdata2:0x8057F300; // type:object size:0x8 data:double diff --git a/configure.py b/configure.py index 08bdcd94..ba317b47 100644 --- a/configure.py +++ b/configure.py @@ -367,6 +367,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_resourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), + Object(Matching, "nw4r/lyt/lyt_util.cpp"), ], [""] ), # EGG diff --git a/include/nw4r/lyt/lyt_pane.h b/include/nw4r/lyt/lyt_pane.h index b73d8d30..20c38ed3 100644 --- a/include/nw4r/lyt/lyt_pane.h +++ b/include/nw4r/lyt/lyt_pane.h @@ -50,8 +50,8 @@ public: return &mAnimList; } - const math::MTX34 *GetGlobalMtx() const { - return &mGlbMtx; + const math::MTX34 &GetGlobalMtx() const { + return mGlbMtx; } Pane *GetParent() const { return mpParent; diff --git a/include/nw4r/lyt/lyt_utils.h b/include/nw4r/lyt/lyt_utils.h index 3c5a72fd..d5ffcb18 100644 --- a/include/nw4r/lyt/lyt_utils.h +++ b/include/nw4r/lyt/lyt_utils.h @@ -8,6 +8,12 @@ namespace nw4r { namespace lyt { void BindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive, bool bDisable); +void UnbindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecusive); +void SetAnimationEnable(Group *pGroup, AnimTransform *pAnimTrans, bool bEnable, bool bRecursive); +bool IsContain(Pane *pPane, const math::VEC2 &pos); +Pane *FindHitPane(Pane *pPane, const math::VEC2 &pos); +Pane *FindHitPane(Layout *pLayout, const math::VEC2 &pos); +Pane *GetNextPane(Pane *); } // namespace lyt diff --git a/include/nw4r/math/math_types.h b/include/nw4r/math/math_types.h index f08094d4..08843736 100644 --- a/include/nw4r/math/math_types.h +++ b/include/nw4r/math/math_types.h @@ -209,10 +209,10 @@ struct MTX34 : _MTX34 { } // clang-format on - operator MtxRef() { + inline operator MtxRef() { return mtx; } - operator MtxRefConst() const { + inline operator MtxRefConst() const { return mtx; } }; diff --git a/src/nw4r/lyt/lyt_util.cpp b/src/nw4r/lyt/lyt_util.cpp index 972ab47e..33bba481 100644 --- a/src/nw4r/lyt/lyt_util.cpp +++ b/src/nw4r/lyt/lyt_util.cpp @@ -1,7 +1,8 @@ -#include -#include +#include +#include #include +#include #include namespace nw4r { @@ -9,22 +10,60 @@ namespace lyt { namespace { // Contains__Q34nw4r3lyt22@unnamed@lyt_util_cpp@FRCQ34nw4r2ut4RectRCQ34nw4r4math4VEC2 -bool Contains(const ut::Rect &rect, const math::VEC2 &point) {} +bool Contains(const ut::Rect &rect, const math::VEC2 &point) { + return (rect.left <= point.x && point.x <= rect.right) && (rect.bottom <= point.y && point.y <= rect.top); +} + } // namespace // BindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb -void BindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive, bool bDisable) {} +void BindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive, bool bDisable) { + ut::LinkList &paneList = *pGroup->GetPaneList(); + for (ut::LinkList::Iterator it = paneList.GetBeginIter(); it != paneList.GetEndIter(); it++) { + it->mTarget->BindAnimation(pAnimTrans, bRecursive, bDisable); + } +} + +// UnbindAnimation__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformb +void UnbindAnimation(Group *pGroup, AnimTransform *pAnimTrans, bool bRecursive) { + ut::LinkList &paneList = *pGroup->GetPaneList(); + for (ut::LinkList::Iterator it = paneList.GetBeginIter(); it != paneList.GetEndIter(); it++) { + it->mTarget->UnbindAnimation(pAnimTrans, bRecursive); + } +} // SetAnimationEnable__Q24nw4r3lytFPQ34nw4r3lyt5GroupPQ34nw4r3lyt13AnimTransformbb -void SetAnimationEnable(Group *pGroup, nw4r::lyt::AnimTransform *pAnimTrans, bool bEnable, bool bRecursive) {} +void SetAnimationEnable(Group *pGroup, nw4r::lyt::AnimTransform *pAnimTrans, bool bEnable, bool bRecursive) { + ut::LinkList &paneList = *pGroup->GetPaneList(); + for (ut::LinkList::Iterator it = paneList.GetBeginIter(); it != paneList.GetEndIter(); it++) { + it->mTarget->SetAnimationEnable(pAnimTrans, bEnable, bRecursive); + } +} // IsContain__Q24nw4r3lytFPQ34nw4r3lyt4PaneRCQ34nw4r4math4VEC2 bool IsContain(Pane *pPane, const math::VEC2 &pos) { - return false; + math::MTX34 invGlbMtx; + PSMTXInverse(pPane->GetGlobalMtx(), invGlbMtx); + math::VEC3 lclPos; + PSMTXMultVec(invGlbMtx, math::VEC3(pos.x, pos.y, 0.0f), lclPos); + return Contains(pPane->GetPaneRect(), math::VEC2(lclPos.x, lclPos.y)); } // FindHitPane__Q24nw4r3lytFPQ34nw4r3lyt4PaneRCQ34nw4r4math4VEC2 Pane *FindHitPane(Pane *pPane, const math::VEC2 &pos) { + // TODO + return nullptr; +} + +// FindHitPane__Q24nw4r3lytFPQ34nw4r3lyt6LayoutRCQ34nw4r4math4VEC2 +Pane *FindHitPane(Layout *pLayout, const math::VEC2 &pos) { + // TODO + return nullptr; +} + +// GetNextPane__Q24nw4r3lytFPQ34nw4r3lyt4Pane +Pane *GetNextPane(Pane *) { + // TODO return nullptr; }