aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-23 19:46:11 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:59 +0200
commit4b8db1ab0ae53bd8f6685af2fb55a550c04f8199 (patch)
tree334bc2d5c0287a9317e3e18f69f5cc9bf06711cb
parentc9297a82291882e4043ae5e0de2e631940e96b52 (diff)
refactor: use char as matrix element in scene
-rw-r--r--src/bootstrap.cpp6
-rw-r--r--src/engine/graphics/scene.cpp7
-rw-r--r--src/engine/graphics/scene.hpp6
-rw-r--r--src/interfaces/scene.hpp4
4 files changed, 12 insertions, 11 deletions
diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp
index ef54940..02ec92d 100644
--- a/src/bootstrap.cpp
+++ b/src/bootstrap.cpp
@@ -76,16 +76,16 @@ auto bootstrap() noexcept -> yacppdic::Container
return std::make_unique<RandomNumberGenerator>(seed);
});
- container.bind<IMatrixFactory<std::string_view>>().to_factory(
+ container.bind<IMatrixFactory<char>>().to_factory(
[](const Bounds &bounds)
{
- return std::make_unique<Matrix<std::string_view>>(bounds);
+ return std::make_unique<Matrix<char>>(bounds);
});
container.bind<ISceneFactory>().to_factory(
[&container](const std::shared_ptr<ICursorController> &cursor_controller)
{
- auto matrix_factory = container.get<IMatrixFactory<std::string_view>>();
+ auto matrix_factory = container.get<IMatrixFactory<Scene::MatrixElement>>();
return std::make_unique<Scene>(matrix_factory, cursor_controller);
});
diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp
index b0d77b8..7a0e960 100644
--- a/src/engine/graphics/scene.cpp
+++ b/src/engine/graphics/scene.cpp
@@ -11,13 +11,13 @@
#include <utility>
Scene::Scene(
- IMatrixFactory<std::string_view> matrix_factory,
+ IMatrixFactory<MatrixElement> matrix_factory,
std::shared_ptr<ICursorController> cursor_controller) noexcept
: _matrix(matrix_factory(size() - Bounds({.width = 0U, .height = 1U}))),
_cursor_controller(std::move(cursor_controller)),
_is_shown(false)
{
- _matrix->fill(" ");
+ _matrix->fill(' ');
}
void Scene::enter() noexcept
@@ -80,8 +80,7 @@ auto Scene::size() const noexcept -> Bounds
return Bounds({window_size.ws_col, window_size.ws_row});
}
-auto Scene::get_matrix() const noexcept
- -> const std::shared_ptr<IMatrix<std::string_view>> &
+auto Scene::get_matrix() const noexcept -> const std::shared_ptr<IMatrix<MatrixElement>> &
{
return _matrix;
}
diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp
index e57e1f8..60b541a 100644
--- a/src/engine/graphics/scene.hpp
+++ b/src/engine/graphics/scene.hpp
@@ -17,7 +17,7 @@ class Scene : public IScene
{
public:
explicit Scene(
- IMatrixFactory<std::string_view> matrix_factory,
+ IMatrixFactory<MatrixElement> matrix_factory,
std::shared_ptr<ICursorController> cursor_controller) noexcept;
void enter() noexcept override;
@@ -27,10 +27,10 @@ public:
[[nodiscard]] auto size() const noexcept -> Bounds override;
[[nodiscard]] auto get_matrix() const noexcept
- -> const std::shared_ptr<IMatrix<std::string_view>> & override;
+ -> const std::shared_ptr<IMatrix<MatrixElement>> & override;
private:
- std::shared_ptr<IMatrix<std::string_view>> _matrix;
+ std::shared_ptr<IMatrix<MatrixElement>> _matrix;
std::shared_ptr<ICursorController> _cursor_controller;
bool _is_shown;
diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp
index 08615a9..903a299 100644
--- a/src/interfaces/scene.hpp
+++ b/src/interfaces/scene.hpp
@@ -16,6 +16,8 @@ class IScene
public:
virtual ~IScene() noexcept = default;
+ using MatrixElement = char;
+
virtual void enter() noexcept = 0;
virtual void leave() noexcept = 0;
@@ -23,7 +25,7 @@ public:
[[nodiscard]] virtual auto size() const noexcept -> Bounds = 0;
[[nodiscard]] virtual auto get_matrix() const noexcept
- -> const std::shared_ptr<IMatrix<std::string_view>> & = 0;
+ -> const std::shared_ptr<IMatrix<MatrixElement>> & = 0;
};
using ISceneFactory = yacppdic::Factory<std::unique_ptr<IScene>(