Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bevy_core #16897

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/scenes/load_scene_example.scn.ron
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
entities: {
4294967296: (
components: {
"bevy_core::name::Name": (
"bevy_ecs::name::Name": (
hash: 17588334858059901562,
name: "joe",
),
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ keywords = ["bevy"]
bevy_app = { path = "../bevy_app", version = "0.15.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.15.0-dev" }
bevy_color = { path = "../bevy_color", version = "0.15.0-dev" }
bevy_core = { path = "../bevy_core", version = "0.15.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.15.0-dev" }
bevy_log = { path = "../bevy_log", version = "0.15.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.15.0-dev" }
Expand Down
22 changes: 20 additions & 2 deletions crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ std = [

## `critical-section` provides the building blocks for synchronization primitives
## on all platforms, including `no_std`.
critical-section = ["bevy_tasks?/critical-section", "bevy_ecs/critical-section"]
critical-section = [
"portable-atomic?/critical-section",
"bevy_tasks?/critical-section",
"bevy_ecs/critical-section",
]

## `portable-atomic` provides additional platform support for atomic types and
## operations, even on targets without native support.
portable-atomic = ["bevy_tasks?/portable-atomic", "bevy_ecs/portable-atomic"]
portable-atomic = [
"dep:portable-atomic",
"dep:portable-atomic-util",
"bevy_tasks?/portable-atomic",
"bevy_ecs/portable-atomic",
]

[dependencies]
# bevy
Expand All @@ -77,6 +86,12 @@ thiserror = { version = "2", default-features = false }
variadics_please = "1.1"
tracing = { version = "0.1", default-features = false, optional = true }
log = { version = "0.4", default-features = false }
portable-atomic = { version = "1", default-features = false, features = [
"fallback",
], optional = true }
portable-atomic-util = { version = "0.2.4", features = [
"alloc",
], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ctrlc = { version = "3.4.4", optional = true }
Expand All @@ -86,6 +101,9 @@ wasm-bindgen = { version = "0.2" }
web-sys = { version = "0.3", features = ["Window"] }
console_error_panic_hook = "0.1.6"

[dev-dependencies]
crossbeam-channel = "0.5.0"

[lints]
workspace = true

Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ impl Default for App {
app.sub_apps.main.update_schedule = Some(Main.intern());

#[cfg(feature = "bevy_reflect")]
app.init_resource::<AppTypeRegistry>();
{
app.init_resource::<AppTypeRegistry>();
app.register_type::<Name>();
}

#[cfg(feature = "reflect_functions")]
app.init_resource::<AppFunctionRegistry>();
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod plugin;
mod plugin_group;
mod schedule_runner;
mod sub_app;
#[cfg(feature = "bevy_tasks")]
mod task_pool_plugin;
#[cfg(all(not(target_arch = "wasm32"), feature = "std"))]
mod terminal_ctrl_c_handler;

Expand All @@ -34,6 +36,8 @@ pub use plugin::*;
pub use plugin_group::*;
pub use schedule_runner::*;
pub use sub_app::*;
#[cfg(feature = "bevy_tasks")]
pub use task_pool_plugin::*;
#[cfg(all(not(target_arch = "wasm32"), feature = "std"))]
pub use terminal_ctrl_c_handler::*;

Expand All @@ -52,4 +56,8 @@ pub mod prelude {
sub_app::SubApp,
Plugin, PluginGroup,
};

#[cfg(feature = "bevy_tasks")]
#[doc(hidden)]
pub use crate::{NonSendMarker, TaskPoolOptions, TaskPoolPlugin};
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
#![cfg_attr(
feature = "portable-atomic",
expect(
clippy::redundant_closure,
reason = "portable_atomic_util::Arc has subtly different implicit behavior"
)
)]

use crate::{App, Last, Plugin};

use alloc::string::ToString;
use bevy_ecs::prelude::*;
use bevy_tasks::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool, TaskPoolBuilder};
use bevy_utils::tracing::trace;
use core::{fmt::Debug, marker::PhantomData};
use log::trace;

#[cfg(feature = "portable-atomic")]
use portable_atomic_util::Arc;

#[cfg(not(feature = "portable-atomic"))]
use alloc::sync::Arc;
use core::fmt::Debug;

#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::tick_global_task_pools_on_main_thread;

/// Setup of default task pools: [`AsyncComputeTaskPool`], [`ComputeTaskPool`], [`IoTaskPool`].
#[derive(Default)]
pub struct TaskPoolPlugin {
/// Options for the [`TaskPool`](bevy_tasks::TaskPool) created at application start.
pub task_pool_options: TaskPoolOptions,
}

impl Plugin for TaskPoolPlugin {
fn build(&self, _app: &mut App) {
// Setup the default bevy task pools
self.task_pool_options.create_default_pools();

#[cfg(not(target_arch = "wasm32"))]
_app.add_systems(Last, tick_global_task_pools);
}
}
/// A dummy type that is [`!Send`](Send), to force systems to run on the main thread.
pub struct NonSendMarker(PhantomData<*mut ()>);

/// A system used to check and advanced our task pools.
///
/// Calls [`tick_global_task_pools_on_main_thread`],
/// and uses [`NonSendMarker`] to ensure that this system runs on the main thread
#[cfg(not(target_arch = "wasm32"))]
fn tick_global_task_pools(_main_thread_marker: Option<NonSend<NonSendMarker>>) {
tick_global_task_pools_on_main_thread();
}

/// Defines a simple way to determine how many threads to use given the number of remaining cores
/// and number of total cores
Expand Down Expand Up @@ -37,7 +84,14 @@ impl TaskPoolThreadAssignmentPolicy {
/// Determine the number of threads to use for this task pool
fn get_number_of_threads(&self, remaining_threads: usize, total_threads: usize) -> usize {
assert!(self.percent >= 0.0);
let mut desired = (total_threads as f32 * self.percent).round() as usize;
let proportion = total_threads as f32 * self.percent;
let mut desired = proportion as usize;

// Equivalent to round() for positive floats without libm requirement for
// no_std compatibility
if proportion - desired as f32 >= 0.5 {
desired += 1;
}

// Limit ourselves to the number of cores available
desired = desired.min(remaining_threads);
Expand All @@ -50,7 +104,7 @@ impl TaskPoolThreadAssignmentPolicy {
}

/// Helper for configuring and creating the default task pools. For end-users who want full control,
/// set up [`TaskPoolPlugin`](super::TaskPoolPlugin)
/// set up [`TaskPoolPlugin`]
#[derive(Clone, Debug)]
pub struct TaskPoolOptions {
/// If the number of physical cores is less than `min_total_threads`, force using
Expand Down Expand Up @@ -208,3 +262,42 @@ impl TaskPoolOptions {
}
}
}

#[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_plugins(TaskPoolPlugin::default());

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();
}
}
1 change: 0 additions & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ js-sys = "0.3"
notify-debouncer-full = { version = "0.4.0", optional = true }

[dev-dependencies]
bevy_core = { path = "../bevy_core", version = "0.15.0-dev" }
bevy_log = { path = "../bevy_log", version = "0.15.0-dev" }

[lints]
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_asset/src/asset_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ mod tests {
use core::num::NonZero;

use crate::{AssetApp, Assets};
use bevy_app::{App, AppExit, Last, Startup, Update};
use bevy_core::TaskPoolPlugin;
use bevy_app::{App, AppExit, Last, Startup, TaskPoolPlugin, Update};
use bevy_ecs::schedule::IntoSystemConfigs;
use bevy_ecs::{
component::Component,
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ mod tests {
AssetPlugin, AssetServer, Assets,
};
use alloc::sync::Arc;
use bevy_app::{App, Update};
use bevy_core::TaskPoolPlugin;
use bevy_app::{App, TaskPoolPlugin, Update};
use bevy_ecs::{
event::EventCursor,
prelude::*,
Expand Down
42 changes: 0 additions & 42 deletions crates/bevy_core/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions crates/bevy_core/README.md

This file was deleted.

Loading
Loading