Skip to content

Commit

Permalink
Deprecate Events::oldest_id (#15658)
Browse files Browse the repository at this point in the history
# Objective

Fixes #15617 

## Solution

The original author confirmed it was not intentional that both these
methods exist.

They do the same, one has the better implementation and the other the
better name.

## Testing

I just ran the unit tests of the module.

---

## Migration Guide

- Change usages of `Events::oldest_id` to `Events::oldest_event_count`
- If `Events::oldest_id` was used to get the actual oldest
`EventId::id`, note that the deprecated method never reliably did that
in the first place as the buffers may contain no id currently.
  • Loading branch information
urben1680 authored Oct 5, 2024
1 parent ddd4b4d commit 2e89e98
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions crates/bevy_ecs/src/event/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ impl<E: Event> Default for Events<E> {
impl<E: Event> Events<E> {
/// Returns the index of the oldest event stored in the event buffer.
pub fn oldest_event_count(&self) -> usize {
self.events_a
.start_event_count
.min(self.events_b.start_event_count)
self.events_a.start_event_count
}

/// "Sends" an `event` by writing it to the current event buffer.
Expand Down Expand Up @@ -279,7 +277,7 @@ impl<E: Event> Events<E> {

/// Get a specific event by id if it still exists in the events buffer.
pub fn get_event(&self, id: usize) -> Option<(&E, EventId<E>)> {
if id < self.oldest_id() {
if id < self.oldest_event_count() {
return None;
}

Expand All @@ -291,11 +289,6 @@ impl<E: Event> Events<E> {
.map(|instance| (&instance.event, instance.event_id))
}

/// Oldest id still in the events buffer.
pub fn oldest_id(&self) -> usize {
self.events_a.start_event_count
}

/// Which event buffer is this event id a part of.
fn sequence(&self, id: usize) -> &EventSequence<E> {
if id < self.events_b.start_event_count {
Expand Down

0 comments on commit 2e89e98

Please sign in to comment.