Skip to content

Refactor: Major codebase cleanup and modernization#13

Merged
nurusanwe merged 3 commits intomainfrom
cleanup/refactor-and-modernize
Oct 9, 2025
Merged

Refactor: Major codebase cleanup and modernization#13
nurusanwe merged 3 commits intomainfrom
cleanup/refactor-and-modernize

Conversation

@nurusanwe
Copy link
Owner

Summary

This PR performs a comprehensive cleanup and modernization of the Educational Ray Tracer codebase, improving code organization, maintainability, and reducing complexity.

Key Changes

🏗️ Architecture Improvements

  1. CLI Argument Parser Extraction (src/cli/argument_parser.hpp)

    • Extracted ~230 lines of argument parsing logic from main.cpp
    • Centralized configuration in ArgumentParser::Config struct
    • Improved testability and maintainability
  2. Renderer Class Extraction (src/core/renderer.hpp)

    • Extracted 200-line rendering lambda into dedicated class
    • Consolidated performance statistics into Renderer::Stats struct
    • Clean separation of rendering logic from main orchestration
  3. Constants Centralization (src/core/constants.hpp)

    • Created Constants namespace for magic numbers
    • Extracted repeated colors, positions, and default values
    • 12+ replacements across codebase

🧹 Code Cleanup

  1. Unified Rendering Architecture

    • Consolidated dual rendering paths (Scene vs Cook-Torrance bypass)
    • All materials now flow through Scene system consistently
    • Removed ~40 lines of fallback code
  2. Dead Code Removal

    • Removed unused #include <cstring> from main.cpp
    • Removed image_light fallback (always use Scene lights)
    • Removed unused member variables from Renderer
  3. Verbosity Reduction

    • Reduced duplicate console output by 30%
    • Resolution now printed 7 times instead of 10

📊 Impact

  • main.cpp: Reduced from ~1,200 to ~915 lines (-23%)
  • Total lines removed: ~374 lines across codebase
  • New files created: 3 (ArgumentParser, Renderer, Constants)
  • Code organization: Significantly improved
  • All tests passing:

Testing

  • ✅ Build successful (./build_simple.sh)
  • ✅ All mathematical tests pass
  • ✅ Lambert rendering works correctly
  • ✅ Cook-Torrance rendering works correctly
  • ✅ Interactive mode functional
  • ✅ Quiet mode reduces output properly

Breaking Changes

None - All existing functionality preserved.

Checklist

  • Code builds without errors
  • All tests pass
  • No functionality removed
  • Improved code organization
  • Documentation structure preserved

RGT and others added 3 commits October 7, 2025 17:14
Quick wins completed:
- Replace raw pointer with unique_ptr in interactive mode (RAII)
- Remove duplicate add_material(const LambertMaterial&) method
- Update all call sites to use polymorphic API with make_unique
- Fix memory safety issues

Changes:
- src/core/scene.hpp: Remove legacy add_material() overload
- src/main.cpp: Use unique_ptr for interactive_material
- tests/test_math_correctness.cpp: Update to polymorphic API

Benefits:
- Better memory safety with automatic cleanup
- Consistent API usage throughout codebase
- No raw pointer management needed
Implements a proper logging system to replace scattered quiet_mode booleans.

New Features:
- Logger class with 4 verbosity levels (Silent/Normal/Verbose/Debug)
- Static API for global verbosity control
- Helper methods: is_verbose(), is_quiet(), is_silent()
- Command-line integration with --quiet and --verbose flags

Changes:
- src/core/logger.hpp: New Logger implementation
- src/main.cpp: Replace quiet_mode with Logger calls throughout

Benefits:
- Centralized verbosity control
- More granular output levels
- Easier to extend in the future
- Cleaner API than boolean parameters

Note: Full integration into Scene/Material classes pending
(those still use verbose boolean parameters, will be updated next)
## Changes

### Architecture Improvements
- Extract CLI argument parsing to ArgumentParser class
- Extract render logic from lambda to Renderer class
- Consolidate rendering paths to unified Scene-based architecture
- Create Constants namespace for magic numbers

### Code Quality
- Remove fallback code paths (always use Scene system)
- Consolidate performance tracking into Renderer::Stats struct
- Remove unused includes (cstring in main.cpp)
- Reduce console output verbosity by 30%

### Impact
- main.cpp reduced by ~280 lines
- Removed ~374 lines total across codebase
- Improved maintainability and testability
- All tests passing

Co-Authored-By: Robot Assistant <noreply@example.com>
@nurusanwe nurusanwe merged commit 506ceb1 into main Oct 9, 2025
6 checks passed
@nurusanwe nurusanwe deleted the cleanup/refactor-and-modernize branch October 9, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant