How simoxeur/cub3d_42 works
Project type and purpose
• Cub3D is a small 3D game engine that parses a simple map file, executes a continuous game loop (handling input, updating game state, performing raycasting, and rendering frames), and displays graphics via the MLX42 windowing library.
File structure
• Top-level modules:
– parse/ : map-file parsing and validation
– srcs/ : core engine (initialization, game loop, input hook, rendering, raycasting, minimap, torch)
– get_next_line/ : line-oriented file reader used by the parser
– utils/ : generic helper functions (string, memory, error handling)
– maps/ and textures/ : external resources (map definitions, sprite/texture files)
• Build orchestrated by a Makefile, relies on external MLX42 library
README insights
• Single executable invoked with a .cub map file
• Controls map to input hooks that drive player movement, torch, and camera rotation
Main components & their interactions
a. Resource Manager (maps/, textures/, get_next_line/)
– Reads .cub file using get_next_line
– Validates map and loads texture paths
– Outputs in-memory structures (map grid, texture references)
b. Initialization Module (srcs/initialisation.c)
– Configures MLX42 window/context
– Allocates and sets up core game state structures
c. Game Loop & Input Handler (srcs/key_hook.c, srcs/input_handle.c)
– Receives keyboard/mouse events from MLX42
– Updates player position, orientation, torch state
d. Raycasting Engine (srcs/ray_handler.c, ray_cast_utils*.c)
– Casts rays per vertical screen stripe
– Computes wall distances and texture coordinates
e. Renderer (srcs/render3d.c, render_utils.c, graphic_handle.c)
– Pushes buffer to the MLX42 window
f. Cleanup & Error Handling (srcs/clean_close.c, srcs/error_mlx.c)
– Frees allocations, closes window, exits gracefully
Architectural patterns & principles
• Event-driven game loop: clear separation of input → update → render stages
• Modular layering:
– Low-level utils and file I/O
– Parser and resource loading
– Core game logic (init, update, raycast)
– Rendering and external library interface
• Single process, single threaded: no networking or external services
• Continuous loop: Input → Update (raycast + state) → Render → back to Input
• Initialization and cleanup as distinct steps outside the main loop