This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Runeforge is a modern, modular, pure Rust roguelike library inspired by libtcod. It provides comprehensive tools for roguelike development including rendering (terminal, software, GPU), field-of-view, pathfinding, input handling, and procedural map generation.
Key Design Principles:
- Modular Architecture: Functionality split into focused crates
- Pure Rust: No C dependencies, easier builds and maintenance
- libtcod API Compatibility: Easy migration path for existing projects
- Multiple Rendering Backends: GPU (wgpu/pixels), Software (CPU), Terminal (ANSI)
- Cross-Platform: Windows, macOS, Linux, WebAssembly support
# Build entire workspace
cargo build --workspace --all-features
# Build specific crate
cargo build -p runeforge-fov
# Build with optimizations (dev profile has opt-level=1)
cargo build --release
# Build for WebAssembly
cargo build --target wasm32-unknown-unknown# Run all tests
cargo test --workspace --all-features
# Run tests for specific crate
cargo test -p runeforge-pathfinding
# Run specific test
cargo test -p runeforge-fov shadowcast
# Run tests with output
cargo test -- --nocapture# Run clippy (strict lints enforced)
cargo clippy --workspace --all-targets --all-features -- -D warnings
# Format all code
cargo fmt --all
# Check formatting without modifying
cargo fmt --all --check# Build documentation for entire workspace
cargo doc --workspace --all-features --no-deps
# Build and open documentation
cargo doc --workspace --all-features --no-deps --open
# Document private items (for development)
cargo doc --workspace --all-features --document-private-items# Run all benchmarks
cargo bench --workspace
# Run specific benchmark
cargo bench -p runeforge-fov
cargo bench -p runeforge-pathfinding
# Benchmark with criterion features
cargo bench --workspace -- --save-baseline main# Core examples
cargo run --example hello_terminal
cargo run --example roguelike_demo
cargo run --example fov_demo
cargo run --example pathfinding_demo
cargo run --example bsp_demo
cargo run --example map_generation_demo
# Windowed examples (GPU rendering)
cargo run --example windowed_roguelike
cargo run --example windowed_tileset_roguelike
# Demo game (comprehensive integration example)
cargo run -p demo-gameThe project uses a modular monorepo pattern with 13+ specialized crates:
runeforge-color: RGB/HSV color manipulation, blending, named constantsruneforge-geometry: 2D primitives (IVec2, Rect, shapes), grid utilitiesruneforge-random: RNG with dice notation (3d6+2), weighted selection
runeforge-direction: Cardinal/ordinal/vertical directions, iteration
runeforge-fov: Field-of-view algorithms (Symmetric Shadowcasting, Adams FOV)runeforge-pathfinding: A*, Dijkstra, BFS, DFS, iterative deepening variantsruneforge-algorithms: Map generation (BSP, Cellular Automata, Drunkard's Walk, Caves)runeforge-noise: Procedural noise generation (Perlin, Simplex)
runeforge-terminal: Console abstraction, multiple rendering backendsruneforge-tileset: TrueType font and bitmap tileset loadingruneforge-input: Keyboard/mouse input with action mapping
runeforge-rl(root): Re-exports all crates with feature flags
The root src/lib.rs re-exports all sub-crates:
// Core types always available
pub use runeforge_color as color;
pub use runeforge_geometry as geometry;
pub use runeforge_random as random;
// Optional feature-gated crates
#[cfg(feature = "fov")]
pub use runeforge_fov as fov;
#[cfg(feature = "terminal")]
pub use runeforge_terminal as terminal;Users can opt-in to only what they need:
runeforge-rl = { version = "0.1", features = ["fov", "pathfinding"] }
# or use "full" for everything
runeforge-rl = { version = "0.1", features = ["full"] }The rendering system uses traits to support multiple backends:
- Terminal Backend: ANSI escape codes for console rendering
- Pixel Backend: GPU-accelerated rendering via
pixelscrate - Software Backend: CPU-based framebuffer rendering
All backends implement common traits in runeforge-terminal.
Each crate exposes a prelude module for convenient imports:
use runeforge_rl::prelude::*;
// Now you have access to common types:
// Color, IVec2, Rect, Rng, etc.The library uses Rust's type system and generics to provide abstractions with no runtime overhead:
- Generic pathfinding over any grid type implementing
PathProvider - Generic FOV over any transparency map
- Inline functions and compile-time optimizations
runeforge-rl (facade)
├── runeforge-color (no deps)
├── runeforge-geometry
│ └── runeforge-direction
├── runeforge-random (rand)
├── runeforge-fov
│ ├── runeforge-geometry
│ └── runeforge-direction
├── runeforge-pathfinding
│ ├── runeforge-geometry
│ ├── runeforge-direction
├── runeforge-algorithms
│ ├── runeforge-geometry
│ └── runeforge-random
├── runeforge-terminal
│ ├── runeforge-color
│ ├── runeforge-geometry
│ └── runeforge-tileset
├── runeforge-tileset (ab_glyph, image)
├── runeforge-input (winit)
└── runeforge-noise (noise crate)The project enforces strict clippy lints:
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(clippy::dbg_macro, clippy::todo, clippy::unimplemented)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)] // wgpu/pixels transitive depsImportant: When adding code, ensure it passes cargo clippy -- -D warnings.
All public APIs require documentation with examples:
/// Calculates field-of-view using symmetric shadowcasting.
///
/// # Arguments
///
/// * `origin` - The center point of the FOV calculation
/// * `radius` - Maximum visibility radius
/// * `transparency` - Map defining which tiles block vision
///
/// # Examples
///
/// ```
/// use runeforge_fov::prelude::*;
/// let origin = IVec2::new(10, 10);
/// let visible = shadowcast(origin, 8, &map);
/// ```
pub fn shadowcast(/* ... */) { }Each crate follows this structure:
crates/runeforge-foo/
├── src/
│ ├── lib.rs # Public API, re-exports
│ ├── prelude.rs # Convenience module
│ ├── algorithm1.rs # Implementation modules
│ ├── algorithm2.rs
│ └── types.rs # Common types
├── benches/
│ └── foo_bench.rs # Criterion benchmarks
└── Cargo.tomlThe workspace defines optimized build profiles:
[profile.dev]
opt-level = 1 # Faster debug builds
debug = 1 # Reduced debug info
[profile.dev.package."*"]
opt-level = 3 # Optimize dependencies even in debug
[profile.release]
lto = "thin" # Link-time optimization
codegen-units = 1 # Better optimization
opt-level = 3
strip = true # Remove debug symbolsBenchmarks use criterion and are located in crates/*/benches/:
runeforge-fov/benches/fov_bench.rs: FOV algorithm performanceruneforge-pathfinding/benches/pathfinding_bench.rs: Pathfinding performance
Located in #[cfg(test)] mod tests within each module:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_shadowcast_basic() {
let origin = IVec2::new(5, 5);
let visible = shadowcast(origin, 3, &simple_map());
assert!(visible.contains(&origin));
}
}Examples in examples/ serve as integration tests and usage demonstrations. They should compile and run successfully.
- Choose appropriate crate (or create new one in
crates/) - Implement algorithm with public API
- Add to crate's
lib.rsandprelude.rs - Write unit tests
- Add benchmark if performance-critical
- Create example demonstrating usage
- Document with rustdoc comments
- Create directory in
crates/runeforge-newfeature/ - Add to workspace members in root
Cargo.toml - Define workspace dependencies in
[workspace.dependencies] - Add feature flag in root
Cargo.tomlfeatures section - Re-export in
src/lib.rswith#[cfg(feature = "newfeature")] - Add to prelude if commonly used
New backends should implement the traits defined in runeforge-terminal:
- Implement console rendering trait
- Handle font/tileset loading
- Manage window/event loop if applicable
- Add feature flag for optional inclusion
glam: Fast linear algebra (Vec2, IVec2, matrices)rand: Random number generationwinit: Cross-platform window managementwgpu: Modern graphics API (Vulkan/Metal/DX12/GL backend)pixels: GPU-accelerated pixel bufferab_glyph: TrueType font renderingimage: PNG/image loadinghashbrown: Fast hash maps/setscriterion: Benchmarking framework
When adding dependencies:
- Prefer
default-features = falseand enable only needed features - Use workspace dependencies for version consistency
- Consider feature flags to make dependencies optional
- Avoid duplicating functionality already in the standard library
Current Phase: 5 (Input & Integration) - ~70% complete
Completed:
- ✅ Core crates (color, geometry, random, direction, distance)
- ✅ FOV algorithms (Symmetric Shadowcasting, Adams)
- ✅ Pathfinding (A*, Dijkstra, BFS, DFS variants)
- ✅ Map generation (BSP, Cellular Automata, Drunkard's Walk, Caves)
- ✅ Rendering system (Terminal, GPU, Software backends)
- ✅ Input handling (keyboard/mouse with action mapping)
- ✅ Complete demo game integration
In Progress/Planned:
- 🔨 Advanced noise generation algorithms
- 🔨 Additional map generation patterns
- 🔨 UI framework/widgets
- 🔨 WebAssembly optimization
See RUNEFORGE.md for detailed roadmap and design decisions.