How madebypixel02/cub3d works
Project type and purpose
• This is a single‐process, native C “game engine” implementing a Wolfenstein-style renderer (a raycaster) using the MiniLibX graphics library.
File structure
• inc/ : public headers defining data structures and function prototypes (cub3d.h, get_next_line.h, keycodes.h, my_mlx.h).
• src/ : modules implementing
• main.c (entry point, init, game loop)
• parse_map.c, map.c (map file parsing, validation)
• get_next_line.c(.utils) (file I/O)
• raycast.c, render.c (ray‐casting logic, fisheye fix, frame generation)
• player.c, game.c, minimap.c, utils.c, end_*.c, error.c (input, state updates, bonus features, cleanup).
• textures/ : XPM sprite assets for walls, doors, Pac-Man, ghosts, torches.
• maps/ : sample .cub maps + MAPS.md.
• Build files (Makefile, .gitignore).
README for additional insights
• No network or database; pure graphics+math+I/O.
Components
a. Main Components
• CLI & Config Loader
• Parser
• Core Game Loop
• Input Handler
• World Updater (player movement, door toggling, collisions, animations)
• Raycasting Engine (distance calculator, fisheye corrector)
• Renderer (texture sampler, vertical stripe drawer)
• MiniLibX Graphics Subsystem (window, event hooks, pixel buffer)
• Cleanup/Exit Handler
b. Relationships & Data Flow
1. User invokes cub3d map.cub on the CLI → Map Parser reads .cub file via get_next_line → builds in‐memory Map data structure + header settings.
2. Resource Manager loads XPM textures (file I/O) into memory.
3. Enter Game Loop:
– Input Handler receives key/mouse events from MiniLibX → updates Player orientation/commands.
– World Updater applies movement vectors & door toggles → updates Map/Player state.
– Raycasting Engine casts N rays per frame (window width) → outputs distance slices & wall side info.
– Renderer uses distance values + textures to produce a pixel buffer.
4. MiniLibX draws the pixel buffer to the window each frame.
5. Loop repeats until exit; Cleanup Handler frees memory and closes window.
c. Architectural Patterns & Principles
• Module separation (parsing vs. rendering vs. input vs. resource loading).
• Event‐driven loop (MiniLibX event hooks).
• Data‐driven rendering pipeline (map+player → rays → frame).
• Single‐threaded, synchronous loop (no concurrency).
d. Key Technologies & Libraries
• C99
• MiniLibX (graphics/window/event API)
• POSIX file I/O (open, read) via get_next_line
• math.h for trigonometry
• XPM file format for textures
Detailed capture of essential elements
• Do not fire‐hose every C file; group related .c/.h into higher‐level modules.
• Cover all critical paths: startup → game loop → shutdown.
• How textures flow from disk → memory → pixel buffer → screen.
• Call out the raycasting math block (distance computation, fisheye correction, wall height formula).