From d2a76bd8cfd883070259bf572a9f723a37c0d96e Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 28 Jun 2022 19:22:06 +0200 Subject: refactor: improve includes with iwyu --- src/bootstrap.cpp | 40 ++++++++++++++++-------------- src/engine/data/bounds.cpp | 2 ++ src/engine/data/bounds.hpp | 4 ++- src/engine/data/vector2.cpp | 5 ++-- src/engine/data/vector2.hpp | 1 + src/engine/engine.cpp | 12 ++++++--- src/engine/engine.hpp | 11 +++++--- src/engine/graphics/component_renderer.cpp | 15 ++++++++--- src/engine/graphics/component_renderer.hpp | 9 ++++--- src/engine/graphics/scene.cpp | 14 ++++++----- src/engine/graphics/scene.hpp | 18 ++++++++------ src/engine/main.cpp | 7 +++--- src/engine/user/cursor.cpp | 5 ++-- src/engine/user/cursor.hpp | 16 ++++++------ src/engine/user/input.cpp | 5 ++-- src/engine/user/input.hpp | 3 +-- src/game/RLE_reader.cpp | 16 +++++------- src/game/components/statusline.cpp | 11 ++++---- src/game/components/statusline.hpp | 16 +++++++----- src/game/game.cpp | 31 +++++++++++++++-------- src/game/game.hpp | 31 +++++++++++++++-------- src/game/status_manager.cpp | 2 -- src/game/status_manager.hpp | 8 +++--- src/interfaces/RLE_reader.hpp | 1 - src/interfaces/generation_tracker.hpp | 3 ++- src/interfaces/scene.hpp | 1 - src/interfaces/status_manager.hpp | 1 - src/util/color.hpp | 1 + src/util/fs.cpp | 3 ++- src/util/ranges_impl.hpp | 1 - 30 files changed, 171 insertions(+), 122 deletions(-) (limited to 'src') diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 12f7369..368f2a8 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -1,37 +1,41 @@ #include "bootstrap.hpp" -// Interfaces -#include "interfaces/RLE_reader.hpp" -#include "interfaces/cell_helper.hpp" -#include "interfaces/component.hpp" -#include "interfaces/component_renderer.hpp" -#include "interfaces/cursor.hpp" -#include "interfaces/engine.hpp" -#include "interfaces/game.hpp" -#include "interfaces/generation_tracker.hpp" -#include "interfaces/input.hpp" -#include "interfaces/matrix.hpp" -#include "interfaces/scene.hpp" -#include "interfaces/status_manager.hpp" -#include "interfaces/statusline.hpp" +#include +#include +#include +#include -// Implementations -#include "engine/data/bounds.hpp" -#include "engine/data/vector2.hpp" #include "engine/engine.hpp" #include "engine/graphics/component_renderer.hpp" #include "engine/graphics/matrix.hpp" +#include "engine/graphics/matrix_impl.hpp" +#include "engine/graphics/matrix_iterator.hpp" +#include "engine/graphics/matrix_iterator_impl.hpp" #include "engine/graphics/scene.hpp" #include "engine/user/cursor.hpp" #include "engine/user/input.hpp" #include "game/RLE_reader.hpp" #include "game/cell_helper.hpp" +#include "game/cell_helper_impl.hpp" #include "game/components/statusline.hpp" #include "game/game.hpp" #include "game/generation_tracker.hpp" #include "game/status_manager.hpp" +#include "interfaces/RLE_reader.hpp" +#include "interfaces/cell_helper.hpp" +#include "interfaces/component.hpp" +#include "interfaces/component_renderer.hpp" +#include "interfaces/cursor.hpp" +#include "interfaces/engine.hpp" +#include "interfaces/game.hpp" +#include "interfaces/generation_tracker.hpp" +#include "interfaces/input.hpp" +#include "interfaces/matrix.hpp" +#include "interfaces/scene.hpp" +#include "interfaces/status_manager.hpp" +#include "interfaces/statusline.hpp" -#include +class Bounds; auto bootstrap() noexcept -> yacppdic::DIContainer { diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp index 21c6660..bee98ba 100644 --- a/src/engine/data/bounds.cpp +++ b/src/engine/data/bounds.cpp @@ -1,5 +1,7 @@ #include "bounds.hpp" +#include "engine/data/vector2.hpp" + Bounds::Bounds(const BoundsOptions &options) noexcept : _width(options.width), _height(options.height) { diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index b122489..2375d77 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -1,8 +1,10 @@ #pragma once +#include + #include "engine/data/vector2.hpp" -#include +class Vector2; enum CoordsValidation { diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index cb81947..84986bd 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -1,9 +1,10 @@ #include "vector2.hpp" -#include "util/hash.hpp" - +#include #include +#include "util/hash_impl.hpp" + auto Vector2::get_x() const noexcept -> Vector2::Value { return _x; diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index b83e924..03c2562 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index b0456a3..7f7c4c3 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1,13 +1,19 @@ #include "engine.hpp" -#include "util/function.hpp" - #include - +#include #include +#include #include #include #include +#include + +#include "interfaces/component.hpp" +#include "interfaces/cursor.hpp" +#include "interfaces/input.hpp" +#include "interfaces/scene.hpp" +#include "util/function_impl.hpp" CLIGameEngine::CLIGameEngine( IGameFactory game_factory, diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index 65d1a80..82bde16 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include + #include "interfaces/component_renderer.hpp" #include "interfaces/cursor.hpp" #include "interfaces/engine.hpp" @@ -7,10 +11,9 @@ #include "interfaces/input.hpp" #include "interfaces/scene.hpp" -#include - -#include -#include +class ICursorController; +class IScene; +class IUserInputObserver; constexpr auto MIN_TIME_SINCE_LAST_UPDATE_MILLIS = 15; diff --git a/src/engine/graphics/component_renderer.cpp b/src/engine/graphics/component_renderer.cpp index effe153..0584028 100644 --- a/src/engine/graphics/component_renderer.cpp +++ b/src/engine/graphics/component_renderer.cpp @@ -1,13 +1,20 @@ #include "component_renderer.hpp" -#include "engine/escape.hpp" -#include "util/color.hpp" - #include - #include +#include #include +#include "engine/data/style.hpp" +#include "engine/data/vector2.hpp" +#include "engine/escape.hpp" +#include "engine/graphics/matrix_iterator.hpp" +#include "engine/graphics/matrix_iterator_impl.hpp" +#include "interfaces/component.hpp" +#include "interfaces/cursor.hpp" +#include "interfaces/matrix.hpp" +#include "util/color.hpp" + ComponentRenderer::ComponentRenderer( std::shared_ptr cursor_controller) noexcept : _cursor_controller(std::move(cursor_controller)) diff --git a/src/engine/graphics/component_renderer.hpp b/src/engine/graphics/component_renderer.hpp index ff1bc47..4d21623 100644 --- a/src/engine/graphics/component_renderer.hpp +++ b/src/engine/graphics/component_renderer.hpp @@ -1,12 +1,15 @@ #pragma once +#include + +#include "engine/data/vector2.hpp" #include "interfaces/component.hpp" #include "interfaces/component_renderer.hpp" #include "interfaces/cursor.hpp" -#include "engine/data/vector2.hpp" - -#include +class IComponent; +class ICursorController; +class Vector2; constexpr auto SET_BOLD_MODE = "{esc}[1m"; diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index ff64edd..7c23c7d 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -1,13 +1,15 @@ #include "scene.hpp" -#include "engine/escape.hpp" -#include "util/color.hpp" - -#include #include - -#include #include +#include +#include +#include +#include + +#include "engine/escape.hpp" + +class IComponent; Scene::Scene(const IMatrixFactory &matrix_factory) noexcept : _matrix(matrix_factory(size())), _is_shown(false) diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 4df5f56..5b52027 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -1,19 +1,21 @@ #pragma once -#include "interfaces/component.hpp" -#include "interfaces/matrix.hpp" -#include "interfaces/scene.hpp" - -#include "engine/data/vector2.hpp" - #include -#include - #include #include #include #include #include +#include + +#include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" +#include "interfaces/component.hpp" +#include "interfaces/matrix.hpp" +#include "interfaces/scene.hpp" + +class IComponent; +struct termios; constexpr fmt::string_view ENABLE_ALT_BUFFER = "{esc}[?1049h"; constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; diff --git a/src/engine/main.cpp b/src/engine/main.cpp index b703218..8043c68 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -1,8 +1,9 @@ -#include "interfaces/engine.hpp" +#include +#include +#include #include "bootstrap.hpp" - -#include +#include "interfaces/engine.hpp" auto main() noexcept -> int { diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index a372ca7..5cd74a6 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -1,10 +1,9 @@ #include "cursor.hpp" -#include "engine/escape.hpp" - -#include #include +#include "engine/escape.hpp" + CursorController::CursorController() noexcept : _position({.x = 0, .y = 0}), _bounds({0, 0}) { diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index 06c6b88..ff7e89f 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -2,16 +2,16 @@ #include "interfaces/cursor.hpp" -#include "engine/data/bounds.hpp" -#include "engine/data/vector2.hpp" - +#include #include -#include - #include #include #include #include +#include + +#include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" constexpr std::string_view MOVE_CURSOR_UP = "{esc}[{amount}A"; constexpr std::string_view MOVE_CURSOR_DOWN = "{esc}[{amount}B"; @@ -39,8 +39,10 @@ class CursorController : public ICursorController, public: CursorController() noexcept; - void move(const Vector2 &direction, const std::uint32_t &amount, bool flush_cout) noexcept - override; + void move( + const Vector2 &direction, + const std::uint32_t &amount, + bool flush_cout) noexcept override; void move_to(const Vector2 &position, bool flush_cout) noexcept override; diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp index f0ffbe5..505a0fa 100644 --- a/src/engine/user/input.cpp +++ b/src/engine/user/input.cpp @@ -1,11 +1,10 @@ #include "input.hpp" -#include "engine/keycodes.hpp" - #include -#include #include +#include "engine/keycodes.hpp" + const std::unordered_map special_keys_map = { {'A', keycodes::UP_ARROW}, {'B', keycodes::DOWN_ARROW}, diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index 12c27ee..9e8196d 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -2,11 +2,10 @@ #include "interfaces/input.hpp" -#include - #include #include #include +#include class UserInputObserver : public IUserInputObserver, diff --git a/src/game/RLE_reader.cpp b/src/game/RLE_reader.cpp index f971966..df2823c 100644 --- a/src/game/RLE_reader.cpp +++ b/src/game/RLE_reader.cpp @@ -1,20 +1,16 @@ #include "RLE_reader.hpp" -#include "engine/data/bounds.hpp" -#include "engine/data/vector2.hpp" -#include "errors/RLE_reader.hpp" -#include "util/algorithm.hpp" -#include "util/io.hpp" -#include "util/string.hpp" - #include - #include -#include #include #include -#include +#include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" +#include "errors/RLE_reader.hpp" +#include "util/algorithm_impl.hpp" +#include "util/io_impl.hpp" +#include "util/string_impl.hpp" RLEReader::RLEReader(const IMatrixFactory &matrix_factory) noexcept : _matrix_factory(matrix_factory) diff --git a/src/game/components/statusline.cpp b/src/game/components/statusline.cpp index c2fe7ea..aac1c27 100644 --- a/src/game/components/statusline.cpp +++ b/src/game/components/statusline.cpp @@ -1,14 +1,13 @@ #include "statusline.hpp" -#include "engine/data/bounds.hpp" -#include "engine/data/vector2.hpp" -#include "util/color.hpp" -#include "util/ranges.hpp" - #include - #include +#include "engine/data/vector2.hpp" +#include "interfaces/matrix.hpp" +#include "util/ranges.hpp" +#include "util/ranges_impl.hpp" + StatusLine::StatusLine(std::shared_ptr component_matrix) noexcept : _component_matrix(std::move(component_matrix)), _need_render(false) { diff --git a/src/game/components/statusline.hpp b/src/game/components/statusline.hpp index 4451fde..a6742c9 100644 --- a/src/game/components/statusline.hpp +++ b/src/game/components/statusline.hpp @@ -1,14 +1,17 @@ #pragma once -#include "interfaces/matrix.hpp" -#include "interfaces/statusline.hpp" +#include +#include +#include +#include #include "engine/data/style.hpp" #include "engine/data/vector2.hpp" +#include "interfaces/component.hpp" +#include "interfaces/matrix.hpp" +#include "interfaces/statusline.hpp" -#include -#include -#include +class Vector2; constexpr std::uint32_t STATUSLINE_COLOR = 0x1A1A1AU; @@ -32,7 +35,8 @@ public: const std::string_view &status, std::int32_t start) noexcept override; - void set_section_length(StatusLineSection section, std::int32_t length) noexcept override; + void + set_section_length(StatusLineSection section, std::int32_t length) noexcept override; void set_section_style(StatusLineSection section, const Style &style) noexcept override; diff --git a/src/game/game.cpp b/src/game/game.cpp index 921f21d..a121089 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,24 +1,33 @@ #include "game.hpp" -#include "engine/data/bounds.hpp" -#include "engine/escape.hpp" -#include "engine/keycodes.hpp" -#include "errors/RLE_reader.hpp" -#include "errors/io.hpp" -#include "util/algorithm.hpp" -#include "util/fs.hpp" -#include "util/string.hpp" - #include #include - -#include +#include +#include #include #include #include +#include #include #include +#include "engine/data/bounds.hpp" +#include "engine/escape.hpp" +#include "engine/graphics/matrix_iterator.hpp" +#include "engine/graphics/matrix_iterator_impl.hpp" +#include "engine/keycodes.hpp" +#include "errors/RLE_reader.hpp" +#include "errors/io.hpp" +#include "interfaces/RLE_reader.hpp" +#include "interfaces/cell_helper.hpp" +#include "interfaces/generation_tracker.hpp" +#include "interfaces/input.hpp" +#include "interfaces/matrix.hpp" +#include "interfaces/status_manager.hpp" +#include "util/algorithm_impl.hpp" +#include "util/fs.hpp" +#include "util/string_impl.hpp" + Game::Game( IStatusLineFactory statusline_factory, std::shared_ptr scene, diff --git a/src/game/game.hpp b/src/game/game.hpp index da1ba11..13e229e 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -1,5 +1,18 @@ #pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "engine/data/vector2.hpp" #include "interfaces/RLE_reader.hpp" #include "interfaces/cell_helper.hpp" #include "interfaces/cursor.hpp" @@ -11,17 +24,13 @@ #include "interfaces/status_manager.hpp" #include "interfaces/statusline.hpp" -#include "engine/data/vector2.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include +class ICellHelper; +class IGenerationTracker; +class IRLEReader; +class IStatusManager; +class IUserInputObserver; +template +class IMatrix; constexpr auto DEFAULT_GENERATIONS_PER_SECOND = 5L; diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp index fd56627..a174680 100644 --- a/src/game/status_manager.cpp +++ b/src/game/status_manager.cpp @@ -1,9 +1,7 @@ #include "status_manager.hpp" #include - #include -#include void StatusManager::bind(const std::shared_ptr &statusline) noexcept { diff --git a/src/game/status_manager.hpp b/src/game/status_manager.hpp index b170cf9..e9f2d15 100644 --- a/src/game/status_manager.hpp +++ b/src/game/status_manager.hpp @@ -1,13 +1,15 @@ #pragma once #include "interfaces/status_manager.hpp" -#include "interfaces/statusline.hpp" - -#include +#include #include #include #include +#include +#include + +#include "interfaces/statusline.hpp" class StatusManager : public IStatusManager, public yacppdic::AutoWirable diff --git a/src/interfaces/RLE_reader.hpp b/src/interfaces/RLE_reader.hpp index a3266a8..9cc6722 100644 --- a/src/interfaces/RLE_reader.hpp +++ b/src/interfaces/RLE_reader.hpp @@ -16,4 +16,3 @@ public: [[nodiscard]] virtual auto read_RLE_file(const std::filesystem::path &path) const -> std::unique_ptr> = 0; }; - diff --git a/src/interfaces/generation_tracker.hpp b/src/interfaces/generation_tracker.hpp index 5f9bd13..291fbbc 100644 --- a/src/interfaces/generation_tracker.hpp +++ b/src/interfaces/generation_tracker.hpp @@ -11,7 +11,8 @@ class IGenerationTracker public: virtual ~IGenerationTracker() noexcept = default; - [[nodiscard]] virtual auto get_current_generation() const noexcept -> std::uint32_t = 0; + [[nodiscard]] virtual auto get_current_generation() const noexcept + -> std::uint32_t = 0; virtual void set_current_generation(std::uint32_t current_generation) noexcept = 0; diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index b7bb97d..d43a8e2 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -36,4 +36,3 @@ public: [[nodiscard]] virtual auto get_components() const noexcept -> std::vector, Vector2>> = 0; }; - diff --git a/src/interfaces/status_manager.hpp b/src/interfaces/status_manager.hpp index 7744eb6..29750d6 100644 --- a/src/interfaces/status_manager.hpp +++ b/src/interfaces/status_manager.hpp @@ -21,4 +21,3 @@ public: const StatusLineSection §ion, const std::string_view &body) noexcept = 0; }; - diff --git a/src/util/color.hpp b/src/util/color.hpp index 2bb147c..d209b36 100644 --- a/src/util/color.hpp +++ b/src/util/color.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/src/util/fs.cpp b/src/util/fs.cpp index 68c3dd9..87e3cc0 100644 --- a/src/util/fs.cpp +++ b/src/util/fs.cpp @@ -1,8 +1,9 @@ #include "fs.hpp" -#include #include #include +#include +#include auto get_current_user_home_path() noexcept -> std::filesystem::path { diff --git a/src/util/ranges_impl.hpp b/src/util/ranges_impl.hpp index b18a11c..1f1a577 100644 --- a/src/util/ranges_impl.hpp +++ b/src/util/ranges_impl.hpp @@ -57,4 +57,3 @@ IOTA_VIEW(auto)::end() const noexcept -> IotaViewIterator { return IotaViewIterator(_bound); } - -- cgit v1.2.3-18-g5258