settings.rs
1 //! Engine wide settings that are applicable using the [Settings](crate::settings::Settings) struct. 2 3 use let_engine_core::backend::{ 4 Backends, 5 audio::{AudioBackend, AudioSettings}, 6 gpu::GpuBackend, 7 networking::NetworkingBackend, 8 }; 9 10 use crate::tick_system::TickSettings; 11 12 /// The initial settings of this engine. 13 pub struct EngineSettings<B: Backends> { 14 /// Settings that determines the look of the window. 15 #[cfg(feature = "client")] 16 pub window: crate::window::WindowBuilder, 17 18 /// The initial settings of the tick system. 19 pub tick_system: TickSettings, 20 21 /// The oldest allowed smooth delta time window calculation sample age. 22 /// 23 /// The higher this duration, the smoother the output of [`Time::fps`](crate::engine::Time::fps) 24 /// and the more readable the FPS value for human eyes. 25 /// 26 /// # Default 27 /// - `Duration::from_millis(300)` 28 #[cfg(feature = "client")] 29 pub oldest_fps_sample: std::time::Duration, 30 31 pub gpu: <B::Gpu as GpuBackend>::Settings, 32 pub audio: AudioSettings<B::Kira>, 33 pub networking: <B::Networking as NetworkingBackend>::Settings, 34 } 35 36 impl<B: Backends> Default for EngineSettings<B> 37 where 38 <B::Kira as AudioBackend>::Settings: Default, 39 { 40 fn default() -> Self { 41 Self { 42 #[cfg(feature = "client")] 43 window: crate::window::WindowBuilder::default(), 44 tick_system: TickSettings::default(), 45 #[cfg(feature = "client")] 46 oldest_fps_sample: std::time::Duration::from_millis(300), 47 gpu: <B::Gpu as GpuBackend>::Settings::default(), 48 audio: AudioSettings::default(), 49 networking: <B::Networking as NetworkingBackend>::Settings::default(), 50 } 51 } 52 } 53 54 impl<B: Backends> Clone for EngineSettings<B> 55 where 56 <B::Kira as AudioBackend>::Settings: Clone, 57 { 58 fn clone(&self) -> Self { 59 Self { 60 #[cfg(feature = "client")] 61 window: self.window.clone(), 62 tick_system: self.tick_system.clone(), 63 #[cfg(feature = "client")] 64 oldest_fps_sample: self.oldest_fps_sample, 65 gpu: self.gpu.clone(), 66 audio: self.audio.clone(), 67 networking: self.networking.clone(), 68 } 69 } 70 } 71 72 impl<B: Backends> EngineSettings<B> { 73 /// Sets the value `window` and returns self. 74 #[cfg(feature = "client")] 75 pub fn window(mut self, window: crate::window::WindowBuilder) -> Self { 76 self.window = window; 77 self 78 } 79 80 /// Sets the value `tick_system` and returns self. 81 pub fn tick_system(mut self, tick_system: TickSettings) -> Self { 82 self.tick_system = tick_system; 83 self 84 } 85 86 /// Sets the oldest allowed smooth delta time FPS calculation sample age. 87 #[cfg(feature = "client")] 88 pub fn oldest_fps_sample(mut self, sample_age: std::time::Duration) -> Self { 89 self.oldest_fps_sample = sample_age; 90 self 91 } 92 93 /// Sets the value `gpu` and returns self. 94 pub fn gpu(mut self, gpu: <B::Gpu as GpuBackend>::Settings) -> Self { 95 self.gpu = gpu; 96 self 97 } 98 99 /// Sets the value `networking` and returns self. 100 pub fn networking( 101 mut self, 102 networking: <B::Networking as NetworkingBackend>::Settings, 103 ) -> Self { 104 self.networking = networking; 105 self 106 } 107 }