aboutsummaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-23 18:12:39 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:59 +0200
commit18e1db1fb8692752f64d3912c3b5ff1818be9028 (patch)
tree38ccd9b4f29e5b2fa0fc07f84b425aa80378301a /src/engine
parent65ca89da7933b5927e31ca6f29f28a24b2838ebe (diff)
refactor: replace last subscriber patterned code
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/engine.hpp1
-rw-r--r--src/engine/graphics/statusline.cpp4
-rw-r--r--src/engine/user/cursor.cpp37
-rw-r--r--src/engine/user/cursor.hpp9
-rw-r--r--src/engine/user/input.hpp1
5 files changed, 4 insertions, 48 deletions
diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp
index b34ea2b..4fb4707 100644
--- a/src/engine/engine.hpp
+++ b/src/engine/engine.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "interfaces/command.hpp"
#include "interfaces/cursor.hpp"
#include "interfaces/engine.hpp"
#include "interfaces/game.hpp"
diff --git a/src/engine/graphics/statusline.cpp b/src/engine/graphics/statusline.cpp
index 52edd8f..a8d0f3b 100644
--- a/src/engine/graphics/statusline.cpp
+++ b/src/engine/graphics/statusline.cpp
@@ -64,14 +64,14 @@ auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2
auto scene_height = static_cast<Vector2::Value>(scene_size.get_height());
- _cursor_controller->move_to(Vector2({.x = x, .y = scene_height}), true);
+ _cursor_controller->move_to(Vector2({.x = x, .y = scene_height}));
return previous_position;
}
void StatusLine::_move_back(Vector2 previous_position) noexcept
{
- _cursor_controller->move_to(previous_position, true);
+ _cursor_controller->move_to(previous_position);
_cursor_controller->show();
}
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp
index 945433b..97e9104 100644
--- a/src/engine/user/cursor.cpp
+++ b/src/engine/user/cursor.cpp
@@ -18,11 +18,9 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no
std::cout.flush();
_position = _position.to_direction(direction, static_cast<Vector2::Value>(amount));
-
- notify_subscribers(CursorEvent::POSITION_CHANGE, _position);
}
-void CursorController::move_to(const Vector2 &position, bool silent) noexcept
+void CursorController::move_to(const Vector2 &position) noexcept
{
fmt::print(
MOVE_CURSOR_TO,
@@ -32,11 +30,6 @@ void CursorController::move_to(const Vector2 &position, bool silent) noexcept
std::cout.flush();
_position = position;
-
- if (!silent)
- {
- notify_subscribers(CursorEvent::POSITION_CHANGE, position);
- }
}
auto CursorController::where() const noexcept -> Vector2
@@ -55,8 +48,6 @@ void CursorController::ensure_position() noexcept
scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x);
_position = Vector2(vector2_options);
-
- notify_subscribers(CursorEvent::POSITION_CHANGE, _position);
}
void CursorController::hide() noexcept
@@ -70,29 +61,3 @@ void CursorController::show() noexcept
fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC));
std::cout.flush();
}
-
-void CursorController::subscribe(
- const Event &event,
- const Subscriber &subscriber) noexcept
-{
- if (_subscribers.count(event) == 0)
- {
- _subscribers.insert({event, std::vector<Subscriber>()});
- }
-
- _subscribers.at(event).push_back(subscriber);
-}
-
-void CursorController::notify_subscribers(const Event &event, const Context &context)
- const noexcept
-{
- if (_subscribers.count(event) == 0)
- {
- return;
- }
-
- for (const auto &subscriber : _subscribers.at(event))
- {
- subscriber->update(context);
- }
-}
diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp
index ae6fe3c..de8c3ae 100644
--- a/src/engine/user/cursor.hpp
+++ b/src/engine/user/cursor.hpp
@@ -38,7 +38,7 @@ public:
void move(const Vector2 &direction, const uint32_t &amount) noexcept override;
- void move_to(const Vector2 &position, bool silent) noexcept override;
+ void move_to(const Vector2 &position) noexcept override;
[[nodiscard]] auto where() const noexcept -> Vector2 override;
@@ -48,13 +48,6 @@ public:
void show() noexcept override;
- void subscribe(const Event &event, const Subscriber &subscriber) noexcept override;
-
- void notify_subscribers(const Event &event, const Context &context)
- const noexcept override;
-
private:
Vector2 _position;
-
- std::unordered_map<CursorEvent, std::vector<Subscriber>> _subscribers;
};
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp
index 2fb97ac..3cec1b8 100644
--- a/src/engine/user/input.hpp
+++ b/src/engine/user/input.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "interfaces/input.hpp"
-#include "interfaces/subscriber.hpp"
#include <yacppdic/auto_wirable.hpp>