From 0ae6ca062f5936ae6f595f45ca0a78ed049452bc Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Sun, 9 Apr 2023 19:11:39 +0200 Subject: =?UTF-8?q?=E2=9C=A8=20Add=20scene=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- racer-tracer/src/scene_controller.rs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 racer-tracer/src/scene_controller.rs (limited to 'racer-tracer/src/scene_controller.rs') 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 { + 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; + + // 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>, TracerError>; + + // Called when the application wants to exit. + fn stop(&self); +} -- cgit v1.2.3