2021-12-17 16:22:09 +03:00
|
|
|
module gg
|
|
|
|
|
|
|
|
import sokol.sapp
|
|
|
|
import os
|
|
|
|
|
2022-04-05 18:42:01 +03:00
|
|
|
// record_frame records the current frame to a file.
|
|
|
|
// record_frame acts according to settings specified in `gg.recorder_settings`.
|
2021-12-17 16:22:09 +03:00
|
|
|
[if gg_record ?]
|
|
|
|
pub fn (mut ctx Context) record_frame() {
|
|
|
|
if ctx.frame in gg.recorder_settings.screenshot_frames {
|
2022-11-15 16:53:13 +03:00
|
|
|
screenshot_file_path := '${gg.recorder_settings.screenshot_prefix}${ctx.frame}.png'
|
2021-12-17 16:22:09 +03:00
|
|
|
$if gg_record_trace ? {
|
2022-11-15 16:53:13 +03:00
|
|
|
eprintln('>>> screenshoting ${screenshot_file_path}')
|
2021-12-17 16:22:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sapp.screenshot_png(screenshot_file_path) or { panic(err) }
|
|
|
|
}
|
|
|
|
if ctx.frame == gg.recorder_settings.stop_at_frame {
|
|
|
|
$if gg_record_trace ? {
|
2022-11-15 16:53:13 +03:00
|
|
|
eprintln('>>> exiting at frame ${ctx.frame}')
|
2021-12-17 16:22:09 +03:00
|
|
|
}
|
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_gg_recorder_settings() &SSRecorderSettings {
|
|
|
|
$if gg_record ? {
|
|
|
|
stop_frame := os.getenv_opt('VGG_STOP_AT_FRAME') or { '-1' }.i64()
|
|
|
|
frames := os.getenv('VGG_SCREENSHOT_FRAMES').split_any(',').map(it.u64())
|
|
|
|
folder := os.getenv('VGG_SCREENSHOT_FOLDER')
|
|
|
|
prefix := os.join_path_single(folder, os.file_name(os.executable()).all_before('.') + '_')
|
|
|
|
return &SSRecorderSettings{
|
|
|
|
stop_at_frame: stop_frame
|
|
|
|
screenshot_frames: frames
|
|
|
|
screenshot_folder: folder
|
|
|
|
screenshot_prefix: prefix
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
return &SSRecorderSettings{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const recorder_settings = new_gg_recorder_settings()
|