Skip to content

Commit

Permalink
Bugfixing and the like.
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoru committed Feb 18, 2014
1 parent 8657137 commit 7df4bdb
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 16 deletions.
40 changes: 39 additions & 1 deletion src/GameWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ const char* fragShader = "#version 120\n"
std::map<int32, KeyType> BindingsManager::ScanFunction;
std::map<int32, KeyType> BindingsManager::ScanFunction7K;

struct sk_s
{
const char* keystring;
int boundkey;
};

sk_s SpecialKeys [] = // only add if someone actually needs more
{
{"LShift", GLFW_KEY_LEFT_SHIFT},
{"RShift", GLFW_KEY_RIGHT_SHIFT},
{"Enter", GLFW_KEY_ENTER},
{"LCtrl", GLFW_KEY_LEFT_CONTROL},
{"RCtrl", GLFW_KEY_RIGHT_CONTROL},
{"LAlt", GLFW_KEY_LEFT_ALT},
{"RAlt", GLFW_KEY_RIGHT_ALT},
{"Tab", GLFW_KEY_TAB},
{"BSPC", GLFW_KEY_BACKSPACE}
};

int KeyTranslate(String K)
{
for (int i = 0; i < (sizeof(SpecialKeys) / sizeof(sk_s)); i++)
{
if (K == SpecialKeys[i].keystring)
return SpecialKeys[i].boundkey;
}

if (K.length())
{
if (Utility::IsNumeric(K.c_str()))
return atoi(K.c_str());
else
return (int)K[0];
}
else
return 0;
}

void BindingsManager::Initialize()
{
ScanFunction[GLFW_KEY_ESCAPE] = KT_Escape;
Expand Down Expand Up @@ -102,7 +140,7 @@ void BindingsManager::Initialize()
char KString[256];
sprintf(KString, "Key%d", i+1);

char Binding = Configuration::GetConfigs(KString, "Keys7K").c_str()[0];
int Binding = KeyTranslate(Configuration::GetConfigs(KString, "Keys7K"));

if (Binding)
ScanFunction7K[Binding] = (KeyType)(KT_Key1 + i);
Expand Down
119 changes: 105 additions & 14 deletions src/NoteLoaderOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
typedef SongInternal::TDifficulty<TrackNote> *SongDiff;
typedef std::vector<String> SplitResult;

// void prototype (String line, Song7K *Out, SongDiff Difficulty)
/* osu!mania loader. credits to wanwan159, woc2006, Zorori and the author of AIBat for helping me understand this. */

bool ReadGeneral (String line, Song7K *Out, SongDiff Difficulty)
{
Expand All @@ -24,7 +24,10 @@ bool ReadGeneral (String line, Song7K *Out, SongDiff Difficulty)
if (Command == "AudioFilename:")
{
if (Content == "virtual") // Virtual mode not yet supported.
{
printf("o!m loader warning: virtual mode is not supported yet\n");
return false;
}
else
{
Out->SongFilename = Out->SongDirectory + "/" + Content;
Expand Down Expand Up @@ -68,6 +71,7 @@ void ReadDifficulty (String line, Song7K *Out, SongDiff Difficulty)

for (int i = 0; i < Difficulty->Channels; i++) // Push a single measure
Difficulty->Measures[i].push_back(SongInternal::Measure<TrackNote>());

}else if (Command == "SliderMultiplier")
{
Out->SliderVelocity = atof(Content.c_str()) * 100;
Expand Down Expand Up @@ -116,51 +120,127 @@ void ReadTiming (String line, Song7K *Out, SongDiff Difficulty)
int GetInterval(float Position, int Channels)
{
float Step = 512.0 / Channels;
float A = 0, B = 0;
int It = 0;

while (It < Channels)
return (int)(Position / Step);
}

String GetSampleFilename(SplitResult &Spl, String NoteType, int Hitsound)
{
int SampleSet, SampleSetAddition, CustomSample, Volume;
String SampleFilename;

if (NoteType == "128")
{
if (Spl[5].length())
return Spl[5];

SampleSet = atoi(Spl[1].c_str());
SampleSetAddition = atoi(Spl[2].c_str());
CustomSample = atoi(Spl[3].c_str());

Volume = atoi(Spl[4].c_str()); // ignored lol

}else if (NoteType == "1")
{
if (Spl[4].length())
return Spl[4];

SampleSet = atoi(Spl[0].c_str());
SampleSetAddition = atoi(Spl[1].c_str());
CustomSample = atoi(Spl[2].c_str());

Volume = atoi(Spl[3].c_str()); // ignored

}else if (NoteType == "2")
{
SampleSet = SampleSetAddition = CustomSample = 0;
}

String SampleSetString;

if (SampleSet)
{
// translate sampleset int into samplesetstring
}else
{
// get sampleset string from sampleset active at starttime
}

String CustomSampleString;

if (CustomSample)
{
char dst[16];
itoa(CustomSample, dst, 10);
CustomSampleString = dst;
}

String HitsoundString;

if (Hitsound)
{
A = B;
B = (It + 1) * Step;
switch (Hitsound)
{
case 1:
HitsoundString = "normal";
case 2:
HitsoundString = "whistle";
case 4:
HitsoundString = "finish";
case 8:
HitsoundString = "clap";
default:
break;
}
}else
return "";

if (Position > A && Position < B)
return It;
if (HitsoundString.length())
{

It++;
}

return 0;
return SampleFilename;
}

#define NOTE_SLIDER 2
#define NOTE_HOLD 128
#define NOTE_NORMAL 1

void ReadObjects (String line, Song7K *Out, SongDiff Difficulty)
{
// Ignoring holds for now for easier reading.
SplitResult Spl;
boost::split(Spl, line, boost::is_any_of(","));

int Track = GetInterval(atof(Spl[0].c_str()), Difficulty->Channels);
int Hitsound;
TrackNote Note;
Note.AssignTrack(Track);

SplitResult Spl2;
boost::split(Spl2, Spl[5], boost::is_any_of(":"));
float startTime = atof(Spl[2].c_str()) / 1000.0;
int NoteType = atoi(Spl[3].c_str());

if (Spl[3] == "128")
if (NoteType & NOTE_HOLD)
{
float endTime = atof(Spl2[0].c_str()) / 1000.0;

if (startTime > endTime)
printf("o!m loader warning: object at track %d has startTime > endTime (%f and %f)\n", Track, startTime, endTime);

Note.AssignTime( startTime, endTime );

Difficulty->TotalScoringObjects += 2;
Difficulty->TotalHolds++;
}else if (Spl[3] == "1")
}else if (NoteType & NOTE_NORMAL)
{
Note.AssignTime( startTime );
Difficulty->TotalNotes++;
Difficulty->TotalScoringObjects++;
}else if (Spl[3] == "2")

}else if (NoteType & NOTE_SLIDER)
{
// 6=repeats 7=length
float sliderRepeats = atof(Spl[6].c_str());
Expand All @@ -170,12 +250,17 @@ void ReadObjects (String line, Song7K *Out, SongDiff Difficulty)
float bpm = (60000.0 / BpmAtBeat(Difficulty->Timing, startTime));
float finalLength = beatDuration * spb(bpm);

if (startTime > finalLength + startTime)
printf("o!m loader warning: object at track %d has startTime > endTime (%f and %f)\n", Track, startTime, finalLength + startTime);

Note.AssignTime( startTime, finalLength + startTime );

Difficulty->TotalScoringObjects += 2;
Difficulty->TotalHolds++;
}

Hitsound = atoi(Spl[4].c_str());

Difficulty->TotalObjects++;
Difficulty->Measures[Track].at(0).MeasureNotes.push_back(Note);

Expand All @@ -199,6 +284,7 @@ void NoteLoaderOM::LoadObjectsFromFile(String filename, String prefix, Song7K *O

Out->SongDirectory = prefix;
Difficulty->TotalNotes = Difficulty->TotalHolds = Difficulty->TotalObjects = Difficulty->TotalScoringObjects = 0;
Difficulty->Duration = 0;

/*
Just like BMS, osu!mania charts have timing data separated by files
Expand Down Expand Up @@ -255,7 +341,12 @@ void NoteLoaderOM::LoadObjectsFromFile(String filename, String prefix, Song7K *O

switch (ReadingMode)
{
case RGeneral: ReadGeneral(Line, Out, Difficulty); break;
case RGeneral: if (!ReadGeneral(Line, Out, Difficulty)) // don't load charts that we can't work with
{
delete Difficulty;
return;
}
break;
case RMetadata: ReadMetadata(Line, Out, Difficulty); break;
case RDifficulty: ReadDifficulty(Line, Out, Difficulty); break;
case REvents: ReadEvents(Line, Out, Difficulty); break;
Expand Down
2 changes: 1 addition & 1 deletion src/ScreenGameplay7K.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ bool ScreenGameplay7K::Run(double Delta)
{
std::stringstream ss;
ss << lastClosest[i];
GFont->DisplayText(ss.str().c_str(), Keys[i].GetPosition() - Vec2(DigitCount(lastClosest[i]) * 3 / 2, 7));
GFont->DisplayText(ss.str().c_str(), Keys[i].GetPosition() - Vec2(DigitCount(lastClosest[i]) * 3, 7));
}

Animations->DrawFromLayer(14);
Expand Down

0 comments on commit 7df4bdb

Please sign in to comment.