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

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

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 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 57)
54
55
56
57
58
59
60
61
    fn update(&mut self, engine_handle: &mut engine_handle::Engine) {
        let dt = engine_handle.get_frame_delta_time();
        println!("{}", dt);
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            std::mem::swap(&mut self.other, &mut self.current);
        }
        self.pos.x += 100.0 * dt;
    }
More examples
Hide additional examples
examples/text.rs (line 49)
48
49
50
51
52
53
54
55
    fn update(&mut self, engine_handle: &mut Engine) {
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            self.text_mat
                .set_text_with_font("hel", Colour::GREEN, &self.comic, engine_handle);
            self.text_mat.set_font_size(40.0, engine_handle);
            self.text_mat.prepare(engine_handle);
        }
    }
examples/rectangles.rs (line 103)
100
101
102
103
104
105
106
107
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();
        self.pos.x += 100.0 * dt;
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            let new_texture = Texture::new(engine_handle, "examples/eggshark.png");
            self.texture_material.change_texture(new_texture);
        }
    }
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/shader.rs (line 111)
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();

        self.theta = (self.theta + dt) % (2.0 * PI);

        let size = engine_handle.get_window_size();
        let mouse_pos = engine_handle.get_mouse_position();

        let new_data = MousePos {
            x: mouse_pos.x / size.x as f32,
            y: mouse_pos.y / size.y as f32,
            _junk: 0.0,
            _padding2: 0.0,
        };

        self.data = new_data;
        self.mouse_material
            .update_uniform_data(&self.data, &engine_handle);
        self.circle_material
            .update_uniform_data(&self.theta, &engine_handle);
    }
source

pub fn window_has_focus(&self) -> bool

Checks if the window has focus

source

pub fn is_window_maximized(&self) -> bool

Checks if the window is maximized not fullscreened

source

pub fn is_window_minimized(&self) -> bool

Checks to see if the window is minimized

source

pub fn is_window_fullscreen(&self) -> bool

Checks to see if the window is fullscreen not maximized

source

pub fn maximize_window(&self)

Will maximize the window

source

pub fn minimize_window(&self)

Will minimize the window

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

source

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

Sets the window title

source

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

Changes the Position of the window in PhysicalPixles

source

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

Sets the physical minimum size of the window

source

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

Gets the physical postion of the window

source

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

Gets the phyisical size of the window,

Examples found in repository?
examples/shader.rs (line 110)
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();

        self.theta = (self.theta + dt) % (2.0 * PI);

        let size = engine_handle.get_window_size();
        let mouse_pos = engine_handle.get_mouse_position();

        let new_data = MousePos {
            x: mouse_pos.x / size.x as f32,
            y: mouse_pos.y / size.y as f32,
            _junk: 0.0,
            _padding2: 0.0,
        };

        self.data = new_data;
        self.mouse_material
            .update_uniform_data(&self.data, &engine_handle);
        self.circle_material
            .update_uniform_data(&self.theta, &engine_handle);
    }
source

pub fn get_window_scale_factor(&self) -> f64

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

source

pub fn toggle_fullscreen(&self)

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

source

pub fn hide_cursor(&mut self)

Hides the cursor

source

pub fn show_cursor(&mut self)

Shows the cursor if its hidden

source

pub fn change_camera_matrix(&mut self, matrix: [f32; 16])

Will update the camera matrix as of version 0.1.0 it will effect all things drawn is also 3D

source

pub fn camera_layout(&self) -> BindGroupLayout

nessicary for creating shaders and wanting to include the camera in the layouts this is required if you would like to use the camera in the shader

source

pub fn texture_layout(&self) -> BindGroupLayout

nessicary for creating shaders and wanting to include textures in the layouts this is required if you would like to use textures in your shader

source

pub fn uniform_layout(&self) -> BindGroupLayout

nessicary for creating shaders and wanting to use your own unifroms this should be pretty generic as it is exposed to both the vertex and fragment stage

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/ngon.rs (line 77)
76
77
78
79
80
81
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();
        self.time = (self.time + dt) % (32.0 * PI);
        self.regular_material
            .update_uniform_data(&self.time, &engine_handle);
    }
More examples
Hide additional examples
examples/texture.rs (line 55)
54
55
56
57
58
59
60
61
    fn update(&mut self, engine_handle: &mut engine_handle::Engine) {
        let dt = engine_handle.get_frame_delta_time();
        println!("{}", dt);
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            std::mem::swap(&mut self.other, &mut self.current);
        }
        self.pos.x += 100.0 * dt;
    }
examples/rectangles.rs (line 101)
100
101
102
103
104
105
106
107
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();
        self.pos.x += 100.0 * dt;
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            let new_texture = Texture::new(engine_handle, "examples/eggshark.png");
            self.texture_material.change_texture(new_texture);
        }
    }
examples/shader.rs (line 106)
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();

        self.theta = (self.theta + dt) % (2.0 * PI);

        let size = engine_handle.get_window_size();
        let mouse_pos = engine_handle.get_mouse_position();

        let new_data = MousePos {
            x: mouse_pos.x / size.x as f32,
            y: mouse_pos.y / size.y as f32,
            _junk: 0.0,
            _padding2: 0.0,
        };

        self.data = new_data;
        self.mouse_material
            .update_uniform_data(&self.data, &engine_handle);
        self.circle_material
            .update_uniform_data(&self.theta, &engine_handle);
    }
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.

source

pub fn add_vsync(&mut self)

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

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()

source

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

Loads in a byte vector resource, can be used to load arbitary files. This will halt the engine utill it is done loading. For more information on this behavoir see the resource module

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. Resources will always be available on the next frame after being requested. Please see the resource module for more information.

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 17)
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let engine = EngineBuilder::new().build().unwrap();

    let line_material = LineMaterial::new(&engine);

    let game = LineExample {
        material: line_material,
    };

    engine.run(game);
}
More examples
Hide additional examples
examples/debug_triangle.rs (line 19)
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut engine = EngineBuilder::new()
        .with_resolution((400, 400))
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let material = MaterialBuilder::new().build(&mut engine);

    let pos = DebugTriangle { material };

    engine.run(pos);
}
examples/text.rs (line 21)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let mut engine = EngineBuilder::new()
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let comic = Font::new("examples/Comic.ttf", &mut engine);
    let text_mat = TextMaterial::new("AA", Colour::RED, 100.0, 100.0, &mut engine);

    let text_example = TextExample { text_mat, comic };

    engine.run(text_example);
}
examples/rectangles.rs (line 29)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let mut engine = EngineBuilder::new()
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let texture = Texture::new(&mut engine, "examples/bplogo.png");

    let texture_material = MaterialBuilder::new()
        .add_texture(texture)
        .build(&mut engine);
    let regular_material = MaterialBuilder::new().build(&mut engine);

    let pos = Position {
        pos: Vec2 { x: 0.0, y: 0.0 },
        regular_material,
        texture_material,
    };

    engine.run(pos);
}
examples/texture.rs (line 29)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let mut engine = EngineBuilder::new()
        .set_window_title("Testing Triangle")
        .with_resolution((400, 400))
        .build()
        .unwrap();

    let texture = Texture::new(&mut engine, "examples/bplogo.png");

    let texture = MaterialBuilder::new()
        .add_texture(texture)
        .build(&mut engine);
    let defualt = MaterialBuilder::new().build(&mut engine);

    let s = TextureExample {
        current: texture,
        other: defualt,
        pos: Vec2 { x: 0.0, y: 0.0 },
    };

    engine.run(s);
}
examples/ngon.rs (line 42)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let mut engine = EngineBuilder::new()
        .with_resolution((500, 500))
        .remove_vsync()
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let data = Time {
        time: 0.0,
        _pading: 0.0,
        _padding2: 0.0,
        _padding4: 0.0,
    };

    let uniform_data = UniformData::new(&engine, &data);

    let mouse_shader = Shader::new("examples/sinewaves.wgsl", true, &mut engine);

    let regular_material = MaterialBuilder::new()
        .set_uniform(&uniform_data)
        .set_shader(mouse_shader)
        .build(&mut engine);

    let pos = Position {
        regular_material,
        time: 0.0,
    };

    engine.run(pos);
}

Auto Trait Implementations§

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
§

impl<T> Upcast<T> for T

§

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