diff --git a/include/JSystem/JGeometry/Util.h b/include/JSystem/JGeometry/Util.h index 4eab4bf2..17b229ae 100644 --- a/include/JSystem/JGeometry/Util.h +++ b/include/JSystem/JGeometry/Util.h @@ -88,6 +88,20 @@ namespace JGeometry { } return cur; } + + // fabricated - taken from SMS decomp. + // NOTE: both `while` loops are reversed for MKDD, compared to SMS. + static inline T wrap(T t, T l, T r) { + if (l >= r) + return l; + + while (t < l) + t += r - l; + while (t >= r) + t -= r - l; + + return t; + } }; typedef TUtil TUtilf; diff --git a/include/Shiraiwa/Objects/MapObjWanwan.h b/include/Shiraiwa/Objects/MapObjWanwan.h index f1f8f688..dd1a792a 100644 --- a/include/Shiraiwa/Objects/MapObjWanwan.h +++ b/include/Shiraiwa/Objects/MapObjWanwan.h @@ -15,19 +15,6 @@ class TMapObjWanwan; -inline f32 normalizeRelativeAngle(f32 angle, f32 min, f32 max) { - if (min >= max) { - return min; - } - for (; angle < min; angle += max - min) { - } - - for (; angle >= max; angle -= max - min) { - } - - return angle; -} - class TMapObjWanwanPile : public GeographyObj { public: TMapObjWanwanPile(); diff --git a/src/Shiraiwa/MapObjWanwan.cpp b/src/Shiraiwa/MapObjWanwan.cpp index 329f189e..96d39f6c 100644 --- a/src/Shiraiwa/MapObjWanwan.cpp +++ b/src/Shiraiwa/MapObjWanwan.cpp @@ -442,7 +442,7 @@ void TMapObjWanwan::fallDown(s32 nextState, bool p2) { void TMapObjWanwan::turnTo() { f32 targetAngle = mAttackAngle; - f32 limit = targetAngle - normalizeRelativeAngle(mRotate, targetAngle - F_PI, targetAngle + F_PI); + f32 limit = targetAngle - JGeometry::TUtilf::wrap(mRotate, targetAngle - F_PI, targetAngle + F_PI); f32 rotate = _22c; if (StateObserver::getState() == 1) {