How beddinao/cub3d works
High-Level Architecture Components
A. Core Application (src/)
• main.c: application entry point, initializes subsystems and enters main loop
• Parsing modules (src/parsing/…):
• Config parser & validator
• Parser & multi-stage validator
• Texture parser & validator
• Rendering modules (src/rendering/…):
• raycasting_init & raycasting_engine: compute wall slices
• hooks & movement: input handling & player state updates
• rendering: orchestrates per-frame rendering
• Utility modules (src/utils/…): common helpers for config, errors, rendering utilities
B. Asset Layer (assets/)
• maps/*.cub: level definitions
• textures (external image files loaded via MLX42)
• recordings: demo animations/screenshots
C. External Libraries (lib/)
• MLX42: window creation, input events, image/shader handling, drawing primitives
• get_next_line: buffered file I/O for parsing
• libft: common C utility functions (string, memory, list, etc.)
D. Build & Configuration
• Makefile/CMakeLists.txt drive compilation, link external libs, generate executable
• /: public headers (cub3d.h, engine.h) defining data structures & APIs
Data Flow & Component Interactions
1. Startup
→ main initializes logging/error handlers
→ initialize MLX42: create window, load shaders/textures into GPU memory
2. Main Loop
a. Input (hooks module) captures key/mouse events → updates player position/orientation
b. Rendering (raycasting_engine): cast rays against map grid, compute distances, wall heights
c. Drawing: write pixel data to MLX42 image buffer → MLX42 present to screen
d. Repeat until exit hook triggers mlx_exit
3. Shutdown
→ free allocated memory (libft, parsing structures)
→ destroy MLX42 resources
Architectural Patterns & Principles
• Modular separation: parsing, rendering, utilities, external libs
• Single-responsibility: each parser/validator handles one aspect of file input
• Event-driven loop: MLX42 hooks trigger state updates & re-renders