Skip to content

Commit

Permalink
change detection location, based on copied from bevyengine#14034
Browse files Browse the repository at this point in the history
  • Loading branch information
slyedoc committed Jul 26, 2024
1 parent b231ebb commit bb21b41
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 54 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ ios_simulator = ["bevy_internal/ios_simulator"]
# Enable built in global state machines
bevy_state = ["bevy_internal/bevy_state"]

change_location = []

[dependencies]
bevy_internal = { path = "crates/bevy_internal", version = "0.14.0", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ multi_threaded = ["bevy_tasks/multi_threaded", "arrayvec"]
bevy_debug_stepping = []
default = ["bevy_reflect"]
serialize = ["dep:serde"]
change_location = []

[dependencies]
bevy_ptr = { path = "../bevy_ptr", version = "0.14.0" }
Expand Down
21 changes: 16 additions & 5 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ impl BundleInfo {
table_row: TableRow,
change_tick: Tick,
bundle: T,
caller: core::panic::Location<'static>,
) {
// NOTE: get_components calls this closure on each component in "bundle order".
// bundle_info.component_ids are also in "bundle order"
Expand All @@ -417,10 +418,13 @@ impl BundleInfo {
let status = unsafe { bundle_component_status.get_status(bundle_component) };
match status {
ComponentStatus::Added => {
column.initialize(table_row, component_ptr, change_tick);
column.initialize(table_row, component_ptr, change_tick,

caller
);
}
ComponentStatus::Mutated => {
column.replace(table_row, component_ptr, change_tick);
column.replace(table_row, component_ptr, change_tick, caller);
}
}
}
Expand All @@ -429,7 +433,7 @@ impl BundleInfo {
// SAFETY: If component_id is in self.component_ids, BundleInfo::new requires that
// a sparse set exists for the component.
unsafe { sparse_sets.get_mut(component_id).debug_checked_unwrap() };
sparse_set.insert(entity, component_ptr, change_tick);
sparse_set.insert(entity, component_ptr, change_tick, caller);
}
}
bundle_component += 1;
Expand Down Expand Up @@ -656,6 +660,7 @@ impl<'w> BundleInserter<'w> {
/// `entity` must currently exist in the source archetype for this inserter. `location`
/// must be `entity`'s location in the archetype. `T` must match this [`BundleInfo`]'s type
#[inline]
#[track_caller]
pub(crate) unsafe fn insert<T: DynamicBundle>(
&mut self,
entity: Entity,
Expand All @@ -666,6 +671,7 @@ impl<'w> BundleInserter<'w> {
let add_bundle = self.add_bundle.as_ref();
let table = self.table.as_mut();
let archetype = self.archetype.as_mut();
let caller = *core::panic::Location::caller();

let (new_archetype, new_location) = match &mut self.result {
InsertBundleResult::SameArchetype => {
Expand All @@ -683,6 +689,7 @@ impl<'w> BundleInserter<'w> {
location.table_row,
self.change_tick,
bundle,
caller,
);

(archetype, location)
Expand Down Expand Up @@ -721,6 +728,7 @@ impl<'w> BundleInserter<'w> {
result.table_row,
self.change_tick,
bundle,
caller,
);

(new_archetype, new_location)
Expand Down Expand Up @@ -800,6 +808,7 @@ impl<'w> BundleInserter<'w> {
move_result.new_row,
self.change_tick,
bundle,
caller,
);

(new_archetype, new_location)
Expand Down Expand Up @@ -896,6 +905,7 @@ impl<'w> BundleSpawner<'w> {
&mut self,
entity: Entity,
bundle: T,
caller: core::panic::Location<'static>,
) -> EntityLocation {
// SAFETY: We do not make any structural changes to the archetype graph through self.world so these pointers always remain valid
let bundle_info = self.bundle_info.as_ref();
Expand All @@ -918,6 +928,7 @@ impl<'w> BundleSpawner<'w> {
table_row,
self.change_tick,
bundle,
caller,
);
entities.set(entity.index(), location);
location
Expand Down Expand Up @@ -946,11 +957,11 @@ impl<'w> BundleSpawner<'w> {
/// # Safety
/// `T` must match this [`BundleInfo`]'s type
#[inline]
pub unsafe fn spawn<T: Bundle>(&mut self, bundle: T) -> Entity {
pub unsafe fn spawn<T: Bundle>(&mut self, bundle: T, caller: core::panic::Location<'static>,) -> Entity {
let entity = self.entities().alloc();
// SAFETY: entity is allocated (but non-existent), `T` matches this BundleInfo's type
unsafe {
self.spawn_non_existent(entity, bundle);
self.spawn_non_existent(entity, bundle, caller);
}
entity
}
Expand Down
Loading

0 comments on commit bb21b41

Please sign in to comment.