Skip to content

Commit b901a50

Browse files
authored
Merge pull request #101 from neogeek/hotfix/inline-methods
[hotfix] Set methods to inline to prevent duplicate symbols.
2 parents 252082a + cad6390 commit b901a50

File tree

17 files changed

+266
-141
lines changed

17 files changed

+266
-141
lines changed

RhythmGameUtilities/Scripts/Common.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public static class CommonInternal
77
{
88

99
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
10-
public static extern float Lerp(float a, float b, float t);
10+
public static extern float LerpInternal(float a, float b, float t);
1111

1212
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
13-
public static extern float InverseLerp(float a, float b, float v);
13+
public static extern float InverseLerpInternal(float a, float b, float v);
1414

1515
}
1616

@@ -25,7 +25,7 @@ public static class Common
2525
/// <param name="t">The value used for interpolation.</param>
2626
public static float Lerp(float a, float b, float t)
2727
{
28-
return CommonInternal.Lerp(a, b, t);
28+
return CommonInternal.LerpInternal(a, b, t);
2929
}
3030

3131
/// <summary>
@@ -36,7 +36,7 @@ public static float Lerp(float a, float b, float t)
3636
/// <param name="v">The value in the middle.</param>
3737
public static float InverseLerp(float a, float b, float v)
3838
{
39-
return CommonInternal.InverseLerp(a, b, v);
39+
return CommonInternal.InverseLerpInternal(a, b, v);
4040
}
4141

4242
}

RhythmGameUtilities/Scripts/Utilities.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ internal static class UtilitiesInternal
88
{
99

1010
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
11-
public static extern float ConvertTickToPosition(int tick, int resolution);
11+
public static extern float ConvertTickToPositionInternal(int tick, int resolution);
1212

1313
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
1414
public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, Tempo[] tempoChanges,
1515
int tempoChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize);
1616

1717
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
18-
public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta);
18+
public static extern bool IsOnTheBeatInternal(int bpm, float currentTime, float delta);
1919

2020
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
21-
public static extern int RoundUpToTheNearestMultiplier(int value, int multiplier);
21+
public static extern int RoundUpToTheNearestMultiplierInternal(int value, int multiplier);
2222

2323
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
24-
public static extern float CalculateAccuracyRatio(int position, int currentPosition, int delta);
24+
public static extern float CalculateAccuracyRatioInternal(int position, int currentPosition, int delta);
2525

2626
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
2727
public static extern IntPtr CalculateBeatBarsInternal(Tempo[] tempoChanges, int tempoChangesSize, int resolution,
@@ -42,7 +42,7 @@ public static class Utilities
4242
/// <param name="resolution">The resolution of the song.</param>
4343
public static float ConvertTickToPosition(int tick, int resolution)
4444
{
45-
return UtilitiesInternal.ConvertTickToPosition(tick, resolution);
45+
return UtilitiesInternal.ConvertTickToPositionInternal(tick, resolution);
4646
}
4747

4848
/// <summary>
@@ -67,7 +67,7 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Tempo[] t
6767
/// <param name="delta">The plus/minus delta to test the current time against.</param>
6868
public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
6969
{
70-
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta);
70+
return UtilitiesInternal.IsOnTheBeatInternal(bpm, currentTime, delta);
7171
}
7272

7373
/// <summary>
@@ -77,7 +77,7 @@ public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
7777
/// <param name="multiplier">The multiplier to round using.</param>
7878
public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
7979
{
80-
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
80+
return UtilitiesInternal.RoundUpToTheNearestMultiplierInternal(value, multiplier);
8181
}
8282

8383
public static BeatBar[] CalculateBeatBars(Tempo[] tempoChanges, int resolution = 192, int ts = 4,
@@ -140,7 +140,7 @@ public static BeatBar[] CalculateBeatBars(Tempo[] tempoChanges, int resolution =
140140
/// <param name="delta">The plus/minus delta to test the current position against.</param>
141141
public static float CalculateAccuracyRatio(int position, int currentPosition, int delta = 50)
142142
{
143-
return UtilitiesInternal.CalculateAccuracyRatio(position, currentPosition, delta);
143+
return UtilitiesInternal.CalculateAccuracyRatioInternal(position, currentPosition, delta);
144144
}
145145

146146
}

UnityPackage/Scripts/Common.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public static class CommonInternal
77
{
88

99
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
10-
public static extern float Lerp(float a, float b, float t);
10+
public static extern float LerpInternal(float a, float b, float t);
1111

1212
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
13-
public static extern float InverseLerp(float a, float b, float v);
13+
public static extern float InverseLerpInternal(float a, float b, float v);
1414

1515
}
1616

@@ -25,7 +25,7 @@ public static class Common
2525
/// <param name="t">The value used for interpolation.</param>
2626
public static float Lerp(float a, float b, float t)
2727
{
28-
return CommonInternal.Lerp(a, b, t);
28+
return CommonInternal.LerpInternal(a, b, t);
2929
}
3030

3131
/// <summary>
@@ -36,7 +36,7 @@ public static float Lerp(float a, float b, float t)
3636
/// <param name="v">The value in the middle.</param>
3737
public static float InverseLerp(float a, float b, float v)
3838
{
39-
return CommonInternal.InverseLerp(a, b, v);
39+
return CommonInternal.InverseLerpInternal(a, b, v);
4040
}
4141

4242
}

UnityPackage/Scripts/Utilities.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ internal static class UtilitiesInternal
88
{
99

1010
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
11-
public static extern float ConvertTickToPosition(int tick, int resolution);
11+
public static extern float ConvertTickToPositionInternal(int tick, int resolution);
1212

1313
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
1414
public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, Tempo[] tempoChanges,
1515
int tempoChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize);
1616

1717
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
18-
public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta);
18+
public static extern bool IsOnTheBeatInternal(int bpm, float currentTime, float delta);
1919

2020
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
21-
public static extern int RoundUpToTheNearestMultiplier(int value, int multiplier);
21+
public static extern int RoundUpToTheNearestMultiplierInternal(int value, int multiplier);
2222

2323
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
24-
public static extern float CalculateAccuracyRatio(int position, int currentPosition, int delta);
24+
public static extern float CalculateAccuracyRatioInternal(int position, int currentPosition, int delta);
2525

2626
[DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)]
2727
public static extern IntPtr CalculateBeatBarsInternal(Tempo[] tempoChanges, int tempoChangesSize, int resolution,
@@ -42,7 +42,7 @@ public static class Utilities
4242
/// <param name="resolution">The resolution of the song.</param>
4343
public static float ConvertTickToPosition(int tick, int resolution)
4444
{
45-
return UtilitiesInternal.ConvertTickToPosition(tick, resolution);
45+
return UtilitiesInternal.ConvertTickToPositionInternal(tick, resolution);
4646
}
4747

4848
/// <summary>
@@ -67,7 +67,7 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Tempo[] t
6767
/// <param name="delta">The plus/minus delta to test the current time against.</param>
6868
public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
6969
{
70-
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta);
70+
return UtilitiesInternal.IsOnTheBeatInternal(bpm, currentTime, delta);
7171
}
7272

7373
/// <summary>
@@ -77,7 +77,7 @@ public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
7777
/// <param name="multiplier">The multiplier to round using.</param>
7878
public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
7979
{
80-
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
80+
return UtilitiesInternal.RoundUpToTheNearestMultiplierInternal(value, multiplier);
8181
}
8282

8383
public static BeatBar[] CalculateBeatBars(Tempo[] tempoChanges, int resolution = 192, int ts = 4,
@@ -140,7 +140,7 @@ public static BeatBar[] CalculateBeatBars(Tempo[] tempoChanges, int resolution =
140140
/// <param name="delta">The plus/minus delta to test the current position against.</param>
141141
public static float CalculateAccuracyRatio(int position, int currentPosition, int delta = 50)
142142
{
143-
return UtilitiesInternal.CalculateAccuracyRatio(position, currentPosition, delta);
143+
return UtilitiesInternal.CalculateAccuracyRatioInternal(position, currentPosition, delta);
144144
}
145145

146146
}

include/RhythmGameUtilities/Common.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C"
5151
* @private
5252
*/
5353

54-
std::string Trim(const char *contents)
54+
inline std::string Trim(const char *contents)
5555
{
5656
return std::regex_replace(contents, std::regex("^\\s+|\\s+$"), "");
5757
}
@@ -64,7 +64,8 @@ std::string Trim(const char *contents)
6464
* @private
6565
*/
6666

67-
std::vector<std::string> Split(const char *contents, const char delimiter)
67+
inline std::vector<std::string> Split(const char *contents,
68+
const char delimiter)
6869
{
6970
auto parts = std::vector<std::string>();
7071

@@ -80,8 +81,8 @@ std::vector<std::string> Split(const char *contents, const char delimiter)
8081
return parts;
8182
}
8283

83-
std::vector<std::string> FindAllMatches(const char *contents,
84-
std::regex pattern)
84+
inline std::vector<std::string> FindAllMatches(const char *contents,
85+
std::regex pattern)
8586
{
8687
auto currentMatch =
8788
std::cregex_iterator(contents, contents + strlen(contents), pattern);
@@ -101,8 +102,8 @@ std::vector<std::string> FindAllMatches(const char *contents,
101102
return matches;
102103
}
103104

104-
std::vector<std::string> FindMatchGroups(const char *contents,
105-
std::regex pattern)
105+
inline std::vector<std::string> FindMatchGroups(const char *contents,
106+
std::regex pattern)
106107
{
107108
auto currentMatch =
108109
std::cregex_iterator(contents, contents + strlen(contents), pattern);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "Common.hpp"
4+
5+
#ifdef _WIN32
6+
#define PACKAGE_API __declspec(dllexport)
7+
#else
8+
#define PACKAGE_API
9+
#endif
10+
11+
namespace RhythmGameUtilities
12+
{
13+
14+
extern "C"
15+
{
16+
PACKAGE_API float LerpInternal(float a, float b, float t)
17+
{
18+
return Lerp(a, b, t);
19+
}
20+
21+
PACKAGE_API float InverseLerpInternal(float a, float b, float v)
22+
{
23+
return InverseLerp(a, b, v);
24+
}
25+
}
26+
27+
} // namespace RhythmGameUtilities

include/RhythmGameUtilities/Enums/Difficulty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef enum Difficulty
2222

2323
} DifficultyType;
2424

25-
std::string ToString(Difficulty difficulty)
25+
inline std::string ToString(Difficulty difficulty)
2626
{
2727
switch (difficulty)
2828
{

include/RhythmGameUtilities/Enums/NamedSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef enum NamedSection
1717
Events
1818
} NamedSectionType;
1919

20-
std::string ToString(NamedSection namedSection)
20+
inline std::string ToString(NamedSection namedSection)
2121
{
2222
switch (namedSection)
2323
{

include/RhythmGameUtilities/Enums/TypeCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef enum TypeCode
2222

2323
} TypeCodeType;
2424

25-
std::string ToString(TypeCode typeCode)
25+
inline std::string ToString(TypeCode typeCode)
2626
{
2727
switch (typeCode)
2828
{

include/RhythmGameUtilities/File.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace RhythmGameUtilities
1616
* @public
1717
*/
1818

19-
std::vector<uint8_t> ReadBytesFromFile(const char *path)
19+
inline std::vector<uint8_t> ReadBytesFromFile(const char *path)
2020
{
2121
std::ifstream file(path, std::ios::binary | std::ios::ate);
2222

@@ -43,7 +43,7 @@ std::vector<uint8_t> ReadBytesFromFile(const char *path)
4343
* @public
4444
*/
4545

46-
std::string ReadStringFromFile(const char *path)
46+
inline std::string ReadStringFromFile(const char *path)
4747
{
4848
std::ifstream file(path);
4949

0 commit comments

Comments
 (0)