Skip to content

Commit

Permalink
Use a recursive clear when removing a container or space view
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 29, 2024
1 parent f4f98b3 commit 9e8a6a3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion crates/viewer/re_viewer_context/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ impl StoreHub {
}

let store_events = blueprint.gc(&GarbageCollectionOptions {
// TODO(#8249): configure blueprint GC to remove an entity if all that remains of it is a recursive clear
target: GarbageCollectionTarget::Everything,
protect_latest: 0,
protect_latest: 1, // keep the latest instance of everything, or we will forget things that haven't changed in a while
time_budget: re_entity_db::DEFAULT_GC_TIME_BUDGET,
protected_time_ranges,
});
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_viewer_context/src/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ impl BlueprintUndoState {
}
}

/// Clears the "redo buffer".
pub fn clear_redo(&mut self, blueprint_db: &mut EntityDb) {
re_tracing::profile_function!();

if let Some(last_kept_event_time) = self.current_time.take() {
let first_dropped_event_time =
TimeInt::new_temporal(last_kept_event_time.as_i64().saturating_add(1));

// Drop everything before the current timeline time
// Drop everything after the current timeline time
blueprint_db.drop_time_range(
&blueprint_timeline(),
ResolvedTimeRange::new(first_dropped_event_time, re_chunk::TimeInt::MAX),
Expand Down
23 changes: 18 additions & 5 deletions crates/viewer/re_viewport_blueprint/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,24 @@ impl ContainerBlueprint {

/// Clears the blueprint component for this container.
pub fn clear(&self, ctx: &ViewerContext<'_>) {
// TODO: ecursive clear
ctx.command_sender.send_system(SystemCommand::DropEntity(
ctx.store_context.blueprint.store_id().clone(),
self.entity_path(),
));
// We can't delete the entity, because we need to support undo.
// TODO(#8249): configure blueprint GC to remove this entity if all that remains is the recursive clear.
let timepoint = ctx.store_context.blueprint_timepoint_for_writes();

let chunk = Chunk::builder(self.entity_path())
.with_archetype(
RowId::new(),
timepoint.clone(),
&re_types::archetypes::Clear::recursive(),
)
.build()
.unwrap();

ctx.command_sender
.send_system(SystemCommand::UpdateBlueprint(
ctx.store_context.blueprint.store_id().clone(),
vec![chunk],
));
}

pub fn to_tile(&self) -> egui_tiles::Tile<SpaceViewId> {
Expand Down
23 changes: 18 additions & 5 deletions crates/viewer/re_viewport_blueprint/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,24 @@ impl SpaceViewBlueprint {
}

pub fn clear(&self, ctx: &ViewerContext<'_>) {
// TODO: log a recursive clear
ctx.command_sender.send_system(SystemCommand::DropEntity(
ctx.store_context.blueprint.store_id().clone(),
self.entity_path(),
));
// We can't delete the entity, because we need to support undo.
// TODO(#8249): configure blueprint GC to remove this entity if all that remains is the recursive clear.
let timepoint = ctx.store_context.blueprint_timepoint_for_writes();

let chunk = Chunk::builder(self.entity_path())
.with_archetype(
RowId::new(),
timepoint.clone(),
&re_types::archetypes::Clear::recursive(),
)
.build()
.unwrap();

ctx.command_sender
.send_system(SystemCommand::UpdateBlueprint(
ctx.store_context.blueprint.store_id().clone(),
vec![chunk],
));
}

#[inline]
Expand Down
5 changes: 2 additions & 3 deletions crates/viewer/re_viewport_blueprint/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,8 @@ impl ViewportBlueprint {
}
}

// TODO: log a recursive clear here
// Clear any existing container blueprints that aren't referenced
// by any tiles.
// Clear any existing container blueprints that aren't referenced by any tiles,
// allowing the GC to remove the previous (non-clear) data from the store (saving RAM).
for (container_id, container) in &self.containers {
let tile_id = blueprint_id_to_tile_id(container_id);
if self.tree.tiles.get(tile_id).is_none() {
Expand Down

0 comments on commit 9e8a6a3

Please sign in to comment.