-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.cpp
More file actions
82 lines (72 loc) · 2.3 KB
/
chart.cpp
File metadata and controls
82 lines (72 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "chart.h"
#include "score.h"
#include <algorithm>
#include <cmath>
void Chart::sort_notes() {
std::sort(notes.begin(), notes.end(), [](const Note &a, const Note &b) {
if (a.beat != b.beat) return a.beat < b.beat;
return a.lane < b.lane;
});
}
Judge judge_from_abs_dt(double absDt, const HitWindows &w) {
if (absDt <= w.perfect) return Judge::PERFECT;
if (absDt <= w.great) return Judge::GREAT;
if (absDt <= w.good) return Judge::GOOD;
if (absDt <= w.bad) return Judge::BAD;
return Judge::MISS;
}
const char *judge_name(Judge j) {
if (j == Judge::PERFECT) return "PERFECT";
if (j == Judge::GREAT) return "GREAT";
if (j == Judge::GOOD) return "GOOD";
if (j == Judge::BAD) return "BAD";
return "MISS";
}
bool try_hit_lane(Chart &chart, int lane, double songBeat,
const HitWindows &w, ScoreState &score) {
int idx = -1;
for (int i = 0; i < (int)chart.notes.size(); i++) {
auto &n = chart.notes[i];
if (n.lane != lane) continue;
if (n.hit || n.missed) continue;
idx = i;
break;
}
if (idx == -1) return false;
auto &n = chart.notes[idx];
double beatDt = songBeat - n.beat; // >0 поздно, <0 рано
double dt = beatDt * chart.timing.seconds_per_beat();
double absDt = std::abs(dt);
Judge j = judge_from_abs_dt(absDt, w);
if (j == Judge::MISS) {
// не штрафуем за спам далеко от ноты
return false;
}
n.hit = true;
score.apply_hit(j, dt);
return true;
}
void update_auto_miss(Chart &chart, double songBeat,
const HitWindows &w, ScoreState &score) {
for (auto &n : chart.notes) {
if (n.hit || n.missed) continue;
double dt = (songBeat - n.beat) * chart.timing.seconds_per_beat();
if (dt > w.bad) {
n.missed = true;
score.apply_miss_auto();
}
}
}
Chart make_test_chart() {
Chart chart;
chart.timing.bpm = 128.0;
chart.timing.beatsPerBar = 4;
chart.timing.offsetSec = 0.0;
double beat = 4.0; // start from bar 2
for (int i = 0; i < 64; i++) {
chart.notes.push_back({i % 4, beat, false, false});
beat += 1.0; // quarter notes
}
chart.sort_notes();
return chart;
}