diff --git a/include/JSystem/JGadget/allocator.h b/include/JSystem/JGadget/allocator.h index 6082e93f3..08498d8f1 100644 --- a/include/JSystem/JGadget/allocator.h +++ b/include/JSystem/JGadget/allocator.h @@ -6,14 +6,19 @@ namespace JGadget { template struct TAllocator { - static TAllocator get() { } + // TODO: this constructor declaration 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 declaration also causes that bss literal to appear in hundreds of other TUs it shouldn't. + TAllocator(); - inline TAllocator(); + // TODO + void AllocateRaw(u32) {} + void DeallocateRaw(void*) {} + void allocate(u32, const void*) {} + void deallocate(T*, u32) {} + void destroy(T*) {} /* 0x00 */ u8 _00; - /* 0x04 */ u32 _04; - /* 0x08 */ u32 _08; - /* 0x0C */ u32 _0C; }; typedef TAllocator TVoidAllocator; diff --git a/include/JSystem/JGadget/search.h b/include/JSystem/JGadget/search.h index a7b351080..6f14459b4 100644 --- a/include/JSystem/JGadget/search.h +++ b/include/JSystem/JGadget/search.h @@ -11,7 +11,7 @@ namespace JGadget { template inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& fallback) { ASSERT(pValue != NULL); - return (idx >= count) ? fallback : pValue[idx]; + return (idx < count) ? pValue[idx] : fallback; } } // namespace JGadget diff --git a/include/JSystem/JStudio/JStudio/functionvalue.h b/include/JSystem/JStudio/JStudio/functionvalue.h index c45af801f..eed1437e2 100644 --- a/include/JSystem/JStudio/JStudio/functionvalue.h +++ b/include/JSystem/JStudio/JStudio/functionvalue.h @@ -76,8 +76,7 @@ public: class TFunctionValueAttribute_refer : public JGadget::TVector_pointer { public: - TFunctionValueAttribute_refer() : - JGadget::TVector_pointer(JGadget::TAllocator()) {} + TFunctionValueAttribute_refer() : JGadget::TVector_pointer(JGadget::TAllocator()) {} ~TFunctionValueAttribute_refer() {} void refer_initialize(); diff --git a/src/JSystem/JStudio/JStudio/functionvalue.cpp b/src/JSystem/JStudio/JStudio/functionvalue.cpp index 2f537a5ae..00ad17a34 100644 --- a/src/JSystem/JStudio/JStudio/functionvalue.cpp +++ b/src/JSystem/JStudio/JStudio/functionvalue.cpp @@ -30,12 +30,10 @@ ExtrapolateParameter gapfnExtrapolateParameter_[4] = { /* 80271020-80271068 .text toFunction_outside__Q27JStudio14TFunctionValueFi */ ExtrapolateParameter TFunctionValue::toFunction_outside(int idx) { - /* Nonmatching */ ExtrapolateParameter fallback = NULL; ExtrapolateParameter result; - result = JGadget::toValueFromIndex(idx, gapfnExtrapolateParameter_, 4, - fallback); + result = JGadget::toValueFromIndex(idx, gapfnExtrapolateParameter_, 4, fallback); if (result == NULL) { JUTWarn w; @@ -80,28 +78,51 @@ 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 */ + /* Nonmatching - operand swap */ // pow3(1.0 - f1) f64 f6 = (1.0 - f1); - f64 temp = f6; - temp = (f6 * f6) * temp; + f64 f0 = f6; + f0 = (f6 * f6) * f0; + f64 f8 = f0; - f64 f0 = f1 * f1; - f64 f8 = f0 * f1; + f64 f9 = f1 * f1; + f64 f10 = f9 * f1; - f64 temp2 = (0.5 + (1.0 / 6.0) * ((f1 + f0) - f8)); + f64 temp2 = ((1.0 / 6.0) + 0.5 * ((f1 + f9) - f10)); f64 temp3 = temp2 * f4; - f64 temp4 = (((1.0 / 6.0) * f8 - f0) + (2.0 / 3.0)); + f64 temp4 = ((0.5 * f10 - f9) + (2.0 / 3.0)); f64 temp5 = temp4 * f3; - return temp5 + (temp * f2 + f8 * f5) * 0.5 + - temp3; + return temp5 + (f8 * f2 + f10 * f5) * (1.0 / 6.0) + temp3; } /* 802711B0-80271290 .text interpolateValue_BSpline_nonuniform__Q27JStudio13functionvalueFdPCdPCd */ -f64 interpolateValue_BSpline_nonuniform(f64, const f64*, const f64*) { - /* Nonmatching */ +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(double a1, double a2, double a3, double a4, double a5) { @@ -141,7 +162,6 @@ void TFunctionValueAttribute_range::range_initialize() { /* 80271324-802713CC .text range_prepare__Q27JStudio29TFunctionValueAttribute_rangeFv */ void TFunctionValueAttribute_range::range_prepare() { - /* Nonmatching */ TFunctionValue::TEProgress progress = range_getProgress(); switch (progress) { @@ -182,7 +202,6 @@ void TFunctionValueAttribute_range::range_set(f64 begin, f64 end) { /* 802713E0-802716F0 .text range_getParameter__Q27JStudio29TFunctionValueAttribute_rangeCFddd */ f64 TFunctionValueAttribute_range::range_getParameter(f64 arg1, f64 arg2, f64 arg3) const { - /* Nonmatching */ f64 progress = range_getParameter_progress(arg1); TFunctionValue::TEAdjust adjust = range_getAdjust(); @@ -220,7 +239,7 @@ TFunctionValueAttribute_range::TFunctionValueAttribute_range() /* 80271734-80271790 .text __ct__Q27JStudio24TFunctionValue_compositeFv */ TFunctionValue_composite::TFunctionValue_composite() : pfn_(NULL), data((void*)NULL) { - /* Nonmatching */ + /* Nonmatching - see TODO comment in allocator.h */ } /* 80271790-80271798 .text getType__Q27JStudio24TFunctionValue_compositeCFv */ @@ -459,7 +478,6 @@ void TFunctionValue_transition::prepare() { /* 80271EE8-802720B0 .text getValue__Q27JStudio25TFunctionValue_transitionFd */ f64 TFunctionValue_transition::getValue(f64 param_1) { - /* Nonmatching */ f64 progress = range_getParameter_progress(param_1); f64 dVar3 = range_getParameter_outside(progress); switch (range_getAdjust()) { @@ -488,6 +506,7 @@ f64 TFunctionValue_transition::getValue(f64 param_1) { } switch (interpolate_get()) { case 0: + default: goto ADJ_UNK3_label; case 1: case 3: @@ -552,7 +571,6 @@ void TFunctionValue_list::prepare() { /* 8027224C-80272604 .text getValue__Q27JStudio19TFunctionValue_listFd */ f64 TFunctionValue_list::getValue(f64 param_1) { - /* Nonmatching */ f64 dVar9 = range_getParameter_progress(param_1); u32 iVar7 = uData_ - 1; TFunctionValue::TEAdjust iVar5 = range_getAdjust();