diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-04-09 19:11:39 +0200 |
|---|---|---|
| committer | Sakarias Johansson <sakariasjohansson@hotmail.com> | 2023-04-14 16:39:04 +0200 |
| commit | 0ae6ca062f5936ae6f595f45ca0a78ed049452bc (patch) | |
| tree | 712111e3aa823de7dc85eadca8fd5f78124afa6b /racer-tracer/src/scene_controller.rs | |
| parent | 5f8faa17457426c4ca8c54bf67b5aa96eb7a52ea (diff) | |
| download | racer-tracer-0ae6ca062f5936ae6f595f45ca0a78ed049452bc.tar.gz racer-tracer-0ae6ca062f5936ae6f595f45ca0a78ed049452bc.tar.xz racer-tracer-0ae6ca062f5936ae6f595f45ca0a78ed049452bc.zip | |
✨ Add scene controller
Wanted to be able to for example move around freely in the scene but
also have something that would for example follow key frames and
render a gif.
Abstracted it with a scene controller. You can hook up keybinds and
other thigns for it as well. Right now there is only the interactive
scene controller which keep the behaviours previous to this change.
Now I could possibly switch it out with something that uses key frames
to render several images to create for example a gif.
List of other Misc changes:
- Add configuration setting for scene controller (`scene_controller`)
- Add configuration setting for renderer
- Add configuration setting for preview renderer (`preview_renderer`)
- Add clone to Config.
- Add from implementation for Renderer to be created from the config
object.
- Add cancel event to image action. An action could be blocking when
the application wants to exit. Actions can now listen to the cancel
event to exit early and not block.
- Fixed bug where WaitForSignal action would block after application
tries to exit.
- Add method to KeyInputs to be able to take a list of callbacks instead of
manually registering every callback one at the time.
Diffstat (limited to 'racer-tracer/src/scene_controller.rs')
| -rw-r--r-- | racer-tracer/src/scene_controller.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/racer-tracer/src/scene_controller.rs b/racer-tracer/src/scene_controller.rs new file mode 100644 index 0000000..4a867f5 --- /dev/null +++ b/racer-tracer/src/scene_controller.rs @@ -0,0 +1,37 @@ +pub mod interactive; + +use slog::Logger; + +use crate::{ + camera::Camera, config::Config, error::TracerError, image::Image, key_inputs::KeyCallback, + scene::Scene, terminal::Terminal, +}; + +pub fn create_screen_buffer(image: &Image) -> Vec<u32> { + vec![0; image.width * image.height] +} + +pub struct SceneData { + pub log: Logger, + pub term: Terminal, + pub config: Config, + pub scene: Scene, + pub camera: Camera, + pub image: Image, +} + +pub trait SceneController: Send + Sync { + // Return a vector of key callbacks. The provided closure will be + // called when the corresponding key is release/pressed. + fn get_inputs(&self) -> Vec<KeyCallback>; + + // Render function + fn render(&self) -> Result<(), TracerError>; + + // Returns the screen buffer produced by the scene controller. + // Returns None if no new buffer is available + fn get_buffer(&self) -> Result<Option<Vec<u32>>, TracerError>; + + // Called when the application wants to exit. + fn stop(&self); +} |
