Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The thing that makes the computer go

Implementations§

Source§

impl Engine

Source

pub fn is_key_down(&self, key: Key) -> bool

Checks if a key is down

Examples found in repository?
examples/rectangles.rs (line 122)
110    fn update(&mut self, engine_handle: &mut Engine) {
111        let dt = engine_handle.get_frame_delta_time();
112        self.pos.x += 100.0 * dt;
113        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114            let new_texture = Texture::new(
115                engine_handle,
116                "examples/eggshark.png",
117                LoadingOp::Background,
118            );
119            self.texture_material.change_texture(new_texture);
120        }
121
122        self.state = engine_handle.is_key_down(Key::Space);
123    }
More examples
Hide additional examples
examples/camera.rs (line 73)
66    fn update(&mut self, engine_handle: &mut Engine) {
67        let dt = engine_handle.get_frame_delta_time();
68        let mouse_pos = engine_handle.get_mouse_position();
69        let size = engine_handle.get_window_size();
70
71        let move_factor = 15.0;
72
73        if engine_handle.is_key_down(Key::A) {
74            self.camera.center.x -= move_factor * dt;
75        }
76
77        if engine_handle.is_key_down(Key::D) {
78            self.camera.center.x += move_factor * dt;
79        }
80
81        if engine_handle.is_key_down(Key::W) {
82            self.camera.center.y += move_factor * dt;
83        }
84
85        if engine_handle.is_key_down(Key::S) {
86            self.camera.center.y -= move_factor * dt;
87        }
88
89        if engine_handle.is_key_down(Key::Left) {
90            self.camera.rotation += move_factor * dt;
91        }
92
93        if engine_handle.is_key_down(Key::Right) {
94            self.camera.rotation -= move_factor * dt;
95        }
96
97        if engine_handle.is_key_down(Key::L) {
98            self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99        }
100
101        if engine_handle.is_key_down(Key::K) {
102            self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103        }
104
105        if engine_handle.is_key_pressed(Key::Enter) {
106            self.camera.rotation += 45.0;
107        }
108
109        let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111        self.text.set_text(
112            &format!(
113                "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114                mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115            ),
116            Colour::WHITE,
117            engine_handle,
118        );
119
120        self.text.prepare(engine_handle);
121    }
Source

pub fn is_key_up(&self, key: Key) -> bool

Checks if a key is up

Source

pub fn is_key_pressed(&self, key: Key) -> bool

Only returns true on the frame where the key is first pressed down

Examples found in repository?
examples/camera.rs (line 105)
66    fn update(&mut self, engine_handle: &mut Engine) {
67        let dt = engine_handle.get_frame_delta_time();
68        let mouse_pos = engine_handle.get_mouse_position();
69        let size = engine_handle.get_window_size();
70
71        let move_factor = 15.0;
72
73        if engine_handle.is_key_down(Key::A) {
74            self.camera.center.x -= move_factor * dt;
75        }
76
77        if engine_handle.is_key_down(Key::D) {
78            self.camera.center.x += move_factor * dt;
79        }
80
81        if engine_handle.is_key_down(Key::W) {
82            self.camera.center.y += move_factor * dt;
83        }
84
85        if engine_handle.is_key_down(Key::S) {
86            self.camera.center.y -= move_factor * dt;
87        }
88
89        if engine_handle.is_key_down(Key::Left) {
90            self.camera.rotation += move_factor * dt;
91        }
92
93        if engine_handle.is_key_down(Key::Right) {
94            self.camera.rotation -= move_factor * dt;
95        }
96
97        if engine_handle.is_key_down(Key::L) {
98            self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99        }
100
101        if engine_handle.is_key_down(Key::K) {
102            self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103        }
104
105        if engine_handle.is_key_pressed(Key::Enter) {
106            self.camera.rotation += 45.0;
107        }
108
109        let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111        self.text.set_text(
112            &format!(
113                "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114                mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115            ),
116            Colour::WHITE,
117            engine_handle,
118        );
119
120        self.text.prepare(engine_handle);
121    }
Source

pub fn is_key_released(&self, key: Key) -> bool

Only returns true on the frame where the key first returns back up

Source

pub fn check_modifiers(&self, modifer: ModifierKeys) -> bool

This will tell you if certain keys like CTRL or Shift are modifying the current key presses.

Source

pub fn get_current_text(&self) -> Option<&str>

returns the text vule of any keys held down helpfull for text entry. As if Shift + w is held this will return Some("W")

Examples found in repository?
examples/input.rs (line 37)
36    fn update(&mut self, engine_handle: &mut Engine) {
37        let text = engine_handle.get_current_text();
38        if let Some(s) = text {
39            self.text.push_str(s);
40
41            self.text_mat
42                .set_text(&self.text, Colour::RED, engine_handle)
43        }
44
45        self.text_mat.prepare(engine_handle);
46    }
Source

pub fn is_mouse_key_down(&self, key: MouseKey) -> bool

Checks if a mouse key is down

Source

pub fn is_mouse_key_up(&self, key: MouseKey) -> bool

Checks if a mouse key is up

Source

pub fn is_mouse_key_pressed(&self, key: MouseKey) -> bool

Only returns true on the frame where the key is first pressed down

Examples found in repository?
examples/texture.rs (line 56)
54    fn update(&mut self, engine_handle: &mut Engine) {
55        let dt = engine_handle.get_frame_delta_time();
56        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
57            std::mem::swap(&mut self.other, &mut self.current);
58        }
59        self.pos.x += 100.0 * dt;
60    }
More examples
Hide additional examples
examples/rectangles.rs (line 113)
110    fn update(&mut self, engine_handle: &mut Engine) {
111        let dt = engine_handle.get_frame_delta_time();
112        self.pos.x += 100.0 * dt;
113        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114            let new_texture = Texture::new(
115                engine_handle,
116                "examples/eggshark.png",
117                LoadingOp::Background,
118            );
119            self.texture_material.change_texture(new_texture);
120        }
121
122        self.state = engine_handle.is_key_down(Key::Space);
123    }
examples/text.rs (line 55)
48    fn update(&mut self, engine_handle: &mut Engine) {
49        self.font_size += 2.0 * engine_handle.get_frame_delta_time();
50
51        self.text_mat.set_font_size(self.font_size, engine_handle);
52        self.text_mat
53            .set_line_height(self.font_size * 1.3, engine_handle);
54
55        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
56            self.text_mat.set_text_with_font(
57                "hello I am talking to you here???",
58                Colour::GREEN,
59                &self.comic,
60                engine_handle,
61            );
62        }
63
64        self.text_mat.prepare(engine_handle);
65    }
Source

pub fn is_mouse_key_released(&self, key: MouseKey) -> bool

Only returns true on the frame where the key first returns back up

Source

pub fn get_mouse_position(&self) -> Vec2<f32>

Gives the current position of the mouse in physical pixels

Examples found in repository?
examples/lightmap.rs (line 96)
95    fn update(&mut self, engine_handle: &mut Engine) {
96        let mouse_pos = engine_handle.get_mouse_position();
97        self.mouse_pos = mouse_pos;
98        let window_size = engine_handle.get_window_size();
99
100        self.light.pos_x = mouse_pos.x / window_size.x as f32;
101        self.light.pos_y = mouse_pos.y / window_size.y as f32;
102        self.material
103            .update_uniform_data(&self.light, &engine_handle)
104            .unwrap();
105
106        self.material
107            .update_uniform_texture(&mut self.uniform_texture, engine_handle)
108            .unwrap_or_else(|_| {});
109    }
More examples
Hide additional examples
examples/shader.rs (line 114)
108    fn update(&mut self, engine_handle: &mut Engine) {
109        let dt = engine_handle.get_frame_delta_time();
110
111        self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113        let size = engine_handle.get_window_size();
114        let mouse_pos = engine_handle.get_mouse_position();
115
116        let new_data = MousePos {
117            x: mouse_pos.x / size.x as f32,
118            y: mouse_pos.y / size.y as f32,
119            _junk: 0.0,
120            _padding2: 0.0,
121        };
122
123        self.data = new_data;
124        self.mouse_material
125            .update_uniform_data(&self.data, &engine_handle)
126            .unwrap();
127        self.circle_material
128            .update_uniform_data(&self.theta, &engine_handle)
129            .unwrap();
130    }
examples/camera.rs (line 68)
66    fn update(&mut self, engine_handle: &mut Engine) {
67        let dt = engine_handle.get_frame_delta_time();
68        let mouse_pos = engine_handle.get_mouse_position();
69        let size = engine_handle.get_window_size();
70
71        let move_factor = 15.0;
72
73        if engine_handle.is_key_down(Key::A) {
74            self.camera.center.x -= move_factor * dt;
75        }
76
77        if engine_handle.is_key_down(Key::D) {
78            self.camera.center.x += move_factor * dt;
79        }
80
81        if engine_handle.is_key_down(Key::W) {
82            self.camera.center.y += move_factor * dt;
83        }
84
85        if engine_handle.is_key_down(Key::S) {
86            self.camera.center.y -= move_factor * dt;
87        }
88
89        if engine_handle.is_key_down(Key::Left) {
90            self.camera.rotation += move_factor * dt;
91        }
92
93        if engine_handle.is_key_down(Key::Right) {
94            self.camera.rotation -= move_factor * dt;
95        }
96
97        if engine_handle.is_key_down(Key::L) {
98            self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99        }
100
101        if engine_handle.is_key_down(Key::K) {
102            self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103        }
104
105        if engine_handle.is_key_pressed(Key::Enter) {
106            self.camera.rotation += 45.0;
107        }
108
109        let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111        self.text.set_text(
112            &format!(
113                "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114                mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115            ),
116            Colour::WHITE,
117            engine_handle,
118        );
119
120        self.text.prepare(engine_handle);
121    }
Source

pub fn get_mouse_delta(&self) -> Vec2<f32>

Returns how much the mouse has moved in the last frame

Source

pub fn window_has_focus(&self) -> bool

Checks if the window has focus

§Panics

When called outside of the functions in the Game trait

Source

pub fn is_window_maximized(&self) -> bool

Checks if the window is maximized not fullscreened

§Panics

When called outside of the functions in the Game trait

Source

pub fn is_window_minimized(&self) -> bool

Checks to see if the window is minimized

§Panics

When called outside of the functions in the Game trait

Source

pub fn is_window_fullscreen(&self) -> bool

Checks to see if the window is fullscreen not maximized

§Panics

When called outside of the functions in the Game trait

Source

pub fn maximize_window(&self)

Will maximize the window

§Panics

When called outside of the functions in the Game trait

Source

pub fn minimize_window(&self)

Will minimize the window

§Panics

When called outside of the functions in the Game trait

Source

pub fn close(&mut self)

Will close the window and stop the program

Source

pub fn set_window_icon(&self, path: &str) -> Result<(), IconError>

Will attempt to set the window icon for more details check the winit docs

§Panics

When called outside of the functions in the Game trait

Source

pub fn set_window_title(&self, title: &str)

Sets the window title

§Panics

When called outside of the functions in the Game trait

Source

pub fn set_window_position(&self, x: f32, y: f32)

Changes the Position of the window in Physical Pixles

§Panics

When called outside of the functions in the Game trait

Source

pub fn set_window_min_size(&self, width: f32, height: f32)

Sets the physical minimum size of the window

§Panics

When called outside of the functions in the Game trait

Source

pub fn get_window_position(&self) -> Option<Vec2<i32>>

Gets the physical postion of the window

§Panics

When called outside of the functions in the Game trait

Source

pub fn get_window_size(&self) -> Vec2<u32>

Gets the phyisical size of the window,

Examples found in repository?
examples/shader.rs (line 113)
108    fn update(&mut self, engine_handle: &mut Engine) {
109        let dt = engine_handle.get_frame_delta_time();
110
111        self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113        let size = engine_handle.get_window_size();
114        let mouse_pos = engine_handle.get_mouse_position();
115
116        let new_data = MousePos {
117            x: mouse_pos.x / size.x as f32,
118            y: mouse_pos.y / size.y as f32,
119            _junk: 0.0,
120            _padding2: 0.0,
121        };
122
123        self.data = new_data;
124        self.mouse_material
125            .update_uniform_data(&self.data, &engine_handle)
126            .unwrap();
127        self.circle_material
128            .update_uniform_data(&self.theta, &engine_handle)
129            .unwrap();
130    }
More examples
Hide additional examples
examples/lightmap.rs (line 22)
15fn main() {
16    let mut engine = EngineBuilder::new()
17        .set_window_title("Lightmap")
18        .with_resolution((800, 800))
19        .build()
20        .unwrap();
21
22    let uniform_texture = UniformTexture::new(&engine, engine.get_window_size());
23
24    let light = Light {
25        colour: Colour::ORANGE,
26        pos_x: 0.0,
27        pos_y: 0.0,
28        brightness: 0.75,
29        aspect_ratio: 1.0,
30    };
31
32    let light_data = UniformData::new(&light);
33
34    let shader_options = ShaderOptions::with_all(&light_data, &uniform_texture);
35    let light_shader = Shader::new(
36        "examples/light.wgsl",
37        shader_options,
38        &mut engine,
39        LoadingOp::Blocking,
40    );
41
42    let material = MaterialBuilder::new()
43        .set_shader(light_shader)
44        .build(&mut engine);
45
46    let ocluder_material = MaterialBuilder::new().build(&mut engine);
47
48    let rectangles = vec![
49        Rectangle::new(Vec2 { x: 120.0, y: 20.0 }, Vec2 { x: 50.0, y: 50.0 }),
50        Rectangle::new(Vec2 { x: 270.0, y: 70.0 }, Vec2 { x: 50.0, y: 50.0 }),
51        Rectangle::new(Vec2 { x: 130.0, y: 280.0 }, Vec2 { x: 50.0, y: 50.0 }),
52        Rectangle::new(Vec2 { x: 220.0, y: 300.0 }, Vec2 { x: 50.0, y: 50.0 }),
53        Rectangle::new(Vec2 { x: 350.0, y: 350.0 }, Vec2 { x: 100.0, y: 100.0 }),
54    ];
55
56    let s = TextureExample {
57        material,
58        ocluder_material,
59        light,
60        uniform_texture,
61        rectangles,
62        mouse_pos: ZEROS,
63    };
64
65    engine.run(s);
66}
67
68struct TextureExample {
69    material: Material<Light>,
70    ocluder_material: Material,
71    light: Light,
72    uniform_texture: UniformTexture,
73    rectangles: Vec<Rectangle>,
74    mouse_pos: Vec2<f32>,
75}
76
77const ZEROS: Vec2<f32> = Vec2 { x: 0.0, y: 0.0 };
78
79impl Game for TextureExample {
80    fn render<'o>(&'o mut self, mut render_handle: RenderHandle<'o>) {
81        self.create_shadow_map(&mut render_handle);
82
83        let mut p2 = render_handle.begin_pass(Colour::BLACK);
84        let size = p2.get_size();
85        let size = Vec2 {
86            x: size.x as f32,
87            y: size.y as f32,
88        };
89
90        self.material
91            .add_rectangle(Vec2 { x: 0.0, y: 0.0 }, size, Colour::WHITE, &p2);
92        self.material.draw(&mut p2);
93    }
94
95    fn update(&mut self, engine_handle: &mut Engine) {
96        let mouse_pos = engine_handle.get_mouse_position();
97        self.mouse_pos = mouse_pos;
98        let window_size = engine_handle.get_window_size();
99
100        self.light.pos_x = mouse_pos.x / window_size.x as f32;
101        self.light.pos_y = mouse_pos.y / window_size.y as f32;
102        self.material
103            .update_uniform_data(&self.light, &engine_handle)
104            .unwrap();
105
106        self.material
107            .update_uniform_texture(&mut self.uniform_texture, engine_handle)
108            .unwrap_or_else(|_| {});
109    }
examples/camera.rs (line 69)
66    fn update(&mut self, engine_handle: &mut Engine) {
67        let dt = engine_handle.get_frame_delta_time();
68        let mouse_pos = engine_handle.get_mouse_position();
69        let size = engine_handle.get_window_size();
70
71        let move_factor = 15.0;
72
73        if engine_handle.is_key_down(Key::A) {
74            self.camera.center.x -= move_factor * dt;
75        }
76
77        if engine_handle.is_key_down(Key::D) {
78            self.camera.center.x += move_factor * dt;
79        }
80
81        if engine_handle.is_key_down(Key::W) {
82            self.camera.center.y += move_factor * dt;
83        }
84
85        if engine_handle.is_key_down(Key::S) {
86            self.camera.center.y -= move_factor * dt;
87        }
88
89        if engine_handle.is_key_down(Key::Left) {
90            self.camera.rotation += move_factor * dt;
91        }
92
93        if engine_handle.is_key_down(Key::Right) {
94            self.camera.rotation -= move_factor * dt;
95        }
96
97        if engine_handle.is_key_down(Key::L) {
98            self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99        }
100
101        if engine_handle.is_key_down(Key::K) {
102            self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103        }
104
105        if engine_handle.is_key_pressed(Key::Enter) {
106            self.camera.rotation += 45.0;
107        }
108
109        let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111        self.text.set_text(
112            &format!(
113                "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114                mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115            ),
116            Colour::WHITE,
117            engine_handle,
118        );
119
120        self.text.prepare(engine_handle);
121    }
Source

pub fn get_window_scale_factor(&self) -> f64

Gets the scale factor to help handle diffrence between phyiscial and logical pixels

§Panics

When called outside of the functions in the Game trait

Source

pub fn toggle_fullscreen(&self)

Toggels fullscreen mode may fail on certain Operating Systems check the winit docs for more information

§Panics

When called outside of the functions in the Game trait

Source

pub fn hide_cursor(&mut self)

Hides the cursor

§Panics

When called outside of the functions in the Game trait

Source

pub fn show_cursor(&mut self)

Shows the cursor if its hidden

§Panics

When called outside of the functions in the Game trait

Source

pub fn get_frame_delta_time(&self) -> f32

Gets the time since the previous frame or change in time between now and last frame

Examples found in repository?
examples/texture.rs (line 55)
54    fn update(&mut self, engine_handle: &mut Engine) {
55        let dt = engine_handle.get_frame_delta_time();
56        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
57            std::mem::swap(&mut self.other, &mut self.current);
58        }
59        self.pos.x += 100.0 * dt;
60    }
More examples
Hide additional examples
examples/ngon.rs (line 80)
79    fn update(&mut self, engine_handle: &mut Engine) {
80        let dt = engine_handle.get_frame_delta_time();
81        self.time.time = (self.time.time + dt) % (32.0 * PI);
82        self.regular_material
83            .update_uniform_data(&self.time, &engine_handle)
84            .unwrap();
85    }
examples/rectangles.rs (line 111)
110    fn update(&mut self, engine_handle: &mut Engine) {
111        let dt = engine_handle.get_frame_delta_time();
112        self.pos.x += 100.0 * dt;
113        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114            let new_texture = Texture::new(
115                engine_handle,
116                "examples/eggshark.png",
117                LoadingOp::Background,
118            );
119            self.texture_material.change_texture(new_texture);
120        }
121
122        self.state = engine_handle.is_key_down(Key::Space);
123    }
examples/text.rs (line 49)
48    fn update(&mut self, engine_handle: &mut Engine) {
49        self.font_size += 2.0 * engine_handle.get_frame_delta_time();
50
51        self.text_mat.set_font_size(self.font_size, engine_handle);
52        self.text_mat
53            .set_line_height(self.font_size * 1.3, engine_handle);
54
55        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
56            self.text_mat.set_text_with_font(
57                "hello I am talking to you here???",
58                Colour::GREEN,
59                &self.comic,
60                engine_handle,
61            );
62        }
63
64        self.text_mat.prepare(engine_handle);
65    }
examples/shader.rs (line 109)
108    fn update(&mut self, engine_handle: &mut Engine) {
109        let dt = engine_handle.get_frame_delta_time();
110
111        self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113        let size = engine_handle.get_window_size();
114        let mouse_pos = engine_handle.get_mouse_position();
115
116        let new_data = MousePos {
117            x: mouse_pos.x / size.x as f32,
118            y: mouse_pos.y / size.y as f32,
119            _junk: 0.0,
120            _padding2: 0.0,
121        };
122
123        self.data = new_data;
124        self.mouse_material
125            .update_uniform_data(&self.data, &engine_handle)
126            .unwrap();
127        self.circle_material
128            .update_uniform_data(&self.theta, &engine_handle)
129            .unwrap();
130    }
examples/camera.rs (line 67)
66    fn update(&mut self, engine_handle: &mut Engine) {
67        let dt = engine_handle.get_frame_delta_time();
68        let mouse_pos = engine_handle.get_mouse_position();
69        let size = engine_handle.get_window_size();
70
71        let move_factor = 15.0;
72
73        if engine_handle.is_key_down(Key::A) {
74            self.camera.center.x -= move_factor * dt;
75        }
76
77        if engine_handle.is_key_down(Key::D) {
78            self.camera.center.x += move_factor * dt;
79        }
80
81        if engine_handle.is_key_down(Key::W) {
82            self.camera.center.y += move_factor * dt;
83        }
84
85        if engine_handle.is_key_down(Key::S) {
86            self.camera.center.y -= move_factor * dt;
87        }
88
89        if engine_handle.is_key_down(Key::Left) {
90            self.camera.rotation += move_factor * dt;
91        }
92
93        if engine_handle.is_key_down(Key::Right) {
94            self.camera.rotation -= move_factor * dt;
95        }
96
97        if engine_handle.is_key_down(Key::L) {
98            self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99        }
100
101        if engine_handle.is_key_down(Key::K) {
102            self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103        }
104
105        if engine_handle.is_key_pressed(Key::Enter) {
106            self.camera.rotation += 45.0;
107        }
108
109        let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111        self.text.set_text(
112            &format!(
113                "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114                mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115            ),
116            Colour::WHITE,
117            engine_handle,
118        );
119
120        self.text.prepare(engine_handle);
121    }
Source

pub fn get_stable_fps(&self) -> f32

Returns a moving average of the last two frame times

Source

pub fn get_target_fps(&self) -> Option<u16>

Gets the current target fps

Source

pub fn remove_target_fps(&mut self)

Will uncap the framerate and cause the engine to redner and update as soon as the next frame is ready unless VSYNC is on then it will draw at the VYSNC rate, which is dependant on user hardware.

Source

pub fn remove_vsync(&mut self)

Will turn off vysnc if the platform suports it, using AutoNoVsync for more information check PresentMode::AutoNoVsync.

§Panics

When called outside of the functions in the Game trait

Source

pub fn add_vsync(&mut self)

Will turn off vysnc if the platform suports it, using AutoVsync for more information check PresentMode::AutoVsync.

§Panics

When called outside of the functions in the Game trait

Source

pub fn set_target_fps(&mut self, fps: u16)

Sets a target fps cap. The thread will spin sleep using the spin_sleep crate untill the desired frame time is reached. If the frames are slower than the target no action is taken to “speed” up the rendering and updating

Source

pub fn measure_string( &mut self, text: &str, font_size: f32, line_height: f32, ) -> Vec2<f32>

Measures string based on the default font. To measure a string with a custom font use TextMaterial::get_measurements()

§Panics

When called outside of the functions in the Game trait

Source

pub fn create_resource<P: AsRef<Path>>( &mut self, path: P, loading_op: LoadingOp, ) -> ResourceId<Vec<u8>>

Loads in a byte vector resource, can be used to load arbitary files.

Source

pub fn get_loading_resource_count(&self) -> usize

This returns the current number of resources that are loading

Source

pub fn get_byte_resource(&self, id: ResourceId<Vec<u8>>) -> Option<&Vec<u8>>

Attemps to fetch a byte resource.

Returns None if the resource isnt loaded yet.

Source

pub fn run<T>(self, game: T)
where T: Game + 'static,

Takes the struct that implements the Game trait and starts the winit event loop running the game

Examples found in repository?
examples/line.rs (line 18)
9fn main() {
10    let engine = EngineBuilder::new().build().unwrap();
11
12    let line_material = LineMaterial::new(&engine);
13
14    let game = LineExample {
15        material: line_material,
16    };
17
18    engine.run(game);
19}
More examples
Hide additional examples
examples/debug_triangle.rs (line 19)
9fn main() {
10    let mut engine = EngineBuilder::new()
11        .with_resolution((400, 400))
12        .build()
13        .unwrap();
14
15    let material = MaterialBuilder::new().build(&mut engine);
16
17    let pos = DebugTriangle { material };
18
19    engine.run(pos);
20}
examples/input.rs (line 19)
9fn main() {
10    let engine = EngineBuilder::new().build().unwrap();
11
12    let text_mat = TextMaterial::new("this is a test", Colour::RED, 20.0, 20.0 * 1.3);
13
14    let text_example = TextExample {
15        text_mat,
16        text: String::new(),
17    };
18
19    engine.run(text_example);
20}
examples/text.rs (line 23)
11fn main() {
12    let mut engine = EngineBuilder::new().build().unwrap();
13
14    let comic = Font::new("examples/Comic.ttf", &mut engine, LoadingOp::Blocking);
15    let text_mat = TextMaterial::new("this is a test", Colour::RED, 0.5, 0.5 * 1.3);
16
17    let text_example = TextExample {
18        text_mat,
19        comic,
20        font_size: 0.5,
21    };
22
23    engine.run(text_example);
24}
examples/rectangles.rs (line 29)
12fn main() {
13    let mut engine = EngineBuilder::new().build().unwrap();
14
15    let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
16
17    let texture_material = MaterialBuilder::new()
18        .add_texture(texture)
19        .build(&mut engine);
20    let regular_material = MaterialBuilder::new().build(&mut engine);
21
22    let pos = Position {
23        pos: vec2! { 0.0 },
24        regular_material,
25        texture_material,
26        state: false,
27    };
28
29    engine.run(pos);
30}
examples/camera.rs (line 37)
13fn main() {
14    let mut engine = EngineBuilder::new().build().unwrap();
15
16    let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
17
18    let material = MaterialBuilder::new()
19        .add_texture(texture)
20        .build(&mut engine);
21
22    let camera = Camera::default();
23
24    let text = TextMaterial::new(
25        "Mouse pos: 0,0 \n Mouse pos: 0, 0",
26        Colour::WHITE,
27        15.0,
28        20.0,
29    );
30
31    let game = CameraExample {
32        material,
33        text,
34        camera,
35    };
36
37    engine.run(game);
38}

Trait Implementations§

Source§

impl<'a> From<&'a mut Engine> for RenderHandle<'a>

Source§

fn from(value: &'a mut Engine) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more