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:
Jay Oster 2023-03-09 19:42:57 -08:00 committed by GitHub
parent bbfd49deba
commit 899e27bafa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 270 additions and 276 deletions

485
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -44,7 +44,7 @@ fn main() -> Result<(), Error> {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// The one and only event that winit_input_helper doesn't have for us... // The one and only event that winit_input_helper doesn't have for us...
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
life.draw(pixels.get_frame_mut()); life.draw(pixels.frame_mut());
if let Err(err) = pixels.render() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {}", err); error!("pixels.render() failed: {}", err);
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;

View file

@ -50,10 +50,10 @@ fn main() -> Result<(), Error> {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { 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 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); context.scaling_renderer.render(encoder, noise_texture);
noise_renderer.update(&context.queue, time); noise_renderer.update(&context.queue, time);

View file

@ -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 &self.texture_view
} }

View file

@ -59,7 +59,7 @@ fn main() -> Result<(), Error> {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
// Draw the world // Draw the world
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
// Prepare Dear ImGui // Prepare Dear ImGui
gui.prepare(&window).expect("gui.prepare() failed"); gui.prepare(&window).expect("gui.prepare() failed");

View file

@ -12,7 +12,7 @@ default = ["optimize"]
[dependencies] [dependencies]
byteorder = "1" byteorder = "1"
env_logger = "0.10" env_logger = "0.10"
game-loop = { version = "0.10", features = ["winit"] } game-loop = { version = "=0.10.1", features = ["winit"] }
getrandom = "0.2" getrandom = "0.2"
gilrs = "0.10" gilrs = "0.10"
log = "0.4" log = "0.4"

View file

@ -8,18 +8,13 @@ pub struct Controls {
} }
/// The player can only move left or right, but can also be stationary. /// The player can only move left or right, but can also be stationary.
#[derive(Debug)] #[derive(Debug, Default)]
pub enum Direction { pub enum Direction {
/// Do not move the player. /// Do not move the player.
#[default]
Still, Still,
/// Move to the left. /// Move to the left.
Left, Left,
/// Move to the right. /// Move to the right.
Right, Right,
} }
impl Default for Direction {
fn default() -> Direction {
Direction::Still
}
}

View file

@ -139,7 +139,7 @@ fn main() -> Result<(), Error> {
}, },
move |g| { move |g| {
// Drawing // 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() { if let Err(err) = g.game.pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
g.exit(); g.exit();

View file

@ -92,7 +92,7 @@ fn main() -> Result<(), Error> {
// Draw the current frame // Draw the current frame
Event::RedrawRequested(_) => { Event::RedrawRequested(_) => {
// Draw the world // Draw the world
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
// Prepare egui // Prepare egui
framework.prepare(&window); framework.prepare(&window);

View file

@ -65,7 +65,7 @@ fn main() -> Result<(), Error> {
} }
// Draw the current frame // Draw the current frame
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
if let Err(err) = pixels.render() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
app.quit(); app.quit();

View file

@ -84,7 +84,7 @@ fn main() -> Result<(), Error> {
// Draw the current frame // Draw the current frame
Event::RedrawRequested(_) => { Event::RedrawRequested(_) => {
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
if let Err(err) = pixels.render() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;

View file

@ -110,7 +110,7 @@ async fn run() {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
if let Err(err) = pixels.render() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;

View file

@ -45,7 +45,7 @@ fn main() -> Result<(), Error> {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
world.draw(pixels.get_frame_mut()); world.draw(pixels.frame_mut());
if let Err(err) = pixels.render() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;

View file

@ -46,9 +46,9 @@ fn main() -> Result<(), Error> {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
for (dst, &src) in pixels for (dst, &src) in pixels
.get_frame_mut() .frame_mut()
.chunks_exact_mut(4) .chunks_exact_mut(4)
.zip(shapes.get_frame().iter()) .zip(shapes.frame().iter())
{ {
dst[0] = (src >> 16) as u8; dst[0] = (src >> 16) as u8;
dst[1] = (src >> 8) as u8; dst[1] = (src >> 8) as u8;

View file

@ -36,7 +36,7 @@ impl Shapes {
} }
/// Gain access to the underlying pixels /// Gain access to the underlying pixels
pub fn get_frame(&self) -> &[u32] { pub fn frame(&self) -> &[u32] {
self.dt.get_data() self.dt.get_data()
} }

View file

@ -43,7 +43,7 @@ fn main() -> Result<(), Error> {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// Draw the current frame // Draw the current frame
if let Event::RedrawRequested(_) = event { 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() { if let Err(err) = pixels.render() {
error!("pixels.render() failed: {err}"); error!("pixels.render() failed: {err}");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;

View file

@ -154,7 +154,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
/// from popular image editing tools or web apps. /// from popular image editing tools or web apps.
/// ///
/// This is the pixel format of the texture that most applications will interact with directly. /// 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 { pub fn texture_format(mut self, texture_format: wgpu::TextureFormat) -> Self {
self.texture_format = texture_format; self.texture_format = texture_format;
self self
@ -339,7 +339,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
texture, texture,
texture_extent, texture_extent,
texture_format: self.texture_format, 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, scaling_renderer,
}; };
@ -479,7 +479,7 @@ pub(crate) fn create_backing_texture(
blend_state, 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; let pixels_buffer_size = ((width * height) as f32 * texture_format_size) as usize;
Ok(( Ok((
@ -493,7 +493,7 @@ pub(crate) fn create_backing_texture(
#[rustfmt::skip] #[rustfmt::skip]
#[inline] #[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::*}; use wgpu::{AstcBlock::*, TextureFormat::*};
// TODO: Use constant arithmetic when supported. // TODO: Use constant arithmetic when supported.

View file

@ -269,10 +269,10 @@ impl Pixels {
/// let mut pixels = Pixels::new(320, 240, surface_texture)?; /// let mut pixels = Pixels::new(320, 240, surface_texture)?;
/// ///
/// // Set clear color to red. /// // Set clear color to red.
/// pixels.set_clear_color(Color::RED); /// pixels.clear_color(Color::RED);
/// # Ok::<(), pixels::Error>(()) /// # 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; self.context.scaling_renderer.clear_color = color;
} }
@ -398,7 +398,7 @@ impl Pixels {
/// let mut pixels = Pixels::new(320, 240, surface_texture)?; /// let mut pixels = Pixels::new(320, 240, surface_texture)?;
/// ///
/// // Clear the pixel buffer /// // Clear the pixel buffer
/// let frame = pixels.get_frame_mut(); /// let frame = pixels.frame_mut();
/// for pixel in frame.chunks_exact_mut(4) { /// for pixel in frame.chunks_exact_mut(4) {
/// pixel[0] = 0x00; // R /// pixel[0] = 0x00; // R
/// pixel[1] = 0x00; // G /// pixel[1] = 0x00; // G
@ -443,7 +443,7 @@ impl Pixels {
/// let mut pixels = Pixels::new(320, 240, surface_texture)?; /// let mut pixels = Pixels::new(320, 240, surface_texture)?;
/// ///
/// // Clear the pixel buffer /// // Clear the pixel buffer
/// let frame = pixels.get_frame_mut(); /// let frame = pixels.frame_mut();
/// for pixel in frame.chunks_exact_mut(4) { /// for pixel in frame.chunks_exact_mut(4) {
/// pixel[0] = 0x00; // R /// pixel[0] = 0x00; // R
/// pixel[1] = 0x00; // G /// 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 /// 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. /// 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 &mut self.pixels
} }
@ -546,7 +546,7 @@ impl Pixels {
/// ///
/// This may be useful for operations that must sample the buffer, such as blending pixel /// This may be useful for operations that must sample the buffer, such as blending pixel
/// colours directly into it. /// colours directly into it.
pub fn get_frame(&self) -> &[u8] { pub fn frame(&self) -> &[u8] {
&self.pixels &self.pixels
} }