diff options
author | HampusM <hampus@hampusmat.com> | 2022-06-23 20:16:07 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-23 20:16:07 +0200 |
commit | afa22dc6450a7f2341c432604d5e50735d6830c7 (patch) | |
tree | b2d3b9a27f8403b1b1117ae7dfef951b14b3c013 /src/game | |
parent | 0f9d874b6af4698234be96de1fddad15aa882a1d (diff) |
perf: reduce cout flushing
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
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<uint32_t>(_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 |