f32 -> f64 & osu_precise fixes + update

This commit is contained in:
MaxOhn
2021-11-12 02:44:40 +01:00
parent db474149d8
commit d703f55b3c
36 changed files with 1110 additions and 696 deletions
+15 -15
View File
@@ -3,27 +3,27 @@ use crate::Mods;
/// Summary struct for a [`Beatmap`](crate::Beatmap)'s attributes.
#[derive(Clone, Debug)]
pub struct BeatmapAttributes {
pub ar: f32,
pub od: f32,
pub cs: f32,
pub hp: f32,
pub clock_rate: f32,
pub ar: f64,
pub od: f64,
pub cs: f64,
pub hp: f64,
pub clock_rate: f64,
}
impl BeatmapAttributes {
const AR0_MS: f32 = 1800.0;
const AR5_MS: f32 = 1200.0;
const AR10_MS: f32 = 450.0;
const AR_MS_STEP_1: f32 = (Self::AR0_MS - Self::AR5_MS) / 5.0;
const AR_MS_STEP_2: f32 = (Self::AR5_MS - Self::AR10_MS) / 5.0;
const AR0_MS: f64 = 1800.0;
const AR5_MS: f64 = 1200.0;
const AR10_MS: f64 = 450.0;
const AR_MS_STEP_1: f64 = (Self::AR0_MS - Self::AR5_MS) / 5.0;
const AR_MS_STEP_2: f64 = (Self::AR5_MS - Self::AR10_MS) / 5.0;
#[inline]
pub(crate) fn new(ar: f32, od: f32, cs: f32, hp: f32) -> Self {
Self {
ar,
od,
cs,
hp,
ar: ar as f64,
od: od as f64,
cs: cs as f64,
hp: hp as f64,
clock_rate: 1.0,
}
}
@@ -40,7 +40,7 @@ impl BeatmapAttributes {
let multiplier = mods.od_ar_hp_multiplier();
// AR
let mut ar = self.ar * multiplier;
let mut ar = (self.ar * multiplier) as f64;
let mut ar_ms = if ar <= 5.0 {
Self::AR0_MS - Self::AR_MS_STEP_1 * ar
} else {
+4 -4
View File
@@ -3,8 +3,8 @@ use std::cmp::Ordering;
/// New rhythm speed change.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct TimingPoint {
pub beat_len: f32,
pub time: f32,
pub beat_len: f64,
pub time: f64,
}
impl PartialOrd for TimingPoint {
@@ -16,8 +16,8 @@ impl PartialOrd for TimingPoint {
/// [`TimingPoint`](crate::parse::TimingPoint) that depends on a previous one.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct DifficultyPoint {
pub time: f32,
pub speed_multiplier: f32,
pub time: f64,
pub speed_multiplier: f64,
}
impl PartialOrd for DifficultyPoint {
+6 -6
View File
@@ -7,14 +7,14 @@ use std::cmp::Ordering;
#[derive(Clone, Debug, PartialEq)]
pub struct HitObject {
pub pos: Pos2,
pub start_time: f32,
pub start_time: f64,
pub kind: HitObjectKind,
pub sound: u8,
}
impl HitObject {
#[inline]
pub fn end_time(&self) -> f32 {
pub fn end_time(&self) -> f64 {
match &self.kind {
HitObjectKind::Circle { .. } => self.start_time,
// incorrect, only called in mania which has no sliders though
@@ -52,20 +52,20 @@ pub enum HitObjectKind {
Circle,
#[cfg(feature = "sliders")]
Slider {
pixel_len: f32,
pixel_len: f64,
repeats: usize,
control_points: Vec<super::PathControlPoint>,
},
#[cfg(not(feature = "sliders"))]
Slider {
pixel_len: f32,
pixel_len: f64,
span_count: usize,
last_control_point: Pos2,
},
Spinner {
end_time: f32,
end_time: f64,
},
Hold {
end_time: f32,
end_time: f64,
},
}
+9 -9
View File
@@ -42,11 +42,11 @@ impl<T> OptionExt<T> for Option<T> {
}
}
trait F32Ext: Sized {
trait FloatExt: Sized {
fn validate(self) -> Result<Self, ParseError>;
}
impl F32Ext for f32 {
impl FloatExt for f64 {
fn validate(self) -> Result<Self, ParseError> {
self.is_finite()
.then(|| self)
@@ -312,10 +312,10 @@ macro_rules! parse_timingpoints_body {
.next()
.next_field("timing point time")?
.trim()
.parse::<f32>()?
.parse::<f64>()?
.validate()?;
let beat_len: f32 = split.next().next_field("beat len")?.trim().parse()?;
let beat_len: f64 = split.next().next_field("beat len")?.trim().parse()?;
if beat_len < 0.0 {
let point = DifficultyPoint {
@@ -429,7 +429,7 @@ macro_rules! parse_hitobjects_body {
.next()
.next_field("hitobject time")?
.trim()
.parse::<f32>()?
.parse::<f64>()?
.validate()?;
if !$self.hit_objects.is_empty() && time < prev_time {
@@ -519,7 +519,7 @@ macro_rules! parse_hitobjects_body {
let pixel_len = split
.next()
.next_field("pixel len")?
.parse::<f32>()?
.parse::<f64>()?
.max(0.0)
.min(MAX_COORDINATE_VALUE);
@@ -733,8 +733,8 @@ pub struct Beatmap {
pub od: f32,
pub cs: f32,
pub hp: f32,
pub slider_mult: f32,
pub tick_rate: f32,
pub slider_mult: f64,
pub tick_rate: f64,
pub hit_objects: Vec<HitObject>,
#[cfg(any(feature = "osu", feature = "fruits"))]
@@ -769,7 +769,7 @@ mod osu_fruits {
use super::Pos2;
pub(super) const MAX_COORDINATE_VALUE: f32 = 131_072.0;
pub(super) const MAX_COORDINATE_VALUE: f64 = 131_072.0;
pub(super) fn convert_points(
points: &[&str],