Skip to content

Commit

Permalink
add system to tick local executors on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Oct 4, 2022
1 parent bf883a1 commit f95c417
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/bevy_core/src/lib.rs
Expand Up @@ -4,7 +4,9 @@
mod name;
mod task_pool_options;

use bevy_ecs::schedule::IntoSystemDescriptor;
use bevy_ecs::system::Resource;
use bevy_ecs::world::World;
pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable};
pub use name::*;
pub use task_pool_options::*;
Expand All @@ -17,6 +19,7 @@ pub mod prelude {

use bevy_app::prelude::*;
use bevy_ecs::entity::Entity;
use bevy_tasks::prelude::tick_global_task_pools_on_main_thread;
use bevy_utils::{Duration, HashSet, Instant};
use std::borrow::Cow;
use std::ops::Range;
Expand All @@ -34,6 +37,13 @@ impl Plugin for CorePlugin {
.unwrap_or_default()
.create_default_pools();

// run function in an exclusive system to make sure it runs on main thread
fn tick_local_executors(_world: &mut World) {
tick_global_task_pools_on_main_thread();
}

app.add_system_to_stage(bevy_app::CoreStage::Last, tick.at_end());

app.register_type::<Entity>().register_type::<Name>();

register_rust_types(app);
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_tasks/src/lib.rs
Expand Up @@ -29,7 +29,10 @@ pub mod prelude {
pub use crate::{
iter::ParallelIterator,
slice::{ParallelSlice, ParallelSliceMut},
usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool},
usages::{
tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool,
IoTaskPool,
},
};
}

Expand Down

0 comments on commit f95c417

Please sign in to comment.