Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
make a litle bit better
Browse files Browse the repository at this point in the history
  • Loading branch information
ouoam committed Nov 19, 2018
1 parent 96070d9 commit 3c9b3ab
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Oshu/Beatmap/Beatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace Beatmap {

int bmHitObjects::TimePreempt = 600;
int bmHitObjects::TimeFadeIn = 400;
double bmHitObjects::TimePreempt = 600;
double bmHitObjects::TimeFadeIn = 400;
int bmHitObjects::CR = 5;

void Beatmap::load(std::string file, bool calcCurve) {
Expand Down
4 changes: 2 additions & 2 deletions Oshu/Beatmap/Beatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ namespace Beatmap {

int endTime;

static int TimePreempt;
static int TimeFadeIn;
static double TimePreempt;
static double TimeFadeIn;
static int CR;
};

Expand Down
16 changes: 16 additions & 0 deletions Oshu/Beatmap/Difficulty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

namespace Beatmap {

class Difficulty {
public:
static double Range(double difficulty, double min, double mid, double max) {
if (difficulty > 5)
return mid + (max - mid) * (difficulty - 5.0) / 5.0;
if (difficulty < 5)
return mid - (mid - min) * (5.0 - difficulty) / 5.0;
return mid;
}
};

}
8 changes: 4 additions & 4 deletions Oshu/Object/Circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class Circle : public ContainerHitObject {

void onMouseClick(uint8_t key) {
approach.fadeTo(1).fadeTo(0, 50).then().expire();
circle.fadeTo(0, 400).scaleTo(1)
.scaleTo(1.5f, 200, Object::Animate::Easing::OutQuad).then().expire();
circleOverlay.fadeTo(0, 400).scaleTo(1)
.scaleTo(1.5f, 200, Object::Animate::Easing::OutQuad).then().expire();
circle.fadeTo(0, 500).scaleTo(1)
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad).then().expire();
circleOverlay.fadeTo(0, 500).scaleTo(1)
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad).then().expire();
canClick = false;
}

Expand Down
60 changes: 60 additions & 0 deletions Oshu/Object/HitWindows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include <cmath>
#include "../Beatmap/Difficulty.h"
#include "../Scoring/HitResult.h"

using namespace Scoring;
using namespace Beatmap;

namespace Object {

class HitWindows {
protected:
double Great;
double Good;
double Meh;
double Miss;

public:
void SetDifficulty(double difficulty) {
Great = Difficulty::Range(difficulty, 160, 100, 40);
Good = Difficulty::Range(difficulty, 280, 200, 120);
Meh = Difficulty::Range(difficulty, 400, 300, 200);
Miss = Difficulty::Range(difficulty, 400, 400, 400);
}

HitResult ResultFor(double timeOffset) {
timeOffset = std::abs(timeOffset);

if (timeOffset <= HalfWindowFor(HitResult::Great))
return HitResult::Great;
if (timeOffset <= HalfWindowFor(HitResult::Good))
return HitResult::Good;
if (timeOffset <= HalfWindowFor(HitResult::Meh))
return HitResult::Meh;
if (timeOffset <= HalfWindowFor(HitResult::Miss))
return HitResult::Miss;

return HitResult::None;
}

double HalfWindowFor(HitResult result) {
switch (result) {
case HitResult::Great:
return Great / 2;
case HitResult::Good:
return Good / 2;
case HitResult::Meh:
return Meh / 2;
case HitResult::Miss:
return Miss / 2;
}
}

bool CanBeHit(double timeOffset) {
return timeOffset <= HalfWindowFor(HitResult::Meh);
}
};

}
4 changes: 4 additions & 0 deletions Oshu/Oshu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,25 @@
<ItemGroup>
<ClInclude Include="Audio\hitsound.h" />
<ClInclude Include="Beatmap\Beatmap.h" />
<ClInclude Include="Beatmap\Difficulty.h" />
<ClInclude Include="DB\beatmap.h" />
<ClInclude Include="DB\DB.h" />
<ClInclude Include="Object\Animate\Animate.h" />
<ClInclude Include="Object\Animate\Easing.h" />
<ClInclude Include="Object\Circle.h" />
<ClInclude Include="Object\Cursor.h" />
<ClInclude Include="Object\Container.h" />
<ClInclude Include="Object\HitWindows.h" />
<ClInclude Include="Object\Pieces.h" />
<ClInclude Include="Object\Slider.h" />
<ClInclude Include="Overlay\hitwindows.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Scoring\HitResult.h" />
<ClInclude Include="Skin\Skin.h" />
<ClInclude Include="UI\Playfield.h" />
<ClInclude Include="UI\Select.h" />
<ClInclude Include="UI\Select\selectSong.h" />
<ClInclude Include="UI\testtest.h" />
<ClInclude Include="UI\testZone.h" />
<ClInclude Include="UI\UI.h" />
<ClInclude Include="Utility\BezierApproximator.h" />
Expand Down
15 changes: 15 additions & 0 deletions Oshu/Oshu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<Filter Include="Header Files\UI\Select">
<UniqueIdentifier>{a730f5b1-dfe3-4b19-a3f9-8ec2db582e00}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Scoring">
<UniqueIdentifier>{875bd6df-6a11-40b5-86a1-793d4b286087}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down Expand Up @@ -140,6 +143,18 @@
<ClInclude Include="UI\Select\selectSong.h">
<Filter>Header Files\UI\Select</Filter>
</ClInclude>
<ClInclude Include="UI\testtest.h">
<Filter>Header Files\UI</Filter>
</ClInclude>
<ClInclude Include="Beatmap\Difficulty.h">
<Filter>Header Files\Beatmap</Filter>
</ClInclude>
<ClInclude Include="Object\HitWindows.h">
<Filter>Header Files\Object</Filter>
</ClInclude>
<ClInclude Include="Scoring\HitResult.h">
<Filter>Header Files\Scoring</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc">
Expand Down
14 changes: 14 additions & 0 deletions Oshu/Scoring/HitResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Scoring {

enum HitResult {
None,
Miss,
Meh,
Good,
Great,
Perfect
};

}
42 changes: 35 additions & 7 deletions Oshu/UI/Select.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SelectUI : public UI {
sf::Texture backgroundTexture;

int selectSong = -1;
int selectSongId = -1;
std::vector<std::unordered_map<std::string, std::string>*> *beatmapSetData;
myMutex beatmapSetDataMutex;

Expand Down Expand Up @@ -90,12 +91,13 @@ class SelectUI : public UI {
void selectNewSongs(int newSong) {
if (selectSong != newSong) {
selectSong = newSong;

updateText = true;

int beatmapID = stoi((*((*searchData)[newSong]))["id"]);
selectSongId = stoi((*((*searchData)[newSong]))["id"]);

beatmapSetDataMutex.lock();
beatmapSetData = songDB.getBeatmapSet(beatmapID);
beatmapSetData = songDB.getBeatmapSet(selectSongId);
beatmapSetDataMutex.unlock();

for (auto v : *beatmapSetData) {
Expand Down Expand Up @@ -266,14 +268,40 @@ class SelectUI : public UI {
std::cout << "Use time : " << aa.getElapsedTime().asMilliseconds() << " ms." << std::endl;

updateText = true;
if (showDataCenter > (*searchData).size() - 1) showDataCenter = (*searchData).size() - 1;


if (selectSong == -1) {
randomSongs();
} else {
float oldTextCenterOffset = selectSong - showDataCenter;

int i = 0;

for (std::unordered_map<std::string, std::string>* row : *searchData) {
if (std::stoi((*row)["id"]) == selectSongId) {
selectSong = i;
if (selectSong == -2) {
showDataCenter = selectSong;
}
else {
showDataCenter = selectSong - oldTextCenterOffset;
}

break;
}
i++;
}

if (i == (*searchData).size()) {
std::cout << "Not Found" << std::endl;
selectSong = -2;
}
}
if (showDataCenter < 0) showDataCenter = 0;
else if (showDataCenter > (*searchData).size() - 1) showDataCenter = (*searchData).size() - 1;
}
}

if (selectSong == -1) {
randomSongs();
}

if (updateTextMutex.tryLock()) {
updateTextMutex.unlock();
if (updateText) {
Expand Down
21 changes: 9 additions & 12 deletions Oshu/UI/testZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sfeMovie/Movie.hpp>

#include "../Beatmap/Beatmap.h"
#include "../Beatmap/Difficulty.h"
#include "../Audio/hitsound.h"
#include "../Object/Container.h"
#include "../Object/Cursor.h"
Expand Down Expand Up @@ -42,7 +43,7 @@ class testUI : public UI {
int dist = 0;

struct {
int s50, s100, s300;
double s50, s100, s300;
} hitWinWidth;

struct {
Expand Down Expand Up @@ -103,21 +104,17 @@ class testUI : public UI {

loadHitSound(&bmPlay, base_dir);

hitWinWidth.s50 = 150 - 50 * (5 - bmPlay.Difficulty.OverallDifficulty) / 5;
hitWinWidth.s100 = 100 - 40 * (5 - bmPlay.Difficulty.OverallDifficulty) / 5;
hitWinWidth.s300 = 50 - 30 * (5 - bmPlay.Difficulty.OverallDifficulty) / 5;
hitWinWidth.s50 = Beatmap::Difficulty::Range(bmPlay.Difficulty.OverallDifficulty, 400, 300, 200);
hitWinWidth.s100 = Beatmap::Difficulty::Range(bmPlay.Difficulty.OverallDifficulty, 280, 200, 120);
hitWinWidth.s300 = Beatmap::Difficulty::Range(bmPlay.Difficulty.OverallDifficulty, 160, 100, 40);

std::cout << hitWinWidth.s50 << "\t" << hitWinWidth.s100 << "\t" << hitWinWidth.s300 << std::endl;

// Calc For Hit Object
int AR = bmPlay.Difficulty.ApproachRate;

if (AR < 5) {
Beatmap::bmHitObjects::TimePreempt = 1200 + 600 * (5 - AR) / 5;
Beatmap::bmHitObjects::TimeFadeIn = 800 + 400 * (5 - AR) / 5;
}
else if (AR > 5) {
Beatmap::bmHitObjects::TimePreempt = 1200 - 750 * (AR - 5) / 5;
Beatmap::bmHitObjects::TimeFadeIn = 800 - 500 * (AR - 5) / 5;
}
Beatmap::bmHitObjects::TimePreempt = Beatmap::Difficulty::Range(AR, 1800, 1200, 450);
Beatmap::bmHitObjects::TimeFadeIn = Beatmap::Difficulty::Range(AR, 1200, 800, 300);

Beatmap::bmHitObjects::CR = bmPlay.Difficulty.CircleRadius;
// End Calc For Hit Object
Expand Down
Loading

0 comments on commit 3c9b3ab

Please sign in to comment.