Struct bottomless_pit::engine_handle::Engine
source · pub struct Engine { /* private fields */ }Expand description
The thing that makes the computer go
Implementations§
source§impl Engine
impl Engine
sourcepub fn is_key_down(&self, key: Key) -> bool
pub fn is_key_down(&self, key: Key) -> bool
Checks if a key is down
sourcepub fn is_key_pressed(&self, key: Key) -> bool
pub fn is_key_pressed(&self, key: Key) -> bool
Only returns true on the frame where the key is first pressed down
sourcepub fn is_key_released(&self, key: Key) -> bool
pub fn is_key_released(&self, key: Key) -> bool
Only returns true on the frame where the key first returns back up
sourcepub fn is_mouse_key_down(&self, key: MouseKey) -> bool
pub fn is_mouse_key_down(&self, key: MouseKey) -> bool
Checks if a mouse key is down
sourcepub fn is_mouse_key_up(&self, key: MouseKey) -> bool
pub fn is_mouse_key_up(&self, key: MouseKey) -> bool
Checks if a mouse key is up
sourcepub fn is_mouse_key_pressed(&self, key: MouseKey) -> bool
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?
More examples
sourcepub fn is_mouse_key_released(&self, key: MouseKey) -> bool
pub fn is_mouse_key_released(&self, key: MouseKey) -> bool
Only returns true on the frame where the key first returns back up
sourcepub fn get_mouse_position(&self) -> Vec2<f32>
pub fn get_mouse_position(&self) -> Vec2<f32>
Gives the current position of the mouse in physical pixels
Examples found in repository?
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);
}sourcepub fn window_has_focus(&self) -> bool
pub fn window_has_focus(&self) -> bool
Checks if the window has focus
sourcepub fn is_window_maximized(&self) -> bool
pub fn is_window_maximized(&self) -> bool
Checks if the window is maximized not fullscreened
sourcepub fn is_window_minimized(&self) -> bool
pub fn is_window_minimized(&self) -> bool
Checks to see if the window is minimized
sourcepub fn is_window_fullscreen(&self) -> bool
pub fn is_window_fullscreen(&self) -> bool
Checks to see if the window is fullscreen not maximized
sourcepub fn maximize_window(&self)
pub fn maximize_window(&self)
Will maximize the window
sourcepub fn minimize_window(&self)
pub fn minimize_window(&self)
Will minimize the window
sourcepub fn set_window_icon(&self, path: &str) -> Result<(), IconError>
pub fn set_window_icon(&self, path: &str) -> Result<(), IconError>
Will attempt to set the window icon for more details check the winit docs
sourcepub fn set_window_title(&self, title: &str)
pub fn set_window_title(&self, title: &str)
Sets the window title
sourcepub fn set_window_position(&self, x: f32, y: f32)
pub fn set_window_position(&self, x: f32, y: f32)
Changes the Position of the window in PhysicalPixles
sourcepub fn set_window_min_size(&self, width: f32, height: f32)
pub fn set_window_min_size(&self, width: f32, height: f32)
Sets the physical minimum size of the window
sourcepub fn get_window_position(&self) -> Option<Vec2<i32>>
pub fn get_window_position(&self) -> Option<Vec2<i32>>
Gets the physical postion of the window
sourcepub fn get_window_size(&self) -> Vec2<u32>
pub fn get_window_size(&self) -> Vec2<u32>
Gets the phyisical size of the window,
Examples found in repository?
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);
}sourcepub fn get_window_scale_factor(&self) -> f64
pub fn get_window_scale_factor(&self) -> f64
Gets the scale factor to help handle diffrence between phyiscial and logical pixels
sourcepub fn toggle_fullscreen(&self)
pub fn toggle_fullscreen(&self)
Toggels fullscreen mode may fail on certain Operating Systems check the winit docs for more information
sourcepub fn hide_cursor(&mut self)
pub fn hide_cursor(&mut self)
Hides the cursor
sourcepub fn show_cursor(&mut self)
pub fn show_cursor(&mut self)
Shows the cursor if its hidden
sourcepub fn change_camera_matrix(&mut self, matrix: [f32; 16])
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
sourcepub fn camera_layout(&self) -> BindGroupLayout
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
sourcepub fn texture_layout(&self) -> BindGroupLayout
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
sourcepub fn uniform_layout(&self) -> BindGroupLayout
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
sourcepub fn get_frame_delta_time(&self) -> f32
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?
More examples
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);
}sourcepub fn get_target_fps(&self) -> Option<u16>
pub fn get_target_fps(&self) -> Option<u16>
Gets the current target fps
sourcepub fn remove_target_fps(&mut self)
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.
sourcepub fn remove_vsync(&mut self)
pub fn remove_vsync(&mut self)
Will turn off vysnc if the platform suports it, using AutoNoVsync for more information check PresentMode::AutoNoVsync.
sourcepub fn add_vsync(&mut self)
pub fn add_vsync(&mut self)
Will turn off vysnc if the platform suports it, using AutoVsync for more information check PresentMode::AutoVsync.
sourcepub fn set_target_fps(&mut self, fps: u16)
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
sourcepub fn measure_string(
&mut self,
text: &str,
font_size: f32,
line_height: f32
) -> Vec2<f32>
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()
sourcepub fn create_resource<P: AsRef<Path>>(
&mut self,
path: P
) -> ResourceId<Vec<u8>>
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
sourcepub fn get_byte_resource(&self, id: ResourceId<Vec<u8>>) -> Option<&Vec<u8>>
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.
sourcepub fn run<T>(self, game: T) -> !where
T: Game + 'static,
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?
More examples
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);
}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);
}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);
}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);
}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);
}