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
@@ -43,8 +43,8 @@ impl OsuDifficultyAttributes {
}
/// Returns a builder for performance calculation.
pub fn performance<'a>(self) -> OsuPerformance<'a> {
self.into()
pub const fn performance<'a>(self) -> OsuPerformance<'a> {
OsuPerformance::from_osu_attributes(self)
}
}
+1 -1
View File
@@ -245,7 +245,7 @@ mod osu_objects {
}
impl OsuObjects {
pub(super) fn new(objects: Box<[OsuObject]>) -> Self {
pub(super) const fn new(objects: Box<[OsuObject]>) -> Self {
Self { objects }
}
+29 -25
View File
@@ -37,8 +37,32 @@ pub struct OsuPerformance<'map> {
impl<'map> OsuPerformance<'map> {
/// Create a new performance calculator for osu!standard maps.
pub fn new(map: OsuBeatmap<'map>) -> Self {
map.into()
pub const fn new(map: OsuBeatmap<'map>) -> Self {
Self {
map_or_attrs: MapOrAttrs::Map(map),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
misses: None,
hitresult_priority: HitResultPriority::DEFAULT,
}
}
pub(crate) const fn from_osu_attributes(attrs: OsuDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrAttrs::Attrs(attrs),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
misses: None,
hitresult_priority: HitResultPriority::DEFAULT,
}
}
/// Attempt to convert the map to the specified mode.
@@ -449,39 +473,19 @@ impl<'map> OsuPerformance<'map> {
impl<'map> From<OsuBeatmap<'map>> for OsuPerformance<'map> {
fn from(map: OsuBeatmap<'map>) -> Self {
Self {
map_or_attrs: MapOrAttrs::Map(map),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
misses: None,
hitresult_priority: HitResultPriority::default(),
}
Self::new(map)
}
}
impl From<OsuDifficultyAttributes> for OsuPerformance<'_> {
fn from(attrs: OsuDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrAttrs::Attrs(attrs),
difficulty: ModeDifficulty::new(),
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
misses: None,
hitresult_priority: HitResultPriority::default(),
}
Self::from_osu_attributes(attrs)
}
}
impl From<OsuPerformanceAttributes> for OsuPerformance<'_> {
fn from(attrs: OsuPerformanceAttributes) -> Self {
attrs.difficulty.into()
Self::from_osu_attributes(attrs.difficulty)
}
}
+15 -3
View File
@@ -1,5 +1,5 @@
/// Aggregation for a score's current state.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct OsuScoreState {
/// Maximum combo that the score has had so far.
/// **Not** the maximum possible combo of the map so far.
@@ -16,8 +16,14 @@ pub struct OsuScoreState {
impl OsuScoreState {
/// Create a new empty score state.
pub fn new() -> Self {
Self::default()
pub const fn new() -> Self {
Self {
max_combo: 0,
n300: 0,
n100: 0,
n50: 0,
misses: 0,
}
}
/// Return the total amount of hits by adding everything up.
@@ -39,3 +45,9 @@ impl OsuScoreState {
f64::from(numerator) / f64::from(denominator)
}
}
impl Default for OsuScoreState {
fn default() -> Self {
Self::new()
}
}