NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
s_lib.hpp
1#pragma once
2#include <types.h>
3
4/**
5 * @brief A collection of motion and interpolation utilities.
6 * @details Provides utilities for timer management, proportional smoothing and fixed step movement
7 * for both scalar and angular data types.
8 *
9 * All functions operate directly on pointers to allow for in-place updates.
10 * @ingroup slib
11 */
12namespace sLib {
13
14/**
15 * @brief Decrements a timer value.
16 * @details The timer is only decreased if it's non-zero.
17 * @param value The timer value to be decremented.
18 * @return The updated timer value.
19 */
20template <typename T>
21T calcTimer(T *value) {
22 if (*value != 0) {
23 *value--;
24 }
25 return *value;
26}
27
28/**
29 * @brief Smoothly moves @p value towards @p target using proportional scaling.
30 * @details If the applied step overshoots the target, the value is snapped exactly to the target.
31 * @param value The value to be updated.
32 * @param target The target value.
33 * @param smoothing The smoothing factor (between @p 0.0 and @p 1.0). Higher value means snappier movement.
34 * @param maxStep The maximum step for a single update.
35 * @param minStep The minimum step to prevent jittering.
36 * @return The absolute remaining distance to the target.
37 */
38float addCalc(float *value, float target, float smoothing, float maxStep, float minStep);
39
40/**
41 * @brief Smoothly moves @p value towards @p target using proportional scaling.
42 * @details If the applied step overshoots the target, the value is snapped exactly to the target.
43 * @param value The value to be updated.
44 * @param target The target value.
45 * @param smoothing The smoothing factor. Higher value means smoother movement.
46 * @param maxStep The maximum step for a single update.
47 * @param minStep The minimum step to prevent jittering.
48 * @return The absolute remaining distance to the target.
49 */
50template <typename T>
51T addCalcAngleT(T *value, T target, T smoothing, T maxStep, T minStep);
52s16 addCalcAngle(s16 *value, s16 target, s16 smoothing, s16 maxStep, s16 minStep); ///< @copydoc sLib::addCalcAngleT(T*, T, T, T, T)
53
54/**
55 * @brief Smoothly moves @p value towards @p target using proportional scaling.
56 * @details If the applied step overshoots the target, the value is snapped exactly to the target.
57 * @param value The value to be updated.
58 * @param target The target value.
59 * @param smoothing The smoothing factor. Higher value means smoother movement.
60 * @param maxStep The maximum step for a single update.
61 */
62template <typename T>
63void addCalcAngleT(T *value, T target, T smoothing, T maxStep);
64void addCalcAngle(s16 *value, s16 target, s16 smoothing, s16 maxStep); ///< @copydoc sLib::addCalcAngleT(T*, T, T, T)
65
66/** @brief Moves @p value towards @p target by a fixed @p step amount.
67 * @details The step direction is automatically adjusted to move toward the target.
68 * If the applied step overshoots the target, the value is snapped exactly to the target.
69 * @param value The value to be updated.
70 * @param target The target value.
71 * @param step The step value.
72 * @return @p TRUE if the value reached the target, @p FALSE otherwise.
73 */
74template <typename T>
75BOOL chaseT(T *value, T target, T step);
76BOOL chase(s16 *value, s16 target, s16 step); ///< @copydoc sLib::chaseT
77BOOL chase(int *value, int target, int step); ///< @copydoc sLib::chaseT
78BOOL chase(long *value, long target, long step); ///< @copydoc sLib::chaseT
79BOOL chase(float *value, float target, float step); ///< @copydoc sLib::chaseT
80
81/** @brief Moves @p value towards @p target by a fixed @p step amount.
82 * @details The step direction is automatically adjusted to move toward the target.
83 * If the applied step overshoots the target, the value is snapped exactly to the target.
84 * @param value The value to be updated.
85 * @param target The target value.
86 * @param step The step value.
87 * @return @p TRUE if the value reached the target, @p FALSE otherwise.
88 */
89BOOL chaseAngle(s16 *value, s16 target, s16 step);
90
91/**
92 * @brief Moves @p value towards @p target by a fixed @p step amount.
93 * @details The sign of @p step determines the rotation direction and is not automatically adjusted.
94 * - If the step direction points toward the target and the applied step overshoots the target,
95 * the value is snapped exactly to the target.
96 * - If the step direction points away from the target, the value continues moving in that direction
97 * and the value is not snapped to the target.
98 * @param value The value to be updated.
99 * @param target The target value.
100 * @param step The step value.
101 * @return @p TRUE if the value reached the target, @p FALSE otherwise.
102 */
103BOOL chaseAngleByRotDir(s16 *value, s16 target, s16 step);
104
105} // namespace sLib
A collection of motion and interpolation utilities.
Definition s_lib.hpp:12
T calcTimer(T *value)
Decrements a timer value.
Definition s_lib.hpp:21
T addCalcAngleT(T *value, T target, T smoothing, T maxStep, T minStep)
Smoothly moves value towards target using proportional scaling.
Definition s_lib.cpp:42
BOOL chaseT(T *value, T target, T step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:99
float addCalc(float *value, float target, float smoothing, float maxStep, float minStep)
Smoothly moves value towards target using proportional scaling.
Definition s_lib.cpp:3
s16 addCalcAngle(s16 *value, s16 target, s16 smoothing, s16 maxStep, s16 minStep)
Smoothly moves value towards target using proportional scaling.
Definition s_lib.cpp:76
BOOL chaseAngleByRotDir(s16 *value, s16 target, s16 step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:158
BOOL chaseAngle(s16 *value, s16 target, s16 step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:135
BOOL chase(s16 *value, s16 target, s16 step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:119