Skip to content

Commit 8f1c86b

Browse files
authored
Merge pull request #105 from neogeek/hotfix/code-cleanup
[hotfix] Code cleanup
2 parents 9cc4217 + bf185ac commit 8f1c86b

25 files changed

+71
-77
lines changed

.clang-tidy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Checks: '-*,clang-analyzer-*,-clang-analyzer-cplusplus*'
1+
Checks: 'performance-*,modernize-*,readability-*,-readability-identifier-length'
2+
CheckOptions:
3+
UnusedIncludes: Strict

.clangd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ CompileFlags:
22
Add:
33
- '-std=c++17'
44
- '-Iinclude'
5+
Diagnostics:
6+
UnusedIncludes: Strict
7+
ClangTidy:
8+
Add: [performance-*, modernize-*, readability-*]
9+
Remove: [readability-identifier-length]

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"name": "Win32",
1414
"includePath": ["${workspaceFolder}/**", "${workspaceFolder}/include"],
1515
"defines": [],
16-
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.40.33617/bin/Hostx64/x64/cl.exe",
16+
"compilerPath": "${env:VCINSTALLDIR}/bin/Hostx64/x64/cl.exe",
1717
"cStandard": "c17",
1818
"cppStandard": "c++17",
1919
"intelliSenseMode": "windows-msvc-x64"

compile_flags.txt

Whitespace-only changes.

include/RhythmGameUtilities/Audio.hpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <algorithm>
34
#include <cmath>
45

56
#ifdef _WIN32
@@ -23,10 +24,10 @@ extern "C"
2324
* @public
2425
*/
2526

26-
PACKAGE_API int **ConvertSamplesToWaveform(float *samples, int size,
27+
PACKAGE_API int **ConvertSamplesToWaveform(const float *samples, int size,
2728
int width, int height)
2829
{
29-
auto waveform = new int *[width];
30+
auto *waveform = new int *[width];
3031

3132
auto step = floor(size / width);
3233
auto amp = height / 2;
@@ -35,24 +36,17 @@ extern "C"
3536
{
3637
waveform[x] = new int[height];
3738

38-
auto min = 1.0f;
39-
auto max = -1.0f;
39+
auto min = 1.0F;
40+
auto max = -1.0F;
4041

4142
for (auto j = 0; j < step; j += 1)
4243
{
43-
auto index = static_cast<int>(x * step + j);
44+
auto index = static_cast<int>((x * step) + j);
4445

4546
auto datum = samples[index];
4647

47-
if (datum < min)
48-
{
49-
min = datum;
50-
}
51-
52-
if (datum > max)
53-
{
54-
max = datum;
55-
}
48+
min = std::min(datum, min);
49+
max = std::max(datum, max);
5650
}
5751

5852
auto minY = static_cast<int>((1 + min) * amp);

include/RhythmGameUtilities/Common.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C"
2626

2727
PACKAGE_API float Lerp(float a, float b, float t)
2828
{
29-
return (1 - t) * a + b * t;
29+
return ((1 - t) * a) + (b * t);
3030
}
3131

3232
/**
@@ -40,7 +40,7 @@ extern "C"
4040

4141
PACKAGE_API float InverseLerp(float a, float b, float v)
4242
{
43-
return std::clamp(((v - a) / (b - a)), 0.0f, 1.0f);
43+
return std::clamp(((v - a) / (b - a)), 0.0F, 1.0F);
4444
}
4545
}
4646

@@ -82,7 +82,7 @@ inline std::vector<std::string> Split(const char *contents,
8282
}
8383

8484
inline std::vector<std::string> FindAllMatches(const char *contents,
85-
std::regex pattern)
85+
const std::regex &pattern)
8686
{
8787
auto currentMatch =
8888
std::cregex_iterator(contents, contents + strlen(contents), pattern);
@@ -103,14 +103,14 @@ inline std::vector<std::string> FindAllMatches(const char *contents,
103103
}
104104

105105
inline std::vector<std::string> FindMatchGroups(const char *contents,
106-
std::regex pattern)
106+
const std::regex &pattern)
107107
{
108108
auto currentMatch =
109109
std::cregex_iterator(contents, contents + strlen(contents), pattern);
110110

111111
auto matches = std::vector<std::string>();
112112

113-
auto match = *currentMatch;
113+
const auto &match = *currentMatch;
114114

115115
for (auto i = 0; i < match.size(); i += 1)
116116
{

include/RhythmGameUtilities/Enums/Difficulty.h renamed to include/RhythmGameUtilities/Enums/Difficulty.hpp

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

88
typedef enum Difficulty
99
{
10-
1110
// Easy Difficulty
1211
Easy,
1312

@@ -19,7 +18,6 @@ typedef enum Difficulty
1918

2019
// Expert Difficulty
2120
Expert
22-
2321
} DifficultyType;
2422

2523
inline std::string ToString(Difficulty difficulty)
File renamed without changes.

include/RhythmGameUtilities/Enums/TypeCode.h renamed to include/RhythmGameUtilities/Enums/TypeCode.hpp

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

88
typedef enum TypeCode
99
{
10-
1110
/// BPM Marker
1211
BPM_Marker,
1312

@@ -19,7 +18,6 @@ typedef enum TypeCode
1918

2019
/// Event Marker
2120
EventMarker
22-
2321
} TypeCodeType;
2422

2523
inline std::string ToString(TypeCode typeCode)

include/RhythmGameUtilities/File.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inline std::vector<uint8_t> ReadBytesFromFile(const char *path)
2222

2323
if (!file.is_open())
2424
{
25-
std::cerr << "Failed to open " << path << "." << std::endl;
25+
std::cerr << "Failed to open " << path << ".\n";
2626
}
2727

2828
auto fileSize = file.tellg();
@@ -49,13 +49,13 @@ inline std::string ReadStringFromFile(const char *path)
4949

5050
if (!file)
5151
{
52-
std::cerr << "Failed to open " << path << "." << std::endl;
52+
std::cerr << "Failed to open " << path << ".\n";
5353

5454
return "";
5555
}
5656

57-
return std::string((std::istreambuf_iterator<char>(file)),
58-
std::istreambuf_iterator<char>());
57+
return {(std::istreambuf_iterator<char>(file)),
58+
std::istreambuf_iterator<char>()};
5959
}
6060

6161
} // namespace RhythmGameUtilities

0 commit comments

Comments
 (0)