#![allow(clippy::needless_return)]
#![allow(clippy::implicit_return)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::items_after_statements)]
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::doc_markdown)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::explicit_iter_loop)]
#![allow(clippy::format_in_format_args)]
#![allow(clippy::cast_precision_loss)]
#![allow(clippy::wildcard_imports)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::std_instead_of_core)]
#![allow(clippy::similar_names)]
#![allow(clippy::duplicated_attributes)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::trivially_copy_pass_by_ref)]
#![allow(clippy::missing_inline_in_public_items)]
#![allow(clippy::useless_vec)]
#![allow(clippy::unnested_or_patterns)]
#![allow(clippy::else_if_without_else)]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::redundant_else)]
#![allow(clippy::cast_lossless)]
use tiles_tools::debug::*;
use tiles_tools::debug::utils;
use std::time::{Duration, Instant};
use std::collections::HashMap;
fn main() {
println!("🔍 Debug System Demonstration");
println!("==============================");
println!("\n📊 Grid Renderer");
println!("----------------");
demonstrate_grid_styles();
println!("\n🗺️ Pathfinding Debug Visualization");
println!("----------------------------------");
demonstrate_pathfinding_debug();
println!("\n🔍 ECS Component Inspector");
println!("-------------------------");
demonstrate_ecs_inspector();
println!("\n⚡ Performance Profiler");
println!("----------------------");
demonstrate_performance_profiler();
println!("\n🛠️ Debug Utilities");
println!("------------------");
demonstrate_debug_utilities();
println!("\n🎮 Integrated Game Debug Session");
println!("-------------------------------");
demonstrate_integrated_debugging();
println!("\n✨ Debug Demo Complete!");
println!("\nKey features demonstrated:");
println!("• Grid visualization with multiple coordinate systems");
println!("• Pathfinding debug overlays and cost visualization");
println!("• ECS entity and component inspection");
println!("• Performance profiling and bottleneck detection");
println!("• ASCII art rendering for console debugging");
println!("• SVG export for documentation and analysis");
println!("• Memory usage monitoring and system metrics");
println!("• Integrated debugging workflows");
}
fn demonstrate_grid_styles() {
println!("Testing different grid styles...");
let mut square_grid = GridRenderer::new()
.with_size(8, 6)
.with_style(GridStyle::Square4);
square_grid.add_colored_marker((1, 1), "S", "Start", DebugColor::Green, 10);
square_grid.add_colored_marker((6, 4), "G", "Goal", DebugColor::Blue, 10);
square_grid.add_colored_marker((3, 2), "X", "Obstacle", DebugColor::Red, 5);
square_grid.add_path(vec![(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (6, 2), (6, 3), (6, 4)], "Path", DebugColor::Yellow);
println!("\n□ Square Grid (4-connected):");
println!("{}", square_grid.render_ascii());
let mut hex_grid = GridRenderer::new()
.with_size(10, 7)
.with_style(GridStyle::Hexagonal);
hex_grid.add_colored_marker((2, 2), "H", "Hero", DebugColor::Green, 10);
hex_grid.add_colored_marker((7, 5), "T", "Treasure", DebugColor::Yellow, 10);
hex_grid.add_area(vec![(4, 3), (5, 3), (4, 4), (5, 4)], "Water", DebugColor::Blue, HighlightStyle::Fill);
println!("⬢ Hexagonal Grid:");
println!("{}", hex_grid.render_ascii());
let mut tri_grid = GridRenderer::new()
.with_size(8, 5)
.with_style(GridStyle::Triangular);
tri_grid.add_colored_marker((3, 2), "△", "Peak", DebugColor::Purple, 10);
tri_grid.add_area(vec![(1, 4), (2, 4), (3, 4)], "Valley", DebugColor::Green, HighlightStyle::Outline);
println!("▲ Triangular Grid:");
println!("{}", tri_grid.render_ascii());
}
fn demonstrate_pathfinding_debug() {
let mut pathfinder = PathfindingDebugger::new(12, 8);
pathfinder.set_start((1, 1));
pathfinder.set_goal((10, 6));
let obstacles = vec![
(4, 2), (4, 3), (4, 4), (4, 5),
(7, 1), (7, 2), (7, 3),
(2, 6), (3, 6), (4, 6),
];
for obstacle in obstacles {
pathfinder.add_obstacle(obstacle);
}
let path = vec![
(1, 1), (2, 1), (3, 1), (5, 1), (6, 1),
(8, 1), (9, 1), (10, 1), (10, 2), (10, 3),
(10, 4), (10, 5), (10, 6),
];
pathfinder.add_path(path, "Optimal Path");
let visited = vec![
(1, 1), (2, 1), (3, 1), (1, 2), (2, 2),
(5, 1), (6, 1), (5, 2), (6, 2), (7, 4),
(8, 1), (9, 1), (8, 4), (9, 4), (10, 1),
(10, 2), (10, 3),
];
pathfinder.add_visited_nodes(visited);
let open = vec![(3, 0), (4, 1), (5, 0), (10, 4), (10, 5), (9, 6)];
pathfinder.add_open_nodes(open);
let mut costs = HashMap::new();
costs.insert((2, 2), 3); costs.insert((5, 2), 2); costs.insert((8, 4), 4); costs.insert((9, 4), 4); costs.insert((9, 5), 2); pathfinder.set_costs(costs);
println!("Pathfinding Debug Visualization:");
println!("{}", pathfinder.render_ascii());
}
fn demonstrate_ecs_inspector() {
let mut inspector = ECSInspector::new();
let entities = vec![
EntityDebugInfo {
id: 1,
components: vec!["Position".to_string(), "Health".to_string(), "Player".to_string()],
position: Some((5, 10)),
data: vec![
("health".to_string(), "100".to_string()),
("level".to_string(), "5".to_string()),
("class".to_string(), "Warrior".to_string()),
].into_iter().collect(),
},
EntityDebugInfo {
id: 2,
components: vec!["Position".to_string(), "AI".to_string(), "Health".to_string()],
position: Some((15, 8)),
data: vec![
("health".to_string(), "75".to_string()),
("ai_state".to_string(), "Patrolling".to_string()),
("enemy_type".to_string(), "Orc".to_string()),
].into_iter().collect(),
},
EntityDebugInfo {
id: 3,
components: vec!["Position".to_string(), "Velocity".to_string(), "Projectile".to_string()],
position: Some((12, 12)),
data: vec![
("damage".to_string(), "25".to_string()),
("speed".to_string(), "10.0".to_string()),
("owner".to_string(), "1".to_string()),
].into_iter().collect(),
},
EntityDebugInfo {
id: 4,
components: vec!["Position".to_string(), "Health".to_string(), "AI".to_string()],
position: Some((3, 15)),
data: vec![
("health".to_string(), "50".to_string()),
("ai_state".to_string(), "Fleeing".to_string()),
("enemy_type".to_string(), "Goblin".to_string()),
].into_iter().collect(),
},
EntityDebugInfo {
id: 5,
components: vec!["Position".to_string(), "Item".to_string()],
position: Some((20, 5)),
data: vec![
("item_type".to_string(), "HealthPotion".to_string()),
("value".to_string(), "50".to_string()),
].into_iter().collect(),
},
];
for entity in entities {
inspector.record_entity(entity);
}
inspector.record_system_timing("MovementSystem".to_string(), Duration::from_micros(1500));
inspector.record_system_timing("RenderSystem".to_string(), Duration::from_micros(8200));
inspector.record_system_timing("AISystem".to_string(), Duration::from_micros(3100));
inspector.record_system_timing("PhysicsSystem".to_string(), Duration::from_micros(4700));
inspector.record_system_timing("CollisionSystem".to_string(), Duration::from_micros(2800));
println!("ECS Inspector Report:");
println!("{}", inspector.generate_report());
println!("\nECS Data as JSON:");
println!("{}", inspector.export_json());
}
fn demonstrate_performance_profiler() {
let mut profiler = PerformanceProfiler::new();
println!("Simulating game performance over 120 frames...");
let base_frame_time = Duration::from_micros(16667);
for frame in 0..120 {
let variance = if frame % 20 == 0 {
Duration::from_micros(8000)
} else if frame % 7 == 0 {
Duration::from_micros(2000)
} else {
Duration::from_micros(((frame * 37) % 1000) as u64) };
let frame_time = base_frame_time + variance;
profiler.record_frame_time(frame_time);
profiler.record_system_time("MovementSystem".to_string(), Duration::from_micros(1000 + (frame % 500) as u64));
profiler.record_system_time("RenderSystem".to_string(), Duration::from_micros(8000 + (frame % 2000) as u64));
profiler.record_system_time("AISystem".to_string(), Duration::from_micros(2000 + (frame % 800) as u64));
profiler.record_system_time("PhysicsSystem".to_string(), Duration::from_micros(3000 + (frame % 1200) as u64));
if frame % 10 == 0 {
let base_memory = 50 * 1024 * 1024; let memory_growth = frame as u64 * 1024 * 10; let entity_count = 100 + (frame / 10) * 5;
profiler.record_memory_sample(base_memory + memory_growth, entity_count);
}
}
println!("Performance Profile Report:");
println!("{}", profiler.generate_report());
let stats = profiler.get_stats();
println!("\nQuick Performance Summary:");
println!("• Average FPS: {:.1}", stats.fps);
println!("• Frame Time: {:.2}ms avg, {:.2}ms max",
stats.avg_frame_time.as_secs_f64() * 1000.0,
stats.max_frame_time.as_secs_f64() * 1000.0);
println!("• Memory: {}", utils::format_memory(stats.current_memory));
println!("• Entities: {}", stats.current_entities);
println!("• Uptime: {}", utils::format_duration(stats.uptime));
}
fn demonstrate_debug_utilities() {
println!("Testing debug utility functions...");
let visibility_map = vec![
vec![true, true, false, false, true],
vec![true, false, false, true, true],
vec![false, false, true, true, true],
vec![true, false, true, false, false],
vec![true, true, true, true, false],
];
println!("\nVisibility Map (# = visible, . = hidden):");
println!("{}", utils::render_bool_grid(&visibility_map, '#', '.'));
let durations = vec![
Duration::from_nanos(500),
Duration::from_micros(150),
Duration::from_millis(25),
Duration::from_secs(2),
];
println!("Duration Formatting:");
for duration in durations {
println!("• {}", utils::format_duration(duration));
}
let memory_sizes = vec![512, 1536, 2048 * 1024, 1536 * 1024 * 1024];
println!("\nMemory Formatting:");
for size in memory_sizes {
println!("• {}", utils::format_memory(size));
}
}
fn demonstrate_integrated_debugging() {
println!("Simulating integrated debugging session...");
let mut main_renderer = GridRenderer::new()
.with_size(15, 10)
.with_style(GridStyle::Square8);
main_renderer.add_colored_marker((2, 2), "P1", "Player 1", DebugColor::Green, 20);
main_renderer.add_colored_marker((12, 8), "P2", "Player 2", DebugColor::Blue, 20);
main_renderer.add_colored_marker((7, 3), "E1", "Enemy Archer", DebugColor::Red, 15);
main_renderer.add_colored_marker((5, 7), "E2", "Enemy Knight", DebugColor::Red, 15);
main_renderer.add_colored_marker((6, 4), "T", "Tree", DebugColor::Green, 5);
main_renderer.add_colored_marker((8, 6), "R", "Rock", DebugColor::Gray, 5);
main_renderer.add_area(
vec![(10, 4), (11, 4), (10, 5), (11, 5)],
"Fire Area",
DebugColor::Orange,
HighlightStyle::Fill
);
main_renderer.add_area(
vec![(1, 1), (2, 1), (3, 1), (1, 2), (3, 2), (1, 3), (2, 3), (3, 3)],
"P1 Movement Range",
DebugColor::Green,
HighlightStyle::Dotted
);
main_renderer.add_annotation((7, 1), "Archer Range", DebugColor::Red);
main_renderer.add_annotation((10, 3), "Danger Zone", DebugColor::Yellow);
println!("\nTactical Game State:");
println!("{}", main_renderer.render_ascii());
let mut frame_profiler = PerformanceProfiler::new();
let start = Instant::now();
std::thread::sleep(Duration::from_micros(100)); frame_profiler.record_system_time("GameLogic".to_string(), start.elapsed());
let render_start = Instant::now();
std::thread::sleep(Duration::from_micros(200)); frame_profiler.record_system_time("Rendering".to_string(), render_start.elapsed());
frame_profiler.record_frame_time(start.elapsed());
frame_profiler.record_memory_sample(45 * 1024 * 1024, 8);
println!("\nFrame Performance:");
let stats = frame_profiler.get_stats();
println!("• Frame time: {}", utils::format_duration(stats.avg_frame_time));
println!("• Memory usage: {}", utils::format_memory(stats.current_memory));
println!("• Active entities: {}", stats.current_entities);
let mut ecs = ECSInspector::new();
let current_entities = vec![
EntityDebugInfo {
id: 1,
components: vec!["Position".to_string(), "Health".to_string(), "Player".to_string()],
position: Some((2, 2)),
data: vec![("health".to_string(), "85".to_string())].into_iter().collect(),
},
EntityDebugInfo {
id: 2,
components: vec!["Position".to_string(), "Health".to_string(), "Player".to_string()],
position: Some((12, 8)),
data: vec![("health".to_string(), "92".to_string())].into_iter().collect(),
},
EntityDebugInfo {
id: 3,
components: vec!["Position".to_string(), "AI".to_string(), "Weapon".to_string()],
position: Some((7, 3)),
data: vec![("weapon".to_string(), "Bow".to_string()), ("ai_state".to_string(), "Aiming".to_string())].into_iter().collect(),
},
];
for entity in current_entities {
ecs.record_entity(entity);
}
println!("\nEntity Summary:");
println!("Total entities: {}", ecs.entity_count());
let entity_ids = ecs.entity_ids();
for id in entity_ids {
if let Some(entity) = ecs.get_entity(id) {
if let Some(pos) = entity.position {
println!("• Entity {}: {} at ({}, {})", id, entity.components.join("+"), pos.0, pos.1);
}
}
}
println!("\n🎯 Integrated debugging session complete!");
println!("This demonstrates how all debug tools work together to provide");
println!("comprehensive visibility into game state, performance, and entities.");
}