sdl2_extras/fspecs/extensions/
world_ext.rs

1use adapters::{CanvasAdapter, GetCanvasError};
2use common::GameTime;
3use std::time::Duration;
4use sdl2::{
5    video::{Window, WindowContext},
6    render::{Canvas, TextureCreator}
7};
8use specs::World;
9
10pub trait WorldExt {
11    fn proceed_on_canvas<F>(&self, canvas_action: F) -> Result<(), GetCanvasError> where F: Fn(&mut Canvas<Window>);
12    fn update_delta_time(&mut self, new_delta: Duration);
13    fn get_texture_creator(&mut self) -> Result<TextureCreator<WindowContext>, GetCanvasError>;
14}
15
16impl WorldExt for World {
17    fn proceed_on_canvas<F>(&self, canvas_action: F) -> Result<(), GetCanvasError>
18    where F: Fn(&mut Canvas<Window>) {
19        self.write_resource::<CanvasAdapter>().proceed(canvas_action)
20    }
21
22    fn update_delta_time(&mut self, new_delta: Duration) {
23        self.write_resource::<GameTime>().set_delta(new_delta);
24    }
25
26    fn get_texture_creator(&mut self) -> Result<TextureCreator<WindowContext>, GetCanvasError> {
27        self.write_resource::<CanvasAdapter>().texture_creator()
28    }
29}