rosu_pp/any/hitresult_generator.rs
1use std::marker::PhantomData;
2
3use crate::any::InspectablePerformance;
4
5/// Provides flexible hitresult generation based on mode and whether it should
6/// focus on performance, accuracy, or other factors.
7pub trait HitResultGenerator<M: InspectablePerformance> {
8 fn generate_hitresults(inspect: M::InspectPerformance<'_>) -> M::HitResults;
9}
10
11/// [`HitResultGenerator`] whose result is generated as fast as possible.
12///
13/// This generator prioritizes performance over accuracy.
14pub struct Fast;
15
16/// [`HitResultGenerator`] whose result is the closest to the target accuracy.
17///
18/// Although the result is not guaranteed to be unique, i.e. there may be other
19/// results with the same accuracy, [`Closest`] guarantees that there are no
20/// other results that are *closer* to the target accuracy.
21pub struct Closest;
22
23/// [`HitResultGenerator`] that strives for a middleground between performance
24/// and accuracy through a statistical approach.
25///
26/// Currently not implemented.
27pub struct Statistical;
28
29/// [`HitResultGenerator`] that ignores accuracy and generates solely based on
30/// [`HitResultPriority`].
31///
32/// [`HitResultPriority`]: crate::any::HitResultPriority
33pub struct IgnoreAccuracy;
34
35/// [`HitResultGenerator`] consisting of a dedicated generator for each mode.
36pub struct Composable<Osu, Taiko, Catch, Mania>(PhantomData<(Osu, Taiko, Catch, Mania)>);
37
38macro_rules! impl_composable_generator {
39 ( $module:ident :: $mode:ident ) => {
40 impl<Osu, Taiko, Catch, Mania> HitResultGenerator<crate::$module::$mode>
41 for Composable<Osu, Taiko, Catch, Mania>
42 where
43 $mode: HitResultGenerator<crate::$module::$mode>,
44 {
45 fn generate_hitresults(
46 inspect: <crate::$module::$mode as crate::any::InspectablePerformance>::InspectPerformance<'_>,
47 ) -> <crate::$module::$mode as crate::model::mode::IGameMode>::HitResults {
48 $mode::generate_hitresults(inspect)
49 }
50 }
51 };
52}
53
54impl_composable_generator!(osu::Osu);
55impl_composable_generator!(taiko::Taiko);
56impl_composable_generator!(catch::Catch);
57impl_composable_generator!(mania::Mania);