Skip to content

Commit

Permalink
Use C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Jul 8, 2024
1 parent f14a6a4 commit c0fef4f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
fail-fast: false
matrix:
platform:
- { name: Windows, os: windows-latest }
- { name: Linux GCC, os: ubuntu-latest }
- { name: Linux Clang, os: ubuntu-latest, flags: -DCMAKE_CXX_COMPILER=clang++ }
- { name: macOS, os: macos-latest }
- { name: Windows, os: windows-2022 }
- { name: Linux GCC, os: ubuntu-24.04 }
- { name: Linux Clang, os: ubuntu-24.04, flags: -DCMAKE_CXX_COMPILER=clang++ }
- { name: macOS, os: macos-14 }
config:
- { name: Debug }
- { name: Release }
Expand All @@ -24,7 +24,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
sudo apt install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libopenal-dev libfreetype-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ FetchContent_MakeAvailable(SFML)

add_executable(mandelbrot src/Mandelbrot.cpp)
target_link_libraries(mandelbrot PRIVATE SFML::Graphics SFML::Audio Threads::Threads)
target_compile_features(mandelbrot 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 @@ -8,7 +8,7 @@ SFML-based Mandelbrot viewer program.
</p>

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

# Building & Running
Expand Down
14 changes: 6 additions & 8 deletions src/Mandelbrot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
#include <SFML/Graphics.hpp>

#include <complex>
#include <iomanip>
#include <format>
#include <thread>

using Complex = std::complex<long double>;

namespace {
auto calculate(const Complex& c, const int iteration_limit) noexcept
constexpr auto calculate(const Complex& c, const int iteration_limit) noexcept
{
auto iterations = 0;
for (auto z = Complex(); std::norm(z) <= 4 && iterations < iteration_limit; ++iterations)
z = z * z + c;
return iterations;
}

auto color(const int iterations, const int iteration_limit) noexcept -> sf::Color
constexpr auto color(const int iterations, const int iteration_limit) noexcept -> sf::Color
{
const auto hue = iterations % 360;
const auto sat = 0.8f;
Expand Down Expand Up @@ -169,10 +169,8 @@ int main()
window.draw(text);
window.display();

auto text_builder = std::ostringstream();
text_builder << std::setw(2) << int(1 / clock.restart().asSeconds()) << " fps\n";
text_builder << iteration_limit << " iters\n";
text_builder << std::setprecision(1) << std::scientific << initial_extent / extent << '\n';
text.setString(text_builder.str());
const auto fps = int(1 / clock.restart().asSeconds());
const auto ratio = initial_extent / extent;
text.setString(std::format("{:2} fps\n{} iters\n{:1.1e}\n", fps, iteration_limit, ratio));
}
}

0 comments on commit c0fef4f

Please sign in to comment.