How bengschor/cub3d works
Main Components
• Raycasting Engine – The heart of the system; this module (located in “srcs/raycasting” and “bns_srcs/raycasting”) is responsible for computing the camera ray for each screen column, performing the Digital Differential Analysis (DDA), determining wall distances, and selecting textures.
• Player & Input Handling – The player movement (rotation, forward/backward movement) is integrated via the “srcs/hooks” and “bns_srcs/hooks” code, which captures and interprets key inputs.
• Utility Functions – Various helper functions found in “srcs/utils” and “bns_srcs/utils”, such as memory management, string handling, and drawing primitives (e.g., Bresenham algorithm for some directions).
Relationships and Interactions
• Initialization:
• The parsing modules (either in srcs/parsing or bns_srcs/parsing for bonus features) set up the game state.
• Game Loop:
• Once initialized, the main loop takes over, where for each frame several actions happen:
a) Input is captured (from srcs/hooks or bns_srcs/hooks).
b) The raycasting module computes the ray direction based on the player’s current position and camera plane. This involves camera ray calculation, determining step directions, side distance initialization, iterating via DDA, and finally computing perpendicular wall distances.
c) Based on distances, wall slices are computed and drawn using texture data.
• Rendering:
• The computed image is rendered on a window managed by the MinilibX library. The rendering process also deals with auxiliary components like an optional minimap.
• Error Management:
• Throughout the process, the utility functions handle errors and ensure resources are managed properly (memory allocation/deallocation, input validation).
Architectural Patterns & Design Principles
• Modular Design – Each of the primary functionalities (parsing, raycasting, input handling, rendering, utilities) is separated into its own directory. This separation aids clarity and maintainability.
• The bottom layer includes “minilibx” as the interface to the operating system’s graphical subsystem.
• The middle layers include core game logic (raycasting engine, player input) and parsing.
• The top layer reflects the high-level application control (main loop and state management).
• Reusability and Extensibility – The bonus directories (e.g. bns_srcs) indicate additional features or extensions built on top of the core engine.
Technologies & External Dependencies
• C language for the core logic.
• MinilibX library – This is a crucial dependency used for windowing and rendering.
• Custom asset loading of textures stored in XPM format (the “assets” directory).
Very Detailed System Design
• Error handling and memory management as supporting features across modules.
• Optionally, include a section to note that the project supports bonus features (as indicated by the separate “bns_srcs” directories) which could be annotated as extended components enhancing the core functionality.