Skip to content

Commit

Permalink
feat: recording session directory groupings
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Mar 11, 2024
1 parent d54291c commit 1e55376
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_light_field"
description = "rust bevy light field array tooling"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["mosure <[email protected]>"]
license = "MIT"
Expand Down
47 changes: 18 additions & 29 deletions tools/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,16 @@ fn press_r_start_recording(
stream_manager: Res<RtspStreamManager>
) {
if keys.just_pressed(KeyCode::KeyR) {
let output_directory = "capture";
std::fs::create_dir_all(output_directory).unwrap();

let base_prefix = "bevy_light_field_";
let output_directory = "capture";
let session_id = get_next_session_id(output_directory);
let output_directory = format!("{}/{}", output_directory, session_id);

let prefix = format!(
"{}{:03}",
base_prefix,
get_next_session_id(output_directory, base_prefix)
);
std::fs::create_dir_all(&output_directory).unwrap();

stream_manager.start_recording(
output_directory,
&prefix,
&output_directory,
"bevy_light_field",
);
}
}
Expand Down Expand Up @@ -374,30 +370,23 @@ fn calculate_grid_dimensions(window_width: f32, window_height: f32, num_streams:
}


fn get_next_session_id(output_directory: &str, base_prefix: &str) -> i32 {
let mut highest_count = -1i32;
if let Ok(entries) = std::fs::read_dir(output_directory) {
for entry in entries.filter_map(|e| e.ok()) {
let path = entry.path();
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
if stem.starts_with(base_prefix) {
let suffix = stem.trim_start_matches(base_prefix);
let numeric_part = suffix.split('_').next().unwrap_or("");
if let Ok(num) = numeric_part.parse::<i32>() {
highest_count = highest_count.max(num);
} else {
println!("failed to parse session ID '{}' for file '{}'", numeric_part, stem);
}
fn get_next_session_id(output_directory: &str) -> i32 {
match std::fs::read_dir(output_directory) {
Ok(entries) => entries.filter_map(|entry| {
let entry = entry.ok()?;
if entry.path().is_dir() {
entry.file_name().to_string_lossy().parse::<i32>().ok()
} else {
None
}
}
}
})
.max()
.map_or(0, |max_id| max_id + 1),
Err(_) => 0,
}

highest_count + 1
}



fn fps_display_setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
Expand Down

0 comments on commit 1e55376

Please sign in to comment.