-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,84 @@ | ||
mod mode; | ||
|
||
use rosu_pp::Beatmap; | ||
use rosu_pp::{Beatmap, GameMode}; | ||
use std::sync::OnceLock; | ||
|
||
pub use self::mode::{Catch, Mania, Mode, Osu, Taiko}; | ||
|
||
static MAPS: OnceLock<[Beatmap; 4]> = OnceLock::new(); | ||
|
||
#[macro_export] | ||
#[rustfmt::skip] | ||
macro_rules! test_map { | ||
($mode:ident) => {{ | ||
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))] | ||
{ common::test_map::<$mode>() } | ||
{ common::test_map(GameMode::$mode) } | ||
#[cfg(any(feature = "async_tokio", feature = "async_std"))] | ||
{ common::test_map::<$mode>().await } | ||
{ common::test_map(GameMode::$mode).await } | ||
}}; | ||
} | ||
|
||
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))] | ||
pub fn test_map<M: Mode>() -> Beatmap { | ||
let path = format!("./maps/{}.osu", M::TEST_MAP_ID); | ||
pub fn test_map(mode: GameMode) -> &'static Beatmap { | ||
let maps = MAPS.get_or_init(|| { | ||
let osu = Beatmap::from_path(path(GameMode::Osu)).unwrap(); | ||
let taiko = Beatmap::from_path(path(GameMode::Taiko)).unwrap(); | ||
let catch = Beatmap::from_path(path(GameMode::Catch)).unwrap(); | ||
let mania = Beatmap::from_path(path(GameMode::Mania)).unwrap(); | ||
|
||
[osu, taiko, catch, mania] | ||
}); | ||
|
||
&maps[mode as usize] | ||
} | ||
|
||
#[cfg(feature = "async_tokio")] | ||
pub async fn test_map(mode: GameMode) -> &'static Beatmap { | ||
let maps = MAPS.get_or_init(|| { | ||
let fut = async { | ||
let osu = Beatmap::from_path(path(GameMode::Osu)).await.unwrap(); | ||
let taiko = Beatmap::from_path(path(GameMode::Taiko)).await.unwrap(); | ||
let catch = Beatmap::from_path(path(GameMode::Catch)).await.unwrap(); | ||
let mania = Beatmap::from_path(path(GameMode::Mania)).await.unwrap(); | ||
|
||
[osu, taiko, catch, mania] | ||
}; | ||
|
||
match tokio::runtime::Handle::try_current() { | ||
Ok(h) => std::thread::spawn(move || h.block_on(fut)).join().unwrap(), | ||
Err(_) => tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.unwrap() | ||
.block_on(fut), | ||
} | ||
}); | ||
|
||
&maps[mode as usize] | ||
} | ||
|
||
#[cfg(feature = "async_std")] | ||
pub async fn test_map(mode: GameMode) -> &'static Beatmap { | ||
let maps = MAPS.get_or_init(|| { | ||
async_std::task::block_on(async { | ||
let osu = Beatmap::from_path(path(GameMode::Osu)).await.unwrap(); | ||
let taiko = Beatmap::from_path(path(GameMode::Taiko)).await.unwrap(); | ||
let catch = Beatmap::from_path(path(GameMode::Catch)).await.unwrap(); | ||
let mania = Beatmap::from_path(path(GameMode::Mania)).await.unwrap(); | ||
|
||
[osu, taiko, catch, mania] | ||
}) | ||
}); | ||
|
||
Beatmap::from_path(path).unwrap() | ||
&maps[mode as usize] | ||
} | ||
|
||
#[cfg(any(feature = "async_tokio", feature = "async_std"))] | ||
pub async fn test_map<M: Mode>() -> Beatmap { | ||
let path = format!("./maps/{}.osu", M::TEST_MAP_ID); | ||
fn path(mode: GameMode) -> String { | ||
let map_id = match mode { | ||
GameMode::Osu => <Osu as Mode>::TEST_MAP_ID, | ||
GameMode::Taiko => <Taiko as Mode>::TEST_MAP_ID, | ||
GameMode::Catch => <Catch as Mode>::TEST_MAP_ID, | ||
GameMode::Mania => <Mania as Mode>::TEST_MAP_ID, | ||
}; | ||
|
||
Beatmap::from_path(path).await.unwrap() | ||
format!("./maps/{map_id}.osu") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters