From 2bff8c999edde11270ecaf6fbd2d24f54d0e360b Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 29 Jun 2022 22:15:36 +0200 Subject: refactor: cell helper take matrix as shared pointer --- src/bootstrap.cpp | 4 ++-- src/game/cell_helper.hpp | 4 ++-- src/game/cell_helper_impl.hpp | 11 ++++++----- src/interfaces/cell_helper.hpp | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 368f2a8..b8649ec 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -73,7 +73,7 @@ auto bootstrap() noexcept -> yacppdic::DIContainer generation_tracker, status_manager, user_input_observer, - cell_helper_factory(*(scene->get_matrix())), + cell_helper_factory(scene->get_matrix()), rle_reader); }); @@ -105,7 +105,7 @@ auto bootstrap() noexcept -> yacppdic::DIContainer }); di_container.bind>().to_factory( - [](const IMatrix &matrix) + [](const std::shared_ptr> &matrix) { return std::make_unique>(matrix); }); diff --git a/src/game/cell_helper.hpp b/src/game/cell_helper.hpp index ee5ab27..cf84a75 100644 --- a/src/game/cell_helper.hpp +++ b/src/game/cell_helper.hpp @@ -13,7 +13,7 @@ template class CellHelper : public ICellHelper { public: - explicit CellHelper(const IMatrix &matrix) noexcept; + explicit CellHelper(std::shared_ptr> matrix) noexcept; [[nodiscard]] auto is_cell_dying(const Vector2 &cell_pos) const noexcept -> bool override; @@ -26,7 +26,7 @@ public: -> std::vector override; private: - const IMatrix &_matrix; + std::shared_ptr> _matrix; static auto _get_position_neighbours(const Vector2 &position) noexcept -> std::list; diff --git a/src/game/cell_helper_impl.hpp b/src/game/cell_helper_impl.hpp index b7da413..bd40794 100644 --- a/src/game/cell_helper_impl.hpp +++ b/src/game/cell_helper_impl.hpp @@ -6,18 +6,19 @@ template constexpr auto has_matrix_value( - const IMatrix &matrix, + const std::shared_ptr> &matrix, const MatrixElement &value) noexcept { return [&matrix, &value](const Vector2 &pos) { - return matrix.get(pos) == value; + return matrix->get(pos) == value; }; } template -CellHelper::CellHelper(const IMatrix &matrix) noexcept - : _matrix(matrix) +CellHelper::CellHelper( + std::shared_ptr> matrix) noexcept + : _matrix(std::move(matrix)) { } @@ -75,7 +76,7 @@ auto CellHelper::find_neighbours(const Vector2 &cell_pos) const n std::vector cell_positions = {}; const auto matrix_size = - Bounds({.width = _matrix.get_column_cnt(), .height = _matrix.get_row_cnt()}); + Bounds({.width = _matrix->get_column_cnt(), .height = _matrix->get_row_cnt()}); const auto neighbours = _get_position_neighbours(cell_pos); diff --git a/src/interfaces/cell_helper.hpp b/src/interfaces/cell_helper.hpp index d814aa7..69bf8b0 100644 --- a/src/interfaces/cell_helper.hpp +++ b/src/interfaces/cell_helper.hpp @@ -28,5 +28,5 @@ public: }; template -using ICellHelperFactory = - yacppdic::Factory(const IMatrix &matrix)>; +using ICellHelperFactory = yacppdic::Factory( + const std::shared_ptr> &matrix)>; -- cgit v1.2.3-18-g5258