From 351b149b279698f5f6c304b44df6f2c81a5a4385 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 4 Feb 2022 09:52:09 -0500 Subject: [PATCH] Move developer-type code options to 'debug' feature --- Cargo.toml | 7 +++++-- Makefile | 21 ++++++++++++------- src/map/camera.rs | 5 +++++ src/map_builders.rs | 5 +++-- src/map_builders/prefab_builder.rs | 3 ++- .../waveform_collapse/constraints.rs | 6 ++++-- src/map_builders/waveform_collapse/solver.rs | 4 +++- src/raws/rawmaster.rs | 6 ++++++ src/spawner.rs | 1 + src/state.rs | 4 ++++ 10 files changed, 46 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7040c0b..cb16349 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] +debug = [] default = ["rltk/opengl", "rltk/serde", "rltk/threaded"] curses = ["rltk/curses", "rltk/serde"] -js = ["getrandom/js", "rltk/opengl", "rltk/serde"] + +# WebAssembly Build +wasm = ["getrandom/js", "rltk/opengl", "rltk/serde"] [dependencies] -getrandom = { version = "0.2.4" } +getrandom = { version = "0.2.4", optional = true } lazy_static = "1.4.0" regex = "1.5.4" rltk = { version = "0.8.1", default-features = false } diff --git a/Makefile b/Makefile index d35417c..0c8cddb 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,15 @@ include help-system.mk +FEATURES?=default + run: $(call print-help, run, Runs the binary in develop mode) - cargo run + cargo run --features $(FEATURES) --no-default-features + +run-debug: $(call print-help, run-debug, Runs the binary with the 'debug' feature, which shows map generation, and other debug functionality) + cargo run --features debug run-pi: $(call print-help, run-pi, Sets appropriate flags so that the game runs on a Raspberry Pi) - MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run + MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run --features $(FEATURES) run-curses: $(call print-help, run-curses, Run the game in a console window via the curses library) cargo run --features curses --no-default-features @@ -13,11 +18,11 @@ build: cargo build build-wasm: $(call print-help, build-wasm, Build the webassembly version of the game) - cargo build --release --target wasm32-unknown-unknown --features js + cargo build --release --target wasm32-unknown-unknown --features wasm wasm-bindgen target/wasm32-unknown-unknown/release/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript build-wasm-dev: $(call print-help, build-wasm-dev, Build the webassembly version of the game (dev version)) - cargo build --target wasm32-unknown-unknown --features js + cargo build --target wasm32-unknown-unknown --features wasm wasm-bindgen target/wasm32-unknown-unknown/debug/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript clean: $(call print-help, clean, Removes save file and compilation artifacts) @@ -25,13 +30,13 @@ clean: $(call print-help, clean, Removes save file and compilation artifacts) cargo clean check: $(call print-help, check, Check code syntax) - cargo check + cargo check --features $(FEATURES) check-wasm: $(call print-help, check-wasm, Check code syntax for webassembly build) - cargo check --target wasm32-unknown-unknown --features js + cargo check --target wasm32-unknown-unknown --features wasm lint: $(call print-help, lint, Check code syntax and style) - cargo clippy + cargo clippy --features $(FEATURES) fmt: $(call print-help, fmt, Runs formatter on code) cargo +nightly fmt @@ -41,6 +46,6 @@ fix: $(call print-help, fix, Fixes some warnings, then runs the formatter) make fmt docs: $(call print-help, docs, Generates code docs) - cargo doc + cargo doc --features $(FEATURES) .phony: run-pi clean check run fmt fix lint docs build build-wasm check-wasm build-wasm-dev \ No newline at end of file diff --git a/src/map/camera.rs b/src/map/camera.rs index 36ed22a..d00cc70 100644 --- a/src/map/camera.rs +++ b/src/map/camera.rs @@ -7,6 +7,11 @@ use crate::map::tile_glyph; use crate::{colors, Map}; /// Whether to render an outline of the current map's boundaries +#[cfg(feature = "debug")] +const SHOW_BOUNDARIES: bool = true; + +/// Whether to render an outline of the current map's boundaries +#[cfg(not(feature = "debug"))] const SHOW_BOUNDARIES: bool = false; /// Get the rectangle representing the current viewport diff --git a/src/map_builders.rs b/src/map_builders.rs index 58dd921..1cf8c84 100644 --- a/src/map_builders.rs +++ b/src/map_builders.rs @@ -35,7 +35,6 @@ mod voronoi; mod voronoi_spawning; mod waveform_collapse; -use ::rltk::prelude::*; use ::specs::prelude::*; use area_ending_point::{AreaEndingPosition, XEnd, YEnd}; use area_starting_points::{AreaStartingPosition, XStart, YStart}; @@ -345,7 +344,9 @@ pub fn random_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain { } pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain { - console::log(format!("Depth: {}", new_depth)); + #[cfg(feature = "debug")] + ::rltk::console::log(format!("Depth: {}", new_depth)); + match new_depth { 1 => town_builder(new_depth, width, height), 2 => forest_builder(new_depth, width, height), diff --git a/src/map_builders/prefab_builder.rs b/src/map_builders/prefab_builder.rs index 4cec6f7..426d29e 100644 --- a/src/map_builders/prefab_builder.rs +++ b/src/map_builders/prefab_builder.rs @@ -136,7 +136,8 @@ impl PrefabBuilder { build_data.spawn_list.push((idx, "Watch Fire".to_string())); } _ => { - rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char)); + #[cfg(feature = "debug")] + ::rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char)); } } } diff --git a/src/map_builders/waveform_collapse/constraints.rs b/src/map_builders/waveform_collapse/constraints.rs index 566a41b..73c15d1 100644 --- a/src/map_builders/waveform_collapse/constraints.rs +++ b/src/map_builders/waveform_collapse/constraints.rs @@ -66,7 +66,8 @@ pub fn build_patterns( // Dedupe if dedupe { - rltk::console::log(format!( + #[cfg(feature = "debug")] + ::rltk::console::log(format!( "Pre de-duplication, there are {} patterns", patterns.len() )); @@ -75,7 +76,8 @@ pub fn build_patterns( let set: HashSet> = patterns.drain(..).collect(); patterns.extend(set.into_iter()); - rltk::console::log(format!("There are {} patterns", patterns.len())); + #[cfg(feature = "debug")] + ::rltk::console::log(format!("There are {} patterns", patterns.len())); } patterns diff --git a/src/map_builders/waveform_collapse/solver.rs b/src/map_builders/waveform_collapse/solver.rs index 4a673e0..4119706 100644 --- a/src/map_builders/waveform_collapse/solver.rs +++ b/src/map_builders/waveform_collapse/solver.rs @@ -194,7 +194,9 @@ impl Solver { } if possible_options.is_empty() { - rltk::console::log("Oh no! It's not possible!"); + #[cfg(feature = "debug")] + ::rltk::console::log("Oh no! It's not possible!"); + self.possible = false; return true; diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index b61e23d..45abd13 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -196,6 +196,7 @@ impl RawMaster { for (i, item) in self.raws.items.iter().enumerate() { if used_names.contains(&item.name) { + #[cfg(feature = "debug")] console::log(format!( "WARNING - duplicate item name in raws [{}]", item.name @@ -208,6 +209,7 @@ impl RawMaster { } for (i, mob) in self.raws.mobs.iter().enumerate() { if used_names.contains(&mob.name) { + #[cfg(feature = "debug")] console::log(format!( "WARNING - duplicate mob name in raws [{}]", mob.name @@ -218,6 +220,7 @@ impl RawMaster { } for (i, prop) in self.raws.props.iter().enumerate() { if used_names.contains(&prop.name) { + #[cfg(feature = "debug")] console::log(format!( "WARNING - duplicate prop name in raws [{}]", prop.name @@ -229,6 +232,7 @@ impl RawMaster { for spawn in self.raws.spawn_table.iter() { if !used_names.contains(&spawn.name) { + #[cfg(feature = "debug")] console::log(format!( "WARNING - Spawn tables references unspecified entity [{}]", spawn.name @@ -392,6 +396,7 @@ pub fn string_to_slot(slot: &str) -> EquipmentSlot { "Hands" => EquipmentSlot::Hands, "Melee" => EquipmentSlot::Melee, _ => { + #[cfg(feature = "debug")] console::log(format!("Warning: unknown equipment slot type [{}]", slot)); EquipmentSlot::Melee @@ -738,6 +743,7 @@ pub fn spawn_named_mob( skills.skills.insert(Skill::Magic, *sk.1); } _ => { + #[cfg(feature = "debug")] console::log(format!("Unknown skill referenced [{}]", sk.0)); } } diff --git a/src/spawner.rs b/src/spawner.rs index ad7f179..d2f697d 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -163,6 +163,7 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) { ); if item_result.is_none() { + #[cfg(feature = "debug")] console::log(format!("WARNING: We don't know how to spawn [{}]!", name)); } } diff --git a/src/state.rs b/src/state.rs index 5bc8396..f7cc980 100644 --- a/src/state.rs +++ b/src/state.rs @@ -11,8 +11,12 @@ use crate::systems::{self, particle_system}; use crate::{camera, colors, damage_system, gamelog, player, saveload_system, spawner}; /// Whether to show a visual representation of map generation +#[cfg(not(feature = "debug"))] pub const SHOW_MAPGEN_VISUALIZER: bool = false; +#[cfg(feature = "debug")] +pub const SHOW_MAPGEN_VISUALIZER: bool = true; + /// Whether to show an FPS counter pub const SHOW_FPS: bool = true;