Skip to content

Commit

Permalink
Fix naming on "tick" Column and ComponentSparseSet methods (bevyengin…
Browse files Browse the repository at this point in the history
…e#9744)

# Objective

- The tick access methods mention "ticks" (as in: plural). Yet, most of
them only access a single tick.

## Solution

- Rename those methods and fix docs to reflect the singular aspect of
the return values

---

## Migration Guide

The following method names were renamed, from `foo_ticks_bar` to
`foo_tick_bar` (`ticks` is now singular, `tick`):
- `ComponentSparseSet::get_added_ticks` → `get_added_tick`
- `ComponentSparseSet::get_changed_ticks` → `get_changed_tick`
- `Column::get_added_ticks` → `get_added_tick`
- `Column::get_changed_ticks` → `get_changed_tick`
- `Column::get_added_ticks_unchecked` → `get_added_tick_unchecked`
- `Column::get_changed_ticks_unchecked` → `get_changed_tick_unchecked`
  • Loading branch information
nicopap authored and Ray Redondo committed Jan 9, 2024
1 parent 90ddea7 commit 67dff51
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl_tick_filter!(
Added,
AddedFetch,
Column::get_added_ticks_slice,
ComponentSparseSet::get_added_ticks
ComponentSparseSet::get_added_tick
);

impl_tick_filter!(
Expand Down Expand Up @@ -612,7 +612,7 @@ impl_tick_filter!(
Changed,
ChangedFetch,
Column::get_changed_ticks_slice,
ComponentSparseSet::get_changed_ticks
ComponentSparseSet::get_changed_tick
);

/// A marker trait to indicate that the filter works at an archetype level.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ impl<const SEND: bool> ResourceData<SEND> {
if self.is_present() {
self.validate_access();
self.column.replace_untracked(Self::ROW, value);
*self.column.get_added_ticks_unchecked(Self::ROW).deref_mut() = change_ticks.added;
*self.column.get_added_tick_unchecked(Self::ROW).deref_mut() = change_ticks.added;
*self
.column
.get_changed_ticks_unchecked(Self::ROW)
.get_changed_tick_unchecked(Self::ROW)
.deref_mut() = change_ticks.changed;
} else {
if !SEND {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ecs/src/storage/sparse_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ impl ComponentSparseSet {
Some((
self.dense.get_data_unchecked(dense_index),
TickCells {
added: self.dense.get_added_ticks_unchecked(dense_index),
changed: self.dense.get_changed_ticks_unchecked(dense_index),
added: self.dense.get_added_tick_unchecked(dense_index),
changed: self.dense.get_changed_tick_unchecked(dense_index),
},
))
}
Expand All @@ -242,15 +242,15 @@ impl ComponentSparseSet {
///
/// Returns `None` if `entity` does not have a component in the sparse set.
#[inline]
pub fn get_added_ticks(&self, entity: Entity) -> Option<&UnsafeCell<Tick>> {
pub fn get_added_tick(&self, entity: Entity) -> Option<&UnsafeCell<Tick>> {
let dense_index = *self.sparse.get(entity.index())? as usize;
#[cfg(debug_assertions)]
assert_eq!(entity, self.entities[dense_index]);
// SAFETY: if the sparse index points to something in the dense vec, it exists
unsafe {
Some(
self.dense
.get_added_ticks_unchecked(TableRow::new(dense_index)),
.get_added_tick_unchecked(TableRow::new(dense_index)),
)
}
}
Expand All @@ -259,15 +259,15 @@ impl ComponentSparseSet {
///
/// Returns `None` if `entity` does not have a component in the sparse set.
#[inline]
pub fn get_changed_ticks(&self, entity: Entity) -> Option<&UnsafeCell<Tick>> {
pub fn get_changed_tick(&self, entity: Entity) -> Option<&UnsafeCell<Tick>> {
let dense_index = *self.sparse.get(entity.index())? as usize;
#[cfg(debug_assertions)]
assert_eq!(entity, self.entities[dense_index]);
// SAFETY: if the sparse index points to something in the dense vec, it exists
unsafe {
Some(
self.dense
.get_changed_ticks_unchecked(TableRow::new(dense_index)),
.get_changed_tick_unchecked(TableRow::new(dense_index)),
)
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_ecs/src/storage/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl Column {
self.data.get_unchecked_mut(row.index())
}

/// Fetches the "added" change detection ticks for the value at `row`.
/// Fetches the "added" change detection tick for the value at `row`.
///
/// Returns `None` if `row` is out of bounds.
///
Expand All @@ -414,11 +414,11 @@ impl Column {
///
/// [`UnsafeCell`]: std::cell::UnsafeCell
#[inline]
pub fn get_added_ticks(&self, row: TableRow) -> Option<&UnsafeCell<Tick>> {
pub fn get_added_tick(&self, row: TableRow) -> Option<&UnsafeCell<Tick>> {
self.added_ticks.get(row.index())
}

/// Fetches the "changed" change detection ticks for the value at `row`.
/// Fetches the "changed" change detection tick for the value at `row`.
///
/// Returns `None` if `row` is out of bounds.
///
Expand All @@ -428,7 +428,7 @@ impl Column {
///
/// [`UnsafeCell`]: std::cell::UnsafeCell
#[inline]
pub fn get_changed_ticks(&self, row: TableRow) -> Option<&UnsafeCell<Tick>> {
pub fn get_changed_tick(&self, row: TableRow) -> Option<&UnsafeCell<Tick>> {
self.changed_ticks.get(row.index())
}

Expand All @@ -445,24 +445,24 @@ impl Column {
}
}

/// Fetches the "added" change detection ticks for the value at `row`. Unlike [`Column::get_added_ticks`]
/// Fetches the "added" change detection tick for the value at `row`. Unlike [`Column::get_added_tick`]
/// this function does not do any bounds checking.
///
/// # Safety
/// `row` must be within the range `[0, self.len())`.
#[inline]
pub unsafe fn get_added_ticks_unchecked(&self, row: TableRow) -> &UnsafeCell<Tick> {
pub unsafe fn get_added_tick_unchecked(&self, row: TableRow) -> &UnsafeCell<Tick> {
debug_assert!(row.index() < self.added_ticks.len());
self.added_ticks.get_unchecked(row.index())
}

/// Fetches the "changed" change detection ticks for the value at `row`. Unlike [`Column::get_changed_ticks`]
/// Fetches the "changed" change detection tick for the value at `row`. Unlike [`Column::get_changed_tick`]
/// this function does not do any bounds checking.
///
/// # Safety
/// `row` must be within the range `[0, self.len())`.
#[inline]
pub unsafe fn get_changed_ticks_unchecked(&self, row: TableRow) -> &UnsafeCell<Tick> {
pub unsafe fn get_changed_tick_unchecked(&self, row: TableRow) -> &UnsafeCell<Tick> {
debug_assert!(row.index() < self.changed_ticks.len());
self.changed_ticks.get_unchecked(row.index())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/world/unsafe_world_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@ unsafe fn get_component_and_ticks(
Some((
components.get_data_unchecked(location.table_row),
TickCells {
added: components.get_added_ticks_unchecked(location.table_row),
changed: components.get_changed_ticks_unchecked(location.table_row),
added: components.get_added_tick_unchecked(location.table_row),
changed: components.get_changed_tick_unchecked(location.table_row),
},
))
}
Expand Down

0 comments on commit 67dff51

Please sign in to comment.