aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user/cursor.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-23 20:16:07 +0200
committerHampusM <hampus@hampusmat.com>2022-06-23 20:16:07 +0200
commitafa22dc6450a7f2341c432604d5e50735d6830c7 (patch)
treeb2d3b9a27f8403b1b1117ae7dfef951b14b3c013 /src/engine/user/cursor.cpp
parent0f9d874b6af4698234be96de1fddad15aa882a1d (diff)
perf: reduce cout flushing
Diffstat (limited to 'src/engine/user/cursor.cpp')
-rw-r--r--src/engine/user/cursor.cpp44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp
index 963531f..b38cee0 100644
--- a/src/engine/user/cursor.cpp
+++ b/src/engine/user/cursor.cpp
@@ -10,7 +10,10 @@ CursorController::CursorController() noexcept
{
}
-void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept
+void CursorController::move(
+ const Vector2 &direction,
+ const uint32_t &amount,
+ bool flush_cout) noexcept
{
auto direction_format = direction_format_map.at(direction);
@@ -18,12 +21,16 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no
fmt::runtime(direction_format.data()),
fmt::arg("esc", ESC),
fmt::arg("amount", amount));
- std::cout.flush();
+
+ if (flush_cout)
+ {
+ std::cout.flush();
+ }
_position = _position.to_direction(direction, static_cast<Vector2::Value>(amount));
}
-void CursorController::move_to(const Vector2 &position) noexcept
+void CursorController::move_to(const Vector2 &position, bool flush_cout) noexcept
{
const auto inverted_pos = _invert_position_y(position);
@@ -32,7 +39,11 @@ void CursorController::move_to(const Vector2 &position) noexcept
fmt::arg("esc", ESC),
fmt::arg("row", inverted_pos.get_y()),
fmt::arg("column", inverted_pos.get_x() + 1));
- std::cout.flush();
+
+ if (flush_cout)
+ {
+ std::cout.flush();
+ }
_position = position;
}
@@ -60,26 +71,39 @@ void CursorController::update_position(const Vector2 &position) noexcept
_position = position;
}
-void CursorController::hide() noexcept
+void CursorController::hide(bool flush_cout) noexcept
{
fmt::print(CURSOR_INVISIBLE, fmt::arg("esc", ESC));
- std::cout.flush();
+
+ if (flush_cout)
+ {
+ std::cout.flush();
+ }
}
-void CursorController::show() noexcept
+void CursorController::show(bool flush_cout) noexcept
{
fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC));
- std::cout.flush();
+
+ if (flush_cout)
+ {
+ std::cout.flush();
+ }
}
-void CursorController::set_cursor_style(CursorStyle cursor_style) noexcept
+void CursorController::set_cursor_style(
+ CursorStyle cursor_style,
+ bool flush_cout) noexcept
{
fmt::print(
SET_CURSOR_STYLE,
fmt::arg("esc", ESC),
fmt::arg("style", static_cast<int>(cursor_style)));
- std::cout.flush();
+ if (flush_cout)
+ {
+ std::cout.flush();
+ }
}
void CursorController::set_bounds(const Bounds &bounds) noexcept