Fix doc_markdown
lints in bevy_ecs
(#3473)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time. This PR fixes lints in the `bevy_ecs` crate.
This commit is contained in:
parent
2d301ea0ea
commit
507441d96f
@ -470,7 +470,7 @@ impl Archetypes {
|
|||||||
/// `table_components` and `sparse_set_components` must be sorted
|
/// `table_components` and `sparse_set_components` must be sorted
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// TableId must exist in tables
|
/// [`TableId`] must exist in tables
|
||||||
pub(crate) fn get_id_or_insert(
|
pub(crate) fn get_id_or_insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
table_id: TableId,
|
table_id: TableId,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Types for handling [`Bundle`]s.
|
//! Types for handling [`Bundle`]s.
|
||||||
//!
|
//!
|
||||||
//! This module contains the `Bundle` trait and some other helper types.
|
//! This module contains the [`Bundle`] trait and some other helper types.
|
||||||
|
|
||||||
pub use bevy_ecs_macros::Bundle;
|
pub use bevy_ecs_macros::Bundle;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ use crate::{
|
|||||||
use bevy_ecs_macros::all_tuples;
|
use bevy_ecs_macros::all_tuples;
|
||||||
use std::{any::TypeId, collections::HashMap};
|
use std::{any::TypeId, collections::HashMap};
|
||||||
|
|
||||||
/// An ordered collection of components.
|
/// An ordered collection of [`Component`]s.
|
||||||
///
|
///
|
||||||
/// Commonly used for spawning entities and adding and removing components in bulk. This
|
/// Commonly used for spawning entities and adding and removing components in bulk. This
|
||||||
/// trait is automatically implemented for tuples of components: `(ComponentA, ComponentB)`
|
/// trait is automatically implemented for tuples of components: `(ComponentA, ComponentB)`
|
||||||
@ -71,33 +71,32 @@ use std::{any::TypeId, collections::HashMap};
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - [Bundle::component_ids] must return the ComponentId for each component type in the bundle, in the
|
/// - [`Bundle::component_ids`] must return the [`ComponentId`] for each component type in the
|
||||||
/// _exact_ order that [Bundle::get_components] is called.
|
/// bundle, in the _exact_ order that [`Bundle::get_components`] is called.
|
||||||
/// - [Bundle::from_components] must call `func` exactly once for each [ComponentId] returned by
|
/// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
|
||||||
/// [Bundle::component_ids].
|
/// [`Bundle::component_ids`].
|
||||||
pub unsafe trait Bundle: Send + Sync + 'static {
|
pub unsafe trait Bundle: Send + Sync + 'static {
|
||||||
/// Gets this [Bundle]'s component ids, in the order of this bundle's Components
|
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
|
||||||
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId>;
|
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId>;
|
||||||
|
|
||||||
/// Calls `func`, which should return data for each component in the bundle, in the order of
|
/// Calls `func`, which should return data for each component in the bundle, in the order of
|
||||||
/// this bundle's Components
|
/// this bundle's [`Component`]s
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Caller must return data for each component in the bundle, in the order of this bundle's
|
/// Caller must return data for each component in the bundle, in the order of this bundle's
|
||||||
/// Components
|
/// [`Component`]s
|
||||||
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
|
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
||||||
/// Calls `func` on each value, in the order of this bundle's Components. This will
|
/// Calls `func` on each value, in the order of this bundle's [`Component`]s. This will
|
||||||
/// "mem::forget" the bundle fields, so callers are responsible for dropping the fields if
|
/// [`std::mem::forget`] the bundle fields, so callers are responsible for dropping the fields
|
||||||
/// that is desirable.
|
/// if that is desirable.
|
||||||
fn get_components(self, func: impl FnMut(*mut u8));
|
fn get_components(self, func: impl FnMut(*mut u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! tuple_impl {
|
macro_rules! tuple_impl {
|
||||||
($($name: ident),*) => {
|
($($name: ident),*) => {
|
||||||
/// SAFE: Component is returned in tuple-order. [Bundle::from_components] and [Bundle::get_components] use tuple-order
|
|
||||||
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
|
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId> {
|
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId> {
|
||||||
@ -258,7 +257,8 @@ impl BundleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `table` must be the "new" table for `entity`. `table_row` must have space allocated for the `entity`, `bundle` must match this BundleInfo's type
|
/// `table` must be the "new" table for `entity`. `table_row` must have space allocated for the
|
||||||
|
/// `entity`, `bundle` must match this [`BundleInfo`]'s type
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
unsafe fn write_components<T: Bundle>(
|
unsafe fn write_components<T: Bundle>(
|
||||||
@ -301,9 +301,9 @@ impl BundleInfo {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the same
|
/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the
|
||||||
/// [ArchetypeId], in the event that adding the given bundle does not result in an Archetype change.
|
/// same [`ArchetypeId`], in the event that adding the given bundle does not result in an
|
||||||
/// Results are cached in the Archetype Graph to avoid redundant work.
|
/// [`Archetype`] change. Results are cached in the [`Archetype`] graph to avoid redundant work.
|
||||||
pub(crate) fn add_bundle_to_archetype(
|
pub(crate) fn add_bundle_to_archetype(
|
||||||
&self,
|
&self,
|
||||||
archetypes: &mut Archetypes,
|
archetypes: &mut Archetypes,
|
||||||
@ -409,8 +409,8 @@ pub(crate) enum InsertBundleResult<'a> {
|
|||||||
|
|
||||||
impl<'a, 'b> BundleInserter<'a, 'b> {
|
impl<'a, 'b> BundleInserter<'a, 'b> {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `entity` must currently exist in the source archetype for this inserter. `archetype_index` must be `entity`'s location in the archetype.
|
/// `entity` must currently exist in the source archetype for this inserter. `archetype_index`
|
||||||
/// `T` must match this BundleInfo's type
|
/// must be `entity`'s location in the archetype. `T` must match this [`BundleInfo`]'s type
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn insert<T: Bundle>(
|
pub unsafe fn insert<T: Bundle>(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -538,7 +538,7 @@ impl<'a, 'b> BundleSpawner<'a, 'b> {
|
|||||||
self.table.reserve(additional);
|
self.table.reserve(additional);
|
||||||
}
|
}
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `entity` must be allocated (but non existent), `T` must match this BundleInfo's type
|
/// `entity` must be allocated (but non-existent), `T` must match this [`BundleInfo`]'s type
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn spawn_non_existent<T: Bundle>(
|
pub unsafe fn spawn_non_existent<T: Bundle>(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -562,7 +562,7 @@ impl<'a, 'b> BundleSpawner<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `T` must match this BundleInfo's type
|
/// `T` must match this [`BundleInfo`]'s type
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn spawn<T: Bundle>(&mut self, bundle: T) -> Entity {
|
pub unsafe fn spawn<T: Bundle>(&mut self, bundle: T) -> Entity {
|
||||||
let entity = self.entities.alloc();
|
let entity = self.entities.alloc();
|
||||||
@ -612,7 +612,7 @@ impl Bundles {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `component_id` must be valid [ComponentId]'s
|
/// `component_id` must be valid [`ComponentId`]'s
|
||||||
unsafe fn initialize_bundle(
|
unsafe fn initialize_bundle(
|
||||||
bundle_type_name: &'static str,
|
bundle_type_name: &'static str,
|
||||||
component_ids: Vec<ComponentId>,
|
component_ids: Vec<ComponentId>,
|
||||||
|
@ -289,7 +289,7 @@ impl Components {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `id` must be a valid [ComponentId]
|
/// `id` must be a valid [`ComponentId`]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn get_info_unchecked(&self, id: ComponentId) -> &ComponentInfo {
|
pub unsafe fn get_info_unchecked(&self, id: ComponentId) -> &ComponentInfo {
|
||||||
debug_assert!(id.index() < self.components.len());
|
debug_assert!(id.index() < self.components.len());
|
||||||
|
@ -493,9 +493,9 @@ impl Entities {
|
|||||||
/// `reserve_entities`, then initializes each one using the supplied function.
|
/// `reserve_entities`, then initializes each one using the supplied function.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Flush _must_ set the entity location to the correct ArchetypeId for the given Entity
|
/// Flush _must_ set the entity location to the correct [`ArchetypeId`] for the given [`Entity`]
|
||||||
/// each time init is called. This _can_ be ArchetypeId::INVALID, provided the Entity has
|
/// each time init is called. This _can_ be [`ArchetypeId::INVALID`], provided the [`Entity`]
|
||||||
/// not been assigned to an Archetype.
|
/// has not been assigned to an [`Archetype`][crate::archetype::Archetype].
|
||||||
pub unsafe fn flush(&mut self, mut init: impl FnMut(Entity, &mut EntityLocation)) {
|
pub unsafe fn flush(&mut self, mut init: impl FnMut(Entity, &mut EntityLocation)) {
|
||||||
let free_cursor = self.free_cursor.get_mut();
|
let free_cursor = self.free_cursor.get_mut();
|
||||||
let current_free_cursor = *free_cursor;
|
let current_free_cursor = *free_cursor;
|
||||||
|
@ -67,7 +67,7 @@ enum State {
|
|||||||
/// [`Events::update`] exactly once per update/frame.
|
/// [`Events::update`] exactly once per update/frame.
|
||||||
///
|
///
|
||||||
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
|
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
|
||||||
/// [`App::add_event`]. [EventReader]s are expected to read events from this collection at
|
/// [`App::add_event`]. [`EventReader`]s are expected to read events from this collection at
|
||||||
/// least once per loop/frame.
|
/// least once per loop/frame.
|
||||||
/// Events will persist across a single frame boundary and so ordering of event producers and
|
/// Events will persist across a single frame boundary and so ordering of event producers and
|
||||||
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
|
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
|
||||||
@ -103,16 +103,16 @@ enum State {
|
|||||||
///
|
///
|
||||||
/// # Details
|
/// # Details
|
||||||
///
|
///
|
||||||
/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and
|
/// [`Events`] is implemented using a double buffer. Each call to [`Events::update`] swaps buffers
|
||||||
/// clears out the oldest buffer. [EventReader]s that read at least once per update will never drop
|
/// and clears out the oldest buffer. [`EventReader`]s that read at least once per update will never
|
||||||
/// events. [EventReader]s that read once within two updates might still receive some events.
|
/// drop events. [`EventReader`]s that read once within two updates might still receive some events.
|
||||||
/// [EventReader]s that read after two updates are guaranteed to drop all events that occurred
|
/// [`EventReader`]s that read after two updates are guaranteed to drop all events that occurred
|
||||||
/// before those updates.
|
/// before those updates.
|
||||||
///
|
///
|
||||||
/// The buffers in [Events] will grow indefinitely if [Events::update] is never called.
|
/// The buffers in [`Events`] will grow indefinitely if [`Events::update`] is never called.
|
||||||
///
|
///
|
||||||
/// An alternative call pattern would be to call [Events::update] manually across frames to control
|
/// An alternative call pattern would be to call [`Events::update`] manually across frames to
|
||||||
/// when events are cleared.
|
/// control when events are cleared.
|
||||||
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
|
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
|
||||||
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
|
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
|
||||||
///
|
///
|
||||||
@ -254,9 +254,9 @@ fn internal_event_reader<'a, T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, T: Resource> EventReader<'w, 's, T> {
|
impl<'w, 's, T: Resource> EventReader<'w, 's, T> {
|
||||||
/// Iterates over the events this EventReader has not seen yet. This updates the EventReader's
|
/// Iterates over the events this [`EventReader`] has not seen yet. This updates the
|
||||||
/// event counter, which means subsequent event reads will not include events that happened
|
/// [`EventReader`]'s event counter, which means subsequent event reads will not include events
|
||||||
/// before now.
|
/// that happened before now.
|
||||||
pub fn iter(&mut self) -> impl DoubleEndedIterator<Item = &T> {
|
pub fn iter(&mut self) -> impl DoubleEndedIterator<Item = &T> {
|
||||||
self.iter_with_id().map(|(event, _id)| event)
|
self.iter_with_id().map(|(event, _id)| event)
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ impl<'w, 's, T: Resource> EventReader<'w, 's, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Resource> Events<T> {
|
impl<T: Resource> Events<T> {
|
||||||
/// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read
|
/// "Sends" an `event` by writing it to the current event buffer. [`EventReader`]s can then read
|
||||||
/// the event.
|
/// the event.
|
||||||
pub fn send(&mut self, event: T) {
|
pub fn send(&mut self, event: T) {
|
||||||
let event_id = EventId {
|
let event_id = EventId {
|
||||||
@ -290,7 +290,7 @@ impl<T: Resource> Events<T> {
|
|||||||
self.event_count += 1;
|
self.event_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a new [ManualEventReader]. This will include all events already in the event buffers.
|
/// Gets a new [`ManualEventReader`]. This will include all events already in the event buffers.
|
||||||
pub fn get_reader(&self) -> ManualEventReader<T> {
|
pub fn get_reader(&self) -> ManualEventReader<T> {
|
||||||
ManualEventReader {
|
ManualEventReader {
|
||||||
last_event_count: 0,
|
last_event_count: 0,
|
||||||
@ -298,8 +298,8 @@ impl<T: Resource> Events<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It
|
/// Gets a new [`ManualEventReader`]. This will ignore all events already in the event buffers.
|
||||||
/// will read all future events.
|
/// It will read all future events.
|
||||||
pub fn get_reader_current(&self) -> ManualEventReader<T> {
|
pub fn get_reader_current(&self) -> ManualEventReader<T> {
|
||||||
ManualEventReader {
|
ManualEventReader {
|
||||||
last_event_count: self.event_count,
|
last_event_count: self.event_count,
|
||||||
@ -324,7 +324,7 @@ impl<T: Resource> Events<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A system that calls [Events::update] once per frame.
|
/// A system that calls [`Events::update`] once per frame.
|
||||||
pub fn update_system(mut events: ResMut<Self>) {
|
pub fn update_system(mut events: ResMut<Self>) {
|
||||||
events.update();
|
events.update();
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ use std::{
|
|||||||
///
|
///
|
||||||
/// See [`Query`](crate::system::Query) for a primer on queries.
|
/// See [`Query`](crate::system::Query) for a primer on queries.
|
||||||
///
|
///
|
||||||
/// # Basic WorldQueries
|
/// # Basic [`WorldQuery`]'s
|
||||||
///
|
///
|
||||||
/// Here is a small list of the most important world queries to know about where `C` stands for a
|
/// Here is a small list of the most important world queries to know about where `C` stands for a
|
||||||
/// [`Component`] and `WQ` stands for a [`WorldQuery`]:
|
/// [`Component`] and `WQ` stands for a [`WorldQuery`]:
|
||||||
/// - `&C`: Queries immutably for the component `C`
|
/// - `&C`: Queries immutably for the component `C`
|
||||||
/// - `&mut C`: Queries mutably for the component `C`
|
/// - `&mut C`: Queries mutably for the component `C`
|
||||||
/// - `Option<WQ>`: Queries the inner WorldQuery `WQ` but instead of discarding the entity if the world
|
/// - `Option<WQ>`: Queries the inner [`WorldQuery`] `WQ` but instead of discarding the entity if the world
|
||||||
/// query fails it returns [`None`]. See [`Query`](crate::system::Query).
|
/// query fails it returns [`None`]. See [`Query`](crate::system::Query).
|
||||||
/// - `(WQ1, WQ2, ...)`: Queries all contained world queries allowing to query for more than one thing.
|
/// - `(WQ1, WQ2, ...)`: Queries all contained world queries allowing to query for more than one thing.
|
||||||
/// This is the `And` operator for filters. See [`Or`].
|
/// This is the `And` operator for filters. See [`Or`].
|
||||||
@ -57,8 +57,8 @@ pub trait Fetch<'world, 'state>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `state` must have been initialized (via [FetchState::init]) using the same `world` passed in
|
/// `state` must have been initialized (via [`FetchState::init`]) using the same `world` passed
|
||||||
/// to this function.
|
/// in to this function.
|
||||||
unsafe fn init(
|
unsafe fn init(
|
||||||
world: &World,
|
world: &World,
|
||||||
state: &Self::State,
|
state: &Self::State,
|
||||||
@ -78,8 +78,8 @@ pub trait Fetch<'world, 'state>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `archetype` and `tables` must be from the [`World`] [`Fetch::init`] was called on. `state` must
|
/// `archetype` and `tables` must be from the [`World`] [`Fetch::init`] was called on. `state`
|
||||||
/// be the [Self::State] this was initialized with.
|
/// must be the [`Self::State`] this was initialized with.
|
||||||
unsafe fn set_archetype(&mut self, state: &Self::State, archetype: &Archetype, tables: &Tables);
|
unsafe fn set_archetype(&mut self, state: &Self::State, archetype: &Archetype, tables: &Tables);
|
||||||
|
|
||||||
/// Adjusts internal state to account for the next [`Table`]. This will always be called on tables
|
/// Adjusts internal state to account for the next [`Table`]. This will always be called on tables
|
||||||
@ -88,7 +88,7 @@ pub trait Fetch<'world, 'state>: Sized {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `table` must be from the [`World`] [`Fetch::init`] was called on. `state` must be the
|
/// `table` must be from the [`World`] [`Fetch::init`] was called on. `state` must be the
|
||||||
/// [Self::State] this was initialized with.
|
/// [`Self::State`] this was initialized with.
|
||||||
unsafe fn set_table(&mut self, state: &Self::State, table: &Table);
|
unsafe fn set_table(&mut self, state: &Self::State, table: &Table);
|
||||||
|
|
||||||
/// Fetch [`Self::Item`] for the given `archetype_index` in the current [`Archetype`]. This must
|
/// Fetch [`Self::Item`] for the given `archetype_index` in the current [`Archetype`]. This must
|
||||||
@ -677,7 +677,7 @@ pub struct OptionFetch<T> {
|
|||||||
matches: bool,
|
matches: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: OptionFetch is read only because T is read only
|
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
|
||||||
unsafe impl<T: ReadOnlyFetch> ReadOnlyFetch for OptionFetch<T> {}
|
unsafe impl<T: ReadOnlyFetch> ReadOnlyFetch for OptionFetch<T> {}
|
||||||
|
|
||||||
/// The [`FetchState`] of `Option<T>`.
|
/// The [`FetchState`] of `Option<T>`.
|
||||||
|
@ -35,7 +35,7 @@ where
|
|||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
|
||||||
/// with a mismatched WorldId is unsound.
|
/// with a mismatched [`WorldId`] is unsound.
|
||||||
pub(crate) unsafe fn new(
|
pub(crate) unsafe fn new(
|
||||||
world: &'w World,
|
world: &'w World,
|
||||||
query_state: &'s QueryState<Q, F>,
|
query_state: &'s QueryState<Q, F>,
|
||||||
@ -174,8 +174,8 @@ where
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a
|
||||||
/// with a mismatched WorldId is unsound.
|
/// `world` with a mismatched [`WorldId`] is unsound.
|
||||||
pub(crate) unsafe fn new(
|
pub(crate) unsafe fn new(
|
||||||
world: &'w World,
|
world: &'w World,
|
||||||
query_state: &'s QueryState<Q, F>,
|
query_state: &'s QueryState<Q, F>,
|
||||||
|
@ -391,7 +391,7 @@ where
|
|||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
||||||
/// with a mismatched WorldId is unsound.
|
/// with a mismatched [`WorldId`] is unsound.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) unsafe fn iter_unchecked_manual<'w, 's, QF: Fetch<'w, 's, State = Q::State>>(
|
pub(crate) unsafe fn iter_unchecked_manual<'w, 's, QF: Fetch<'w, 's, State = Q::State>>(
|
||||||
&'s self,
|
&'s self,
|
||||||
@ -411,7 +411,7 @@ where
|
|||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
||||||
/// with a mismatched WorldId is unsound.
|
/// with a mismatched [`WorldId`] is unsound.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) unsafe fn iter_combinations_unchecked_manual<
|
pub(crate) unsafe fn iter_combinations_unchecked_manual<
|
||||||
'w,
|
'w,
|
||||||
@ -450,7 +450,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Runs `func` on each query result for the given [`World`]. This is faster than the equivalent
|
/// Runs `func` on each query result for the given [`World`]. This is faster than the equivalent
|
||||||
/// iter_mut() method, but cannot be chained like a normal [`Iterator`].
|
/// `iter_mut()` method, but cannot be chained like a normal [`Iterator`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn for_each_mut<'w, 's, FN: FnMut(<Q::Fetch as Fetch<'w, 's>>::Item)>(
|
pub fn for_each_mut<'w, 's, FN: FnMut(<Q::Fetch as Fetch<'w, 's>>::Item)>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
@ -590,7 +590,7 @@ where
|
|||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
||||||
/// with a mismatched WorldId is unsound.
|
/// with a mismatched [`WorldId`] is unsound.
|
||||||
pub(crate) unsafe fn for_each_unchecked_manual<
|
pub(crate) unsafe fn for_each_unchecked_manual<
|
||||||
'w,
|
'w,
|
||||||
's,
|
's,
|
||||||
@ -650,7 +650,7 @@ where
|
|||||||
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
|
||||||
/// have unique access to the components they query.
|
/// have unique access to the components they query.
|
||||||
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
|
||||||
/// with a mismatched WorldId is unsound.
|
/// with a mismatched [`WorldId`] is unsound.
|
||||||
pub(crate) unsafe fn par_for_each_unchecked_manual<
|
pub(crate) unsafe fn par_for_each_unchecked_manual<
|
||||||
'w,
|
'w,
|
||||||
's,
|
's,
|
||||||
|
@ -41,8 +41,8 @@ impl ParallelSystemExecutor for SingleThreadedExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SingleThreadedExecutor {
|
impl SingleThreadedExecutor {
|
||||||
/// Calls system.new_archetype() for each archetype added since the last call to
|
/// Calls `system.new_archetype()` for each archetype added since the last call to
|
||||||
/// [update_archetypes] and updates cached archetype_component_access.
|
/// `update_archetypes` and updates cached `archetype_component_access`.
|
||||||
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
|
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
|
||||||
let archetypes = world.archetypes();
|
let archetypes = world.archetypes();
|
||||||
let new_generation = archetypes.generation();
|
let new_generation = archetypes.generation();
|
||||||
|
@ -154,8 +154,8 @@ impl ParallelSystemExecutor for ParallelExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ParallelExecutor {
|
impl ParallelExecutor {
|
||||||
/// Calls system.new_archetype() for each archetype added since the last call to
|
/// Calls `system.new_archetype()` for each archetype added since the last call to
|
||||||
/// [update_archetypes] and updates cached archetype_component_access.
|
/// `update_archetypes` and updates cached `archetype_component_access`.
|
||||||
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
|
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
let span = bevy_utils::tracing::info_span!("update_archetypes");
|
let span = bevy_utils::tracing::info_span!("update_archetypes");
|
||||||
|
@ -282,7 +282,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::set], but if there is already a next state, it will be overwritten
|
/// Same as [`Self::set`], but if there is already a next state, it will be overwritten
|
||||||
/// instead of failing
|
/// instead of failing
|
||||||
pub fn overwrite_set(&mut self, state: T) -> Result<(), StateError> {
|
pub fn overwrite_set(&mut self, state: T) -> Result<(), StateError> {
|
||||||
if self.stack.last().unwrap() == &state {
|
if self.stack.last().unwrap() == &state {
|
||||||
@ -309,7 +309,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::replace], but if there is already a next state, it will be overwritten
|
/// Same as [`Self::replace`], but if there is already a next state, it will be overwritten
|
||||||
/// instead of failing
|
/// instead of failing
|
||||||
pub fn overwrite_replace(&mut self, state: T) -> Result<(), StateError> {
|
pub fn overwrite_replace(&mut self, state: T) -> Result<(), StateError> {
|
||||||
if self.stack.last().unwrap() == &state {
|
if self.stack.last().unwrap() == &state {
|
||||||
@ -320,7 +320,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::set], but does a push operation instead of a next operation
|
/// Same as [`Self::set`], but does a push operation instead of a next operation
|
||||||
pub fn push(&mut self, state: T) -> Result<(), StateError> {
|
pub fn push(&mut self, state: T) -> Result<(), StateError> {
|
||||||
if self.stack.last().unwrap() == &state {
|
if self.stack.last().unwrap() == &state {
|
||||||
return Err(StateError::AlreadyInState);
|
return Err(StateError::AlreadyInState);
|
||||||
@ -334,7 +334,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::push], but if there is already a next state, it will be overwritten
|
/// Same as [`Self::push`], but if there is already a next state, it will be overwritten
|
||||||
/// instead of failing
|
/// instead of failing
|
||||||
pub fn overwrite_push(&mut self, state: T) -> Result<(), StateError> {
|
pub fn overwrite_push(&mut self, state: T) -> Result<(), StateError> {
|
||||||
if self.stack.last().unwrap() == &state {
|
if self.stack.last().unwrap() == &state {
|
||||||
@ -345,7 +345,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::set], but does a pop operation instead of a set operation
|
/// Same as [`Self::set`], but does a pop operation instead of a set operation
|
||||||
pub fn pop(&mut self) -> Result<(), StateError> {
|
pub fn pop(&mut self) -> Result<(), StateError> {
|
||||||
if self.scheduled.is_some() {
|
if self.scheduled.is_some() {
|
||||||
return Err(StateError::StateAlreadyQueued);
|
return Err(StateError::StateAlreadyQueued);
|
||||||
@ -359,7 +359,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [Self::pop], but if there is already a next state, it will be overwritten
|
/// Same as [`Self::pop`], but if there is already a next state, it will be overwritten
|
||||||
/// instead of failing
|
/// instead of failing
|
||||||
pub fn overwrite_pop(&mut self) -> Result<(), StateError> {
|
pub fn overwrite_pop(&mut self) -> Result<(), StateError> {
|
||||||
if self.stack.len() == 1 {
|
if self.stack.len() == 1 {
|
||||||
|
@ -105,11 +105,11 @@ impl BlobVec {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// - index must be in-bounds
|
/// - index must be in-bounds
|
||||||
/// - the memory in the `BlobVec` starting at index `index`, of a size matching this `BlobVec`'s
|
/// - the memory in the [`BlobVec`] starting at index `index`, of a size matching this
|
||||||
/// `item_layout`, must have been previously initialized with an item matching this `BlobVec`'s
|
/// [`BlobVec`]'s `item_layout`, must have been previously initialized with an item matching
|
||||||
/// item_layout
|
/// this [`BlobVec`]'s `item_layout`
|
||||||
/// - the memory at `*value` must also be previously initialized with an item matching this
|
/// - the memory at `*value` must also be previously initialized with an item matching this
|
||||||
/// `BlobVec`'s `item_layout`
|
/// [`BlobVec`]'s `item_layout`
|
||||||
/// - the item that was stored in `*value` is left logically uninitialised/moved out of after
|
/// - the item that was stored in `*value` is left logically uninitialised/moved out of after
|
||||||
/// calling this function, and as such should not be used or dropped by the caller.
|
/// calling this function, and as such should not be used or dropped by the caller.
|
||||||
pub unsafe fn replace_unchecked(&mut self, index: usize, value: *mut u8) {
|
pub unsafe fn replace_unchecked(&mut self, index: usize, value: *mut u8) {
|
||||||
@ -139,9 +139,9 @@ impl BlobVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// len must be <= capacity. if length is decreased, "out of bounds" items must be dropped.
|
/// `len` must be <= `capacity`. if length is decreased, "out of bounds" items must be dropped.
|
||||||
/// Newly added items must be immediately populated with valid values and length must be
|
/// Newly added items must be immediately populated with valid values and length must be
|
||||||
/// increased. For better unwind safety, call [BlobVec::set_len] _after_ populating a new
|
/// increased. For better unwind safety, call [`BlobVec::set_len`] _after_ populating a new
|
||||||
/// value.
|
/// value.
|
||||||
pub unsafe fn set_len(&mut self, len: usize) {
|
pub unsafe fn set_len(&mut self, len: usize) {
|
||||||
debug_assert!(len <= self.capacity());
|
debug_assert!(len <= self.capacity());
|
||||||
@ -149,11 +149,11 @@ impl BlobVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Performs a "swap remove" at the given `index`, which removes the item at `index` and moves
|
/// Performs a "swap remove" at the given `index`, which removes the item at `index` and moves
|
||||||
/// the last item in the [BlobVec] to `index` (if `index` is not the last item). It is the
|
/// the last item in the [`BlobVec`] to `index` (if `index` is not the last item). It is the
|
||||||
/// caller's responsibility to drop the returned pointer, if that is desirable.
|
/// caller's responsibility to drop the returned pointer, if that is desirable.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// It is the caller's responsibility to ensure that `index` is < self.len()
|
/// It is the caller's responsibility to ensure that `index` is < `self.len()`
|
||||||
/// Callers should _only_ access the returned pointer immediately after calling this function.
|
/// Callers should _only_ access the returned pointer immediately after calling this function.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn swap_remove_and_forget_unchecked(&mut self, index: usize) -> *mut u8 {
|
pub unsafe fn swap_remove_and_forget_unchecked(&mut self, index: usize) -> *mut u8 {
|
||||||
@ -230,15 +230,15 @@ impl Drop for BlobVec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html
|
/// From <https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html>
|
||||||
fn array_layout(layout: &Layout, n: usize) -> Option<Layout> {
|
fn array_layout(layout: &Layout, n: usize) -> Option<Layout> {
|
||||||
let (array_layout, offset) = repeat_layout(layout, n)?;
|
let (array_layout, offset) = repeat_layout(layout, n)?;
|
||||||
debug_assert_eq!(layout.size(), offset);
|
debug_assert_eq!(layout.size(), offset);
|
||||||
Some(array_layout)
|
Some(array_layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace with Layout::repeat if/when it stabilizes
|
// TODO: replace with `Layout::repeat` if/when it stabilizes
|
||||||
/// From https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html
|
/// From <https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html>
|
||||||
fn repeat_layout(layout: &Layout, n: usize) -> Option<(Layout, usize)> {
|
fn repeat_layout(layout: &Layout, n: usize) -> Option<(Layout, usize)> {
|
||||||
// This cannot overflow. Quoting from the invariant of Layout:
|
// This cannot overflow. Quoting from the invariant of Layout:
|
||||||
// > `size`, when rounded up to the nearest multiple of `align`,
|
// > `size`, when rounded up to the nearest multiple of `align`,
|
||||||
@ -257,7 +257,7 @@ fn repeat_layout(layout: &Layout, n: usize) -> Option<(Layout, usize)> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html
|
/// From <https://doc.rust-lang.org/beta/src/core/alloc/layout.rs.html>
|
||||||
const fn padding_needed_for(layout: &Layout, align: usize) -> usize {
|
const fn padding_needed_for(layout: &Layout, align: usize) -> usize {
|
||||||
let len = layout.size();
|
let len = layout.size();
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ mod tests {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `blob_vec` must have a layout that matches Layout::new::<T>()
|
/// `blob_vec` must have a layout that matches `Layout::new::<T>()`
|
||||||
unsafe fn push<T>(blob_vec: &mut BlobVec, mut value: T) {
|
unsafe fn push<T>(blob_vec: &mut BlobVec, mut value: T) {
|
||||||
let index = blob_vec.push_uninit();
|
let index = blob_vec.push_uninit();
|
||||||
blob_vec.initialize_unchecked(index, (&mut value as *mut T).cast::<u8>());
|
blob_vec.initialize_unchecked(index, (&mut value as *mut T).cast::<u8>());
|
||||||
@ -305,7 +305,7 @@ mod tests {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `blob_vec` must have a layout that matches Layout::new::<T>()
|
/// `blob_vec` must have a layout that matches `Layout::new::<T>()`
|
||||||
unsafe fn swap_remove<T>(blob_vec: &mut BlobVec, index: usize) -> T {
|
unsafe fn swap_remove<T>(blob_vec: &mut BlobVec, index: usize) -> T {
|
||||||
assert!(index < blob_vec.len());
|
assert!(index < blob_vec.len());
|
||||||
let value = blob_vec.swap_remove_and_forget_unchecked(index);
|
let value = blob_vec.swap_remove_and_forget_unchecked(index);
|
||||||
@ -314,8 +314,8 @@ mod tests {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `blob_vec` must have a layout that matches Layout::new::<T>(), it most store a valid T value
|
/// `blob_vec` must have a layout that matches `Layout::new::<T>()`, it most store a valid `T`
|
||||||
/// at the given `index`
|
/// value at the given `index`
|
||||||
unsafe fn get_mut<T>(blob_vec: &mut BlobVec, index: usize) -> &mut T {
|
unsafe fn get_mut<T>(blob_vec: &mut BlobVec, index: usize) -> &mut T {
|
||||||
assert!(index < blob_vec.len());
|
assert!(index < blob_vec.len());
|
||||||
&mut *blob_vec.get_unchecked(index).cast::<T>()
|
&mut *blob_vec.get_unchecked(index).cast::<T>()
|
||||||
|
@ -397,9 +397,9 @@ macro_rules! impl_sparse_set_index {
|
|||||||
|
|
||||||
impl_sparse_set_index!(u8, u16, u32, u64, usize);
|
impl_sparse_set_index!(u8, u16, u32, u64, usize);
|
||||||
|
|
||||||
/// A collection of [ComponentSparseSet] storages, indexed by [ComponentId]
|
/// A collection of [`ComponentSparseSet`] storages, indexed by [`ComponentId`]
|
||||||
///
|
///
|
||||||
/// Can be accessed via [Storages](crate::storage::Storages)
|
/// Can be accessed via [`Storages`](crate::storage::Storages)
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SparseSets {
|
pub struct SparseSets {
|
||||||
sets: SparseSet<ComponentId, ComponentSparseSet>,
|
sets: SparseSet<ComponentId, ComponentSparseSet>,
|
||||||
|
@ -410,9 +410,9 @@ impl Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A collection of [Table] storages, indexed by [TableId]
|
/// A collection of [`Table`] storages, indexed by [`TableId`]
|
||||||
///
|
///
|
||||||
/// Can be accessed via [Storages](crate::storage::Storages)
|
/// Can be accessed via [`Storages`](crate::storage::Storages)
|
||||||
pub struct Tables {
|
pub struct Tables {
|
||||||
tables: Vec<Table>,
|
tables: Vec<Table>,
|
||||||
table_ids: HashMap<u64, TableId>,
|
table_ids: HashMap<u64, TableId>,
|
||||||
|
@ -88,13 +88,14 @@ impl<'w, 's> Commands<'w, 's> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an [EntityCommands] for the given `entity` (if it exists) or spawns one if it doesn't exist.
|
/// Returns an [`EntityCommands`] for the given `entity` (if it exists) or spawns one if it
|
||||||
/// This will return [None] if the `entity` exists with a different generation.
|
/// doesn't exist. This will return [`None`] if the `entity` exists with a different generation.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// Spawning a specific `entity` value is rarely the right choice. Most apps should favor [`Commands::spawn`].
|
/// Spawning a specific `entity` value is rarely the right choice. Most apps should favor
|
||||||
/// This method should generally only be used for sharing entities across apps, and only when they have a
|
/// [`Commands::spawn`]. This method should generally only be used for sharing entities across
|
||||||
/// scheme worked out to share an ID space (which doesn't happen by default).
|
/// apps, and only when they have a scheme worked out to share an ID space (which doesn't happen
|
||||||
|
/// by default).
|
||||||
pub fn get_or_spawn<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> {
|
pub fn get_or_spawn<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> {
|
||||||
self.add(GetOrSpawn { entity });
|
self.add(GetOrSpawn { entity });
|
||||||
EntityCommands {
|
EntityCommands {
|
||||||
@ -103,8 +104,8 @@ impl<'w, 's> Commands<'w, 's> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawns a [Bundle] without pre-allocating an [Entity]. The [Entity] will be allocated when
|
/// Spawns a [`Bundle`] without pre-allocating an [`Entity`]. The [`Entity`] will be allocated
|
||||||
/// this [Command] is applied.
|
/// when this [`Command`] is applied.
|
||||||
pub fn spawn_and_forget(&mut self, bundle: impl Bundle) {
|
pub fn spawn_and_forget(&mut self, bundle: impl Bundle) {
|
||||||
self.queue.push(Spawn { bundle })
|
self.queue.push(Spawn { bundle })
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,17 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
/// An ECS system that can be added to a [Schedule](crate::schedule::Schedule)
|
/// An ECS system that can be added to a [`Schedule`](crate::schedule::Schedule)
|
||||||
///
|
///
|
||||||
/// Systems are functions with all arguments implementing [SystemParam](crate::system::SystemParam).
|
/// Systems are functions with all arguments implementing
|
||||||
|
/// [`SystemParam`](crate::system::SystemParam).
|
||||||
///
|
///
|
||||||
/// Systems are added to an application using `App::add_system(my_system)`
|
/// Systems are added to an application using `App::add_system(my_system)`
|
||||||
/// or similar methods, and will generally run once per pass of the main loop.
|
/// or similar methods, and will generally run once per pass of the main loop.
|
||||||
///
|
///
|
||||||
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
|
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
|
||||||
/// It's possible to specify explicit execution order between specific systems,
|
/// It's possible to specify explicit execution order between specific systems,
|
||||||
/// see [SystemDescriptor](crate::schedule::SystemDescriptor).
|
/// see [`SystemDescriptor`](crate::schedule::SystemDescriptor).
|
||||||
pub trait System: Send + Sync + 'static {
|
pub trait System: Send + Sync + 'static {
|
||||||
/// The system's input. See [`In`](crate::system::In) for
|
/// The system's input. See [`In`](crate::system::In) for
|
||||||
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
|
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
|
||||||
|
@ -55,9 +55,9 @@ pub type SystemParamItem<'w, 's, P> = <<P as SystemParam>::Fetch as SystemParamF
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// It is the implementor's responsibility to ensure `system_meta` is populated with the _exact_
|
/// It is the implementor's responsibility to ensure `system_meta` is populated with the _exact_
|
||||||
/// [`World`] access used by the `SystemParamState` (and associated [`SystemParamFetch`]).
|
/// [`World`] access used by the [`SystemParamState`] (and associated [`SystemParamFetch`]).
|
||||||
/// Additionally, it is the implementor's responsibility to ensure there is no
|
/// Additionally, it is the implementor's responsibility to ensure there is no
|
||||||
/// conflicting access across all SystemParams.
|
/// conflicting access across all [`SystemParam`]'s.
|
||||||
pub unsafe trait SystemParamState: Send + Sync + 'static {
|
pub unsafe trait SystemParamState: Send + Sync + 'static {
|
||||||
/// Values of this type can be used to adjust the behavior of the
|
/// Values of this type can be used to adjust the behavior of the
|
||||||
/// system parameter. For instance, this can be used to pass
|
/// system parameter. For instance, this can be used to pass
|
||||||
@ -1213,7 +1213,7 @@ macro_rules! impl_system_param_tuple {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFE: implementors of each SystemParamState in the tuple have validated their impls
|
/// SAFE: implementors of each `SystemParamState` in the tuple have validated their impls
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
unsafe impl<$($param: SystemParamState),*> SystemParamState for ($($param,)*) {
|
unsafe impl<$($param: SystemParamState),*> SystemParamState for ($($param,)*) {
|
||||||
type Config = ($(<$param as SystemParamState>::Config,)*);
|
type Config = ($(<$param as SystemParamState>::Config,)*);
|
||||||
|
@ -448,16 +448,16 @@ impl<'w> EntityMut<'w> {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Caller must not modify the world in a way that changes the current entity's location
|
/// Caller must not modify the world in a way that changes the current entity's location
|
||||||
/// If the caller _does_ do something that could change the location, self.update_location()
|
/// If the caller _does_ do something that could change the location, `self.update_location()`
|
||||||
/// must be called before using any other methods in EntityMut
|
/// must be called before using any other methods in [`EntityMut`]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn world_mut(&mut self) -> &mut World {
|
pub unsafe fn world_mut(&mut self) -> &mut World {
|
||||||
self.world
|
self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the internal entity location to match the current location in the internal [World].
|
/// Updates the internal entity location to match the current location in the internal
|
||||||
/// This is only needed if the user called [EntityMut::world], which enables the location to
|
/// [`World`]. This is only needed if the user called [`EntityMut::world`], which enables the
|
||||||
/// change.
|
/// location to change.
|
||||||
pub fn update_location(&mut self) {
|
pub fn update_location(&mut self) {
|
||||||
self.location = self.world.entities().get(self.entity).unwrap();
|
self.location = self.world.entities().get(self.entity).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ impl World {
|
|||||||
&self.bundles
|
&self.bundles
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a [WorldCell], which safely enables multiple mutable World accesses at the same
|
/// Retrieves a [`WorldCell`], which safely enables multiple mutable World accesses at the same
|
||||||
/// time, provided those accesses do not conflict with each other.
|
/// time, provided those accesses do not conflict with each other.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cell(&mut self) -> WorldCell<'_> {
|
pub fn cell(&mut self) -> WorldCell<'_> {
|
||||||
@ -174,8 +174,8 @@ impl World {
|
|||||||
self.components.init_component::<T>(&mut self.storages)
|
self.components.init_component::<T>(&mut self.storages)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves an [EntityRef] that exposes read-only operations for the given `entity`.
|
/// Retrieves an [`EntityRef`] that exposes read-only operations for the given `entity`.
|
||||||
/// This will panic if the `entity` does not exist. Use [World::get_entity] if you want
|
/// This will panic if the `entity` does not exist. Use [`World::get_entity`] if you want
|
||||||
/// to check for entity existence instead of implicitly panic-ing.
|
/// to check for entity existence instead of implicitly panic-ing.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@ -202,8 +202,8 @@ impl World {
|
|||||||
.unwrap_or_else(|| panic!("Entity {:?} does not exist", entity))
|
.unwrap_or_else(|| panic!("Entity {:?} does not exist", entity))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves an [EntityMut] that exposes read and write operations for the given `entity`.
|
/// Retrieves an [`EntityMut`] that exposes read and write operations for the given `entity`.
|
||||||
/// This will panic if the `entity` does not exist. Use [World::get_entity_mut] if you want
|
/// This will panic if the `entity` does not exist. Use [`World::get_entity_mut`] if you want
|
||||||
/// to check for entity existence instead of implicitly panic-ing.
|
/// to check for entity existence instead of implicitly panic-ing.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@ -230,8 +230,8 @@ impl World {
|
|||||||
.unwrap_or_else(|| panic!("Entity {:?} does not exist", entity))
|
.unwrap_or_else(|| panic!("Entity {:?} does not exist", entity))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an [EntityMut] for the given `entity` (if it exists) or spawns one if it doesn't exist.
|
/// Returns an [`EntityMut`] for the given `entity` (if it exists) or spawns one if it doesn't exist.
|
||||||
/// This will return [None] if the `entity` exists with a different generation.
|
/// This will return [`None`] if the `entity` exists with a different generation.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// Spawning a specific `entity` value is rarely the right choice. Most apps should favor [`World::spawn`].
|
/// Spawning a specific `entity` value is rarely the right choice. Most apps should favor [`World::spawn`].
|
||||||
@ -253,9 +253,9 @@ impl World {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves an [EntityRef] that exposes read-only operations for the given `entity`.
|
/// Retrieves an [`EntityRef`] that exposes read-only operations for the given `entity`.
|
||||||
/// Returns [None] if the `entity` does not exist. Use [World::entity] if you don't want
|
/// Returns [`None`] if the `entity` does not exist. Use [`World::entity`] if you don't want
|
||||||
/// to unwrap the [EntityRef] yourself.
|
/// to unwrap the [`EntityRef`] yourself.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, world::World};
|
/// use bevy_ecs::{component::Component, world::World};
|
||||||
@ -281,9 +281,9 @@ impl World {
|
|||||||
Some(EntityRef::new(self, entity, location))
|
Some(EntityRef::new(self, entity, location))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves an [EntityMut] that exposes read and write operations for the given `entity`.
|
/// Retrieves an [`EntityMut`] that exposes read and write operations for the given `entity`.
|
||||||
/// Returns [None] if the `entity` does not exist. Use [World::entity_mut] if you don't want
|
/// Returns [`None`] if the `entity` does not exist. Use [`World::entity_mut`] if you don't want
|
||||||
/// to unwrap the [EntityMut] yourself.
|
/// to unwrap the [`EntityMut`] yourself.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, world::World};
|
/// use bevy_ecs::{component::Component, world::World};
|
||||||
@ -310,7 +310,7 @@ impl World {
|
|||||||
Some(unsafe { EntityMut::new(self, entity, location) })
|
Some(unsafe { EntityMut::new(self, entity, location) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawns a new [Entity] and returns a corresponding [EntityMut], which can be used
|
/// Spawns a new [`Entity`] and returns a corresponding [`EntityMut`], which can be used
|
||||||
/// to add components to the entity or retrieve its id.
|
/// to add components to the entity or retrieve its id.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@ -474,8 +474,8 @@ impl World {
|
|||||||
self.last_change_tick = self.increment_change_tick();
|
self.last_change_tick = self.increment_change_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns [QueryState] for the given [WorldQuery], which is used to efficiently
|
/// Returns [`QueryState`] for the given [`WorldQuery`], which is used to efficiently
|
||||||
/// run queries on the [World] by storing and reusing the [QueryState].
|
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World};
|
/// use bevy_ecs::{component::Component, entity::Entity, world::World};
|
||||||
///
|
///
|
||||||
@ -541,8 +541,8 @@ impl World {
|
|||||||
QueryState::new(self)
|
QueryState::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns [QueryState] for the given filtered [WorldQuery], which is used to efficiently
|
/// Returns [`QueryState`] for the given filtered [`WorldQuery`], which is used to efficiently
|
||||||
/// run queries on the [World] by storing and reusing the [QueryState].
|
/// run queries on the [`World`] by storing and reusing the [`QueryState`].
|
||||||
/// ```
|
/// ```
|
||||||
/// use bevy_ecs::{component::Component, entity::Entity, world::World, query::With};
|
/// use bevy_ecs::{component::Component, entity::Entity, world::World, query::With};
|
||||||
///
|
///
|
||||||
@ -569,7 +569,7 @@ impl World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator of entities that had components of type `T` removed
|
/// Returns an iterator of entities that had components of type `T` removed
|
||||||
/// since the last call to [World::clear_trackers].
|
/// since the last call to [`World::clear_trackers`].
|
||||||
pub fn removed<T: Component>(&self) -> std::iter::Cloned<std::slice::Iter<'_, Entity>> {
|
pub fn removed<T: Component>(&self) -> std::iter::Cloned<std::slice::Iter<'_, Entity>> {
|
||||||
if let Some(component_id) = self.components.get_id(TypeId::of::<T>()) {
|
if let Some(component_id) = self.components.get_id(TypeId::of::<T>()) {
|
||||||
self.removed_with_id(component_id)
|
self.removed_with_id(component_id)
|
||||||
@ -579,7 +579,7 @@ impl World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator of entities that had components with the given `component_id` removed
|
/// Returns an iterator of entities that had components with the given `component_id` removed
|
||||||
/// since the last call to [World::clear_trackers].
|
/// since the last call to [`World::clear_trackers`].
|
||||||
pub fn removed_with_id(
|
pub fn removed_with_id(
|
||||||
&self,
|
&self,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
|
Loading…
Reference in New Issue
Block a user