Skip to content

Commit 9ae131f

Browse files
Reverted to SystemParam only form of EventReader etc.
1 parent 0140b63 commit 9ae131f

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

crates/bevy_ecs/src/event.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,12 @@ fn internal_event_reader<'a, T>(
306306
}
307307
}
308308
/// Sends events of type `T`.
309+
#[derive(SystemParam)]
309310
pub struct EventWriter<'a, T: Component> {
310-
events: &'a mut Events<T>,
311-
}
312-
313-
impl<'a, T: Component> SystemParam for EventWriter<'a, T> {
314-
type Fetch = ResMutState<Events<T>>;
311+
events: ResMut<'a, Events<T>>,
315312
}
316313

317314
impl<'a, T: Component> EventWriter<'a, T> {
318-
pub fn new(events: &'a mut Events<T>) -> Self {
319-
EventWriter::<'a, T> { events }
320-
}
321-
322315
pub fn send(&mut self, event: T) {
323316
self.events.send(event);
324317
}
@@ -329,13 +322,10 @@ impl<'a, T: Component> EventWriter<'a, T> {
329322
}
330323

331324
/// Reads events of type `T` in order and tracks which events have already been read.
325+
#[derive(SystemParam)]
332326
pub struct EventReader<'a, T: Component> {
333327
last_event_count: Local<'a, (usize, PhantomData<T>)>,
334-
events: &'a Events<T>,
335-
}
336-
337-
impl<'a, T: Component> SystemParam for EventReader<'a, T> {
338-
type Fetch = ResState<Events<T>>;
328+
events: Res<'a, Events<T>>,
339329
}
340330

341331
impl<'a, T: Component> EventReader<'a, T> {
@@ -361,22 +351,19 @@ impl<'a, T: Component> EventReader<'a, T> {
361351
/// allowing events to accumulate on your components or resources until consumed.
362352
/// Note: due to the draining nature of this reader, you probably only want one
363353
/// EventConsumer per event storage location + event type combination.
354+
#[derive(SystemParam)]
364355
pub struct EventConsumer<'a, T: Component> {
365-
events: &'a mut Events<T>,
366-
}
367-
368-
impl<'a, T: Component> SystemParam for EventConsumer<'a, T> {
369-
type Fetch = ResMutState<Events<T>>;
356+
events: ResMut<'a, Events<T>>,
370357
}
371358

372359
impl<'a, T: Component> EventConsumer<'a, T> {
373360
/// Drains all available events this EventConsumer has access to into an iterator
374-
pub fn drain(self) -> impl DoubleEndedIterator<Item = T> + 'a {
361+
pub fn drain(self) -> impl DoubleEndedIterator<Item = T> {
375362
self.events.drain()
376363
}
377364

378365
/// Drains all available events this EventConsumer has access to into an iterator and returns the id
379-
pub fn drain_with_id(self) -> impl DoubleEndedIterator<Item = (T, EventId<T>)> + 'a {
366+
pub fn drain_with_id(self) -> impl DoubleEndedIterator<Item = (T, EventId<T>)> {
380367
self.events.drain_with_id()
381368
}
382369
}

0 commit comments

Comments
 (0)