Skip to content

Commit 3f11639

Browse files
authored
Time control is now behind a RwLock, making recording config access non-mutable everywhere (#4389)
### What * Another step towards #1325 * Follow-up to #4387 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [app.rerun.io](https://app.rerun.io/pr/4389) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4389) - [Docs preview](https://rerun.io/preview/405ddca2f8389bb62e1d1e65ef59a3d211361968/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/405ddca2f8389bb62e1d1e65ef59a3d211361968/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent ee83418 commit 3f11639

18 files changed

Lines changed: 202 additions & 136 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/re_data_ui/src/item_ui.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ pub fn time_button(
238238
timeline: &Timeline,
239239
value: TimeInt,
240240
) -> egui::Response {
241-
let is_selected = ctx.rec_cfg.time_ctrl.is_time_selected(timeline, value);
241+
let is_selected = ctx
242+
.rec_cfg
243+
.time_ctrl
244+
.read()
245+
.is_time_selected(timeline, value);
242246

243247
let response = ui.selectable_label(
244248
is_selected,
@@ -249,8 +253,9 @@ pub fn time_button(
249253
if response.clicked() {
250254
ctx.rec_cfg
251255
.time_ctrl
256+
.write()
252257
.set_timeline_and_time(*timeline, value);
253-
ctx.rec_cfg.time_ctrl.pause();
258+
ctx.rec_cfg.time_ctrl.write().pause();
254259
}
255260
response
256261
}
@@ -269,14 +274,15 @@ pub fn timeline_button_to(
269274
text: impl Into<egui::WidgetText>,
270275
timeline: &Timeline,
271276
) -> egui::Response {
272-
let is_selected = ctx.rec_cfg.time_ctrl.timeline() == timeline;
277+
let is_selected = ctx.rec_cfg.time_ctrl.read().timeline() == timeline;
273278

274279
let response = ui
275280
.selectable_label(is_selected, text)
276281
.on_hover_text("Click to switch to this timeline");
277282
if response.clicked() {
278-
ctx.rec_cfg.time_ctrl.set_timeline(*timeline);
279-
ctx.rec_cfg.time_ctrl.pause();
283+
let mut time_ctrl = ctx.rec_cfg.time_ctrl.write();
284+
time_ctrl.set_timeline(*timeline);
285+
time_ctrl.pause();
280286
}
281287
response
282288
}

crates/re_space_view_spatial/src/contexts/depth_offsets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl ViewContextSystem for EntityDepthOffsets {
5151
for data_result in query.iter_visible_data_results(Self::name()) {
5252
if let Some(draw_order) = store.query_latest_component::<DrawOrder>(
5353
&data_result.entity_path,
54-
&ctx.rec_cfg.time_ctrl.current_query(),
54+
&ctx.rec_cfg.time_ctrl.read().current_query(),
5555
) {
5656
entities_per_draw_order
5757
.entry(draw_order.value)

crates/re_space_view_spatial/src/contexts/transform_context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ impl ViewContextSystem for TransformContext {
8787
re_tracing::profile_function!();
8888

8989
let entity_db = ctx.store_db.entity_db();
90-
let time_ctrl = &ctx.rec_cfg.time_ctrl;
9190

9291
// TODO(jleibs): The need to do this hints at a problem with how we think about
9392
// the interaction between properties and "context-systems".
@@ -114,7 +113,7 @@ impl ViewContextSystem for TransformContext {
114113
return;
115114
};
116115

117-
let time_query = time_ctrl.current_query();
116+
let time_query = ctx.rec_cfg.time_ctrl.read().current_query();
118117

119118
// Child transforms of this space
120119
self.gather_descendants_transforms(

crates/re_space_view_text_log/src/space_view_class.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl SpaceViewClass for TextSpaceView {
167167
let time = ctx
168168
.rec_cfg
169169
.time_ctrl
170+
.read()
170171
.time_i64()
171172
.unwrap_or(state.latest_time);
172173

@@ -277,8 +278,10 @@ fn table_ui(
277278

278279
use egui_extras::Column;
279280

280-
let global_timeline = *ctx.rec_cfg.time_ctrl.timeline();
281-
let global_time = ctx.rec_cfg.time_ctrl.time_int();
281+
let (global_timeline, global_time) = {
282+
let time_ctrl = ctx.rec_cfg.time_ctrl.read();
283+
(*time_ctrl.timeline(), time_ctrl.time_int())
284+
};
282285

283286
let mut table_builder = egui_extras::TableBuilder::new(ui)
284287
.resizable(true)

crates/re_space_view_time_series/src/space_view_class.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,14 @@ impl SpaceViewClass for TimeSeriesSpaceView {
160160
) -> Result<(), SpaceViewSystemExecutionError> {
161161
re_tracing::profile_function!();
162162

163-
let time_ctrl = &ctx.rec_cfg.time_ctrl;
164-
let current_time = time_ctrl.time_i64();
165-
let time_type = time_ctrl.time_type();
166-
let timeline = time_ctrl.timeline();
163+
let (current_time, time_type, timeline) = {
164+
// Avoid holding the lock for long
165+
let time_ctrl = ctx.rec_cfg.time_ctrl.read();
166+
let current_time = time_ctrl.time_i64();
167+
let time_type = time_ctrl.time_type();
168+
let timeline = *time_ctrl.timeline();
169+
(current_time, time_type, timeline)
170+
};
167171

168172
let timeline_name = timeline.name().to_string();
169173

@@ -236,12 +240,13 @@ impl SpaceViewClass for TimeSeriesSpaceView {
236240
transform,
237241
} = plot.show(ui, |plot_ui| {
238242
if plot_ui.response().secondary_clicked() {
239-
let timeline = ctx.rec_cfg.time_ctrl.timeline();
240-
ctx.rec_cfg.time_ctrl.set_timeline_and_time(
241-
*timeline,
243+
let mut time_ctrl_write = ctx.rec_cfg.time_ctrl.write();
244+
let timeline = *time_ctrl_write.timeline();
245+
time_ctrl_write.set_timeline_and_time(
246+
timeline,
242247
plot_ui.pointer_coordinate().unwrap().x as i64 + time_offset,
243248
);
244-
ctx.rec_cfg.time_ctrl.pause();
249+
time_ctrl_write.pause();
245250
}
246251

247252
for line in &time_series.lines {
@@ -301,7 +306,7 @@ impl SpaceViewClass for TimeSeriesSpaceView {
301306
let time =
302307
time_offset + transform.value_from_position(pointer_pos).x.round() as i64;
303308

304-
let time_ctrl = &mut ctx.rec_cfg.time_ctrl;
309+
let mut time_ctrl = ctx.rec_cfg.time_ctrl.write();
305310
time_ctrl.set_time(time);
306311
time_ctrl.pause();
307312

crates/re_time_panel/src/data_density_graph.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use egui::{epaint::Vertex, lerp, pos2, remap, Color32, NumExt as _, Rect, Shape}
1111
use re_data_store::TimeHistogram;
1212
use re_data_ui::{item_ui, DataUi};
1313
use re_log_types::{TimeInt, TimeRange, TimeReal};
14-
use re_viewer_context::{Item, UiVerbosity, ViewerContext};
14+
use re_viewer_context::{Item, TimeControl, UiVerbosity, ViewerContext};
1515

1616
use super::time_ranges_ui::TimeRangesUi;
1717

@@ -368,6 +368,7 @@ fn smooth(density: &[f32]) -> Vec<f32> {
368368
pub fn data_density_graph_ui(
369369
data_dentity_graph_painter: &mut DataDensityGraphPainter,
370370
ctx: &mut ViewerContext<'_>,
371+
time_ctrl: &mut TimeControl,
371372
time_area_response: &egui::Response,
372373
time_area_painter: &egui::Painter,
373374
ui: &egui::Ui,
@@ -486,11 +487,12 @@ pub fn data_density_graph_ui(
486487

487488
if time_area_response.clicked_by(egui::PointerButton::Primary) {
488489
ctx.set_single_selection(item);
489-
ctx.rec_cfg.time_ctrl.set_time(hovered_time_range.min);
490-
ctx.rec_cfg.time_ctrl.pause();
490+
time_ctrl.set_time(hovered_time_range.min);
491+
time_ctrl.pause();
491492
} else if !ui.ctx().memory(|mem| mem.is_anything_being_dragged()) {
492493
show_row_ids_tooltip(
493494
ctx,
495+
time_ctrl,
494496
ui.ctx(),
495497
item,
496498
hovered_time_range,
@@ -521,6 +523,7 @@ fn make_brighter(color: Color32) -> Color32 {
521523

522524
fn show_row_ids_tooltip(
523525
ctx: &mut ViewerContext<'_>,
526+
time_ctrl: &mut TimeControl,
524527
egui_ctx: &egui::Context,
525528
item: &Item,
526529
time_range: TimeRange,
@@ -552,8 +555,7 @@ fn show_row_ids_tooltip(
552555

553556
ui.add_space(8.0);
554557

555-
let timeline = *ctx.rec_cfg.time_ctrl.timeline();
556-
let query = re_arrow_store::LatestAtQuery::new(timeline, time_range.max);
558+
let query = re_arrow_store::LatestAtQuery::new(*time_ctrl.timeline(), time_range.max);
557559
item.data_ui(ctx, ui, UiVerbosity::Reduced, &query);
558560
});
559561
}

0 commit comments

Comments
 (0)