From 8061ce0ea43126a22af0c34ed8de3f7276c6cc1f Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Tue, 19 Nov 2019 19:37:36 -0800 Subject: [PATCH] Reorganize dependencies (#46) * Reorganize dependencies * Enable logging in the minimal-winit example * Fix a very minor bug in the minimal-winit example --- Cargo.toml | 44 +++++++++++++++++++++++++------- examples/conway/README.md | 2 +- examples/invaders/README.md | 2 +- examples/minimal-winit/README.md | 2 +- examples/minimal-winit/main.rs | 5 ++-- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c28ba6a..c08ca85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,18 +25,44 @@ maintenance = { status = "actively-developed" } [dependencies] wgpu = "0.4" +# These are only used by the examples, and enabled with features +# See: https://github.com/rust-lang/cargo/issues/1982 +byteorder = { version = "1.3", optional = true } +env_logger = { version = "0.7", optional = true } +getrandom = { version = "0.1", optional = true } +gilrs = { version = "0.7", optional = true } +line_drawing = { version = "0.8", optional = true } +log = { version = "0.4", features = ["release_max_level_warn"], optional = true } +randomize = { version = "3.0", optional = true } +simple-invaders = { path = "simple-invaders", optional = true } +winit = { version = "0.20.0-alpha4", optional = true } +winit_input_helper = { version = "0.4.0-alpha4", optional = true } + [dev-dependencies] -byteorder = "1.3" -env_logger = "0.7" -getrandom = "0.1" -gilrs = "0.7" -line_drawing = "0.8" -log = { version = "0.4", features = ["release_max_level_warn"] } pixels-mocks = { path = "pixels-mocks" } -randomize = "3.0" -simple-invaders = { path = "simple-invaders" } winit = "0.20.0-alpha4" -winit_input_helper = "0.4.0-alpha4" + +[[example]] +name = "conway" +required-features = ["conway"] + +[[example]] +name = "invaders" +required-features = ["invaders"] + +[[example]] +name = "minimal-winit" +required-features = ["minimal-winit"] + +[features] +default = [] +log-deps = ["env_logger", "log"] +random-deps = ["byteorder", "getrandom", "randomize"] +winit-deps = ["winit", "winit_input_helper"] + +conway = ["line_drawing", "log-deps", "random-deps", "winit-deps"] +invaders = ["gilrs", "log-deps", "random-deps", "simple-invaders", "winit-deps"] +minimal-winit = ["log-deps", "winit-deps"] [workspace] members = [ diff --git a/examples/conway/README.md b/examples/conway/README.md index a931f11..779e28f 100644 --- a/examples/conway/README.md +++ b/examples/conway/README.md @@ -5,7 +5,7 @@ ## Running ```bash -cargo run --release --example conway +cargo run --release --example conway --features conway ``` ## Controls diff --git a/examples/invaders/README.md b/examples/invaders/README.md index cfc0fe7..3b251ed 100644 --- a/examples/invaders/README.md +++ b/examples/invaders/README.md @@ -7,7 +7,7 @@ The pixels have invaded! ## Running ```bash -cargo run --release --example invaders +cargo run --release --example invaders --features invaders ``` ## Controls diff --git a/examples/minimal-winit/README.md b/examples/minimal-winit/README.md index 87a0579..003cab3 100644 --- a/examples/minimal-winit/README.md +++ b/examples/minimal-winit/README.md @@ -7,7 +7,7 @@ Minimal example with `winit`. ## Running ```bash -cargo run --release --example minimal-winit +cargo run --release --example minimal-winit --features minimal-winit ``` ## About diff --git a/examples/minimal-winit/main.rs b/examples/minimal-winit/main.rs index 657734a..7ca9c5e 100644 --- a/examples/minimal-winit/main.rs +++ b/examples/minimal-winit/main.rs @@ -21,6 +21,7 @@ struct World { } fn main() -> Result<(), Error> { + env_logger::init(); let event_loop = EventLoop::new(); let mut input = WinitInputHelper::new(); let window = { @@ -94,10 +95,10 @@ impl World { /// Update the `World` internal state; bounce the box around the screen. fn update(&mut self) { - if self.box_x < 0 || self.box_x + BOX_SIZE >= WIDTH as i16 { + if self.box_x <= 0 || self.box_x + BOX_SIZE - 1 >= WIDTH as i16 { self.velocity_x *= -1; } - if self.box_y < 0 || self.box_y + BOX_SIZE >= HEIGHT as i16 { + if self.box_y <= 0 || self.box_y + BOX_SIZE - 1 >= HEIGHT as i16 { self.velocity_y *= -1; }