Skip to content

Commit

Permalink
Removed lifetime by storing StorageType directly
Browse files Browse the repository at this point in the history
See #2119 to clean this up.
  • Loading branch information
alice-i-cecile committed May 8, 2021
1 parent 161876a commit a38df3c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/bevy_ecs/src/query/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use crate::{
use std::any::TypeId;

impl<'a, T: Component> WorldQuery for EventWriter<'a, T> {
type Fetch = EventWriterFetch<'a, T>;
type Fetch = EventWriterFetch<T>;
type State = EventWriterState<T>;
}

struct EventWriterFetch<'s, T> {
struct EventWriterFetch<T> {
/// EventWriter query parameters require write access to &mut Events<T>
write_fetch: WriteFetch<Events<T>>,
state: &'s EventWriterState<T>,
storage_type: StorageType,
}

impl<'a, T: Component> Fetch<'a> for EventWriterFetch<'a, T> {
impl<'a, T: Component> Fetch<'a> for EventWriterFetch<T> {
/// EventWriter queries return an EventWriter<T> in each item
type Item = EventWriter<'a, T>;
/// This is the corresponding S: FetchState type
type State = EventWriterState<T>;

/// Checks the storage type of the corresponding Events<T> component
fn is_dense(&self) -> bool {
match self.state.event_storage_type {
match self.storage_type {
StorageType::SparseSet => false,
StorageType::Table => true,
}
Expand All @@ -48,7 +48,11 @@ impl<'a, T: Component> Fetch<'a> for EventWriterFetch<'a, T> {
last_change_tick,
change_tick,
),
state,
storage_type: world
.components
.get_info(world.components.get_id(TypeId::of::<Events<T>>()).unwrap())
.unwrap()
.storage_type(),
}
}

Expand Down

0 comments on commit a38df3c

Please sign in to comment.