Skip to content

Commit

Permalink
Start using C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Oct 29, 2024
1 parent 54038be commit f1cb19b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_executable(raytracer
)
target_link_libraries(raytracer PRIVATE SFML::Graphics)
target_compile_definitions(raytracer PRIVATE FONT_PATH="${CMAKE_SOURCE_DIR}/data")
target_compile_features(raytracer PRIVATE cxx_std_20)

add_custom_target(format
COMMAND clang-format -i `git ls-files *.hpp *.cpp`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SFML-based raytracer program
![raytracer](docs/raytracer.png)

# Requirements
* C++17
* C++20
* CMake 3.28

# Building & Running
Expand Down
15 changes: 8 additions & 7 deletions src/Raytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <algorithm>
#include <atomic>
#include <format>
#include <iostream>
#include <thread>

Expand Down Expand Up @@ -36,12 +37,12 @@ namespace {
scene.emplace_back(sf::Vector3f(0, -1000, 0), 1000.f, Lambertian { { 0.3f, 0.6f, 0.1f } });

// Add fixed large spheres
scene.emplace_back(sf::Vector3f(-4, 2, 0), 2.f, Lambertian { { 0.2f, 0.3f, 0.7f } });
scene.emplace_back(sf::Vector3f(-0.5f, 1.5, 1), 1.5f, Metal { { 0.7f, 0.4f, 0.3f }, 1.f });
scene.emplace_back(sf::Vector3f(1.25f, 1, 1.5f), 1.f, Metal { { 0.7f, 0.6f, 0.5f }, 0.f });
scene.emplace_back(sf::Vector3f(3, 0.75f, 3), 0.75f, Metal { { 0.8f, 0.2f, 0.1f }, 0.5f });
scene.emplace_back(sf::Vector3f(4, 0.5f, 5), 0.5f, Metal { { 0.8f, 0.7f, 0.1f }, 0.f });
scene.emplace_back(sf::Vector3f(2, 0.5, 6), 0.5f, Dielectric { 1.5f });
scene.emplace_back(sf::Vector3f(-4, 2, 0), 2.f, Lambertian { .albedo { 0.2f, 0.3f, 0.7f } });
scene.emplace_back(sf::Vector3f(-0.5f, 1.5, 1), 1.5f, Metal { .albedo = { 0.7f, 0.4f, 0.3f }, .fuzz = 1.f });
scene.emplace_back(sf::Vector3f(1.25f, 1, 1.5f), 1.f, Metal { .albedo = { 0.7f, 0.6f, 0.5f }, .fuzz = 0.f });
scene.emplace_back(sf::Vector3f(3, 0.75f, 3), 0.75f, Metal { .albedo = { 0.8f, 0.2f, 0.1f }, .fuzz = 0.5f });
scene.emplace_back(sf::Vector3f(4, 0.5f, 5), 0.5f, Metal { .albedo = { 0.8f, 0.7f, 0.1f }, .fuzz = 0.f });
scene.emplace_back(sf::Vector3f(2, 0.5, 6), 0.5f, Dielectric { .index_of_refraction = 1.5f });

return scene;
}
Expand Down Expand Up @@ -134,7 +135,7 @@ int main()
// Print elapased time
const auto elapsed
= std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - now);
std::cout << "Render time: " << std::fixed << std::setprecision(2) << elapsed.count() << "s" << std::endl;
std::cout << std::format("Render time: {:.2f}s\n", elapsed.count());
};

// Start rendering
Expand Down

0 comments on commit f1cb19b

Please sign in to comment.