From afa22dc6450a7f2341c432604d5e50735d6830c7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 23 Jun 2022 20:16:07 +0200 Subject: perf: reduce cout flushing --- src/game/game.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/game') diff --git a/src/game/game.cpp b/src/game/game.cpp index fd53841..055fcd6 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -275,13 +275,12 @@ void Game::_on_normal_mode_update() noexcept _erase_entire_line(); - std::cout << ":"; - std::cout.flush(); + std::cout.put(':'); _cursor_controller->update_position( _cursor_controller->where() + Vector2::right()); - _cursor_controller->set_cursor_style(_command_mode_cursor_style); + _cursor_controller->set_cursor_style(_command_mode_cursor_style, true); _command_mode_input = ""; @@ -466,7 +465,7 @@ void Game::_on_command_mode_update() noexcept _command_mode_input.erase(input_pos_x - 1U, 1U); - _cursor_controller->move(Vector2::left(), 1U); + _cursor_controller->move(Vector2::left(), 1U, true); std::cout.put(' '); std::cout.flush(); @@ -474,15 +473,14 @@ void Game::_on_command_mode_update() noexcept _cursor_controller->update_position( _cursor_controller->where() + Vector2::right()); - _cursor_controller->move(Vector2::left(), 1U); + _cursor_controller->move(Vector2::left(), 1U, true); _erase_line_from_cursor(); - std::cout << _command_mode_input.substr(input_pos_x - 1U); - std::cout.flush(); + fmt::print("{}", _command_mode_input.substr(input_pos_x - 1U)); _cursor_controller->move_to(position); - _cursor_controller->move(Vector2::left(), 1U); + _cursor_controller->move(Vector2::left(), 1U, true); break; } @@ -490,7 +488,7 @@ void Game::_on_command_mode_update() noexcept case keycodes::LEFT_ARROW: if (_cursor_controller->where().get_x() >= 2) { - _cursor_controller->move(Vector2::left(), 1U); + _cursor_controller->move(Vector2::left(), 1U, true); } break; @@ -498,7 +496,7 @@ void Game::_on_command_mode_update() noexcept if (static_cast(_cursor_controller->where().get_x()) - 1U < _command_mode_input.size()) { - _cursor_controller->move(Vector2::right(), 1U); + _cursor_controller->move(Vector2::right(), 1U, true); } break; @@ -518,16 +516,15 @@ void Game::_on_command_mode_update() noexcept _erase_line_from_cursor(); - std::cout << pressed_key << _command_mode_input.substr(input_pos_x + 1U); - std::cout.flush(); + fmt::print("{}{}", pressed_key, _command_mode_input.substr(input_pos_x + 1)); - _cursor_controller->move_to(position + Vector2::right()); + _cursor_controller->move_to(position + Vector2::right(), true); break; } _command_mode_input += pressed_key; - std::cout << pressed_key; + std::cout.put(pressed_key); std::cout.flush(); _cursor_controller->update_position( @@ -626,14 +623,13 @@ void Game::_set_space( { const auto prev_position = _cursor_controller->where(); - _cursor_controller->move_to(position); + _cursor_controller->move_to(position, true); std::cout.put(character); - std::cout.flush(); matrix->set(position, character); - _cursor_controller->move_to(prev_position); + _cursor_controller->move_to(prev_position, true); } void Game::_erase_entire_line() noexcept -- cgit v1.2.3-18-g5258