osu: finished no_leniency version
This commit is contained in:
@@ -7,7 +7,7 @@ A standalone crate to calculate star ratings and performance points for all [osu
|
|||||||
### Roadmap
|
### Roadmap
|
||||||
- osu sr versions
|
- osu sr versions
|
||||||
- [x] no_sliders_no_leniency (i.e. oppai)
|
- [x] no_sliders_no_leniency (i.e. oppai)
|
||||||
- [ ] no_sliders
|
- [x] no_leniency
|
||||||
- [ ] all included
|
- [ ] all included
|
||||||
- [x] taiko sr
|
- [x] taiko sr
|
||||||
- [x] ctb sr
|
- [x] ctb sr
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub(crate) enum Curve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Curve {
|
impl Curve {
|
||||||
|
#[inline]
|
||||||
pub(crate) fn linear(a: Pos2, b: Pos2) -> Self {
|
pub(crate) fn linear(a: Pos2, b: Pos2) -> Self {
|
||||||
Self::Linear { a, b }
|
Self::Linear { a, b }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ pub(crate) fn point_at_distance(array: &[Pos2], distance: f32) -> Pos2 {
|
|||||||
let mut current_distance = 0.0;
|
let mut current_distance = 0.0;
|
||||||
let mut new_distance = 0.0;
|
let mut new_distance = 0.0;
|
||||||
|
|
||||||
// TODO: Optimize
|
|
||||||
while i < array.len() - 2 {
|
while i < array.len() - 2 {
|
||||||
new_distance = (array[i] - array[i + 1]).length();
|
new_distance = (array[i] - array[i + 1]).length();
|
||||||
current_distance += new_distance;
|
current_distance += new_distance;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub(crate) enum Curve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Curve {
|
impl Curve {
|
||||||
|
#[inline]
|
||||||
pub(crate) fn linear(a: Pos2, b: Pos2) -> Self {
|
pub(crate) fn linear(a: Pos2, b: Pos2) -> Self {
|
||||||
Self::Linear { a, b }
|
Self::Linear { a, b }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ mod versions;
|
|||||||
pub use pp::*;
|
pub use pp::*;
|
||||||
pub use versions::*;
|
pub use versions::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct DifficultyAttributes {
|
pub struct DifficultyAttributes {
|
||||||
pub stars: f32,
|
pub stars: f32,
|
||||||
pub ar: f32,
|
pub ar: f32,
|
||||||
|
|||||||
@@ -21,14 +21,9 @@ pub fn stars(map: &Beatmap, mods: impl Mods) -> DifficultyAttributes {
|
|||||||
|
|
||||||
if map.hit_objects.len() < 2 {
|
if map.hit_objects.len() < 2 {
|
||||||
return DifficultyAttributes {
|
return DifficultyAttributes {
|
||||||
stars: 0.0,
|
|
||||||
ar: attributes.ar,
|
ar: attributes.ar,
|
||||||
od: attributes.od,
|
od: attributes.od,
|
||||||
speed_strain: 0.0,
|
..Default::default()
|
||||||
aim_strain: 0.0,
|
|
||||||
max_combo: 0,
|
|
||||||
n_circles: 0,
|
|
||||||
n_spinners: 0,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
use parse::{Beatmap, DifficultyPoint, TimingPoint};
|
||||||
|
use std::slice::Iter;
|
||||||
|
|
||||||
|
macro_rules! next_tuple {
|
||||||
|
($iter:expr, ($first:ident, $second:ident)) => {
|
||||||
|
$iter.next().map(|e| (e.$first, e.$second))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct ControlPointIter<'p> {
|
||||||
|
timing_points: Iter<'p, TimingPoint>,
|
||||||
|
difficulty_points: Iter<'p, DifficultyPoint>,
|
||||||
|
|
||||||
|
next_timing: Option<(f32, f32)>,
|
||||||
|
next_difficulty: Option<(f32, f32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'p> ControlPointIter<'p> {
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn new(map: &'p Beatmap) -> Self {
|
||||||
|
let mut timing_points = map.timing_points.iter();
|
||||||
|
let mut difficulty_points = map.difficulty_points.iter();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
next_timing: next_tuple!(timing_points, (time, beat_len)),
|
||||||
|
next_difficulty: next_tuple!(difficulty_points, (time, speed_multiplier)),
|
||||||
|
|
||||||
|
timing_points,
|
||||||
|
difficulty_points,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) enum ControlPoint {
|
||||||
|
Timing { time: f32, beat_len: f32 },
|
||||||
|
Difficulty { time: f32, speed_mult: f32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ControlPoint {
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn time(&self) -> f32 {
|
||||||
|
match self {
|
||||||
|
Self::Timing { time, .. } => *time,
|
||||||
|
Self::Difficulty { time, .. } => *time,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'p> Iterator for ControlPointIter<'p> {
|
||||||
|
type Item = ControlPoint;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
match (self.next_timing, self.next_difficulty) {
|
||||||
|
(Some((time, beat_len)), Some((d, _))) if time <= d => {
|
||||||
|
self.next_timing = next_tuple!(self.timing_points, (time, beat_len));
|
||||||
|
|
||||||
|
Some(ControlPoint::Timing { time, beat_len })
|
||||||
|
}
|
||||||
|
(_, Some((time, speed_mult))) => {
|
||||||
|
self.next_difficulty =
|
||||||
|
next_tuple!(self.difficulty_points, (time, speed_multiplier));
|
||||||
|
|
||||||
|
Some(ControlPoint::Difficulty { time, speed_mult })
|
||||||
|
}
|
||||||
|
(Some((time, beat_len)), None) => {
|
||||||
|
self.next_timing = next_tuple!(self.timing_points, (time, beat_len));
|
||||||
|
|
||||||
|
Some(ControlPoint::Timing { time, beat_len })
|
||||||
|
}
|
||||||
|
(None, None) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
use super::OsuObject;
|
use super::OsuObject;
|
||||||
|
|
||||||
const NORMALIZED_RADIUS: f32 = 52.0;
|
pub(crate) struct DifficultyObject<'h> {
|
||||||
|
pub(crate) base: &'h OsuObject,
|
||||||
pub(crate) struct DifficultyObject {
|
|
||||||
pub(crate) base: OsuObject,
|
|
||||||
pub(crate) prev: Option<(f32, f32)>, // (jump_dist, strain_time)
|
pub(crate) prev: Option<(f32, f32)>, // (jump_dist, strain_time)
|
||||||
|
|
||||||
pub(crate) jump_dist: f32,
|
pub(crate) jump_dist: f32,
|
||||||
@@ -14,28 +12,21 @@ pub(crate) struct DifficultyObject {
|
|||||||
pub(crate) strain_time: f32,
|
pub(crate) strain_time: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DifficultyObject {
|
impl<'h> DifficultyObject<'h> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
base: OsuObject,
|
base: &'h OsuObject,
|
||||||
prev: OsuObject,
|
prev: &OsuObject,
|
||||||
prev_diff: Option<DifficultyObject>,
|
prev_vals: Option<(f32, f32)>, // (jump_dist, strain_time)
|
||||||
prev_prev: Option<OsuObject>,
|
prev_prev: Option<OsuObject>,
|
||||||
clock_rate: f32,
|
clock_rate: f32,
|
||||||
radius: f32,
|
scaling_factor: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let delta = (base.time() - prev.time()) / clock_rate;
|
let delta = (base.time - prev.time) / clock_rate;
|
||||||
let strain_time = delta.max(50.0);
|
let strain_time = delta.max(50.0);
|
||||||
|
|
||||||
let mut scaling_factor = NORMALIZED_RADIUS / radius;
|
let pos = base.pos;
|
||||||
|
let travel_dist = prev.travel_dist.unwrap_or(0.0);
|
||||||
if radius < 30.0 {
|
let prev_cursor_pos = prev.end_pos;
|
||||||
let small_circle_bonus = (30.0 - radius).min(5.0) / 50.0;
|
|
||||||
scaling_factor *= 1.0 + small_circle_bonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pos = base.pos();
|
|
||||||
let travel_dist = prev.travel_dist();
|
|
||||||
let prev_cursor_pos = prev.pos();
|
|
||||||
|
|
||||||
let jump_dist = if base.is_spinner() {
|
let jump_dist = if base.is_spinner() {
|
||||||
0.0
|
0.0
|
||||||
@@ -44,7 +35,7 @@ impl DifficultyObject {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let angle = prev_prev.map(|prev_prev| {
|
let angle = prev_prev.map(|prev_prev| {
|
||||||
let prev_prev_cursor_pos = prev_prev.pos();
|
let prev_prev_cursor_pos = prev_prev.end_pos;
|
||||||
|
|
||||||
let v1 = prev_prev_cursor_pos - prev_cursor_pos;
|
let v1 = prev_prev_cursor_pos - prev_cursor_pos;
|
||||||
let v2 = pos - prev_cursor_pos;
|
let v2 = pos - prev_cursor_pos;
|
||||||
@@ -55,11 +46,9 @@ impl DifficultyObject {
|
|||||||
det.atan2(dot).abs()
|
det.atan2(dot).abs()
|
||||||
});
|
});
|
||||||
|
|
||||||
let prev = prev_diff.map(|o| (o.jump_dist, o.strain_time));
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
base,
|
base,
|
||||||
prev,
|
prev: prev_vals,
|
||||||
|
|
||||||
jump_dist,
|
jump_dist,
|
||||||
travel_dist,
|
travel_dist,
|
||||||
|
|||||||
@@ -1,129 +1,131 @@
|
|||||||
use crate::DifficultyAttributes;
|
use crate::DifficultyAttributes;
|
||||||
|
|
||||||
|
mod control_point_iter;
|
||||||
mod difficulty_object;
|
mod difficulty_object;
|
||||||
mod osu_object;
|
mod osu_object;
|
||||||
mod skill;
|
mod skill;
|
||||||
mod skill_kind;
|
mod skill_kind;
|
||||||
|
mod slider_state;
|
||||||
|
|
||||||
use difficulty_object::DifficultyObject;
|
use difficulty_object::DifficultyObject;
|
||||||
use osu_object::OsuObject;
|
use osu_object::OsuObject;
|
||||||
use skill::Skill;
|
use skill::Skill;
|
||||||
use skill_kind::SkillKind;
|
use skill_kind::SkillKind;
|
||||||
|
use slider_state::SliderState;
|
||||||
|
|
||||||
use parse::{Beatmap, Mods};
|
use parse::{Beatmap, Mods};
|
||||||
|
|
||||||
const OBJECT_RADIUS: f32 = 64.0;
|
const OBJECT_RADIUS: f32 = 64.0;
|
||||||
const SECTION_LEN: f32 = 400.0;
|
const SECTION_LEN: f32 = 400.0;
|
||||||
const DIFFICULTY_MULTIPLIER: f32 = 0.0675;
|
const DIFFICULTY_MULTIPLIER: f32 = 0.0675;
|
||||||
|
const NORMALIZED_RADIUS: f32 = 52.0;
|
||||||
|
|
||||||
/// Star calculation for osu!standard maps
|
/// Star calculation for osu!standard maps.
|
||||||
|
///
|
||||||
|
/// Slider paths are considered but stack leniency is ignored.
|
||||||
|
/// As most maps don't even make use of leniency and even if,
|
||||||
|
/// it has generally little effect on stars, the results are close to perfect.
|
||||||
|
/// This version is considerably more efficient than `all_included` since
|
||||||
|
/// processing stack leniency is relatively expensive.
|
||||||
pub fn stars(map: &Beatmap, mods: impl Mods) -> DifficultyAttributes {
|
pub fn stars(map: &Beatmap, mods: impl Mods) -> DifficultyAttributes {
|
||||||
let attributes = map.attributes().mods(mods);
|
let attributes = map.attributes().mods(mods);
|
||||||
|
|
||||||
if map.hit_objects.len() < 2 {
|
let mut diff_attributes = DifficultyAttributes {
|
||||||
return DifficultyAttributes {
|
|
||||||
stars: 0.0,
|
|
||||||
ar: attributes.ar,
|
ar: attributes.ar,
|
||||||
od: attributes.od,
|
od: attributes.od,
|
||||||
speed_strain: 0.0,
|
..Default::default()
|
||||||
aim_strain: 0.0,
|
|
||||||
max_combo: 0,
|
|
||||||
n_circles: 0,
|
|
||||||
n_spinners: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if map.hit_objects.len() < 2 {
|
||||||
|
return diff_attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
let section_len = SECTION_LEN * attributes.clock_rate;
|
let section_len = SECTION_LEN * attributes.clock_rate;
|
||||||
let radius = OBJECT_RADIUS * (1.0 - 0.7 * (attributes.cs - 5.0) / 5.0) / 2.0;
|
let radius = OBJECT_RADIUS * (1.0 - 0.7 * (attributes.cs - 5.0) / 5.0) / 2.0;
|
||||||
|
let mut scaling_factor = NORMALIZED_RADIUS / radius;
|
||||||
|
|
||||||
|
if radius < 30.0 {
|
||||||
|
let small_circle_bonus = (30.0 - radius).min(5.0) / 50.0;
|
||||||
|
scaling_factor *= 1.0 + small_circle_bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut slider_state = SliderState::new(&map);
|
||||||
|
|
||||||
let mut hit_objects = map
|
let mut hit_objects = map
|
||||||
.hit_objects
|
.hit_objects
|
||||||
.iter()
|
.iter()
|
||||||
.map(|h| OsuObject::new(h, map, &attributes));
|
.map(|h| OsuObject::new(h, map, radius, &mut diff_attributes, &mut slider_state));
|
||||||
|
|
||||||
let mut skills = vec![Skill::new(SkillKind::Aim), Skill::new(SkillKind::Speed)];
|
let mut aim = Skill::new(SkillKind::Aim);
|
||||||
|
let mut speed = Skill::new(SkillKind::Speed);
|
||||||
|
|
||||||
|
// First object has no predecessor and thus no strain, handle distinctly
|
||||||
let mut current_section_end =
|
let mut current_section_end =
|
||||||
(map.hit_objects[0].start_time / section_len).ceil() * section_len;
|
(map.hit_objects[0].start_time / section_len).ceil() * section_len;
|
||||||
|
|
||||||
let mut prev_prev = None;
|
let mut prev_prev = None;
|
||||||
let mut prev = hit_objects.next().unwrap();
|
let mut prev = hit_objects.next().unwrap();
|
||||||
let mut prev_diff = None;
|
let mut prev_vals = None;
|
||||||
|
|
||||||
let mut _i = 0;
|
// Handle second object separately to remove later if-branching
|
||||||
|
let curr = hit_objects.next().unwrap();
|
||||||
for curr in hit_objects {
|
|
||||||
let h = DifficultyObject::new(
|
let h = DifficultyObject::new(
|
||||||
curr.clone(),
|
&curr,
|
||||||
prev.clone(),
|
&prev,
|
||||||
prev_diff,
|
prev_vals,
|
||||||
prev_prev,
|
prev_prev,
|
||||||
attributes.clock_rate,
|
attributes.clock_rate,
|
||||||
radius,
|
scaling_factor,
|
||||||
);
|
);
|
||||||
|
|
||||||
// println!(
|
aim.process(&h);
|
||||||
// "strain_time={} | travel_dist={} | jump_dist={} | angle={:?}",
|
speed.process(&h);
|
||||||
// h.strain_time, h.travel_dist, h.jump_dist, h.angle
|
|
||||||
// );
|
|
||||||
|
|
||||||
// println!("[{}] time={}", _i, curr.time());
|
prev_prev = Some(prev);
|
||||||
|
prev_vals = Some((h.jump_dist, h.strain_time));
|
||||||
|
prev = curr;
|
||||||
|
|
||||||
while h.base.time() > current_section_end {
|
// Handle all other objects
|
||||||
for skill in skills.iter_mut() {
|
for curr in hit_objects {
|
||||||
skill.save_current_peak();
|
let h = DifficultyObject::new(
|
||||||
skill.start_new_section_from(current_section_end);
|
&curr,
|
||||||
|
&prev,
|
||||||
|
prev_vals,
|
||||||
|
prev_prev,
|
||||||
|
attributes.clock_rate,
|
||||||
|
scaling_factor,
|
||||||
|
);
|
||||||
|
|
||||||
_i += 1;
|
while h.base.time > current_section_end {
|
||||||
}
|
aim.save_current_peak();
|
||||||
|
aim.start_new_section_from(current_section_end);
|
||||||
|
speed.save_current_peak();
|
||||||
|
speed.start_new_section_from(current_section_end);
|
||||||
|
|
||||||
current_section_end += section_len;
|
current_section_end += section_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
for skill in skills.iter_mut() {
|
aim.process(&h);
|
||||||
skill.process(&h);
|
speed.process(&h);
|
||||||
}
|
|
||||||
|
|
||||||
prev_prev = Some(prev);
|
prev_prev = Some(prev);
|
||||||
|
prev_vals = Some((h.jump_dist, h.strain_time));
|
||||||
prev = curr;
|
prev = curr;
|
||||||
prev_diff = Some(h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for skill in skills.iter_mut() {
|
aim.save_current_peak();
|
||||||
skill.save_current_peak();
|
speed.save_current_peak();
|
||||||
}
|
|
||||||
|
|
||||||
// println!("Aim:");
|
let aim_strain = aim.difficulty_value().sqrt() * DIFFICULTY_MULTIPLIER;
|
||||||
// for (i, strain) in skills[0].strain_peaks.iter().enumerate() {
|
let speed_strain = speed.difficulty_value().sqrt() * DIFFICULTY_MULTIPLIER;
|
||||||
// println!("{}: {}", i, strain);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// println!("Speed:");
|
let stars = aim_strain + speed_strain + (aim_strain - speed_strain).abs() / 2.0;
|
||||||
// for (i, strain) in skills[1].strain_peaks.iter().enumerate() {
|
|
||||||
// println!("{}: {}", i, strain);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// println!("Aim: {:?}", skills[0].strain_peaks);
|
diff_attributes.stars = stars;
|
||||||
// println!("Speed: {:?}", skills[1].strain_peaks);
|
diff_attributes.speed_strain = speed_strain;
|
||||||
|
diff_attributes.aim_strain = aim_strain;
|
||||||
|
|
||||||
let aim_rating = skills[0].difficulty_value().sqrt() * DIFFICULTY_MULTIPLIER;
|
diff_attributes
|
||||||
// println!("After:\n{:?}", skills[0].strain_peaks);
|
|
||||||
|
|
||||||
let speed_rating = skills[1].difficulty_value().sqrt() * DIFFICULTY_MULTIPLIER;
|
|
||||||
// println!("After:\n{:?}", skills[1].strain_peaks);
|
|
||||||
|
|
||||||
let stars = aim_rating + speed_rating + (aim_rating - speed_rating).abs() / 2.0;
|
|
||||||
|
|
||||||
DifficultyAttributes {
|
|
||||||
stars,
|
|
||||||
ar: attributes.ar,
|
|
||||||
od: attributes.od,
|
|
||||||
speed_strain: speed_rating,
|
|
||||||
aim_strain: aim_rating,
|
|
||||||
max_combo: 0, // TODO
|
|
||||||
n_circles: 0, // TODO
|
|
||||||
n_spinners: 0, // TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -135,14 +137,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_leniency_single_stars() {
|
fn no_leniency_single_stars() {
|
||||||
// let file = match File::open("E:/Games/osu!/beatmaps/1851299.osu") {
|
let file = match File::open("./test/70090.osu") {
|
||||||
// Ok(file) => file,
|
|
||||||
// Err(why) => panic!("Could not open file: {}", why),
|
|
||||||
// };
|
|
||||||
let file = match File::open("C:/Users/Max/Desktop/2578801.osu") {
|
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(why) => panic!("Could not open file: {}", why),
|
Err(why) => panic!("Could not open file: {}", why),
|
||||||
};
|
};
|
||||||
|
// let file = match File::open("C:/Users/Max/Desktop/2578801.osu") {
|
||||||
|
// Ok(file) => file,
|
||||||
|
// Err(why) => panic!("Could not open file: {}", why),
|
||||||
|
// };
|
||||||
|
|
||||||
let map = match Beatmap::parse(file) {
|
let map = match Beatmap::parse(file) {
|
||||||
Ok(map) => map,
|
Ok(map) => map,
|
||||||
@@ -215,23 +217,30 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_leniency_single_pp() {
|
fn no_leniency_single_pp() {
|
||||||
// let file = match File::open("E:/Games/osu!/beatmaps/1851299.osu") {
|
let file = match File::open("E:/Games/osu!/beatmaps/1241370.osu") {
|
||||||
// Ok(file) => file,
|
|
||||||
// Err(why) => panic!("Could not open file: {}", why),
|
|
||||||
// };
|
|
||||||
let file = match File::open("C:/Users/Max/Desktop/2578801.osu") {
|
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(why) => panic!("Could not open file: {}", why),
|
Err(why) => panic!("Could not open file: {}", why),
|
||||||
};
|
};
|
||||||
|
// let file = match File::open("C:/Users/Max/Desktop/2578801.osu") {
|
||||||
|
// Ok(file) => file,
|
||||||
|
// Err(why) => panic!("Could not open file: {}", why),
|
||||||
|
// };
|
||||||
|
|
||||||
let map = match Beatmap::parse(file) {
|
let map = match Beatmap::parse(file) {
|
||||||
Ok(map) => map,
|
Ok(map) => map,
|
||||||
Err(why) => panic!("Error while parsing map: {}", why),
|
Err(why) => panic!("Error while parsing map: {}", why),
|
||||||
};
|
};
|
||||||
|
|
||||||
let calculator = PpCalculator::new(&map).mods(0);
|
let calculator = PpCalculator::new(&map)
|
||||||
|
// .misses(2)
|
||||||
|
// .accuracy(96.78)
|
||||||
|
// .combo(1876)
|
||||||
|
// .n100(0)
|
||||||
|
.mods(8 + 16);
|
||||||
|
|
||||||
let result = calculator.calculate(stars);
|
let result = calculator.calculate(stars);
|
||||||
|
|
||||||
|
println!("Stars: {}", result.attributes.stars);
|
||||||
println!("PP: {}", result.pp);
|
println!("PP: {}", result.pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,64 @@
|
|||||||
#![allow(unused)]
|
use super::slider_state::SliderState;
|
||||||
|
use crate::{curve::Curve, DifficultyAttributes};
|
||||||
|
|
||||||
use crate::curve::Curve;
|
use parse::{Beatmap, HitObject, HitObjectKind, PathType, Pos2};
|
||||||
|
|
||||||
use parse::{Beatmap, BeatmapAttributes, HitObject, HitObjectKind, PathType, Pos2};
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
macro_rules! binary_search {
|
|
||||||
($slice:expr, $target:expr) => {
|
|
||||||
$slice.binary_search_by(|p| p.time.partial_cmp(&$target).unwrap_or(Ordering::Equal))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const OBJECT_RADIUS: f32 = 64.0;
|
|
||||||
const STACK_DIST: f32 = 3.0;
|
|
||||||
const LEGACY_LAST_TICK_OFFSET: f32 = 36.0;
|
const LEGACY_LAST_TICK_OFFSET: f32 = 36.0;
|
||||||
|
|
||||||
#[derive(Clone)] // TODO: Remove clone
|
pub(crate) struct OsuObject {
|
||||||
pub(crate) enum OsuObject {
|
pub(crate) time: f32,
|
||||||
Circle {
|
pub(crate) pos: Pos2,
|
||||||
pos: Pos2,
|
pub(crate) end_pos: Pos2,
|
||||||
time: f32,
|
// circle: Some(0.0) | slider: Some(_) | spinner: None
|
||||||
},
|
pub(crate) travel_dist: Option<f32>,
|
||||||
Slider {
|
|
||||||
objects: Vec<SliderTick>,
|
|
||||||
|
|
||||||
cursor_end_pos: Pos2,
|
|
||||||
cursor_travel_dist: f32,
|
|
||||||
},
|
|
||||||
Spinner {
|
|
||||||
pos: Pos2,
|
|
||||||
time: f32,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OsuObject {
|
impl OsuObject {
|
||||||
pub(crate) fn new(h: &HitObject, map: &Beatmap, attributes: &BeatmapAttributes) -> Self {
|
pub(crate) fn new(
|
||||||
let pos = h.pos;
|
h: &HitObject,
|
||||||
let time = h.start_time;
|
map: &Beatmap,
|
||||||
|
radius: f32,
|
||||||
let scale = (1.0 - 0.7 * (attributes.cs - 5.0) / 5.0) / 2.0;
|
attributes: &mut DifficultyAttributes,
|
||||||
let mut stack_height = 0.0;
|
slider_state: &mut SliderState,
|
||||||
|
) -> Self {
|
||||||
|
attributes.max_combo += 1; // hitcircle, slider head, or spinner
|
||||||
|
|
||||||
match &h.kind {
|
match &h.kind {
|
||||||
HitObjectKind::Circle => Self::Circle { pos, time },
|
HitObjectKind::Circle => {
|
||||||
|
attributes.n_circles += 1;
|
||||||
|
|
||||||
|
Self {
|
||||||
|
time: h.start_time,
|
||||||
|
pos: h.pos,
|
||||||
|
end_pos: h.pos,
|
||||||
|
travel_dist: Some(0.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
HitObjectKind::Slider {
|
HitObjectKind::Slider {
|
||||||
pixel_len,
|
pixel_len,
|
||||||
repeats,
|
repeats,
|
||||||
curve_points,
|
curve_points,
|
||||||
path_type,
|
path_type,
|
||||||
} => {
|
} => {
|
||||||
let (beat_len, timing_time) = {
|
// Key values which are computed here
|
||||||
match binary_search!(map.timing_points, time) {
|
let mut end_pos = h.pos;
|
||||||
Ok(idx) => {
|
let mut travel_dist = 0.0;
|
||||||
let point = &map.timing_points[idx];
|
|
||||||
(point.beat_len, point.time)
|
|
||||||
}
|
|
||||||
Err(0) => (1000.0, 0.0),
|
|
||||||
Err(idx) => {
|
|
||||||
let point = &map.timing_points[idx - 1];
|
|
||||||
(point.beat_len, point.time)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (speed_multiplier, diff_time) = {
|
|
||||||
match binary_search!(map.difficulty_points, time) {
|
|
||||||
Ok(idx) => {
|
|
||||||
let point = &map.difficulty_points[idx];
|
|
||||||
(point.speed_multiplier, point.time)
|
|
||||||
}
|
|
||||||
Err(0) => (1.0, 0.0),
|
|
||||||
Err(idx) => {
|
|
||||||
let point = &map.difficulty_points[idx - 1];
|
|
||||||
(point.speed_multiplier, point.time)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
slider_state.update(h.start_time); // Responsible for timing point values
|
||||||
|
let approx_follow_circle_radius = radius * 3.0;
|
||||||
let mut tick_distance = 100.0 * map.sv / map.tick_rate;
|
let mut tick_distance = 100.0 * map.sv / map.tick_rate;
|
||||||
|
|
||||||
if map.version >= 8 {
|
if map.version >= 8 {
|
||||||
tick_distance /= (100.0 / speed_multiplier).max(10.0).min(1000.0) / 100.0;
|
tick_distance /=
|
||||||
|
(100.0 / slider_state.speed_mult).max(10.0).min(1000.0) / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let spm = if timing_time > diff_time {
|
let duration = *repeats as f32 * slider_state.beat_len * pixel_len
|
||||||
1.0
|
/ (map.sv * slider_state.speed_mult)
|
||||||
} else {
|
/ 100.0;
|
||||||
speed_multiplier
|
let span_duration = duration / *repeats as f32;
|
||||||
};
|
|
||||||
|
|
||||||
let duration = *repeats as f32 * beat_len * pixel_len / (map.sv * spm) / 100.0;
|
|
||||||
|
|
||||||
// let velocity = *pixel_len as f32 / duration;
|
|
||||||
|
|
||||||
// println!("duration={}", duration);
|
|
||||||
// println!("velocity={}", velocity);
|
|
||||||
|
|
||||||
|
// Ensure path type validity
|
||||||
let path_type = if *path_type == PathType::PerfectCurve && curve_points.len() > 3 {
|
let path_type = if *path_type == PathType::PerfectCurve && curve_points.len() > 3 {
|
||||||
PathType::Bezier
|
PathType::Bezier
|
||||||
} else if curve_points.len() == 2 {
|
} else if curve_points.len() == 2 {
|
||||||
@@ -104,6 +67,7 @@ impl OsuObject {
|
|||||||
*path_type
|
*path_type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Build the curve w.r.t. the curve points
|
||||||
let curve = match path_type {
|
let curve = match path_type {
|
||||||
PathType::Linear => Curve::linear(curve_points[0], curve_points[1]),
|
PathType::Linear => Curve::linear(curve_points[0], curve_points[1]),
|
||||||
PathType::Bezier => Curve::bezier(&curve_points),
|
PathType::Bezier => Curve::bezier(&curve_points),
|
||||||
@@ -111,122 +75,13 @@ impl OsuObject {
|
|||||||
PathType::PerfectCurve => Curve::perfect(&curve_points),
|
PathType::PerfectCurve => Curve::perfect(&curve_points),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut current_distance = tick_distance;
|
// Called on each slider object except for the head.
|
||||||
let time_add = duration * (tick_distance / (pixel_len * *repeats as f32));
|
// Increases combo and adjusts `end_pos` and `travel_dist`
|
||||||
|
// w.r.t. the object position at the given time on the slider curve.
|
||||||
|
let mut compute_vertex = |time: f32| {
|
||||||
|
attributes.max_combo += 1;
|
||||||
|
|
||||||
let target = pixel_len - tick_distance / 8.0;
|
let mut progress = (time - h.start_time) / span_duration;
|
||||||
let mut ticks = Vec::with_capacity((target / tick_distance) as usize);
|
|
||||||
|
|
||||||
while current_distance < target {
|
|
||||||
let pos = curve.point_at_distance(current_distance);
|
|
||||||
let time = h.start_time + time_add * (ticks.len() + 1) as f32;
|
|
||||||
ticks.push(SliderTick::new(pos, time));
|
|
||||||
current_distance += tick_distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut slider_objects = Vec::with_capacity(repeats * (ticks.len() + 1));
|
|
||||||
slider_objects.push(SliderTick::new(h.pos, h.start_time));
|
|
||||||
|
|
||||||
if *repeats <= 1 {
|
|
||||||
slider_objects.append(&mut ticks);
|
|
||||||
} else {
|
|
||||||
slider_objects.append(&mut ticks.clone());
|
|
||||||
|
|
||||||
for repeat_id in 1..repeats - 1 {
|
|
||||||
let dist = (repeat_id % 2) as f32 * pixel_len;
|
|
||||||
let time_offset = (duration / *repeats as f32) * repeat_id as f32;
|
|
||||||
let pos = curve.point_at_distance(dist);
|
|
||||||
|
|
||||||
// Reverse tick / last legacy tick
|
|
||||||
slider_objects.push(SliderTick::new(pos, h.start_time + time_offset));
|
|
||||||
|
|
||||||
ticks.reverse();
|
|
||||||
slider_objects.extend_from_slice(&ticks); // tick time doesn't need to be adjusted for some reason
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handling last span separatly so that `ticks` vector isn't cloned again
|
|
||||||
let dist = ((repeats - 1) % 2) as f32 * pixel_len;
|
|
||||||
let time_offset = (duration / *repeats as f32) * (repeats - 1) as f32;
|
|
||||||
let pos = curve.point_at_distance(dist);
|
|
||||||
|
|
||||||
slider_objects.push(SliderTick::new(pos, h.start_time + time_offset));
|
|
||||||
|
|
||||||
ticks.reverse();
|
|
||||||
slider_objects.append(&mut ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Slider tail
|
|
||||||
let span_duration = duration / *repeats as f32;
|
|
||||||
let final_span_idx = repeats.saturating_sub(1);
|
|
||||||
let final_span_start_time = h.start_time + final_span_idx as f32 * span_duration;
|
|
||||||
let final_span_end_time = (h.start_time + duration / 2.0)
|
|
||||||
.max(final_span_start_time + span_duration - LEGACY_LAST_TICK_OFFSET);
|
|
||||||
let mut final_progress =
|
|
||||||
(final_span_end_time - final_span_start_time) / span_duration;
|
|
||||||
|
|
||||||
if *repeats & 1 == 0 {
|
|
||||||
final_progress = 1.0 - final_progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "final_span_index={} | final_span_start_time={} | \
|
|
||||||
// final_span_end_time={} | final_progress={}",
|
|
||||||
// final_span_idx, final_span_start_time, final_span_end_time, final_progress
|
|
||||||
// );
|
|
||||||
|
|
||||||
// println!("len={}", final_progress * *pixel_len as f32);
|
|
||||||
|
|
||||||
let dist_end = (repeats % 2) as f32 * pixel_len;
|
|
||||||
|
|
||||||
let pos = curve.point_at_distance(dist_end);
|
|
||||||
slider_objects.push(SliderTick::new(pos, final_span_end_time));
|
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "start_time={} | span_duration={} | vel={} | \
|
|
||||||
// tick_dist={} | dist={} | span_count={} | \
|
|
||||||
// legacy_last_tick_offset={}",
|
|
||||||
// h.start_time,
|
|
||||||
// duration / *repeats as f32,
|
|
||||||
// *pixel_len as f32 / duration,
|
|
||||||
// tick_distance,
|
|
||||||
// *pixel_len,
|
|
||||||
// *repeats,
|
|
||||||
// 36
|
|
||||||
// );
|
|
||||||
|
|
||||||
// println!("> Slider: {:?}", slider_objects);
|
|
||||||
|
|
||||||
let radius = OBJECT_RADIUS * scale;
|
|
||||||
|
|
||||||
let stack_offset = {
|
|
||||||
let c = stack_height * scale * -6.4;
|
|
||||||
|
|
||||||
Pos2 { x: c, y: c }
|
|
||||||
};
|
|
||||||
|
|
||||||
// println!("radius={} | stack_offset={:?}", radius, stack_offset);
|
|
||||||
|
|
||||||
let pos = h.pos;
|
|
||||||
let stacked_pos = pos + stack_offset; // TODO: Simplify for below
|
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "stacked_pos = {:?} + {:?} = {:?}",
|
|
||||||
// pos, stack_offset, stacked_pos
|
|
||||||
// );
|
|
||||||
|
|
||||||
let mut cursor_end_pos = stacked_pos;
|
|
||||||
let mut cursor_travel_dist = 0.0;
|
|
||||||
let approx_follow_circle_radius = radius * 3.0;
|
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "stacked_pos={:?} | approx_follow_circle_radius={}",
|
|
||||||
// stacked_pos, approx_follow_circle_radius
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let mut curr_offset = tick_distance;
|
|
||||||
|
|
||||||
for (i, tick) in slider_objects.iter().skip(1).enumerate() {
|
|
||||||
let mut progress = (tick.time - h.start_time) / span_duration;
|
|
||||||
|
|
||||||
if progress % 2.0 >= 1.0 {
|
if progress % 2.0 >= 1.0 {
|
||||||
progress = 1.0 - progress % 1.0;
|
progress = 1.0 - progress % 1.0;
|
||||||
@@ -237,116 +92,83 @@ impl OsuObject {
|
|||||||
let curr_dist = pixel_len * progress;
|
let curr_dist = pixel_len * progress;
|
||||||
let curr_pos = curve.point_at_distance(curr_dist);
|
let curr_pos = curve.point_at_distance(curr_dist);
|
||||||
|
|
||||||
let diff = stacked_pos + curr_pos - pos - cursor_end_pos;
|
let diff = curr_pos - end_pos;
|
||||||
let mut dist = diff.length();
|
let mut dist = diff.length();
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "position at: progress=? | d={} => {:?}",
|
|
||||||
// curr_offset, tick.pos
|
|
||||||
// );
|
|
||||||
// curr_offset += tick_distance;
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"[{}] diff = {:?} + {:?} - {:?} = {:?} | dist={}",
|
|
||||||
i,
|
|
||||||
stacked_pos,
|
|
||||||
tick.pos - pos,
|
|
||||||
cursor_end_pos,
|
|
||||||
diff,
|
|
||||||
dist
|
|
||||||
);
|
|
||||||
|
|
||||||
// println!("{} > {}", dist, approx_follow_circle_radius);
|
|
||||||
|
|
||||||
if dist > approx_follow_circle_radius {
|
if dist > approx_follow_circle_radius {
|
||||||
let normalized = diff.normalize();
|
|
||||||
// println!("diff before: {:?}", diff);
|
|
||||||
// println!("diff after: {:?}", normalized);
|
|
||||||
dist -= approx_follow_circle_radius;
|
dist -= approx_follow_circle_radius;
|
||||||
cursor_end_pos += normalized * dist;
|
end_pos += diff.normalize() * dist;
|
||||||
|
travel_dist += dist;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// println!("+= {} * {} => {:?}", normalized, dist, cursor_end_pos);
|
let mut current_distance = tick_distance;
|
||||||
|
let time_add = duration * (tick_distance / (pixel_len * *repeats as f32));
|
||||||
|
|
||||||
cursor_travel_dist += dist;
|
let target = pixel_len - tick_distance / 8.0;
|
||||||
// println!("+= {} => {}", dist, cursor_travel_dist);
|
let mut ticks = Vec::with_capacity((target / tick_distance) as usize);
|
||||||
|
|
||||||
|
// Tick of the first span
|
||||||
|
if current_distance < target {
|
||||||
|
for tick_idx in 1.. {
|
||||||
|
let time = h.start_time + time_add * tick_idx as f32;
|
||||||
|
compute_vertex(time);
|
||||||
|
ticks.push(time);
|
||||||
|
current_distance += tick_distance;
|
||||||
|
|
||||||
|
if current_distance >= target {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("cursor_travel_dist={}", cursor_travel_dist);
|
// Other spans
|
||||||
|
if *repeats > 1 {
|
||||||
|
for repeat_id in 1..*repeats {
|
||||||
|
let time_offset = (duration / *repeats as f32) * repeat_id as f32;
|
||||||
|
|
||||||
println!("---");
|
// Reverse tick
|
||||||
|
compute_vertex(h.start_time + time_offset);
|
||||||
|
|
||||||
Self::Slider {
|
// Actual ticks
|
||||||
objects: slider_objects,
|
if repeat_id & 1 == 1 {
|
||||||
|
ticks.iter().rev().for_each(|&time| compute_vertex(time));
|
||||||
cursor_end_pos,
|
} else {
|
||||||
cursor_travel_dist,
|
ticks.iter().for_each(|&time| compute_vertex(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slider tail
|
||||||
|
let final_span_idx = repeats.saturating_sub(1);
|
||||||
|
let final_span_start_time = h.start_time + final_span_idx as f32 * span_duration;
|
||||||
|
let final_span_end_time = (h.start_time + duration / 2.0)
|
||||||
|
.max(final_span_start_time + span_duration - LEGACY_LAST_TICK_OFFSET);
|
||||||
|
compute_vertex(final_span_end_time);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
time: h.start_time,
|
||||||
|
pos: h.pos,
|
||||||
|
end_pos,
|
||||||
|
travel_dist: Some(travel_dist),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HitObjectKind::Spinner { .. } => {
|
||||||
|
attributes.n_spinners += 1;
|
||||||
|
|
||||||
|
Self {
|
||||||
|
time: h.start_time,
|
||||||
|
pos: h.pos,
|
||||||
|
end_pos: h.pos,
|
||||||
|
travel_dist: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HitObjectKind::Spinner { .. } => Self::Spinner { pos, time },
|
|
||||||
HitObjectKind::Hold { .. } => panic!("found Hold object in osu!standard file"),
|
HitObjectKind::Hold { .. } => panic!("found Hold object in osu!standard file"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) fn time(&self) -> f32 {
|
|
||||||
match self {
|
|
||||||
Self::Circle { time, .. } => *time,
|
|
||||||
Self::Slider { objects, .. } => objects[0].time,
|
|
||||||
Self::Spinner { time, .. } => *time,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) fn travel_dist(&self) -> f32 {
|
|
||||||
match self {
|
|
||||||
Self::Slider {
|
|
||||||
cursor_travel_dist, ..
|
|
||||||
} => *cursor_travel_dist,
|
|
||||||
_ => 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) fn cursor_end_position(&self) -> Pos2 {
|
|
||||||
match self {
|
|
||||||
Self::Circle { pos, .. } => *pos,
|
|
||||||
Self::Slider { cursor_end_pos, .. } => *cursor_end_pos,
|
|
||||||
Self::Spinner { pos, .. } => *pos,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn is_spinner(&self) -> bool {
|
pub(crate) fn is_spinner(&self) -> bool {
|
||||||
matches!(self, Self::Spinner { .. })
|
self.travel_dist.is_none()
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove pub
|
|
||||||
#[inline]
|
|
||||||
pub fn pos(&self) -> Pos2 {
|
|
||||||
match self {
|
|
||||||
Self::Circle { pos, .. } => *pos,
|
|
||||||
Self::Slider { objects, .. } => objects[0].pos,
|
|
||||||
Self::Spinner { .. } => Pos2::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub(crate) struct SliderTick {
|
|
||||||
pos: Pos2,
|
|
||||||
time: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SliderTick {
|
|
||||||
fn new(pos: Pos2, time: f32) -> Self {
|
|
||||||
Self { pos, time }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove
|
|
||||||
impl std::fmt::Debug for SliderTick {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
write!(f, "{{pos={:?} | time={}}}", self.pos, self.time)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ const AIM_STRAIN_DECAY_BASE: f32 = 0.15;
|
|||||||
const DECAY_WEIGHT: f32 = 0.9;
|
const DECAY_WEIGHT: f32 = 0.9;
|
||||||
|
|
||||||
pub(crate) struct Skill {
|
pub(crate) struct Skill {
|
||||||
pub current_strain: f32,
|
current_strain: f32,
|
||||||
current_section_peak: f32,
|
current_section_peak: f32,
|
||||||
|
|
||||||
kind: SkillKind,
|
kind: SkillKind,
|
||||||
pub strain_peaks: Vec<f32>, // TODO: Remove pub
|
strain_peaks: Vec<f32>,
|
||||||
|
|
||||||
prev_time: Option<f32>,
|
prev_time: Option<f32>,
|
||||||
}
|
}
|
||||||
@@ -36,16 +36,12 @@ impl Skill {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn save_current_peak(&mut self) {
|
pub(crate) fn save_current_peak(&mut self) {
|
||||||
if self.prev_time.is_some() {
|
|
||||||
self.strain_peaks.push(self.current_section_peak);
|
self.strain_peaks.push(self.current_section_peak);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn start_new_section_from(&mut self, time: f32) {
|
pub(crate) fn start_new_section_from(&mut self, time: f32) {
|
||||||
if let Some(prev) = self.prev_time {
|
self.current_section_peak = self.peak_strain(time - self.prev_time.unwrap());
|
||||||
self.current_section_peak = self.peak_strain(time - prev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -53,7 +49,7 @@ impl Skill {
|
|||||||
self.current_strain *= self.strain_decay(current.delta);
|
self.current_strain *= self.strain_decay(current.delta);
|
||||||
self.current_strain += self.kind.strain_value_of(¤t) * self.skill_multiplier();
|
self.current_strain += self.kind.strain_value_of(¤t) * self.skill_multiplier();
|
||||||
self.current_section_peak = self.current_section_peak.max(self.current_strain);
|
self.current_section_peak = self.current_section_peak.max(self.current_strain);
|
||||||
self.prev_time.replace(current.base.time());
|
self.prev_time.replace(current.base.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn difficulty_value(&mut self) -> f32 {
|
pub(crate) fn difficulty_value(&mut self) -> f32 {
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ impl SkillKind {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("pos={:?}", current.base.pos());
|
|
||||||
|
|
||||||
let mut result = 0.0;
|
let mut result = 0.0;
|
||||||
|
|
||||||
if let Some((prev_jump_dist, prev_strain_time)) = current.prev {
|
if let Some((prev_jump_dist, prev_strain_time)) = current.prev {
|
||||||
@@ -39,23 +37,14 @@ impl SkillKind {
|
|||||||
* (current.jump_dist - scale).max(0.0))
|
* (current.jump_dist - scale).max(0.0))
|
||||||
.sqrt();
|
.sqrt();
|
||||||
|
|
||||||
// println!("angle_bonus={}", angle_bonus);
|
|
||||||
|
|
||||||
result = 1.5 * apply_diminishing_exp(angle_bonus.max(0.0))
|
result = 1.5 * apply_diminishing_exp(angle_bonus.max(0.0))
|
||||||
/ (TIMING_THRESHOLD).max(prev_strain_time)
|
/ (TIMING_THRESHOLD).max(prev_strain_time)
|
||||||
} else {
|
|
||||||
// println!("nop");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// println!("no prev");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let jump_dist_exp = apply_diminishing_exp(current.jump_dist);
|
let jump_dist_exp = apply_diminishing_exp(current.jump_dist);
|
||||||
let travel_dist_exp = apply_diminishing_exp(current.travel_dist);
|
let travel_dist_exp = apply_diminishing_exp(current.travel_dist);
|
||||||
|
|
||||||
// println!("jump_dist={} => {}", current.jump_dist, jump_dist_exp);
|
|
||||||
// println!("travel_dist={} => {}", current.travel_dist, travel_dist_exp);
|
|
||||||
|
|
||||||
let dist_exp =
|
let dist_exp =
|
||||||
jump_dist_exp + travel_dist_exp + (travel_dist_exp * jump_dist_exp).sqrt();
|
jump_dist_exp + travel_dist_exp + (travel_dist_exp * jump_dist_exp).sqrt();
|
||||||
|
|
||||||
@@ -79,8 +68,6 @@ impl SkillKind {
|
|||||||
|
|
||||||
let mut angle_bonus = 1.0;
|
let mut angle_bonus = 1.0;
|
||||||
|
|
||||||
// println!("angle: {:?}", current.angle);
|
|
||||||
|
|
||||||
if let Some(angle) = current.angle.filter(|a| *a < SPEED_ANGLE_BONUS_BEGIN) {
|
if let Some(angle) = current.angle.filter(|a| *a < SPEED_ANGLE_BONUS_BEGIN) {
|
||||||
let exp_base = (1.5 * (SPEED_ANGLE_BONUS_BEGIN - angle)).sin();
|
let exp_base = (1.5 * (SPEED_ANGLE_BONUS_BEGIN - angle)).sin();
|
||||||
angle_bonus = 1.0 + exp_base * exp_base / 3.57;
|
angle_bonus = 1.0 + exp_base * exp_base / 3.57;
|
||||||
@@ -88,7 +75,6 @@ impl SkillKind {
|
|||||||
if angle < PI_OVER_2 {
|
if angle < PI_OVER_2 {
|
||||||
angle_bonus = 1.28;
|
angle_bonus = 1.28;
|
||||||
|
|
||||||
// TODO: Improve ifs
|
|
||||||
if dist < 90.0 && angle < PI_OVER_4 {
|
if dist < 90.0 && angle < PI_OVER_4 {
|
||||||
angle_bonus += (1.0 - angle_bonus) * ((90.0 - dist) / 10.0).min(1.0);
|
angle_bonus += (1.0 - angle_bonus) * ((90.0 - dist) / 10.0).min(1.0);
|
||||||
} else if dist < 90.0 {
|
} else if dist < 90.0 {
|
||||||
@@ -99,11 +85,6 @@ impl SkillKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!(
|
|
||||||
// "dist={} | speed_bonus={} | angle_bonus={}",
|
|
||||||
// dist, speed_bonus, angle_bonus
|
|
||||||
// );
|
|
||||||
|
|
||||||
(1.0 + (speed_bonus - 1.0) * 0.75)
|
(1.0 + (speed_bonus - 1.0) * 0.75)
|
||||||
* angle_bonus
|
* angle_bonus
|
||||||
* (0.95 + speed_bonus * (dist / SINGLE_SPACING_TRESHOLD).powf(3.5))
|
* (0.95 + speed_bonus * (dist / SINGLE_SPACING_TRESHOLD).powf(3.5))
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
use super::control_point_iter::{ControlPoint, ControlPointIter};
|
||||||
|
|
||||||
|
use parse::Beatmap;
|
||||||
|
|
||||||
|
pub(crate) struct SliderState<'p> {
|
||||||
|
control_points: ControlPointIter<'p>,
|
||||||
|
next: Option<ControlPoint>,
|
||||||
|
pub(crate) beat_len: f32,
|
||||||
|
pub(crate) speed_mult: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'p> SliderState<'p> {
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn new(map: &'p Beatmap) -> Self {
|
||||||
|
let mut control_points = ControlPointIter::new(map);
|
||||||
|
|
||||||
|
let (beat_len, speed_mult) = match control_points.next() {
|
||||||
|
Some(ControlPoint::Timing { beat_len, .. }) => (beat_len, 1.0),
|
||||||
|
Some(ControlPoint::Difficulty { speed_mult, .. }) => (1000.0, speed_mult),
|
||||||
|
None => (1000.0, 1.0),
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
next: control_points.next(),
|
||||||
|
control_points,
|
||||||
|
beat_len,
|
||||||
|
speed_mult,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn update(&mut self, time: f32) {
|
||||||
|
while let Some(next) = self.next.as_ref().filter(|n| time >= n.time()) {
|
||||||
|
match next {
|
||||||
|
ControlPoint::Timing { beat_len, .. } => {
|
||||||
|
self.beat_len = *beat_len;
|
||||||
|
self.speed_mult = 1.0;
|
||||||
|
}
|
||||||
|
ControlPoint::Difficulty { speed_mult, .. } => self.speed_mult = *speed_mult,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.next = self.control_points.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ impl<'p> Iterator for ControlPointIter<'p> {
|
|||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match (self.next_timing, self.next_difficulty) {
|
match (self.next_timing, self.next_difficulty) {
|
||||||
(Some(time), Some((d, _))) if time < d => {
|
(Some(time), Some((d, _))) if time <= d => {
|
||||||
self.next_timing = self.timing_points.next().map(|t| t.time);
|
self.next_timing = self.timing_points.next().map(|t| t.time);
|
||||||
|
|
||||||
Some(ControlPoint::Timing { time })
|
Some(ControlPoint::Timing { time })
|
||||||
|
|||||||
@@ -172,8 +172,8 @@ mod tests {
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_sliders_no_leniency_single_stars() {
|
fn no_sliders_single_stars() {
|
||||||
let file = match File::open("E:/Games/osu!/beatmaps/1241370.osu") {
|
let file = match File::open("E:/Games/osu!/beatmaps/70090.osu") {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(why) => panic!("Could not open file: {}", why),
|
Err(why) => panic!("Could not open file: {}", why),
|
||||||
};
|
};
|
||||||
@@ -187,14 +187,14 @@ mod tests {
|
|||||||
Err(why) => panic!("Error while parsing map: {}", why),
|
Err(why) => panic!("Error while parsing map: {}", why),
|
||||||
};
|
};
|
||||||
|
|
||||||
let stars = stars(&map, 0).stars;
|
let stars = stars(&map, 1024 + 8 + 64 + 16).stars;
|
||||||
|
|
||||||
println!("Stars: {}", stars);
|
println!("Stars: {}", stars);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn no_sliders_no_leniency_stars() {
|
fn no_sliders_stars() {
|
||||||
let margin = 0.5;
|
let margin = 0.5;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
@@ -252,7 +252,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_sliders_no_leniency_single_pp() {
|
fn no_sliders_single_pp() {
|
||||||
let file = match File::open("E:/Games/osu!/beatmaps/1241370.osu") {
|
let file = match File::open("E:/Games/osu!/beatmaps/1241370.osu") {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(why) => panic!("Could not open file: {}", why),
|
Err(why) => panic!("Could not open file: {}", why),
|
||||||
@@ -268,11 +268,11 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let calculator = PpCalculator::new(&map)
|
let calculator = PpCalculator::new(&map)
|
||||||
// .misses(2)
|
.misses(2)
|
||||||
// .accuracy(96.78)
|
.accuracy(96.78)
|
||||||
// .combo(100)
|
.combo(1876)
|
||||||
// .n100(0)
|
// .n100(0)
|
||||||
.mods(0);
|
.mods(8 + 16);
|
||||||
|
|
||||||
let result = calculator.calculate(stars);
|
let result = calculator.calculate(stars);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user