made bunch of functions const
This commit is contained in:
@@ -30,11 +30,11 @@ pub struct Difficulty<'map> {
|
||||
|
||||
impl<'map> Difficulty<'map> {
|
||||
/// Create a new difficulty calculator for the given beatmap.
|
||||
pub fn new(map: &'map Beatmap) -> Self {
|
||||
pub const fn new(map: &'map Beatmap) -> Self {
|
||||
Self::new_with_is_convert(Cow::Borrowed(map), false)
|
||||
}
|
||||
|
||||
fn new_with_is_convert(map: Cow<'map, Beatmap>, is_convert: bool) -> Self {
|
||||
const fn new_with_is_convert(map: Cow<'map, Beatmap>, is_convert: bool) -> Self {
|
||||
Self {
|
||||
map,
|
||||
is_convert,
|
||||
|
||||
@@ -14,8 +14,12 @@ pub struct ModeDifficulty {
|
||||
|
||||
impl ModeDifficulty {
|
||||
/// Create a new difficulty calculator.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
mods: 0,
|
||||
passed_objects: None,
|
||||
clock_rate: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Specify mods through their bit values.
|
||||
|
||||
@@ -30,10 +30,11 @@ pub enum Performance<'map> {
|
||||
|
||||
impl<'map> Performance<'map> {
|
||||
/// Create a new performance calculator for maps of any mode.
|
||||
pub fn new(map: &'map Beatmap) -> Self {
|
||||
pub const fn new(map: &'map Beatmap) -> Self {
|
||||
let mode = map.mode;
|
||||
let map = Cow::Borrowed(map);
|
||||
|
||||
match map.mode {
|
||||
match mode {
|
||||
GameMode::Osu => Self::Osu(OsuPerformance::new(Converted::new(map, false))),
|
||||
GameMode::Taiko => Self::Taiko(TaikoPerformance::new(Converted::new(map, false))),
|
||||
GameMode::Catch => Self::Catch(CatchPerformance::new(Converted::new(map, false))),
|
||||
@@ -274,7 +275,7 @@ impl<'map> Performance<'map> {
|
||||
|
||||
impl<A: AttributeProvider> From<A> for Performance<'_> {
|
||||
fn from(attrs: A) -> Self {
|
||||
fn inner(attrs: DifficultyAttributes) -> Performance<'static> {
|
||||
const fn inner(attrs: DifficultyAttributes) -> Performance<'static> {
|
||||
match attrs {
|
||||
DifficultyAttributes::Osu(attrs) => Performance::Osu(attrs.performance()),
|
||||
DifficultyAttributes::Taiko(attrs) => Performance::Taiko(attrs.performance()),
|
||||
@@ -309,11 +310,20 @@ impl_from_converted!(Catch);
|
||||
impl_from_converted!(Mania);
|
||||
|
||||
/// While generating remaining hitresults, decide how they should be distributed.
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum HitResultPriority {
|
||||
/// Prioritize good hitresults over bad ones
|
||||
#[default]
|
||||
BestCase,
|
||||
/// Prioritize bad hitresults over good ones
|
||||
WorstCase,
|
||||
}
|
||||
|
||||
impl HitResultPriority {
|
||||
pub(crate) const DEFAULT: Self = Self::BestCase;
|
||||
}
|
||||
|
||||
impl Default for HitResultPriority {
|
||||
fn default() -> Self {
|
||||
Self::DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -5,7 +5,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// Aggregation for a score's current state.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ScoreState {
|
||||
/// Maximum combo that the score has had so far. **Not** the maximum
|
||||
/// possible combo of the map so far.
|
||||
@@ -32,8 +32,16 @@ pub struct ScoreState {
|
||||
|
||||
impl ScoreState {
|
||||
/// Create a new empty score state.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
max_combo: 0,
|
||||
n_geki: 0,
|
||||
n_katu: 0,
|
||||
n300: 0,
|
||||
n100: 0,
|
||||
n50: 0,
|
||||
misses: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the total amount of hits by adding everything up based on the
|
||||
@@ -158,3 +166,9 @@ impl From<ManiaScoreState> for ScoreState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ScoreState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user