Skip to content

Commit

Permalink
Cleaned up multi_threaded features so they aren't included when multi…
Browse files Browse the repository at this point in the history
…_threaded isn't turned on
  • Loading branch information
BobG1983 committed Jun 18, 2024
1 parent f139568 commit 50adea1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
8 changes: 6 additions & 2 deletions crates/bevy_ecs/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ pub(crate) use base::EventInstance;
pub use base::{Event, EventId};
pub use bevy_ecs_macros::Event;
pub use collections::{Events, SendBatchIds};
pub use peek_iterators::{EventPeekIterator, EventPeekIteratorWithId, EventPeekParIter};
pub use read_iterators::{EventIterator, EventIteratorWithId, EventParIter};
#[cfg(feature = "multi_threaded")]
pub use peek_iterators::EventPeekParIter;
pub use peek_iterators::{EventPeekIterator, EventPeekIteratorWithId};
#[cfg(feature = "multi_threaded")]
pub use read_iterators::EventParIter;
pub use read_iterators::{EventIterator, EventIteratorWithId};
pub use reader::{EventReader, ManualEventReader};
pub use registry::{EventRegistry, ShouldUpdateEvents};
pub use update::{
Expand Down
10 changes: 6 additions & 4 deletions crates/bevy_ecs/src/event/peek_iterators.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate as bevy_ecs;
use bevy_ecs::{
batching::BatchingStrategy,
event::{Event, EventId, EventInstance, Events, ManualEventReader},
};
#[cfg(feature = "multi_threaded")]
use bevy_ecs::batching::BatchingStrategy;
use bevy_ecs::event::{Event, EventId, EventInstance, Events, ManualEventReader};
use bevy_utils::detailed_trace;
use std::{iter::Chain, slice::Iter};

Expand Down Expand Up @@ -128,11 +127,13 @@ impl<'a, E: Event> ExactSizeIterator for EventPeekIteratorWithId<'a, E> {

/// A parallel iterator over `Event`s.
#[derive(Debug)]
#[cfg(feature = "multi_threaded")]
pub struct EventPeekParIter<'a, E: Event> {
slices: [&'a [EventInstance<E>]; 2],
batching_strategy: BatchingStrategy,
}

#[cfg(feature = "multi_threaded")]
impl<'a, E: Event> EventPeekParIter<'a, E> {
/// Creates a new parallel iterator over `events` that have not yet been seen by `reader`.
pub fn new(reader: &'a ManualEventReader<E>, events: &'a Events<E>) -> Self {
Expand Down Expand Up @@ -227,6 +228,7 @@ impl<'a, E: Event> EventPeekParIter<'a, E> {
}
}

#[cfg(feature = "multi_threaded")]
impl<'a, E: Event> IntoIterator for EventPeekParIter<'a, E> {
type IntoIter = EventPeekIteratorWithId<'a, E>;
type Item = <Self::IntoIter as Iterator>::Item;
Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_ecs/src/event/read_iterators.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate as bevy_ecs;
use bevy_ecs::{
batching::BatchingStrategy,
event::{Event, EventId, EventInstance, Events, ManualEventReader},
};
#[cfg(feature = "multi_threaded")]
use bevy_ecs::batching::BatchingStrategy;
use bevy_ecs::event::{Event, EventId, EventInstance, Events, ManualEventReader};
use bevy_utils::detailed_trace;
use std::{iter::Chain, slice::Iter};

Expand Down Expand Up @@ -141,13 +140,15 @@ impl<'a, E: Event> ExactSizeIterator for EventIteratorWithId<'a, E> {

/// A parallel iterator over `Event`s.
#[derive(Debug)]
#[cfg(feature = "multi_threaded")]
pub struct EventParIter<'a, E: Event> {
reader: &'a mut ManualEventReader<E>,
slices: [&'a [EventInstance<E>]; 2],
batching_strategy: BatchingStrategy,
unread: usize,
}

#[cfg(feature = "multi_threaded")]
impl<'a, E: Event> EventParIter<'a, E> {
/// Creates a new parallel iterator over `events` that have not yet been seen by `reader`.
pub fn new(reader: &'a mut ManualEventReader<E>, events: &'a Events<E>) -> Self {
Expand Down Expand Up @@ -206,12 +207,12 @@ impl<'a, E: Event> EventParIter<'a, E> {
///
/// [`ComputeTaskPool`]: bevy_tasks::ComputeTaskPool
pub fn for_each_with_id<FN: Fn(&'a E, EventId<E>) + Send + Sync + Clone>(mut self, func: FN) {
#[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))]
#[cfg(target_arch = "wasm32")]
{
self.into_iter().for_each(|(e, i)| func(e, i));
}

#[cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded"))]
#[cfg(not(target_arch = "wasm32"))]
{
let pool = bevy_tasks::ComputeTaskPool::get();
let thread_count = pool.thread_num();
Expand Down Expand Up @@ -253,6 +254,7 @@ impl<'a, E: Event> EventParIter<'a, E> {
}
}

#[cfg(feature = "multi_threaded")]
impl<'a, E: Event> IntoIterator for EventParIter<'a, E> {
type IntoIter = EventIteratorWithId<'a, E>;
type Item = <Self::IntoIter as Iterator>::Item;
Expand Down
10 changes: 8 additions & 2 deletions crates/bevy_ecs/src/event/reader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate as bevy_ecs;
#[cfg(feature = "multi_threaded")]
use bevy_ecs::event::{EventParIter, EventPeekParIter};
use bevy_ecs::{
event::{
Event, EventIterator, EventIteratorWithId, EventParIter, EventPeekIterator,
EventPeekIteratorWithId, EventPeekParIter, Events,
Event, EventIterator, EventIteratorWithId, EventPeekIterator, EventPeekIteratorWithId,
Events,
},
system::{Local, Res, SystemParam},
};
Expand Down Expand Up @@ -113,6 +115,7 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
/// assert_eq!(counter.into_inner(), 4950);
/// ```
///
#[cfg(feature = "multi_threaded")]
pub fn par_read(&mut self) -> EventParIter<'_, E> {
self.reader.par_read(&self.events)
}
Expand Down Expand Up @@ -156,6 +159,7 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
/// assert_eq!(counter.into_inner(), 4950);
/// ```
///
#[cfg(feature = "multi_threaded")]
pub fn par_peek(&self) -> EventPeekParIter<'_, E> {
self.reader.par_peek(&self.events)
}
Expand Down Expand Up @@ -290,11 +294,13 @@ impl<E: Event> ManualEventReader<E> {
}

/// See [`EventReader::par_read`]
#[cfg(feature = "multi_threaded")]
pub fn par_read<'a>(&'a mut self, events: &'a Events<E>) -> EventParIter<'a, E> {
EventParIter::new(self, events)
}

/// See [`EventReader::par_peek`]
#[cfg(feature = "multi_threaded")]
pub fn par_peek<'a>(&'a self, events: &'a Events<E>) -> EventPeekParIter<'a, E> {
EventPeekParIter::new(self, events)
}
Expand Down

0 comments on commit 50adea1

Please sign in to comment.