Skip to content

Commit bf8fbdf

Browse files
committed
Slightly improve code quality of basic display
1 parent 7f7f0c5 commit bf8fbdf

File tree

6 files changed

+61
-97
lines changed

6 files changed

+61
-97
lines changed

.github/scripts/conan-ci-setup.sh

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ mv "$profile" "${profile}.bak"
1515
sed 's/^\(compiler\.cppstd=\).\{1,\}$/\1'"$std/" "${profile}.bak" > "$profile"
1616
rm "${profile}.bak"
1717

18+
# Add lines to global.conf
19+
global_conf="$HOME/.conan2/global.conf"
20+
mkdir -p "$(dirname "$global_conf")"
21+
{
22+
echo "tools.system.package_manager:mode = install"
23+
echo "tools.system.package_manager:sudo = true"
24+
} >> "$global_conf"
25+
1826
if [ -f conan_cache_save.tgz ]; then
1927
conan cache restore conan_cache_save.tgz
2028
fi

.github/workflows/ci.yml

-51
Original file line numberDiff line numberDiff line change
@@ -29,57 +29,6 @@ jobs:
2929
if: always()
3030
run: cmake -P cmake/spell.cmake
3131

32-
coverage:
33-
needs: [lint]
34-
35-
runs-on: ubuntu-22.04
36-
37-
# To enable coverage, delete the last line from the conditional below and
38-
# edit the "<name>" placeholder to your GitHub name.
39-
# If you do not wish to use codecov, then simply delete this job from the
40-
# workflow.
41-
if: github.repository_owner == '<name>'
42-
&& false
43-
44-
steps:
45-
- uses: actions/checkout@v4
46-
47-
- name: Install LCov
48-
run: sudo apt-get update -q
49-
&& sudo apt-get install lcov -q -y
50-
51-
- name: Install Python
52-
uses: actions/setup-python@v5
53-
with: { python-version: "3.12" }
54-
55-
- name: Conan cache
56-
uses: actions/cache@v4
57-
with:
58-
path: conan_cache_save.tgz
59-
key: conan-coverage-${{ hashFiles('conan*.[pl][yo]*') }}
60-
61-
- name: Install dependencies
62-
run: bash < .github/scripts/conan-ci-setup.sh
63-
64-
- name: Configure
65-
run: cmake --preset=ci-coverage
66-
67-
- name: Build
68-
run: cmake --build build/coverage -j 2
69-
70-
- name: Test
71-
working-directory: build/coverage
72-
run: ctest --output-on-failure --no-tests=error -j 2
73-
74-
- name: Process coverage info
75-
run: cmake --build build/coverage -t coverage
76-
77-
- name: Submit to codecov.io
78-
uses: codecov/codecov-action@v4
79-
with:
80-
file: build/coverage/coverage.info
81-
token: ${{ secrets.CODECOV_TOKEN }}
82-
8332
sanitize:
8433
needs: [lint]
8534

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include(cmake/variables.cmake)
1818
add_library(
1919
fractal-generator_lib OBJECT
2020
source/lib.cpp
21+
source/graphics/basic_display.cpp
2122
)
2223

2324
target_include_directories(

source/graphics/basic_display.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "basic_display.hpp"
2+
3+
#include <SFML/Graphics.hpp>
4+
5+
namespace fractal {
6+
void BasicDisplay::set_pixel(std::size_t x_pos, std::size_t y_pos, uint8_t value)
7+
{
8+
pixels_.at(x_pos).at(y_pos) = value;
9+
}
10+
11+
void BasicDisplay::display_window()
12+
{
13+
sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "SFML Window");
14+
15+
window.setFramerateLimit(FRAME_RATE);
16+
17+
sf::Image image;
18+
image.create(WINDOW_WIDTH, WINDOW_HEIGHT);
19+
for (std::size_t x_pos = 0; x_pos < WINDOW_WIDTH; ++x_pos) {
20+
for (std::size_t y_pos = 0; y_pos < WINDOW_HEIGHT; ++y_pos) {
21+
std::uint8_t pixel_value = pixels_.at(x_pos).at(y_pos);
22+
image.setPixel(
23+
static_cast<unsigned int>(x_pos), static_cast<unsigned int>(y_pos),
24+
sf::Color(pixel_value, pixel_value, pixel_value)
25+
);
26+
}
27+
}
28+
29+
sf::Texture texture;
30+
texture.loadFromImage(image);
31+
32+
sf::Sprite sprite(texture);
33+
34+
while (window.isOpen()) {
35+
sf::Event event;
36+
while (window.pollEvent(event)) {
37+
if (event.type == sf::Event::Closed) {
38+
window.close();
39+
}
40+
}
41+
42+
window.clear(sf::Color::Black);
43+
44+
window.draw(sprite);
45+
46+
window.display();
47+
}
48+
}
49+
} // namespace fractal

source/graphics/basic_display.hpp

+2-45
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
#include "config.hpp"
44

5-
#include <SFML/Graphics.hpp>
6-
7-
#include <cstddef>
85
#include <cstdint>
96

107
#include <array>
@@ -14,47 +11,7 @@ class BasicDisplay {
1411
std::array<std::array<uint8_t, WINDOW_HEIGHT>, WINDOW_WIDTH> pixels_{};
1512

1613
public:
17-
void set_pixel(std::size_t x_pos, std::size_t y_pos, uint8_t value)
18-
{
19-
pixels_.at(x_pos).at(y_pos) = value;
20-
}
21-
22-
void display_window()
23-
{
24-
sf::RenderWindow window(
25-
sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "SFML Window"
26-
);
27-
28-
window.setFramerateLimit(FRAME_RATE);
29-
30-
sf::Image image;
31-
image.create(WINDOW_WIDTH, WINDOW_HEIGHT);
32-
for (std::size_t x = 0; x < WINDOW_WIDTH; ++x) {
33-
for (std::size_t y = 0; y < WINDOW_HEIGHT; ++y) {
34-
uint8_t pixel_value = pixels_.at(x).at(y);
35-
image.setPixel(x, y, sf::Color(pixel_value, pixel_value, pixel_value));
36-
}
37-
}
38-
39-
sf::Texture texture;
40-
texture.loadFromImage(image);
41-
42-
sf::Sprite sprite(texture);
43-
44-
while (window.isOpen()) {
45-
sf::Event event;
46-
while (window.pollEvent(event)) {
47-
if (event.type == sf::Event::Closed) {
48-
window.close();
49-
}
50-
}
51-
52-
window.clear(sf::Color::Black);
53-
54-
window.draw(sprite);
55-
56-
window.display();
57-
}
58-
}
14+
void set_pixel(std::size_t x_pos, std::size_t y_pos, std::uint8_t value);
15+
void display_window();
5916
};
6017
} // namespace fractal

source/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
int main()
44
{
55
fractal::BasicDisplay display;
6-
for (size_t i = 0; i < 100; i++) {
6+
for (std::size_t i = 0; i < 100; i++) {
77
display.set_pixel(100, 100 + i, 255);
88
}
99
display.display_window();

0 commit comments

Comments
 (0)