diff options
Diffstat (limited to 'source')
24 files changed, 323 insertions, 177 deletions
diff --git a/source/benoit/benoit.rs b/source/benoit/benoit.rs index a9b7b42..c97e264 100644 --- a/source/benoit/benoit.rs +++ b/source/benoit/benoit.rs @@ -35,8 +35,8 @@ pub mod video; pub const VERSION: (u32, u32, u32) = ( 0x2, // Major - 0x5, // Minor - 0x1, // Patch + 0x6, // Minor + 0x0, // Patch ); pub const PRECISION: u32 = 0x80; diff --git a/source/benoit/benoit/app/handle_keys.rs b/source/benoit/benoit/app/handle_keys.rs index 5b27897..04e5a54 100644 --- a/source/benoit/benoit/app/handle_keys.rs +++ b/source/benoit/benoit/app/handle_keys.rs @@ -117,39 +117,33 @@ impl App { } fn cycle_fractal(&mut self, distance: i8) { - self.fractal.cycle(distance); + self.fractal.kind.cycle(distance); - eprintln!("renderer the {}", self.fractal.kind().name()); + eprintln!("renderer the {}", self.fractal.kind.name()); } fn toggle_inverse(&mut self) { - let inverse = !self.fractal.inverse(); + self.fractal.inverse = !self.fractal.inverse; - match inverse { + match self.fractal.inverse { false => eprintln!("reverting fractal"), true => eprintln!("inverting fractals"), }; - - self.fractal.set_inverse(inverse); } fn toggle_julia(&mut self) { - let julia = !self.fractal.julia(); + self.fractal.julia = !self.fractal.julia; - match julia { + match self.fractal.julia { false => eprintln!("disabled the julia set"), true => eprintln!("enabled the julia set"), }; - - self.fractal.set_julia(julia); } fn cycle_palette(&mut self, direction: i8) { - let palette = self.palette.cycle(direction); - - eprintln!("using palette \"{}\"", palette.name()); + self.palette.cycle(direction); - self.palette = palette; + eprintln!("using palette \"{}\"", self.palette.name()); } fn reset_viewport(&mut self) { diff --git a/source/benoit/benoit/app/print_controls.rs b/source/benoit/benoit/app/print_controls.rs index 936d286..f6f2612 100644 --- a/source/benoit/benoit/app/print_controls.rs +++ b/source/benoit/benoit/app/print_controls.rs @@ -24,7 +24,7 @@ use crate::benoit::app::App; impl App { - pub(super) fn print_controls(&self) { + pub(super) fn print_controls() { println!("Controls:"); println!("- \u{1B}[1mW\u{1B}[0m Translate +Im"); println!("- \u{1B}[1mA\u{1B}[0m Translate -Re"); diff --git a/source/benoit/benoit/app/run.rs b/source/benoit/benoit/app/run.rs index b4f8fb4..1810faa 100644 --- a/source/benoit/benoit/app/run.rs +++ b/source/benoit/benoit/app/run.rs @@ -36,12 +36,12 @@ impl App { pub fn run(mut self) -> i32 { let mut video = Video::initialise(self.canvas_width, self.canvas_height, self.scale); - self.print_controls(); + App::print_controls(); let mut event_pump = video.sdl.event_pump().expect("unable to get event pump"); - let mut image = Image::allocate( self.canvas_width, self.canvas_height); let mut render = Render::allocate(self.canvas_width, self.canvas_height); + let mut image = Image::allocate( self.canvas_width, self.canvas_height); // Used for translation feedback: let mut prev_centre = self.centre.clone(); @@ -63,9 +63,8 @@ impl App { image.colour(&render, self.palette, self.max_iter_count, self.colour_range); - video.draw(&image, self.scale); + video.draw_image(&image, self.scale); self.draw_feedback(&mut video, &prev_centre, &prev_zoom); - video.update(); video.sync(&frame_start); diff --git a/source/benoit/benoit/configuration.rs b/source/benoit/benoit/configuration.rs index 104ba41..ca96a54 100644 --- a/source/benoit/benoit/configuration.rs +++ b/source/benoit/benoit/configuration.rs @@ -60,7 +60,7 @@ pub struct Configuration { } impl Configuration { - pub const DEFAULT_FRACTAL: Fractal = Fractal::new(FractalKind::Mandelbrot, false, false); + pub const DEFAULT_FRACTAL: Fractal = Fractal { kind: FractalKind::Mandelbrot, inverse: false, julia: false }; pub const DEFAULT_CENTRE: (f64, f64) = (0.0, 0.0); pub const DEFAULT_EXTRA: (f64, f64) = (0.0, 0.0); diff --git a/source/benoit/benoit/configuration/load.rs b/source/benoit/benoit/configuration/load.rs index f17c145..a993a4d 100644 --- a/source/benoit/benoit/configuration/load.rs +++ b/source/benoit/benoit/configuration/load.rs @@ -52,20 +52,16 @@ impl Configuration { get_integer(&mut configuration.thread_count, &configuration_table, "thread_count"); if let Some(name) = get_string(&configuration_table, "fractal") { - configuration.fractal.set_kind(match name.as_str() { - "burningship" => FractalKind::BurningShip, - "mandelbrot" => FractalKind::Mandelbrot, - "multibrot3" => FractalKind::Multibrot3, - "multibrot4" => FractalKind::Multibrot4, - "tricorn" => FractalKind::Tricorn, - name => panic!("invalid fractal kind \"{name}\""), - }); + configuration.fractal.kind = match FractalKind::from_str(name.as_str()) { + Ok(kind) => kind, + Err(message) => panic!("{message}"), + }; } { let mut inverse = false; get_boolean(&mut inverse, &configuration_table, "inverse"); - configuration.fractal.set_inverse(inverse); + configuration.fractal.inverse = inverse; } get_integer(&mut configuration.canvas_width, &configuration_table, "canvas_width"); @@ -82,16 +78,9 @@ impl Configuration { get_integer(&mut configuration.max_iter_count, &configuration_table, "maximum_iteration_count"); if let Some(name) = get_string(&configuration_table, "palette") { - configuration.palette = match name.as_str() { - "emerald" => Palette::Emerald, - "fire" => Palette::Fire, - "greyscale" => Palette::Greyscale, - "hsv" => Palette::Hsv, - "lch" => Palette::Lch, - "ruby" => Palette::Ruby, - "sapphire" => Palette::Sapphire, - "twilight" => Palette::Twilight, - name => panic!("invalid palette \"{name}\""), + configuration.palette = match Palette::from_str(name.as_str()) { + Ok(palette) => palette, + Err(message) => panic!("{message}"), }; } @@ -102,10 +91,9 @@ impl Configuration { } if let Some(name) = get_string(&configuration_table, "image_format") { - configuration.image_format = match name.as_str() { - "png" => ImageFormat::Png, - "webp" => ImageFormat::Webp, - name => panic!("invalid image format \"{name}\""), + configuration.image_format = match ImageFormat::from_str(name.as_str()) { + Ok(format) => format, + Err(message) => panic!("{message}"), }; } diff --git a/source/benoit/benoit/fractal.rs b/source/benoit/benoit/fractal.rs index 7630571..74ad168 100644 --- a/source/benoit/benoit/fractal.rs +++ b/source/benoit/benoit/fractal.rs @@ -25,14 +25,11 @@ use crate::benoit::complex::Complex; use std::mem::transmute; +pub mod from_str; + mod iterate; -#[derive(Clone, Copy)] -pub struct Fractal { - kind: FractalKind, - inverse: bool, - julia: bool, -} +pub type IteratorFunction = fn(&mut Complex, &Complex); #[derive(Clone, Copy)] #[repr(u8)] @@ -45,20 +42,41 @@ pub enum FractalKind { Multibrot4, } -pub type IteratorFunction = fn(&mut Complex, &Complex); +impl FractalKind { + const NUM: usize = Self::Multibrot4 as usize + 0x1; -impl Fractal { - #[must_use] - pub const fn new(kind: FractalKind, inverse: bool, julia: bool) -> Self { - let fractal = Fractal { - kind: kind, - inverse: inverse, - julia: julia, + pub fn name(self) -> &'static str { + return match self { + FractalKind::BurningShip => "burning ship", + FractalKind::Mandelbrot => "mandelbrot set", + FractalKind::Multibrot3 => "multibrot3 set", + FractalKind::Multibrot4 => "multibrot4 set", + FractalKind::Tricorn => "tricorn", + }; + } + + pub fn cycle(&mut self, direction: i8) { + let raw = *self as i16 + direction as i16; + + const NUM: isize = FractalKind::NUM as isize; + let new: u8 = match raw as isize { + -0x1 => (FractalKind::NUM - 0x1) as u8, + NUM => 0x0, + _ => raw as u8, }; - return fractal; + *self = unsafe { transmute(new) }; } +} + +#[derive(Clone, Copy)] +pub struct Fractal { + pub kind: FractalKind, + pub inverse: bool, + pub julia: bool, +} +impl Fractal { pub fn name(&self) -> String { let kind = self.kind.name(); @@ -77,21 +95,6 @@ impl Fractal { } #[must_use] - pub fn kind(&self) -> FractalKind { - return self.kind; - } - - #[must_use] - pub fn inverse(&self) -> bool { - return self.inverse; - } - - #[must_use] - pub fn julia(&self) -> bool { - return self.julia; - } - - #[must_use] pub fn exponent(&self) -> f32 { return match self.kind { FractalKind::BurningShip => 2.0, @@ -112,50 +115,4 @@ impl Fractal { FractalKind::Tricorn => iterate::tricorn, }; } - - pub fn set_kind(&mut self, kind: FractalKind) { - self.kind = kind; - } - - pub fn set_inverse(&mut self, inverse: bool) { - self.inverse = inverse; - } - - pub fn set_julia(&mut self, julia: bool) { - self.julia = julia; - } - - pub fn cycle(&mut self, direction: i8) { - // Not important. - debug_assert!(direction != 0x0); - - let raw = self.kind as i8 + direction; - - let new: FractalKind = if raw < 0x0 { - FractalKind::MAX - } else if raw > FractalKind::MAX as i8 { - FractalKind::MIN - } else { - unsafe { transmute(raw) } - }; - - let new: FractalKind = unsafe { transmute(new) }; - - self.kind = new; - } -} - -impl FractalKind { - const MIN: FractalKind = FractalKind::Mandelbrot; - const MAX: FractalKind = FractalKind::Multibrot4; - - pub fn name(self) -> &'static str { - return match self { - FractalKind::BurningShip => "burning ship", - FractalKind::Mandelbrot => "mandelbrot set", - FractalKind::Multibrot3 => "multibrot3 set", - FractalKind::Multibrot4 => "multibrot4 set", - FractalKind::Tricorn => "tricorn", - }; - } } diff --git a/source/benoit/benoit/fractal/from_str.rs b/source/benoit/benoit/fractal/from_str.rs new file mode 100644 index 0000000..151fc98 --- /dev/null +++ b/source/benoit/benoit/fractal/from_str.rs @@ -0,0 +1,48 @@ +/* + Copyright 2021, 2023 Gabriel Bjørnager Jensen. + + This file is part of Benoit. + + Benoit is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + Benoit is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU + Affero General Public License along with Benoit. + If not, see <https://www.gnu.org/licenses/>. +*/ + +use crate::benoit::fractal::FractalKind; + +use std::str::FromStr; + +impl FromStr for FractalKind { + type Err = String; + + fn from_str(string: &str) -> Result<Self, Self::Err> { + use FractalKind::*; + + let kind = match string { + "burningship" => Some(BurningShip), + "mandelbrot" => Some(Mandelbrot), + "multibrot3" => Some(Multibrot3), + "multibrot4" => Some(Multibrot4), + "tricorn" => Some(Tricorn), + _ => None, + }; + + return match kind { + Some(kind) => Ok(kind), + _ => Err(format!("invalid fractal kind \"{string}\"")), + }; + } +} diff --git a/source/benoit/benoit/image.rs b/source/benoit/benoit/image.rs index dffacb0..4b9396f 100644 --- a/source/benoit/benoit/image.rs +++ b/source/benoit/benoit/image.rs @@ -27,6 +27,7 @@ use std::slice::from_raw_parts; pub mod allocate; pub mod colour; pub mod dump; +pub mod from_str; pub struct Image { width: u32, diff --git a/source/benoit/benoit/image/from_str.rs b/source/benoit/benoit/image/from_str.rs new file mode 100644 index 0000000..c4a86b9 --- /dev/null +++ b/source/benoit/benoit/image/from_str.rs @@ -0,0 +1,45 @@ +/* + Copyright 2021, 2023 Gabriel Bjørnager Jensen. + + This file is part of Benoit. + + Benoit is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + Benoit is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU + Affero General Public License along with Benoit. + If not, see <https://www.gnu.org/licenses/>. +*/ + +use crate::benoit::image::ImageFormat; + +use std::str::FromStr; + +impl FromStr for ImageFormat { + type Err = String; + + fn from_str(string: &str) -> Result<Self, Self::Err> { + use ImageFormat::*; + + let kind = match string { + "png" => Some(Png), + "webp" => Some(Webp), + _ => None, + }; + + return match kind { + Some(kind) => Ok(kind), + _ => Err(format!("invalid image format \"{string}\"")), + }; + } +} diff --git a/source/benoit/benoit/palette.rs b/source/benoit/benoit/palette.rs index f47b4fb..8235bbc 100644 --- a/source/benoit/benoit/palette.rs +++ b/source/benoit/benoit/palette.rs @@ -26,6 +26,8 @@ extern crate enum_iterator; use enum_iterator::Sequence; use std::mem::transmute; +pub mod from_str; + mod data; mod paint; @@ -37,7 +39,7 @@ pub type PaletteData = [(f32, f32, f32); PALETTE_DATA_LENGTH]; #[derive(Clone, Copy, Sequence)] #[repr(u8)] pub enum Palette { - // Sorted according to date of addition. + Simple, Twilight, Fire, Greyscale, @@ -49,8 +51,7 @@ pub enum Palette { } impl Palette { - const MIN: Self = Palette::Twilight; - const MAX: Self = Palette::Lch; + pub const NUM: usize = Self::Lch as usize + 0x1; #[must_use] pub fn name(self) -> &'static str { @@ -62,6 +63,7 @@ impl Palette { Palette::Lch => "lch", Palette::Ruby => "ruby", Palette::Sapphire => "sapphire", + Palette::Simple => "simple", Palette::Twilight => "twilight", }; } @@ -72,19 +74,17 @@ impl Palette { return unsafe { &*self.mut_data() }; } - #[must_use] - pub fn cycle(&self, direction: i8) -> Self { - let raw = *self as i8 + direction; - - let new: Palette = if raw < 0x0 { - Palette::MAX - } else if raw > Palette::MAX as i8 { - Palette::MIN - } else { - unsafe { transmute(raw) } + pub fn cycle(&mut self, direction: i8) { + let raw = *self as i16 + direction as i16; + + const NUM: isize = Palette::NUM as isize; + let new: u8 = match raw as isize { + -0x1 => (Self::NUM - 0x1) as u8, + NUM => 0x0, + _ => raw as u8, }; - return new; + *self = unsafe { transmute(new) }; } #[must_use] @@ -97,6 +97,7 @@ impl Palette { Palette::Lch => paint::lch, Palette::Ruby => paint::ruby, Palette::Sapphire => paint::sapphire, + Palette::Simple => paint::simple, Palette::Twilight => paint::twilight, }; } diff --git a/source/benoit/benoit/palette/data.rs b/source/benoit/benoit/palette/data.rs index cd5d866..fdb8fa9 100644 --- a/source/benoit/benoit/palette/data.rs +++ b/source/benoit/benoit/palette/data.rs @@ -32,36 +32,15 @@ use std::time::Instant; impl Palette { #[must_use] pub(super) unsafe fn mut_data(self) -> &'static mut PaletteData { - return match self { - Palette::Emerald => &mut DATA_EMERALD, - Palette::Fire => &mut DATA_FIRE, - Palette::Greyscale => &mut DATA_GREYSCALE, - Palette::Hsv => &mut DATA_HSV, - Palette::Lch => &mut DATA_LCH, - Palette::Ruby => &mut DATA_RUBY, - Palette::Sapphire => &mut DATA_SAPPHIRE, - Palette::Twilight => &mut DATA_TWILIGHT, - }; + return &mut PALETTE_DATA[self as usize]; } } -#[must_use] -const fn default_palette_data() -> PaletteData { - return [(0.0, 0.0, 0.0); PALETTE_DATA_LENGTH]; -} - -static mut DATA_EMERALD: PaletteData = default_palette_data(); -static mut DATA_FIRE: PaletteData = default_palette_data(); -static mut DATA_GREYSCALE: PaletteData = default_palette_data(); -static mut DATA_HSV: PaletteData = default_palette_data(); -static mut DATA_LCH: PaletteData = default_palette_data(); -static mut DATA_RUBY: PaletteData = default_palette_data(); -static mut DATA_SAPPHIRE: PaletteData = default_palette_data(); -static mut DATA_TWILIGHT: PaletteData = default_palette_data(); - -static PALETTES_FILLED: AtomicBool = AtomicBool::new(false); +static mut PALETTE_DATA: [PaletteData; Palette::NUM] = [[(0.0, 0.0, 0.0); PALETTE_DATA_LENGTH]; Palette::NUM]; pub fn fill_palettes() { + static PALETTES_FILLED: AtomicBool = AtomicBool::new(false); + match PALETTES_FILLED.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) { Err(_) => panic!("palettes already filled"), _ => {}, diff --git a/source/benoit/benoit/palette/from_str.rs b/source/benoit/benoit/palette/from_str.rs new file mode 100644 index 0000000..3576d74 --- /dev/null +++ b/source/benoit/benoit/palette/from_str.rs @@ -0,0 +1,52 @@ +/* + Copyright 2021, 2023 Gabriel Bjørnager Jensen. + + This file is part of Benoit. + + Benoit is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + Benoit is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU + Affero General Public License along with Benoit. + If not, see <https://www.gnu.org/licenses/>. +*/ + +use crate::benoit::palette::Palette; + +use std::str::FromStr; + +impl FromStr for Palette { + type Err = String; + + fn from_str(string: &str) -> Result<Self, Self::Err> { + use Palette::*; + + let kind = match string { + "emerald" => Some(Emerald), + "fire" => Some(Fire), + "greyscale" => Some(Greyscale), + "hsv" => Some(Hsv), + "lch" => Some(Lch), + "ruby" => Some(Ruby), + "sapphire" => Some(Sapphire), + "simple" => Some(Simple), + "twilight" => Some(Twilight), + _ => None, + }; + + return match kind { + Some(kind) => Ok(kind), + _ => Err(format!("invalid palette \"{string}\"")), + }; + } +} diff --git a/source/benoit/benoit/palette/paint.rs b/source/benoit/benoit/palette/paint.rs index 4859c28..84ff005 100644 --- a/source/benoit/benoit/palette/paint.rs +++ b/source/benoit/benoit/palette/paint.rs @@ -28,6 +28,7 @@ pub mod hsv; pub mod lch; pub mod ruby; pub mod sapphire; +pub mod simple; pub mod twilight; pub use emerald::*; @@ -37,4 +38,5 @@ pub use hsv::*; pub use lch::*; pub use ruby::*; pub use sapphire::*; +pub use simple::*; pub use twilight::*; diff --git a/source/benoit/benoit/palette/paint/simple.rs b/source/benoit/benoit/palette/paint/simple.rs new file mode 100644 index 0000000..c2e013f --- /dev/null +++ b/source/benoit/benoit/palette/paint/simple.rs @@ -0,0 +1,32 @@ +/* + Copyright 2021, 2023 Gabriel Bjørnager Jensen. + + This file is part of Benoit. + + Benoit is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + Benoit is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU + Affero General Public License along with Benoit. + If not, see <https://www.gnu.org/licenses/>. +*/ + +// Original colour palette from MandelbrotSDL. + +pub fn simple(factor: f32) -> (f32, f32, f32) { + let red = factor * 3.0 % 1.0; + let green = factor * 5.0 % 1.0; + let blue = factor * 7.0 % 1.0; + + return (red, green, blue); +} diff --git a/source/benoit/benoit/render/render.rs b/source/benoit/benoit/render/render.rs index 7ce1a3e..63a0e19 100644 --- a/source/benoit/benoit/render/render.rs +++ b/source/benoit/benoit/render/render.rs @@ -53,8 +53,8 @@ impl Render { extra.clone(), zoom.clone(), max_iter_count, - fractal.inverse(), - fractal.julia(), + fractal.inverse, + fractal.julia, ); let iterator = fractal.iterator(); diff --git a/source/benoit/benoit/script.rs b/source/benoit/benoit/script.rs index 6403bef..8cff0ca 100644 --- a/source/benoit/benoit/script.rs +++ b/source/benoit/benoit/script.rs @@ -32,8 +32,9 @@ use rug::Float; pub mod animate; pub mod configure; -pub mod dump; +pub mod dump_frame; pub mod run; +pub mod set_title; pub mod still; pub struct Script { diff --git a/source/benoit/benoit/script/animate.rs b/source/benoit/benoit/script/animate.rs index 48fea58..8745090 100644 --- a/source/benoit/benoit/script/animate.rs +++ b/source/benoit/benoit/script/animate.rs @@ -36,8 +36,8 @@ impl Script { pub(super) fn animate(&self) -> i32 { let frame_count = self.frame_stop - self.frame_start + 0x1; - let mut image = Image::allocate( self.canvas_width, self.canvas_height); let mut render = Render::allocate(self.canvas_width, self.canvas_height); + let mut image = Image::allocate( self.canvas_width, self.canvas_height); // zoom_start: let mut zoom = Float::with_val(PRECISION, 1.0 / 4.0); @@ -60,7 +60,7 @@ impl Script { for frame in 0x0..=frame_count { let frame_name = format!("frame{frame:010}"); - Script::dump( + Script::dump_frame( self.dump_path.as_str(), frame_name.as_str(), &mut image, diff --git a/source/benoit/benoit/script/dump.rs b/source/benoit/benoit/script/dump_frame.rs index d8c23f2..29dd718 100644 --- a/source/benoit/benoit/script/dump.rs +++ b/source/benoit/benoit/script/dump_frame.rs @@ -34,7 +34,7 @@ use rug::Float; use std::time::Instant; impl Script { - pub(super) fn dump( + pub(super) fn dump_frame( dump_path: &str, name: &str, image: &mut Image, @@ -48,7 +48,8 @@ impl Script { colour_range: f32, image_format: ImageFormat, ) { - eprint!("\"{name}\" (2^{:.9}x)...", zoom.to_f64().log2()); + eprint!("\"{name}\" (2^{:.9}x): rendering...", zoom.to_f64().log2()); + Script::set_title("rendering"); let time_start = Instant::now(); @@ -62,15 +63,19 @@ impl Script { let render_time = time_start.elapsed(); eprint!(" {:.3}ms, colouring...", render_time.as_micros() as f32 / 1000.0); + Script::set_title("colouring"); image.colour(&render, palette, max_iter_count, colour_range); let colour_time = time_start.elapsed() - render_time; - eprint!(" {:.3}ms...", colour_time.as_micros() as f32 / 1000.0); + eprint!(" {:.3}ms, dumping...", colour_time.as_micros() as f32 / 1000.0); + Script::set_title("dumping"); let path = format!("{dump_path}/{name}"); - image.dump(path.as_str(), image_format); - eprintln!(" done"); + + let dump_time = time_start.elapsed() - colour_time - render_time; + eprintln!(" {:.3}ms - \u{1B}[1m\u{1B}[92mdone!\u{1B}[0m", dump_time.as_micros() as f32 / 1000.0); + Script::set_title("done"); } } diff --git a/source/benoit/benoit/script/set_title.rs b/source/benoit/benoit/script/set_title.rs new file mode 100644 index 0000000..d063165 --- /dev/null +++ b/source/benoit/benoit/script/set_title.rs @@ -0,0 +1,42 @@ +/* + Copyright 2021, 2023 Gabriel Bjørnager Jensen. + + This file is part of Benoit. + + Benoit is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + Benoit is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU + Affero General Public License along with Benoit. + If not, see <https://www.gnu.org/licenses/>. +*/ + +use crate::benoit::script::Script; + +#[cfg(windows)] +extern crate windows; + +#[cfg(windows)] +use windows::Win32::System::Console::SetConsoleTitleA; + +impl Script { + #[cfg(unix)] + pub(super) fn set_title(title: &str) { + eprint!("\u{1B}]0;{title}\u{07}"); + } + + #[cfg(windows)] + pub(super) fn set_title(title: &str) { + unsafe { SetConsoleTitleA(title) }; + } +} diff --git a/source/benoit/benoit/script/still.rs b/source/benoit/benoit/script/still.rs index b93dc11..8da69ca 100644 --- a/source/benoit/benoit/script/still.rs +++ b/source/benoit/benoit/script/still.rs @@ -28,12 +28,12 @@ use crate::benoit::script::Script; impl Script { #[must_use] pub(super) fn still(&self) -> i32 { - let mut image = Image::allocate( self.canvas_width, self.canvas_height); let mut render = Render::allocate(self.canvas_width, self.canvas_height); + let mut image = Image::allocate( self.canvas_width, self.canvas_height); const FRAME_NAME: &str = "render"; - Script::dump( + Script::dump_frame( self.dump_path.as_str(), FRAME_NAME, &mut image, diff --git a/source/benoit/benoit/video.rs b/source/benoit/benoit/video.rs index 88c853b..d0de33f 100644 --- a/source/benoit/benoit/video.rs +++ b/source/benoit/benoit/video.rs @@ -26,7 +26,7 @@ extern crate sdl2; use sdl2::{Sdl, VideoSubsystem}; use sdl2::render::WindowCanvas; -pub mod draw; +pub mod draw_image; pub mod draw_textual_feedback; pub mod draw_translation_feedback; pub mod initialise; diff --git a/source/benoit/benoit/video/draw.rs b/source/benoit/benoit/video/draw_image.rs index 69b77b2..9554b3b 100644 --- a/source/benoit/benoit/video/draw.rs +++ b/source/benoit/benoit/video/draw_image.rs @@ -30,7 +30,7 @@ use sdl2::pixels::Color; use sdl2::rect::Rect; impl Video { - pub fn draw(&mut self, image: &Image, scale: u32) { + pub fn draw_image(&mut self, image: &Image, scale: u32) { let (canvas_width, canvas_height) = image.size(); let canvas_size = canvas_height as usize * canvas_width as usize; diff --git a/source/benoit/main.rs b/source/benoit/main.rs index adc1617..eb857b8 100644 --- a/source/benoit/main.rs +++ b/source/benoit/main.rs @@ -38,10 +38,10 @@ use std::thread::available_parallelism; fn main() { println!(); - println!("\u{1B}[1mBENO\u{CE}T\u{1B}[0m {:X}.{:X}.{:X}", VERSION.0, VERSION.1, VERSION.2); - println!("Copyright 2021, 2023 Gabriel Bj\u{F8}rnager Jensen."); + println!(" \u{1B}[1mBENO\u{CE}T\u{1B}[0m {:X}.{:X}.{:X}", VERSION.0, VERSION.1, VERSION.2); + println!(" Copyright 2021, 2023 Gabriel Bj\u{F8}rnager Jensen."); println!(); - println!("Le p\u{E8}re cogita et c'est pourquoi il fut."); + println!(" \u{1B}[3mLe p\u{E8}re cogita et c'est pourquoi il fut.\u{1B}[0m"); println!(); fill_palettes(); |