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