// Main DDA loop - keep stepping until we hit a wall while (1) { // Compare distances: which boundary is closer? if (params->side_dist_x < params->side_dist_y) { // Vertical boundary is closer - step horizontally params->map_x += params->step_x; // Move to next/prev column params->side_dist_x += params->delta_dist_x; // Update distance params->side = 0; // Mark as vertical wall hit } else { // Horizontal boundary is closer - step vertically params->map_y += params->step_y; // Move to next/prev row params->side_dist_y += params->delta_dist_y; // Update distance params->side = 1; // Mark as horizontal wall hit } // Check what's in this new grid cell hit_tile = cub->data.map.map[params->map_y][params->map_x]; // Found a wall? Stop here! if (hit_tile == '1' || hit_tile == '2' || hit_tile == '3') { params->hit_tile = hit_tile; break; // Exit the loop - we found our wall! } }
The Core Logic: Always step to whichever grid boundary is closest. This ensures we never miss a wall!
Why it's called "Digital Differential Analyzer":
• Digital: Works on discrete grid cells
• Differential: Uses differences between grid positions
• Analyzer: Analyzes the line path efficiently
Performance Magic:
Instead of checking every pixel (400×400 = 160,000 checks), we only check grid boundaries (maybe 10-20 steps). That's why old games ran so fast!