sliders now share a vertex buf
This commit is contained in:
+11
-8
@@ -41,8 +41,8 @@ pub(crate) struct Curve {
|
||||
}
|
||||
|
||||
impl Curve {
|
||||
pub(crate) fn new(points: &[PathControlPoint], expected_len: f32) -> Self {
|
||||
let mut path = Self::calculate_path(points);
|
||||
pub(crate) fn new(points: &[PathControlPoint], expected_len: f32, buf: &mut Vec<Pos2>) -> Self {
|
||||
let mut path = Self::calculate_path(points, buf);
|
||||
let lengths = Self::calculate_length(points, &mut path, expected_len);
|
||||
|
||||
Self { path, lengths }
|
||||
@@ -74,14 +74,15 @@ impl Curve {
|
||||
return Pos2::zero();
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
let p1 = if i == 0 {
|
||||
return self.path[0];
|
||||
} else if i >= self.path.len() {
|
||||
} else if let Some(p) = self.path.get(i) {
|
||||
*p
|
||||
} else {
|
||||
return self.path[self.path.len() - 1];
|
||||
}
|
||||
};
|
||||
|
||||
let p0 = self.path[i - 1];
|
||||
let p1 = self.path[i];
|
||||
|
||||
let d0 = self.lengths[i - 1];
|
||||
let d1 = self.lengths[i];
|
||||
@@ -97,13 +98,15 @@ impl Curve {
|
||||
p0 + (p1 - p0) * w
|
||||
}
|
||||
|
||||
fn calculate_path(points: &[PathControlPoint]) -> Vec<Pos2> {
|
||||
fn calculate_path(points: &[PathControlPoint], vertices: &mut Vec<Pos2>) -> Vec<Pos2> {
|
||||
if points.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
vertices.clear();
|
||||
vertices.extend(points.iter().map(|p| p.pos));
|
||||
|
||||
let mut path = Vec::new();
|
||||
let vertices: Vec<_> = points.iter().map(|p| p.pos).collect();
|
||||
let mut start = 0;
|
||||
|
||||
for i in 0..points.len() {
|
||||
|
||||
+4
-2
@@ -45,6 +45,7 @@ pub fn stars(
|
||||
let with_hr = mods.hr();
|
||||
let mut ticks = Vec::new(); // using the same buffer for all sliders
|
||||
let mut slider_state = SliderState::new(map);
|
||||
let mut curve_buf = Vec::new();
|
||||
|
||||
let mut fruits = 0;
|
||||
let mut droplets = 0;
|
||||
@@ -92,7 +93,7 @@ pub fn stars(
|
||||
/ 100.0;
|
||||
|
||||
// Build the curve w.r.t. the curve points
|
||||
let curve = Curve::new(curve_points, *pixel_len);
|
||||
let curve = Curve::new(curve_points, *pixel_len, &mut curve_buf);
|
||||
|
||||
let mut current_distance = tick_distance;
|
||||
let time_add = duration * (tick_distance / (*pixel_len * *repeats as f32));
|
||||
@@ -284,6 +285,7 @@ pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
|
||||
let with_hr = mods.hr();
|
||||
let mut ticks = Vec::new(); // using the same buffer for all sliders
|
||||
let mut slider_state = SliderState::new(map);
|
||||
let mut curve_buf = Vec::new();
|
||||
|
||||
// BUG: Incorrect object order on 2B maps that have fruits within sliders
|
||||
let mut hit_objects = map
|
||||
@@ -325,7 +327,7 @@ pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
|
||||
/ 100.0;
|
||||
|
||||
// Build the curve w.r.t. the curve points
|
||||
let curve = Curve::new(curve_points, *pixel_len);
|
||||
let curve = Curve::new(curve_points, *pixel_len, &mut curve_buf);
|
||||
|
||||
let mut current_distance = tick_distance;
|
||||
let time_add = duration * (tick_distance / (*pixel_len * *repeats as f32));
|
||||
|
||||
@@ -68,6 +68,7 @@ pub fn stars(
|
||||
}
|
||||
|
||||
let mut slider_state = SliderState::new(map);
|
||||
let mut curve_buf = Vec::new();
|
||||
let mut ticks_buf = Vec::new();
|
||||
|
||||
let mut hit_objects = map
|
||||
@@ -83,6 +84,7 @@ pub fn stars(
|
||||
&mut ticks_buf,
|
||||
&mut diff_attributes,
|
||||
&mut slider_state,
|
||||
&mut curve_buf,
|
||||
)
|
||||
})
|
||||
.map(|mut h| {
|
||||
@@ -239,6 +241,7 @@ pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
|
||||
|
||||
let mut slider_state = SliderState::new(map);
|
||||
let mut ticks_buf = Vec::new();
|
||||
let mut curve_buf = Vec::new();
|
||||
|
||||
let mut hit_objects = map.hit_objects.iter().filter_map(|h| {
|
||||
OsuObject::new(
|
||||
@@ -249,6 +252,7 @@ pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
|
||||
&mut ticks_buf,
|
||||
&mut diff_attributes,
|
||||
&mut slider_state,
|
||||
&mut curve_buf,
|
||||
)
|
||||
});
|
||||
|
||||
@@ -367,17 +371,17 @@ fn custom_osu() {
|
||||
let start = Instant::now();
|
||||
let result = crate::OsuPP::new(&map).mods(0).calculate();
|
||||
|
||||
let iters = 500;
|
||||
let iters = 100;
|
||||
let accum = start.elapsed();
|
||||
|
||||
// * Tiny benchmark for pp calculation
|
||||
// let mut accum = accum;
|
||||
let mut accum = accum;
|
||||
|
||||
// for _ in 0..iters {
|
||||
// let start = Instant::now();
|
||||
// let _result = crate::OsuPP::new(&map).mods(0).calculate();
|
||||
// accum += start.elapsed();
|
||||
// }
|
||||
for _ in 0..iters {
|
||||
let start = Instant::now();
|
||||
let _result = crate::OsuPP::new(&map).mods(0).calculate();
|
||||
accum += start.elapsed();
|
||||
}
|
||||
|
||||
println!("{:#?}", result);
|
||||
println!("Calculation average: {:?}", accum / iters);
|
||||
|
||||
@@ -35,6 +35,7 @@ impl OsuObject {
|
||||
ticks: &mut Vec<f32>,
|
||||
attributes: &mut DifficultyAttributes,
|
||||
slider_state: &mut SliderState,
|
||||
slider_buf: &mut Vec<Pos2>,
|
||||
) -> Option<Self> {
|
||||
attributes.max_combo += 1; // hitcircle, slider head, or spinner
|
||||
|
||||
@@ -67,7 +68,7 @@ impl OsuObject {
|
||||
}
|
||||
|
||||
// Build the curve w.r.t. the curve points
|
||||
let curve = Curve::new(curve_points, *pixel_len);
|
||||
let curve = Curve::new(curve_points, *pixel_len, slider_buf);
|
||||
|
||||
let velocity =
|
||||
(BASE_SCORING_DISTANCE * map.slider_mult * slider_state.slider_velocity)
|
||||
|
||||
Reference in New Issue
Block a user