made bunch of functions const

This commit is contained in:
MaxOhn
2024-02-29 23:31:07 +01:00
parent 270d3d0008
commit 852f6cfa45
21 changed files with 233 additions and 140 deletions
+2 -2
View File
@@ -35,8 +35,8 @@ impl CatchDifficultyAttributes {
}
/// Returns a builder for performance calculation.
pub fn performance<'a>(self) -> CatchPerformance<'a> {
self.into()
pub const fn performance<'a>(self) -> CatchPerformance<'a> {
CatchPerformance::from_catch_attributes(self)
}
pub(crate) fn set_object_count(&mut self, count: &ObjectCount) {
+1 -1
View File
@@ -26,7 +26,7 @@ const RNG_SEED: i32 = 1337;
/// A [`Beatmap`] for [`Catch`] calculations.
pub type CatchBeatmap<'a> = Converted<'a, Catch>;
pub fn check_convert(map: &Beatmap) -> ConvertStatus {
pub const fn check_convert(map: &Beatmap) -> ConvertStatus {
match map.mode {
GameMode::Osu => ConvertStatus::Conversion,
GameMode::Catch => ConvertStatus::Noop,
+29 -25
View File
@@ -33,8 +33,32 @@ pub struct CatchPerformance<'map> {
impl<'map> CatchPerformance<'map> {
/// Create a new performance calculator for osu!catch maps.
pub fn new(map: CatchBeatmap<'map>) -> Self {
map.into()
pub const fn new(map: CatchBeatmap<'map>) -> Self {
Self {
map_or_attrs: MapOrAttrs::Map(map),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
fruits: None,
droplets: None,
tiny_droplets: None,
tiny_droplet_misses: None,
misses: None,
}
}
pub(crate) const fn from_catch_attributes(attrs: CatchDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrAttrs::Attrs(attrs),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
fruits: None,
droplets: None,
tiny_droplets: None,
tiny_droplet_misses: None,
misses: None,
}
}
/// Provide the result of a previous difficulty or performance calculation.
@@ -406,39 +430,19 @@ impl<'map> TryFrom<OsuPerformance<'map>> for CatchPerformance<'map> {
impl<'map> From<CatchBeatmap<'map>> for CatchPerformance<'map> {
fn from(map: CatchBeatmap<'map>) -> Self {
Self {
map_or_attrs: MapOrAttrs::Map(map),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
fruits: None,
droplets: None,
tiny_droplets: None,
tiny_droplet_misses: None,
misses: None,
}
Self::new(map)
}
}
impl From<CatchDifficultyAttributes> for CatchPerformance<'_> {
fn from(attrs: CatchDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrAttrs::Attrs(attrs),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
fruits: None,
droplets: None,
tiny_droplets: None,
tiny_droplet_misses: None,
misses: None,
}
Self::from_catch_attributes(attrs)
}
}
impl From<CatchPerformanceAttributes> for CatchPerformance<'_> {
fn from(attrs: CatchPerformanceAttributes) -> Self {
attrs.difficulty.into()
Self::from_catch_attributes(attrs.difficulty)
}
}
+16 -3
View File
@@ -1,5 +1,5 @@
/// Aggregation for a score's current state.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CatchScoreState {
/// Maximum combo that the score has had so far.
/// **Not** the maximum possible combo of the map so far.
@@ -20,8 +20,15 @@ pub struct CatchScoreState {
impl CatchScoreState {
/// Create a new empty score state.
pub fn new() -> Self {
Self::default()
pub const fn new() -> Self {
Self {
max_combo: 0,
n_fruits: 0,
n_droplets: 0,
n_tiny_droplets: 0,
n_tiny_droplet_misses: 0,
misses: 0,
}
}
/// Return the total amount of hits by adding everything up.
@@ -47,3 +54,9 @@ impl CatchScoreState {
f64::from(numerator) / f64::from(denominator)
}
}
impl Default for CatchScoreState {
fn default() -> Self {
Self::new()
}
}