How glagan/42-cub3d works
Project type and purpose
• This is a single‐player raycasting “game engine” project in C, inspired by Wolfenstein 3D.
File structure
• Top‐level C modules:
• main.c, cub3d.c, game.c – orchestrate initialization, game loop, and state updates
• bmp.c – BMP screenshot writer
• engine/: core raycasting and rendering logic (camera, raycast, draw_wall/floor/sky, sprites, UI, shadow, crosshair, shortcuts)
• gnl/: get_next_line helper for file I/O
• mlx/: wrapper around the MiniLibX graphics/input API (window, image, event hook, string‐drawing)
• textures/: .xpm image assets used by engine
• utils/: generic C helpers (string, memory, conversions, position struct)
• maps/: sample .cub files for testing
README insights
• Describes controls, features (shadows, crosshair, sprites), and dependencies on MiniLibX and BMP export.
Main components
a. Components
2. Core Game Loop (main.c, cub3d.c, game.c) – initializes subsystems, enters loop: process input, update, render
3. Input Handler (engine/shortcuts.c + mlx event hooks) – translates keyboard events (WASD, QE, I/O/L toggles, ESC) into game actions
4. Raycasting & Rendering Engine (engine/*)
– Camera & view/projection (camera.c, tables.c)
– Raycasting per pixel (raycast.c)
– Sprite management (sprite.c, sprite_utils.c)
– UI overlay (crosshair.c, ui.c, minimap in quest.c)
5. Graphics Abstraction Layer (mlx/*) – creates window, handles events, manages frame buffer (mlx_image.swift/C), draws pixels/text
6. Asset Store (textures/*) – XPM files used by rendering engine
7. Utility Library (utils/* & gnl/*) – low‐level helpers for strings, memory, file reading
8. BMP Exporter (bmp.c) – writes current frame buffer to BMP on demand
b. Relationships & Data Flow
• Core Loop → Input Handler: registers callbacks, polls events via MLX
• Core Loop → Rendering Engine: passes camera state, map data, asset pointers → produces frame buffer
• Rendering Engine → Graphics Layer (MLX): pushes frame buffer each tick, draws UI overlays
• User via MLX → Input Handler → Core Loop: changes camera position/orientation or toggles UI options
• Core Loop → BMP Exporter: when user requests screenshot
• Utility Library used by nearly every component for common operations
c. Architectural patterns & design principles
• Modular separation by responsibility (parsing, game logic, rendering, I/O, utilities)
• Single‐threaded game loop
• Layered architecture: Core → Engine → Graphics API
• Data‐driven design: map files and textures external to code
• Use of callback/event model for input via MLX
d. Key technologies/libraries
• C language, POSIX file I/O
• MiniLibX (MLX) for windowing, events, image buffer
• XPM textures, BMP export
• get_next_line for line‐by‐line file parsing
Final advice
• Be extremely detailed: include each submodule (e.g., render_wall vs. render_floor) if desired.
• Configuration flow, game‐state updates, rendering pipeline, and I/O event flow clearly.
• Avoid over‐abstracting—show the real .c/.h boundaries so maintenance and scaling decisions are evident.