Skip to content

Commit

Permalink
Use clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Jun 13, 2023
1 parent 33c843a commit 945fdb8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "wgpu-game-of-life"
version = "0.1.0"
edition = "2021"
description = "Wgpu game of life"
license = "MIT"
repository = "https://github.com/fornwall/wgpu-game-of-life"
keywords = ["advent-of-code"]
categories = ["graphics"]

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ else
WASM_OPT += -O0
endif

CLIPPY_PARAMS = --all-targets -- \
-W clippy::cargo \
-W clippy::cast_lossless \
-W clippy::dbg_macro \
-W clippy::expect_used \
-W clippy::manual_filter_map \
-W clippy::if_not_else \
-W clippy::items_after_statements \
-W clippy::large_stack_arrays \
-W clippy::linkedlist \
-W clippy::match_same_arms \
-W clippy::option_if_let_else \
-W clippy::redundant_closure_for_method_calls \
-W clippy::needless_continue \
-W clippy::needless_pass_by_value \
-W clippy::semicolon_if_nothing_returned \
-W clippy::similar_names \
-W clippy::single_match_else \
-W clippy::trivially_copy_pass_by_ref \
-W clippy::unreadable-literal \
-W clippy::unseparated-literal-suffix \
-W clippy::unnested_or_patterns \
-A clippy::wildcard_dependencies

CARGO_COMMAND = cargo +nightly

check:
$(CARGO_COMMAND) fmt --all
$(CARGO_COMMAND) clippy --tests $(CLIPPY_PARAMS)

macos-app:
cargo install cargo-bundle
cargo bundle --release
Expand All @@ -30,3 +60,5 @@ wasm:
$(WASM_BINDGEN) --out-dir site/generated target/wasm32-unknown-unknown/$(WASM_DIR)/wgpu_game_of_life.wasm
$(WASM_OPT) -o site/generated/wgpu_game_of_life_bg.wasm site/generated/wgpu_game_of_life_bg.wasm
(sleep 1 && open http://localhost:8888) & cd site && python3 -m http.server 8888

.PHONY: check macos-app run-app wasm
28 changes: 14 additions & 14 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use winit::{
event::{ElementState, Event, KeyboardInput, StartCause, VirtualKeyCode, WindowEvent},
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::ControlFlow,
};

use crate::State;

pub fn handle_event_loop(event: Event<()>, state: &mut State, control_flow: &mut ControlFlow) {
pub fn handle_event_loop(event: &Event<()>, state: &mut State, control_flow: &mut ControlFlow) {
// *control_flow = ControlFlow::WaitUntil(Instant::now().add(Duration::from_millis(1000)));
match event {
Event::WindowEvent {
&Event::WindowEvent {
ref event,
window_id,
} if window_id == state.window.id() => {
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn handle_event_loop(event: Event<()>, state: &mut State, control_flow: &mut
}
}

Event::RedrawRequested(window_id) if window_id == state.window.id() => {
&Event::RedrawRequested(window_id) if window_id == state.window.id() => {
state.update();
match state.render() {
Ok(_) => {}
Expand All @@ -59,16 +59,16 @@ pub fn handle_event_loop(event: Event<()>, state: &mut State, control_flow: &mut
Err(e) => eprintln!("{:?}", e),
}
}
Event::NewEvents(StartCause::Init) => {
// From the winit README:
// "A lot of functionality expects the application to be ready before you start doing anything;
// this includes creating windows, fetching monitors, drawing, and so on, see issues #2238, #2051
// and #2087.
// If you encounter problems, you should try doing your initialization inside
// Event::NewEvents(StartCause::Init)."
//state .window .set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
//state.window.focus_window();
}
//Event::NewEvents(StartCause::Init) => {
// From the winit README:
// "A lot of functionality expects the application to be ready before you start doing anything;
// this includes creating windows, fetching monitors, drawing, and so on, see issues #2238, #2051
// and #2087.
// If you encounter problems, you should try doing your initialization inside
// Event::NewEvents(StartCause::Init)."
//state .window .set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
//state.window.focus_window();
//}
Event::MainEventsCleared => {
state.window.request_redraw();
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn run() {
let mut state = State::new(window).await;

event_loop.run(move |event, _, control_flow| {
event_loop::handle_event_loop(event, &mut state, control_flow)
event_loop::handle_event_loop(&event, &mut state, control_flow);
});
}

Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a> State<'a> {
.formats
.iter()
.copied()
.find(|f| f.is_srgb())
.find(wgpu::TextureFormat::is_srgb)
.unwrap_or(surface_caps.formats[0]);

let config = wgpu::SurfaceConfiguration {
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<'a> State<'a> {
let render_pipeline = render_pipeline_from_shader(
&device,
&render_pipeline_layout,
shader,
&shader,
&config,
cells_stride,
square_stride,
Expand Down Expand Up @@ -562,7 +562,7 @@ impl<'a> State<'a> {
fn render_pipeline_from_shader(
device: &wgpu::Device,
render_pipeline_layout: &wgpu::PipelineLayout,
shader: wgpu::ShaderModule,
shader: &wgpu::ShaderModule,
config: &wgpu::SurfaceConfiguration,
cells_stride: wgpu::VertexBufferLayout,
square_stride: wgpu::VertexBufferLayout,
Expand All @@ -571,12 +571,12 @@ fn render_pipeline_from_shader(
label: Some("render_pipeline"),
layout: Some(render_pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
module: shader,
entry_point: "vertex_main",
buffers: &[cells_stride, square_stride],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
module: shader,
entry_point: "fragment_main",
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
Expand Down

0 comments on commit 945fdb8

Please sign in to comment.