use bevy::{
app::{App, Plugin},
ecs::schedule::ScheduleLabel,
prelude::World,
};
use inventory::collect;
#[doc(hidden)]
pub use inventory::submit;
#[doc(hidden)]
pub use paste::paste;
pub mod prelude {
pub use super::{RegistrationPlugin, app};
pub use bevy_registration_procedural_macros::{init, schedule, system};
}
#[cfg(target_family = "wasm")]
unsafe extern "C" {
fn __wasm_call_ctors();
}
pub struct RegistrationPlugin;
impl Plugin for RegistrationPlugin {
fn build(&self, app: &mut App) {
#[cfg(target_family = "wasm")]
unsafe {
__wasm_call_ctors();
}
inventory::iter::<AppFunction>
.into_iter()
.for_each(|app_function| {
(app_function.0)(app);
});
}
}
#[doc(hidden)]
pub struct AppFunction(pub fn(&mut App));
collect!(AppFunction);
#[macro_export]
macro_rules! app {
($function: expr) => {
bevy_registration::submit! {
bevy_registration::AppFunction($function)
}
};
}
pub fn try_run_schedule<T: ScheduleLabel + Default>(world: &mut World) {
let _ = world.try_run_schedule(T::default());
}