Remove get_ and set_ prefixes from public APIs (#341)
This renames: - `get_frame` to `frame` - `get_frame_mut` to `frame_mut` - `set_clear_color` to `clear_color` Which more closely follows convention set by the standard library et al.
This commit is contained in:
parent
bbfd49deba
commit
899e27bafa
485
Cargo.lock
generated
485
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -44,7 +44,7 @@ fn main() -> Result<(), Error> {
|
|||
event_loop.run(move |event, _, control_flow| {
|
||||
// The one and only event that winit_input_helper doesn't have for us...
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
life.draw(pixels.get_frame_mut());
|
||||
life.draw(pixels.frame_mut());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {}", err);
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
|
|
@ -50,10 +50,10 @@ fn main() -> Result<(), Error> {
|
|||
event_loop.run(move |event, _, control_flow| {
|
||||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
|
||||
let render_result = pixels.render_with(|encoder, render_target, context| {
|
||||
let noise_texture = noise_renderer.get_texture_view();
|
||||
let noise_texture = noise_renderer.texture_view();
|
||||
context.scaling_renderer.render(encoder, noise_texture);
|
||||
|
||||
noise_renderer.update(&context.queue, time);
|
||||
|
|
|
@ -158,7 +158,7 @@ impl NoiseRenderer {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_texture_view(&self) -> &wgpu::TextureView {
|
||||
pub(crate) fn texture_view(&self) -> &wgpu::TextureView {
|
||||
&self.texture_view
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ fn main() -> Result<(), Error> {
|
|||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
// Draw the world
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
|
||||
// Prepare Dear ImGui
|
||||
gui.prepare(&window).expect("gui.prepare() failed");
|
||||
|
|
|
@ -12,7 +12,7 @@ default = ["optimize"]
|
|||
[dependencies]
|
||||
byteorder = "1"
|
||||
env_logger = "0.10"
|
||||
game-loop = { version = "0.10", features = ["winit"] }
|
||||
game-loop = { version = "=0.10.1", features = ["winit"] }
|
||||
getrandom = "0.2"
|
||||
gilrs = "0.10"
|
||||
log = "0.4"
|
||||
|
|
|
@ -8,18 +8,13 @@ pub struct Controls {
|
|||
}
|
||||
|
||||
/// The player can only move left or right, but can also be stationary.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub enum Direction {
|
||||
/// Do not move the player.
|
||||
#[default]
|
||||
Still,
|
||||
/// Move to the left.
|
||||
Left,
|
||||
/// Move to the right.
|
||||
Right,
|
||||
}
|
||||
|
||||
impl Default for Direction {
|
||||
fn default() -> Direction {
|
||||
Direction::Still
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ fn main() -> Result<(), Error> {
|
|||
},
|
||||
move |g| {
|
||||
// Drawing
|
||||
g.game.world.draw(g.game.pixels.get_frame_mut());
|
||||
g.game.world.draw(g.game.pixels.frame_mut());
|
||||
if let Err(err) = g.game.pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
g.exit();
|
||||
|
|
|
@ -92,7 +92,7 @@ fn main() -> Result<(), Error> {
|
|||
// Draw the current frame
|
||||
Event::RedrawRequested(_) => {
|
||||
// Draw the world
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
|
||||
// Prepare egui
|
||||
framework.prepare(&window);
|
||||
|
|
|
@ -65,7 +65,7 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
|
||||
// Draw the current frame
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
app.quit();
|
||||
|
|
|
@ -84,7 +84,7 @@ fn main() -> Result<(), Error> {
|
|||
|
||||
// Draw the current frame
|
||||
Event::RedrawRequested(_) => {
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
|
|
@ -110,7 +110,7 @@ async fn run() {
|
|||
event_loop.run(move |event, _, control_flow| {
|
||||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
|
|
@ -45,7 +45,7 @@ fn main() -> Result<(), Error> {
|
|||
event_loop.run(move |event, _, control_flow| {
|
||||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
world.draw(pixels.get_frame_mut());
|
||||
world.draw(pixels.frame_mut());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
|
|
@ -46,9 +46,9 @@ fn main() -> Result<(), Error> {
|
|||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
for (dst, &src) in pixels
|
||||
.get_frame_mut()
|
||||
.frame_mut()
|
||||
.chunks_exact_mut(4)
|
||||
.zip(shapes.get_frame().iter())
|
||||
.zip(shapes.frame().iter())
|
||||
{
|
||||
dst[0] = (src >> 16) as u8;
|
||||
dst[1] = (src >> 8) as u8;
|
||||
|
|
|
@ -36,7 +36,7 @@ impl Shapes {
|
|||
}
|
||||
|
||||
/// Gain access to the underlying pixels
|
||||
pub fn get_frame(&self) -> &[u32] {
|
||||
pub fn frame(&self) -> &[u32] {
|
||||
self.dt.get_data()
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ fn main() -> Result<(), Error> {
|
|||
event_loop.run(move |event, _, control_flow| {
|
||||
// Draw the current frame
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
pixels.get_frame_mut().copy_from_slice(drawing.data());
|
||||
pixels.frame_mut().copy_from_slice(drawing.data());
|
||||
if let Err(err) = pixels.render() {
|
||||
error!("pixels.render() failed: {err}");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
|
|
@ -154,7 +154,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
/// from popular image editing tools or web apps.
|
||||
///
|
||||
/// This is the pixel format of the texture that most applications will interact with directly.
|
||||
/// The format influences the structure of byte data that is returned by [`Pixels::get_frame`].
|
||||
/// The format influences the structure of byte data that is returned by [`Pixels::frame`].
|
||||
pub fn texture_format(mut self, texture_format: wgpu::TextureFormat) -> Self {
|
||||
self.texture_format = texture_format;
|
||||
self
|
||||
|
@ -339,7 +339,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
texture,
|
||||
texture_extent,
|
||||
texture_format: self.texture_format,
|
||||
texture_format_size: get_texture_format_size(self.texture_format),
|
||||
texture_format_size: texture_format_size(self.texture_format),
|
||||
scaling_renderer,
|
||||
};
|
||||
|
||||
|
@ -479,7 +479,7 @@ pub(crate) fn create_backing_texture(
|
|||
blend_state,
|
||||
);
|
||||
|
||||
let texture_format_size = get_texture_format_size(backing_texture_format);
|
||||
let texture_format_size = texture_format_size(backing_texture_format);
|
||||
let pixels_buffer_size = ((width * height) as f32 * texture_format_size) as usize;
|
||||
|
||||
Ok((
|
||||
|
@ -493,7 +493,7 @@ pub(crate) fn create_backing_texture(
|
|||
|
||||
#[rustfmt::skip]
|
||||
#[inline]
|
||||
const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
||||
const fn texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
||||
use wgpu::{AstcBlock::*, TextureFormat::*};
|
||||
|
||||
// TODO: Use constant arithmetic when supported.
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -269,10 +269,10 @@ impl Pixels {
|
|||
/// let mut pixels = Pixels::new(320, 240, surface_texture)?;
|
||||
///
|
||||
/// // Set clear color to red.
|
||||
/// pixels.set_clear_color(Color::RED);
|
||||
/// pixels.clear_color(Color::RED);
|
||||
/// # Ok::<(), pixels::Error>(())
|
||||
/// ```
|
||||
pub fn set_clear_color(&mut self, color: wgpu::Color) {
|
||||
pub fn clear_color(&mut self, color: wgpu::Color) {
|
||||
self.context.scaling_renderer.clear_color = color;
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ impl Pixels {
|
|||
/// let mut pixels = Pixels::new(320, 240, surface_texture)?;
|
||||
///
|
||||
/// // Clear the pixel buffer
|
||||
/// let frame = pixels.get_frame_mut();
|
||||
/// let frame = pixels.frame_mut();
|
||||
/// for pixel in frame.chunks_exact_mut(4) {
|
||||
/// pixel[0] = 0x00; // R
|
||||
/// pixel[1] = 0x00; // G
|
||||
|
@ -443,7 +443,7 @@ impl Pixels {
|
|||
/// let mut pixels = Pixels::new(320, 240, surface_texture)?;
|
||||
///
|
||||
/// // Clear the pixel buffer
|
||||
/// let frame = pixels.get_frame_mut();
|
||||
/// let frame = pixels.frame_mut();
|
||||
/// for pixel in frame.chunks_exact_mut(4) {
|
||||
/// pixel[0] = 0x00; // R
|
||||
/// pixel[1] = 0x00; // G
|
||||
|
@ -538,7 +538,7 @@ impl Pixels {
|
|||
|
||||
/// Get a mutable byte slice for the pixel buffer. The buffer is _not_ cleared for you; it will
|
||||
/// retain the previous frame's contents until you clear it yourself.
|
||||
pub fn get_frame_mut(&mut self) -> &mut [u8] {
|
||||
pub fn frame_mut(&mut self) -> &mut [u8] {
|
||||
&mut self.pixels
|
||||
}
|
||||
|
||||
|
@ -546,7 +546,7 @@ impl Pixels {
|
|||
///
|
||||
/// This may be useful for operations that must sample the buffer, such as blending pixel
|
||||
/// colours directly into it.
|
||||
pub fn get_frame(&self) -> &[u8] {
|
||||
pub fn frame(&self) -> &[u8] {
|
||||
&self.pixels
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue