Skip to content

Commit 7b8212c

Browse files
committed
Added and updated method comments.
1 parent cf2340c commit 7b8212c

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

include/RhythmGameUtilities/Audio.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ namespace RhythmGameUtilities
1313

1414
extern "C"
1515
{
16+
/**
17+
* Converts samples from an audio file into data used to display a waveform.
18+
*
19+
* @param samples Array of sample data from an audio file.
20+
* @param size Length of the array.
21+
* @param width Width of the waveform.
22+
* @param height Height of the waveform.
23+
* @public
24+
*/
25+
1626
PACKAGE_API int **ConvertSamplesToWaveform(float *samples, int size,
1727
int width, int height)
1828
{
@@ -57,14 +67,23 @@ extern "C"
5767
return waveform;
5868
}
5969

70+
/**
71+
* Free data returned from the ConvertSamplesToWaveform function.
72+
*
73+
* @param waveform Waveform multidimensional array.
74+
* @param width Width of the waveform.
75+
* @public
76+
*/
77+
6078
PACKAGE_API void FreeWaveform(int **waveform, int width)
6179
{
6280
if (waveform != nullptr)
6381
{
64-
for (int x = 0; x < width; x++)
82+
for (int x = 0; x < width; x += 1)
6583
{
6684
delete[] waveform[x];
6785
}
86+
6887
delete[] waveform;
6988
}
7089
}

include/RhythmGameUtilities/Common.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,55 @@ namespace RhythmGameUtilities
1515

1616
extern "C"
1717
{
18+
/**
19+
* Calculates the linear interpolation between two values.
20+
*
21+
* @param a The start value.
22+
* @param b The end value.
23+
* @param t The value used for interpolation.
24+
* @public
25+
*/
1826

1927
PACKAGE_API float Lerp(float a, float b, float t)
2028
{
2129
return (1 - t) * a + b * t;
2230
}
2331

32+
/**
33+
* Calculates the fraction, based on a value between two values.
34+
*
35+
* @param a The start value.
36+
* @param b The end value.
37+
* @param v The value in the middle.
38+
* @public
39+
*/
40+
2441
PACKAGE_API float InverseLerp(float a, float b, float v)
2542
{
2643
return std::clamp(((v - a) / (b - a)), 0.0f, 1.0f);
2744
}
2845
}
46+
47+
/**
48+
* Trims a string value.
49+
*
50+
* @param contents The string to trim.
51+
* @private
52+
*/
53+
2954
std::string Trim(const char *contents)
3055
{
3156
return std::regex_replace(contents, std::regex("^\\s+|\\s+$"), "");
3257
}
3358

59+
/**
60+
* Splits a string into an array based on a delimiter.
61+
*
62+
* @param contents The string to split.
63+
* @param delimiter The delimiter to split on.
64+
* @private
65+
*/
66+
3467
std::vector<std::string> Split(const char *contents, const char delimiter)
3568
{
3669
auto parts = std::vector<std::string>();

include/RhythmGameUtilities/File.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
namespace RhythmGameUtilities
88
{
99

10+
/**
11+
* Reads the entire contents of a file.
12+
*
13+
* @param path The path of the file to read.
14+
* @public
15+
*/
16+
1017
std::string ReadFromFile(const char *path)
1118
{
1219
std::ifstream file(path);

include/RhythmGameUtilities/Utilities.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const float SECONDS_PER_MINUTE = 60.0f;
2626
* @param seconds The seconds to generate ticks with.
2727
* @param resolution The resolution of the song.
2828
* @param bpmChanges All BPM changes within the song.
29+
* @public
2930
*/
3031

3132
int ConvertSecondsToTicks(float seconds, int resolution,
@@ -61,6 +62,13 @@ int ConvertSecondsToTicks(float seconds, int resolution,
6162
return totalTicks;
6263
}
6364

65+
/**
66+
* Takes a map of key/value pairs and returns a list of adjacent key pairs.
67+
*
68+
* @param keyValuePairs Key/value pairs map.
69+
* @public
70+
*/
71+
6472
std::vector<std::tuple<int, int>>
6573
GenerateAdjacentKeyPairs(std::map<int, int> keyValuePairs)
6674
{
@@ -148,6 +156,7 @@ extern "C"
148156
*
149157
* @param tick The tick.
150158
* @param resolution The resolution of the song.
159+
* @public
151160
*/
152161

153162
PACKAGE_API float ConvertTickToPosition(float tick, int resolution)
@@ -160,6 +169,7 @@ extern "C"
160169
*
161170
* @param bpm The base BPM for a song.
162171
* @param currentTime A timestamp to compare to the BPM.
172+
* @public
163173
*/
164174

165175
PACKAGE_API bool IsOnTheBeat(float bpm, float currentTime)
@@ -175,11 +185,29 @@ extern "C"
175185
return result;
176186
}
177187

188+
/**
189+
* Rounds a value up the nearest multiplier.
190+
*
191+
* @param value The value to round.
192+
* @param multiplier The multiplier to round using.
193+
* @public
194+
*/
195+
178196
PACKAGE_API int RoundUpToTheNearestMultiplier(int value, int multiplier)
179197
{
180198
return (int)std::ceil((float)value / multiplier) * multiplier;
181199
}
182200

201+
/**
202+
* Calculated the accuracy ratio of the current position against a static
203+
* position.
204+
*
205+
* @param position The position to test against.
206+
* @param currentPosition The current position.
207+
* @param delta The plus/minus delta to test the current position against.
208+
* @public
209+
*/
210+
183211
PACKAGE_API float CalculateAccuracyRatio(int position, int currentPosition,
184212
int delta = 50)
185213
{

0 commit comments

Comments
 (0)