Skip to content

Commit fc57e29

Browse files
authored
Merge pull request #124 from alphastrata/giff-frame-capture-in-config-#84
Giff frame capture in config #84
2 parents a40eaf5 + fcf4ca9 commit fc57e29

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You will notice a large swath of the `wgsl` code from the Bevy codebase here, _w
4545
- Tips and Tools to format your `wgsl` work, so it looks more rusty (which will help you quickly get up to speed with the existing `wgsl` in the Bevy codebase).
4646
- Scripts to pull _all_ the functions from the Bevy codebase's shader code so you can easily lookup what's available for import. (See `scripts/README.md`)
4747
- Scripts to search the Bevy source code (opening your browser) for specific keywords. (See `scripts/README.md`)
48-
- Continious image capture to create .gifs! (Currently only supporting a maximum framerate of 20FPS for capture.)
48+
- Continious image capture to create .gifs! (Currently only supporting a maximum framerate of 20FPS for capture.) For the finest quality GIFs, we recommend [this guide on using ffmpeg](https://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html).
4949
- Automatic recompilation and update of shaders upon saving changes in your editor.
5050
- Quick iteration and experimentation with `wgsl` shader code.
5151
- Transparent background, with always-on-top (so you can have it on top of your editor, most OSes should be supported).

src/system/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ pub struct UserSession {
3636
/// RenderTarget for when we're making a gif out of
3737
#[serde(skip)]
3838
pub gif_buffer: Option<Handle<Image>>,
39+
#[serde(default = "default_gif_framerate")]
40+
pub gif_framerate: f64,
3941
}
42+
43+
fn default_gif_framerate() -> f64 {
44+
0.05
45+
}
46+
4047
// Provide a default function for window_dims
4148
fn default_window_dims() -> (u32, u32) {
4249
(800, 600) // Default window dimensions
@@ -210,6 +217,7 @@ impl Default for UserSession {
210217
.unwrap_or_default()
211218
.as_secs(),
212219
gif_buffer: None,
220+
gif_framerate: 0.05,
213221
}
214222
}
215223
}
@@ -227,6 +235,7 @@ mod tests {
227235
always_on_top: false,
228236
last_updated: 1635900000,
229237
gif_buffer: None,
238+
gif_framerate: 0.05,
230239
};
231240

232241
let temp_path = "./temp_config.toml";
@@ -250,6 +259,7 @@ mod tests {
250259
always_on_top: true,
251260
last_updated: 1635900000,
252261
gif_buffer: None,
262+
gif_framerate: 0.05,
253263
};
254264
test_config.save_to_toml(p).unwrap();
255265
}

src/system/gif_maker.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bevy::{
1414
// use bevy::render::view::RenderLayers; // Not currently used, commented out for now
1515
use bevy::window::{PrimaryWindow, WindowResized};
1616

17-
use crate::prelude::AppState;
17+
use crate::{prelude::AppState, system::config::UserSession};
1818

1919
//NOTE: new strategy, take_screenshot exists on the screenshot manager so let's just use that pushing images into an ordered stack of images.
2020
// On enter/exit we move into gif mode.
@@ -41,7 +41,9 @@ impl Plugin for GifMakerPlugin {
4141
app.add_systems(Update, gif_capture_toggle.run_if(on_message::<KeyboardInput>));
4242

4343
// Limit timestep we can snap for our gif to 20 FPS
44-
app.insert_resource(Time::<Fixed>::from_seconds(0.05));
44+
let user_config = app.world().get_resource::<UserSession>();
45+
let framerate = user_config.map_or(0.05, |c| c.gif_framerate);
46+
app.insert_resource(Time::<Fixed>::from_seconds(framerate));
4547
app.add_systems(
4648
FixedUpdate,
4749
(continous_capture.run_if(resource_exists_and_equals(Shooting(true))),),

0 commit comments

Comments
 (0)