fix: fixed indexing in gradual catch calc

This commit is contained in:
MaxOhn
2023-11-09 19:30:25 +01:00
parent 5b4a349aaf
commit e70cec0c0d
+11 -5
View File
@@ -113,6 +113,7 @@ impl Iterator for CatchOwnedGradualDifficulty {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct CatchObjectIter { struct CatchObjectIter {
hit_object_idx: usize,
last_object: Option<FruitOrJuice>, last_object: Option<FruitOrJuice>,
params: FruitParams, params: FruitParams,
} }
@@ -129,6 +130,7 @@ impl CatchObjectIter {
}; };
Self { Self {
hit_object_idx: 0,
last_object: None, last_object: None,
params, params,
} }
@@ -138,21 +140,25 @@ impl CatchObjectIter {
self.params.attributes.clone() self.params.attributes.clone()
} }
fn next(&mut self, map: &Beatmap, idx: usize) -> Option<CatchObject> { fn next(&mut self, map: &Beatmap) -> Option<CatchObject> {
if let opt @ Some(_) = self.last_object.as_mut().and_then(Iterator::next) { if let opt @ Some(_) = self.last_object.as_mut().and_then(Iterator::next) {
return opt; return opt;
} }
map.hit_objects[idx..] map.hit_objects[self.hit_object_idx..]
.iter() .iter()
.find_map(|h| FruitOrJuice::new(h, &mut self.params, map)) .find_map(|h| {
self.hit_object_idx += 1;
FruitOrJuice::new(h, &mut self.params, map)
})
.and_then(|h| self.last_object.insert(h).next()) .and_then(|h| self.last_object.insert(h).next())
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct CatchGradualDifficultyInner { struct CatchGradualDifficultyInner {
pub(crate) idx: usize, idx: usize,
clock_rate: f64, clock_rate: f64,
hit_objects: CatchObjectIter, hit_objects: CatchObjectIter,
movement: Movement, movement: Movement,
@@ -207,7 +213,7 @@ impl CatchGradualDifficultyInner {
} }
fn next(&mut self, map: &Beatmap) -> Option<CatchDifficultyAttributes> { fn next(&mut self, map: &Beatmap) -> Option<CatchDifficultyAttributes> {
let curr = self.hit_objects.next(map, self.idx)?; let curr = self.hit_objects.next(map)?;
self.idx += 1; self.idx += 1;
if self.idx == 1 { if self.idx == 1 {