diff --git a/configure.py b/configure.py index 8ecc6b8d8..42d4a3027 100755 --- a/configure.py +++ b/configure.py @@ -712,7 +712,7 @@ config.libs = [ Object(Matching, "JSystem/JStudio/JStudio/jstudio-data.cpp"), Object(Matching, "JSystem/JStudio/JStudio/jstudio-math.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio/jstudio-object.cpp"), - Object(NonMatching, "JSystem/JStudio/JStudio/functionvalue.cpp"), + Object(Equivalent, "JSystem/JStudio/JStudio/functionvalue.cpp"), # weak func order Object(NonMatching, "JSystem/JStudio/JStudio/fvb.cpp"), Object(Matching, "JSystem/JStudio/JStudio/fvb-data.cpp"), Object(Matching, "JSystem/JStudio/JStudio/fvb-data-parse.cpp"), diff --git a/include/JSystem/JGadget/allocator.h b/include/JSystem/JGadget/allocator.h index 7b110acfa..998668cf4 100644 --- a/include/JSystem/JGadget/allocator.h +++ b/include/JSystem/JGadget/allocator.h @@ -6,14 +6,6 @@ namespace JGadget { template struct TAllocator { - // TODO: This explicit ctor needs to be removed in order to match TFunctionValue_composite's constructor - // in functionvalue.cpp, and in order to get the @564 struct literal to appear in the .sbss section of that TU. - // However, removing this definition also causes that bss literal to appear in other TUs it shouldn't. - // This seems related to the 16 1-byte weak bss symbols that appear in a ton of different TUs (@936 to @1036) - // as this literal also has alignment 1 in the debug maps but alignment for in non-debug maps. - // Specifically it's the JGadget::TAllocator() inside of TFunctionValueAttribute_refer that creates the literal. - TAllocator() {} - T* allocate(u32 count, const void *param_2) { return AllocateRaw(count * sizeof(T)); } diff --git a/include/JSystem/JGadget/define.h b/include/JSystem/JGadget/define.h new file mode 100644 index 000000000..aa8be7d39 --- /dev/null +++ b/include/JSystem/JGadget/define.h @@ -0,0 +1,46 @@ +#ifndef DEFINE_H +#define DEFINE_H + +#include "dolphin/types.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 int); + JGadget_outMessage& operator<<(u8); + JGadget_outMessage& operator<<(const char* str); + JGadget_outMessage& operator<<(s8); + JGadget_outMessage& operator<<(s32); + JGadget_outMessage& operator<<(u32); + JGadget_outMessage& operator<<(const void*); + +private: + MessageFunc mMsgFunc; + char mBuffer[256]; + char* mWrite_p; + char* mFile; + int mLine; +}; + +#define JGADGET_ASSERTWARN(cond) ((cond) || (false)) + +#define JGADGET_EXITWARN(cond) \ + if (!(cond)) { \ + false; \ + return false; \ + } +} +#endif + +#endif diff --git a/include/JSystem/JGadget/search.h b/include/JSystem/JGadget/search.h index 6f14459b4..6ee489994 100644 --- a/include/JSystem/JGadget/search.h +++ b/include/JSystem/JGadget/search.h @@ -1,10 +1,24 @@ #ifndef SEARCH_H #define SEARCH_H -#include "global.h" +#include +#include +#include namespace JGadget { +namespace search { + +template +struct TExpandStride_ {}; + +template <> +struct TExpandStride_ { + static s32 get(s32 n) { return n << 3; } +}; + +} // namespace search + //! @todo: mangled name isn't correct, fix this //! Current: toValueFromIndex__7JGadgetFiPCPFdd_dUlRCPFdd_d //! Target: toValueFromIndex__7JGadgetFiPCPFdd_dUlRCPFdd_d_RCPFdd_d @@ -14,6 +28,94 @@ inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& f return (idx < count) ? pValue[idx] : fallback; } +template +struct TIterator : public std::iterator { +}; + +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 +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 +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 /* SEARCH_H */ diff --git a/include/JSystem/JStudio/JStudio/functionvalue.h b/include/JSystem/JStudio/JStudio/functionvalue.h index 55a33f3a4..56e0b3066 100644 --- a/include/JSystem/JStudio/JStudio/functionvalue.h +++ b/include/JSystem/JStudio/JStudio/functionvalue.h @@ -3,7 +3,10 @@ #include "JSystem/JGadget/search.h" #include "JSystem/JGadget/vector.h" +#include "JSystem/JGadget/define.h" +#include "JSystem/JUtility/JUTAssert.h" #include "global.h" +#include namespace JStudio { @@ -77,7 +80,8 @@ public: class TFunctionValueAttribute_refer : public JGadget::TVector_pointer { public: - TFunctionValueAttribute_refer() : JGadget::TVector_pointer(JGadget::TAllocator()) {} + // TFunctionValueAttribute_refer() : JGadget::TVector_pointer(JGadget::TAllocator()) {} + inline TFunctionValueAttribute_refer(); ~TFunctionValueAttribute_refer() {} void refer_initialize(); @@ -306,21 +310,75 @@ class TFunctionValue_list_parameter : public TFunctionValue, public TFunctionValueAttribute_range, public TFunctionValueAttribute_interpolate { public: - struct TIterator_data_ { - TIterator_data_(const f32* value) : value_(value) {} - TIterator_data_(const TIterator_data_& other) : value_(other.value_) {} + 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) { +#ifdef DEBUG + pOwn_ = &rParent; +#endif + pf_ = value; + } - void operator=(const TIterator_data_& rhs) { value_ = rhs.value_; } - TIterator_data_& operator--() { - value_ -= 2; + const f32* get() const { return pf_; } + void set(const f32* value) { pf_ = value; } + + friend bool operator==(const TIterator_data_& r1, const TIterator_data_& r2) { +#ifdef 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*() { +#ifdef DEBUG + JUT_ASSERT(947, pf_!=0); +#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 bool operator==(const TIterator_data_& lhs, const TIterator_data_& rhs) { return lhs.value_ == rhs.value_; } - const f32* get() const { return value_; } - void set(const f32* value) { value_ = value; } + friend s32 operator-(const TIterator_data_& r1, const TIterator_data_& r2) { +#ifdef 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; + } - const f32* value_; +#ifdef DEBUG + /* 0x00 */ const TFunctionValue_list_parameter* pOwn_; + /* 0x04 */ const f32* pf_; +#else + /* 0x00 */ const f32* pf_; +#endif }; typedef f64 (*update_INTERPOLATE)(const TFunctionValue_list_parameter&, f64); @@ -334,19 +392,17 @@ public: 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 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); - f64 data_getValue_back() { - return pfData_[(uData_ - 1) * 2]; + static const u32 suData_size = 2; + + f64 data_getValue_back() const { + return pfData_[(uData_ - 1) * suData_size]; } - f64 data_getValue_front() { return pfData_[0]; } + f64 data_getValue_front() const { return pfData_[0]; } private: /* 0x44 */ const f32* pfData_; @@ -359,28 +415,86 @@ private: class TFunctionValue_hermite : public TFunctionValue, public TFunctionValueAttribute_range { public: - struct TIterator_data_ { + 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) { - value_ = value; - size_ = rParent.data_getSize(); +#ifdef DEBUG + pOwn_ = &rParent; +#endif + pf_ = value; + uSize_ = rParent.data_getSize(); } - const f32* get() { return value_; } - + const f32* get() const { return pf_; } void set(const f32* value, u32 size) { - value_ = value; - size_ = size; + pf_ = value; + uSize_ = size; } - - friend bool operator==(const TIterator_data_& lhs, const TIterator_data_& rhs) { return lhs.value_ == rhs.value_; } + friend bool operator==(const TIterator_data_& r1, const TIterator_data_& r2) { +#ifdef 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*() { +#ifdef DEBUG + JUT_ASSERT(1098, pf_!=0); +#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--() { - value_ -= size_; + pf_ -= uSize_; return *this; } - /* 0x00 */ const f32* value_; - /* 0x04 */ u32 size_; + friend s32 operator-(const TIterator_data_& r1, const TIterator_data_& r2) { +#ifdef 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_; + } + +#ifdef DEBUG + /* 0x00 */ const TFunctionValue_hermite* pOwn_; + /* 0x04 */ const f32* pf_; + /* 0x08 */ u32 uSize_; +#else + /* 0x00 */ const f32* pf_; + /* 0x04 */ u32 uSize_; +#endif }; TFunctionValue_hermite(); @@ -394,13 +508,13 @@ public: virtual f64 getValue(f64); u32 data_getSize() const { return uSize_; } - f64 data_getValue_back() { - return pf_[(u_ - 1) * uSize_]; + f64 data_getValue_back() const { + return pfData_[(u_ - 1) * uSize_]; } - f64 data_getValue_front() { return pf_[0]; } + f64 data_getValue_front() const { return pfData_[0]; } private: - /* 0x40 */ const f32* pf_; + /* 0x40 */ const f32* pfData_; /* 0x44 */ u32 u_; /* 0x48 */ u32 uSize_; /* 0x4c */ TIterator_data_ dat1; @@ -408,6 +522,35 @@ private: /* 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) + value = max; + + return value; +} + +}; // namespace functionvalue + } // namespace JStudio #endif /* FUNCTIONVALUE_H */ diff --git a/include/JSystem/JStudio/JStudio/object-id.h b/include/JSystem/JStudio/JStudio/object-id.h index 0a3321097..274b3a9ec 100644 --- a/include/JSystem/JStudio/JStudio/object-id.h +++ b/include/JSystem/JStudio/JStudio/object-id.h @@ -20,12 +20,14 @@ private: /* 0x04 */ u32 mID_size; }; -struct TPRObject_ID_equal : public TIDData { - TPRObject_ID_equal(const void* id, u32 id_size) : TIDData(id, id_size) {} -}; - struct TObject_ID : public TIDData { TObject_ID(const void* id, u32 id_size) : TIDData(id, id_size) {} + TIDData const& getIDData() const { return *this; } +}; + +struct TPRObject_ID_equal : public TIDData { + TPRObject_ID_equal(const void* id, u32 id_size) : TIDData(id, id_size) {} + bool operator()(TObject_ID const& id) const { return TIDData::isEqual(id.getIDData(), *this); } }; } // namespace object diff --git a/include/weak_bss_3569.h b/include/weak_bss_3569.h index 9444c6e5e..cf4686551 100644 --- a/include/weak_bss_3569.h +++ b/include/weak_bss_3569.h @@ -5,8 +5,11 @@ // This is some kind of weak objects that get included in the .bss sections of several TUs. // Its true source is currently unknown, so include this header in TUs that need it to match for now. -#include "dolphin/mtx/vec.h" +#include "dolphin/types.h" +template struct bss_3569 { u8 val[0xC]; }; -static Vec bss_3569; +static inline void dummy_bss_3569() { + bss_3569(); // @3569 +} #endif /* WEAK_BSS_3569_H */ diff --git a/include/weak_bss_936_to_1036.h b/include/weak_bss_936_to_1036.h index d4be24287..dfadbce5e 100644 --- a/include/weak_bss_936_to_1036.h +++ b/include/weak_bss_936_to_1036.h @@ -3,28 +3,37 @@ // Fake header. // These are some kind of weak objects that get included in the .bss sections of several TUs. +// They each have size 1, and alignment 1 in the debug maps, but alignment 4 in the non-debug maps. // Their true source is currently unknown, so include this header in TUs that need them to match for now. -#include "global.h" +// A possible origin for one of these could be the constructor of TFunctionValueAttribute_refer in +// functionvalue.h. That constructor includes `JGadget::TAllocator()` in it, which produces +// one weak bss object that has the correct size and alignment. However, we need 16 of them, while +// that only creates one. Also, that header seems to be required in some actors that *don't* need +// any of these weak bss objects. So that constructor is moved to functionvalue.cpp and this fake +// header should be included where necessary instead. #include "weak_bss_3569.h" // IWYU pragma: keep +#include "JSystem/JStudio/JStudio/functionvalue.h" // IWYU pragma: keep // They each have size 1, and alignment 1 in the debug maps, but alignment 4 in the non-debug maps. -static u8 bss_1036 ALIGN_DECL(4); -static u8 bss_1034 ALIGN_DECL(4); -static u8 bss_1032 ALIGN_DECL(4); -static u8 bss_1031 ALIGN_DECL(4); -static u8 bss_1026 ALIGN_DECL(4); -static u8 bss_1024 ALIGN_DECL(4); -static u8 bss_1022 ALIGN_DECL(4); -static u8 bss_1021 ALIGN_DECL(4); -static u8 bss_984 ALIGN_DECL(4); -static u8 bss_982 ALIGN_DECL(4); -static u8 bss_980 ALIGN_DECL(4); -static u8 bss_979 ALIGN_DECL(4); -static u8 bss_941 ALIGN_DECL(4); -static u8 bss_939 ALIGN_DECL(4); -static u8 bss_937 ALIGN_DECL(4); -static u8 bss_936 ALIGN_DECL(4); +static inline void dummy_bss_936_to_1036() { + JGadget::TAllocator(); // @1036 + JGadget::TAllocator(); // @1034 + JGadget::TAllocator(); // @1032 + JGadget::TAllocator(); // @1031 + JGadget::TAllocator(); // @1026 + JGadget::TAllocator(); // @1024 + JGadget::TAllocator(); // @1022 + JGadget::TAllocator(); // @1021 + JGadget::TAllocator(); // @984 + JGadget::TAllocator(); // @982 + JGadget::TAllocator(); // @980 + JGadget::TAllocator(); // @979 + JGadget::TAllocator(); // @941 + JGadget::TAllocator(); // @939 + JGadget::TAllocator(); // @937 + JGadget::TAllocator(); // @936 +} #endif /* WEAK_BSS_936_TO_1036_H */ diff --git a/src/JSystem/JStudio/JStudio/functionvalue.cpp b/src/JSystem/JStudio/JStudio/functionvalue.cpp index b49539405..3ed957c92 100644 --- a/src/JSystem/JStudio/JStudio/functionvalue.cpp +++ b/src/JSystem/JStudio/JStudio/functionvalue.cpp @@ -4,19 +4,12 @@ // #include "JSystem/JStudio/JStudio/functionvalue.h" -#include "JSystem/JStudio/JStudio/functionvalue_weak.h" #include "JSystem/JUtility/JUTException.h" #include "JSystem/JGadget/linklist.h" #include "dolphin/types.h" #include "math.h" #include "arith.h" -namespace JGadget { -template -// TODO -Iterator findUpperBound_binary_current(Iterator, Iterator, Iterator, const B1&); -}; // namespace JGadget - namespace JStudio { namespace { @@ -51,6 +44,12 @@ TFunctionValue::TFunctionValue() {} /* 80271078-802710C0 .text __dt__Q27JStudio14TFunctionValueFv */ TFunctionValue::~TFunctionValue() {} +// This seems like it would belong in the functionvalue.h header, but putting it there causes the +// `JGadget::TAllocator()` part to spawn a weak bss object that appears in many TUs. +// Some TUs do need a weak bss object like that, but it also gets put in ones that don't need it. +TFunctionValueAttribute_refer::TFunctionValueAttribute_refer() : + JGadget::TVector_pointer(JGadget::TAllocator()) {} + /* 802710C0-802710E8 .text refer_initialize__Q27JStudio29TFunctionValueAttribute_referFv */ void TFunctionValueAttribute_refer::refer_initialize() { clear(); @@ -77,24 +76,25 @@ f64 interpolateValue_hermite(f64 c0, f64 c1, f64 x, f64 c2, f64 x2, f64 c3, f64 } /* 8027114C-802711B0 .text interpolateValue_BSpline_uniform__Q27JStudio13functionvalueFddddd */ -f64 interpolateValue_BSpline_uniform(f64 f1, f64 f2, f64 f3, f64 f4, f64 f5) { - /* Nonmatching - operand swap */ - // pow3(1.0 - f1) - f64 f6 = (1.0 - f1); - f64 f0 = f6; - f0 = (f6 * f6) * f0; - f64 f8 = f0; +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 f9 = f1 * f1; - f64 f10 = f9 * f1; + f64 interpolationFactorSquared = interpolationFactor * interpolationFactor; + f64 interpolationFactorCubed = interpolationFactorSquared * interpolationFactor; - f64 temp2 = ((1.0 / 6.0) + 0.5 * ((f1 + f9) - f10)); - f64 temp3 = temp2 * f4; + f64 coefficient1 = inverseInterpolationFactorCubed; - f64 temp4 = ((0.5 * f10 - f9) + (2.0 / 3.0)); - f64 temp5 = temp4 * f3; + f64 blendFactorForPoint3 = (1.0 / 2.0) * interpolationFactorCubed - interpolationFactorSquared + (2.0 / 3.0); - return temp5 + (f8 * f2 + f10 * f5) * (1.0 / 6.0) + temp3; + 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); } /* 802711B0-80271290 .text interpolateValue_BSpline_nonuniform__Q27JStudio13functionvalueFdPCdPCd */ @@ -239,7 +239,6 @@ TFunctionValueAttribute_range::TFunctionValueAttribute_range() /* 80271734-80271790 .text __ct__Q27JStudio24TFunctionValue_compositeFv */ TFunctionValue_composite::TFunctionValue_composite() : pfn_(NULL), data((void*)NULL) { - /* Nonmatching - see TODO comment in allocator.h */ } /* 80271790-80271798 .text getType__Q27JStudio24TFunctionValue_compositeCFv */ @@ -655,7 +654,7 @@ f64 TFunctionValue_list::update_INTERPOLATE_BSPLINE_dataMore3_(const TFunctionVa } /* 80272728-80272794 .text __ct__Q27JStudio29TFunctionValue_list_parameterFv */ -TFunctionValue_list_parameter::TFunctionValue_list_parameter() : pfData_(NULL), uData_(0), dat1(NULL), dat2(dat1), dat3(dat1), pfnUpdate_(NULL) {} +TFunctionValue_list_parameter::TFunctionValue_list_parameter() : pfData_(NULL), uData_(0), dat1(*this, NULL), dat2(dat1), dat3(dat1), pfnUpdate_(NULL) {} /* 80272794-8027279C .text getType__Q27JStudio29TFunctionValue_list_parameterCFv */ u32 TFunctionValue_list_parameter::getType() const { @@ -687,7 +686,7 @@ void TFunctionValue_list_parameter::initialize() { pfData_ = NULL; uData_ = 0; - TIterator_data_ iter(NULL); + TIterator_data_ iter(*this, NULL); dat1 = iter; dat2 = dat1; @@ -725,7 +724,6 @@ void TFunctionValue_list_parameter::prepare() { /* 80272904-802729DC .text getValue__Q27JStudio29TFunctionValue_list_parameterFd */ f64 TFunctionValue_list_parameter::getValue(f64 pfData_) { - /* Nonmatching */ pfData_ = range_getParameter(pfData_, data_getValue_front(), data_getValue_back()); // JUT_ASSERT(1395, pfData_!=0) @@ -840,7 +838,7 @@ f64 TFunctionValue_list_parameter::update_INTERPOLATE_BSPLINE_dataMore3_(const T } /* 80272CB8-80272D38 .text __ct__Q27JStudio22TFunctionValue_hermiteFv */ -TFunctionValue_hermite::TFunctionValue_hermite() : pf_(NULL), u_(0), uSize_(0), dat1(*this, NULL), dat2(dat1), dat3(dat1) {} +TFunctionValue_hermite::TFunctionValue_hermite() : pfData_(NULL), u_(0), uSize_(0), dat1(*this, NULL), dat2(dat1), dat3(dat1) {} /* 80272D38-80272D40 .text getType__Q27JStudio22TFunctionValue_hermiteCFv */ u32 TFunctionValue_hermite::getType() const { @@ -857,12 +855,12 @@ void TFunctionValue_hermite::data_set(const f32* pf, u32 u, u32 uSize) { ASSERT((pf != NULL) || (u == 0)); ASSERT((uSize == 3) || (uSize == 4)); - pf_ = pf; + pfData_ = pf; u_ = u; uSize_ = uSize; - dat1.set(pf_, uSize_); - dat2.set(&pf_[u_ * uSize_], uSize_); + dat1.set(pfData_, uSize_); + dat2.set(&pfData_[u_ * uSize_], uSize_); dat3 = dat1; } @@ -870,7 +868,7 @@ void TFunctionValue_hermite::data_set(const f32* pf, u32 u, u32 uSize) { void TFunctionValue_hermite::initialize() { range_initialize(); - pf_ = NULL; + pfData_ = NULL; u_ = 0; uSize_ = 0; @@ -887,7 +885,6 @@ void TFunctionValue_hermite::prepare() { /* 80272E40-80272F64 .text getValue__Q27JStudio22TFunctionValue_hermiteFd */ f64 TFunctionValue_hermite::getValue(f64 pfData_) { - /* Nonmatching */ pfData_ = range_getParameter(pfData_, data_getValue_front(), data_getValue_back()); // JUT_ASSERT(1395, pfData_!=0) dat3 = JGadget::findUpperBound_binary_current(dat1, dat2, dat3, pfData_); diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm.h b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm.h index adde83897..6e711b8df 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/algorithm.h @@ -3,8 +3,31 @@ #include #include +#include namespace std { + +template +inline ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val, Predicate p) { + typedef typename iterator_traits::difference_type difference_type; + difference_type len = std::distance(first, last); + + while (len > 0) { + ForwardIterator i = first; + difference_type step = len / 2; + std::advance(i, step); + + if (p(*i, val)) { + first = ++i; + len -= step + 1; + } else { + len = step; + } + } + + return first; +} + template ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val) { typedef typename iterator_traits::difference_type difference_type; @@ -26,11 +49,41 @@ ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T return first; } -template -ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& val); +template +ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& val, Predicate p) { + typedef typename iterator_traits::difference_type difference_type; + difference_type len = std::distance(first, last); + + while (len > 0) { + ForwardIterator i = first; + difference_type step = len / 2; + std::advance(i, step); + + if (!p(val, *i)) { + first = ++i; + len -= step + 1; + } else { + len = step; + } + } + + return first; +} template -InputIt find_if(InputIt first, InputIt last, UnaryPredicate p); +InputIt find_if(InputIt first, InputIt last, UnaryPredicate p) { + while (first != last && !p(*first)) { + ++first; + } + return first; +} + +template +inline ForwardIterator find(ForwardIterator first, ForwardIterator last, T& val) { + for (; first != last && *first != val; ++first) { + } + return first; +} /* template diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/functional.h b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/functional.h index 8a11caaea..1c7b8fb46 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/functional.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/functional.h @@ -2,7 +2,21 @@ #define MSL_FUNCTIONAL_H_ namespace std { -template struct less {}; + +namespace detail { + +template +struct less { + bool operator()(const T1& lhs, const T2& rhs) const { return lhs < rhs; } +}; + +} // namespace detail + +template +struct less : public std::detail::less { + bool operator()(const T& lhs, const T& rhs) const { return lhs < rhs; } +}; + } // namespace std #endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/iterator.h b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/iterator.h index 44d88a3ba..73ca5de69 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/iterator.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include/iterator.h @@ -1,9 +1,7 @@ -#ifndef ITERATOR_H -#define ITERATOR_H #ifndef MSL_ITERATOR_H_ #define MSL_ITERATOR_H_ -#include "stddef.h" +#include namespace std { struct input_iterator_tag {}; @@ -30,6 +28,20 @@ struct iterator_traits { typedef random_access_iterator_tag iterator_category; }; +template< + class Category, + class T, + class Distance, + class Pointer, + class Reference +> struct iterator { + typedef Distance difference_type; + typedef T value_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; +}; + template inline void __advance(InputIterator& i, Distance n, input_iterator_tag) { for (; n > 0; --n) @@ -95,6 +107,3 @@ inline void advance_pointer(InputIt& it, Distance n) { } // namespace std #endif - - -#endif /* ITERATOR_H */ diff --git a/src/d/actor/d_a_lamp.cpp b/src/d/actor/d_a_lamp.cpp index 1f10f22db..14818ff16 100644 --- a/src/d/actor/d_a_lamp.cpp +++ b/src/d/actor/d_a_lamp.cpp @@ -9,40 +9,7 @@ #include "d/d_procname.h" #include "m_Do/m_Do_mtx.h" -// RW data -static dCcD_SrcSph sph_src = { - // dCcD_SrcGObjInf - { - /* Flags */ 0, - /* SrcObjAt Type */ 0, - /* SrcObjAt Atp */ 0, - /* SrcObjAt SPrm */ 0, - /* SrcObjTg Type */ AT_TYPE_FIRE | AT_TYPE_UNK20000 | AT_TYPE_FIRE_ARROW | AT_TYPE_WIND | AT_TYPE_UNK400000, - /* SrcObjTg SPrm */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsOther_e, - /* SrcObjCo SPrm */ 0, - /* SrcGObjAt Se */ 0, - /* SrcGObjAt HitMark */ 0, - /* SrcGObjAt Spl */ 0, - /* SrcGObjAt Mtrl */ 0, - /* SrcGObjAt SPrm */ 0, - /* SrcGObjTg Se */ 0, - /* SrcGObjTg HitMark */ 0, - /* SrcGObjTg Spl */ 0, - /* SrcGObjTg Mtrl */ 0, - /* SrcGObjTg SPrm */ 0, - /* SrcGObjCo SPrm */ 0, - }, - // cM3dGSphS - { - /* Center */ 0.0f, 0.0f, 0.0f, - /* Radius */ 30.0f, - }, -}; -static u8 padding[76]; - -// Need to break these out to get the rodata ordered right -static const float partHeightOffset = 20.0f; -static const float partMaxFlickerPerTick = 0.02f; +#include "weak_bss_936_to_1036.h" // IWYU pragma: keep /* 000000EC-00000158 .text daLamp_Draw__FP10lamp_class */ static BOOL daLamp_Draw(lamp_class* i_this) { @@ -95,9 +62,9 @@ static BOOL daLamp_Execute(lamp_class* i_this) { if (i_this->mPa.getEmitter()) { cXyz whitePartPos = i_this->mPos; - whitePartPos.y += partHeightOffset; + whitePartPos.y += 20.0f; dComIfGp_particle_setSimple(dPa_name::ID_COMMON_4004, &whitePartPos); - cLib_addCalc2(&i_this->mParticlePower, cM_rndF(0.2f) + 1.0f, 0.5f, partMaxFlickerPerTick); + cLib_addCalc2(&i_this->mParticlePower, cM_rndF(0.2f) + 1.0f, 0.5f, 0.02f); } else { i_this->mParticlePower = 0.0f; } @@ -187,6 +154,36 @@ static cPhs_State daLamp_Create(fopAc_ac_c* i_ac) { i_this->mParameters = 0; } i_this->mStts.Init(0xff, 0xff, i_this); + + static dCcD_SrcSph sph_src = { + // dCcD_SrcGObjInf + { + /* Flags */ 0, + /* SrcObjAt Type */ 0, + /* SrcObjAt Atp */ 0, + /* SrcObjAt SPrm */ 0, + /* SrcObjTg Type */ AT_TYPE_FIRE | AT_TYPE_UNK20000 | AT_TYPE_FIRE_ARROW | AT_TYPE_WIND | AT_TYPE_UNK400000, + /* SrcObjTg SPrm */ cCcD_TgSPrm_Set_e | cCcD_TgSPrm_IsOther_e, + /* SrcObjCo SPrm */ 0, + /* SrcGObjAt Se */ 0, + /* SrcGObjAt HitMark */ 0, + /* SrcGObjAt Spl */ 0, + /* SrcGObjAt Mtrl */ 0, + /* SrcGObjAt SPrm */ 0, + /* SrcGObjTg Se */ 0, + /* SrcGObjTg HitMark */ 0, + /* SrcGObjTg Spl */ 0, + /* SrcGObjTg Mtrl */ 0, + /* SrcGObjTg SPrm */ 0, + /* SrcGObjCo SPrm */ 0, + }, + // cM3dGSphS + { + /* Center */ 0.0f, 0.0f, 0.0f, + /* Radius */ 30.0f, + }, + }; + i_this->mSph.Set(sph_src); i_this->mSph.SetStts(&i_this->mStts); diff --git a/src/d/actor/d_a_obj_gaship.cpp b/src/d/actor/d_a_obj_gaship.cpp index f3194dc0a..7d448d76c 100644 --- a/src/d/actor/d_a_obj_gaship.cpp +++ b/src/d/actor/d_a_obj_gaship.cpp @@ -10,9 +10,9 @@ #include "m_Do/m_Do_mtx.h" #include "d/res/res_gaship.h" -const char daObjGaship::Act_c::M_arcname[7] = "GaShip"; +#include "weak_bss_936_to_1036.h" // IWYU pragma: keep -static f32 dummy[19]; +const char daObjGaship::Act_c::M_arcname[7] = "GaShip"; /* 000000EC-000002DC .text birth_flag__Q211daObjGaship5Act_cFv */ void daObjGaship::Act_c::birth_flag() { diff --git a/src/d/actor/d_a_tag_msg.cpp b/src/d/actor/d_a_tag_msg.cpp index 48a9427e0..afa484923 100644 --- a/src/d/actor/d_a_tag_msg.cpp +++ b/src/d/actor/d_a_tag_msg.cpp @@ -2,6 +2,7 @@ // Generated by dtk // Translation Unit: d_a_tag_msg.cpp // + #include "d/actor/d_a_tag_msg.h" #include "d/actor/d_a_player_main.h" #include "d/d_com_inf_game.h"