aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-29 22:15:36 +0200
committerHampusM <hampus@hampusmat.com>2022-06-29 22:27:36 +0200
commit2bff8c999edde11270ecaf6fbd2d24f54d0e360b (patch)
tree7f879bdd592ba972b195e7fe55bb637f1b3c00b1 /src/game
parentd02d46d27982a8e351736067ab9787f87052b989 (diff)
refactor: cell helper take matrix as shared pointer
Diffstat (limited to 'src/game')
-rw-r--r--src/game/cell_helper.hpp4
-rw-r--r--src/game/cell_helper_impl.hpp11
2 files changed, 8 insertions, 7 deletions
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 <typename MatrixElement>
class CellHelper : public ICellHelper
{
public:
- explicit CellHelper(const IMatrix<MatrixElement> &matrix) noexcept;
+ explicit CellHelper(std::shared_ptr<IMatrix<MatrixElement>> matrix) noexcept;
[[nodiscard]] auto is_cell_dying(const Vector2 &cell_pos) const noexcept
-> bool override;
@@ -26,7 +26,7 @@ public:
-> std::vector<Vector2> override;
private:
- const IMatrix<MatrixElement> &_matrix;
+ std::shared_ptr<IMatrix<MatrixElement>> _matrix;
static auto _get_position_neighbours(const Vector2 &position) noexcept
-> std::list<Vector2>;
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 <typename MatrixElement>
constexpr auto has_matrix_value(
- const IMatrix<MatrixElement> &matrix,
+ const std::shared_ptr<IMatrix<MatrixElement>> &matrix,
const MatrixElement &value) noexcept
{
return [&matrix, &value](const Vector2 &pos)
{
- return matrix.get(pos) == value;
+ return matrix->get(pos) == value;
};
}
template <typename MatrixElement>
-CellHelper<MatrixElement>::CellHelper(const IMatrix<MatrixElement> &matrix) noexcept
- : _matrix(matrix)
+CellHelper<MatrixElement>::CellHelper(
+ std::shared_ptr<IMatrix<MatrixElement>> matrix) noexcept
+ : _matrix(std::move(matrix))
{
}
@@ -75,7 +76,7 @@ auto CellHelper<MatrixElement>::find_neighbours(const Vector2 &cell_pos) const n
std::vector<Vector2> 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);