Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions includes/RhythmGameUtilities/Parsers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +91,4 @@ std::vector<ChartSection> ParseSectionsFromChart(const char *contents)
return sections;
}

extern "C"
{
PACKAGE_API
ChartSectionInternal *ParseSectionsFromChartInternal(const char *contents,
int *outSize)
{
auto internalSections = ParseSectionsFromChart(contents);

*outSize = internalSections.size();

auto sections = (ChartSectionInternal *)malloc(
internalSections.size() * sizeof(ChartSectionInternal));

for (auto i = 0; i < internalSections.size(); i += 1)
{
sections[i].name =
(char *)malloc(strlen(internalSections[i].name.c_str()) + 1);
strcpy(sections[i].name, internalSections[i].name.c_str());

sections[i].lines = (KeyValuePairInternal *)malloc(
internalSections[i].lines.size() *
sizeof(KeyValuePairInternal));

sections[i].lineCount = internalSections[i].lines.size();

for (auto j = 0; j < internalSections[i].lines.size(); j += 1)
{
sections[i].lines[j].key = (char *)malloc(
strlen(internalSections[i].lines[j].first.c_str()) + 1);
strcpy(sections[i].lines[j].key,
internalSections[i].lines[j].first.c_str());

auto values = internalSections[i].lines[j].second;

for (auto k = 0; k < values.size(); k += 1)
{
sections[i].lines[j].values[k] =
(char *)malloc(strlen(values[k].c_str()) + 1);
strcpy(sections[i].lines[j].values[k], values[k].c_str());
}

sections[i].lines[j].valueCount = values.size();
}
}

return sections;
}
}

} // namespace RhythmGameUtilities
64 changes: 64 additions & 0 deletions includes/RhythmGameUtilities/ParsersInternal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include "Parsers.hpp"
#include "Utilities.hpp"

#ifdef _WIN32
#define PACKAGE_API __declspec(dllexport)
#else
#define PACKAGE_API
#endif

namespace RhythmGameUtilities
{

extern "C"
{
PACKAGE_API
ChartSectionInternal *ParseSectionsFromChartInternal(const char *contents,
int *outSize)
{
auto internalSections = ParseSectionsFromChart(contents);

*outSize = internalSections.size();

auto sections = (ChartSectionInternal *)malloc(
internalSections.size() * sizeof(ChartSectionInternal));

for (auto i = 0; i < internalSections.size(); i += 1)
{
sections[i].name =
(char *)malloc(strlen(internalSections[i].name.c_str()) + 1);
strcpy(sections[i].name, internalSections[i].name.c_str());

sections[i].lines = (KeyValuePairInternal *)malloc(
internalSections[i].lines.size() *
sizeof(KeyValuePairInternal));

sections[i].lineCount = internalSections[i].lines.size();

for (auto j = 0; j < internalSections[i].lines.size(); j += 1)
{
sections[i].lines[j].key = (char *)malloc(
strlen(internalSections[i].lines[j].first.c_str()) + 1);
strcpy(sections[i].lines[j].key,
internalSections[i].lines[j].first.c_str());

auto values = internalSections[i].lines[j].second;

for (auto k = 0; k < values.size(); k += 1)
{
sections[i].lines[j].values[k] =
(char *)malloc(strlen(values[k].c_str()) + 1);
strcpy(sections[i].lines[j].values[k], values[k].c_str());
}

sections[i].lines[j].valueCount = values.size();
}
}

return sections;
}
}

} // namespace RhythmGameUtilities
2 changes: 2 additions & 0 deletions includes/RhythmGameUtilities/RhythmGameUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

#include "Audio.hpp"
#include "Parsers.hpp"
#include "ParsersInternal.hpp"
#include "Utilities.hpp"
#include "UtilitiesInternal.hpp"
43 changes: 0 additions & 43 deletions includes/RhythmGameUtilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,6 @@ extern "C"
return tick / resolution;
}

PACKAGE_API int ConvertSecondsToTicksInternal(float seconds, int resolution,
int *bpmChangesKeys,
int *bpmChangesValues,
int bpmChangesSize)
{
std::map<int, int> bpmChanges;

for (auto i = 0; i < bpmChangesSize; i += 1)
{
bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i];
}

return ConvertSecondsToTicks(seconds, resolution, bpmChanges);
}

PACKAGE_API bool IsOnTheBeat(float bpm, float currentTime)
{
auto beatInterval = SECONDS_PER_MINUTE / bpm;
Expand Down Expand Up @@ -154,34 +139,6 @@ extern "C"
{
return std::clamp(((v - a) / (b - a)), 0.0f, 1.0f);
}

PACKAGE_API BeatBar *
CalculateBeatBarsInternal(int *bpmChangesKeys, int *bpmChangesValues,
int bpmChangesSize, int resolution, int ts,
bool includeHalfNotes, int *outSize)
{
auto bpmChanges = std::map<int, int>();

for (auto i = 0; i < bpmChangesSize; i += 1)
{
bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i];
}

auto internalBeatBars =
CalculateBeatBars(bpmChanges, resolution, ts, includeHalfNotes);

*outSize = internalBeatBars.size();

auto beatBars =
(BeatBar *)malloc(internalBeatBars.size() * sizeof(BeatBar));

for (auto i = 0; i < internalBeatBars.size(); i += 1)
{
beatBars[i] = internalBeatBars[i];
}

return beatBars;
}
}

std::string Trim(const char *contents)
Expand Down
64 changes: 64 additions & 0 deletions includes/RhythmGameUtilities/UtilitiesInternal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include <map>

#include "Structs/BeatBar.h"

#include "Utilities.hpp"

#ifdef _WIN32
#define PACKAGE_API __declspec(dllexport)
#else
#define PACKAGE_API
#endif

namespace RhythmGameUtilities
{

extern "C"
{
PACKAGE_API int ConvertSecondsToTicksInternal(float seconds, int resolution,
int *bpmChangesKeys,
int *bpmChangesValues,
int bpmChangesSize)
{
std::map<int, int> bpmChanges;

for (auto i = 0; i < bpmChangesSize; i += 1)
{
bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i];
}

return ConvertSecondsToTicks(seconds, resolution, bpmChanges);
}

PACKAGE_API BeatBar *
CalculateBeatBarsInternal(int *bpmChangesKeys, int *bpmChangesValues,
int bpmChangesSize, int resolution, int ts,
bool includeHalfNotes, int *outSize)
{
auto bpmChanges = std::map<int, int>();

for (auto i = 0; i < bpmChangesSize; i += 1)
{
bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i];
}

auto internalBeatBars =
CalculateBeatBars(bpmChanges, resolution, ts, includeHalfNotes);

*outSize = internalBeatBars.size();

auto beatBars =
(BeatBar *)malloc(internalBeatBars.size() * sizeof(BeatBar));

for (auto i = 0; i < internalBeatBars.size(); i += 1)
{
beatBars[i] = internalBeatBars[i];
}

return beatBars;
}
}

} // namespace RhythmGameUtilities
44 changes: 0 additions & 44 deletions tests/RhythmGameUtilities/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,54 +104,10 @@ void testParseValuesFromChartSections()
std::cout << ".";
}

void testParseSectionsFromChartInternal()
{
int size = 0;

auto sections = ParseSectionsFromChartInternal(contents, &size);

assert(size == 4);

assert(strcmp(sections[0].name, "Song") == 0);
assert(sections[0].lineCount == 12);
assert(strcmp(sections[1].name, "SyncTrack") == 0);
assert(sections[1].lineCount == 11);
assert(strcmp(sections[2].name, "Events") == 0);
assert(sections[2].lineCount == 16);
assert(strcmp(sections[3].name, "ExpertSingle") == 0);
assert(sections[3].lineCount == 11);

std::cout << ".";
}

void testParseValuesFromChartSectionsInternal()
{
int size = 0;

auto sections = ParseSectionsFromChartInternal(contents, &size);

assert(size == 4);

assert(sections[0].lineCount == 12);

assert(strcmp(sections[0].lines[0].key, "Name") == 0);
assert(strcmp(sections[0].lines[0].values[0], "Example Song") == 0);

assert(strcmp(sections[0].lines[6].key, "Resolution") == 0);
assert(strcmp(sections[0].lines[6].values[0], "192") == 0);

assert(strcmp(sections[0].lines[11].key, "MusicStream") == 0);
assert(strcmp(sections[0].lines[11].values[0], "Example Song.ogg") == 0);

std::cout << ".";
}

int main()
{
testParseSectionsFromChart();
testParseValuesFromChartSections();
testParseSectionsFromChartInternal();
testParseValuesFromChartSectionsInternal();

return 0;
}
Loading