From 838b797b0701f2495c74791db3e53f4158e46602 Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Fri, 15 Nov 2024 08:33:19 +0100 Subject: [PATCH 1/3] Add function to print the demo keybindings --- demo/include/utils/utils.hpp | 2 ++ demo/src/main.cpp | 3 +++ demo/src/utils.cpp | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/demo/include/utils/utils.hpp b/demo/include/utils/utils.hpp index 5faf27ae..8282e9db 100644 --- a/demo/include/utils/utils.hpp +++ b/demo/include/utils/utils.hpp @@ -11,4 +11,6 @@ int dotsInRadius(const Position& center, const demo::EnvironmentModel::ConstPtr& environmentModel, int pathEndNeighborhoodRadius); +void printKeybindings(); + } // namespace utils diff --git a/demo/src/main.cpp b/demo/src/main.cpp index 70df2ffc..96c8ebd8 100644 --- a/demo/src/main.cpp +++ b/demo/src/main.cpp @@ -7,6 +7,7 @@ #include "demo/pacman_agent.hpp" #include "demo/types.hpp" #include "utils/pacman_wrapper.hpp" +#include "utils/utils.hpp" using namespace demo; using namespace utils; @@ -14,6 +15,8 @@ using namespace arbitration_graphs; int main() { try { + printKeybindings(); + PacmanWrapper demo; PacmanAgent agent(demo.game()); diff --git a/demo/src/utils.cpp b/demo/src/utils.cpp index deaecd07..b34050d2 100644 --- a/demo/src/utils.cpp +++ b/demo/src/utils.cpp @@ -1,3 +1,5 @@ +#include + #include "utils/utils.hpp" namespace utils { @@ -31,4 +33,16 @@ int dotsInRadius(const Position& center, return nDots; } +void printKeybindings() { + std::cout << "\n" + << "\033[1;36m=====================================\033[0m\n" + << "\033[1;37m CONTROLS \033[0m\n" + << "\033[1;36m=====================================\033[0m\n" + << " \033[1;32mESC/Q\033[0m - Quit the demo\n" + << " \033[1;32mSpace\033[0m - Pause the demo\n" + << " \033[1;32mP\033[0m - Toggle path visualization\n" + << "\033[1;36m=====================================\033[0m\n" + << '\n'; +} + } // namespace utils From bcc4961a4146ee464d9deddecef11153ed023e96 Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Fri, 15 Nov 2024 08:44:46 +0100 Subject: [PATCH 2/3] Move printKeybindings into PacmanWrapper class --- demo/include/utils/pacman_wrapper.hpp | 2 ++ demo/include/utils/utils.hpp | 2 -- demo/src/main.cpp | 5 ++--- demo/src/pacman_wrapper.cpp | 14 ++++++++++++++ demo/src/utils.cpp | 14 -------------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/demo/include/utils/pacman_wrapper.hpp b/demo/include/utils/pacman_wrapper.hpp index 0c5b2c93..93806374 100644 --- a/demo/include/utils/pacman_wrapper.hpp +++ b/demo/include/utils/pacman_wrapper.hpp @@ -27,6 +27,8 @@ class PacmanWrapper { return game_; } + void printKeybindings(); + private: void handleUserInput(); void renderPath(const demo::Positions& path); diff --git a/demo/include/utils/utils.hpp b/demo/include/utils/utils.hpp index 8282e9db..5faf27ae 100644 --- a/demo/include/utils/utils.hpp +++ b/demo/include/utils/utils.hpp @@ -11,6 +11,4 @@ int dotsInRadius(const Position& center, const demo::EnvironmentModel::ConstPtr& environmentModel, int pathEndNeighborhoodRadius); -void printKeybindings(); - } // namespace utils diff --git a/demo/src/main.cpp b/demo/src/main.cpp index 96c8ebd8..2dfcd771 100644 --- a/demo/src/main.cpp +++ b/demo/src/main.cpp @@ -7,7 +7,6 @@ #include "demo/pacman_agent.hpp" #include "demo/types.hpp" #include "utils/pacman_wrapper.hpp" -#include "utils/utils.hpp" using namespace demo; using namespace utils; @@ -15,9 +14,9 @@ using namespace arbitration_graphs; int main() { try { - printKeybindings(); - PacmanWrapper demo; + demo.printKeybindings(); + PacmanAgent agent(demo.game()); gui::WebServer server(8080, true); diff --git a/demo/src/pacman_wrapper.cpp b/demo/src/pacman_wrapper.cpp index d42b9ae5..0948572b 100644 --- a/demo/src/pacman_wrapper.cpp +++ b/demo/src/pacman_wrapper.cpp @@ -1,5 +1,7 @@ #include "utils/pacman_wrapper.hpp" +#include + #include #include @@ -108,6 +110,18 @@ void PacmanWrapper::progressGame(const demo::Command& command, FrameCap sync{fps}; } +void PacmanWrapper::printKeybindings() { + std::cout << "\n" + << "\033[1;36m=====================================\033[0m\n" + << "\033[1;37m CONTROLS \033[0m\n" + << "\033[1;36m=====================================\033[0m\n" + << " \033[1;32mESC/Q\033[0m - Quit the demo\n" + << " \033[1;32mSpace\033[0m - Pause the demo\n" + << " \033[1;32mP\033[0m - Toggle path visualization\n" + << "\033[1;36m=====================================\033[0m\n" + << '\n'; +} + void PacmanWrapper::renderPath(const demo::Positions& path) { // Set path color and transparency SDL_CHECK(SDL_SetRenderDrawColor(renderer_.get(), 0, 255, 0, 90)); diff --git a/demo/src/utils.cpp b/demo/src/utils.cpp index b34050d2..deaecd07 100644 --- a/demo/src/utils.cpp +++ b/demo/src/utils.cpp @@ -1,5 +1,3 @@ -#include - #include "utils/utils.hpp" namespace utils { @@ -33,16 +31,4 @@ int dotsInRadius(const Position& center, return nDots; } -void printKeybindings() { - std::cout << "\n" - << "\033[1;36m=====================================\033[0m\n" - << "\033[1;37m CONTROLS \033[0m\n" - << "\033[1;36m=====================================\033[0m\n" - << " \033[1;32mESC/Q\033[0m - Quit the demo\n" - << " \033[1;32mSpace\033[0m - Pause the demo\n" - << " \033[1;32mP\033[0m - Toggle path visualization\n" - << "\033[1;36m=====================================\033[0m\n" - << '\n'; -} - } // namespace utils From ae890715baa4ba1c6f53b56d0dfc3f428f92a9b7 Mon Sep 17 00:00:00 2001 From: Piotr Spieker Date: Fri, 15 Nov 2024 13:46:19 +0100 Subject: [PATCH 3/3] Make sure the keybindings are printed by flushing once with `std::endl` --- demo/src/pacman_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/pacman_wrapper.cpp b/demo/src/pacman_wrapper.cpp index 0948572b..7ff832e0 100644 --- a/demo/src/pacman_wrapper.cpp +++ b/demo/src/pacman_wrapper.cpp @@ -119,7 +119,7 @@ void PacmanWrapper::printKeybindings() { << " \033[1;32mSpace\033[0m - Pause the demo\n" << " \033[1;32mP\033[0m - Toggle path visualization\n" << "\033[1;36m=====================================\033[0m\n" - << '\n'; + << std::endl; } void PacmanWrapper::renderPath(const demo::Positions& path) {