#![warn(missing_docs)] //! This crate provides core functionality for Bevy Engine. mod name; mod task_pool_options; use bevy_ecs::system::Resource; pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable}; pub use name::*; pub use task_pool_options::*; pub mod prelude { //! The Bevy Core Prelude. #[doc(hidden)] pub use crate::{DefaultTaskPoolOptions, Name}; } use bevy_app::prelude::*; use bevy_ecs::entity::Entity; use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; use bevy_utils::{Duration, HashSet, Instant}; use std::borrow::Cow; use std::ops::Range; #[cfg(not(target_arch = "wasm32"))] use bevy_ecs::schedule::IntoSystemDescriptor; #[cfg(not(target_arch = "wasm32"))] use bevy_tasks::tick_global_task_pools_on_main_thread; /// Adds core functionality to Apps. #[derive(Default)] pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { // Setup the default bevy task pools app.world .get_resource::() .cloned() .unwrap_or_default() .create_default_pools(); #[cfg(not(target_arch = "wasm32"))] app.add_system_to_stage( bevy_app::CoreStage::Last, tick_global_task_pools_on_main_thread.at_end(), ); app.register_type::().register_type::(); app.register_type::() .register_type::() .register_type::>() .register_type_data::, ReflectSerialize>() .register_type_data::, ReflectDeserialize>(); register_rust_types(app); register_math_types(app); app.init_resource::(); } } fn register_rust_types(app: &mut App) { app.register_type::>() .register_type::() .register_type::>() .register_type::>() .register_type::>() .register_type::() .register_type::(); } fn register_math_types(app: &mut App) { app.register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::() .register_type::(); } /// Keeps a count of rendered frames since the start of the app /// /// Wraps to 0 when it reaches the maximum u32 value #[derive(Default, Resource, Clone, Copy)] pub struct FrameCount(pub u32); #[cfg(test)] mod tests { use super::*; use bevy_tasks::prelude::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool}; #[test] fn runs_spawn_local_tasks() { let mut app = App::new(); app.add_plugin(CorePlugin); let (async_tx, async_rx) = crossbeam_channel::unbounded(); AsyncComputeTaskPool::get() .spawn_local(async move { async_tx.send(()).unwrap(); }) .detach(); let (compute_tx, compute_rx) = crossbeam_channel::unbounded(); ComputeTaskPool::get() .spawn_local(async move { compute_tx.send(()).unwrap(); }) .detach(); let (io_tx, io_rx) = crossbeam_channel::unbounded(); IoTaskPool::get() .spawn_local(async move { io_tx.send(()).unwrap(); }) .detach(); app.run(); async_rx.try_recv().unwrap(); compute_rx.try_recv().unwrap(); io_rx.try_recv().unwrap(); } }