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; }