From 17c163dca9a2cece8f73be396d649f2d567b9b68 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 31 May 2026 15:31:49 +0200 Subject: [PATCH] Import JStudio from TP --- config/SOUE01/splits.txt | 5 +- config/SOUE01/symbols.txt | 2 +- configure.py | 26 +- include/JSystem/JGadget/binary.h | 189 +++ include/JSystem/JGadget/define.h | 73 + include/JSystem/JGadget/linklist.h | 350 +++++ include/JSystem/JGadget/pointer.h | 33 + include/JSystem/JGadget/search.h | 166 +++ include/JSystem/JGadget/std-memory.h | 39 + include/JSystem/JGadget/std-vector.h | 224 +++ include/JSystem/JStudio/JStudio/ctb-data.h | 4 + include/JSystem/JStudio/JStudio/ctb.h | 157 +++ .../JSystem/JStudio/JStudio/functionvalue.h | 550 ++++++++ .../JSystem/JStudio/JStudio/fvb-data-parse.h | 51 + include/JSystem/JStudio/JStudio/fvb-data.h | 68 + include/JSystem/JStudio/JStudio/fvb.h | 160 +++ .../JSystem/JStudio/JStudio/jstudio-control.h | 305 ++++ .../JSystem/JStudio/JStudio/jstudio-data.h | 11 + .../JSystem/JStudio/JStudio/jstudio-math.h | 68 + .../JSystem/JStudio/JStudio/jstudio-object.h | 462 +++++++ include/JSystem/JStudio/JStudio/object-id.h | 43 + .../JSystem/JStudio/JStudio/stb-data-parse.h | 112 ++ include/JSystem/JStudio/JStudio/stb-data.h | 69 + include/JSystem/JStudio/JStudio/stb.h | 250 ++++ include/JSystem/JUtility/JUTAssert.h | 1 + include/rvl/MTX/mtx.h | 4 +- src/JSystem/JGadget/binary.cpp | 79 ++ src/JSystem/JGadget/linklist.cpp | 168 +++ src/JSystem/JGadget/std-vector.cpp | 23 + src/JSystem/JStudio/JStudio/ctb-data.cpp | 3 + src/JSystem/JStudio/JStudio/ctb.cpp | 139 ++ src/JSystem/JStudio/JStudio/functionvalue.cpp | 902 ++++++++++++ .../JStudio/JStudio/fvb-data-parse.cpp | 16 + src/JSystem/JStudio/JStudio/fvb-data.cpp | 3 + src/JSystem/JStudio/JStudio/fvb.cpp | 459 +++++++ .../JStudio/JStudio/jstudio-control.cpp | 192 +++ src/JSystem/JStudio/JStudio/jstudio-data.cpp | 3 + src/JSystem/JStudio/JStudio/jstudio-math.cpp | 67 + .../JStudio/JStudio/jstudio-object.cpp | 1222 +++++++++++++++++ src/JSystem/JStudio/JStudio/object-id.cpp | 53 + .../JStudio/JStudio/stb-data-parse.cpp | 82 ++ src/JSystem/JStudio/JStudio/stb-data.cpp | 4 + src/JSystem/JStudio/JStudio/stb.cpp | 485 +++++++ src/JSystem/TPosition3.h | 89 ++ .../MSL/MSL_C++/MSL_Common/Include/algorithm | 11 +- .../MSL/MSL_C++/MSL_Common/Include/limits | 2 +- src/egg/gfx/eggDrawGX.cpp | 6 +- 47 files changed, 7400 insertions(+), 30 deletions(-) create mode 100644 include/JSystem/JGadget/binary.h create mode 100644 include/JSystem/JGadget/define.h create mode 100644 include/JSystem/JGadget/linklist.h create mode 100644 include/JSystem/JGadget/pointer.h create mode 100644 include/JSystem/JGadget/search.h create mode 100644 include/JSystem/JGadget/std-memory.h create mode 100644 include/JSystem/JGadget/std-vector.h create mode 100644 include/JSystem/JStudio/JStudio/ctb-data.h create mode 100644 include/JSystem/JStudio/JStudio/ctb.h create mode 100644 include/JSystem/JStudio/JStudio/functionvalue.h create mode 100644 include/JSystem/JStudio/JStudio/fvb-data-parse.h create mode 100644 include/JSystem/JStudio/JStudio/fvb-data.h create mode 100644 include/JSystem/JStudio/JStudio/fvb.h create mode 100644 include/JSystem/JStudio/JStudio/jstudio-control.h create mode 100644 include/JSystem/JStudio/JStudio/jstudio-data.h create mode 100644 include/JSystem/JStudio/JStudio/jstudio-math.h create mode 100644 include/JSystem/JStudio/JStudio/jstudio-object.h create mode 100644 include/JSystem/JStudio/JStudio/object-id.h create mode 100644 include/JSystem/JStudio/JStudio/stb-data-parse.h create mode 100644 include/JSystem/JStudio/JStudio/stb-data.h create mode 100644 include/JSystem/JStudio/JStudio/stb.h create mode 100644 src/JSystem/JGadget/binary.cpp create mode 100644 src/JSystem/JGadget/linklist.cpp create mode 100644 src/JSystem/JGadget/std-vector.cpp create mode 100644 src/JSystem/JStudio/JStudio/ctb-data.cpp create mode 100644 src/JSystem/JStudio/JStudio/ctb.cpp create mode 100644 src/JSystem/JStudio/JStudio/functionvalue.cpp create mode 100644 src/JSystem/JStudio/JStudio/fvb-data-parse.cpp create mode 100644 src/JSystem/JStudio/JStudio/fvb-data.cpp create mode 100644 src/JSystem/JStudio/JStudio/fvb.cpp create mode 100644 src/JSystem/JStudio/JStudio/jstudio-control.cpp create mode 100644 src/JSystem/JStudio/JStudio/jstudio-data.cpp create mode 100644 src/JSystem/JStudio/JStudio/jstudio-math.cpp create mode 100644 src/JSystem/JStudio/JStudio/jstudio-object.cpp create mode 100644 src/JSystem/JStudio/JStudio/object-id.cpp create mode 100644 src/JSystem/JStudio/JStudio/stb-data-parse.cpp create mode 100644 src/JSystem/JStudio/JStudio/stb-data.cpp create mode 100644 src/JSystem/JStudio/JStudio/stb.cpp create mode 100644 src/JSystem/TPosition3.h diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 9e47132a7..25f247294 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -5358,15 +5358,16 @@ JSystem/JStudio/JStudio_JStage/object-message.cpp: .text start:0x804C3870 end:0x804C39D4 align:16 .data start:0x80570378 end:0x805703A0 -toBeSorted/JSystem/unk_jstage_maybe.cpp: +JSystem/JStage/unk_jstage_maybe.cpp: .text start:0x804C39E0 end:0x804C3FC8 align:16 .rodata start:0x804FBF98 end:0x804FBFA8 .data start:0x805703A0 end:0x805703B8 - .sdata2 start:0x8057F9A0 end:0x8057F9B8 + .sdata2 start:0x8057F9A0 end:0x8057F9A8 JSystem/JStudio/JStudio_JParticle/control.cpp: .text start:0x804C3FD0 end:0x804C42CC align:16 .data start:0x805703B8 end:0x805703D0 + .sdata2 start:0x8057F9A8 end:0x8057F9B8 JSystem/JStudio/JStudio_JParticle/object-particle.cpp: .text start:0x804C42D0 end:0x804C53DC align:16 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 2803de4a6..b6ca8c573 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -27040,7 +27040,7 @@ parseBlock_block_ctb___Q27JStudio6TParseFRCQ47JStudio3stb4data13TParse_TBlockUl getRotation_xyz__Q27JStudio4mathFPA4_ffff = .text:0x804BD110; // type:function size:0x16C getTransformation_SRxyzT__Q27JStudio4mathFPA4_fRC3VecRC3VecRC3Vec = .text:0x804BD280; // type:function size:0x90 getFromTransformation_SRxyzT__Q27JStudio4mathFP3VecP3VecP3VecPA4_Cf = .text:0x804BD310; // type:function size:0x2CC -__sinit_\jstudio_math_cpp = .text:0x804BD5E0; // type:function size:0xC scope:local +__sinit_\jstudio-math_cpp = .text:0x804BD5E0; // type:function size:0xC scope:local __dt__Q37JStudio14TVariableValue7TOutputFv = .text:0x804BD5F0; // type:function size:0x40 update__Q27JStudio14TVariableValueFdPQ27JStudio8TAdaptor = .text:0x804BD630; // type:function size:0x64 update_immediate___Q27JStudio14TVariableValueFPQ27JStudio14TVariableValued = .text:0x804BD6A0; // type:function size:0x14 diff --git a/configure.py b/configure.py index 8d8cd555e..55bf63328 100644 --- a/configure.py +++ b/configure.py @@ -1355,8 +1355,8 @@ def MatchingFor(*versions): JSystemLib( "JGadget", [ - Object(NonMatching, "JSystem/JGadget/binary.cpp"), - Object(NonMatching, "JSystem/JGadget/linklist.cpp"), + Object(Matching, "JSystem/JGadget/binary.cpp"), + Object(Matching, "JSystem/JGadget/linklist.cpp"), Object(NonMatching, "JSystem/JGadget/std-vector.cpp"), ], ), @@ -1364,19 +1364,19 @@ def MatchingFor(*versions): "JStudio", [ Object(NonMatching, "JSystem/JStudio/JStudio/ctb.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/ctb-data.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/ctb-data.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/functionvalue.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/fvb.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/fvb-data.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/fvb-data-parse.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/fvb-data.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/fvb-data-parse.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/jstudio-control.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/jstudio-data.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/jstudio-data.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/jstudio-math.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/jstudio-object.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/object-id.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/object-id.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/stb.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/stb-data.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/stb-data-parse.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/stb-data.cpp"), + Object(Matching, "JSystem/JStudio/JStudio/stb-data-parse.cpp"), ], ), JSystemLib( @@ -1388,8 +1388,12 @@ def MatchingFor(*versions): Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object-camera.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object-light.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object-message.cpp"), - # this one is hard to identify - Object(NonMatching, "toBeSorted/JSystem/unk_jstage_maybe.cpp"), + ], + ), + JSystemLib( + "JStage", + [ + Object(NonMatching, "JSystem/JStage/unk_jstage_maybe.cpp"), ], ), JSystemLib( diff --git a/include/JSystem/JGadget/binary.h b/include/JSystem/JGadget/binary.h new file mode 100644 index 000000000..f395076c0 --- /dev/null +++ b/include/JSystem/JGadget/binary.h @@ -0,0 +1,189 @@ +#ifndef JGADGET_BINARY_H +#define JGADGET_BINARY_H + +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JGadget/search.h" + +namespace JGadget { +namespace binary { + +struct TEBit { + u32 value; +}; + +const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second, TEBit* tebit); + +inline bool isPower2(unsigned int arg0) { + return arg0 != 0 && (arg0 & arg0 - 1) == 0; +} + +inline u32 align_roundUp(unsigned int arg0, unsigned int uAlign) { + JUT_ASSERT(98, isPower2(uAlign)); + return (arg0 + uAlign - 1) & ~(uAlign - 1); +} + +struct TParseData { + TParseData(const void* pContent) : raw(pContent) {} + + const void* getRaw() const { return raw; } + void setRaw(const void* p) { raw = p; } + + /* 0x0 */ const void* raw; +}; + +template +struct TParseData_aligned : public TParseData { + TParseData_aligned(const void* pContent) : TParseData(pContent) {} + void setRaw(const void* p) { + /* if ((u32)p % S != 0) { + JUTWarn w; + w << "misaligned : " << (u32)p; + } */ + static_cast(this)->setRaw(p); + } +}; + +// Base for header and/or block parsing +struct TParse_header_block { + virtual ~TParse_header_block() = 0; + + virtual bool parseHeader_next(const void** ppData_inout, u32* puBlock_out, u32 arg2) = 0; + virtual bool parseBlock_next(const void** ppData_inout, u32* puData_out, u32 arg2) = 0; + + bool parse_next(const void** ppData_inout, u32 a2); + + bool parse(const void* ppData_inout, u32 a2) { + return parse_next(&ppData_inout, a2); + } +}; + +template +struct TParseValue_raw_ { + typedef T ParseType; + static T parse(const void* data) { return (T)*(T*)data; } +}; + +template +struct TParseValue_raw : public TParseValue_raw_ { + typedef TParseValue_raw_ InnerParseValueClass; +}; + +template +struct TParseValue_endian_big_ : public TParseValue_raw_ { + static T parse(const void* data) { return TParseValue_raw_::parse(data); } +}; + +template +struct TParseValue : public Parser { + static typename Parser::ParseType parse(const void* data) { return Parser::parse(data); } + + 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(typename Parser::ParseType)); + } +}; + +template +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 = reinterpret_cast(begin); + bool unused = false; + (void)&unused; + } + + const void* get() const { return mBegin; } + + typename Parser::ParseType operator*() const { + return TParseValue::parse(get()); + } + + TValueIterator& operator++() { + mBegin += size; + return *this; + } + + const TValueIterator operator++(int) { + TValueIterator old(*this); + ++(*this); + return old; + } + + TValueIterator& operator+=(s32 n) { + mBegin += size * n; + return *this; + } + + TValueIterator& operator--() { + mBegin -= size; + return *this; + } + + char const* mBegin; +}; + +template +struct TValueIterator_raw : public TValueIterator, sizeof(T)> { + TValueIterator_raw(const void* begin) : TValueIterator, sizeof(T)>(begin) {} + + friend bool operator==(TValueIterator, sizeof(T)> a, TValueIterator, sizeof(T)> b) { + return a.mBegin == b.mBegin; + } + + friend bool operator!=(TValueIterator, sizeof(T)> a, TValueIterator, sizeof(T)> b) { + return !operator==(a, b); + } + + friend TValueIterator, sizeof(T)> operator+(TValueIterator, sizeof(T)> a, s32 b) { + TValueIterator, sizeof(T)> it = a; + it += b; + return it; + } +}; + +template +struct TParseValue_misaligned_ : public TParseValue_raw_ { + typedef T ParseType; + static T parse(const void* data) { return TParseValue_raw_::parse(data); } +}; + +template +struct TParseValue_misaligned : public TParseValue_raw_ { + typedef TParseValue_misaligned_ InnerParseValueClass; +}; + +template +struct TValueIterator_misaligned : public TValueIterator, sizeof(T)> { + TValueIterator_misaligned(const void* begin) : TValueIterator, sizeof(T)>(begin) {} + + friend bool operator==(TValueIterator, sizeof(T)> a, TValueIterator, sizeof(T)> b) { + return a.mBegin == b.mBegin; + } + + friend bool operator!=(TValueIterator, sizeof(T)> a, TValueIterator, sizeof(T)> b) { + return !operator==(a, b); + } + + friend TValueIterator, sizeof(T)> operator+(TValueIterator, sizeof(T)> a, s32 b) { + TValueIterator, sizeof(T)> it(a); + it += b; + return it; + } +}; + +} // namespace binary +} // namespace JGadget + +#endif /* JGADGET_BINARY_H */ diff --git a/include/JSystem/JGadget/define.h b/include/JSystem/JGadget/define.h new file mode 100644 index 000000000..5ad6e58ad --- /dev/null +++ b/include/JSystem/JGadget/define.h @@ -0,0 +1,73 @@ +#ifndef JGADGET_DEFINE_H +#define JGADGET_DEFINE_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { + +class JGadget_outMessage { +public: + typedef void (*MessageFunc)(const char*, int, const char*); + + static void warning(const char*, int, const char*); + + JGadget_outMessage(MessageFunc fn, const char* file, int line); + ~JGadget_outMessage(); + + JGadget_outMessage& operator<<(int param_1) { return *this << (s32)param_1; } + JGadget_outMessage& operator<<(u16); + JGadget_outMessage& operator<<(unsigned); + JGadget_outMessage& operator<<(u8 param_1) { return *this << (char)param_1; } + JGadget_outMessage& operator<<(const char* str); + JGadget_outMessage& operator<<(char); + JGadget_outMessage& operator<<(s32); + JGadget_outMessage& operator<<(u32); + JGadget_outMessage& operator<<(const void*); + + static const int BUFFER_SIZE = 256; + +private: + MessageFunc mMsgFunc; + char mBuffer[BUFFER_SIZE]; + char* mWrite_p; + const char* mFile; + int mLine; +}; + +#if DEBUG + +#define JGADGET_ASSERTWARN(line, COND) \ + ((COND)) || (JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << #COND, false); + +#define JGADGET_WARNMSG(line, msg) \ + JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << msg, false; + +#define JGADGET_WARNMSG1(line, msg, arg) \ + JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \ + out << msg << (arg); + +#define JGADGET_WARNMSG3(line, msg, arg1, arg2, arg3) \ + JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \ + out << msg << (arg1) << (arg2) << (arg3); + +#define JGADGET_WARNMSG4(line, msg, arg1, arg2, arg3, arg4) \ + JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \ + out << msg << (arg1) << (arg2) << (arg3) << (arg4); + +#define JGADGET_EXITWARN(line, COND) \ + if (!(COND)) { \ + JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << #COND, false; \ + return false; \ + } +#else +#define JGADGET_ASSERTWARN(line, COND) (void)0 +#define JGADGET_WARNMSG(line, msg) (void)0 +#define JGADGET_WARNMSG1(line, msg, arg) (void)0 +#define JGADGET_WARNMSG4(line, msg, arg1, arg2, arg3, arg4) (void)0 +#define JGADGET_EXITWARN(line, COND) (void)0 +#endif +} +#endif + +#endif diff --git a/include/JSystem/JGadget/linklist.h b/include/JSystem/JGadget/linklist.h new file mode 100644 index 000000000..578d77d7f --- /dev/null +++ b/include/JSystem/JGadget/linklist.h @@ -0,0 +1,350 @@ +#ifndef LINKLIST_H +#define LINKLIST_H + +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JGadget/search.h" +#include + + +namespace JGadget { +struct TLinkListNode { + TLinkListNode() { + pNext_ = NULL; + pPrev_ = NULL; + } + + ~TLinkListNode() { +#if DEBUG + JGADGET_ASSERTWARN(77, pNext_==NULL); + JGADGET_ASSERTWARN(78, pPrev_==NULL); +#endif + } + + TLinkListNode* getNext() const { return pNext_; } + TLinkListNode* getPrev() const { return pPrev_; } + void clear_() { pNext_ = NULL; pPrev_ = NULL; } + +public: + /* 0x0 */ TLinkListNode* pNext_; + /* 0x4 */ TLinkListNode* pPrev_; +}; // Size: 0x8 + +struct TNodeLinkList { + struct iterator : public std::iterator { + iterator() { p_ = NULL; } + explicit iterator(TLinkListNode* pNode) { p_ = pNode; } + iterator& operator=(const iterator& other) { p_ = other.p_; return *this; } + + iterator& operator++() { p_ = p_->getNext(); return *this; } + iterator& operator--() { p_ = p_->getPrev(); return *this; } + iterator operator++(int) { const iterator old(*this); (void)++*this; return old; } + iterator operator--(int) { const iterator old(*this); (void)--*this; return old; } + friend bool operator==(iterator a, iterator b) { return a.p_ == b.p_; } + friend bool operator!=(iterator a, iterator b) { return !(a == b); } + + TLinkListNode* operator->() const { return p_; } + TLinkListNode& operator*() const { + JUT_ASSERT(196, p_!=NULL); + return *p_; + } + + public: + /* 0x00 */ TLinkListNode* p_; + }; + + struct const_iterator { + explicit const_iterator(const TLinkListNode* pNode) { p_ = pNode; } + explicit const_iterator(const iterator it) { p_ = it.p_; } + + const_iterator& operator++() { p_ = p_->getNext(); return *this; } + const_iterator& operator--() { p_ = p_->getPrev(); return *this; } + const_iterator operator++(int) { const const_iterator old(*this); (void)++*this; return old; } + const_iterator operator--(int) { const const_iterator old(*this); (void)--*this; return old; } + friend bool operator==(const_iterator a, const_iterator b) { return a.p_ == b.p_; } + friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); } + + friend bool operator==(const_iterator a, iterator b) { return a.p_ == b.p_; } + friend bool operator!=(const_iterator a, iterator b) { return !(a == b); } + + const TLinkListNode* operator->() const { return p_; } + const TLinkListNode& operator*() const { return *p_; } + + public: + /* 0x00 */ const TLinkListNode* p_; + }; + + TNodeLinkList() : oNode_() { Initialize_(); } + ~TNodeLinkList(); + + void Initialize_() { + count = 0; + oNode_.pNext_ = &oNode_; + oNode_.pPrev_ = &oNode_; + } + + iterator begin() { return iterator(oNode_.getNext()); } + const_iterator begin() const { return const_iterator(oNode_.getNext()); } + iterator end() { return iterator(&oNode_); } + const_iterator end() const { return const_iterator((TLinkListNode*)(&oNode_)); } + u32 size() const { return count; } + bool empty() const { return size() == 0; } + iterator pop_front() { return erase(begin()); } + void clear() { erase(begin(), end()); } + + iterator erase(iterator, iterator); + iterator erase(iterator); + void splice(iterator, TNodeLinkList&); + void splice(iterator, TNodeLinkList&, iterator); + void splice(iterator, TNodeLinkList&, iterator, iterator); + iterator Find(const TLinkListNode*); + iterator Insert(iterator, TLinkListNode*); + iterator Erase(TLinkListNode*); + void Remove(TLinkListNode*); + bool Confirm() const; + bool Confirm_iterator(const_iterator) const; + + bool Iterator_isEnd_(const_iterator it) const { return it.p_ == &oNode_; } + template + void Remove_if(Predicate predicate, TNodeLinkList& tList) { + iterator it = begin(); + + while (!Iterator_isEnd_(const_iterator(it))) { + if (predicate(*it)) { + iterator itPrev = it; + ++it; + tList.splice(tList.end(), *this, itPrev); + } else { + ++it; + } + } + } + + template + void remove_if(Predicate predicate) { + TNodeLinkList list; + Remove_if(predicate, list); + } + +public: + /* 0x00 */ u32 count; + /* 0x04 */ TLinkListNode oNode_; +}; // Size: 0xC + +template +struct TLinkList : TNodeLinkList { + TLinkList() : TNodeLinkList() {} + + struct iterator : TNodeLinkList::iterator { + iterator() {} + explicit iterator(TNodeLinkList::iterator iter) : TNodeLinkList::iterator(iter) {} + + iterator& operator=(const iterator& rhs) { + //TODO: Probably fakematch? Not sure what's going on here exactly + (TIterator&)*this = + (const TIterator&)rhs; + this->p_ = rhs.p_; + return *this; + } + + iterator& operator++() { + TNodeLinkList::iterator::operator++(); + return *this; + } + iterator& operator--() { + TNodeLinkList::iterator::operator--(); + return *this; + } + iterator operator++(int) { + const iterator old(*this); + ++*this; + return old; + } + iterator operator--(int) { + const iterator old(*this); + --*this; + return old; + } + friend bool operator==(iterator a, iterator b) { + return (TNodeLinkList::iterator&)a == (TNodeLinkList::iterator&)b; + } + friend bool operator!=(iterator a, iterator b) { return !(a == b); } + + T* operator->() const { return Element_toValue(TNodeLinkList::iterator::operator->()); } + T& operator*() const { + T* p = operator->(); + JUT_ASSERT(541, p!=NULL); + return *p; + } + + typedef s32 difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef std::bidirectional_iterator_tag iterator_category; + }; + + struct const_iterator : TNodeLinkList::const_iterator { + explicit const_iterator(TNodeLinkList::const_iterator iter) : + TNodeLinkList::const_iterator(iter) {} + explicit const_iterator(iterator iter) : + TNodeLinkList::const_iterator((TNodeLinkList::iterator&)iter) {} + + const_iterator& operator++() { + TNodeLinkList::const_iterator::operator++(); + return *this; + } + const_iterator& operator--() { + TNodeLinkList::const_iterator::operator++(); + return *this; + } + const_iterator operator++(int) { + const const_iterator old(*this); + ++*this; + return old; + } + const_iterator operator--(int) { + const const_iterator old(*this); + --*this; + return old; + } + friend bool operator==(const_iterator a, const_iterator b) { + return (TNodeLinkList::const_iterator&)a == (TNodeLinkList::const_iterator&)b; + } + friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); } + + const T* operator->() const { return Element_toValue(TNodeLinkList::const_iterator::operator->()); } + const T& operator*() const { + const T* p = &*operator->(); + JUT_ASSERT(0x24a, p!=NULL); + return *p; + } + }; + + static TLinkListNode* Element_toNode(T* p) { + JUT_ASSERT(0x2F1, p!=NULL); + return reinterpret_cast(reinterpret_cast(p) - I); + } + static const TLinkListNode* Element_toNode(const T* p) { + JUT_ASSERT(0x2F6, p!=NULL); + return reinterpret_cast(reinterpret_cast(p) - I); + } + static T* Element_toValue(TLinkListNode* p) { + JUT_ASSERT(0x2FB, p!=NULL); + return reinterpret_cast(reinterpret_cast(p) + I); + } + static const T* Element_toValue(const TLinkListNode* p) { + JUT_ASSERT(0x300, p!=NULL); + return reinterpret_cast(reinterpret_cast(p) + I); + } + + iterator Insert(iterator iter, T* element) { + return iterator(TNodeLinkList::Insert((TNodeLinkList::iterator&)iter, Element_toNode(element))); + } + iterator Erase(T* element) { return iterator(TNodeLinkList::Erase(Element_toNode(element))); } + + iterator begin() { return iterator(TNodeLinkList::begin()); } + const_iterator begin() const { return const_iterator(const_cast(this)->begin()); } + iterator end() { return iterator(TNodeLinkList::end()); } + const_iterator end() const { return const_iterator(const_cast(this)->end()); } + T& front() { + JUT_ASSERT(642, !empty()); + return *begin(); + } + T& back() { JUT_ASSERT(652, !empty()); return *--end(); } + void pop_front() { erase(TNodeLinkList::begin()); } + void Push_front(T* element) { Insert(begin(), element); } + void Push_back(T* element) { Insert(end(), element); } + iterator Find(const T* element) { + return iterator(TNodeLinkList::Find(Element_toNode(element))); + } + void Remove(T* element) { TNodeLinkList::Remove(Element_toNode(element)); } + + typedef T value_type; +}; + +template +struct TLinkList_factory : public TLinkList { + inline virtual ~TLinkList_factory() = 0; + virtual T* Do_create() = 0; + virtual void Do_destroy(T*) = 0; + + void Clear_destroy() { + while (!this->empty()) { + T* item = &this->front(); + this->pop_front(); + Do_destroy(item); + } + } + + typename TLinkList::iterator Erase_destroy(T* param_0) { + typename TLinkList::iterator spC(this->Erase(param_0)); + Do_destroy(param_0); + return spC; + } +}; + +template +TLinkList_factory::~TLinkList_factory() { +#ifdef __MWERKS__ + JGADGET_ASSERTWARN(934, empty()); +#else + JGADGET_ASSERTWARN(934, this->empty()); +#endif +} + +template +struct TEnumerator { + inline TEnumerator(T _current, T _end) + : current(_current), end(_end) {} + + bool isEnd() const { return current != end; } + operator bool() const { return isEnd(); } + T operator*() { + T rv = current; + ++current; + return rv; + } + + T current; + T end; +}; + +// TEnumerator2 should be the same but there are two issues: +// 1. How to derive the iterator return type for operator* (the debug makes it seem like operator* is called +// so the return value should be what the iterator points to) +// 2. Calling the * operator seems to make functions using TEnumerator not work. See +// JStudio::TAdaptor::adaptor_setVariableValue_n +// Perhaps template specialization? +template +struct TEnumerator2 { + inline TEnumerator2(Iterator _current, Iterator _end) + : current(_current), end(_end) {} + + bool isEnd() const { return current != end; } + operator bool() const { return isEnd(); } + T& operator*() { + T& rv = *current; + ++current; + return rv; + } + + Iterator current; + Iterator end; +}; + +template +struct TContainerEnumerator : public TEnumerator2 { + inline TContainerEnumerator(T& param_0) + : TEnumerator2(param_0.begin(), param_0.end()) {} +}; + + +template +struct TContainerEnumerator_const : public TEnumerator2::const_iterator, const T> { + inline TContainerEnumerator_const(const TLinkList* param_0) + : TEnumerator2::const_iterator, const T>(param_0->begin(), param_0->end()) {} +}; + +}; // namespace JGadget + +#endif /* LINKLIST_H */ diff --git a/include/JSystem/JGadget/pointer.h b/include/JSystem/JGadget/pointer.h new file mode 100644 index 000000000..9ea7c3af7 --- /dev/null +++ b/include/JSystem/JGadget/pointer.h @@ -0,0 +1,33 @@ +#ifndef POINTER_H +#define POINTER_H + +namespace JGadget { + +template +class TPointer { +public: + TPointer(T* ptr) : mPtr(ptr) {} + ~TPointer() {} + void set(T* ptr) { mPtr = ptr; } + T* mPtr; +}; + +template +class TPointer_delete : public TPointer { +public: +#ifdef __MWERKS__ + TPointer_delete(T* ptr) : TPointer(ptr) {} + ~TPointer_delete() { + delete mPtr; + } +#else + TPointer_delete(T* ptr) : TPointer(ptr) {} + ~TPointer_delete() { + delete this->mPtr; + } +#endif +}; + +} + +#endif diff --git a/include/JSystem/JGadget/search.h b/include/JSystem/JGadget/search.h new file mode 100644 index 000000000..a0356c95b --- /dev/null +++ b/include/JSystem/JGadget/search.h @@ -0,0 +1,166 @@ +#ifndef JGADGET_SEARCH_H +#define JGADGET_SEARCH_H + +#include "common.h" + +#include +#include +#include +#include + +namespace JGadget { +namespace search { +template +struct TExpandStride_ {}; + +template <> +struct TExpandStride_ { + static s32 get(s32 n) { return n << 3; } +}; + +struct TPR1IsEqual_string_ { + TPR1IsEqual_string_(const char* sz) { + string_ = sz; + } + + bool operator()(const char* sz) const { + bool ret; + if (string_ == NULL) { + ret = sz == NULL; + } else { + ret = sz != NULL && strcmp(string_, sz) == 0; + } + return ret; + } + + const char* string_; +}; + +} // namespace search + +const char* toStringFromIndex(int index, const char* const* pValue, u32 count, const char* fallback); +int toIndexFromString_linear(const char*, const char* const*, u32, int); + +template +inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& fallback) { + JUT_ASSERT(200, pValue!=NULL); + u32 index = idx; + if (index >= count) { + return fallback; + } else { + return pValue[index]; + } +} + +template +inline int toIndexFromValue_linear_if(Predicate p, const T* pValue, u32 count, int fallback) { + JUT_ASSERT(212, pValue!=NULL); + + const T* first = pValue; + const T* last = pValue + count; + const T* found = std::find_if(first, last, p); + + if (found == last) { + return fallback; + } + + return std::distance(first, found); +} + +template +struct TIterator : public std::iterator { +}; + +template +struct TIterator_reverse : public std::reverse_iterator { + TIterator_reverse() {} + TIterator_reverse(Iterator it) : std::reverse_iterator(it) {} +}; + +template +inline Iterator findUpperBound_binary_all(Iterator first, Iterator last, const T& val, Predicate p) { + return std::upper_bound(first, last, val, p); +} + +template +inline Iterator findUpperBound_binary_begin(Iterator first, Iterator last, const T& val, Predicate p) { + if (first == last) { + return last; + } + + typedef typename std::iterator_traits::difference_type difference_type; + difference_type dist = std::distance(first, last); + difference_type stride = 1; + search::TExpandStride_ expand; + Iterator i = first; + + while (true) { + if (p(val, *i)) { + if (stride == 1) { + return i; + } else { + break; + } + } + first = i; + dist -= stride; + if (dist <= 0) { + i = last; + break; + } + i += stride; + stride = expand.get(stride); + } + + return findUpperBound_binary_all(first, i, val, p); +} + +template +inline Iterator findUpperBound_binary_end(Iterator first, Iterator last, const T& val, Predicate p) { + if (first == last) { + return last; + } + + typedef typename std::iterator_traits::difference_type difference_type; + --last; + difference_type dist = std::distance(first, last); + difference_type stride = 1; + search::TExpandStride_ expand; + Iterator i = last; + + while (true) { + if (!p(val, *i)) { + if (stride == 1) { + return ++i; + } else { + break; + } + } + last = i; + dist -= stride; + if (dist <= 0) { + i = first; + break; + } + i -= stride; + stride = expand.get(stride); + } + + return findUpperBound_binary_all(i, ++last, val, p); +} + +template +inline Iterator findUpperBound_binary_current(Iterator first, Iterator last, Iterator current, const T& val, Predicate p) { + return current == last || p(val, *current) ? + findUpperBound_binary_end(first, current, val, p) : + findUpperBound_binary_begin(current, last, val, p); +} + +template +inline Iterator findUpperBound_binary_current(Iterator first, Iterator last, Iterator current, const T& val) { + return findUpperBound_binary_current(first, last, current, val, std::less()); +} + +} // namespace JGadget + +#endif /* JGADGET_SEARCH_H */ diff --git a/include/JSystem/JGadget/std-memory.h b/include/JSystem/JGadget/std-memory.h new file mode 100644 index 000000000..c78c31742 --- /dev/null +++ b/include/JSystem/JGadget/std-memory.h @@ -0,0 +1,39 @@ +#ifndef STD_MEMORY_H +#define STD_MEMORY_H + +#include "JSystem/JUtility/JUTAssert.h" + +namespace JGadget { +template +struct TAllocator { + T* allocate(u32 count, const void *param_2) { + return AllocateRaw(count * sizeof(T)); + } + + T* AllocateRaw(u32 size) { + return (T*)operator new(size); + } + + void deallocate(T* mem, u32 size) { + DeallocateRaw(mem); + } + + void DeallocateRaw(void* mem) { + delete (char*)mem; + } + + void construct(T* p, const T& other) { + JUT_ASSERT(67, p!=NULL); + new(p) T(other); + } + + void destroy(T* p) { + (void)p; + JUT_ASSERT(68, p!=NULL); + } + + /* 0x0 */ u8 mAllocator; +}; +} + +#endif /* STD_MEMORY_H */ diff --git a/include/JSystem/JGadget/std-vector.h b/include/JSystem/JGadget/std-vector.h new file mode 100644 index 000000000..f4073a7c3 --- /dev/null +++ b/include/JSystem/JGadget/std-vector.h @@ -0,0 +1,224 @@ +#ifndef STD_VECTOR_H +#define STD_VECTOR_H + +#include "JSystem/JGadget/std-memory.h" +#include "JSystem/JGadget/define.h" +#include +#include +#include + +namespace JGadget { +namespace vector { +u32 extend_default(u32, u32, u32); +}; + +typedef u32 (*extendFunc)(u32, u32, u32); + +template > +struct TVector { + struct TDestructed_deallocate_ { + TDestructed_deallocate_(JGadget::TAllocator& allocator, T* ptr) { + mAllocator = &allocator; + mPtr = ptr; + } + + ~TDestructed_deallocate_() { mAllocator->deallocate(mPtr, 0); } + + void set(T* ptr) { mPtr = ptr; } + + Allocator* mAllocator; + T* mPtr; + }; + + typedef T* iterator; + typedef const T* const_iterator; + + TVector(Allocator const& allocator) { +#if PLATFORM_GCN + mAllocator = allocator; +#endif + pBegin_ = NULL; + pEnd_ = pBegin_; + mCapacity = 0; + pfnExtend_ = JGadget::vector::extend_default; + } + + ~TVector() { +#if DEBUG + Confirm(); +#endif + clear(); + JGADGET_ASSERTWARN(250, size()==0); + mAllocator.deallocate(pBegin_, 0); + } + + void insert(T* pos, u32 count, const T& val) { + if (count == 0) { + return; + } + + T* ptr = Insert_raw(pos, count); + if (ptr == end()) { + JGADGET_WARNMSG(321, "can't allocate memory"); + } else { + std::uninitialized_fill_n(ptr, count, val); + } + } + + T* Insert_raw(T* pFirst, u32 pCount) { + T* const pIt = pFirst; + JUT_ASSERT(446, (pBegin_<=pIt)&&(pIt<=pEnd_)); + + if (pCount == 0) { + return pFirst; + } + + if (pCount + size() <= mCapacity) { + void** newEnd = pIt + pCount; + + if (newEnd < pEnd_) { + void** pOverwrittenValues = pEnd_ - pCount; + std::uninitialized_copy(pOverwrittenValues, pEnd_, pEnd_); + std::copy_backward(pIt, pOverwrittenValues, pEnd_); + DestroyElement_(pIt, newEnd); + + pEnd_ += pCount; + return pFirst; + } else { + std::uninitialized_copy(pIt, pEnd_, newEnd); + DestroyElement_(pIt, pEnd_); + + pEnd_ += pCount; + return pFirst; + } + } + + u32 newSize = GetSize_extend_(pCount); + + void** newDataPointer = mAllocator.allocate(newSize, 0); + if (!newDataPointer) { + return end(); + } + + TDestructed_deallocate_ destructionDeallocator(mAllocator, newDataPointer); + + void** const endOfCopy = std::uninitialized_copy(pBegin_, pIt, newDataPointer); + std::uninitialized_copy(pIt, pEnd_, endOfCopy + pCount); + + DestroyElement_all_(); + destructionDeallocator.set(pBegin_); + + pEnd_ = newDataPointer + (pEnd_ - pBegin_ + pCount); + pBegin_ = newDataPointer; + mCapacity = newSize; + + return endOfCopy; + } + + T* insert(T* pos, const T& val) { + u32 diff = (int)((uintptr_t)pos - (uintptr_t)begin()) / 4; + insert(pos, 1, val); + return pBegin_ + diff; + } + + iterator begin() { return pBegin_; } + const_iterator begin() const { return pBegin_; } + iterator end() { return pEnd_; } + const_iterator end() const { return pEnd_; } + + u32 size() const { + if (pBegin_ == 0) { + return 0; + } + return (int)((uintptr_t)pEnd_ - (uintptr_t)pBegin_) / 4; + } + + u32 capacity() const { return mCapacity; } + + bool Confirm() const { + if (size() > mCapacity) { + JGADGET_WARNMSG(507, "illegal size"); + return false; + } + return true; + } + + u32 GetSize_extend_(u32 count) const { + JUT_ASSERT(555, pfnExtend_!=NULL); + + u32 oldSize = size(); + u32 neededNewSpace = oldSize + count; + u32 extendedSize = pfnExtend_(capacity(), oldSize, count); + + return neededNewSpace > extendedSize ? neededNewSpace : extendedSize; + } + + void DestroyElement_(T* pFirst, T* pLast) { + JUT_ASSERT(536, (pBegin_<=pFirst)&&(pFirst<=pEnd_)); + JUT_ASSERT(537, (pBegin_<=pLast)&&(pLast<=pEnd_)); + T* it = pFirst; + for (; it != pLast; it++) { + mAllocator.destroy(it); + } + } + + void DestroyElement_all_() { DestroyElement_(pBegin_, pEnd_); } + + T* erase(T* pFirst, T* pLast) { + iterator pItFirst = pFirst; + iterator pItLast = pLast; + JUT_ASSERT(347, (pBegin_<=pItFirst)&&(pItFirst<=pEnd_)) + JUT_ASSERT(348, (pBegin_<=pItLast)&&(pItLast<=pEnd_)); + JUT_ASSERT(349, pItFirst<=pItLast); + T* vectorEnd = pEnd_; // DEBUG NONMATCHING + T* ppvVar3 = std::copy(pItLast, vectorEnd, pItFirst); + DestroyElement_(ppvVar3, pEnd_); + pEnd_ = ppvVar3; + return pFirst; + } + + void clear() { erase(begin(), end()); } + + /* 0x00 */ Allocator mAllocator; + /* 0x04 */ T* pBegin_; + /* 0x08 */ T* pEnd_; + /* 0x0C */ u32 mCapacity; + /* 0x10 */ extendFunc pfnExtend_; +}; + +struct TVector_pointer_void : public TVector > { + TVector_pointer_void(const JGadget::TAllocator& allocator); + TVector_pointer_void(u32, void* const&, + const JGadget::TAllocator& allocator); + + ~TVector_pointer_void(); + + void insert(void**, void* const&); + void** erase(void**, void**); + + void clear() { erase(begin(), end()); } + void push_back(void* const& value) { insert(end(), (void* const&)value); } +}; + +template +struct TVector_pointer : TVector_pointer_void { + TVector_pointer(const TAllocator& allocator) : TVector_pointer_void(allocator) {} + ~TVector_pointer() {} + + typedef T* iterator; + typedef const T* const_iterator; + + const T* begin() const { return (const T*)TVector_pointer_void::begin(); } + T* begin() { return (T*)TVector_pointer_void::begin(); } + + const T* end() const { return (const T*)TVector_pointer_void::end(); } + T* end() { return (T*)TVector_pointer_void::end(); } + + void push_back(const T& ref) { + static_cast(this)->push_back((void* const&)ref); + } +}; + +} // namespace JGadget + +#endif /* STD_VECTOR_H */ diff --git a/include/JSystem/JStudio/JStudio/ctb-data.h b/include/JSystem/JStudio/JStudio/ctb-data.h new file mode 100644 index 000000000..ecdf1767b --- /dev/null +++ b/include/JSystem/JStudio/JStudio/ctb-data.h @@ -0,0 +1,4 @@ +#ifndef CTB_DATA_H +#define CTB_DATA_H + +#endif /* CTB_DATA_H */ diff --git a/include/JSystem/JStudio/JStudio/ctb.h b/include/JSystem/JStudio/JStudio/ctb.h new file mode 100644 index 000000000..fb1312b87 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/ctb.h @@ -0,0 +1,157 @@ +#ifndef CTB_H +#define CTB_H + +#include "JSystem/JGadget/binary.h" +#include "JSystem/JGadget/linklist.h" +#include "JSystem/JStudio/JStudio/object-id.h" +#include "JSystem/JUtility/JUTAssert.h" + +namespace JStudio { +namespace ctb { +struct TObject : public object::TObject_ID { + TObject(const void* id, u32 size, const void* param_2) : object::TObject_ID(id, size) { + pData_ = param_2; + JUT_ASSERT(82, pData_!=NULL); + } + virtual ~TObject() = 0; + virtual int getScheme() const = 0; + const void* getData() const { return pData_; } + + /* 0x08 vtable */ + /* 0x0C */ JGadget::TLinkListNode ocObject_; + /* 0x14 */ const void* pData_; +}; + +struct data { + struct THeaderData { + u32 signature; + u16 byteOrder; + u16 version; + u8 field_0x0[4]; + u32 blockNumber; + u8 content[0]; + }; + + struct TParse_THeader : public JGadget::binary::TParseData_aligned<4> { + TParse_THeader(const void* pContent) : JGadget::binary::TParseData_aligned<4>(pContent) {} + const THeaderData* get() const { + return (THeaderData*) getRaw(); + } + + const void* get_signature() const { + return &get()->signature; + } + + u32 get_blockNumber() const { + return get()->blockNumber; + } + + u16 get_byteOrder() const { + return get()->byteOrder; + } + + u16 get_version() const { + return get()->version; + } + + const void* getContent() const { + return ((THeaderData*) getRaw())->content; + } + }; + + struct TBlockData { + u32 size; + u16 scheme; + u16 IDSize; + u32 field_0x8[0]; + }; + + struct TParse_TBlock : public JGadget::binary::TParseData_aligned<4> { + TParse_TBlock(const void* pContent) : JGadget::binary::TParseData_aligned<4>(pContent) {} + const TBlockData* get() const { + return (const TBlockData*)getRaw(); + } + + u32 get_size() const { + return get()->size; + } + + u16 get_scheme() const { + return get()->scheme; + } + + u16 get_IDSize() const { + return get()->IDSize; + } + + const void* getBlockEnd_() const { + return ((const TBlockData*)getRaw())->field_0x8; + } + + const void* get_ID() const { + const void* rv = NULL; + if (get_IDSize() != 0) { + rv = getBlockEnd_(); + } + return rv; + } + + const void* getContent() const { + return (const void*)((char*)getBlockEnd_() + JGadget::binary::align_roundUp((u16)get_IDSize(), 4)); + } + + const TParse_TBlock* getNext() { + return (TParse_TBlock*)((char*)getRaw() + get_size()); + } + }; + + static const u32 ga4cSignature; +}; + +struct TObject_TxyzRy : public TObject { + TObject_TxyzRy(JStudio::ctb::data::TParse_TBlock const&); + + virtual ~TObject_TxyzRy() {} + virtual int getScheme() const; +}; + +struct TFactory { + TFactory() {} + + virtual ~TFactory(); + virtual TObject* create(JStudio::ctb::data::TParse_TBlock const&); + virtual void destroy(JStudio::ctb::TObject*); +}; + +struct TControl { + TControl(); + virtual ~TControl(); + void appendObject(JStudio::ctb::TObject*); + void removeObject(JStudio::ctb::TObject*); + void destroyObject(JStudio::ctb::TObject*); + void destroyObject_all(); + JStudio::ctb::TObject* getObject(void const*, u32); + JStudio::ctb::TObject* getObject_index(u32); + + TFactory* getFactory() const { return pFactory_; } + void setFactory(TFactory* factory) { pFactory_ = factory; } + + /* 0x4 */ TFactory* pFactory_; + /* 0x8 */ JGadget::TLinkList ocObject_; +}; + +struct TParse : public JGadget::binary::TParse_header_block { + TParse(JStudio::ctb::TControl*); + virtual ~TParse(); + virtual bool parseHeader_next(void const**, u32*, u32); + virtual bool parseBlock_next(void const**, u32*, u32); + + TControl* getControl() { return pControl_; } + + /* 0x4 */ TControl* pControl_; +}; + +}; // namespace ctb +}; // namespace JStudio + +#endif /* CTB_H */ diff --git a/include/JSystem/JStudio/JStudio/functionvalue.h b/include/JSystem/JStudio/JStudio/functionvalue.h new file mode 100644 index 000000000..8938ce9ab --- /dev/null +++ b/include/JSystem/JStudio/JStudio/functionvalue.h @@ -0,0 +1,550 @@ +#ifndef FUNCTIONVALUE_H +#define FUNCTIONVALUE_H + +#include +#include "JSystem/JGadget/std-vector.h" +#include "JSystem/JGadget/search.h" + +namespace JStudio { + +typedef f64 TValue; + +typedef f64 (*ExtrapolateParameter)(f64, f64); + +class TFunctionValue; +class TFunctionValueAttributeSet; + +class TFunctionValueAttribute_refer; +class TFunctionValueAttribute_range; +class TFunctionValueAttribute_interpolate; + +class TFunctionValue { +public: + enum TEProgress { PROG_INIT }; + enum TEAdjust { ADJ_INIT, ADJ_UNK1, ADJ_UNK2, ADJ_UNK3, ADJ_UNK4 }; + enum TEOutside { OUT_INIT }; + enum TEInterpolate {}; + + TFunctionValue(); + virtual ~TFunctionValue() = 0; + + virtual u32 getType() const = 0; + virtual TFunctionValueAttributeSet getAttributeSet() = 0; + virtual void initialize() = 0; + virtual void prepare() = 0; + virtual TValue getValue(f64 arg1) = 0; + + static ExtrapolateParameter toFunction_outside(int); + + static ExtrapolateParameter toFunction(TFunctionValue::TEOutside outside) { + return toFunction_outside(outside); + } +}; + +class TFunctionValueAttributeSet_const { +public: + TFunctionValueAttributeSet_const(TFunctionValueAttribute_refer* refer, + TFunctionValueAttribute_range* range, + TFunctionValueAttribute_interpolate* interp) + : refer_(refer), range_(range), interp_(interp) {} + + TFunctionValueAttribute_refer* refer_get() const { return refer_; } + TFunctionValueAttribute_range* range_get() const { return range_; } + TFunctionValueAttribute_interpolate* interpolate_get() const { return interp_; } + +private: + /* 0x00 */ TFunctionValueAttribute_refer* refer_; + /* 0x04 */ TFunctionValueAttribute_range* range_; + /* 0x08 */ TFunctionValueAttribute_interpolate* interp_; +}; + +class TFunctionValueAttributeSet : public TFunctionValueAttributeSet_const { +public: + TFunctionValueAttributeSet(TFunctionValueAttribute_refer* refer, + TFunctionValueAttribute_range* range, + TFunctionValueAttribute_interpolate* interp) + : TFunctionValueAttributeSet_const(refer, range, interp) {} + + TFunctionValueAttribute_refer* refer_get() const { + return TFunctionValueAttributeSet_const::refer_get(); + } + TFunctionValueAttribute_range* range_get() const { + return TFunctionValueAttributeSet_const::range_get(); + } + TFunctionValueAttribute_interpolate* interpolate_get() const { + return TFunctionValueAttributeSet_const::interpolate_get(); + } +}; + +class TFunctionValueAttribute_refer : public JGadget::TVector_pointer { +public: + TFunctionValueAttribute_refer() : JGadget::TVector_pointer(JGadget::TAllocator()) {} + ~TFunctionValueAttribute_refer() {} + + void refer_initialize(); + + const TFunctionValueAttribute_refer* refer_getContainer() const { return this; } + JGadget::TVector_pointer& refer_referContainer() { return *this; } + bool refer_isReferring(const TFunctionValue* p) const { return false; } // todo +}; + +class TFunctionValueAttribute_range { +public: + TFunctionValueAttribute_range(); + + void range_initialize(); + void range_prepare(); + void range_set(f64, f64); + f64 range_getParameter(f64, f64, f64) const; + + TFunctionValue::TEProgress range_getProgress() const { + return (TFunctionValue::TEProgress)mProgress; + } + void range_setProgress(TFunctionValue::TEProgress progress) { mProgress = progress; } + TFunctionValue::TEAdjust range_getAdjust() const { return (TFunctionValue::TEAdjust)mAdjust; } + void range_setAdjust(TFunctionValue::TEAdjust adjust) { mAdjust = adjust; } + void range_setOutside(TFunctionValue::TEOutside outside) { range_setOutside(outside, outside); } + void range_setOutside(TFunctionValue::TEOutside begin, TFunctionValue::TEOutside end) { + range_setOutside_begin(begin); + range_setOutside_end(end); + } + void range_setOutside_begin(TFunctionValue::TEOutside begin) { mBegin = begin; } + void range_setOutside_end(TFunctionValue::TEOutside end) { mEnd = end; } + f64 range_getParameter_outside(f64 arg1) const { + f64 result = arg1; + result -= fBegin_; + if (result < 0.0) { + result = TFunctionValue::toFunction(mBegin)(result, fDifference_); + } else if (result >= fDifference_) { + result = TFunctionValue::toFunction(mEnd)(result, fDifference_); + } + result += fBegin_; + return result; + } + f64 range_getParameter_progress(f64 arg1) const { return _20 + _28 * (arg1 - _20); } + f64 range_getBegin() const { return fBegin_;} + f64 range_getEnd() const { return fEnd_;} + f64 range_getDifference() const { return fDifference_; } + +private: + /* 0x00 */ f64 fBegin_; + /* 0x08 */ f64 fEnd_; + /* 0x10 */ f64 fDifference_; + /* 0x18 */ s8 mProgress; + /* 0x19 */ s8 mAdjust; + /* 0x1A */ s8 _1a[2]; + /* 0x1C */ u32 _1c; + /* 0x20 */ f64 _20; + /* 0x28 */ f64 _28; + /* 0x30 */ TFunctionValue::TEOutside mBegin; + /* 0x34 */ TFunctionValue::TEOutside mEnd; +}; + +class TFunctionValueAttribute_interpolate { +public: + TFunctionValueAttribute_interpolate() : interpolate_(0) {} + + void interpolate_initialize() { interpolate_ = 0; } + void interpolate_prepare() {} + u32 interpolate_get() const { return interpolate_; } + void interpolate_set(TFunctionValue::TEInterpolate interpolate) { interpolate_ = interpolate; } + +private: + /* 0x0 */ u32 interpolate_; +}; + +class TFunctionValue_constant : public TFunctionValue { +public: + TFunctionValue_constant(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + + void data_set(f64 value) { fValue_ = value; } + +private: + f64 fValue_; +}; + +class TFunctionValue_composite : public TFunctionValue, public TFunctionValueAttribute_refer { +public: + struct TData { + TData(void* data) : u32data((u32)data) {} + TData(const void* data) : rawData(data) {} + TData(u32 data) : u32data(data) {} + TData(f32 data) : f32data(data) {} + + inline void operator=(const TData& rhs) { f32data = rhs.f32data; } + u32 get_unsignedInteger() const { return u32data; } + u32 get_outside() const { return u32data; } + f64 get_value() const { return f32data; } + + union { + const void* rawData; + u32 u32data; + f64 f32data; + }; + }; + typedef f64 (*UnkFunc)(f64, const TFunctionValueAttribute_refer*, + const TFunctionValue_composite::TData*); + typedef f64 (*CompositeFunc)(const JGadget::TVector_pointer&, + const TFunctionValue_composite::TData&, f64); + + TFunctionValue_composite(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + static f64 composite_raw(TVector_pointer const&, TData const&, f64); + static f64 composite_index(TVector_pointer const&, TData const&, f64); + static f64 composite_parameter(TVector_pointer const&, + TData const&, f64); + static f64 composite_add(TVector_pointer const&, + TData const&, f64); + static f64 composite_subtract(TVector_pointer const&, TData const&, + f64); + static f64 composite_multiply(TVector_pointer const&, TData const&, + f64); + static f64 composite_divide(TVector_pointer const&, TData const&, + f64); + + void data_set(CompositeFunc fn, const TData& dat) { + pfn_ = (UnkFunc)fn; + data_setData(dat); + } + const TData* data_getData() const { return &data; } + void data_setData(const TData& dat) { data = dat; } + +// private: + UnkFunc pfn_; + TData data; +}; + +class TFunctionValue_transition : public TFunctionValue, + public TFunctionValueAttribute_range, + public TFunctionValueAttribute_interpolate { +public: + TFunctionValue_transition(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + + void data_set(f64 a1, f64 a2) { + _48 = a1; + _50 = a2; + } + + f64 data_getDifference() const { return _50 - _48; } + +private: + /* 0x48 */ f64 _48; + /* 0x50 */ f64 _50; +}; + +class TFunctionValue_list : public TFunctionValue, + public TFunctionValueAttribute_range, + public TFunctionValueAttribute_interpolate { +public: + struct TIndexData_ { + f64 _0; + f64 _8; + u32 _10; + }; + typedef f64 (*update_INTERPOLATE)(const TFunctionValue_list&, const TIndexData_&); + + TFunctionValue_list(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + + void data_set(const f32* pf, u32 u) { + // ASSERT((pf != NULL) || (u == 0)); + _44 = pf; + uData_ = u; + } + + void data_setInterval(f64 f) { + // ASSERT(f > TValue(0)); + _50 = f; + } + + static f64 + update_INTERPOLATE_NONE_(JStudio::TFunctionValue_list const&, + JStudio::TFunctionValue_list::TIndexData_ const&); + static f64 + update_INTERPOLATE_LINEAR_(JStudio::TFunctionValue_list const&, + JStudio::TFunctionValue_list::TIndexData_ const&); + static f64 + update_INTERPOLATE_PLATEAU_(JStudio::TFunctionValue_list const&, + JStudio::TFunctionValue_list::TIndexData_ const&); + static f64 + update_INTERPOLATE_BSPLINE_dataMore3_(JStudio::TFunctionValue_list const&, + JStudio::TFunctionValue_list::TIndexData_ const&); + +private: + /* 0x44 */ const f32* _44; + /* 0x48 */ u32 uData_; + /* 0x50 */ f64 _50; + /* 0x58 */ update_INTERPOLATE pfnUpdate_; +}; + +class TFunctionValue_list_parameter : public TFunctionValue, + public TFunctionValueAttribute_range, + public TFunctionValueAttribute_interpolate { +public: + struct TIterator_data_ + : public JGadget::TIterator< + std::random_access_iterator_tag, + const f32, + ptrdiff_t, + const f32*, + const f32& + > + { + TIterator_data_(const TFunctionValue_list_parameter& rParent, const f32* value) { +#if DEBUG + pOwn_ = &rParent; +#endif + pf_ = value; + } + + const f32* get() const { return pf_; } + void set(const f32* value) { pf_ = value; } + + friend bool operator==(const TIterator_data_& r1, const TIterator_data_& r2) { +#if DEBUG + if (!(r1.pOwn_==r2.pOwn_)) { + JGadget_outMessage msg(JGadget_outMessage::warning, __FILE__, 124); + msg << "r1.pOwn_==r2.pOwn_"; + } +#endif + return r1.pf_ == r2.pf_; + } + + f32 operator*() { + // this guard is required - removing it breaks float regalloc in std::upper_bound + #if DEBUG + JUT_ASSERT(947, pf_!=NULL); + #endif + return *pf_; + } + + TIterator_data_& operator+=(s32 n) { + pf_ += suData_size * n; + return *this; + } + TIterator_data_& operator-=(s32 n) { + pf_ -= suData_size * n; + return *this; + } + TIterator_data_& operator++() { + pf_ += suData_size; + return *this; + } + TIterator_data_& operator--() { + pf_ -= suData_size; + return *this; + } + + friend s32 operator-(const TIterator_data_& r1, const TIterator_data_& r2) { +#if DEBUG + if (!(r1.pOwn_==r2.pOwn_)) { + JGadget_outMessage msg(JGadget_outMessage::warning, __FILE__, 124); + msg << "r1.pOwn_==r2.pOwn_"; + } +#endif + return (r1.pf_ - r2.pf_) / suData_size; + } + +#if DEBUG + /* 0x00 */ const TFunctionValue_list_parameter* pOwn_; +#endif + /* 0x00 */ const f32* pf_; + }; + typedef f64 (*update_INTERPOLATE)(const TFunctionValue_list_parameter&, f64); + + TFunctionValue_list_parameter(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + void data_set(f32 const*, u32); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + + static f64 + update_INTERPOLATE_NONE_(JStudio::TFunctionValue_list_parameter const&, f64); + static f64 + update_INTERPOLATE_LINEAR_(JStudio::TFunctionValue_list_parameter const&, f64); + static f64 + update_INTERPOLATE_PLATEAU_(JStudio::TFunctionValue_list_parameter const&, f64); + static f64 + update_INTERPOLATE_BSPLINE_dataMore3_(JStudio::TFunctionValue_list_parameter const&, f64); + + static const u32 suData_size = 2; + + f64 data_getValue_back() const { + return pfData_[(uData_ - 1) * suData_size]; + } + f64 data_getValue_front() const { return pfData_[0]; } + +private: + /* 0x44 */ const f32* pfData_; + /* 0x48 */ u32 uData_; + /* 0x4c */ TIterator_data_ dat1; + /* 0x50 */ TIterator_data_ dat2; + /* 0x54 */ TIterator_data_ dat3; + /* 0x58 */ update_INTERPOLATE pfnUpdate_; +}; + +class TFunctionValue_hermite : public TFunctionValue, public TFunctionValueAttribute_range { +public: + struct TIterator_data_ + : public JGadget::TIterator< + std::random_access_iterator_tag, + const f32, + ptrdiff_t, + const f32*, + const f32& + > + { + TIterator_data_(const TFunctionValue_hermite& rParent, const f32* value) { +#if DEBUG + pOwn_ = &rParent; +#endif + pf_ = value; + uSize_ = rParent.data_getSize(); + } + + const f32* get() const { return pf_; } + void set(const f32* value, u32 size) { + pf_ = value; + uSize_ = size; + } + + friend bool operator==(const TIterator_data_& r1, const TIterator_data_& r2) { +#if DEBUG + if (!(r1.pOwn_==r2.pOwn_)) { + JGadget_outMessage msg(JGadget_outMessage::warning, __FILE__, 124); + msg << "r1.pOwn_==r2.pOwn_"; + } +#endif + return r1.pf_ == r2.pf_; + } + + f32 operator*() { +#if DEBUG + JUT_ASSERT(1098, pf_!=NULL); +#endif + return *pf_; + } + + TIterator_data_& operator+=(s32 n) { + pf_ += uSize_ * n; + return *this; + } + TIterator_data_& operator-=(s32 n) { + pf_ -= uSize_ * n; + return *this; + } + TIterator_data_& operator++() { + pf_ += uSize_; + return *this; + } + TIterator_data_& operator--() { + pf_ -= uSize_; + return *this; + } + + friend s32 operator-(const TIterator_data_& r1, const TIterator_data_& r2) { +#if DEBUG + if (!(r1.pOwn_==r2.pOwn_)) { + JGadget_outMessage msg(JGadget_outMessage::warning, __FILE__, 124); + msg << "r1.pOwn_==r2.pOwn_"; + } + if (!(r1.uSize_==r2.uSize_)) { + JGadget_outMessage msg(JGadget_outMessage::warning, __FILE__, 124); + msg << "r1.uSize_==r2.uSize_"; + } + JUT_ASSERT(0, r1.uSize_>0); +#endif + return (r1.pf_ - r2.pf_) / r1.uSize_; + } + +#if DEBUG + /* 0x00 */ const TFunctionValue_hermite* pOwn_; + /* 0x04 */ const f32* pf_; + /* 0x08 */ u32 uSize_; +#else + /* 0x00 */ const f32* pf_; + /* 0x04 */ u32 uSize_; +#endif + }; + + TFunctionValue_hermite(); + + virtual u32 getType() const; + virtual TFunctionValueAttributeSet getAttributeSet(); + void data_set(f32 const*, u32, u32); + virtual void initialize(); + virtual void prepare(); + virtual f64 getValue(f64); + + u32 data_getSize() const { return uSize_; } + f64 data_getValue_back() const { + return pfData_[(u_ - 1) * uSize_]; + } + f64 data_getValue_front() const { return pfData_[0]; } + +private: + /* 0x40 */ const f32* pfData_; + /* 0x44 */ u32 u_; + /* 0x48 */ u32 uSize_; + /* 0x4c */ TIterator_data_ dat1; + /* 0x50 */ TIterator_data_ dat2; + /* 0x54 */ TIterator_data_ dat3; +}; + +namespace functionvalue { + +inline f64 extrapolateParameter_raw(f64 a1, f64 a2) { + return a1; +} + +inline f64 extrapolateParameter_repeat(f64 a1, f64 a2) { + f64 t = fmod(a1, a2); + + if (t < 0.0) + t += a2; + + return t; +} + +f64 extrapolateParameter_turn(f64, f64); + +inline f64 extrapolateParameter_clamp(f64 value, f64 max) { + if (value <= 0.0) + return 0.0; + + if (max <= value) + return max; + + return value; +} + +}; // namespace functionvalue + +} // namespace JStudio + +#endif /* FUNCTIONVALUE_H */ diff --git a/include/JSystem/JStudio/JStudio/fvb-data-parse.h b/include/JSystem/JStudio/JStudio/fvb-data-parse.h new file mode 100644 index 000000000..1caa41755 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/fvb-data-parse.h @@ -0,0 +1,51 @@ +#ifndef FVB_DATA_PARSE_H +#define FVB_DATA_PARSE_H + +#include "JSystem/JStudio/JStudio/fvb-data.h" + +namespace JStudio { +namespace fvb { +namespace data { + +class TParse_TBlock : public TParseData_aligned<4> { +public: + TParse_TBlock(const void* content) : TParseData_aligned<4>(content) {} + + const TBlock* get() const { return (TBlock*)getRaw(); } + + u32 get_size() const { return get()->size; } + const void* getNext() const { + return (const void*)((u8*)getRaw() + get_size()); + } + u16 get_type() const { return get()->type; } + u16 get_IDSize() const { return get()->id_size; } + const void* getBlockEnd_() const { return (u8*)getRaw() + sizeof(TBlock); } + const void* get_ID() const { + const void* ret = 0; + if (get_IDSize()) + ret = getBlockEnd_(); + return ret; + } + const void* getContent() const { + return (const void*)((intptr_t)getBlockEnd_() + align_roundUp(get_IDSize(), 4)); + } +}; + +class TParse_TParagraph : public TParseData_aligned<4> { +public: + struct TData { + /* 0x00 */ u32 u32Size; + /* 0x04 */ u32 u32Type; + /* 0x08 */ const void* pContent; + /* 0x0C */ const void* next; + }; + TParse_TParagraph(const void* content) : TParseData_aligned<4>(content) {} + + void getData(JStudio::fvb::data::TParse_TParagraph::TData*) const; +}; + +} // namespace data +} // namespace fvb +} // namespace JStudio + +#endif /* FVB_DATA_PARSE_H */ diff --git a/include/JSystem/JStudio/JStudio/fvb-data.h b/include/JSystem/JStudio/JStudio/fvb-data.h new file mode 100644 index 000000000..3932d0edc --- /dev/null +++ b/include/JSystem/JStudio/JStudio/fvb-data.h @@ -0,0 +1,68 @@ +#ifndef FVB_DATA_H +#define FVB_DATA_H + +#include "JSystem/JGadget/binary.h" +#include "JSystem/JStudio/JStudio/functionvalue.h" + +using namespace JGadget::binary; + +namespace JStudio { +namespace fvb { +namespace data { + +extern const char ga4cSignature[4]; + +const int PARAGRAPH_DATA = 1; + +enum TEComposite { + /* 0x0 */ COMPOSITE_NONE, + /* 0x1 */ COMPOSITE_RAW, + /* 0x2 */ COMPOSITE_IDX, + /* 0x3 */ COMPOSITE_PARAM, + /* 0x4 */ COMPOSITE_ADD, + /* 0x5 */ COMPOSITE_SUB, + /* 0x6 */ COMPOSITE_MUL, + /* 0x7 */ COMPOSITE_DIV, + /* 0x8 */ COMPOSITE_ENUM_SIZE, +}; + +typedef TFunctionValue_composite::TData (*CompositeDataFunc)(const void*); + +struct CompositeOperation { + TFunctionValue_composite::CompositeFunc composite; + CompositeDataFunc getCompositeData; +}; + +struct TBlock { + /* 0x0 */ u32 size; + /* 0x4 */ u16 type; + /* 0x6 */ u16 id_size; + /* 0x8 */ u8 id[0]; +}; + +struct THeader { + /* 0x00 */ char signature[4]; + /* 0x04 */ u16 byte_order; // must be 0xFEFF + /* 0x06 */ u16 version; // 0-1 = obselete, 2-7 = OK + /* 0x08 */ u32 _8; + /* 0x0C */ u32 block_number; + /* 0x10 */ u8 content[0]; +}; +// Parses a THeader +class TParse_THeader : public TParseData_aligned<4> { +public: + TParse_THeader(const void* p) : TParseData_aligned<4>(p) {} + + const THeader* get() const { return (THeader*)getRaw(); } + const void* getContent() const { return ((THeader*)getRaw())->content; } + const char* get_signature() const { return get()->signature; } + u16 get_byteOrder() const { return get()->byte_order; } + u16 get_version() const { return get()->version; } + u32 get_blockNumber() const { return get()->block_number; } +}; + +} // namespace data +} // namespace fvb +} // namespace JStudio + +#endif /* FVB_DATA_H */ diff --git a/include/JSystem/JStudio/JStudio/fvb.h b/include/JSystem/JStudio/JStudio/fvb.h new file mode 100644 index 000000000..59ec510ec --- /dev/null +++ b/include/JSystem/JStudio/JStudio/fvb.h @@ -0,0 +1,160 @@ +#ifndef FVB_H +#define FVB_H + +#include "JSystem/JGadget/linklist.h" +#include "JSystem/JStudio/JStudio/fvb-data-parse.h" +#include "JSystem/JStudio/JStudio/object-id.h" + +namespace JStudio { +namespace fvb { + +class TControl; + +class TParse : public TParse_header_block { +public: + TParse(JStudio::fvb::TControl*); + virtual ~TParse(); + virtual bool parseHeader_next(void const**, u32*, u32); + virtual bool parseBlock_next(void const**, u32*, u32); + + TControl* getControl() const { return pControl_; } + +private: + TControl* pControl_; +}; + +class TObject : public object::TObject_ID { +public: + TObject(const data::TParse_TBlock& block); + TObject(void const* id, u32 id_size, TFunctionValue* value); + + explicit TObject(const data::TParse_TBlock& block, TFunctionValue* value) + : TObject_ID(block.get_ID(), block.get_IDSize()), pfv_(value) { + // ASSERT(pfv_ != NULL); + } + + virtual ~TObject() = 0; + + virtual void prepare_data_(const data::TParse_TParagraph::TData& data, TControl* control) = 0; + + void prepare(const data::TParse_TBlock& block, TControl* control); + + TFunctionValue* const referFunctionValue() { return pfv_; } + +protected: + /* 0x0C */ JGadget::TLinkListNode mNode; + /* 0x14 */ TFunctionValue* pfv_; +}; + +class TFactory { +public: + TFactory() {} + + virtual ~TFactory(); + virtual TObject* create(JStudio::fvb::data::TParse_TBlock const&); + virtual void destroy(JStudio::fvb::TObject*); +}; + +class TControl { +public: + TControl(); + virtual ~TControl(); + + void appendObject(JStudio::fvb::TObject*); + void removeObject(JStudio::fvb::TObject*); + void destroyObject(JStudio::fvb::TObject*); + void destroyObject_all(); + TObject* getObject(void const*, u32); + TObject* getObject_index(u32); + + TFactory* getFactory() const { return pFactory; } + void setFactory(TFactory* factory) { pFactory = factory; } + +private: + /* 0x4 */ TFactory* pFactory; + /* 0x8 */ JGadget::TLinkList ocObject_; +}; // Size: 0x14 + +class TObject_composite : public TObject { +public: + TObject_composite(JStudio::fvb::data::TParse_TBlock const&); + virtual void prepare_data_(JStudio::fvb::data::TParse_TParagraph::TData const&, + JStudio::fvb::TControl*); + virtual ~TObject_composite() {} + +private: + TFunctionValue_composite fnValue; +}; + +class TObject_constant : public TObject { +public: + TObject_constant(data::TParse_TBlock const&); + virtual ~TObject_constant() {} + + virtual void prepare_data_(data::TParse_TParagraph::TData const&, TControl*); + +private: + TFunctionValue_constant fnValue; +}; + +class TObject_transition : public TObject { +public: + TObject_transition(data::TParse_TBlock const&); + virtual ~TObject_transition() {} + + virtual void prepare_data_(data::TParse_TParagraph::TData const&, TControl*); + +private: + TFunctionValue_transition fnValue; +}; + +class TObject_list : public TObject { +public: + struct ListData { + /* 0x0 */ f32 _0; + /* 0x4 */ u32 _4; + /* 0x8 */ f32 _8[0]; + }; + TObject_list(data::TParse_TBlock const&); + virtual ~TObject_list() {} + + virtual void prepare_data_(data::TParse_TParagraph::TData const&, TControl*); + +private: + TFunctionValue_list fnValue; +}; + +class TObject_list_parameter : public TObject { +public: + struct ListData { + u32 _0; + f32 _4[0]; + }; + TObject_list_parameter(data::TParse_TBlock const&); + virtual ~TObject_list_parameter() {} + + virtual void prepare_data_(data::TParse_TParagraph::TData const&, TControl*); + +private: + TFunctionValue_list_parameter fnValue; +}; + +struct TObject_hermite : public TObject { +public: + struct ListData { + u32 _0; // u : 28, uSize : 4 + f32 _4[0]; + }; + TObject_hermite(data::TParse_TBlock const&); + virtual ~TObject_hermite() {} + + virtual void prepare_data_(data::TParse_TParagraph::TData const&, TControl*); + +private: + TFunctionValue_hermite fnValue; +}; + +} // namespace fvb +} // namespace JStudio + +#endif /* FVB_H */ diff --git a/include/JSystem/JStudio/JStudio/jstudio-control.h b/include/JSystem/JStudio/JStudio/jstudio-control.h new file mode 100644 index 000000000..3851dbdf5 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/jstudio-control.h @@ -0,0 +1,305 @@ +#ifndef JSTUDIO_CONTROL_H +#define JSTUDIO_CONTROL_H + +#include "JSystem/JStudio/JStudio/fvb.h" +#include "JSystem/JStudio/JStudio/stb.h" +#include "JSystem/JStudio/JStudio/ctb.h" +#include +#include + +namespace JStudio { +struct TObject; +struct TCreateObject { + TCreateObject() {} + virtual ~TCreateObject() = 0; + virtual bool create(TObject**, JStudio::stb::data::TParse_TBlock_object const&) = 0; + + template + static typename AdaptorT::ObjectType* createFromAdaptor(JStudio::stb::data::TParse_TBlock_object const& param_1, AdaptorT* param_2) { + typename AdaptorT::ObjectType* rv = new typename AdaptorT::ObjectType(param_1, param_2); + if (rv == NULL) { + return NULL; + } + rv->prepareAdaptor(); + return rv; + } + + /* 0x4 */ JGadget::TLinkListNode mNode; +}; // Size: 0xC + +struct TFactory : public stb::TFactory { + TFactory() {} + + virtual ~TFactory(); + virtual TObject* create(JStudio::stb::data::TParse_TBlock_object const&); + + void appendCreateObject(JStudio::TCreateObject*); + + /* 0x04 */ JGadget::TLinkList mList; + /* 0x10 */ fvb::TFactory fvb_Factory; + /* 0x14 */ ctb::TFactory ctb_Factory; +}; + +class TControl : public stb::TControl { +public: + struct TTransform_translation_rotation_scaling { + Vec translation; + Vec rotation; + Vec scaling; + }; + struct TTransform_position : public Vec {}; + struct TTransform_position_direction { + Vec position; + Vec direction; + }; + + TControl(); + virtual ~TControl(); + void setFactory(JStudio::TFactory*); + int transformOnSet_setOrigin_TxyzRy(Vec const&, f32); + int transformOnGet_setOrigin_TxyzRy(Vec const&, f32); + int transform_setOrigin_ctb(JStudio::ctb::TObject const&); + bool transform_setOrigin_ctb_index(u32); + + void stb_destroyObject_all() { stb::TControl::destroyObject_all(); } + void fvb_destroyObject_all() { fvb_Control.destroyObject_all(); } + void ctb_destroyObject_all() { ctb_Control.destroyObject_all(); } + + void destroyObject_all() { + stb_destroyObject_all(); + fvb_destroyObject_all(); + ctb_destroyObject_all(); + } + + void transformOnSet_enable(bool param_0) { mTransformOnSet = param_0; } + void transformOnGet_enable(bool param_0) { mTransformOnGet = param_0; } + + void transform_enable(bool param_0) { + transformOnSet_enable(param_0); + transformOnGet_enable(param_0); + } + + bool transform_setOrigin_TxyzRy(const Vec& xyz, f32 rotY) { + transformOnSet_setOrigin_TxyzRy(xyz, rotY); + transformOnGet_setOrigin_TxyzRy(xyz, rotY); + return true; + } + + void transform_setOrigin(const Vec& xyz, f32 rotY) { + transform_setOrigin_TxyzRy(xyz, rotY); + } + + void setSecondPerFrame(f64 param_0) { mSecondPerFrame = param_0; } + f64 getSecondPerFrame() const { return mSecondPerFrame; } + + ctb::TObject* ctb_getObject_index(u32 index) { + return ctb_Control.getObject_index(index); + } + + fvb::TObject* fvb_getObject(const void* param_1, u32 param_2) { + return fvb_Control.getObject(param_1, param_2); + } + + fvb::TObject* fvb_getObject_index(u32 index) { + return fvb_Control.getObject_index(index); + } + + TFunctionValue* getFunctionValue(const void* param_1, u32 param_2) { + fvb::TObject* obj = fvb_getObject(param_1, param_2); + if (obj == NULL) { + return NULL; + } + return obj->referFunctionValue(); + } + + TFunctionValue* getFunctionValue_index(u32 index) { + fvb::TObject* obj = fvb_getObject_index(index); + if (obj == NULL) { + return NULL; + } + return obj->referFunctionValue(); + } + + bool transformOnSet_isEnabled() const { return mTransformOnSet; } + CMtxP transformOnSet_getMatrix() const { return mTransformOnSet_Matrix; } + + void transformOnSet_transformTranslation(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(226, pDst!=NULL); + JUT_ASSERT(227, &rSrc!=pDst); + MTXMultVec(transformOnSet_getMatrix(), &rSrc, pDst); + } + + void transformOnSet_transformRotation(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(232, pDst!=NULL); + JUT_ASSERT(233, &rSrc!=pDst); + pDst->x = rSrc.x; + pDst->y = rSrc.y + mTransformOnSet_RotationY; + pDst->z = rSrc.z; + } + + void transformOnSet_transformScaling(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(240, pDst!=NULL); + JUT_ASSERT(241, &rSrc!=pDst); + *pDst = rSrc; + } + + void transformOnSet_transform(const TTransform_position ¶m_1, TTransform_position* param_2) const { + transformOnSet_transformTranslation(param_1, param_2); + } + + void transformOnSet_transform(const TTransform_translation_rotation_scaling& param_1, + TTransform_translation_rotation_scaling* param_2) const { + transformOnSet_transformTranslation(param_1.translation, ¶m_2->translation); + transformOnSet_transformRotation(param_1.rotation, ¶m_2->rotation); + transformOnSet_transformScaling(param_1.scaling, ¶m_2->scaling); + } + + const TTransform_position* transformOnSet_transform_ifEnabled(const TTransform_position& param_1, + TTransform_position* param_2) const { + if (!transformOnSet_isEnabled()) { + return ¶m_1; + } + transformOnSet_transform(param_1, param_2); + return param_2; + } + + const TTransform_translation_rotation_scaling* + transformOnSet_transform_ifEnabled(const TTransform_translation_rotation_scaling& param_1, + TTransform_translation_rotation_scaling* param_2) const { + if (!transformOnSet_isEnabled()) { + return ¶m_1; + } + transformOnSet_transform(param_1, param_2); + return param_2; + } + + bool transformOnGet_isEnabled() const { return mTransformOnGet; } + CMtxP transformOnGet_getMatrix() const { return mTransformOnGet_Matrix; } + + void transformOnGet_transformTranslation(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(296, pDst!=NULL); + JUT_ASSERT(297, &rSrc!=pDst); + MTXMultVec(transformOnGet_getMatrix(), &rSrc, pDst); + } + + void transformOnGet_transformDirection(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(316, pDst!=NULL); + JUT_ASSERT(317, &rSrc!=pDst); + MTXMultVecSR(transformOnGet_getMatrix(), &rSrc, pDst); + } + + void transformOnGet_transform(const TTransform_position_direction& param_1, + TTransform_position_direction* pDst) const { + JUT_ASSERT(289, pDst!=NULL); + transformOnGet_transformTranslation(param_1.position, &pDst->position); + transformOnGet_transformDirection(param_1.direction, &pDst->direction); + } + + const TTransform_position_direction* + transformOnGet_transform_ifEnabled(const TTransform_position_direction& param_1, + TTransform_position_direction* param_2) const { + if (!transformOnGet_isEnabled()) { + return ¶m_1; + } + transformOnGet_transform(param_1, param_2); + return param_2; + } + + void transformOnGet_transform(const TTransform_position& param_1, + TTransform_position* pDst) const { + transformOnGet_transformTranslation(param_1, pDst); + } + + const TTransform_position* + transformOnGet_transform_ifEnabled(const TTransform_position& param_1, + TTransform_position* param_2) const { + if (!transformOnGet_isEnabled()) { + return ¶m_1; + } + transformOnGet_transform(param_1, param_2); + return param_2; + } + + void transformOnGet_transformRotation(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(302, pDst!=NULL); + JUT_ASSERT(303, &rSrc!=pDst); + pDst->x = rSrc.x; + pDst->y = rSrc.y + mTransformOnGet_RotationY; + pDst->z = rSrc.z; + } + + void transformOnGet_transformScaling(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(310, pDst!=NULL); + JUT_ASSERT(311, &rSrc!=pDst); + *pDst = rSrc; + } + + void transformOnGet_transform(TTransform_translation_rotation_scaling* param_1, + TTransform_translation_rotation_scaling* pDst) const { + JUT_ASSERT(263, pDst!=NULL); + transformOnGet_transformTranslation(param_1->translation, &pDst->translation); + transformOnGet_transformRotation(param_1->rotation, &pDst->rotation); + transformOnGet_transformScaling(param_1->scaling, &pDst->scaling); + } + + TTransform_translation_rotation_scaling* + transformOnGet_transform_ifEnabled(TTransform_translation_rotation_scaling* param_1, + TTransform_translation_rotation_scaling* param_2) const { + if (!transformOnGet_isEnabled()) { + return param_1; + } + transformOnGet_transform(param_1, param_2); + return param_2; + } + + void transformOnSet_transformDirection(const Vec& rSrc, Vec* pDst) const { + JUT_ASSERT(246, pDst!=NULL); + JUT_ASSERT(247, &rSrc!=pDst); + MTXMultVecSR(transformOnSet_getMatrix(), &rSrc, pDst); + } + + void transformOnSet_transform(const TTransform_position_direction& param_1, + TTransform_position_direction* pDst) const { + JUT_ASSERT(219, pDst!=NULL); + transformOnSet_transformTranslation(param_1.position, &pDst->position); + transformOnSet_transformDirection(param_1.direction, &pDst->direction); + } + + const TTransform_position_direction* + transformOnSet_transform_ifEnabled(const TTransform_position_direction& param_1, + TTransform_position_direction* param_2) const { + if (!transformOnSet_isEnabled()) { + return ¶m_1; + } + transformOnSet_transform(param_1, param_2); + return param_2; + } + + /* 0x58 */ f64 mSecondPerFrame; + /* 0x60 */ fvb::TControl fvb_Control; + /* 0x74 */ ctb::TControl ctb_Control; + /* 0x88 */ bool mTransformOnSet; + /* 0x89 */ bool mTransformOnGet; + /* 0x8C */ Vec field_0x8c; + /* 0x98 */ Vec field_0x98; + /* 0xA4 */ f32 mTransformOnSet_RotationY; + /* 0xA8 */ f32 mTransformOnGet_RotationY; + /* 0xAC */ Mtx mTransformOnSet_Matrix; + /* 0xDC */ Mtx mTransformOnGet_Matrix; +}; + +struct TParse : public stb::TParse { + TParse(JStudio::TControl*); + bool parseBlock_block_fvb_(JStudio::stb::data::TParse_TBlock const&, u32); + bool parseBlock_block_ctb_(JStudio::stb::data::TParse_TBlock const&, u32); + + virtual ~TParse(); + virtual bool parseHeader(JStudio::stb::data::TParse_THeader const&, u32); + virtual bool parseBlock_block(JStudio::stb::data::TParse_TBlock const&, u32); + + TControl* getControl() { return (TControl*)stb::TParse::getControl(); } +}; + +}; // namespace JStudio + +#endif /* JSTUDIO_CONTROL_H */ diff --git a/include/JSystem/JStudio/JStudio/jstudio-data.h b/include/JSystem/JStudio/JStudio/jstudio-data.h new file mode 100644 index 000000000..9dc95fae9 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/jstudio-data.h @@ -0,0 +1,11 @@ +#ifndef JSTUDIO_DATA_H +#define JSTUDIO_DATA_H + + +namespace JStudio { +namespace data { + extern const char ga8cSignature[8]; +} // namespace data +} // namespace JStudio + +#endif /* JSTUDIO_DATA_H */ diff --git a/include/JSystem/JStudio/JStudio/jstudio-math.h b/include/JSystem/JStudio/JStudio/jstudio-math.h new file mode 100644 index 000000000..aa4949729 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/jstudio-math.h @@ -0,0 +1,68 @@ +#ifndef JSTUDIO_MATH_H +#define JSTUDIO_MATH_H + +#include + +#include + +#define m_PI_D 3.141592653589793 + +namespace JStudio { +namespace math { + void getRotation_xyz(MtxP, f32, f32, f32); + void getTransformation_SRxyzT(MtxP, Vec const&, Vec const&, Vec const&); + void getFromTransformation_SRxyzT(Vec*, Vec*, Vec*, CMtxP); + + inline void getRotation_y(Mtx param_0, f32 param_1) { + MTXRotRad(param_0, 0x79, DEG_TO_RAD(param_1)); + } + + inline void getTransformation_RyT(Mtx param_0, const Vec& param_1, f32 param_2) { + Mtx amStack_40; + getRotation_y(amStack_40, param_2); + MTXTransApply(amStack_40, param_0, param_1.x, param_1.y, param_1.z); + } + + inline void rotate_y(Mtx param_0, Mtx param_1, f32 param_2) { + Mtx afStack_38; + getRotation_y(afStack_38, param_2); + MTXConcat(afStack_38, param_1, param_0); + } + + inline void rotate_xyz(Mtx param_0, Mtx param_1, f32 param_2, f32 param_3, f32 param_4) { + Mtx amStack_30; + getRotation_xyz(amStack_30, param_2, param_3, param_4); + MTXConcat(amStack_30, param_0, param_1); + } + + inline void rotate_xyz(Mtx param_0, Mtx param_1, const Vec& param_2) { + rotate_xyz(param_0, param_1, param_2.x, param_2.y, param_2.z); + } + + inline f32 getFromTransformation_Sn(CMtxP param_1, u32 param_2) { + Vec local_18; + local_18.x = param_1[0][param_2]; + local_18.y = param_1[1][param_2]; + local_18.z = param_1[2][param_2]; + return VECMag(&local_18); + } + + inline void getFromTransformation_S(Vec* param_1, CMtxP param_2) { + param_1->x = getFromTransformation_Sn(param_2, 0); + param_1->y = getFromTransformation_Sn(param_2, 1); + param_1->z = getFromTransformation_Sn(param_2, 2); + } + + inline void getFromTransformation_T(Vec* param_1, CMtxP param_2) { + param_1->x = param_2[0][3]; + param_1->y = param_2[1][3]; + param_1->z = param_2[2][3]; + } + + inline void getTransformation_T(Mtx mtx, const Vec* param_2) { + MTXTrans(mtx, param_2->x, param_2->y, param_2->z); + } +}; +}; // namespace JStudio + +#endif /* JSTUDIO_MATH_H */ diff --git a/include/JSystem/JStudio/JStudio/jstudio-object.h b/include/JSystem/JStudio/JStudio/jstudio-object.h new file mode 100644 index 000000000..c50db5473 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/jstudio-object.h @@ -0,0 +1,462 @@ +#ifndef JSTUDIO_OBJECT_H +#define JSTUDIO_OBJECT_H + +#include "common.h" + +#include "JSystem/JStudio/JStudio/jstudio-control.h" +#include +#include + +// TODO get rid of this override +#undef NAN +#define NAN (0.0f / 0.0f) + +typedef struct _GXColor GXColor; + +namespace JStudio { +namespace data { + enum TEOperationData { + UNK_0x1 = 0x1, + UNK_0x2 = 0x2, + UNK_0x3 = 0x3, + UNK_0x10 = 0x10, + UNK_0x11 = 0x11, + UNK_0x12 = 0x12, + UNK_0x18 = 0x18, + UNK_0x19 = 0x19, + }; +}; + +struct TAdaptor; +struct TVariableValue { + struct TOutput { + virtual void operator()(f32, JStudio::TAdaptor*) const = 0; + virtual ~TOutput() = 0; + }; + + struct TOutput_none_ : TOutput { + ~TOutput_none_(); + void operator()(f32, JStudio::TAdaptor*) const; + }; + + void update(f64, JStudio::TAdaptor*); + static void update_immediate_(JStudio::TVariableValue*, f64); + static void update_time_(JStudio::TVariableValue*, f64); + static void update_functionValue_(JStudio::TVariableValue*, f64); + TVariableValue() : field_0x4(0), field_0x8(NULL), pOutput_(&soOutput_none_) {} + + void setValue_immediate(f32 value) { + field_0x8 = &update_immediate_; + field_0x4 = 0; + field_0xc.val = value; + } + + void setValue_none() { +#if DEBUG + field_0xc.fv = NULL; +#endif + field_0x8 = NULL; + } + + void setValue_time(f32 value) { + field_0x8 = &update_time_; + field_0x4 = 0; + field_0xc.val = value; + } + + void setValue_functionValue(TFunctionValue* value) { + field_0x8 = &update_functionValue_; + field_0x4 = 0; + field_0xc.fv = value; + } + + f32 getValue() const { return mValue; } + + template + T getValue_clamp() const { + u8 min = std::numeric_limits::min(); + u8 max = std::numeric_limits::max(); + if (mValue <= min) { + return (T)min; + } else if (mValue >= max) { + return (T)max; + } + return mValue; + } + u8 getValue_uint8() const { return getValue_clamp(); } + + void forward(u32 param_0) { + u32 max = std::numeric_limits::max(); + if (max - field_0x4 <= param_0) { + field_0x4 = max; + } else { + field_0x4 += param_0; + } + } + + void setOutput(const TOutput* param_1) { + pOutput_ = (param_1 != NULL) ? param_1 : &soOutput_none_; + } + + static TOutput_none_ soOutput_none_; + + /* 0x00 */ f32 mValue; + /* 0x04 */ u32 field_0x4; + /* 0x08 */ void (*field_0x8)(TVariableValue*, double); + /* 0x0C */ union { + TFunctionValue* fv; + f32 val; + } field_0xc; + /* 0x10 */ const TOutput* pOutput_; +}; // Size: 0x14 + +typedef void (TObject::*paragraphFunc)(u32, void const*, u32); + +class TObject : public stb::TObject { +public: + TObject(JStudio::stb::data::TParse_TBlock_object const&, JStudio::TAdaptor*); + void forward_value(u32); + + virtual ~TObject() = 0; + virtual void do_begin(); + virtual void do_end(); + virtual void do_paragraph(u32, void const*, u32) = 0; + virtual void do_wait(u32); + virtual void do_data(void const*, u32, void const*, u32); + + TAdaptor* getAdaptor() const { return mpAdaptor; } + + void setAdaptor(TAdaptor* pAdaptor) { + mpAdaptor = pAdaptor; + prepareAdaptor(); + } + + TControl* getControl() { return (TControl*)stb::TObject::getControl(); } + const TControl* getControl() const { return (const TControl*)stb::TObject::getControl(); } + + inline void prepareAdaptor(); + + template + T* createFromAdaptor(const stb::data::TParse_TBlock_object& param_0, T* param_1) { + T* n = new T(param_0, param_1); + + if (n == NULL) { + return NULL; + } + + n->prepareAdaptor(); + + return n; + } + + /* 0x34 */ TAdaptor* mpAdaptor; +}; + +struct TAdaptor { + struct TSetVariableValue_immediate { + TSetVariableValue_immediate() : field_0x0(-1), field_0x4(NAN) {} + TSetVariableValue_immediate(u32 param_1, f32 param_2) : + field_0x0(param_1), field_0x4(param_2) {} + u32 field_0x0; + f32 field_0x4; + }; + typedef void (*setVarFunc)(JStudio::TAdaptor*, JStudio::TControl*, u32, void const*, u32); + TAdaptor(TVariableValue *param_1, u32 param_2) { + pObject_ = NULL; + pValue_ = param_1; + uvv_ = param_2; + } + virtual ~TAdaptor() = 0; + virtual void adaptor_do_prepare(); + virtual void adaptor_do_begin(); + virtual void adaptor_do_end(); + virtual void adaptor_do_update(u32); + virtual void adaptor_do_data(void const*, u32, void const*, u32); + + void adaptor_setVariableValue(JStudio::TControl*, u32, + JStudio::data::TEOperationData, void const*, u32); + void adaptor_setVariableValue_n(JStudio::TControl*, u32 const*, u32, + JStudio::data::TEOperationData, void const*, + u32); + void + adaptor_setVariableValue_immediate(JStudio::TAdaptor::TSetVariableValue_immediate const*); + void adaptor_setVariableValue_Vec(u32 const*, Vec const&); + void adaptor_getVariableValue_Vec(Vec*, u32 const*) const; + void adaptor_setVariableValue_GXColor(u32 const*, GXColor const&); + void adaptor_getVariableValue_GXColor(GXColor*, u32 const*) const; + void adaptor_updateVariableValue(JStudio::TControl*, u32); + static void adaptor_setVariableValue_VOID_(JStudio::TAdaptor*, JStudio::TControl*, u32, + void const*, u32); + static void adaptor_setVariableValue_IMMEDIATE_(JStudio::TAdaptor*, JStudio::TControl*, + u32, void const*, u32); + static void adaptor_setVariableValue_TIME_(JStudio::TAdaptor*, JStudio::TControl*, u32, + void const*, u32); + static void adaptor_setVariableValue_FVR_NAME_(JStudio::TAdaptor*, JStudio::TControl*, + u32, void const*, u32); + static void adaptor_setVariableValue_FVR_INDEX_(JStudio::TAdaptor*, JStudio::TControl*, + u32, void const*, u32); + + const char* adaptor_getID_string() const; + + void adaptor_setObject_(const TObject* pObject) { + pObject_ = pObject; + } + + TVariableValue* adaptor_referVariableValue(u32 param_0) { + return &pValue_[param_0]; + } + + void adaptor_setVariableValue_immediate(u32 param_0, f32 param_1) { + adaptor_referVariableValue(param_0)->setValue_immediate(param_1); + } + + const TVariableValue* adaptor_getVariableValue(u32 u) const { + JUT_ASSERT(293, uadaptor_setObject_(this); + mpAdaptor->adaptor_do_prepare(); + } +} + +struct TAdaptor_actor : public TAdaptor { + enum TEVariableValue { + TE_VALUE_NONE = -1, + TEACTOR_1 = 1, + }; + + TAdaptor_actor() + : TAdaptor(mValue, ARRAY_LENGTH(mValue)) + , mValue() + { + } + virtual ~TAdaptor_actor() = 0; + virtual void adaptor_do_PARENT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_FUNCTION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_RELATION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_RELATION_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_RELATION_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_SHAPE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_ANIMATION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_ANIMATION_MODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_TEXTURE_ANIMATION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_TEXTURE_ANIMATION_MODE(JStudio::data::TEOperationData, const void*, u32) = 0; + + /* 0x10 */ TVariableValue mValue[14]; + + static u32 const sauVariableValue_3_TRANSLATION_XYZ[3]; + static u32 const sauVariableValue_3_ROTATION_XYZ[3]; + static u32 const sauVariableValue_3_SCALING_XYZ[3]; +}; // Size: 0x128 + +struct TObject_actor : public TObject { + TObject_actor(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_actor*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_ambientLight : public TAdaptor { + TAdaptor_ambientLight() : TAdaptor(mValue, 4) {} + virtual ~TAdaptor_ambientLight() = 0; + + /* 0x10 */ TVariableValue mValue[4]; + + static u32 const sauVariableValue_3_COLOR_RGB[3]; + static u32 const sauVariableValue_4_COLOR_RGBA[4]; +}; + +struct TObject_ambientLight : public TObject { + TObject_ambientLight(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_ambientLight*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_camera : public TAdaptor { + enum TEVariableValue { + TECAMERA_6 = 6, + TECAMERA_7 = 7, + TECAMERA_8 = 8, + TECAMERA_9 = 9, + }; + + TAdaptor_camera() : TAdaptor(mValue, 12) {} + virtual ~TAdaptor_camera() = 0; + + virtual void adaptor_do_PARENT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_FUNCTION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_TARGET_PARENT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_TARGET_PARENT_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_TARGET_PARENT_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + + /* 0x10 */ TVariableValue mValue[12]; + + static u32 const sauVariableValue_3_POSITION_XYZ[3]; + static u32 const sauVariableValue_3_TARGET_POSITION_XYZ[3]; + static u32 const sauVariableValue_2_DISTANCE_NEAR_FAR[2]; +}; + +struct TObject_camera : public TObject { + TObject_camera(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_camera*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_fog : public TAdaptor { + enum TEVariableValue { + TEFOG_4 = 4, + TEFOG_5 = 5, + }; + + TAdaptor_fog() : TAdaptor(mValue, 6) {} + virtual ~TAdaptor_fog() = 0; + + /* 0x10 */ TVariableValue mValue[6]; + + static u32 const sauVariableValue_3_COLOR_RGB[3]; + static u32 const sauVariableValue_4_COLOR_RGBA[4]; + static u32 const sauVariableValue_2_RANGE_BEGIN_END[2]; +}; + +struct TObject_fog : public TObject { + TObject_fog(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_fog*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_light : public TAdaptor { + enum TEVariableValue { + TE_VALUE_NONE = -1, + TE_VALUE_7 = 7, + TE_VALUE_8 = 8, + TE_VALUE_9 = 9, + TE_VALUE_10 = 10, + TE_VALUE_11 = 11, + }; + + TAdaptor_light() : TAdaptor(mValue, 13) {} + virtual ~TAdaptor_light() = 0; + virtual void adaptor_do_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_FACULTY(JStudio::data::TEOperationData, const void*, u32) = 0; + + /* 0x10 */ TVariableValue mValue[13]; + + static u32 const sauVariableValue_3_COLOR_RGB[3]; + static u32 const sauVariableValue_4_COLOR_RGBA[4]; + static u32 const sauVariableValue_3_POSITION_XYZ[3]; + static u32 const sauVariableValue_3_TARGET_POSITION_XYZ[3]; + static u32 const sauVariableValue_2_DIRECTION_THETA_PHI[2]; +}; + +struct TObject_light : public TObject { + TObject_light(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_light*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_message : public TAdaptor { + TAdaptor_message() : TAdaptor(NULL, 0) {} + virtual ~TAdaptor_message() = 0; + virtual void adaptor_do_MESSAGE(JStudio::data::TEOperationData, const void*, u32) = 0; +}; + +struct TObject_message : public TObject { + TObject_message(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_message*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_particle : public TAdaptor { + TAdaptor_particle() : TAdaptor(mValue, 20) {} + virtual ~TAdaptor_particle() = 0; + + virtual void adaptor_do_PARTICLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_BEGIN(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_BEGIN_FADE_IN(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_END(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_END_FADE_OUT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_FUNCTION(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_REPEAT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_ON_EXIT_NOT_END(JStudio::data::TEOperationData, const void*, u32) = 0; + + /* 0x10 */ TVariableValue mValue[20]; + + static u32 const sauVariableValue_3_TRANSLATION_XYZ[3]; + static u32 const sauVariableValue_3_ROTATION_XYZ[3]; + static u32 const sauVariableValue_3_SCALING_XYZ[3]; + static u32 const sauVariableValue_3_COLOR_RGB[3]; + static u32 const sauVariableValue_4_COLOR_RGBA[4]; + static u32 const sauVariableValue_3_COLOR1_RGB[3]; + static u32 const sauVariableValue_4_COLOR1_RGBA[4]; +}; + +struct TObject_particle : public TObject { + TObject_particle(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_particle*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +struct TAdaptor_sound : public TAdaptor { + enum TEVariableValue { + UNK_7 = 7, + UNK_8 = 8, + UNK_9 = 9, + UNK_10 = 10, + UNK_11 = 11, + UNK_NONE = -1, + }; + + TAdaptor_sound() : TAdaptor(mValue, 13) {} + virtual ~TAdaptor_sound() = 0; + + virtual void adaptor_do_SOUND(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_BEGIN(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_BEGIN_FADE_IN(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_END(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_END_FADE_OUT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_NODE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_PARENT_ENABLE(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_REPEAT(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_CONTINUOUS(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_LOCATED(JStudio::data::TEOperationData, const void*, u32) = 0; + virtual void adaptor_do_ON_EXIT_NOT_END(JStudio::data::TEOperationData, const void*, u32) = 0; + + /* 0x10 */ TVariableValue mValue[13]; + + static u32 const sauVariableValue_3_POSITION_XYZ[3]; +}; // Size: 0x114 + +struct TObject_sound : public TObject { + TObject_sound(JStudio::stb::data::TParse_TBlock_object const&, + JStudio::TAdaptor_sound*); + + virtual void do_paragraph(u32, void const*, u32); +}; + +}; // namespace JStudio + +#endif /* JSTUDIO_OBJECT_H */ diff --git a/include/JSystem/JStudio/JStudio/object-id.h b/include/JSystem/JStudio/JStudio/object-id.h new file mode 100644 index 000000000..b9166e219 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/object-id.h @@ -0,0 +1,43 @@ +#ifndef OBJECT_ID_H +#define OBJECT_ID_H + +#include "common.h" + +namespace JStudio { +namespace object { + + +struct TIDData { +public: + TIDData(const void* pID, u32 uIDSize_) : mID(pID), mID_size(uIDSize_) {} + + static bool isEqual(JStudio::object::TIDData const&, JStudio::object::TIDData const&); + inline const u8* getID() const { return (const u8*)mID; } + inline u32 getIDSize() const { return mID_size; } + +protected: + /* 0x00 */ const void* mID; + /* 0x04 */ u32 mID_size; +}; + +struct TObject_ID { + TObject_ID(const void* id, u32 id_size) : mData(id, id_size) {} + ~TObject_ID() {} + TIDData const& getIDData() const { return mData; } + const u8 *getID() const { return mData.getID(); } + + TIDData mData; +}; + +struct TPRObject_ID_equal { + TPRObject_ID_equal(const void* id, u32 id_size) : mData(id, id_size) {} + ~TPRObject_ID_equal() {} + bool operator()(TObject_ID const& id) const { return TIDData::isEqual(id.getIDData(), mData); } + + TIDData mData; +}; + +} // namespace object +} // namespace JStudio + +#endif /* OBJECT_ID_H */ diff --git a/include/JSystem/JStudio/JStudio/stb-data-parse.h b/include/JSystem/JStudio/JStudio/stb-data-parse.h new file mode 100644 index 000000000..80c94eeeb --- /dev/null +++ b/include/JSystem/JStudio/JStudio/stb-data-parse.h @@ -0,0 +1,112 @@ +#ifndef STB_DATA_PARSE_H +#define STB_DATA_PARSE_H + +#include "JSystem/JGadget/binary.h" +#include "JSystem/JStudio/JStudio/stb-data.h" + +using namespace JGadget::binary; + +namespace JStudio { +namespace stb { +namespace data { + +// Parses a THeader +class TParse_THeader : public TParseData_aligned<4> { +public: + TParse_THeader(const void* p) : TParseData_aligned<4>(p) {} + + const THeader* get() const { return (THeader*)getRaw(); } + const void* getContent() const { return ((THeader*)getRaw())->content; } + const char* get_signature() const { return get()->signature; } + u16 get_byteOrder() const { return get()->byte_order; } + u16 get_version() const { return get()->version; } + u32 get_blockNumber() const { return get()->block_number; } + const THeader::Target& get_target() const { return get()->target; } +}; + +class TParse_TBlock : public TParseData_aligned<4> { +public: + TParse_TBlock(const void* content) : TParseData_aligned<4>(content) {} + + const TBlock* get() const { return (TBlock*)getRaw(); } + const TBlock* getNext() const { return (TBlock*)((u8*)getRaw() + get_size()); } + + u32 get_size() const { return get()->size; } + u32 get_type() const { return get()->type; } + const void* getContent() const { return ((char*)getRaw()) + 8;} +}; + +class TParse_TSequence : public TParseData_aligned<4> { +public: + struct TData { + /* 0x00 */ u8 type; + /* 0x04 */ u32 param; + /* 0x08 */ const void* content; + /* 0x0C */ const void* next; + }; + + TParse_TSequence(const void* content) : TParseData_aligned<4>(content) {} + void getData(TData*) const; + + const void* get() const { return getRaw(); } + u32 get_head() const { return *(u32*)get(); } +}; + +class TParse_TParagraph : public TParseData_aligned<4> { +public: + struct TData { + /* 0x00 */ u32 type; + /* 0x04 */ u32 param; + /* 0x08 */ const void* content; + /* 0x0C */ const void* next; + }; + + TParse_TParagraph(const void* content) : TParseData_aligned<4>(content) {} + void getData(TData*) const; +}; + +struct TParse_TParagraph_data : public TParseData { + struct TData { + /* 0x00 */ u8 status; + /* 0x04 */ u32 entrySize; + /* 0x08 */ u32 entryCount; + /* 0x0C */ const void* content; + /* 0x10 */ const void* next; + }; + + TParse_TParagraph_data(const void* content) : TParseData(content) {} + void getData(TData* pData) const; +}; + +// Parses a TObject ("demo object") +class TParse_TBlock_object : public TParse_TBlock { +public: + TParse_TBlock_object(const void* content) : TParse_TBlock(content) {} + + const TBlock_object* get() const { return (TBlock_object*)getRaw(); } + const void* getContent() const { + return ((TBlock_object*)getRaw())->id + align_roundUp(get_IDSize(), 4); + } + + u16 get_flag() const { return get()->flag; } + u16 get_IDSize() const { return get()->id_size; } + const void* get_ID() const { return get()->id; } +}; + +class TParse_TParagraph_dataID : public TParseData_aligned<4> { +public: + TParse_TParagraph_dataID(const void* pContent) : TParseData_aligned<4>(pContent) {} + + const TParagraph* get() const { return (TParagraph*)getRaw(); } + u16 get_IDSize() const { return get()->id_size; } + const void* get_ID() const { return get()->id; } + const void* getContent() const { + return ((TParagraph*)getRaw())->id + align_roundUp(get_IDSize(), 4); + } +}; + +} // namespace data +} // namespace stb +} // namespace JStudio + +#endif /* STB_DATA_PARSE_H */ diff --git a/include/JSystem/JStudio/JStudio/stb-data.h b/include/JSystem/JStudio/JStudio/stb-data.h new file mode 100644 index 000000000..a3bf83dfb --- /dev/null +++ b/include/JSystem/JStudio/JStudio/stb-data.h @@ -0,0 +1,69 @@ +#ifndef STB_DATA_H +#define STB_DATA_H + +#include "common.h" + +namespace JStudio { +namespace stb { +namespace data { + +const int guBit_TSequence_type = 24; + +const int BLOCK_SOUND = 'JSND'; +const int BLOCK_ACTOR = 'JACT'; +const int BLOCK_AMBIENTLIGHT = 'JABL'; +const int BLOCK_CAMERA = 'JCMR'; +const int BLOCK_FOG = 'JFOG'; +const int BLOCK_LIGHT = 'JLIT'; +const int BLOCK_MESSAGE = 'JMSG'; +const int BLOCK_PARTICLE = 'JPTC'; +const int BLOCK_NONE = -1; + +// Used to expand a signed 24 int to a signed 32 int +const u32 gu32Mask_TSequence_value_signExpansion = 0xFF000000; +extern const u32 ga4cSignature; // 'STB/0' +extern const s32 gauDataSize_TEParagraph_data[8]; + +inline void toString_block(char* a5c, u32 arg1) { + // from debug, todo +} + +struct THeader { + struct Target { + /* 0x00 */ char name[8]; // "jstudio" + /* 0x08 */ u16 _8[3]; + /* 0x0E */ u16 target_version; + }; + + /* 0x00 */ char signature[4]; + /* 0x04 */ u16 byte_order; // must be 0xFEFF + /* 0x06 */ u16 version; // 0-1 = obselete, 2-7 = OK + /* 0x08 */ u32 _8; + /* 0x0C */ u32 block_number; + /* 0x10 */ Target target; + /* 0x20 */ u8 content[0]; +}; + +struct TBlock { + /* 0x0 */ u32 size; + /* 0x4 */ u32 type; // char[4] JMSG, JSND, JACT, ... +}; + +struct TBlock_object : TBlock { + /* 0x8 */ u16 flag; + /* 0xA */ u16 id_size; + /* 0xC */ u8 id[0]; // unique identifier + ///* ??? */ u8 content[0]; +}; + +struct TParagraph { + /* 0x0 */ u16 _0; + /* 0x2 */ u16 id_size; + /* 0x4 */ u8 id[0]; // unique identifier +}; + +} // namespace data +} // namespace stb +} // namespace JStudio + +#endif /* STB_DATA_H */ diff --git a/include/JSystem/JStudio/JStudio/stb.h b/include/JSystem/JStudio/JStudio/stb.h new file mode 100644 index 000000000..ff41b78c4 --- /dev/null +++ b/include/JSystem/JStudio/JStudio/stb.h @@ -0,0 +1,250 @@ +#ifndef STB_H +#define STB_H + +#include "JSystem/JGadget/linklist.h" +#include "JSystem/JStudio/JStudio/object-id.h" +#include "JSystem/JStudio/JStudio/stb-data-parse.h" +#include +#include + +namespace JStudio { +class TObject; +namespace stb { + +class TControl; + +class TParse : public TParse_header_block { +public: + TParse(TControl*); + virtual ~TParse(); + virtual bool parseHeader_next(void const**, u32*, u32); + virtual bool parseBlock_next(void const**, u32*, u32); + virtual bool parseHeader(data::TParse_THeader const&, u32); + virtual bool parseBlock_block(data::TParse_TBlock const&, u32); + virtual bool parseBlock_object(data::TParse_TBlock_object const&, u32); + + TControl* getControl() const { return pControl; } + +private: + TControl* pControl; +}; + +class TObject : public object::TObject_ID { +public: + enum TEStatus { + /* 0x0 */ STATUS_STILL = 0, + /* 0x1 */ STATUS_END = 1 << 0, + /* 0x2 */ STATUS_WAIT = 1 << 1, + /* 0x4 */ STATUS_SUSPEND = 1 << 2, + /* 0x8 */ STATUS_INACTIVE = 1 << 3, + }; + + TObject(data::TParse_TBlock_object const&); + explicit TObject(u32, void const*, u32); + virtual ~TObject(); + + void setFlag_operation(u8, int); +#if PLATFORM_SHIELD && !DEBUG + void reset(void const* arg1) { + bSequence_ = 0; + mStatus = STATUS_STILL; + pSequence_next = arg1; + u32Wait_ = 0; + } +#else + void reset(void const*); +#endif +#if !DEBUG + void reset() { reset(NULL); } +#else + void reset(); +#endif + bool forward(u32); + virtual void do_begin(); + virtual void do_end(); + virtual void do_paragraph(u32, void const*, u32); + virtual void do_wait(u32); + virtual void do_data(void const*, u32, void const*, u32); + void process_sequence_(); + void process_paragraph_reserved_(u32, void const*, u32); + + const char* toString_status(int status); + + void on_begin() { do_begin(); } + void on_end() { do_end(); } + void on_paragraph(u32 arg1, const void* arg2, u32 arg3) { do_paragraph(arg1, arg2, arg3); } + void on_wait(u32 arg1) { do_wait(arg1); } + void on_data(const void* arg1, u32 arg2, const void* arg3, u32 arg4) { + do_data(arg1, arg2, arg3, arg4); + } + + TControl* getControl() const { return pControl; } + void setControl_(TControl* control) { pControl = control; } + int getSuspend() const { return _20; } + void setSuspend(s32 val) { _20 = val; } + bool isSuspended() const { return getSuspend() > 0; } + void suspend(s32 val) { _20 += val; } + const void* getSequence() const { return pSequence; } + void setSequence_(const void* arg1) { pSequence = arg1; } + const void* getSequence_offset(s32 i_no) const { + intptr_t s32Val = (intptr_t)getSequence(); + return (const void*)(s32Val + i_no); + } + const void* getSequence_next() const { return pSequence_next; } + void setSequence_next(const void* seq) { pSequence_next = seq; } + u32 getWait() const { return u32Wait_; } + void setWait(u32 wait) { u32Wait_ = wait; } + TEStatus getStatus() const { return mStatus; } + void setStatus_(TEStatus status) { mStatus = status; } + u32 toInt32FromUInt24_(u32 val) { + if (val & 0x800000) { + val |= data::gu32Mask_TSequence_value_signExpansion; + } + return val; + } + void setFlag_operation_(u32 u32Data) { + // ASSERT((u32Data >> data::guBit_TSequence_type) == 0); + setFlag_operation(u32Data >> 16, u32Data & 0xFFFF); + } + + /* 0x10 */ JGadget::TLinkListNode ocObject_; + +public: // private: // public for the fakematch in JStudio_JStage::TAdaptor_actor::adaptor_do_begin + /* 0x14 */ TControl* pControl; + /* 0x18 */ u32 signature; + /* 0x1C */ u16 mFlag; + /* 0x1E */ u8 bSequence_; + /* 0x20 */ u32 _20; // "second per frame"? + /* 0x24 */ const void* pSequence; + /* 0x28 */ const void* pSequence_next; + /* 0x2C */ u32 u32Wait_; + /* 0x30 */ TEStatus mStatus; +}; + +class TFactory { +public: + TFactory() {} + + virtual ~TFactory(); + virtual JStudio::TObject* create(data::TParse_TBlock_object const&); + virtual void destroy(TObject*); +}; + +class TObject_control : public TObject { +public: + TObject_control(void const*, u32); +}; + +// Manages TObjects +class TControl { +public: + TControl(); + virtual ~TControl(); + + void appendObject(TObject*); + void removeObject(TObject*); + void destroyObject(TObject*); + void destroyObject_all(); + TObject* getObject(void const*, u32); + void reset(); + bool forward(u32); + + void setStatus_(u32 status) { mStatus = status; } + void resetStatus_() { setStatus_(0); } + bool isSuspended() const { return _54 > 0; } + TFactory* getFactory() const { return pFactory; } + void setFactory(TFactory* factory) { pFactory = factory; } + TObject_control& referObject_control() { return mObject_control; } + int getSuspend() const { return _54; } + void setSuspend(s32 suspend) { mObject_control.setSuspend(suspend); } + void suspend(s32 param_0) { mObject_control.suspend(param_0); } + void unsuspend(s32 param_0) { suspend(-param_0); } + +private: + /* 0x04 */ u32 _4; + /* 0x08 */ u32 _8; + /* 0x0C */ TFactory* pFactory; + /* 0x10 */ JGadget::TLinkList ocObject_; + /* 0x1C */ u32 mStatus; + /* 0x20 */ TObject_control mObject_control; + /* 0x54 */ s32 _54; +}; + +template +struct TParseData : public data::TParse_TParagraph_data::TData { + TParseData(const void* pContent) { + set(data::TParse_TParagraph_data(pContent)); + } + + TParseData() { + set(NULL); + } + + void set(const data::TParse_TParagraph_data& data) { + data.getData(this); + } + + void set(const void* pContent) { + set(data::TParse_TParagraph_data(pContent)); + } + + bool isEnd() const { + return status == 0; + } + + bool empty() const { + return content == NULL; + } + + bool isValid() const { + return !empty() && status == S; + } + + const void* getContent() const { return content; } + + u32 size() const { return entryCount; } +}; + +template > +struct TParseData_fixed : public TParseData { + TParseData_fixed(const void* pContent) : TParseData(pContent) {} + TParseData_fixed() : TParseData() {} + + const void* getNext() const { + return this->next; + } + + bool isValid() const { + return TParseData::isValid() && getNext() != NULL; + } + + Iterator begin() const { + return Iterator(this->content); + } + + Iterator end() const { + 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> { + TParseData_string(const void* pContent) : TParseData<0x60>(pContent) {} + TParseData_string() : TParseData<0x60>() {} + + const char* getData() const { return (const char*)getContent(); } +}; + +} // namespace stb +} // namespace JStudio + +#endif /* STB_H */ diff --git a/include/JSystem/JUtility/JUTAssert.h b/include/JSystem/JUtility/JUTAssert.h index c8459b1a5..73384e8fc 100644 --- a/include/JSystem/JUtility/JUTAssert.h +++ b/include/JSystem/JUtility/JUTAssert.h @@ -41,6 +41,7 @@ #define JUT_WARN_DEVICE(...) #define JUT_LOG(...) #define JUT_CONFIRM(...) +#define JUT_EXPECT(...) #endif namespace JUTAssertion { diff --git a/include/rvl/MTX/mtx.h b/include/rvl/MTX/mtx.h index 2283df0c1..4cacfcfad 100644 --- a/include/rvl/MTX/mtx.h +++ b/include/rvl/MTX/mtx.h @@ -53,8 +53,8 @@ void PSMTXConcatArray(const Mtx, const Mtx, Mtx, u32); void PSMTXTranspose(const Mtx, Mtx); u32 PSMTXInverse(const Mtx, Mtx); u32 PSMTXInvXpose(const Mtx, Mtx); -void PSMTXRotRad(Mtx, f32, char); -void PSMTXRotTrig(Mtx, f32, f32, char); +void PSMTXRotRad(Mtx, char, f32); +void PSMTXRotTrig(Mtx, char, f32, f32); void PSMTXRotAxisRad(Mtx, const Vec *, f32); void PSMTXTrans(Mtx, f32, f32, f32); void PSMTXTransApply(const Mtx, Mtx, f32, f32, f32); diff --git a/src/JSystem/JGadget/binary.cpp b/src/JSystem/JGadget/binary.cpp new file mode 100644 index 000000000..175fd7a4f --- /dev/null +++ b/src/JSystem/JGadget/binary.cpp @@ -0,0 +1,79 @@ +#include "JSystem/JGadget/binary.h" +#include "JSystem/JGadget/define.h" +#include + +#if DEBUG +static void dummyString() { + // probably some stripped function that called JUT_ASSERT here + DEAD_STRING("Halt"); +} +#endif + +const void* JGadget::binary::parseVariableUInt_16_32_following(const void* pBuffer, u32* pu32First, u32* pu32Second, + JGadget::binary::TEBit* pTEBit) { + u16* pu16 = (u16*)pBuffer; + JUT_ASSERT(122, pu16!=NULL); + JUT_ASSERT(123, pu32First!=NULL); + JUT_ASSERT(124, pu32Second!=NULL); + + JGadget::binary::TEBit spC; + if (pTEBit == NULL) { + pTEBit = &spC; + } + + u32 var_r30 = *pu16; + if ((var_r30 & 0x8000) == 0) { + pTEBit->value = 0x10; + + *pu32First = var_r30; + pu16++; + *pu32Second = *pu16; + + return pu16 + 1; + } else { + pTEBit->value = 0x20; + + var_r30 &= 0x7FFF; + var_r30 <<= 16; + pu16++; + var_r30 |= *pu16; + + *pu32First = var_r30; + pu16++; + *pu32Second = *(u32*)pu16; + + return pu16 + 2; + } +} + +JGadget::binary::TParse_header_block::~TParse_header_block() {} + +bool JGadget::binary::TParse_header_block::parse_next(const void** ppData_inout, u32 idx) { + u32 uBlock, uData; + + if (ppData_inout == NULL || *ppData_inout == NULL) { + JGADGET_WARNMSG(172, "data not specified"); + return false; + } + + bool var_r29 = true; + var_r29 = parseHeader_next(ppData_inout, &uBlock, idx) && var_r29; + + if (!(idx & 1) && !var_r29) { + return var_r29; + } + + while (uBlock > 0) { + const void* p = *ppData_inout; + var_r29 = parseBlock_next(ppData_inout, &uData, idx) && var_r29; + + JUT_ASSERT(192, std::uintptr_t(*ppData_inout)==std::uintptr_t(p)+uData); + + if ((idx & 2) == 0 && !var_r29) { + return var_r29; + } + uBlock--; + } + + return var_r29; +} diff --git a/src/JSystem/JGadget/linklist.cpp b/src/JSystem/JGadget/linklist.cpp new file mode 100644 index 000000000..1ec4e3a6d --- /dev/null +++ b/src/JSystem/JGadget/linklist.cpp @@ -0,0 +1,168 @@ +#include "JSystem/JGadget/linklist.h" +#include "JSystem/JGadget/define.h" + +namespace JGadget { +namespace { +template +class TPRIsEqual_pointer_ { +public: + TPRIsEqual_pointer_(const T* p) { this->p_ = p; } + + bool operator()(const T& rSrc) const { return &rSrc == this->p_; } + +private: + const T* p_; +}; +} +} + +JGadget::TNodeLinkList::~TNodeLinkList() { +#if DEBUG + Confirm(); + clear(); + JGADGET_ASSERTWARN(84, empty()) + oNode_.clear_(); +#endif +} + +JGadget::TNodeLinkList::iterator +JGadget::TNodeLinkList::erase(JGadget::TNodeLinkList::iterator it) { + JUT_ASSERT(102, it.p_!=&oNode_); + iterator next = it; + ++next; + return erase(it, next); +} + +JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::erase(iterator a, iterator b) { + TLinkListNode* cur = a.p_; + TLinkListNode* end = b.p_; + TLinkListNode* next; + + for (; cur != end; cur = next) { + next = cur->pNext_; + Erase(cur); + } + + return b; +} + +void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc) { + JUT_ASSERT(146, this!=&rSrc); + splice(it, rSrc, rSrc.begin(), rSrc.end()); + JUT_ASSERT(148, rSrc.empty()); +} + +void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc, iterator itSrc) { + iterator itSrcNext = itSrc; + ++itSrcNext; + + if ((it == itSrc) || (it == itSrcNext)) { + return; + } else { + TLinkListNode* const node = &(*itSrc); + rSrc.Erase(node); + Insert(it, node); + } +} + +void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc, iterator itBegin, iterator itEnd) { + s32 dist = 0; + if (this == &rSrc) { + if (itBegin == itEnd) { + return; + } + } else { + dist = std::distance(itBegin, itEnd); + if (dist == 0) { + return; + } + } + TLinkListNode* r31 = it.p_; + TLinkListNode* r30 = itBegin.p_; + TLinkListNode* r29 = itEnd.p_; + TLinkListNode* r25 = r29->pPrev_; + TLinkListNode* r24 = r30->pPrev_; + r24->pNext_ = r29; + r29->pPrev_ = r24; + rSrc.count -= dist; + TLinkListNode* r23 = r31->pPrev_; + r23->pNext_ = r30; + r30->pPrev_ = r23; + r25->pNext_ = r31; + r31->pPrev_ = r25; + count += dist; +} + +JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Find(const JGadget::TLinkListNode* p) { + return std::find_if(begin(), end(), TPRIsEqual_pointer_(p)); +} + +JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Insert(iterator it, TLinkListNode* p) { + JUT_ASSERT(300, p!=NULL); + TLinkListNode* pIt = it.p_; + JUT_ASSERT(302, pIt!=NULL); + TLinkListNode* pItPrev = pIt->pPrev_; + JUT_ASSERT(305, pItPrev!=0); + JGADGET_ASSERTWARN(307, p->pNext_==NULL); + JGADGET_ASSERTWARN(308, p->pPrev_==NULL); + + p->pNext_ = pIt; + p->pPrev_ = pItPrev; + pIt->pPrev_ = p; + pItPrev->pNext_ = p; + count++; + return iterator(p); +} + +JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Erase(TLinkListNode* p) { + JUT_ASSERT(325, !empty()); + JUT_ASSERT(326, p!=0); + JUT_ASSERT(327, p!=&oNode_); + TLinkListNode* pNext = p->pNext_; + TLinkListNode* pPrev = p->pPrev_; + JUT_ASSERT(330, pNext!=NULL); + pNext->pPrev_ = pPrev; + JUT_ASSERT(332, pPrev!=NULL); + pPrev->pNext_ = pNext; + count--; +#if DEBUG + p->clear_(); +#endif + return iterator(pNext); +} + +// NONMATCHING - missing stack +void JGadget::TNodeLinkList::Remove(TLinkListNode* p) { + remove_if(TPRIsEqual_pointer_(p)); +} + +bool JGadget::TNodeLinkList::Confirm() const { + int u = 0; + const_iterator itEnd = end(); + JGADGET_EXITWARN(357, itEnd.p_==&oNode_); + const_iterator it = begin(); + JGADGET_EXITWARN(359, it.p_==oNode_.pNext_); + for (; it != itEnd; ++it, ++u) { + JGADGET_EXITWARN(362, upNext_->pPrev_==pIt); + JGADGET_EXITWARN(366, pIt->pPrev_->pNext_==pIt); + } + JGADGET_EXITWARN(368, it.p_==&oNode_); + JGADGET_EXITWARN(369, u==size()); + return true; +} + +bool JGadget::TNodeLinkList::Confirm_iterator(const_iterator it) const { + const_iterator itBegin = begin(); + const_iterator itEnd = end(); + while (itBegin != itEnd) { + if (itBegin == it) { + return true; + } + ++itBegin; + } + JGADGET_EXITWARN(383, it==itEnd); + return true; +} diff --git a/src/JSystem/JGadget/std-vector.cpp b/src/JSystem/JGadget/std-vector.cpp new file mode 100644 index 000000000..464cd18c7 --- /dev/null +++ b/src/JSystem/JGadget/std-vector.cpp @@ -0,0 +1,23 @@ +#include "JSystem/JGadget/std-vector.h" + +u32 JGadget::vector::extend_default(u32 param_0, u32 param_1, u32 param_2) { + return param_1 << 1; +} + +JGadget::TVector_pointer_void::TVector_pointer_void(JGadget::TAllocator const& param_0) : TVector(param_0) { +} + +void dummy_weak_order(JGadget::TVector vec) { + vec.insert(NULL, 0, NULL); +} + +JGadget::TVector_pointer_void::~TVector_pointer_void() { +} + +void JGadget::TVector_pointer_void::insert(void** param_0, void* const& param_1) { + TVector::insert(param_0, param_1); +} + +void** JGadget::TVector_pointer_void::erase(void** param_0, void** param_1) { + return TVector::erase(param_0, param_1); +} diff --git a/src/JSystem/JStudio/JStudio/ctb-data.cpp b/src/JSystem/JStudio/JStudio/ctb-data.cpp new file mode 100644 index 000000000..0f1ea4e5c --- /dev/null +++ b/src/JSystem/JStudio/JStudio/ctb-data.cpp @@ -0,0 +1,3 @@ +#include "JSystem/JStudio/JStudio/ctb.h" + +const u32 JStudio::ctb::data::ga4cSignature = 'CTB\0'; diff --git a/src/JSystem/JStudio/JStudio/ctb.cpp b/src/JSystem/JStudio/JStudio/ctb.cpp new file mode 100644 index 000000000..e53f84b93 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/ctb.cpp @@ -0,0 +1,139 @@ +#include "JSystem/JStudio/JStudio/ctb.h" +#include "JSystem/JGadget/define.h" +#include +#include +#include + +JStudio::ctb::TObject::~TObject() {} + +JStudio::ctb::TObject_TxyzRy::TObject_TxyzRy(JStudio::ctb::data::TParse_TBlock const& param_0) + : TObject(param_0.get_ID(), param_0.get_IDSize(), param_0.getContent()) {} + +int JStudio::ctb::TObject_TxyzRy::getScheme() const { + return 1; +} + +JStudio::ctb::TControl::TControl() : pFactory_(NULL) {} + +JStudio::ctb::TControl::~TControl() { + JGADGET_ASSERTWARN(94, ocObject_.empty()); +} + +void JStudio::ctb::TControl::appendObject(JStudio::ctb::TObject* p) { + JUT_ASSERT(106, p!=NULL) + ocObject_.Push_back(p); +} + +void JStudio::ctb::TControl::removeObject(JStudio::ctb::TObject* p) { + JUT_ASSERT(113, p!=NULL) + ocObject_.Erase(p); +} + +void JStudio::ctb::TControl::destroyObject(JStudio::ctb::TObject* param_0) { + removeObject(param_0); + TFactory *pFactory = getFactory(); + JUT_ASSERT(129, pFactory!=NULL); + pFactory->destroy(param_0); +} + +void JStudio::ctb::TControl::destroyObject_all() { + while (!ocObject_.empty()) { + destroyObject(&ocObject_.back()); + } +} + +// NONMATCHING - TPRObject_ID_equal issues +JStudio::ctb::TObject* JStudio::ctb::TControl::getObject(void const* param_0, u32 param_1) { + JGadget::TLinkList::iterator begin = ocObject_.begin(); + JGadget::TLinkList::iterator end = ocObject_.end(); + JGadget::TLinkList::iterator local_50 = std::find_if(begin, end, object::TPRObject_ID_equal(param_0, param_1)); + if ((local_50 != end) != false) { + return &*local_50; + } + return NULL; +} + +JStudio::ctb::TObject* JStudio::ctb::TControl::getObject_index(u32 param_0) { + if (param_0 >= ocObject_.size()) { + return 0; + } + JGadget::TLinkList::iterator aiStack_14 = ocObject_.begin(); + std::advance(aiStack_14, param_0); + return &*aiStack_14; +} + +JStudio::ctb::TFactory::~TFactory() {} + +JStudio::ctb::TObject* JStudio::ctb::TFactory::create(JStudio::ctb::data::TParse_TBlock const& param_0) { + switch(param_0.get_scheme()) { + case 1: + return new TObject_TxyzRy(param_0); + default: + return NULL; + } +} + +void JStudio::ctb::TFactory::destroy(JStudio::ctb::TObject* param_0) { + delete param_0; +} + +// NONMATCHING TParse_header_block vtable location +JStudio::ctb::TParse::TParse(JStudio::ctb::TControl* param_0) : pControl_(param_0) {} + +JStudio::ctb::TParse::~TParse() {} + +bool JStudio::ctb::TParse::parseHeader_next(void const** ppData_inout, u32* puBlock_out, u32 param_3) { + JUT_ASSERT(221, ppData_inout!=NULL); + JUT_ASSERT(222, puBlock_out!=NULL); + void const* pData = *ppData_inout; + JUT_ASSERT(224, pData!=NULL); + data::TParse_THeader aTStack_478(pData); + *ppData_inout = aTStack_478.getContent(); + *puBlock_out = aTStack_478.get_blockNumber(); + if (memcmp(aTStack_478.get_signature(), &JStudio::ctb::data::ga4cSignature, sizeof(JStudio::ctb::data::ga4cSignature)) != 0) { + return false; + } + if (aTStack_478.get_byteOrder() != 0xfeff) { + return false; + } + u16 version = aTStack_478.get_version(); + if (version < 1) { + return false; + } + return version <= 1; +} + +bool JStudio::ctb::TParse::parseBlock_next(void const** ppData_inout, u32* puData_out, u32 param_3) { + JUT_ASSERT(260, ppData_inout!=NULL); + JUT_ASSERT(261, puData_out!=NULL); + void const* pData = *ppData_inout; + JUT_ASSERT(263, pData!=NULL); + data::TParse_TBlock aTStack_260(pData); + *ppData_inout = aTStack_260.getNext(); + *puData_out = aTStack_260.get_size(); + JStudio::ctb::TControl* pControl = getControl(); + JUT_ASSERT(269, pControl!=NULL); + if ((param_3 & 0x10) != 0) { + if (pControl->getObject(aTStack_260.get_ID(), aTStack_260.get_IDSize()) != NULL) { + return true; + } + } + if ((param_3 & 0x20) != 0) { + return true; + } + JStudio::ctb::TFactory* pFactory = pControl->getFactory(); + if (pFactory == NULL) { + return false; + } + + JStudio::ctb::TObject* pTVar6 = pFactory->create(aTStack_260); + if (pTVar6 == NULL) { + if ((param_3 & 0x40) == 0) { + return false; + } else { + return true; + } + } + pControl->appendObject(pTVar6); + return true; +} diff --git a/src/JSystem/JStudio/JStudio/functionvalue.cpp b/src/JSystem/JStudio/JStudio/functionvalue.cpp new file mode 100644 index 000000000..f8bca8b28 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/functionvalue.cpp @@ -0,0 +1,902 @@ +#include "JSystem/JStudio/JStudio/functionvalue.h" +#include "JSystem/JGadget/define.h" +#include "JSystem/JGadget/search.h" +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JGadget/linklist.h" +#include +#include +#include + +namespace JStudio { + +namespace { + +const ExtrapolateParameter gapfnExtrapolateParameter_[4] = { + functionvalue::extrapolateParameter_raw, + functionvalue::extrapolateParameter_repeat, + functionvalue::extrapolateParameter_turn, + functionvalue::extrapolateParameter_clamp, +}; + +} // namespace + +ExtrapolateParameter TFunctionValue::toFunction_outside(int idx) { + ExtrapolateParameter fallback = NULL; + ExtrapolateParameter result; + + result = JGadget::toValueFromIndex(idx, gapfnExtrapolateParameter_, 4, + fallback); + + if (result == NULL) { + // JUTWarn w; + // w << "unknown outside : " << idx; + + return gapfnExtrapolateParameter_[0]; + } + + return result; +} + +TFunctionValue::TFunctionValue() {} +TFunctionValue::~TFunctionValue() {} + +void TFunctionValueAttribute_refer::refer_initialize() { + clear(); +} + +static f64 dummy_literal1() { + return 0.0; +} + +namespace functionvalue { + +f64 interpolateValue_hermite(f64 c0, f64 c1, f64 x, f64 c2, f64 x2, f64 c3, f64 x3) { + f64 a; + f64 b; + f64 c; + f64 d; + + a = c0 - c1; + b = a * (1.0 / (x2 - c1)); // (a - b) * 1.0 / (c - d) + c = b - 1.0; // 1.0 + d = (3.0 + -2.0 * b) * (b * b); // 3.0 - 2.0 * b + f64 cab = (c * a * b); + f64 coeffx3 = cab * x3; + f64 cca = (c * c * a); + f64 coeffc2 = cca * c2; + return ((1.0 - d) * x + (d * c3)) + coeffc2 + coeffx3; +} + + +f64 interpolateValue_BSpline_uniform(f64 interpolationFactor, f64 point2, f64 point3, f64 point4, f64 point5) { + f64 inverseInterpolationFactor = (1.0 - interpolationFactor); + f64 inverseInterpolationFactorSquared = inverseInterpolationFactor * inverseInterpolationFactor; + f64 inverseInterpolationFactorCubed = inverseInterpolationFactorSquared * inverseInterpolationFactor; + + f64 interpolationFactorSquared = interpolationFactor * interpolationFactor; + f64 interpolationFactorCubed = interpolationFactorSquared * interpolationFactor; + + f64 coefficient1 = inverseInterpolationFactorCubed; + + f64 blendFactorForPoint3 = (1.0 / 2.0) * interpolationFactorCubed - interpolationFactorSquared + (2.0 / 3.0); + + f64 blendFactorForPoint4 = + (1.0 / 2.0) * (interpolationFactor + interpolationFactorSquared - interpolationFactorCubed) + (1.0 / 6.0); + + f64 coefficient2 = interpolationFactorCubed; + + return ((coefficient1 * point2) + (coefficient2 * point5)) * (1.0 / 6.0) + (blendFactorForPoint3 * point3) + + (blendFactorForPoint4 * point4); +} + +f64 interpolateValue_BSpline_nonuniform(f64 interpolationFactor, const f64* controlPoints, const f64* knotVector) { + f64 knot0 = knotVector[0]; + f64 knot1 = knotVector[1]; + f64 knot2 = knotVector[2]; + f64 knot3 = knotVector[3]; + f64 knot4 = knotVector[4]; + f64 knot5 = knotVector[5]; + f64 diff0 = interpolationFactor - knot0; + f64 diff1 = interpolationFactor - knot1; + f64 diff2 = interpolationFactor - knot2; + f64 diff3 = knot3 - interpolationFactor; + f64 diff4 = knot4 - interpolationFactor; + f64 diff5 = knot5 - interpolationFactor; + f64 inverseDeltaKnot32 = 1 / (knot3 - knot2); + f64 blendFactor3 = (diff3 * inverseDeltaKnot32) / (knot3 - knot1); + f64 blendFactor2 = (diff2 * inverseDeltaKnot32) / (knot4 - knot2); + f64 blendFactor1 = (diff3 * blendFactor3) / (knot3 - knot0); + f64 blendFactor4 = ((diff1 * blendFactor3) + (diff4 * blendFactor2)) / (knot4 - knot1); + f64 blendFactor5 = (diff2 * blendFactor2) / (knot5 - knot2); + f64 term1 = diff3 * blendFactor1; + f64 term2 = (diff0 * blendFactor1) + (diff4 * blendFactor4); + f64 term3 = (diff1 * blendFactor4) + (diff5 * blendFactor5); + f64 term4 = diff2 * blendFactor5; + + return (term1 * controlPoints[0]) + (term2 * controlPoints[1]) + (term3 * controlPoints[2]) + (term4 * controlPoints[3]); +} + +inline f64 interpolateValue_linear(f64 a1, f64 a2, f64 a3, f64 a4, f64 a5) { + return a3 + ((a5 - a3) * (a1 - a2)) / (a4 - a2); +} + +inline f64 interpolateValue_linear_1(f64 a1, f64 a2, f64 a3, f64 a4) { + return a3 + (a4 - a3) * (a1 - a2); +} + +inline f64 interpolateValue_plateau(f64 a1, f64 a2, f64 a3, f64 a4, f64 a5) { + return interpolateValue_hermite(a1, a2, a3, 0.0, a4, a5, 0.0); +} + +f64 extrapolateParameter_turn(f64 param_0, f64 param_1) { + f64 dVar2 = 2.0 * param_1; + f64 dVar1 = extrapolateParameter_repeat(param_0, dVar2); + if (dVar1 >= param_1) { + dVar1 = dVar2 - dVar1; + } + return dVar1; +} + +} // namespace functionvalue + +void TFunctionValueAttribute_range::range_initialize() { + fBegin_ = NAN; + fEnd_ = fBegin_; + fDifference_ = fBegin_; + + range_setProgress(TFunctionValue::PROG_INIT); + range_setAdjust(TFunctionValue::ADJ_INIT); + range_setOutside(TFunctionValue::OUT_INIT); +} + +void TFunctionValueAttribute_range::range_prepare() { + TFunctionValue::TEProgress progress = range_getProgress(); + + switch (progress) { + default: + // JUTWarn w; + // w << "unknown progress : " << progress; + case 0: + _20 = 0.0; + _28 = 1.0; + break; + case 1: + _20 = 0.0; + _28 = -1.0; + break; + case 2: + _20 = fBegin_; + _28 = -1.0; + break; + case 3: + _20 = fEnd_; + _28 = -1.0; + break; + case 4: + _20 = 0.5 * (fBegin_ + fEnd_); + _28 = -1.0; + break; + } +} + +void TFunctionValueAttribute_range::range_set(f64 begin, f64 end) { + fBegin_ = begin; + fEnd_ = end; + fDifference_ = end - begin; + + JUT_ASSERT(458, fDifference_>=TValue(0)); +} + +f64 TFunctionValueAttribute_range::range_getParameter(f64 arg1, f64 arg2, f64 arg3) const { + f64 progress = range_getParameter_progress(arg1); + TFunctionValue::TEAdjust adjust = range_getAdjust(); + + f64 result; + + switch (adjust) { + default: + // JUTWarn w; + // w << "unknown adjust : " << adjust; + case 0: + result = range_getParameter_outside(progress); + break; + case 1: + result = range_getParameter_outside(progress + fBegin_); + break; + case 2: + result = range_getParameter_outside(progress + fEnd_); + break; + case 3: + result = range_getParameter_outside(progress + 0.5 * (fBegin_ + fEnd_)); + break; + case 4: + f64 temp = range_getParameter_outside(progress); + result = arg2 + ((temp - fBegin_) * (arg3 - arg2)) / fDifference_; + break; + } + return result; +} + + +TFunctionValueAttribute_range::TFunctionValueAttribute_range() + : fBegin_(NAN), fEnd_(fBegin_), fDifference_(fBegin_), + mProgress(TFunctionValue::PROG_INIT), mAdjust(TFunctionValue::ADJ_INIT), _20(fBegin_), + _28(fBegin_), mBegin(TFunctionValue::OUT_INIT), mEnd(TFunctionValue::OUT_INIT) {} + +TFunctionValue_composite::TFunctionValue_composite() : pfn_(NULL), data((void*)NULL) { +} + +u32 TFunctionValue_composite::getType() const { + return 1; +} + +TFunctionValueAttributeSet TFunctionValue_composite::getAttributeSet() { + return TFunctionValueAttributeSet(this, NULL, NULL); +} + +void TFunctionValue_composite::initialize() { + refer_initialize(); + pfn_ = NULL; + data = TData((void*)NULL); +} + +void TFunctionValue_composite::prepare() { + /* empty function */ +} + +f64 TFunctionValue_composite::getValue(f64 arg1) { + const TFunctionValueAttribute_refer* container = refer_getContainer(); + // ASSERT(!refer_isReferring(this)); + // ASSERT(pfn_ != NULL); + + return pfn_(arg1, container, data_getData()); +} + +f64 TFunctionValue_composite::composite_raw(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + u32 index = param_2.get_unsignedInteger(); + if (index >= param_1.size()) { + return 0.0; + } + TFunctionValue** p = (TFunctionValue**)param_1.begin(); + std::advance(p, index); + JUT_ASSERT(0x247, p!=NULL); + TFunctionValue* piVar4 = *p; + return piVar4->getValue(param_3); +} + + +f64 TFunctionValue_composite::composite_index(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + s32 size = param_1.size(); + if (size <= 1) { + return 0.0; + } + TFunctionValue** local_148 = (TFunctionValue**)param_1.begin(); + TFunctionValue* pFront = *local_148; + JUT_ASSERT(599, pFront!=NULL); + TValue fData = pFront->getValue(param_3); + s32 index = floor(fData); + u32 uVar2 = param_2.get_outside(); + switch (uVar2) { + case 0: + case 3: + default: + if (index < 0) { + index = 0; + } else if (index >= size - 1) { + index = size - 2; + } + break; + case 1: { +#ifdef __MWERKS__ + div_t dt = div(index, size - 1); +#else + div_t dt = div((int)index, (int)size - 1); +#endif + index = dt.rem; + if (index < 0) { + index = size + index; + index--; + } + break; + } + case 2: + if (size - 1 == 1) { + index = 0; + } else { + u32 uVar3 = (u32)(size - 2) * 2; +#ifdef __MWERKS__ + div_t dt2 = div(index, uVar3); +#else + div_t dt2 = div((int)index, (int)uVar3); +#endif + index = dt2.rem; + if (index < 0) { + index += uVar3; + } + if (index >= size - 1) { + index = uVar3 - index; + } + } + break; + } + +#ifdef __MWERKS__ + std::advance_pointer(local_148, index + 1); +#else + std::advance(local_148, index + 1); +#endif + pFront = *local_148; + return pFront->getValue(param_3); +} + + +// TODO: remove when TContainerEnumerator_const is generic enough +template +struct TContainerEnumerator_const_TVector : public JGadget::TEnumerator { + inline TContainerEnumerator_const_TVector(JGadget::TVector_pointer const& param_1) + : JGadget::TEnumerator(param_1.begin(), param_1.end()) {} +}; + +f64 +TFunctionValue_composite::composite_parameter(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + f64 dVar4 = param_3 - param_2.get_value(); + TContainerEnumerator_const_TVector aTStack_18(param_1); + while (aTStack_18) { + TFunctionValue* const* ppiVar3 = *aTStack_18; + TFunctionValue* piVar3 = *ppiVar3; + dVar4 = piVar3->getValue(dVar4); + } + return dVar4; +} + +f64 TFunctionValue_composite::composite_add(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + f64 dVar4 = param_2.get_value(); + TContainerEnumerator_const_TVector aTStack_18(param_1); + while (aTStack_18) { + TFunctionValue* const* p = *aTStack_18; + JUT_ASSERT(0x2a1, p!=NULL); + TFunctionValue* piVar3 = *p; + dVar4 += piVar3->getValue(param_3); + } + return dVar4; +} + +f64 TFunctionValue_composite::composite_subtract(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + u32 size = param_1.size(); + if (size == 0) { + return 0.0; + } + TContainerEnumerator_const_TVector aTStack_18(param_1); + TFunctionValue* const* local_148 = *aTStack_18; + TFunctionValue* pFront = *local_148; + JUT_ASSERT(688, pFront!=NULL); + f64 dVar4 = pFront->getValue(param_3); + while (aTStack_18) { + TFunctionValue* const* p = *aTStack_18; + JUT_ASSERT(0x2b5, p!=NULL); + TFunctionValue* piVar3 = *p; + dVar4 -= piVar3->getValue(param_3); + } + dVar4 -= param_2.f32data; + return dVar4; +} + + +f64 TFunctionValue_composite::composite_multiply(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + f64 dVar4 = param_2.get_value(); + TContainerEnumerator_const_TVector aTStack_18(param_1); + while (aTStack_18) { + TFunctionValue* const* p = *aTStack_18; + JUT_ASSERT(0x2c5, p!=NULL); + TFunctionValue* piVar3 = *p; + dVar4 *= piVar3->getValue(param_3); + } + return dVar4; +} + +f64 TFunctionValue_composite::composite_divide(TVector_pointer const& param_1, + TData const& param_2, f64 param_3) { + u32 size = param_1.size(); + if (size == 0) { + return 0.0; + } + TContainerEnumerator_const_TVector aTStack_18(param_1); + TFunctionValue* const* local_148 = *aTStack_18; + TFunctionValue* pFront = *local_148; + JUT_ASSERT(724, pFront!=NULL); + TValue fData = pFront->getValue(param_3); + while (aTStack_18) { + TFunctionValue* const* p = *aTStack_18; + JUT_ASSERT(0x2d9, p!=NULL); + TFunctionValue* piVar3 = *p; + fData /= piVar3->getValue(param_3); + JGADGET_ASSERTWARN(0x2db, fData!=TValue(0)); + } +#if DEBUG + TValue v = param_2.get_value(); + JGADGET_ASSERTWARN(0x2df, fData!=TValue(0)); +#endif + fData /= param_2.f32data; + return fData; +} + +#if PLATFORM_WII || PLATFORM_SHIELD +#define NUMERIC_LIMIT double +#else +#define NUMERIC_LIMIT float +#endif + +TFunctionValue_constant::TFunctionValue_constant() : fValue_(std::numeric_limits::signaling_NaN()) {} + +u32 TFunctionValue_constant::getType() const { + return 2; +} + +TFunctionValueAttributeSet TFunctionValue_constant::getAttributeSet() { + return TFunctionValueAttributeSet(NULL, NULL, NULL); +} + +void TFunctionValue_constant::initialize() { + fValue_ = NAN; +} + +void TFunctionValue_constant::prepare() { + /* empty function */ +} + +f64 TFunctionValue_constant::getValue(f64 arg1) { + return fValue_; +} + +TFunctionValue_transition::TFunctionValue_transition() : _48(NAN), _50(_48) {} + +u32 TFunctionValue_transition::getType() const { + return 3; +} + +TFunctionValueAttributeSet TFunctionValue_transition::getAttributeSet() { + return TFunctionValueAttributeSet(NULL, this, this); +} + +void TFunctionValue_transition::initialize() { + range_initialize(); + interpolate_initialize(); + + _48 = NAN; + _50 = _48; +} + +void TFunctionValue_transition::prepare() { + range_prepare(); + interpolate_prepare(); +} + +f64 TFunctionValue_transition::getValue(f64 param_1) { + f64 progress = range_getParameter_progress(param_1); + f64 dVar3 = range_getParameter_outside(progress); + switch (range_getAdjust()) { + default: + if (dVar3 < range_getBegin()) { + return _48; + } + return _50; + case TFunctionValue::ADJ_UNK2: + if (dVar3 < range_getEnd()) { + return _48; + } + return _50; + case TFunctionValue::ADJ_UNK3: + ADJ_UNK3_label: + if (dVar3 < 0.5 * (range_getBegin() + range_getEnd())) { + return _48; + } + return _50; + case TFunctionValue::ADJ_UNK4: + if (dVar3 < range_getBegin()) { + return _48; + } + if (dVar3 >= range_getEnd()) { + return _50; + } + switch (interpolate_get()) { + case 0: + goto ADJ_UNK3_label; + case 1: + case 3: + return _48 + ((dVar3 - range_getBegin()) * data_getDifference()) / range_getDifference(); + case 2: + return functionvalue::interpolateValue_plateau(dVar3, range_getBegin(), _48, range_getEnd(), _50); + default: + goto ADJ_UNK3_label; + } + } +} + +TFunctionValue_list::TFunctionValue_list() : _44(NULL), uData_(0), _50(NAN), pfnUpdate_(NULL) {} + +u32 TFunctionValue_list::getType() const { + return 4; +} + +TFunctionValueAttributeSet TFunctionValue_list::getAttributeSet() { + return TFunctionValueAttributeSet(NULL, this, this); +} + +void TFunctionValue_list::initialize() { + range_initialize(); + interpolate_initialize(); + + _44 = NULL; + uData_ = 0; + _50 = NAN; + pfnUpdate_ = NULL; +} + +void TFunctionValue_list::prepare() { + range_prepare(); + interpolate_prepare(); + + u32 interp = interpolate_get(); + + switch (interp) { + default: + // JUTWarn w; + // w << "unknown interpolation : " << interp; + case 0: + pfnUpdate_ = update_INTERPOLATE_NONE_; + break; + case 1: + pfnUpdate_ = update_INTERPOLATE_LINEAR_; + break; + case 2: + pfnUpdate_ = update_INTERPOLATE_PLATEAU_; + break; + case 3: + pfnUpdate_ = update_INTERPOLATE_BSPLINE_dataMore3_; + if (uData_ == 2) + pfnUpdate_ = update_INTERPOLATE_LINEAR_; + break; + } +} + +f64 TFunctionValue_list::getValue(f64 param_1) { + f64 dVar9 = range_getParameter_progress(param_1); + u32 iVar7 = uData_ - 1; + TFunctionValue::TEAdjust iVar5 = range_getAdjust(); + f64 dVar12 = iVar7; + TIndexData_ local_178; + f64 parOutside; + switch (iVar5) { + case 0: + default: + parOutside = range_getParameter_outside(dVar9); + local_178._0 = parOutside / _50; + break; + case 1: + parOutside = range_getParameter_outside(dVar9 + range_getBegin()); + local_178._0 = parOutside / _50; + break; + case 2: + parOutside = range_getParameter_outside(dVar9 + range_getEnd()); + local_178._0 = parOutside / _50; + break; + case 3: + parOutside = range_getParameter_outside(dVar9 + 0.5 * (range_getBegin() + range_getEnd())); + local_178._0 = parOutside / _50; + break; + case 4: + parOutside = range_getParameter_outside(dVar9); + local_178._0 = (dVar12 * (parOutside - range_getBegin())) / range_getDifference(); + break; + } + + if (local_178._0 < 0.0) { + return _44[0]; + } + if (local_178._0 >= dVar12) { + return _44[iVar7]; + } + local_178._8 = floor(local_178._0); + local_178._10 = local_178._8; + JUT_ASSERT(1063, pfnUpdate_!=NULL); + return pfnUpdate_(*this, local_178); +} + + +f64 TFunctionValue_list::update_INTERPOLATE_NONE_(const TFunctionValue_list& rThis, + const TIndexData_& data) { + return rThis._44[data._10]; +} + +f64 TFunctionValue_list::update_INTERPOLATE_LINEAR_(const TFunctionValue_list& rThis, + const TIndexData_& data) { + return functionvalue::interpolateValue_linear_1(data._0, data._8, rThis._44[data._10], + rThis._44[data._10 + 1]); +} + +f64 TFunctionValue_list::update_INTERPOLATE_PLATEAU_(const TFunctionValue_list& rThis, + const TIndexData_& data) { + const f32* arr = rThis._44; + + return functionvalue::interpolateValue_plateau(data._0, data._8, arr[data._10], + 1.0 + data._8, arr[data._10 + 1]); +} + + +f64 TFunctionValue_list::update_INTERPOLATE_BSPLINE_dataMore3_( + TFunctionValue_list const& rThis, TFunctionValue_list::TIndexData_ const& param_2) { + f64 dVar11 = rThis._44[param_2._10]; + f64 dVar10 = rThis._44[param_2._10 + 1]; + f64 dVar9; + f64 dVar8; + if (param_2._10 == 0) { + JUT_ASSERT(1119, rThis.uData_>=3); + dVar9 = 2.0 * dVar11 - dVar10; + dVar8 = rThis._44[param_2._10 + 2]; + } else { + if (param_2._10 == rThis.uData_ - 2) { + JUT_ASSERT(1125, rThis.uData_>=3); + dVar9 = rThis._44[param_2._10 - 1]; + dVar8 = 2.0 * dVar10 - dVar11; + } else { + JUT_ASSERT(1131, rThis.uData_>=3); + dVar9 = rThis._44[param_2._10 - 1]; + dVar8 = rThis._44[param_2._10 + 2]; + } + } + return functionvalue::interpolateValue_BSpline_uniform(param_2._0 - param_2._8, dVar9, dVar11, dVar10, dVar8); +} + + +TFunctionValue_list_parameter::TFunctionValue_list_parameter() + : pfData_(NULL), uData_(0), dat1(*this, NULL), dat2(dat1), dat3(dat1), pfnUpdate_(NULL) {} + +u32 TFunctionValue_list_parameter::getType() const { + return 5; +} + +TFunctionValueAttributeSet TFunctionValue_list_parameter::getAttributeSet() { + return TFunctionValueAttributeSet(NULL, this, this); +} + +void TFunctionValue_list_parameter::data_set(const f32* pf, u32 u) { + JUT_ASSERT(1277, (pf != NULL) || (u == 0)); + + pfData_ = pf; + uData_ = u; + + dat1.set(pfData_); + dat2.set(&pfData_[uData_ * 2]); + dat3 = dat1; +#if DEBUG + pfnUpdate_ = NULL; +#endif +} + +void TFunctionValue_list_parameter::initialize() { + range_initialize(); + interpolate_initialize(); + + pfData_ = NULL; + uData_ = 0; + + TIterator_data_ iter(*this, NULL); + + dat1 = iter; + dat2 = dat1; + dat3 = dat1; + pfnUpdate_ = NULL; +} + +void TFunctionValue_list_parameter::prepare() { + range_prepare(); + interpolate_prepare(); + + u32 interp = interpolate_get(); + switch (interp) { + default: + // JUTWarn w; + // w << "unknown interpolation : " << interp; + case 0: + pfnUpdate_ = update_INTERPOLATE_NONE_; + break; + case 1: + pfnUpdate_ = update_INTERPOLATE_LINEAR_; + break; + case 2: + pfnUpdate_ = update_INTERPOLATE_PLATEAU_; + break; + case 3: + pfnUpdate_ = update_INTERPOLATE_BSPLINE_dataMore3_; + if (uData_ != 2) + return; + pfnUpdate_ = update_INTERPOLATE_LINEAR_; + break; + } +} + +f64 TFunctionValue_list_parameter::getValue(f64 param_0) { + param_0 = range_getParameter(param_0, data_getValue_front(), data_getValue_back()); + JUT_ASSERT(1395, pfData_!=NULL) + + dat3 = JGadget::findUpperBound_binary_current(dat1, dat2, dat3, param_0); + if (dat3 == dat1) { + return dat3.get()[1]; + } + if (dat3 == dat2) { + --dat3; + return dat3.get()[1]; + } + + const f32* pf = dat3.get(); + JUT_ASSERT(1411, (pfData_<=pf-suData_size)&&(pf=3) + const f32* pfVar2 = rThis.dat3.get(); + f64 local_68[4]; + f64 local_48[6]; + local_68[1] = pfVar2[-1]; + local_68[2] = pfVar2[1]; + local_48[2] = pfVar2[-2]; + local_48[3] = pfVar2[0]; + s32 iVar5 = ((intptr_t)pfVar2 - (intptr_t)rThis.dat1.get()) / 4; + s32 iVar3 = ((intptr_t)rThis.dat2.get() - (intptr_t)pfVar2) / 4; + switch(iVar5) { + case 2: + local_68[0] = 2.0 * local_68[1] - local_68[2]; + local_68[3] = pfVar2[3]; + local_48[4] = pfVar2[2]; + local_48[1] = 2.0 * local_48[2] - local_48[3]; + local_48[0] = 2.0 * local_48[2] - local_48[4]; + switch (iVar3) { + case 2: + JUT_ASSERT(1481, false); + case 4: + local_48[5] = 2.0 * local_48[4] - local_48[3]; + break; + default: + local_48[5] = pfVar2[4]; + break; + } + break; + case 4: + local_68[0] = pfVar2[-3]; + local_48[1] = pfVar2[-4]; + local_48[0] = 2.0 * local_48[1] - local_48[2]; + switch (iVar3) + { + case 2: + local_68[3] = 2.0 * local_68[2] - local_68[1]; + local_48[4] = 2.0 * local_48[3] - local_48[2]; + local_48[5] = 2.0 * local_48[3] - local_48[1]; + break; + case 4: + local_68[3] = pfVar2[3]; + local_48[4] = pfVar2[2]; + local_48[5] = 2.0 * local_48[4] - local_48[3]; + break; + default: + local_68[3] = pfVar2[3]; + local_48[4] = pfVar2[2]; + local_48[5] = pfVar2[4]; + } + break; + default: + local_68[0] = pfVar2[-3]; + local_48[1] = pfVar2[-4]; + local_48[0] = pfVar2[-6]; + switch (iVar3) { + case 2: + local_68[3] = 2.0 * local_68[2] - local_68[1]; + local_48[4] = 2.0 * local_48[3] - local_48[2]; + local_48[5] = 2.0 * local_48[3] - local_48[1]; + break; + case 4: + local_68[3] = pfVar2[3]; + local_48[4] = pfVar2[2]; + local_48[5] = 2.0 * local_48[4] - local_48[3]; + break; + default: + local_68[3] = pfVar2[3]; + local_48[4] = pfVar2[2]; + local_48[5] = pfVar2[4]; + break; + } + break; + } + return functionvalue::interpolateValue_BSpline_nonuniform(param_2, local_68, local_48); +} + + +TFunctionValue_hermite::TFunctionValue_hermite() + : pfData_(NULL), u_(0), uSize_(0), dat1(*this, NULL), dat2(dat1), dat3(dat1) {} + +u32 JStudio::TFunctionValue_hermite::getType() const { + return 6; +} + +TFunctionValueAttributeSet TFunctionValue_hermite::getAttributeSet() { + return TFunctionValueAttributeSet(NULL, this, NULL); +} + +void TFunctionValue_hermite::data_set(const f32* pf, u32 u, u32 uSize) { + JUT_ASSERT(1676, (pf != NULL) || (u == 0)); + JUT_ASSERT(1677, (uSize == 3) || (uSize == 4)); + + pfData_ = pf; + u_ = u; + uSize_ = uSize; + + dat1.set(pfData_, uSize_); + dat2.set(&pfData_[u_ * uSize_], uSize_); + dat3 = dat1; +} + +void TFunctionValue_hermite::initialize() { + range_initialize(); + + pfData_ = NULL; + u_ = 0; + uSize_ = 0; + + dat1 = TIterator_data_(*this, NULL); + dat2 = dat1; + dat3 = dat1; +} + +void TFunctionValue_hermite::prepare() { + range_prepare(); +} + +f64 TFunctionValue_hermite::getValue(f64 param_0) { + param_0 = range_getParameter(param_0, data_getValue_front(), data_getValue_back()); + JUT_ASSERT(1716, pfData_!=NULL) + + dat3 = JGadget::findUpperBound_binary_current(dat1, dat2, dat3, param_0); + + if (dat3 == dat1) { + return dat3.get()[1]; + } + if (dat3 == dat2) { + --dat3; + return dat3.get()[1]; + } + + const f32* pfVar5 = dat3.get(); + const f32* pfVar7 = pfVar5 - uSize_; + return functionvalue::interpolateValue_hermite( + param_0, pfVar7[0], pfVar7[1], + pfVar7[uSize_ - 1], pfVar5[0], + pfVar5[1], pfVar5[2]); +} + +} // namespace JStudio diff --git a/src/JSystem/JStudio/JStudio/fvb-data-parse.cpp b/src/JSystem/JStudio/JStudio/fvb-data-parse.cpp new file mode 100644 index 000000000..ea01642f9 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/fvb-data-parse.cpp @@ -0,0 +1,16 @@ +#include "JSystem/JStudio/JStudio/fvb-data-parse.h" + +void JStudio::fvb::data::TParse_TParagraph::getData(TParse_TParagraph::TData* pData) const +{ + JUT_ASSERT(24, pData!=NULL); + const void *ptr = getRaw(); + ptr = JGadget::binary::parseVariableUInt_16_32_following(ptr, (u32*)pData, (u32*)&pData->u32Type, NULL); + u32 t = (u32)pData->u32Size; + if (!t) { + pData->pContent = NULL; + pData->next = (const u16*)ptr; + } else { + pData->pContent = (const u16*)ptr; + pData->next = (u8*)ptr + JGadget::binary::align_roundUp(t, 4); + } +} diff --git a/src/JSystem/JStudio/JStudio/fvb-data.cpp b/src/JSystem/JStudio/JStudio/fvb-data.cpp new file mode 100644 index 000000000..46d5f9900 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/fvb-data.cpp @@ -0,0 +1,3 @@ +#include "JSystem/JStudio/JStudio/fvb-data.h" + +const char JStudio::fvb::data::ga4cSignature[4] = "FVB"; diff --git a/src/JSystem/JStudio/JStudio/fvb.cpp b/src/JSystem/JStudio/JStudio/fvb.cpp new file mode 100644 index 000000000..8846293ec --- /dev/null +++ b/src/JSystem/JStudio/JStudio/fvb.cpp @@ -0,0 +1,459 @@ +#include "JSystem/JStudio/JStudio/fvb.h" +#include "JSystem/JGadget/define.h" +#include + +namespace JStudio { +namespace fvb { + +TObject::~TObject() { + // JGADGET_ASSERTWARN(26, pfv_!=NULL); +} + +void TObject::prepare(data::TParse_TBlock const& rBlock, TControl* pControl) { + JUT_ASSERT(35, pfv_!=NULL); + JUT_ASSERT(36, pControl!=NULL); + TFunctionValueAttributeSet set = pfv_->getAttributeSet(); + const void* pNext = (const void*)rBlock.getNext(); + const void* pData = (const void*)rBlock.getContent(); + while (pData < pNext) { + data::TParse_TParagraph para(pData); + data::TParse_TParagraph::TData dat; + para.getData(&dat); + u32 u32Type = dat.u32Type; + u32 u32Size = dat.u32Size; + const void* pContent = dat.pContent; + switch (u32Type) { + case 0: + goto end; + case 1: + prepare_data_(dat, pControl); + break; + case 0x10: { + // JGADGET_ASSERTWARN(61, u32Size>=4); + JUT_ASSERT(62, pContent!=NULL); + TFunctionValueAttribute_refer* pfvaRefer = set.refer_get(); + // JGADGET_ASSERTWARN(64, pfvaRefer!=NULL); + if (pfvaRefer == NULL) { + // JGADGET_WARNMSG(67, "invalid paragraph"); + break; + } + JGadget::TVector_pointer& rCnt = pfvaRefer->refer_referContainer(); + u8* content = (u8*)pContent; + u32 i = *(u32*)content; + u8* ptr = content + 4; + for (; i != 0; i--) { + u32 size = *(u32*)ptr; + TObject* pObject = pControl->getObject(ptr + 4, size); + if (pObject != NULL) { + TFunctionValue* const rfv = pObject->referFunctionValue(); + TFunctionValue* const* pRfv = &rfv; + rCnt.push_back(*pRfv); + } else { + JGADGET_WARNMSG(85, "object not found by ID"); + } + ptr += align_roundUp(size, 4) + 4; + } + } break; + case 0x11: { + JGADGET_ASSERTWARN(93, u32Size>=4); + JUT_ASSERT(94, pContent!=NULL); + TFunctionValueAttribute_refer* pfvaRefer = set.refer_get(); + JGADGET_ASSERTWARN(96, pfvaRefer!=NULL); + if (pfvaRefer == NULL) { + JGADGET_WARNMSG(99, "invalid paragraph"); + break; + } + + JGadget::TVector_pointer& rCnt = pfvaRefer->refer_referContainer(); + u8* ptr = (u8*)pContent; + u32 i = *(u32*)ptr; + for (; ptr += 4, i != 0; i--) { + u32 index = *(u32*)ptr; + TObject* pObject = pControl->getObject_index(index); + if (pObject != NULL) { + TFunctionValue* const rfv = pObject->referFunctionValue(); + TFunctionValue* const* pRfv = &rfv; + rCnt.push_back(*pRfv); + } else { + JGADGET_WARNMSG(114, "object not found by index : " << index); + } + } + } break; + case 0x12: { + JGADGET_ASSERTWARN(121, u32Size==8); + JUT_ASSERT(122, pContent!=NULL); + TFunctionValueAttribute_range* pfvaRange = set.range_get(); + JGADGET_ASSERTWARN(124, pfvaRange!=NULL); + if (pfvaRange == NULL) { + JGADGET_WARNMSG(127, "invalid paragraph"); + break; + } + f32* arr = (f32*)pContent; + pfvaRange->range_set(arr[0], arr[1]); + } break; + case 0x13: { + JGADGET_ASSERTWARN(138, u32Size==4); + JUT_ASSERT(139, pContent!=NULL); + TFunctionValueAttribute_range* pfvaRange = set.range_get(); + JGADGET_ASSERTWARN(141, pfvaRange!=NULL); + if (pfvaRange == NULL) { + JGADGET_WARNMSG(144, "invalid paragraph"); + break; + } + + TFunctionValue::TEProgress prog = *(TFunctionValue::TEProgress*)pContent; + pfvaRange->range_setProgress(prog); + } break; + case 0x14: { + JGADGET_ASSERTWARN(156, u32Size==4); + JUT_ASSERT(157, pContent!=NULL); + TFunctionValueAttribute_range* pfvaRange = set.range_get(); + JGADGET_ASSERTWARN(159, pfvaRange!=NULL); + if (pfvaRange == NULL) { + JGADGET_WARNMSG(162, "invalid paragraph"); + break; + } + + TFunctionValue::TEAdjust adjust = *(TFunctionValue::TEAdjust*)pContent; + pfvaRange->range_setAdjust(adjust); + } break; + case 0x15: { + JGADGET_ASSERTWARN(174, u32Size==4); + JUT_ASSERT(175, pContent!=NULL); + TFunctionValueAttribute_range* pfvaRange = set.range_get(); + JGADGET_ASSERTWARN(177, pfvaRange!=NULL); + if (pfvaRange == NULL) { + JGADGET_WARNMSG(180, "invalid paragraph"); + break; + } + + u16* out = (u16*)pContent; + pfvaRange->range_setOutside((TFunctionValue::TEOutside)out[0], + (TFunctionValue::TEOutside)out[1]); + } break; + case 0x16: { + JGADGET_ASSERTWARN(193, u32Size==4); + JUT_ASSERT(194, pContent!=NULL); + TFunctionValueAttribute_interpolate* pfvaInterpolate = set.interpolate_get(); + JGADGET_ASSERTWARN(197, pfvaInterpolate!=NULL); + if (pfvaInterpolate == NULL) { + JGADGET_WARNMSG(200, "invalid paragraph"); + break; + } + + TFunctionValue::TEInterpolate interp = *(TFunctionValue::TEInterpolate*)pContent; + pfvaInterpolate->interpolate_set(interp); + } break; + default: + JGADGET_WARNMSG(211, "unknown paragraph : " << u32Type); + break; + } + pData = dat.next; + JUT_ASSERT(214, pData!=NULL); + } +end: + JGADGET_ASSERTWARN(216, pData==pNext); + pfv_->prepare(); +} + +namespace { + +TFunctionValue_composite::TData getCompositeData_raw_(const void* arg1) { + return TFunctionValue_composite::TData(*(const void**)arg1); +} + +TFunctionValue_composite::TData getCompositeData_index_(const void* arg1) { + return TFunctionValue_composite::TData(*(u32*)arg1); +} + +TFunctionValue_composite::TData getCompositeData_parameter_(const void* arg1) { + return TFunctionValue_composite::TData(*(f32*)arg1); +} + +TFunctionValue_composite::TData getCompositeData_add_(const void* arg1) { + return TFunctionValue_composite::TData(*(f32*)arg1); +} + +TFunctionValue_composite::TData getCompositeData_subtract_(const void* arg1) { + return TFunctionValue_composite::TData(*(f32*)arg1); +} + +TFunctionValue_composite::TData getCompositeData_multiply_(const void* arg1) { + return TFunctionValue_composite::TData(*(f32*)arg1); +} + +TFunctionValue_composite::TData getCompositeData_divide_(const void* arg1) { + return TFunctionValue_composite::TData(*(f32*)arg1); +} + +const data::CompositeOperation saCompositeOperation_[8] = { + {NULL, NULL}, + {&TFunctionValue_composite::composite_raw, &getCompositeData_raw_}, + {&TFunctionValue_composite::composite_index, &getCompositeData_index_}, + {&TFunctionValue_composite::composite_parameter, &getCompositeData_parameter_}, + {&TFunctionValue_composite::composite_add, &getCompositeData_add_}, + {&TFunctionValue_composite::composite_subtract, &getCompositeData_subtract_}, + {&TFunctionValue_composite::composite_multiply, &getCompositeData_multiply_}, + {&TFunctionValue_composite::composite_divide, &getCompositeData_divide_}, +}; + +static const data::CompositeOperation* getCompositeOperation_(data::TEComposite comp) { + return &saCompositeOperation_[comp]; +} + +} // namespace + +TObject_composite::TObject_composite(const data::TParse_TBlock& block) : TObject(block, &fnValue) {} + +void TObject_composite::prepare_data_(const data::TParse_TParagraph::TData& rData, + TControl* control) { + JUT_ASSERT(306, rData.u32Type==data::PARAGRAPH_DATA); + u32 u32Size = rData.u32Size; + struct unknown { + data::TEComposite composite_type; + u32 data; + }; + + const unknown* pContent = static_cast(rData.pContent); + JGADGET_ASSERTWARN(310, u32Size== 8); + JUT_ASSERT(311, pContent!=NULL); + + data::TEComposite type = pContent->composite_type; + const data::CompositeOperation* op = getCompositeOperation_(type); + data::CompositeDataFunc pfn = op->getCompositeData; + JUT_ASSERT(316, pfn!=NULL); + fnValue.data_set(op->composite, pfn(&pContent->data)); +} + +TObject_constant::TObject_constant(data::TParse_TBlock const& param_0) + : TObject(param_0, &fnValue) {} + +void TObject_constant::prepare_data_(const data::TParse_TParagraph::TData& rData, + TControl* control) { + JUT_ASSERT(337, rData.u32Type==data::PARAGRAPH_DATA); + + u32 u32Size = rData.u32Size; + const f32* pContent = static_cast(rData.pContent); + JGADGET_ASSERTWARN(341, u32Size==4); + JUT_ASSERT(342, pContent!=NULL); + f32 val = pContent[0]; + fnValue.data_set(val); +} + +TObject_transition::TObject_transition(data::TParse_TBlock const& param_0) + : TObject(param_0, &fnValue) {} + +void TObject_transition::prepare_data_(const data::TParse_TParagraph::TData& rData, + TControl* control) { + // ASSERT(rData.u32Type == data::PARAGRAPH_DATA); + + u32 u32Size = rData.u32Size; + JGADGET_ASSERTWARN(0, u32Size == 8); + + const f32* pContent = static_cast(rData.pContent); + // ASSERT(pContent != NULL); + + fnValue.data_set(pContent[0], pContent[1]); +} + +TObject_list::TObject_list(data::TParse_TBlock const& param_0) : TObject(param_0, &fnValue) {} + +void TObject_list::prepare_data_(const data::TParse_TParagraph::TData& rData, TControl* control) { + // ASSERT(rData.u32Type == data::PARAGRAPH_DATA); + + u32 u32Size = rData.u32Size; + JGADGET_ASSERTWARN(0, u32Size >= 8); + + const ListData* pContent = static_cast(rData.pContent); + // ASSERT(pContent != NULL); + + fnValue.data_setInterval(pContent->_0); + fnValue.data_set(pContent->_8, pContent->_4); +} + +TObject_list_parameter::TObject_list_parameter(data::TParse_TBlock const& param_0) + : TObject(param_0, &fnValue) {} + +void TObject_list_parameter::prepare_data_(const data::TParse_TParagraph::TData& rData, + TControl* control) { + // ASSERT(rData.u32Type == data::PARAGRAPH_DATA); + + u32 u32Size = rData.u32Size; + JGADGET_ASSERTWARN(0, u32Size >= 8); + + const ListData* pContent = static_cast(rData.pContent); + // ASSERT(pContent != NULL); + + fnValue.data_set(pContent->_4, pContent->_0); +} + +TObject_hermite::TObject_hermite(data::TParse_TBlock const& param_0) : TObject(param_0, &fnValue) {} + +void TObject_hermite::prepare_data_(const data::TParse_TParagraph::TData& rData, + TControl* control) { + // ASSERT(rData.u32Type == data::PARAGRAPH_DATA); + + u32 u32Size = rData.u32Size; + JGADGET_ASSERTWARN(0, u32Size >= 8); + + const ListData* pContent = static_cast(rData.pContent); + // ASSERT(pContent != NULL); + + fnValue.data_set(pContent->_4, pContent->_0 & 0xFFFFFFF, pContent->_0 >> 0x1C); +} + +TControl::TControl() : pFactory(NULL) {} + +TControl::~TControl() { + JGADGET_ASSERTWARN(0, ocObject_.empty()); +} + +void TControl::appendObject(TObject* object) { + ocObject_.Push_back(object); +} + +void TControl::removeObject(TObject* object) { + ocObject_.Erase(object); +} + +void TControl::destroyObject(TObject* object) { + removeObject(object); + getFactory()->destroy(object); +} + +void TControl::destroyObject_all() { + while (!ocObject_.empty()) { + destroyObject(&ocObject_.back()); + } +} + +TObject* TControl::getObject(void const* id, u32 idSize) { + typedef JGadget::TLinkList::iterator iterator; + iterator begin = ocObject_.begin(); + iterator end = ocObject_.end(); + iterator it = std::find_if(begin, end, object::TPRObject_ID_equal(id, idSize)); + return it != end ? &*it : NULL; +} + +TObject* TControl::getObject_index(u32 index) { + if (index >= ocObject_.size()) { + return NULL; + } + + JGadget::TLinkList::iterator it = ocObject_.begin(); + std::advance(it, index); + return &*it; +} + +TFactory::~TFactory() {} + +TObject* TFactory::create(data::TParse_TBlock const& rBlock) { + switch (rBlock.get_type()) { + case 1: + return new TObject_composite(rBlock); + case 2: + return new TObject_constant(rBlock); + case 3: + return new TObject_transition(rBlock); + case 4: + return new TObject_list(rBlock); + case 5: + return new TObject_list_parameter(rBlock); + case 6: + return new TObject_hermite(rBlock); + default: + // JUTWarn w; + // w << "unknown type : "; + return NULL; + } +} + +void TFactory::destroy(TObject* pObject) { + delete pObject; +} + +TParse::TParse(TControl* pControl) : pControl_(pControl) { + // ASSERT(pControl_ != NULL); +} + +TParse::~TParse() {} + +bool TParse::parseHeader_next(void const** ppData_inout, u32* puBlock_out, u32 flags) { + // ASSERT(ppData_inout != NULL); + // ASSERT(puBlock_out != NULL); + + const void* pData = *ppData_inout; + // ASSERT(pData != NULL); + + const data::TParse_THeader header(pData); + *ppData_inout = header.getContent(); + *puBlock_out = header.get_blockNumber(); + + if (memcmp(header.get_signature(), &data::ga4cSignature, 4) != 0) { + // JUTWarn w; + // w << "unknown signature"; + return false; + } + + if (header.get_byteOrder() != 0xFEFF) { + // JUTWarn w; + // w << "illegal byte-order"; + return false; + } + u16 version = header.get_version(); + if (version < 2) { + // JUTWarn w; + // w << "obselete version : " << (s32)0; + return false; + } else if (version > 0x100) { + // JUTWarn w; + // w << "unknown version : " << version; + return false; + } + return true; +} + +bool TParse::parseBlock_next(void const** ppData_inout, u32* puData_out, u32 flags) { + // ASSERT(ppData_inout != NULL); + // ASSERT(puData_out != NULL); + + const void* pData = *ppData_inout; + // ASSERT(pData != NULL); + data::TParse_TBlock blk(pData); + *ppData_inout = blk.getNext(); + *puData_out = blk.get_size(); + + TControl* pControl = getControl(); + // ASSERT(pControl != NULL); + + if (flags & 0x10) { + if (pControl->getObject(blk.get_ID(), blk.get_IDSize()) != NULL) + return 1; + } + if (flags & 0x20) { + return 1; + } + + TFactory* pFactory = pControl->getFactory(); + if (pFactory == NULL) { + // JUTWarn w; + // w << "factory not specified"; + return 0; + } + + TObject* pObject = pFactory->create(blk); + if (pObject == NULL) { + // JUTWarn w; + // w << "can't create function-value"; + if (flags & 0x40) { + return 1; + } + return 0; + } + pObject->prepare(blk, pControl); + pControl->appendObject(pObject); + return 1; +} + +} // namespace fvb +} // namespace JStudio diff --git a/src/JSystem/JStudio/JStudio/jstudio-control.cpp b/src/JSystem/JStudio/JStudio/jstudio-control.cpp new file mode 100644 index 000000000..18abf6d6a --- /dev/null +++ b/src/JSystem/JStudio/JStudio/jstudio-control.cpp @@ -0,0 +1,192 @@ +// +// jstudio-control +// + +#include "JSystem/JStudio/JStudio/jstudio-control.h" +#include "JSystem/JStudio/JStudio/jstudio-math.h" +#include "JSystem/JStudio/JStudio/jstudio-data.h" +#include + +JStudio::TControl::TControl() { + mTransformOnSet = false; + mTransformOnGet = false; + Vec aVStack_20 = {0.0f,0.0f,0.0f}; + transform_setOrigin_TxyzRy(aVStack_20, 0.0f); +} + +JStudio::TControl::~TControl() {} + +void JStudio::TControl::setFactory(JStudio::TFactory* factory) { + fvb::TFactory* fvbFactory = NULL; + ctb::TFactory* ctbFactory = NULL; + if (factory != NULL) { + fvbFactory = &factory->fvb_Factory; + ctbFactory = &factory->ctb_Factory; + } + stb::TControl::setFactory(factory); + fvb_Control.setFactory(fvbFactory); + ctb_Control.setFactory(ctbFactory); +} + +int JStudio::TControl::transformOnSet_setOrigin_TxyzRy(Vec const& param_0, f32 param_1) { + field_0x8c = param_0; + mTransformOnSet_RotationY = param_1; + JStudio::math::getTransformation_RyT(mTransformOnSet_Matrix, param_0, param_1); + return 1; +} + +int JStudio::TControl::transformOnGet_setOrigin_TxyzRy(Vec const& param_0, f32 param_1) { + field_0x98 = param_0; + mTransformOnGet_RotationY = param_1; + Mtx afStack_48; + MTXTrans(afStack_48, -param_0.x, -param_0.y, -param_0.z); + math::rotate_y(mTransformOnGet_Matrix, afStack_48, -param_1); + return 1; +} + +int JStudio::TControl::transform_setOrigin_ctb(JStudio::ctb::TObject const& param_0) { + switch (param_0.getScheme()) { + case 1: { + const f32* pfVar4 = (const f32*)param_0.getData(); + Vec local_144 = {0.0f, 0.0f, 0.0f}; + local_144.x = pfVar4[0]; + local_144.y = pfVar4[1]; + local_144.z = pfVar4[2]; + transform_setOrigin_TxyzRy(local_144, pfVar4[3]); + break; + } + default: + return 0; + } + return 1; +} + +bool JStudio::TControl::transform_setOrigin_ctb_index(u32 index) { + ctb::TObject* object = ctb_getObject_index(index); + if (object == NULL) { + return false; + } + transform_setOrigin_ctb(*object); + return true; +} + +JStudio::TCreateObject::~TCreateObject() {} + +JStudio::TFactory::~TFactory() {} + +void JStudio::TFactory::appendCreateObject(JStudio::TCreateObject* param_0) { + mList.Push_back(param_0); +} + + +JStudio::TObject* JStudio::TFactory::create(JStudio::stb::data::TParse_TBlock_object const& rParse) { + JGadget::TContainerEnumerator > aTStack_368(mList); + while(aTStack_368) { + TCreateObject& piVar1 = *aTStack_368; + JStudio::TObject* obj; + if (piVar1.create(&obj, rParse)) { + return obj; + } + } +#if DEBUG + u32 type = rParse.get_type(); + char a5c[8]; + stb::data::toString_block(a5c, type); + const char* szID = (const char*)rParse.get_ID(); + JGADGET_ASSERTWARN(0x108, rParse.get_IDSize()>0); + JGADGET_ASSERTWARN(0x109, szID[rParse.get_IDSize()-1]=='\\0'); + JGADGET_WARNMSG3(0x10c, "ID not found\n demo object : ", szID, "\n type : ", a5c); +#endif + return NULL; +} + +JStudio::TParse::TParse(JStudio::TControl* param_0) : stb::TParse(param_0) { +} + +JStudio::TParse::~TParse() {} + +bool JStudio::TParse::parseHeader(JStudio::stb::data::TParse_THeader const& param_0, + u32 param_1) { + const JStudio::stb::data::THeader::Target& target = param_0.get_target(); + if (memcmp(target.name, JStudio::data::ga8cSignature, sizeof(JStudio::data::ga8cSignature)) != 0) { + return false; + } + if (target.target_version < 2) { + return false; + } + if (target.target_version > 6) { + return false; + } + JStudio::TControl* pControl = getControl(); + JUT_ASSERT(322, pControl!=NULL); + if ((param_1 & 0x100) == 0) { + Vec local_468 = {0.0f, 0.0f, 0.0f}; + pControl->transform_setOrigin_TxyzRy(local_468, 0.0f); + pControl->transform_enable(false); + } + return true; +} + +bool JStudio::TParse::parseBlock_block(JStudio::stb::data::TParse_TBlock const& param_0, + u32 param_1) { + switch(param_0.get_type()) { + case 'JFVB': + return parseBlock_block_fvb_(param_0, param_1); + case 'JCTB': + return parseBlock_block_ctb_(param_0, param_1); + default: + return stb::TParse::parseBlock_block(param_0, param_1); + } +} + +bool JStudio::TParse::parseBlock_block_fvb_(JStudio::stb::data::TParse_TBlock const& param_0, + u32 param_1) { + TControl* pControl = getControl(); + JUT_ASSERT(361, pControl!=NULL); + const void* pContent = param_0.getContent(); + JUT_ASSERT(363, pContent!=NULL); + u32 uVar4 = param_1 & 0xf; + if ((param_1 & 0x10) != 0) { + uVar4 |= 0x10; + } + if ((param_1 & 0x20) != 0) { + uVar4 |= 0x20; + } + if ((param_1 & 0x40) != 0) { + uVar4 |= 0x40; + } + fvb::TParse aTStack_30(&pControl->fvb_Control); + if (!aTStack_30.parse(pContent, uVar4)) { + return false; + } + return true; +} + +bool JStudio::TParse::parseBlock_block_ctb_(JStudio::stb::data::TParse_TBlock const& param_0, + u32 param_1) { + TControl* pControl = getControl(); + JUT_ASSERT(386, pControl!=NULL); + const void* pContent = param_0.getContent(); + JUT_ASSERT(388, pContent!=NULL); + u32 uVar4 = param_1 & 0xf; + if ((param_1 & 0x10) != 0) { + uVar4 |= 0x10; + } + if ((param_1 & 0x20) != 0) { + uVar4 |= 0x20; + } + if ((param_1 & 0x40) != 0) { + uVar4 |= 0x40; + } + ctb::TParse aTStack_30(&pControl->ctb_Control); + if (!aTStack_30.parse(pContent, uVar4)) { + return false; + } + if ((param_1 & 0x200) == 0) { + if (pControl->transform_setOrigin_ctb_index(0) == 0) { + return 0; + } + pControl->transform_enable(true); + } + return true; +} diff --git a/src/JSystem/JStudio/JStudio/jstudio-data.cpp b/src/JSystem/JStudio/JStudio/jstudio-data.cpp new file mode 100644 index 000000000..fb7df8a3e --- /dev/null +++ b/src/JSystem/JStudio/JStudio/jstudio-data.cpp @@ -0,0 +1,3 @@ +#include "JSystem/JStudio/JStudio/jstudio-data.h" + +const char JStudio::data::ga8cSignature[8] = "jstudio"; diff --git a/src/JSystem/JStudio/JStudio/jstudio-math.cpp b/src/JSystem/JStudio/JStudio/jstudio-math.cpp new file mode 100644 index 000000000..f828252b8 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/jstudio-math.cpp @@ -0,0 +1,67 @@ +#include "JSystem/JStudio/JStudio/jstudio-math.h" +#include "JSystem/JGeometry.h" +#include "JSystem/TPosition3.h" +#include + +void JStudio::math::getRotation_xyz(MtxP param_1, f32 x, f32 y, f32 z) { + f32 cosx = cosf(DEG_TO_RAD(x)); + f32 sinx = sinf(DEG_TO_RAD(x)); + f32 cosy = cosf(DEG_TO_RAD(y)); + f32 siny = sinf(DEG_TO_RAD(y)); + f32 cosz = cosf(DEG_TO_RAD(z)); + f32 sinz = sinf(DEG_TO_RAD(z)); + f32 cosxcosz = cosx * cosz; + f32 cosxsinz = cosx * sinz; + f32 sinxcosz = sinx * cosz; + f32 sinxsinz = sinx * sinz; + + param_1[0][0] = cosy * cosz; + param_1[1][0] = cosy * sinz; + param_1[2][0] = -siny; + param_1[2][1] = sinx * cosy; + param_1[2][2] = cosx * cosy; + param_1[0][1] = ((sinxcosz * siny) - cosxsinz); + param_1[0][2] = (sinxsinz + (cosxcosz * siny)); + param_1[1][1] = (cosxcosz + (sinxsinz * siny)); + param_1[1][2] = (((cosxsinz) * siny) - sinxcosz); + param_1[0][3] = 0.0f; + param_1[1][3] = 0.0f; + param_1[2][3] = 0.0f; +} + +void JStudio::math::getTransformation_SRxyzT(MtxP param_1, Vec const& param_2, Vec const& param_3, + Vec const& param_4) { + Mtx afStack_40; + MTXScale(afStack_40, param_2.x, param_2.y, param_2.z); + Mtx amStack_70; + rotate_xyz(afStack_40, amStack_70, param_3); + MTXTransApply(amStack_70, param_1, param_4.x, param_4.y, param_4.z); +} + +void JStudio::math::getFromTransformation_SRxyzT(Vec* param_1, Vec* param_2, Vec* param_3, + CMtxP param_4) { + getFromTransformation_S(param_1, param_4); + getFromTransformation_T(param_3, param_4); + JGeometry::TRotation3 > aTStack_88; + JGeometry::TVec3 local_a0; + double dVar9 = 0.0; + double dVar8 = 0.0; + double dVar7 = 0.0; + if (0.0f != param_1->x) { + dVar9 = 1.0 / param_1->x; + } + if (0.0f != param_1->y) { + dVar8 = 1.0 / param_1->y; + } + if (0.0f != param_1->z) { + dVar7 = 1.0 / param_1->z; + } + aTStack_88.set(param_4[0][0] * dVar9, param_4[0][1] * dVar8, param_4[0][2] * dVar7, + param_4[1][0] * dVar9, param_4[1][1] * dVar8, param_4[1][2] * dVar7, + param_4[2][0] * dVar9, param_4[2][1] * dVar8, param_4[2][2] * dVar7); + aTStack_88.getEulerXYZ(&local_a0); + local_a0 *= 180.0 / m_PI_D; + param_2->x = local_a0.x; + param_2->y = local_a0.y; + param_2->z = local_a0.z; +} diff --git a/src/JSystem/JStudio/JStudio/jstudio-object.cpp b/src/JSystem/JStudio/JStudio/jstudio-object.cpp new file mode 100644 index 000000000..55244a35d --- /dev/null +++ b/src/JSystem/JStudio/JStudio/jstudio-object.cpp @@ -0,0 +1,1222 @@ +#include "JSystem/JStudio/JStudio/jstudio-object.h" + +namespace JStudio { +namespace { + +template +class TOutputVariableValue_BOOL_ : public JStudio::TVariableValue::TOutput { +public: + typedef void (T::*Func)(JStudio::data::TEOperationData, const void*, u32); + + TOutputVariableValue_BOOL_(Func f) : mFunc(f) {} + virtual void operator()(f32 f, JStudio::TAdaptor* adaptor) const { + BOOL value = 0; + if (f >= 0.5f) { + value = 1; + } + (static_cast(adaptor)->*mFunc)(data::UNK_0x2, &value, 4); + } + virtual ~TOutputVariableValue_BOOL_() {} + +private: + Func mFunc; +}; + +TOutputVariableValue_BOOL_ + soovv_actor_PARENT_ENABLE_(&JStudio::TAdaptor_actor::adaptor_do_PARENT_ENABLE); +TOutputVariableValue_BOOL_ + soovv_actor_RELATION_ENABLE_(&JStudio::TAdaptor_actor::adaptor_do_RELATION_ENABLE); + +TOutputVariableValue_BOOL_ + soovv_camera_PARENT_ENABLE_(&JStudio::TAdaptor_camera::adaptor_do_PARENT_ENABLE); +TOutputVariableValue_BOOL_ + soovv_camera_TARGET_PARENT_ENABLE_(&JStudio::TAdaptor_camera::adaptor_do_TARGET_PARENT_ENABLE); + +TOutputVariableValue_BOOL_ + soovv_light_ENABLE_(&JStudio::TAdaptor_light::adaptor_do_ENABLE); + +TOutputVariableValue_BOOL_ + soovv_particle_PARENT_ENABLE_(&JStudio::TAdaptor_particle::adaptor_do_PARENT_ENABLE); +TOutputVariableValue_BOOL_ + soovv_particle_REPEAT_(&JStudio::TAdaptor_particle::adaptor_do_REPEAT); +TOutputVariableValue_BOOL_ + soovv_particle_ON_EXIT_NOT_END_(&JStudio::TAdaptor_particle::adaptor_do_ON_EXIT_NOT_END); + +TOutputVariableValue_BOOL_ + soovv_sound_PARENT_ENABLE_(&JStudio::TAdaptor_sound::adaptor_do_PARENT_ENABLE); +TOutputVariableValue_BOOL_ + soovv_sound_REPEAT_(&JStudio::TAdaptor_sound::adaptor_do_REPEAT); +TOutputVariableValue_BOOL_ + soovv_sound_CONTINUOUS_(&JStudio::TAdaptor_sound::adaptor_do_CONTINUOUS); +TOutputVariableValue_BOOL_ + soovv_sound_LOCATED_(&JStudio::TAdaptor_sound::adaptor_do_LOCATED); +TOutputVariableValue_BOOL_ + soovv_sound_ON_EXIT_NOT_END_(&JStudio::TAdaptor_sound::adaptor_do_ON_EXIT_NOT_END); +}; // namespace +}; // namespace JStudio + +JStudio::TVariableValue::TOutput::~TOutput() {} + +void JStudio::TVariableValue::update(f64 param_0, JStudio::TAdaptor* param_1) { + if (field_0x8) { + field_0x8(this, param_0); + JUT_ASSERT(200, pOutput_!=NULL); + (*pOutput_)(mValue, param_1); + } +} + +void JStudio::TVariableValue::update_immediate_(JStudio::TVariableValue* param_0, f64 param_1) { + param_0->mValue = param_0->field_0xc.val; + param_0->field_0x8 = NULL; +} + +void JStudio::TVariableValue::update_time_(JStudio::TVariableValue* param_0, f64 param_1) { + f64 v = param_0->field_0xc.val * (param_0->field_0x4 * param_1); + param_0->mValue = v; +} + +void JStudio::TVariableValue::update_functionValue_(JStudio::TVariableValue* param_0, + f64 param_1) { + + TFunctionValue *fv = param_0->field_0xc.fv; + f64 v = fv->getValue(param_0->field_0x4 * param_1); + param_0->mValue = v; +} + +JStudio::TVariableValue::TOutput_none_::~TOutput_none_() {} + +void JStudio::TVariableValue::TOutput_none_::operator()(f32 param_0, + JStudio::TAdaptor* param_1) const { + /* empty function */ +} + +JStudio::TAdaptor::~TAdaptor() {} + +const char *JStudio::TAdaptor::adaptor_getID_string() const { + return pObject_ != NULL ? (const char*)pObject_->getID() : "(unnamed)"; +} + +// void JStudio::TAdaptor::adaptor_do_prepare() { +void JStudio::TAdaptor::adaptor_do_prepare() { + /* empty function */ +} + +void JStudio::TAdaptor::adaptor_do_begin() { + /* empty function */ +} + +void JStudio::TAdaptor::adaptor_do_end() { + /* empty function */ +} + +void JStudio::TAdaptor::adaptor_do_update(u32 param_0) { + /* empty function */ +} + +void JStudio::TAdaptor::adaptor_do_data(void const* param_0, u32 param_1, void const* param_2, + u32 param_3) { + /* empty function */ +} + +void JStudio::TAdaptor::adaptor_setVariableValue(JStudio::TControl* pControl, u32 param_2, + JStudio::data::TEOperationData param_3, + void const* param_4, u32 param_5) { + setVarFunc func; + JUT_ASSERT(304, pControl!=NULL); + switch (param_3) { + case JStudio::data::UNK_0x1: + func = &adaptor_setVariableValue_VOID_; + break; + case JStudio::data::UNK_0x2: + func = &adaptor_setVariableValue_IMMEDIATE_; + break; + case JStudio::data::UNK_0x3: + func = &adaptor_setVariableValue_TIME_; + break; + case JStudio::data::UNK_0x10: + func = &adaptor_setVariableValue_FVR_NAME_; + break; + case JStudio::data::UNK_0x12: + func = &adaptor_setVariableValue_FVR_INDEX_; + break; + default: + return; + } + + (*func)(this, pControl, param_2, param_4, param_5); +} + + +void JStudio::TAdaptor::adaptor_setVariableValue_n(JStudio::TControl* pControl, + u32 const* param_2, u32 param_3, + JStudio::data::TEOperationData param_4, + void const* param_5, u32 param_6) { + JUT_ASSERT(343, pControl!=NULL); + setVarFunc pcVar6; + u32 iVar7; + switch(param_4) { + case JStudio::data::UNK_0x1: + iVar7 = 0; + pcVar6 = adaptor_setVariableValue_VOID_; + break; + case JStudio::data::UNK_0x2: + iVar7 = 4; + pcVar6 = adaptor_setVariableValue_IMMEDIATE_; + break; + case JStudio::data::UNK_0x3: + iVar7 = 4; + pcVar6 = adaptor_setVariableValue_TIME_; + break; + case JStudio::data::UNK_0x12: + iVar7 = 4; + pcVar6 = adaptor_setVariableValue_FVR_INDEX_; + break; + default: + return; + } + + JGadget::TEnumerator enumerator(param_2, param_2 + param_3); + while (enumerator) { + (*pcVar6)(this, pControl, **enumerator, param_5, iVar7); + param_5 = (const void*)((intptr_t)param_5 + iVar7); + } +} + +void JStudio::TAdaptor::adaptor_setVariableValue_immediate( + JStudio::TAdaptor::TSetVariableValue_immediate const* p) { + JUT_ASSERT(388, p!=NULL); + u32 uVar1; + while ((uVar1 = p->field_0x0) != 0xffffffff) { + adaptor_setVariableValue_immediate(uVar1, p->field_0x4); + p++; + } +} + +void JStudio::TAdaptor::adaptor_setVariableValue_Vec(u32 const* puIndex, Vec const& param_2) { + JUT_ASSERT(400, puIndex!=NULL); + adaptor_referVariableValue(puIndex[0])->setValue_immediate(param_2.x); + adaptor_referVariableValue(puIndex[1])->setValue_immediate(param_2.y); + adaptor_referVariableValue(puIndex[2])->setValue_immediate(param_2.z); +} + +void JStudio::TAdaptor::adaptor_getVariableValue_Vec(Vec* param_1, u32 const* param_2) const { + param_1->x = adaptor_getVariableValue(param_2[0])->getValue(); + param_1->y = adaptor_getVariableValue(param_2[1])->getValue(); + param_1->z = adaptor_getVariableValue(param_2[2])->getValue(); +} + +void JStudio::TAdaptor::adaptor_setVariableValue_GXColor(u32 const* puIndex, + GXColor const& param_2) { + JUT_ASSERT(431, puIndex!=NULL); + adaptor_referVariableValue(puIndex[0])->setValue_immediate(param_2.r); + adaptor_referVariableValue(puIndex[1])->setValue_immediate(param_2.g); + adaptor_referVariableValue(puIndex[2])->setValue_immediate(param_2.b); + adaptor_referVariableValue(puIndex[3])->setValue_immediate(param_2.a); +} + +void JStudio::TAdaptor::adaptor_getVariableValue_GXColor(GXColor* param_1, + u32 const* param_2) const { + param_1->r = adaptor_getVariableValue(param_2[0])->getValue_uint8(); + param_1->g = adaptor_getVariableValue(param_2[1])->getValue_uint8(); + param_1->b = adaptor_getVariableValue(param_2[2])->getValue_uint8(); + param_1->a = adaptor_getVariableValue(param_2[3])->getValue_uint8(); +} + +void JStudio::TAdaptor::adaptor_updateVariableValue(JStudio::TControl* pControl, u32 param_2) { + JUT_ASSERT(479, pControl!=NULL); + f64 dVar3 = pControl->getSecondPerFrame(); + JGadget::TEnumerator enumerator(pValue_, pValue_ + uvv_); + while (enumerator) { + JStudio::TVariableValue* value = *enumerator; + value->forward(param_2); + value->update(dVar3, this); + } +} + +void JStudio::TAdaptor::adaptor_setVariableValue_VOID_(JStudio::TAdaptor* param_1, + JStudio::TControl* param_2, u32 param_3, + void const* param_4, u32 uSize) { + JUT_ASSERT(499, uSize==0); + param_1->pValue_[param_3].setValue_none(); +} + +void JStudio::TAdaptor::adaptor_setVariableValue_IMMEDIATE_(JStudio::TAdaptor* param_1, + JStudio::TControl* param_2, u32 param_3, + void const* param_4, u32 param_5) { + TVariableValue* value = ¶m_1->pValue_[param_3]; + value->setValue_immediate(*(f32*)param_4); +} + +void JStudio::TAdaptor::adaptor_setVariableValue_TIME_(JStudio::TAdaptor* param_1, + JStudio::TControl* param_2, u32 param_3, + void const* param_4, u32 param_5) { + TVariableValue* value = ¶m_1->pValue_[param_3]; + value->setValue_time(*(f32*)param_4); +} + +void JStudio::TAdaptor::adaptor_setVariableValue_FVR_NAME_(JStudio::TAdaptor* param_1, + JStudio::TControl* param_2, u32 param_3, + void const* param_4, u32 param_5) { + TVariableValue* value = ¶m_1->pValue_[param_3]; + value->setValue_functionValue(param_2->getFunctionValue(param_4,param_5)); +} + +void JStudio::TAdaptor::adaptor_setVariableValue_FVR_INDEX_(JStudio::TAdaptor* param_1, + JStudio::TControl* param_2, u32 param_3, + void const* param_4, u32 param_5) { + TVariableValue* value = ¶m_1->pValue_[param_3]; + value->setValue_functionValue(param_2->getFunctionValue_index(*(u32*)param_4)); +} + +JStudio::TObject::~TObject() { + delete mpAdaptor; +} + +void JStudio::TObject::forward_value(u32 param_0) { + TAdaptor* adaptor = getAdaptor(); + if (adaptor != NULL) { + adaptor->adaptor_updateVariableValue(getControl(), param_0); + adaptor->adaptor_do_update(param_0); + } +} + +void JStudio::TObject::do_begin() { + TAdaptor* adaptor = getAdaptor(); + if (adaptor != NULL) { + adaptor->adaptor_do_begin(); + } +} + +void JStudio::TObject::do_end() { + TAdaptor* adaptor = getAdaptor(); + if (adaptor != NULL) { + adaptor->adaptor_do_end(); + } +} + +void JStudio::TObject::do_wait(u32 param_0) { + forward_value(param_0); +} + +void JStudio::TObject::do_data(void const* param_0, u32 param_1, void const* param_2, + u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + if (adaptor != NULL) { + adaptor->adaptor_do_data(param_0, param_1, param_2, param_3); + } +} + +JStudio::TObject::TObject(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor* param_1) + : stb::TObject(param_0), mpAdaptor(param_1) {} + +JStudio::TAdaptor_actor::~TAdaptor_actor() { +} + +JStudio::TObject_actor::TObject_actor(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_actor* param_1) : TObject(param_0, param_1) { + +} + +u32 const JStudio::TAdaptor_actor::sauVariableValue_3_TRANSLATION_XYZ[3] = { + 3, 4, 5, +}; + + u32 const JStudio::TAdaptor_actor::sauVariableValue_3_ROTATION_XYZ[3] = { + 6, 7, 8, +}; + +u32 const JStudio::TAdaptor_actor::sauVariableValue_3_SCALING_XYZ[3] = { + 9, 10, 11, +}; + + JStudio::TVariableValue::TOutput_none_ JStudio::TVariableValue::soOutput_none_; + +void JStudio::TObject_actor::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + typedef void (TAdaptor_actor::*actorParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + actorParagraphFunc pmfn_ = NULL; + TVariableValue::TOutput *pOutput; + switch (uVar1) { + case 57: + pmfn_ = &TAdaptor_actor::adaptor_do_SHAPE; + goto fun; + case 58: + pmfn_ = &TAdaptor_actor::adaptor_do_ANIMATION; + goto fun; + case 67: + pmfn_ = &TAdaptor_actor::adaptor_do_ANIMATION_MODE; + goto fun; + case 76: + pmfn_ = &TAdaptor_actor::adaptor_do_TEXTURE_ANIMATION; + goto fun; + case 78: + pmfn_ = &TAdaptor_actor::adaptor_do_TEXTURE_ANIMATION_MODE; + goto fun; + case 48: + pmfn_ = &TAdaptor_actor::adaptor_do_PARENT; + goto fun; + case 49: + pmfn_ = &TAdaptor_actor::adaptor_do_PARENT_NODE; + goto fun; + case 50: + pmfn_ = &TAdaptor_actor::adaptor_do_PARENT_ENABLE; + u = 12; + pOutput = &JStudio::soovv_actor_PARENT_ENABLE_; + goto value_or_fun; + case 81: + pmfn_ = &TAdaptor_actor::adaptor_do_PARENT_FUNCTION; + goto fun; + case 51: + pmfn_ = &TAdaptor_actor::adaptor_do_RELATION; + goto fun; + case 52: + pmfn_ = &TAdaptor_actor::adaptor_do_RELATION_NODE; + goto fun; + case 53: + pmfn_ = &TAdaptor_actor::adaptor_do_RELATION_ENABLE; + u = 13; + pOutput = &JStudio::soovv_actor_RELATION_ENABLE_; + goto value_or_fun; + case 59: + u = 0; + goto value; + case 75: + u = 1; + goto value; + case 9: + u = 3; + goto value; + case 10: + u = 4; + goto value; + case 11: + u = 5; + goto value; + case 13: + u = 6; + goto value; + case 14: + u = 7; + goto value; + case 15: + u = 8; + goto value; + case 17: + u = 9; + goto value; + case 18: + u = 10; + goto value; + case 19: + u = 11; + goto value; + case 12: + pN = TAdaptor_actor::sauVariableValue_3_TRANSLATION_XYZ; + u = 3; + goto value_n; + case 16: + pN = TAdaptor_actor::sauVariableValue_3_ROTATION_XYZ; + u = 3; + goto value_n; + case 20: + pN = TAdaptor_actor::sauVariableValue_3_SCALING_XYZ; + u = 3; + goto value_n; + default: + return; + } + +value_or_fun: + switch (operation) { + case data::UNK_0x10: + case data::UNK_0x11: + case data::UNK_0x12: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + adaptor->adaptor_referVariableValue(u)->setOutput(pOutput); + break; + default: + (((TAdaptor_actor*)adaptor)->*pmfn_)(operation, param_2, param_3); + break; + } + return; + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; + +fun: + (((TAdaptor_actor*)adaptor)->*pmfn_)(operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_ambientLight::~TAdaptor_ambientLight() {} + +JStudio::TObject_ambientLight::TObject_ambientLight( + JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_ambientLight* param_1) : TObject(param_0, param_1) { +} + +u32 const JStudio::TAdaptor_ambientLight::sauVariableValue_3_COLOR_RGB[3] = { + 0, 1, 2, +}; + +u32 const JStudio::TAdaptor_ambientLight::sauVariableValue_4_COLOR_RGBA[4] = { + 0, 1, 2, 3, +}; + +void JStudio::TObject_ambientLight::do_paragraph(u32 param_1, void const* param_2, + u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + switch (uVar1) { + case 29: + u = 0; + goto value; + case 30: + u = 1; + goto value; + case 31: + u = 2; + goto value; + case 32: + u = 3; + goto value; + case 33: + pN = TAdaptor_ambientLight::sauVariableValue_3_COLOR_RGB; + u = 3; + goto value_n; + case 34: + pN = TAdaptor_ambientLight::sauVariableValue_4_COLOR_RGBA; + u = 4; + goto value_n; + default: + return; + } + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_camera::~TAdaptor_camera() {} + +JStudio::TObject_camera::TObject_camera(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_camera* param_1) + : TObject(param_0, param_1) {} + +u32 const JStudio::TAdaptor_camera::sauVariableValue_3_POSITION_XYZ[3] = { + 0, 1, 2, +}; + +u32 const JStudio::TAdaptor_camera::sauVariableValue_3_TARGET_POSITION_XYZ[3] = { + 3, 4, 5, +}; + +u32 const JStudio::TAdaptor_camera::sauVariableValue_2_DISTANCE_NEAR_FAR[2] = { + 8, 9, +}; + +void JStudio::TObject_camera::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + typedef void (TAdaptor_camera::*cameraParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + cameraParagraphFunc pmfn_ = NULL; + TVariableValue::TOutput *pOutput; + switch (uVar1) { + case 48: + pmfn_ = &TAdaptor_camera::adaptor_do_PARENT; + goto fun; + case 49: + pmfn_ = &TAdaptor_camera::adaptor_do_PARENT_NODE; + goto fun; + case 50: + pmfn_ = &TAdaptor_camera::adaptor_do_PARENT_ENABLE; + u = 10; + pOutput = &JStudio::soovv_camera_PARENT_ENABLE_; + goto value_or_fun; + case 81: + pmfn_ = &TAdaptor_camera::adaptor_do_PARENT_FUNCTION; + goto fun; + case 82: + pmfn_ = &TAdaptor_camera::adaptor_do_TARGET_PARENT; + goto fun; + case 83: + pmfn_ = &TAdaptor_camera::adaptor_do_TARGET_PARENT_NODE; + goto fun; + case 84: + pmfn_ = &TAdaptor_camera::adaptor_do_TARGET_PARENT_ENABLE; + u = 11; + pOutput = &JStudio::soovv_camera_TARGET_PARENT_ENABLE_; + goto value_or_fun; + case 21: + u = 0; + goto value; + case 22: + u = 1; + goto value; + case 23: + u = 2; + goto value; + case 25: + u = 3; + goto value; + case 26: + u = 4; + goto value; + case 27: + u = 5; + goto value; + case 39: + u = 6; + goto value; + case 38: + u = 7; + goto value; + case 40: + u = 8; + goto value; + case 41: + u = 9; + goto value; + case 24: + pN = TAdaptor_camera::sauVariableValue_3_POSITION_XYZ; + u = 3; + goto value_n; + case 28: + pN = TAdaptor_camera::sauVariableValue_3_TARGET_POSITION_XYZ; + u = 3; + goto value_n; + case 42: + pN = TAdaptor_camera::sauVariableValue_2_DISTANCE_NEAR_FAR; + u = 2; + goto value_n; + default: + return; + } + +value_or_fun: + switch (operation) { + case data::UNK_0x10: + case data::UNK_0x11: + case data::UNK_0x12: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + adaptor->adaptor_referVariableValue(u)->setOutput(pOutput); + break; + default: + (((TAdaptor_camera*)adaptor)->*pmfn_)(operation, param_2, param_3); + break; + } + return; + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; + +fun: + (((TAdaptor_camera*)adaptor)->*pmfn_)(operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_fog::~TAdaptor_fog() {} + +JStudio::TObject_fog::TObject_fog(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_fog* param_1) : TObject(param_0, param_1) {} + +u32 const JStudio::TAdaptor_fog::sauVariableValue_3_COLOR_RGB[3] = { + 0, 1, 2, +}; + +u32 const JStudio::TAdaptor_fog::sauVariableValue_4_COLOR_RGBA[4] = { + 0, 1, 2, 3, +}; + +u32 const JStudio::TAdaptor_fog::sauVariableValue_2_RANGE_BEGIN_END[2] = { + 4, 5, +}; + +void JStudio::TObject_fog::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + switch (uVar1) { + case 29: + u = 0; + goto value; + case 30: + u = 1; + goto value; + case 31: + u = 2; + goto value; + case 32: + u = 3; + goto value; + case 43: + u = 4; + goto value; + case 44: + u = 5; + goto value; + case 33: + pN = TAdaptor_fog::sauVariableValue_3_COLOR_RGB; + u = 3; + goto value_n; + case 34: + pN = TAdaptor_fog::sauVariableValue_4_COLOR_RGBA; + u = 4; + goto value_n; + case 45: + pN = TAdaptor_fog::sauVariableValue_2_RANGE_BEGIN_END; + u = 2; + goto value_n; + default: + return; + } + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_light::~TAdaptor_light() {} + +JStudio::TObject_light::TObject_light(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_light* param_1) : TObject(param_0, param_1) {} + +u32 const JStudio::TAdaptor_light::sauVariableValue_2_DIRECTION_THETA_PHI[2] = { + 10, 11, +}; + + u32 const JStudio::TAdaptor_light::sauVariableValue_3_COLOR_RGB[3] = { + 0, 1, 2, +}; + +u32 const JStudio::TAdaptor_light::sauVariableValue_4_COLOR_RGBA[4] = { + 0, 1, 2, 3, +}; + +u32 const JStudio::TAdaptor_light::sauVariableValue_3_POSITION_XYZ[3] = { + 4, 5, 6, +}; + +u32 const JStudio::TAdaptor_light::sauVariableValue_3_TARGET_POSITION_XYZ[3] = { + 7, 8, 9, +}; + +void JStudio::TObject_light::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + typedef void (TAdaptor_light::*lightParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + lightParagraphFunc pmfn_ = NULL; + TVariableValue::TOutput *pOutput; + switch (uVar1) { + case 54: + pmfn_ = &TAdaptor_light::adaptor_do_ENABLE; + u = 12; + pOutput = &JStudio::soovv_light_ENABLE_; + goto value_or_fun; + case 55: + pmfn_ = &TAdaptor_light::adaptor_do_FACULTY; + goto fun; + case 29: + u = 0; + goto value; + case 30: + u = 1; + goto value; + case 31: + u = 2; + goto value; + case 32: + u = 3; + goto value; + case 21: + u = 4; + goto value; + case 22: + u = 5; + goto value; + case 23: + u = 6; + goto value; + case 25: + u = 7; + goto value; + case 26: + u = 8; + goto value; + case 27: + u = 9; + goto value; + case 35: + u = 10; + goto value; + case 36: + u = 11; + goto value; + case 33: + pN = TAdaptor_light::sauVariableValue_3_COLOR_RGB; + u = 3; + goto value_n; + case 34: + pN = TAdaptor_light::sauVariableValue_4_COLOR_RGBA; + u = 4; + goto value_n; + case 24: + pN = TAdaptor_light::sauVariableValue_3_POSITION_XYZ; + u = 3; + goto value_n; + case 28: + pN = TAdaptor_light::sauVariableValue_3_TARGET_POSITION_XYZ; + u = 3; + goto value_n; + case 37: + pN = TAdaptor_light::sauVariableValue_2_DIRECTION_THETA_PHI; + u = 2; + goto value_n; + default: + return; + } + +value_or_fun: + switch (operation) { + case data::UNK_0x10: + case data::UNK_0x11: + case data::UNK_0x12: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + adaptor->adaptor_referVariableValue(u)->setOutput(pOutput); + break; + default: + (((TAdaptor_light*)adaptor)->*pmfn_)(operation, param_2, param_3); + break; + } + return; + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; + +fun: + (((TAdaptor_light*)adaptor)->*pmfn_)(operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_message::~TAdaptor_message() {} + +JStudio::TObject_message::TObject_message(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_message* param_1) + : TObject(param_0, param_1) {} + +void JStudio::TObject_message::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + if (adaptor != NULL) { + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1f); + typedef void (TAdaptor_message::*messageParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + messageParagraphFunc pmfn_ = NULL; + switch (uVar1) { + case 0x42: + pmfn_ = &TAdaptor_message::adaptor_do_MESSAGE; + break; + default: + return; + } + JUT_ASSERT(1161, pmfn_!=NULL); + (((TAdaptor_message*)adaptor)->*pmfn_)(operation, param_2, param_3); + } + +} + +JStudio::TAdaptor_particle::~TAdaptor_particle() {} + +JStudio::TObject_particle::TObject_particle( + JStudio::stb::data::TParse_TBlock_object const& param_0, JStudio::TAdaptor_particle* param_1) : TObject(param_0, param_1) {} + + u32 const JStudio::TAdaptor_particle::sauVariableValue_3_TRANSLATION_XYZ[3] = { + 0, 1, 2, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_3_ROTATION_XYZ[3] = { + 3, 4, 5, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_3_SCALING_XYZ[3] = { + 6, 7, 8, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_3_COLOR_RGB[3] = { + 9, 10, 11, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_4_COLOR_RGBA[4] = { + 9, 10, 11, 12, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_3_COLOR1_RGB[3] = { + 9, 10, 11, +}; + +u32 const JStudio::TAdaptor_particle::sauVariableValue_4_COLOR1_RGBA[4] = { + 9, 10, 11, 12, +}; + +void JStudio::TObject_particle::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + typedef void (TAdaptor_particle::*particleParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + particleParagraphFunc pmfn_ = NULL; + TVariableValue::TOutput *pOutput; + switch (uVar1) { + case 68: + pmfn_ = &TAdaptor_particle::adaptor_do_PARTICLE; + goto fun; + case 79: + pmfn_ = &TAdaptor_particle::adaptor_do_BEGIN; + goto fun; + case 46: + pmfn_ = &TAdaptor_particle::adaptor_do_BEGIN_FADE_IN; + goto fun; + case 80: + pmfn_ = &TAdaptor_particle::adaptor_do_END; + goto fun; + case 47: + pmfn_ = &TAdaptor_particle::adaptor_do_END_FADE_OUT; + goto fun; + case 48: + pmfn_ = &TAdaptor_particle::adaptor_do_PARENT; + goto fun; + case 49: + pmfn_ = &TAdaptor_particle::adaptor_do_PARENT_NODE; + goto fun; + case 50: + pmfn_ = &TAdaptor_particle::adaptor_do_PARENT_ENABLE; + u = 17; + pOutput = &JStudio::soovv_particle_PARENT_ENABLE_; + goto value_or_fun; + case 81: + pmfn_ = &TAdaptor_particle::adaptor_do_PARENT_FUNCTION; + goto fun; + case 86: + pmfn_ = &TAdaptor_particle::adaptor_do_REPEAT; + u = 18; + pOutput = &JStudio::soovv_particle_REPEAT_; + goto value_or_fun; + case 85: + pmfn_ = &TAdaptor_particle::adaptor_do_ON_EXIT_NOT_END; + u = 19; + pOutput = &JStudio::soovv_particle_ON_EXIT_NOT_END_; + goto value_or_fun; + case 9: + u = 0; + goto value; + case 10: + u = 1; + goto value; + case 11: + u = 2; + goto value; + case 13: + u = 3; + goto value; + case 14: + u = 4; + goto value; + case 15: + u = 5; + goto value; + case 17: + u = 6; + goto value; + case 18: + u = 7; + goto value; + case 19: + u = 8; + goto value; + case 29: + u = 9; + goto value; + case 30: + u = 10; + goto value; + case 31: + u = 11; + goto value; + case 32: + u = 12; + goto value; + case 69: + u = 13; + goto value; + case 70: + u = 14; + goto value; + case 71: + u = 15; + goto value; + case 72: + u = 16; + goto value; + case 12: + pN = TAdaptor_particle::sauVariableValue_3_TRANSLATION_XYZ; + u = 3; + goto value_n; + case 16: + pN = TAdaptor_particle::sauVariableValue_3_ROTATION_XYZ; + u = 3; + goto value_n; + case 20: + pN = TAdaptor_particle::sauVariableValue_3_SCALING_XYZ; + u = 3; + goto value_n; + case 33: + pN = TAdaptor_particle::sauVariableValue_3_COLOR_RGB; + u = 3; + goto value_n; + case 34: + pN = TAdaptor_particle::sauVariableValue_4_COLOR_RGBA; + u = 4; + goto value_n; + case 73: + pN = TAdaptor_particle::sauVariableValue_3_COLOR1_RGB; + u = 3; + goto value_n; + case 74: + pN = TAdaptor_particle::sauVariableValue_4_COLOR1_RGBA; + u = 4; + goto value_n; + default: + return; + } + +value_or_fun: + switch (operation) { + case data::UNK_0x10: + case data::UNK_0x11: + case data::UNK_0x12: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + adaptor->adaptor_referVariableValue(u)->setOutput(pOutput); + break; + default: + (((TAdaptor_particle*)adaptor)->*pmfn_)(operation, param_2, param_3); + break; + } + return; + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; + +fun: + (((TAdaptor_particle*)adaptor)->*pmfn_)(operation, param_2, param_3); + return; +} + +JStudio::TAdaptor_sound::~TAdaptor_sound() {} + +JStudio::TObject_sound::TObject_sound(JStudio::stb::data::TParse_TBlock_object const& param_0, + JStudio::TAdaptor_sound* param_1) : TObject(param_0, param_1) {} + +u32 const JStudio::TAdaptor_sound::sauVariableValue_3_POSITION_XYZ[3] = { + 0, 1, 2, +}; + +void JStudio::TObject_sound::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + TAdaptor* adaptor = getAdaptor(); + TControl* control; + if (adaptor == NULL) { + return; + } + typedef void (TAdaptor_sound::*soundParagraphFunc)(JStudio::data::TEOperationData, const void*, u32); + + control = getControl(); + u32 uVar1 = (param_1 >> 5); + data::TEOperationData operation = (data::TEOperationData)(param_1 &= 0x1F); + u32 u; + const u32* pN; + soundParagraphFunc pmfn_ = NULL; + TVariableValue::TOutput *pOutput; + switch (uVar1) { + case 60: + pmfn_ = &TAdaptor_sound::adaptor_do_SOUND; + goto fun; + case 79: + pmfn_ = &TAdaptor_sound::adaptor_do_BEGIN; + goto fun; + case 46: + pmfn_ = &TAdaptor_sound::adaptor_do_BEGIN_FADE_IN; + goto fun; + case 80: + pmfn_ = &TAdaptor_sound::adaptor_do_END; + goto fun; + case 47: + pmfn_ = &TAdaptor_sound::adaptor_do_END_FADE_OUT; + goto fun; + case 48: + pmfn_ = &TAdaptor_sound::adaptor_do_PARENT; + goto fun; + case 49: + pmfn_ = &TAdaptor_sound::adaptor_do_PARENT_NODE; + goto fun; + case 50: + pmfn_ = &TAdaptor_sound::adaptor_do_PARENT_ENABLE; + u = 3; + pOutput = &JStudio::soovv_sound_PARENT_ENABLE_; + goto value_or_fun; + case 86: + pmfn_ = &TAdaptor_sound::adaptor_do_REPEAT; + u = 4; + pOutput = &JStudio::soovv_sound_REPEAT_; + goto value_or_fun; + case 87: + pmfn_ = &TAdaptor_sound::adaptor_do_CONTINUOUS; + u = 5; + pOutput = &JStudio::soovv_sound_CONTINUOUS_; + goto value_or_fun; + case 56: + pmfn_ = &TAdaptor_sound::adaptor_do_LOCATED; + u = 6; + pOutput = &JStudio::soovv_sound_LOCATED_; + goto value_or_fun; + case 85: + pmfn_ = &TAdaptor_sound::adaptor_do_ON_EXIT_NOT_END; + u = 12; + pOutput = &JStudio::soovv_sound_ON_EXIT_NOT_END_; + goto value_or_fun; + case 21: + u = 0; + goto value; + case 22: + u = 1; + goto value; + case 23: + u = 2; + goto value; + case 61: + u = 7; + goto value; + case 62: + u = 8; + goto value; + case 63: + u = 9; + goto value; + case 64: + u = 10; + goto value; + case 65: + u = 11; + goto value; + case 24: + pN = TAdaptor_sound::sauVariableValue_3_POSITION_XYZ; + u = 3; + goto value_n; + default: + return; + } + +value_or_fun: + switch (operation) { + case data::UNK_0x10: + case data::UNK_0x11: + case data::UNK_0x12: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + adaptor->adaptor_referVariableValue(u)->setOutput(pOutput); + break; + default: + (((TAdaptor_sound*)adaptor)->*pmfn_)(operation, param_2, param_3); + break; + } + return; + +value: + adaptor->adaptor_setVariableValue(control, u, operation, param_2, param_3); + return; + +value_n: + adaptor->adaptor_setVariableValue_n(control, pN, u, operation, param_2, param_3); + return; + +fun: + (((TAdaptor_sound*)adaptor)->*pmfn_)(operation, param_2, param_3); + return; +} diff --git a/src/JSystem/JStudio/JStudio/object-id.cpp b/src/JSystem/JStudio/JStudio/object-id.cpp new file mode 100644 index 000000000..ba1a522b4 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/object-id.cpp @@ -0,0 +1,53 @@ +// +// object-id +// + +#include "JSystem/JStudio/JStudio/object-id.h" +#include "JSystem/JUtility/JUTAssert.h" + +bool JStudio::object::TIDData::isEqual(JStudio::object::TIDData const& a, + JStudio::object::TIDData const& b) { + u32 aSize = a.getIDSize(); + u32 bSize = b.getIDSize(); + if (aSize != bSize) { + return false; + } + + const u8* aStr32 = a.getID(); + const u8* bStr32 = b.getID(); + if (aStr32 == bStr32) { + // they point to the same id + return true; + } + + u32 u = aSize; + for (; u >= 4; u -= 4, aStr32 += 4, bStr32 += 4) { + if (*(u32*)aStr32 != *(u32*)bStr32) { + return false; + } + } + + const u8* aStrBytes = aStr32; + const u8* bStrBytes = bStr32; + JUT_ASSERT(46, u<4); + switch (u) { + case 3: + if (*aStrBytes != *bStrBytes) { + return false; + } + aStrBytes++; + bStrBytes++; + case 2: + if (*aStrBytes != *bStrBytes) { + return false; + } + aStrBytes++; + bStrBytes++; + case 1: + if (*aStrBytes != *bStrBytes) { + return false; + } + } + + return true; +} diff --git a/src/JSystem/JStudio/JStudio/stb-data-parse.cpp b/src/JSystem/JStudio/JStudio/stb-data-parse.cpp new file mode 100644 index 000000000..6d8811b31 --- /dev/null +++ b/src/JSystem/JStudio/JStudio/stb-data-parse.cpp @@ -0,0 +1,82 @@ +#include "JSystem/JStudio/JStudio/stb-data-parse.h" +#include "JSystem/JUtility/JUTAssert.h" +#include +#include + +namespace JStudio { +namespace stb { +namespace data { + +void TParse_TSequence::getData(TData* pData) const { + JUT_ASSERT(50, pData!=NULL); + + pData->content = NULL; + pData->next = NULL; + u32 head = get_head(); + u8 type = head >> 24; + u32 param = head & 0xffffff; + pData->type = type & 0xff; + pData->param = param; + + if (type == 0) + return; + + const void* next = (const void*)((intptr_t)getRaw() + 4); + if (type <= 0x7f) { + pData->next = next; + } else { + pData->content = next; + pData->next = (const void*)((intptr_t)next + param); + } +} + +void TParse_TParagraph::getData(TData* pData) const { + JUT_ASSERT(80, pData!=NULL); + + const void* data = getRaw(); + u32 result; + data = parseVariableUInt_16_32_following(data, &result, &pData->type, NULL); + pData->param = result; + if (result == 0) { + pData->content = NULL; + pData->next = data; + } else { + pData->content = data; + pData->next = (const void*)((intptr_t)data + align_roundUp(result, 4)); + } +} + +void TParse_TParagraph_data::getData(TParse_TParagraph_data::TData* pData) const { + JUT_ASSERT(104, pData!=NULL); + pData->entrySize = 0; + pData->entryCount = 0; + pData->content = NULL; + pData->next = NULL; + u8* temp = (u8*)getRaw(); + u8* filedata = temp; + if (filedata == NULL) + return; + u8 r29 = *filedata; + pData->status = r29 & ~0x8; + if (!r29) + return; + filedata++; + u32 r28 = 1; + if (r29 & 8) { + r28 = *filedata; + filedata++; + } + pData->entryCount = r28; + pData->content = filedata; + + u8 r27 = r29 & 7; + if (r27 == 0) + return; + u32 dataSize = (gauDataSize_TEParagraph_data)[r27]; + pData->entrySize = dataSize; + pData->next = filedata + (dataSize * r28); +} + +} // namespace data +} // namespace stb +} // namespace JStudio diff --git a/src/JSystem/JStudio/JStudio/stb-data.cpp b/src/JSystem/JStudio/JStudio/stb-data.cpp new file mode 100644 index 000000000..ccb51946b --- /dev/null +++ b/src/JSystem/JStudio/JStudio/stb-data.cpp @@ -0,0 +1,4 @@ +#include "JSystem/JStudio/JStudio/stb-data.h" + +const s32 JStudio::stb::data::gauDataSize_TEParagraph_data[8] = {0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40}; +const u32 JStudio::stb::data::ga4cSignature = 'STB\0'; diff --git a/src/JSystem/JStudio/JStudio/stb.cpp b/src/JSystem/JStudio/JStudio/stb.cpp new file mode 100644 index 000000000..ce0227aca --- /dev/null +++ b/src/JSystem/JStudio/JStudio/stb.cpp @@ -0,0 +1,485 @@ +#include "JSystem/JStudio/JStudio/stb.h" +#include "JSystem/JStudio/JStudio/jstudio-object.h" +#include "JSystem/JGadget/define.h" +#include +#include + +namespace JStudio { +namespace stb { + +// unchecked, in debug dol +const char* TObject::toString_status(int status) { + const char* result; + + switch (status) { + default: + result = "(undefined)"; + break; + case 0: + result = "still"; + break; + case 1: + result = "end"; + break; + case 2: + result = "wait"; + break; + case 4: + result = "suspend"; + break; + case 8: + result = "inactive"; + break; + } + return result; +} + +TObject::TObject(u32 arg1, const void* id, u32 id_size) + : TObject_ID(id, id_size), pControl(NULL), signature(arg1), mFlag(0), bSequence_(0), _20(0), + pSequence(NULL), pSequence_next(NULL), u32Wait_(0), mStatus(STATUS_STILL) {} + +TObject::TObject(const data::TParse_TBlock_object& object) + : TObject_ID(object.get_ID(), object.get_IDSize()), pControl(NULL), + signature(object.get_type()), mFlag(object.get_flag()), bSequence_(0), _20(0), pSequence(0), + pSequence_next(object.getContent()), u32Wait_(0), mStatus(STATUS_STILL) {} + +TObject::~TObject() { + // JGADGET_ASSERTWARN(0, getControl() == NULL); +} + +void TObject::setFlag_operation(u8 op, int val) { + switch (op) { + default: + // JUTWarn w; + // w << "unknown flag-operation : " << op; + break; + case 1: + mFlag |= val; + break; + case 2: + mFlag &= val; + break; + case 3: + mFlag ^= val; + break; + } +} + +#if !PLATFORM_SHIELD || DEBUG +void TObject::reset(const void* arg1) { + bSequence_ = 0; + mStatus = STATUS_STILL; + pSequence_next = arg1; + u32Wait_ = 0; +} +#endif + +#if DEBUG +void TObject::reset() { + reset(NULL); +} +#endif + +bool TObject::forward(u32 arg1) { + bool temp = false; + + while (true) { + if (mFlag & 0x8000) { + switch (getStatus()) { + case STATUS_STILL: + case STATUS_END: + break; + case STATUS_WAIT: + case STATUS_SUSPEND: + setStatus_(STATUS_INACTIVE); + if (bSequence_) { + on_end(); + } + break; + case STATUS_INACTIVE: + break; + default: + // // ASSERT(false); + break; + } + return true; + } + + if (getStatus() == STATUS_INACTIVE) { + // // ASSERT(bSequence_); + on_begin(); + setStatus_(STATUS_WAIT); + } + // // ASSERT(getStatus() != STATUS_INACTIVE); + + TControl* control = getControl(); + if ((control != NULL && control->isSuspended()) || isSuspended()) { + if (bSequence_) { + // // ASSERT((getStatus() == STATUS_WAIT) || (getStatus() == STATUS_SUSPEND)); + setStatus_(STATUS_SUSPEND); + on_wait(arg1); + } + return true; + } + + while (true) { + void* nextseq = (void*)getSequence_next(); + setSequence_(nextseq); + + if (nextseq == NULL) { + if (bSequence_) { + // // ASSERT(getStatus() != STATUS_STILL); + if (!temp) { + on_wait(0); + } + bSequence_ = false; + setStatus_(STATUS_END); + on_end(); + } + return false; + } + + if (!bSequence_) { + // // ASSERT(getStatus() == STATUS_STILL); + bSequence_ = true; + on_begin(); + } + setStatus_(STATUS_WAIT); + if (u32Wait_ == 0) { + process_sequence_(); + if (u32Wait_ == 0) { + break; + } + } + // // ASSERT(u32Wait_ > 0); + + temp = true; + if (arg1 >= u32Wait_) { + u32 wait = u32Wait_; + arg1 -= u32Wait_; + u32Wait_ = 0; + on_wait(wait); + } else { + u32Wait_ -= arg1; + on_wait(arg1); + return true; + } + } + } +} + +void TObject::do_begin() { + /* empty function */ +} + +void TObject::do_end() { + /* empty function */ +} + +void TObject::do_paragraph(u32 param_0, void const* param_1, u32 param_2) { + /* empty function */ +} + +void TObject::do_wait(u32 param_0) { + /* empty function */ +} + +void TObject::do_data(void const* param_0, u32 param_1, void const* param_2, u32 param_3) { + /* empty function */ +} + +void TObject::process_sequence_() { + // // ASSERT(getWait() == 0); + data::TParse_TSequence seq(getSequence()); + + data::TParse_TSequence::TData dat; + + seq.getData(&dat); + u8 type = dat.type; + u32 u32Value = dat.param; + const void* pContent = dat.content; + const void* pNext = dat.next; + setSequence_next(dat.next); + + switch (type) { + case 0: + JGADGET_ASSERTWARN(0, u32Value == 0); + JGADGET_ASSERTWARN(0, pContent == NULL); + break; + case 1: + JGADGET_ASSERTWARN(0, pContent == NULL); + setFlag_operation_(u32Value); + break; + case 2: + JGADGET_ASSERTWARN(0, pContent == NULL); + setWait(u32Value); + break; + case 3: { + JGADGET_ASSERTWARN(0, pContent == NULL); + s32 off = toInt32FromUInt24_(u32Value); + void* nextseq = (void*)getSequence_offset(off); + setSequence_next(nextseq); + break; + } + case 4: { + JGADGET_ASSERTWARN(0, pContent == NULL); + u32 val = toInt32FromUInt24_(u32Value); + suspend(val); + break; + } + case 0x80: { + // ASSERT(pContent != NULL); + void* p = (void*)pContent; + data::TParse_TParagraph para(NULL); + while (p < pNext) { + para.setRaw(p); + + data::TParse_TParagraph::TData para_dat; + para.getData(¶_dat); + if (para_dat.type <= 0xff) { + process_paragraph_reserved_(para_dat.type, para_dat.content, para_dat.param); + } else { + on_paragraph(para_dat.type, para_dat.content, para_dat.param); + } + p = (void*)para_dat.next; + // ASSERT(p != NULL); + } + JGADGET_ASSERTWARN(0, p == pNext); + break; + } + default: + // JUTWarn w; + // w << "unknown sequence : " << dat.type; + break; + } +} + +void TObject::process_paragraph_reserved_(u32 arg1, const void* pContent, u32 uSize) { + switch (arg1) { + case 0x1: + // ASSERT(pContent != NULL); + // ASSERT(uSize == 4); + setFlag_operation_(*(u32*)pContent); + break; + case 0x2: + // ASSERT(pContent != NULL); + // ASSERT(uSize == 4); + setWait(*(u32*)pContent); + break; + case 0x3: { + // ASSERT(pContent != NULL); + // ASSERT(uSize == 4); + const void* seq = getSequence_offset(*(s32*)pContent); + setSequence_next(seq); + break; + } + case 0x80: + on_data(NULL, 0, pContent, uSize); + break; + case 0x81: { + data::TParse_TParagraph_dataID dataID(pContent); + const void* temp = dataID.getContent(); + on_data(dataID.get_ID(), dataID.get_IDSize(), temp, + uSize - ((uintptr_t)temp - (uintptr_t)dataID.getRaw())); + break; + } + case 0x82: + // ASSERT(pContent != NULL); + break; + } +} + +TObject_control::TObject_control(const void* arg1, u32 arg2) : TObject(-1, arg1, arg2) {} + +TControl::TControl() : _4(0), _8(0), pFactory(NULL), mObject_control(NULL, 0), _54(0) { + resetStatus_(); + mObject_control.setControl_(this); +} + +// TObject_control::TObject_control() definition gets inlined here + +TControl::~TControl() { + mObject_control.setControl_(NULL); + JGADGET_ASSERTWARN(0, ocObject_.empty()); +} + +void TControl::appendObject(TObject* p) { + p->setControl_(this); + ocObject_.Push_back(p); +} + +void TControl::removeObject(TObject* p) { + // ASSERT(p != NULL); + // ASSERT(p->getControl() == this); + p->setControl_(NULL); + ocObject_.Erase(p); +} + +void TControl::destroyObject(TObject* p) { + removeObject(p); + // ASSERT(pFactory != NULL); + pFactory->destroy(p); +} + +void TControl::destroyObject_all() { + while (!ocObject_.empty()) { + destroyObject(&ocObject_.back()); + } +} + +// NONMATCHING - TPRObject_ID_equal copy issue +TObject* TControl::getObject(void const* param_0, u32 param_1) { + JGadget::TLinkList::iterator begin = ocObject_.begin(); + JGadget::TLinkList::iterator end = ocObject_.end(); + JGadget::TLinkList::iterator local_50 = std::find_if(begin, end, object::TPRObject_ID_equal(param_0, param_1)); + if ((local_50 != end) != false) { + return &*local_50; + } + return NULL; +} + +void TControl::reset() { + resetStatus_(); + mObject_control.reset(); + JGadget::TContainerEnumerator > aTStack_18(ocObject_); + while (aTStack_18) { + (*aTStack_18).reset(); + } +} + +bool TControl::forward(u32 param_0) { + _54 = mObject_control.getSuspend(); + bool rv = mObject_control.forward(param_0); + int uVar7 = 0xf; + int uVar6 = 0; + JGadget::TContainerEnumerator > aTStack_38(ocObject_); + while (aTStack_38) { + JStudio::stb::TObject& this_00 = *aTStack_38; + rv = this_00.forward(param_0) || rv; + int uVar3 = this_00.getStatus(); + uVar7 &= uVar3; + uVar6 |= uVar3; + } + setStatus_(uVar7 | (uVar6 << 0x10)); + return rv; +} + +TFactory::~TFactory() {} + +JStudio::TObject* TFactory::create(data::TParse_TBlock_object const& param_0) { + return NULL; +} + +void TFactory::destroy(TObject* p) { + delete p; +} + +TParse::TParse(TControl* pControl) : pControl(pControl) {} + +TParse::~TParse() {} + +bool TParse::parseHeader_next(const void** ppData_inout, u32* puBlock_out, u32 flags) { + // ASSERT(ppData_inout != NULL); + // ASSERT(puBlock_out != NULL); + + const void* pData = *ppData_inout; + // ASSERT(pData != NULL); + + const data::TParse_THeader header(pData); + *ppData_inout = header.getContent(); + *puBlock_out = header.get_blockNumber(); + + if (memcmp(header.get_signature(), &data::ga4cSignature, 4) != 0) { + // JUTWarn w; + // w << "unknown signature"; + return false; + } + + if (header.get_byteOrder() != 0xFEFF) { + // JUTWarn w; + // w << "illegal byte-order"; + return false; + } + u16 version = header.get_version(); + if (version < 1) { + // JUTWarn w; + // w << "obselete version : " << (s32)0; + return false; + } else if (version > 3) { + // JUTWarn w; + // w << "unknown version : " << version; + return false; + } + return parseHeader(header, flags); +} + +bool TParse::parseBlock_next(void const** ppData_inout, u32* puData_out, u32 flags) { + // ASSERT(ppData_inout != NULL); + // ASSERT(puData_out != NULL); + + const void* pData = *ppData_inout; + // ASSERT(pData != NULL); + + data::TParse_TBlock blk(pData); + *ppData_inout = blk.getNext(); + *puData_out = blk.get_size(); + return parseBlock_block(blk, flags); +} + +bool TParse::parseHeader(data::TParse_THeader const& param_0, u32 flags) { + return true; +} + +bool TParse::parseBlock_block(const data::TParse_TBlock& ppBlock, u32 flags) { + return parseBlock_object(ppBlock.get(), flags); +} + +bool TParse::parseBlock_object(const data::TParse_TBlock_object& ppObject, u32 flags) { + TControl* pControl = getControl(); + // ASSERT(pControl != NULL); + + if (ppObject.get_type() == data::BLOCK_NONE) { + TObject_control& ref = pControl->referObject_control(); + ref.reset(ppObject.getContent()); + return true; + } + + if (flags & 0x10) { + TObject* p = pControl->getObject(ppObject.get_ID(), ppObject.get_IDSize()); + if (p != NULL) { + p->reset(ppObject.getContent()); + return true; + } + } + + if (flags & 0x20) + return true; + + TFactory* pFactory = pControl->getFactory(); + if (pFactory == NULL) { + // JUTWarn w; + // w << "factory not specified"; + return false; + } + + JStudio::TObject* p = pFactory->create(ppObject); + if (p == NULL) { + if (flags & 0x40) + return true; + + char a5c[8]; + char t[16]; + int type = ppObject.get_type(); + data::toString_block(a5c, type); + + // JUTWarn w; + // w << "can't create object : " << a5c; + // w << "(0x" << type << ")"; + return false; + } + pControl->appendObject(p); + return true; +} + +} // namespace stb +} // namespace JStudio diff --git a/src/JSystem/TPosition3.h b/src/JSystem/TPosition3.h new file mode 100644 index 000000000..df4cb8db4 --- /dev/null +++ b/src/JSystem/TPosition3.h @@ -0,0 +1,89 @@ +#ifndef TPOSITION3_H +#define TPOSITION3_H + +#include "JSystem/JMath/JMath.h" +#include "JSystem/JGeometry.h" + +#include + +namespace JGeometry { + +template +struct SMatrix34C { + T data[3][4]; +}; + +template <> +struct SMatrix34C { + f32 data[3][4]; + + typedef f32 ArrType[4]; + void set(const ArrType* src) { + JMath::gekko_ps_copy12(data, src); + } + + operator ArrType*() { return data; } + operator const ArrType*() const { return data; } +}; + +template +struct SMatrix33C { + T data[3][3]; + + inline T& ref(int i, int j) { + return data[i][j]; + } + + inline T at(int i, int j) const { + return data[i][j]; + } + + inline void set(T param_1, T param_2, T param_3, T param_4, T param_5, + T param_6, T param_7, T param_8, T param_9) { + ref(0,0) = param_1; + ref(0,1) = param_2; + ref(0,2) = param_3; + ref(1,0) = param_4; + ref(1,1) = param_5; + ref(1,2) = param_6; + ref(2,0) = param_7; + ref(2,1) = param_8; + ref(2,2) = param_9; + } +}; + +template +struct TMatrix34 : public T { + void identity() { MTXIdentity(this->data); } +}; + +template +struct TRotation3 : public T {}; + +template +struct TRotation3 > : public SMatrix33C { + inline void getEulerXYZ(TVec3* param_1) const { + if (this->at(2, 0) - TUtil::one() >= -TUtil::epsilon()) { + param_1->set(TUtil::atan2(-this->at(0, 1), this->at(1, 1)), -TUtil::halfPI(), 0.0); + } else { + if (this->at(2, 0) + TUtil::one() <= TUtil::epsilon()) { + param_1->set(TUtil::atan2(this->at(0, 1), this->at(1, 1)), TUtil::halfPI(), 0.0); + } else { + param_1->x = TUtil::atan2(this->at(2, 1), this->at(2, 2)); + param_1->z = TUtil::atan2(this->at(1, 0), this->at(0, 0)); + param_1->y = TUtil::asin(-this->at(2, 0)); + } + } + } +}; + +template +struct TPosition3 : public T { + TPosition3() {} +}; + +typedef TPosition3 > > TPosition3f32; + +} // namespace JGeometry + +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm index 3801f9cb9..0d51ad27e 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm +++ b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm @@ -76,23 +76,14 @@ ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T return first; } -// should be inline, but breaks JStudio/JStudio/ctb weak function order template -InputIt find_if(InputIt first, InputIt last, UnaryPredicate p) { +inline InputIt find_if(InputIt first, InputIt last, UnaryPredicate p) { while (first != last && !p(*first)) { ++first; } return first; } -// fakematch: val should be a const reference, but that breaks JMessage::TResource::toMessageIndex_messageID -template -inline ForwardIterator find(ForwardIterator first, ForwardIterator last, T& val) { - while (first != last && !(*first == val)) { - ++first; - } - return first; -} /* template diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/limits b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/limits index 5da476c21..89a2f86dd 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/limits +++ b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/limits @@ -83,7 +83,7 @@ public: } }; -#if __REVOLUTION_SDK__ +#if PLATFORM_WII template <> class numeric_limits { public: diff --git a/src/egg/gfx/eggDrawGX.cpp b/src/egg/gfx/eggDrawGX.cpp index c428ac4a7..9ab4bfa50 100644 --- a/src/egg/gfx/eggDrawGX.cpp +++ b/src/egg/gfx/eggDrawGX.cpp @@ -594,7 +594,7 @@ void DrawGX::CreateDisplayList(EGG::Heap *pHeap) { DrawCircleYPolygonFan(mtx, 0.0f, POS_NUM[i - DL_9]); MTXIdentity(mtx); - MTXRotRad(mtx, M_PI, 0x7A); + MTXRotRad(mtx, 0x7A, M_PI); MTXTransApply(mtx, mtx, 0.0f, -0.5f, 0.0f); DrawCircleYPolygonFan(mtx, 0.0f, POS_NUM[i - DL_9]); break; @@ -604,7 +604,7 @@ void DrawGX::CreateDisplayList(EGG::Heap *pHeap) { nw4r::math::MTX34 mtx; MTXIdentity(mtx); DrawCircleYPolygonFan(mtx, 1.0f, POS_NUM[i - DL_11]); - MTXRotRad(mtx, M_PI, 0x7A); + MTXRotRad(mtx, 0x7A, M_PI); DrawCircleYPolygonFan(mtx, 0.0f, POS_NUM[i - DL_11]); break; } @@ -612,7 +612,7 @@ void DrawGX::CreateDisplayList(EGG::Heap *pHeap) { case DL_8: { nw4r::math::MTX34 mtx; MTXIdentity(mtx); - MTXRotRad(mtx, M_PI / 2.0f, 0x78); + MTXRotRad(mtx, 0x78, M_PI / 2.0f); DrawCircleYPolygonFan(mtx, 0.0f, POS_NUM[i - DL_7]); break; }