Skip to content

Commit

Permalink
Increase type safety and clarity for change detection (bevyengine#7905)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJoJet authored and Shfty committed Mar 19, 2023
1 parent 816d9ff commit 596ce46
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 570 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_ecs/macros/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
unsafe fn init_fetch<'__w>(
_world: &'__w #path::world::World,
state: &Self::State,
_last_change_tick: u32,
_change_tick: u32
_last_run: #path::component::Tick,
_this_run: #path::component::Tick,
) -> <Self as #path::query::WorldQuery>::Fetch<'__w> {
#fetch_struct_name {
#(#field_idents:
<#field_types>::init_fetch(
_world,
&state.#field_idents,
_last_change_tick,
_change_tick
_last_run,
_this_run,
),
)*
#(#ignored_field_idents: Default::default(),)*
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
state: &'s mut Self::State,
system_meta: &SystemMeta,
world: &'w World,
change_tick: u32,
change_tick: Tick,
) -> Self::Item<'w, 's> {
ParamSet {
param_states: state,
Expand Down Expand Up @@ -431,7 +431,7 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
state: &'s2 mut Self::State,
system_meta: &#path::system::SystemMeta,
world: &'w2 #path::world::World,
change_tick: u32,
change_tick: #path::component::Tick,
) -> Self::Item<'w2, 's2> {
let (#(#tuple_patterns,)*) = <
(#(#tuple_types,)*) as #path::system::SystemParam
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl BundleInfo {
components: &mut Components,
storages: &'a mut Storages,
archetype_id: ArchetypeId,
change_tick: u32,
change_tick: Tick,
) -> BundleInserter<'a, 'b> {
let new_archetype_id =
self.add_bundle_to_archetype(archetypes, storages, components, archetype_id);
Expand Down Expand Up @@ -342,7 +342,7 @@ impl BundleInfo {
archetypes: &'a mut Archetypes,
components: &mut Components,
storages: &'a mut Storages,
change_tick: u32,
change_tick: Tick,
) -> BundleSpawner<'a, 'b> {
let new_archetype_id =
self.add_bundle_to_archetype(archetypes, storages, components, ArchetypeId::EMPTY);
Expand Down Expand Up @@ -383,7 +383,7 @@ impl BundleInfo {
bundle_component_status: &S,
entity: Entity,
table_row: TableRow,
change_tick: u32,
change_tick: Tick,
bundle: T,
) {
// NOTE: get_components calls this closure on each component in "bundle order".
Expand All @@ -397,7 +397,7 @@ impl BundleInfo {
// SAFETY: bundle_component is a valid index for this bundle
match bundle_component_status.get_status(bundle_component) {
ComponentStatus::Added => {
column.initialize(table_row, component_ptr, Tick::new(change_tick));
column.initialize(table_row, component_ptr, change_tick);
}
ComponentStatus::Mutated => {
column.replace(table_row, component_ptr, change_tick);
Expand Down Expand Up @@ -508,7 +508,7 @@ pub(crate) struct BundleInserter<'a, 'b> {
sparse_sets: &'a mut SparseSets,
result: InsertBundleResult<'a>,
archetypes_ptr: *mut Archetype,
change_tick: u32,
change_tick: Tick,
}

pub(crate) enum InsertBundleResult<'a> {
Expand Down Expand Up @@ -666,7 +666,7 @@ pub(crate) struct BundleSpawner<'a, 'b> {
bundle_info: &'b BundleInfo,
table: &'a mut Table,
sparse_sets: &'a mut SparseSets,
change_tick: u32,
change_tick: Tick,
}

impl<'a, 'b> BundleSpawner<'a, 'b> {
Expand Down
Loading

0 comments on commit 596ce46

Please sign in to comment.