From ba75752e148a2ac81e9fc0dc27c85b76ef98364e Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 1 Oct 2022 01:32:56 -0700 Subject: [PATCH] Match CFontImageDef, can't link due to extraneous TToken destructor Former-commit-id: 77b921601a56b7339b62f6617192b0533a22f7a7 --- asm/Collision/InternalColliders.s | 3 +- asm/Dolphin/thp/THPDec.s | 3 -- asm/Kyoto/Text/CFontImageDef.s | 1 - include/Kyoto/CObjectReference.hpp | 47 ++++++++++++++++++++++++++ include/Kyoto/CToken.hpp | 3 +- include/Kyoto/CVParamTransfer.hpp | 15 +++++++++ include/Kyoto/Graphics/CTexture.hpp | 7 +++- include/Kyoto/IObjectStore.hpp | 49 +--------------------------- include/Kyoto/TToken.hpp | 2 +- include/Kyoto/Text/CFontImageDef.hpp | 30 +++++++++++++++++ include/rstl/vector.hpp | 16 +++++++++ src/Kyoto/Text/CFontImageDef.cpp | 38 +++++++++++++++++++++ 12 files changed, 157 insertions(+), 57 deletions(-) create mode 100644 include/Kyoto/CObjectReference.hpp create mode 100644 include/Kyoto/CVParamTransfer.hpp create mode 100644 include/Kyoto/Text/CFontImageDef.hpp create mode 100644 src/Kyoto/Text/CFontImageDef.cpp diff --git a/asm/Collision/InternalColliders.s b/asm/Collision/InternalColliders.s index b09f1400..42a95b9e 100644 --- a/asm/Collision/InternalColliders.s +++ b/asm/Collision/InternalColliders.s @@ -103,8 +103,7 @@ AddTypes__17InternalCollidersFv: lbl_803D6A20: # ROM: 0x3D3A20 .asciz "CCollidableAABox" - .byte 0x43, 0x43, 0x6F - .asciz "llidableSphere" + .asciz "CCollidableSphere" .balign 4 .4byte 0 diff --git a/asm/Dolphin/thp/THPDec.s b/asm/Dolphin/thp/THPDec.s index 195ed9eb..9bf6fcc6 100644 --- a/asm/Dolphin/thp/THPDec.s +++ b/asm/Dolphin/thp/THPDec.s @@ -949,9 +949,6 @@ lbl_803C2720: /* 803C2724 003BF684 7C 06 00 AE */ lbzx r0, r6, r0 /* 803C2728 003BF688 28 00 00 00 */ cmplwi r0, 0 /* 803C272C 003BF68C 40 82 FF BC */ bne lbl_803C26E8 - -.global sub_803c2730 -sub_803c2730: /* 803C2730 003BF690 4E 80 00 20 */ blr .global __THPHuffGenerateDecoderTables diff --git a/asm/Kyoto/Text/CFontImageDef.s b/asm/Kyoto/Text/CFontImageDef.s index 18847d81..1b961e47 100644 --- a/asm/Kyoto/Text/CFontImageDef.s +++ b/asm/Kyoto/Text/CFontImageDef.s @@ -245,4 +245,3 @@ lbl_803D8348: # ROM: 0x3D5348 .asciz "??(??)" .balign 4 - diff --git a/include/Kyoto/CObjectReference.hpp b/include/Kyoto/CObjectReference.hpp new file mode 100644 index 00000000..eeb4ca6d --- /dev/null +++ b/include/Kyoto/CObjectReference.hpp @@ -0,0 +1,47 @@ +#ifndef __COBJECTREFERENCE_HPP__ +#define __COBJECTREFERENCE_HPP__ + +#include +#include + + +#define kInvalidAssetId 0xFFFFFFFFu + +typedef uint CAssetId; +typedef uint FourCC; + +struct SObjectTag { + FourCC type; + CAssetId id; + + SObjectTag() {} + SObjectTag(FourCC type, CAssetId id) : type(type), id(id) {} + SObjectTag(const SObjectTag& other) : type(other.type), id(other.id) {} +}; + +class IObj; +class IObjectStore; +class CObjectReference { +public: + CObjectReference(const rstl::auto_ptr< IObj >& obj); + // : x0_refCount(0) + // , x2_locked(false) + // , x2_lockCount(0) + // , xc_objectStore(nullptr) + // , x10_object(obj.release()) + // , x14_params(CVParamTransfer::Null()) {} + + CObjectReference(IObjectStore* store, const rstl::auto_ptr< IObj >& obj, SObjectTag tag, + CVParamTransfer xfer); + + bool IsLoaded() const { return x10_object != nullptr; } +private: + u16 x0_refCount; + bool x2_locked : 1; + u16 x2_lockCount : 15; + SObjectTag x4_objTag; + IObjectStore* xc_objectStore; + IObj* x10_object; + CVParamTransfer x14_params; +}; +#endif // __COBJECTREFERENCE_HPP__ diff --git a/include/Kyoto/CToken.hpp b/include/Kyoto/CToken.hpp index 2119e2dd..65069ed4 100644 --- a/include/Kyoto/CToken.hpp +++ b/include/Kyoto/CToken.hpp @@ -4,6 +4,7 @@ #include "types.h" #include "Kyoto/IObj.hpp" +#include "Kyoto/CObjectReference.hpp" class CObjectReference; @@ -18,7 +19,7 @@ public: CObjOwnerDerivedFromIObjUntyped* GetObj(); void Lock(); - + bool IsLoaded() const { return x0_objRef->IsLoaded(); } private: CObjectReference* x0_objRef; bool x4_lockHeld; diff --git a/include/Kyoto/CVParamTransfer.hpp b/include/Kyoto/CVParamTransfer.hpp new file mode 100644 index 00000000..6b62e7ad --- /dev/null +++ b/include/Kyoto/CVParamTransfer.hpp @@ -0,0 +1,15 @@ +#ifndef __CVPARAMTRANSFER_HPP__ +#define __CVPARAMTRANSFER_HPP__ + +#include + +class IObj; +class CVParamTransfer { +public: + static CVParamTransfer Null(); + +private: + rstl::rc_ptr< unkptr > x0_; +}; + +#endif // __CVPARAMTRANSFER_HPP__ diff --git a/include/Kyoto/Graphics/CTexture.hpp b/include/Kyoto/Graphics/CTexture.hpp index c88f2c10..2937e9d0 100644 --- a/include/Kyoto/Graphics/CTexture.hpp +++ b/include/Kyoto/Graphics/CTexture.hpp @@ -27,8 +27,13 @@ public: static void InvalidateTexmap(GXTexMapID id); + s16 GetWidth() const { return mWidth; } + s16 GetHeight() const { return mHeight; } private: - u8 pad[0x68]; + u32 mTexelFormat; // TODO: Enum + s16 mWidth; + s16 mHeight; + u8 pad[0x60]; }; #endif diff --git a/include/Kyoto/IObjectStore.hpp b/include/Kyoto/IObjectStore.hpp index dc2f79da..c191fcf3 100644 --- a/include/Kyoto/IObjectStore.hpp +++ b/include/Kyoto/IObjectStore.hpp @@ -2,58 +2,11 @@ #define _IOBJECTSTORE_HPP #include "types.h" +#include "Kyoto/CToken.hpp" #include "rstl/auto_ptr.hpp" #include "rstl/rc_ptr.hpp" -#define kInvalidAssetId 0xFFFFFFFFu - -typedef uint CAssetId; -typedef uint FourCC; - -struct SObjectTag { - FourCC type; - CAssetId id; - - SObjectTag() {} - SObjectTag(FourCC type, CAssetId id) : type(type), id(id) {} - SObjectTag(const SObjectTag& other) : type(other.type), id(other.id) {} -}; - -class IObjectStore; -class IObj; -class CVParamTransfer { -public: - static CVParamTransfer Null(); - -private: - rstl::rc_ptr< unkptr > x0_; -}; -class CObjectReference { -public: - CObjectReference(const rstl::auto_ptr< IObj >& obj); - // : x0_refCount(0) - // , x2_locked(false) - // , x2_lockCount(0) - // , xc_objectStore(nullptr) - // , x10_object(obj.release()) - // , x14_params(CVParamTransfer::Null()) {} - - CObjectReference(IObjectStore* store, const rstl::auto_ptr< IObj >& obj, SObjectTag tag, - CVParamTransfer xfer); - -private: - u16 x0_refCount; - bool x2_locked : 1; - u16 x2_lockCount : 15; - SObjectTag x4_objTag; - IObjectStore* xc_objectStore; - IObj* x10_object; - CVParamTransfer x14_params; -}; - -class CToken; - class IObjectStore { public: virtual CToken GetObj(const SObjectTag& tag, CVParamTransfer xfer) = 0; diff --git a/include/Kyoto/TToken.hpp b/include/Kyoto/TToken.hpp index 40f8b7cd..6ba63ae4 100644 --- a/include/Kyoto/TToken.hpp +++ b/include/Kyoto/TToken.hpp @@ -16,7 +16,7 @@ public: TToken(const CToken& token) : CToken(token) {} TToken(T* obj) : CToken(TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj).release()) {} TToken(const rstl::auto_ptr< T >& obj) : CToken(GetIObjObjectFor(obj).release()) {} - + T* GetT() { return reinterpret_cast< T* >(CToken::GetObj()->GetContents()); } T* operator*() { return GetT(); } diff --git a/include/Kyoto/Text/CFontImageDef.hpp b/include/Kyoto/Text/CFontImageDef.hpp new file mode 100644 index 00000000..c8ad700a --- /dev/null +++ b/include/Kyoto/Text/CFontImageDef.hpp @@ -0,0 +1,30 @@ +#ifndef __CFONTIMAGEDEF_HPP__ +#define __CFONTIMAGEDEF_HPP__ + +#include +#include +#include +#include + +class CTexture; +class CVector2f; +class CFontImageDef { +public: + CFontImageDef(const TToken< CTexture >& texture, const CVector2f& cropFactor); + CFontImageDef(const rstl::vector< TToken< CTexture > >& texture, float fps, + const CVector2f& cropFactor); + bool IsLoaded() const; + //inline short GetWidth() { } + int GetHeight() { + TToken tex = mTextures[0]; + return tex.GetT()->GetHeight() * mCropFactor.GetY(); + } + int CalculateBaseline(); + +private: + float mFPS; + rstl::vector< TToken< CTexture > > mTextures; + CVector2f mCropFactor; +}; + +#endif // __CFONTIMAGEDEF__ diff --git a/include/rstl/vector.hpp b/include/rstl/vector.hpp index 62c15ea1..eba4927a 100644 --- a/include/rstl/vector.hpp +++ b/include/rstl/vector.hpp @@ -40,6 +40,22 @@ public: inline const_iterator end() const { return const_iterator(xc_items + x4_count); } inline vector() : x4_count(0), x8_capacity(0), xc_items(NULL) {} inline vector(int count) : x4_count(0), x8_capacity(0), xc_items(0) { reserve(count); } + inline explicit vector(const T& v) : x4_count(1), x8_capacity(1) { + if (x4_count * sizeof(T) == 0) { + xc_items = NULL; + } else { + x0_allocator.allocate(xc_items, x4_count * sizeof(T)); + } + new (&xc_items[0]) T(v); + } + vector(int count, const T& v) : x4_count(count), x8_capacity(count) { + if (x4_count * sizeof(T) == 0) { + xc_items = NULL; + } else { + x0_allocator.allocate(xc_items, x4_count * sizeof(T)); + } + uninitialized_fill_n(xc_items, x8_capacity, v); + } vector(const vector& other) { x4_count = other.x4_count; x8_capacity = other.x8_capacity; diff --git a/src/Kyoto/Text/CFontImageDef.cpp b/src/Kyoto/Text/CFontImageDef.cpp new file mode 100644 index 00000000..2ca5f0ec --- /dev/null +++ b/src/Kyoto/Text/CFontImageDef.cpp @@ -0,0 +1,38 @@ +#include +#include + +CFontImageDef::CFontImageDef(const TToken< CTexture >& texture, const CVector2f& cropFactor) +: mFPS(0.f), mTextures(texture), mCropFactor(cropFactor) { + rstl::vector< TToken< CTexture > >::iterator it = mTextures.begin(); + + for (; it != mTextures.end(); ++it) { + it->Lock(); + } +} + +CFontImageDef::CFontImageDef(const rstl::vector< TToken< CTexture > >& textures, float fps, + const CVector2f& cropFactor) +: mFPS(fps), mTextures(textures), mCropFactor(cropFactor) { + rstl::vector< TToken< CTexture > >::iterator it = mTextures.begin(); + for (; it != mTextures.end(); ++it) { + it->Lock(); + } +} + +bool CFontImageDef::IsLoaded() const { + for (int i = 0; i < mTextures.size(); ++i) { + if (!mTextures[i].IsLoaded()) { + return false; + } + } + + return true; +} + +int CFontImageDef::CalculateBaseline() { + int height; + + height = GetHeight(); + + return (height * 2.5f) / 3.f; +}