diff options
| author | LagoLunatic <LagoLunatic@users.noreply.github.com> | 2025-06-18 01:11:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-17 22:11:53 -0700 |
| commit | 23cba4d117cc34f4fafce838eed8cef103fce79c (patch) | |
| tree | 8d1aeb54e8b34697797384b4c980c77d847683a2 /include/JSystem | |
| parent | 5a13ca438a89c34d706432792d5257fcb2ad6b83 (diff) | |
getDemoIDData matched, fix up various inlines and template classes (#2489)
* Fix debug build
* getDemoIDData matched, fix up various inlines and template classes
* Remove nonmatching comments
Diffstat (limited to 'include/JSystem')
| -rw-r--r-- | include/JSystem/JGadget/binary.h | 98 | ||||
| -rw-r--r-- | include/JSystem/JStudio/JStudio/object-id.h | 2 | ||||
| -rw-r--r-- | include/JSystem/JStudio/JStudio/stb-data-parse.h | 13 | ||||
| -rw-r--r-- | include/JSystem/JStudio/JStudio/stb.h | 45 | ||||
| -rw-r--r-- | include/JSystem/JUtility/JUTFader.h | 2 | ||||
| -rw-r--r-- | include/JSystem/JUtility/TColor.h | 5 |
6 files changed, 115 insertions, 50 deletions
diff --git a/include/JSystem/JGadget/binary.h b/include/JSystem/JGadget/binary.h index 71be3ed553..24f7c96085 100644 --- a/include/JSystem/JGadget/binary.h +++ b/include/JSystem/JGadget/binary.h @@ -2,6 +2,7 @@ #define BINARY_H #include "dolphin/types.h" +#include "JSystem/JGadget/search.h" namespace JGadget { namespace binary { @@ -26,11 +27,11 @@ struct TParseData { /* 0x0 */ const void* raw; }; -template <int T> +template <int S> struct TParseData_aligned : public TParseData { TParseData_aligned(const void* pContent) : TParseData(pContent) {} void setRaw(const void* p) { - /* if ((u32)p % T != 0) { + /* if ((u32)p % S != 0) { JUTWarn w; w << "misaligned : " << (u32)p; } */ @@ -63,41 +64,56 @@ struct TParse_header_block { template <typename T> struct TParseValue_raw_ { typedef T ParseType; - static T parse(const void* data) { return *(T*)data; } + static T parse(const void* data) { return (T)*(T*)data; } +}; + +template <typename T> +struct TParseValue_raw : public TParseValue_raw_<T> { + typedef TParseValue_raw_<T> InnerParseValueClass; }; template <typename T> struct TParseValue_endian_big_ : public TParseValue_raw_<T> { - static T parse(const void* data) { return TParseValue_raw_::parse(data); } + static T parse(const void* data) { return TParseValue_raw_<T>::parse(data); } }; -template <typename T, template <class> class Parser> -struct TParseValue : public Parser<T> { - static T parse(const void* data) { return Parser<T>::parse(data); } +template <class Parser> +struct TParseValue : public Parser { + static typename Parser::ParseType parse(const void* data) { return Parser::parse(data); } - static T parse(const void* data, s32 advanceNum) { - return Parser<T>::parse(advance(data, advanceNum)); + static typename Parser::ParseType parse(const void* data, s32 advanceNum) { + return Parser::parse(advance(data, advanceNum)); } static const void* advance(const void* data, s32 advanceNum) { - return (char*)data + (advanceNum * sizeof(T)); + return (char*)data + (advanceNum * sizeof(Parser::ParseType)); } }; template<class Parser, int size> -struct TValueIterator { +struct TValueIterator + : public JGadget::TIterator< + std::random_access_iterator_tag, + typename Parser::ParseType, + ptrdiff_t, + typename Parser::ParseType*, + typename Parser::ParseType& + > + { + typedef typename Parser::ParseType ValueType; + TValueIterator(const void* begin) { - mBegin = begin; + mBegin = reinterpret_cast<const char*>(begin); } const void* get() const { return mBegin; } typename Parser::ParseType operator*() const { - return Parser::parse(get()); + return TParseValue<typename Parser::InnerParseValueClass>::parse(get()); } TValueIterator& operator++() { - const_cast<u32*>(mBegin)++; + mBegin += size; return *this; } @@ -107,31 +123,67 @@ struct TValueIterator { return old; } - TValueIterator& operator+=(s32 v) { - const_cast<u32*>(mBegin) += v; + TValueIterator& operator+=(s32 n) { + mBegin += size * n; + return *this; + } + + TValueIterator& operator--() { + mBegin -= size; return *this; } - const void* mBegin; + char const* mBegin; }; template<typename T> -struct TValueIterator_raw : public TValueIterator<TParseValue_raw_<u8>, 1> { - TValueIterator_raw(const void* begin) : TValueIterator<TParseValue_raw_<u8>, 1>(begin) {} +struct TValueIterator_raw : public TValueIterator<TParseValue_raw<T>, sizeof(T)> { + TValueIterator_raw(const void* begin) : TValueIterator<TParseValue_raw<T>, sizeof(T)>(begin) {} + + friend bool operator==(TValueIterator<TParseValue_raw<T>, sizeof(T)> a, TValueIterator<TParseValue_raw<T>, sizeof(T)> b) { + return a.mBegin == b.mBegin; + } + + friend bool operator!=(TValueIterator<TParseValue_raw<T>, sizeof(T)> a, TValueIterator<TParseValue_raw<T>, sizeof(T)> b) { + return !operator==(a, b); + } + + friend TValueIterator<TParseValue_raw<T>, sizeof(T)> operator+(TValueIterator<TParseValue_raw<T>, sizeof(T)> a, s32 b) { + TValueIterator<TParseValue_raw<T>, sizeof(T)> it = a; + it += b; + return it; + } +}; + +template <typename T> +struct TParseValue_misaligned_ : public TParseValue_raw_<T> { + typedef T ParseType; + static T parse(const void* data) { return TParseValue_raw_<T>::parse(data); } }; template <typename T> -struct TParseValue_misaligned : TParseValue_raw_<T> { - static T parse(const void* data) { return TParseValue_raw_::parse(data); } +struct TParseValue_misaligned : public TParseValue_raw_<T> { + typedef TParseValue_misaligned_<T> InnerParseValueClass; }; template<typename T> struct TValueIterator_misaligned : public TValueIterator<TParseValue_misaligned<T>, sizeof(T)> { TValueIterator_misaligned(const void* begin) : TValueIterator<TParseValue_misaligned<T>, sizeof(T)>(begin) {} -}; + friend bool operator==(TValueIterator<TParseValue_misaligned<T>, sizeof(T)> a, TValueIterator<TParseValue_misaligned<T>, sizeof(T)> b) { + return a.mBegin == b.mBegin; + } + + friend bool operator!=(TValueIterator<TParseValue_misaligned<T>, sizeof(T)> a, TValueIterator<TParseValue_misaligned<T>, sizeof(T)> b) { + return !operator==(a, b); + } -inline bool operator==(TValueIterator<TParseValue_misaligned<u32>, 4> a, TValueIterator<TParseValue_misaligned<u32>, 4> b) { return a.mBegin == b.mBegin; } + friend TValueIterator<TParseValue_misaligned<T>, sizeof(T)> operator+(TValueIterator<TParseValue_misaligned<T>, sizeof(T)> a, s32 b) { + TValueIterator<TParseValue_misaligned<T>, sizeof(T)> it(a); + it += b; + return it; + } +}; } // namespace binary } // namespace JGadget diff --git a/include/JSystem/JStudio/JStudio/object-id.h b/include/JSystem/JStudio/JStudio/object-id.h index bd8ebf7234..cd05ef494b 100644 --- a/include/JSystem/JStudio/JStudio/object-id.h +++ b/include/JSystem/JStudio/JStudio/object-id.h @@ -28,7 +28,7 @@ struct TObject_ID : public TIDData { struct TPRObject_ID_equal : public TIDData { TPRObject_ID_equal(const void* id, u32 id_size) : TIDData(id, id_size) {} - TPRObject_ID_equal(const TPRObject_ID_equal& other) : TIDData(other.mID, other.mID_size) {} + ~TPRObject_ID_equal() {} bool operator()(TObject_ID const& id) const { return TIDData::isEqual(id.getIDData(), *this); } }; diff --git a/include/JSystem/JStudio/JStudio/stb-data-parse.h b/include/JSystem/JStudio/JStudio/stb-data-parse.h index f8c5bd470f..57ba3378d8 100644 --- a/include/JSystem/JStudio/JStudio/stb-data-parse.h +++ b/include/JSystem/JStudio/JStudio/stb-data-parse.h @@ -65,16 +65,16 @@ public: /* 80289A08 */ void getData(TData*) const; }; -struct TParse_TParagraph_data : public TParseData_aligned<4> { +struct TParse_TParagraph_data : public TParseData { struct TData { /* 0x00 */ u8 status; - /* 0x04 */ u32 dataSize; - /* 0x08 */ u32 _8; - /* 0x0C */ const void* fileCount; - /* 0x10 */ const void* _10; + /* 0x04 */ u32 entrySize; + /* 0x08 */ u32 entryCount; + /* 0x0C */ const void* content; + /* 0x10 */ const void* next; }; - TParse_TParagraph_data(const void* content) : TParseData_aligned<4>(content) {} + TParse_TParagraph_data(const void* content) : TParseData(content) {} /* 80289A80 */ void getData(TData* pData) const; }; @@ -90,7 +90,6 @@ public: u16 get_flag() const { return get()->flag; } u16 get_IDSize() const { return get()->id_size; } - u32 get_type() const { return get()->type; } const void* get_ID() const { return get()->id; } }; diff --git a/include/JSystem/JStudio/JStudio/stb.h b/include/JSystem/JStudio/JStudio/stb.h index 6582961688..eae49feced 100644 --- a/include/JSystem/JStudio/JStudio/stb.h +++ b/include/JSystem/JStudio/JStudio/stb.h @@ -7,7 +7,7 @@ #include "dolphin/os.h" namespace JStudio { -struct TObject; +class TObject; namespace stb { class TControl; @@ -156,11 +156,10 @@ private: /* 0x54 */ s32 _54; }; -template <int T> +template <int S> struct TParseData : public data::TParse_TParagraph_data::TData { TParseData(const void* pContent) { - data::TParse_TParagraph_data data(pContent); - set(data); + set(data::TParse_TParagraph_data(pContent)); } TParseData() { @@ -171,45 +170,57 @@ struct TParseData : public data::TParse_TParagraph_data::TData { data.getData(this); } + void set(const void* pContent) { + set(data::TParse_TParagraph_data(pContent)); + } + bool isEnd() const { return status == 0; } bool empty() const { - return fileCount == NULL; + return content == NULL; } bool isValid() const { - return !empty() && status == 50; + return !empty() && status == S; } - const void* getContent() const { return fileCount; } + const void* getContent() const { return content; } - u32 size() const { return dataSize; } + u32 size() const { return entryCount; } }; -template <int T, class Iterator=JGadget::binary::TValueIterator_raw<u8> > -struct TParseData_fixed : public TParseData<T> { - TParseData_fixed(const void* pContent) : TParseData<T>(pContent) {} - TParseData_fixed() : TParseData<T>() {} +template <int S, class Iterator=JGadget::binary::TValueIterator_raw<u8> > +struct TParseData_fixed : public TParseData<S> { + TParseData_fixed(const void* pContent) : TParseData<S>(pContent) {} + TParseData_fixed() : TParseData<S>() {} const void* getNext() const { - return _10; + return this->next; } bool isValid() const { - return TParseData::isValid() && getNext() != NULL; + return TParseData<S>::isValid() && getNext() != NULL; } Iterator begin() const { - return Iterator(fileCount); + return Iterator(this->content); } Iterator end() const { - Iterator i(fileCount); - i += size(); + Iterator i(this->content); + i += this->size(); return i; } + + typename Iterator::ValueType front() const { + return *begin(); + } + + typename Iterator::ValueType back() const { + return *--end(); + } }; struct TParseData_string : public TParseData<0x60> { diff --git a/include/JSystem/JUtility/JUTFader.h b/include/JSystem/JUtility/JUTFader.h index 7c308269a7..f6d67ac03b 100644 --- a/include/JSystem/JUtility/JUTFader.h +++ b/include/JSystem/JUtility/JUTFader.h @@ -25,7 +25,7 @@ public: /* 802E56DC */ virtual void draw(); s32 getStatus() const { return mStatus; } - void setColor(JUtility::TColor& color) { mColor.set(color); } + void setColor(JUtility::TColor color) { mColor.set(color); } /* 0x04 */ s32 mStatus; /* 0x08 */ u16 field_0x8; diff --git a/include/JSystem/JUtility/TColor.h b/include/JSystem/JUtility/TColor.h index 2691dff536..0f2a684289 100644 --- a/include/JSystem/JUtility/TColor.h +++ b/include/JSystem/JUtility/TColor.h @@ -28,7 +28,10 @@ struct TColor : public GXColor { } void set(u32 u32Color) { *(u32*)&r = u32Color; } - void set(GXColor gxColor) { *(GXColor*)&r = gxColor; } + void set(GXColor gxColor) { + GXColor* temp = this; + *temp = gxColor; + } }; } // namespace JUtility |
