aboutsummaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/data/bounds.hpp3
-rw-r--r--src/engine/data/vector2.cpp6
-rw-r--r--src/engine/data/vector2.hpp13
-rw-r--r--src/engine/engine.cpp20
-rw-r--r--src/engine/engine.hpp27
-rw-r--r--src/engine/graphics/scene.cpp13
-rw-r--r--src/engine/graphics/scene.hpp12
-rw-r--r--src/engine/graphics/window.cpp2
-rw-r--r--src/engine/matrix_iterator.tpp12
-rw-r--r--src/engine/user/cursor.cpp29
-rw-r--r--src/engine/user/cursor.hpp14
-rw-r--r--src/engine/user/input.cpp8
-rw-r--r--src/engine/user/input.hpp16
13 files changed, 107 insertions, 68 deletions
diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp
index 5444503..731db5c 100644
--- a/src/engine/data/bounds.hpp
+++ b/src/engine/data/bounds.hpp
@@ -34,7 +34,8 @@ public:
void set_height(Value height) noexcept;
- [[nodiscard]] auto validate_coords(const Vector2 &coords) const noexcept -> CoordsValidation;
+ [[nodiscard]] auto validate_coords(const Vector2 &coords) const noexcept
+ -> CoordsValidation;
auto operator*=(const Bounds &rhs) noexcept -> const Bounds &;
auto operator+=(const Bounds &rhs) noexcept -> const Bounds &;
diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp
index 0554930..6d8ebad 100644
--- a/src/engine/data/vector2.cpp
+++ b/src/engine/data/vector2.cpp
@@ -22,10 +22,10 @@ void Vector2::set_y(Vector2::Value y) noexcept
_y = y;
}
-auto Vector2::to_direction(const Vector2 &direction,
- Vector2::Value amount) const noexcept -> Vector2
+auto Vector2::to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept
+ -> Vector2
{
- return *this + (direction * Vector2({.x = amount, .y = amount}));
+ return *this + (direction * Vector2({ .x = amount, .y = amount }));
}
auto Vector2::operator+=(const Vector2 &rhs) noexcept -> const Vector2 &
diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp
index 95baf1c..a6de35e 100644
--- a/src/engine/data/vector2.hpp
+++ b/src/engine/data/vector2.hpp
@@ -30,8 +30,9 @@ public:
void set_y(Value y) noexcept;
- [[nodiscard]] auto to_direction(const Vector2 &direction,
- Vector2::Value amount) const noexcept -> Vector2;
+ [[nodiscard]] auto
+ to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept
+ -> Vector2;
auto operator+=(const Vector2 &rhs) noexcept -> const Vector2 &;
auto operator-=(const Vector2 &rhs) noexcept -> const Vector2 &;
@@ -47,7 +48,7 @@ public:
*/
static constexpr auto up() noexcept -> Vector2
{
- return Vector2({.x = 0, .y = -1});
+ return Vector2({ .x = 0, .y = -1 });
}
/**
@@ -55,7 +56,7 @@ public:
*/
static constexpr auto down() noexcept -> Vector2
{
- return Vector2({.x = 0, .y = 1});
+ return Vector2({ .x = 0, .y = 1 });
}
/**
@@ -64,7 +65,7 @@ public:
static constexpr auto left() noexcept -> Vector2
{
- return Vector2({.x = -1, .y = 0});
+ return Vector2({ .x = -1, .y = 0 });
}
/**
@@ -72,7 +73,7 @@ public:
*/
static constexpr auto right() noexcept -> Vector2
{
- return Vector2({.x = 1, .y = 0});
+ return Vector2({ .x = 1, .y = 0 });
}
private:
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp
index a05fed9..3bf8503 100644
--- a/src/engine/engine.cpp
+++ b/src/engine/engine.cpp
@@ -5,10 +5,13 @@
#include <thread>
#include <utility>
-CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory,
- std::shared_ptr<IInputHandler> input_handler,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept
+CLIGameEngine::CLIGameEngine(
+ IGameFactory game_factory,
+ ISceneFactory scene_factory,
+ std::shared_ptr<IInputHandler> input_handler,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+) noexcept
: _game_factory(std::move(game_factory)),
_scene_factory(std::move(scene_factory)),
_input_handler(std::move(input_handler)),
@@ -35,7 +38,8 @@ void CLIGameEngine::start() noexcept
_input_handler->leave_raw_mode();
game->on_exit();
- }));
+ }
+ ));
_configure_input(game->get_input_config());
@@ -43,7 +47,8 @@ void CLIGameEngine::start() noexcept
[this]()
{
_input_handler->listen();
- }));
+ }
+ ));
while (true)
{
@@ -52,7 +57,8 @@ void CLIGameEngine::start() noexcept
}
void CLIGameEngine::_configure_input(
- const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept
+ const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config
+) noexcept
{
for (const auto &config_pair : input_config)
{
diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp
index 32afa56..c13245f 100644
--- a/src/engine/engine.hpp
+++ b/src/engine/engine.hpp
@@ -12,16 +12,24 @@
#include <memory>
#include <unordered_map>
-class CLIGameEngine
- : public ICLIGameEngine,
- public AutoWirable<ICLIGameEngine, CLIGameEngine, IGameFactory, ISceneFactory,
- IInputHandler, ICursorController, IWindow>
+class CLIGameEngine : public ICLIGameEngine,
+ public AutoWirable<
+ ICLIGameEngine,
+ CLIGameEngine,
+ IGameFactory,
+ ISceneFactory,
+ IInputHandler,
+ ICursorController,
+ IWindow>
{
public:
- CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory,
- std::shared_ptr<IInputHandler> input_handler,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept;
+ CLIGameEngine(
+ IGameFactory game_factory,
+ ISceneFactory scene_factory,
+ std::shared_ptr<IInputHandler> input_handler,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+ ) noexcept;
void start() noexcept override;
@@ -34,5 +42,6 @@ private:
std::shared_ptr<IWindow> _window;
void _configure_input(
- const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept;
+ const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config
+ ) noexcept;
};
diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp
index c27a6d5..d5cf89b 100644
--- a/src/engine/graphics/scene.cpp
+++ b/src/engine/graphics/scene.cpp
@@ -8,11 +8,13 @@
#include <iostream>
#include <utility>
-Scene::Scene(IMatrixFactory<std::string_view> matrix_factory,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept
+Scene::Scene(
+ IMatrixFactory<std::string_view> matrix_factory,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+) noexcept
: _is_shown(false),
- _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))),
+ _matrix(matrix_factory(window->size() - Bounds({ .width = 0U, .height = 1U }))),
_cursor_controller(std::move(cursor_controller)),
_window(std::move(window))
{
@@ -45,7 +47,8 @@ void Scene::leave() noexcept
_is_shown = false;
}
-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<std::string_view>> &
{
return _matrix;
}
diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp
index 3dcaa2d..aaf0095 100644
--- a/src/engine/graphics/scene.hpp
+++ b/src/engine/graphics/scene.hpp
@@ -15,16 +15,18 @@ constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l";
class Scene : public IScene
{
public:
- explicit Scene(IMatrixFactory<std::string_view> matrix_factory,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept;
+ explicit Scene(
+ IMatrixFactory<std::string_view> matrix_factory,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+ ) noexcept;
void enter() noexcept override;
void leave() noexcept override;
- [[nodiscard]] auto
- get_matrix() const noexcept -> const std::shared_ptr<IMatrix<std::string_view>> & override;
+ [[nodiscard]] auto get_matrix() const noexcept
+ -> const std::shared_ptr<IMatrix<std::string_view>> & override;
private:
bool _is_shown;
diff --git a/src/engine/graphics/window.cpp b/src/engine/graphics/window.cpp
index bb33402..2d880fc 100644
--- a/src/engine/graphics/window.cpp
+++ b/src/engine/graphics/window.cpp
@@ -9,5 +9,5 @@ auto Window::size() const noexcept -> Bounds
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
ioctl(0, TIOCGWINSZ, &window_size);
- return Bounds({window_size.ws_col, window_size.ws_row});
+ return Bounds({ window_size.ws_col, window_size.ws_row });
}
diff --git a/src/engine/matrix_iterator.tpp b/src/engine/matrix_iterator.tpp
index 031136c..9697861 100644
--- a/src/engine/matrix_iterator.tpp
+++ b/src/engine/matrix_iterator.tpp
@@ -35,13 +35,15 @@ auto MatrixRowIterator<Element>::operator*() const noexcept -> Element &
}
template <typename Element>
-auto MatrixRowIterator<Element>::operator==(const MatrixRowIterator &rhs) const noexcept -> bool
+auto MatrixRowIterator<Element>::operator==(const MatrixRowIterator &rhs) const noexcept
+ -> bool
{
return _column_ptr == rhs._column_ptr;
}
template <typename Element>
-auto MatrixRowIterator<Element>::operator!=(const MatrixRowIterator &rhs) const noexcept -> bool
+auto MatrixRowIterator<Element>::operator!=(const MatrixRowIterator &rhs) const noexcept
+ -> bool
{
return _column_ptr != rhs._column_ptr;
}
@@ -69,8 +71,10 @@ auto MatrixRow<Element>::end() const noexcept -> MatrixRowIterator<Element>
// Matrix iterator
template <typename Element>
-MatrixIterator<Element>::MatrixIterator(RowPtr row_ptr,
- const uint32_t &column_cnt) noexcept
+MatrixIterator<Element>::MatrixIterator(
+ RowPtr row_ptr,
+ const uint32_t &column_cnt
+) noexcept
: _row_ptr(row_ptr), _column_cnt(column_cnt)
{
}
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp
index 2b240b9..71f02da 100644
--- a/src/engine/user/cursor.cpp
+++ b/src/engine/user/cursor.cpp
@@ -5,14 +5,17 @@
#include <cstdlib>
#include <iostream>
-CursorController::CursorController() noexcept : _position({.x = 0, .y = 0}) {}
+CursorController::CursorController() noexcept : _position({ .x = 0, .y = 0 }) {}
void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept
{
auto direction_format = direction_format_map.at(direction);
- fmt::print(fmt::runtime(direction_format.data()), fmt::arg("esc", ESC),
- fmt::arg("amount", amount));
+ fmt::print(
+ fmt::runtime(direction_format.data()),
+ fmt::arg("esc", ESC),
+ fmt::arg("amount", amount)
+ );
std::cout.flush();
_position = _position.to_direction(direction, static_cast<Vector2::Value>(amount));
@@ -22,8 +25,12 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no
void CursorController::move_to(const Vector2 &position, bool silent) noexcept
{
- fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", position.get_y()),
- fmt::arg("column", position.get_x()));
+ fmt::print(
+ MOVE_CURSOR_TO,
+ fmt::arg("esc", ESC),
+ fmt::arg("row", position.get_y()),
+ fmt::arg("column", position.get_x())
+ );
std::cout.flush();
_position = position;
@@ -66,19 +73,21 @@ void CursorController::show() noexcept
std::cout.flush();
}
-void CursorController::subscribe(const Event &event,
- const Subscriber &subscriber) noexcept
+void CursorController::subscribe(
+ const Event &event,
+ const Subscriber &subscriber
+) noexcept
{
if (_subscribers.count(event) == 0)
{
- _subscribers.insert({event, std::vector<Subscriber>()});
+ _subscribers.insert({ event, std::vector<Subscriber>() });
}
_subscribers.at(event).push_back(subscriber);
}
-void CursorController::notify_subscribers(const Event &event,
- const Context &context) const noexcept
+void CursorController::notify_subscribers(const Event &event, const Context &context)
+ const noexcept
{
if (_subscribers.count(event) == 0)
{
diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp
index fcdfd3b..9d614f1 100644
--- a/src/engine/user/cursor.hpp
+++ b/src/engine/user/cursor.hpp
@@ -23,11 +23,11 @@ constexpr fmt::string_view REQUEST_CURSOR_POSITION = "{esc}[6n";
constexpr fmt::string_view CURSOR_VISIBLE = "{esc}[?25h";
constexpr fmt::string_view CURSOR_INVISIBLE = "{esc}[?25l";
-const std::unordered_map<Vector2, std::string_view, Vector2Hasher> direction_format_map =
- {{Vector2::up(), MOVE_CURSOR_UP},
- {Vector2::down(), MOVE_CURSOR_DOWN},
- {Vector2::left(), MOVE_CURSOR_LEFT},
- {Vector2::right(), MOVE_CURSOR_RIGHT}};
+const std::unordered_map<Vector2, std::string_view, Vector2Hasher>
+ direction_format_map = { { Vector2::up(), MOVE_CURSOR_UP },
+ { Vector2::down(), MOVE_CURSOR_DOWN },
+ { Vector2::left(), MOVE_CURSOR_LEFT },
+ { Vector2::right(), MOVE_CURSOR_RIGHT } };
class CursorController : public ICursorController,
public AutoWirable<ICursorController, CursorController>
@@ -49,8 +49,8 @@ public:
void subscribe(const Event &event, const Subscriber &subscriber) noexcept override;
- void notify_subscribers(const Event &event,
- const Context &context) const noexcept override;
+ void notify_subscribers(const Event &event, const Context &context)
+ const noexcept override;
private:
Vector2 _position;
diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp
index 1d6bc09..d335fc9 100644
--- a/src/engine/user/input.cpp
+++ b/src/engine/user/input.cpp
@@ -14,15 +14,17 @@ void InputHandler::listen() const noexcept
}
void InputHandler::subscribe(
- const Event &event, const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept
+ const Event &event,
+ const std::shared_ptr<ISubscriber<Context>> &subscriber
+) noexcept
{
auto event_index = _event_as_index(event);
_subscribers.at(event_index).push_back(subscriber);
}
-void InputHandler::notify_subscribers(const Event &event,
- const Context &context) const noexcept
+void InputHandler::notify_subscribers(const Event &event, const Context &context)
+ const noexcept
{
auto event_index = _event_as_index(event);
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp
index 410f3a6..6a7bf26 100644
--- a/src/engine/user/input.hpp
+++ b/src/engine/user/input.hpp
@@ -17,20 +17,22 @@ public:
void listen() const noexcept override;
- void
- subscribe(const Event &event,
- const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override;
+ void subscribe(
+ const Event &event,
+ const std::shared_ptr<ISubscriber<Context>> &subscriber
+ ) noexcept override;
- void notify_subscribers(const Event &event,
- const Context &context) const noexcept override;
+ void notify_subscribers(const Event &event, const Context &context)
+ const noexcept override;
void enter_raw_mode() noexcept override;
void leave_raw_mode() noexcept override;
private:
- std::array<std::vector<std::shared_ptr<ISubscriber<Context>>>,
- static_cast<std::size_t>(CHAR_MAX * 2U)>
+ std::array<
+ std::vector<std::shared_ptr<ISubscriber<Context>>>,
+ static_cast<std::size_t>(CHAR_MAX * 2U)>
_subscribers;
std::shared_ptr<termios> _original_termios = nullptr;