use std::time::Duration;
use super::config::Config;
use super::sound_system::SoundSystem;
use super::window::{Window, WindowCommand};
pub struct Context<Cfg>
where
Cfg: Config,
{
pub(super) delta: Duration,
pub(super) input: Cfg::Input,
pub(super) shall_stop: bool,
pub(super) window_commands: Vec<WindowCommand>,
pub(super) sound_system: Option<SoundSystem>,
pub(super) converter: Cfg::Converter,
}
impl<Cfg> Context<Cfg>
where
Cfg: Config,
{
pub fn delta(&self) -> Duration {
self.delta
}
pub fn input(&self) -> &Cfg::Input {
&self.input
}
pub fn shutdown(&mut self) {
self.shall_stop = true;
}
pub(super) fn shall_stop(&self) -> bool {
self.shall_stop
}
pub fn add_window_command<F: 'static + FnOnce(&mut Window)>(&mut self, command: F) {
self.window_commands.push(Box::new(command))
}
pub fn sound_system(&mut self) -> Option<&SoundSystem> {
self.sound_system.as_ref()
}
pub fn sound_system_mut(&mut self) -> Option<&mut SoundSystem> {
self.sound_system.as_mut()
}
pub fn converter(&self) -> &Cfg::Converter {
&self.converter
}
pub fn converter_mut(&mut self) -> &mut Cfg::Converter {
&mut self.converter
}
}