Skip to content

Commit

Permalink
Rip OpenMP from SM, use C++11 instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwidghet committed Jan 23, 2017
1 parent de405af commit 5a1a217
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
8 changes: 0 additions & 8 deletions StepmaniaCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Enable OpenMP
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

# Set up the linker flags for MSVC builds.
configure_msvc_runtime()

Expand Down
71 changes: 39 additions & 32 deletions src/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "NotesLoaderBMS.h"
#include <algorithm>
#include "MinaCalc.h"
#include <thread>

/* register DisplayBPM with StringConversion */
#include "EnumHelper.h"
Expand Down Expand Up @@ -481,49 +482,55 @@ RString Steps::GenerateChartKey(NoteData& nd, TimingData *td)
{
RString k = "";
RString o = "";
float bpm;
vector<int>& nerv = nd.GetNonEmptyRowVector();

unsigned int numThreads = max(std::thread::hardware_concurrency(), 1u);
std::vector<RString> keyParts;
keyParts.reserve(numThreads);

size_t segmentSize = nerv.size() / numThreads;
std::vector<std::thread> threads;
threads.reserve(numThreads);

for (unsigned int curThread = 0; curThread < numThreads; curThread++)
{
keyParts.push_back("");
size_t start = segmentSize * curThread;
size_t end = start + segmentSize;
if (curThread + 1 == numThreads)
end = nerv.size();

threads.push_back(std::thread(&Steps::FillStringWithBPMs, this, start, end, std::ref(nerv), std::ref(nd), td, std::ref(keyParts[curThread])));
}

RString firstHalf = "";
RString secondHalf = "";

#pragma omp parallel sections
for (auto& t : threads)
{
#pragma omp section
{
for (size_t r = 0; r < nerv.size() / 2; r++) {
int row = nerv[r];
for (int t = 0; t < nd.GetNumTracks(); ++t) {
const TapNote &tn = nd.GetTapNote(t, row);
firstHalf.append(to_string(tn.type));
}
bpm = td->GetBPMAtRow(row);
firstHalf.append(to_string(static_cast<int>(bpm + 0.374643f)));
}
}

#pragma omp section
{
for (size_t r = nerv.size() / 2; r < nerv.size(); r++) {
int row = nerv[r];
for (int t = 0; t < nd.GetNumTracks(); ++t) {
const TapNote &tn = nd.GetTapNote(t, row);
secondHalf.append(to_string(tn.type));
}
bpm = td->GetBPMAtRow(row);
secondHalf.append(to_string(static_cast<int>(bpm + 0.374643f)));
}
}
if(t.joinable())
t.join();
}
k = firstHalf + secondHalf;

//ChartKeyRecord = k;
for(size_t i = 0; i < numThreads; i++)
k += keyParts[i];

o.append("X"); // I was thinking of using "C" to indicate chart.. however.. X is cooler... - Mina
o.append(BinaryToHex(CryptManager::GetSHA1ForString(k)));
return o;
}

void Steps::FillStringWithBPMs(size_t startRow, size_t endRow, vector<int>& nerv, NoteData& nd, TimingData *td, RString& inOut)
{
float bpm = 0.f;
for (size_t r = startRow; r < endRow; r++) {
int row = nerv[r];
for (int t = 0; t < nd.GetNumTracks(); ++t) {
const TapNote& tn = nd.GetTapNote(t, row);
inOut.append(to_string(tn.type));
}
bpm = td->GetBPMAtRow(row);
inOut.append(to_string(static_cast<int>(bpm + 0.374643f)));
}
}

int Steps::GetNPSVector(NoteData nd, vector<float>& etar)
{
vector<vector<int>> doot;
Expand Down
3 changes: 3 additions & 0 deletions src/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ class Steps
using the notedata stored in game memory immediately after reading it than parsing it using lua. - Mina */
RString GenerateChartKey(NoteData& nd, TimingData *td);

/* Append all of the bpms in the given range to the input string */
void FillStringWithBPMs(size_t startRow, size_t endRow, vector<int>& nerv, NoteData& nd, TimingData *td, RString& inOut);

/**
* @brief Determine if the Steps have any major timing changes during gameplay.
* @return true if it does, or false otherwise. */
Expand Down

0 comments on commit 5a1a217

Please sign in to comment.