Skip to content

Commit ce6f185

Browse files
committed
Implemented capture controls (F12)
1 parent 90a9828 commit ce6f185

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

Diff for: src/app/capture.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use app::constants::*;
2+
use chrono::DateTime;
3+
use chrono::Utc;
14
use gl;
25
use glutin;
36
use glutin::GlContext;
@@ -23,10 +26,11 @@ impl Capture {
2326
//use gl;
2427
gl::ReadPixels::load_with(|s| window.get_proc_address(s) as *const _);
2528
let (w, h) = window.get_inner_size().unwrap();
29+
let now: DateTime<Utc> = Utc::now();
2630
Capture {
2731
seq: 0,
28-
capture_path: PathBuf::from("capture"),
29-
capture_prefix: String::from("capture_"),
32+
capture_path: PathBuf::from(CAPTURE_FOLDER).join(now.format(CAPTURE_FOLDER_TIMESTAMP_PATTERN).to_string()),
33+
capture_prefix: String::from(CAPTURE_FILENAME_PREFIX),
3034
enabled: false,
3135
batch_size: 600,
3236
w,
@@ -88,16 +92,24 @@ impl Capture {
8892
self.images.clear()
8993
}
9094

95+
// Remote control, detects state changes
96+
pub fn enable(&mut self, enabled: bool) {
97+
if enabled != self.enabled {
98+
self.toggle()
99+
}
100+
}
101+
102+
// Starts/restarts recording
103+
pub fn start(&mut self) { self.enabled = true }
104+
105+
// Stops recording and flushes
91106
pub fn stop(&mut self) {
92107
if self.enabled {
93108
self.flush();
94109
}
95110
self.enabled = false;
96111
}
97112

98-
// Starts/restarts recording
99-
pub fn start(&mut self) { self.enabled = true }
100-
101113
pub fn enabled(&self) -> bool { self.enabled }
102114

103115
pub fn toggle(&mut self) {

Diff for: src/app/constants.rs

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ pub const CONFIG_DIR_RESOURCES: &'static str = "resources";
9393
pub const DUMP_FILE_PATTERN_CSV: &'static str = "%Y%m%d_%H%M%S.csv";
9494
pub const DUMP_FILE_PATTERN_JSON: &'static str = "%Y%m%d_%H%M%S.json";
9595

96+
pub const CAPTURE_FOLDER_TIMESTAMP_PATTERN: &'static str = "%Y%m%d_%H%M%S";
97+
pub const CAPTURE_FOLDER: &'static str = "capture";
98+
pub const CAPTURE_FILENAME_PREFIX: &'static str = "capture_";
99+
96100
pub const AMBIENT_LIGHTS: &'static [[f32; 4]] = &[
97101
[1.0, 1.0, 1.0, 1.0],
98102
[3.1, 3.1, 3.1, 1.0],

Diff for: src/app/controller.rs

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl InputController for DefaultController {
5151
GamepadL3 -> ToggleGui,
5252
N0 -> CamReset,
5353
Home -> CamReset,
54+
GamepadSelect -> ToggleCapture,
5455
GamepadStart -> TogglePause,
5556
KpHome -> CamReset,
5657
GamepadDPadUp -> ZoomIn,
@@ -63,6 +64,7 @@ impl InputController for DefaultController {
6364
F7 -> SaveWorldToFile,
6465
F8 -> RestartFromCheckpoint,
6566
F10 -> ToggleDebug,
67+
F12 -> ToggleCapture,
6668
GamepadStart -> ToggleDebug,
6769
Z -> DeselectAll,
6870
L -> NextLight,

Diff for: src/app/events.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum Event {
4444

4545
TogglePause,
4646
ToggleGui,
47+
ToggleCapture,
4748

4849
AppQuit,
4950

Diff for: src/app/main.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ pub fn main_loop(
132132
},
133133
..
134134
} => renderer.rebuild().unwrap(),
135-
WindowEvent::KeyboardInput {
136-
input: KeyboardInput {
137-
virtual_keycode: Some(VirtualKeyCode::F12),
138-
..
139-
},
140-
..
141-
} => capture.toggle(),
142135
e => {
143136
mapper.translate(&e).map(|i| app.on_input_event(&i));
144137
}
@@ -147,6 +140,8 @@ pub fn main_loop(
147140
}
148141
});
149142

143+
capture.enable(app.is_capturing());
144+
150145
if !app.is_running() {
151146
capture.stop();
152147
app.save_world_to_file();

Diff for: src/app/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub struct App {
273273
frame_smooth: math::MovingAverage<Seconds>,
274274
is_running: bool,
275275
is_paused: bool,
276+
is_capturing: bool,
276277
// interactions: Vec<Event>,
277278
//
278279
camera: math::Inertial<f32>,
@@ -379,6 +380,7 @@ impl App {
379380
frame_smooth: math::MovingAverage::new(FRAME_SMOOTH_COUNT),
380381
is_running: true,
381382
is_paused: false,
383+
is_capturing: false,
382384
// savegame
383385
saved_state_dir: config_home.join(CONFIG_DIR_SAVED_STATE),
384386
config_home,
@@ -451,6 +453,7 @@ impl App {
451453
Event::AppQuit => self.quit(),
452454
Event::TogglePause => self.is_paused = !self.is_paused,
453455
Event::ToggleGui => self.has_ui_overlay = !self.has_ui_overlay,
456+
Event::ToggleCapture => self.is_capturing = !self.is_capturing,
454457
Event::SaveGenePoolToFile => self.save_gene_pool_to_file(),
455458
Event::SaveWorldToFile => self.save_world_to_file(),
456459
Event::BeginDrag(_, _) => {
@@ -538,6 +541,8 @@ impl App {
538541
}
539542

540543
pub fn is_running(&self) -> bool { self.is_running }
544+
545+
pub fn is_capturing(&self) -> bool { self.is_capturing }
541546

542547
pub fn on_input_event(&mut self, e: &input::Event) { self.input_state.event(e); }
543548

0 commit comments

Comments
 (0)