diff --git a/Examples/1_UserControlledExample/include/UserControlledClient.hpp b/Examples/1_UserControlledExample/include/UserControlledClient.hpp index 9dc7630b..5c7b41a0 100644 --- a/Examples/1_UserControlledExample/include/UserControlledClient.hpp +++ b/Examples/1_UserControlledExample/include/UserControlledClient.hpp @@ -7,7 +7,7 @@ class UserControlledClient : public Botcraft::ManagersClient { public: - UserControlledClient(bool online, bool use_renderer_); + UserControlledClient(bool online, bool use_renderer_, std::pair resolution); ~UserControlledClient(); protected: diff --git a/Examples/1_UserControlledExample/src/UserControlledClient.cpp b/Examples/1_UserControlledExample/src/UserControlledClient.cpp index 98f6d5a2..0d0a2a66 100644 --- a/Examples/1_UserControlledExample/src/UserControlledClient.cpp +++ b/Examples/1_UserControlledExample/src/UserControlledClient.cpp @@ -21,7 +21,8 @@ using namespace Botcraft; using namespace ProtocolCraft; -UserControlledClient::UserControlledClient(bool online, bool use_renderer_) : ManagersClient(use_renderer_) +UserControlledClient::UserControlledClient(bool online, bool use_renderer_, std::pair resolution) : + ManagersClient(use_renderer_, { resolution }) { #if USE_GUI mouse_sensitivity = 0.1f; diff --git a/Examples/1_UserControlledExample/src/main.cpp b/Examples/1_UserControlledExample/src/main.cpp index 295ab923..97fcb941 100644 --- a/Examples/1_UserControlledExample/src/main.cpp +++ b/Examples/1_UserControlledExample/src/main.cpp @@ -23,6 +23,8 @@ struct Args bool connect = true; std::string address = "127.0.0.1:25565"; std::string login = "BCUserControl"; + int width = 800; + int height = 600; int return_code = 0; }; @@ -59,7 +61,7 @@ int main(int argc, char* argv[]) } } - UserControlledClient client(args.connect, true); + UserControlledClient client(args.connect, true, { args.width, args.height }); if (args.connect) { @@ -143,6 +145,27 @@ Args ParseCommandLine(int argc, char* argv[]) return args; } } + else if (arg == "--resolution") + { + if (i + 1 < argc) + { + args.width = atoi(argv[++i]); + char *komma = strchr(argv[i], ','); + if (komma == nullptr) + { + LOG_FATAL("--resolution requires width,height parameter"); + args.return_code = 1; + return args; + } + args.height = atoi(komma + 1); + } + else + { + LOG_FATAL("--resolution requires an argument"); + args.return_code = 1; + return args; + } + } } return args; } diff --git a/Examples/2_ChatCommandExample/include/ChatCommandClient.hpp b/Examples/2_ChatCommandExample/include/ChatCommandClient.hpp index a200ea2d..38034a13 100644 --- a/Examples/2_ChatCommandExample/include/ChatCommandClient.hpp +++ b/Examples/2_ChatCommandExample/include/ChatCommandClient.hpp @@ -10,7 +10,7 @@ class ChatCommandClient : public Botcraft::TemplatedBehaviourClient { public: - ChatCommandClient(const bool use_renderer_); + ChatCommandClient(const bool use_renderer_, std::pair resolution); ~ChatCommandClient(); protected: diff --git a/Examples/2_ChatCommandExample/src/ChatCommandClient.cpp b/Examples/2_ChatCommandExample/src/ChatCommandClient.cpp index c6aea3c5..5d472536 100644 --- a/Examples/2_ChatCommandExample/src/ChatCommandClient.cpp +++ b/Examples/2_ChatCommandExample/src/ChatCommandClient.cpp @@ -7,6 +7,7 @@ #include "botcraft/Game/Entities/EntityManager.hpp" #include "botcraft/Game/Entities/LocalPlayer.hpp" #include "botcraft/Network/NetworkManager.hpp" +#include "botcraft/Renderer/RenderingManager.hpp" #include "botcraft/AI/BehaviourTree.hpp" #include "botcraft/AI/Tasks/AllTasks.hpp" @@ -16,7 +17,8 @@ using namespace Botcraft; using namespace ProtocolCraft; -ChatCommandClient::ChatCommandClient(const bool use_renderer_) : TemplatedBehaviourClient(use_renderer_) +ChatCommandClient::ChatCommandClient(const bool use_renderer_, std::pair resolution) : + TemplatedBehaviourClient(use_renderer_, { resolution }) { std::cout << "Known commands:\n"; std::cout << " Pathfinding to position:\n"; @@ -25,8 +27,6 @@ ChatCommandClient::ChatCommandClient(const bool use_renderer_) : TemplatedBehavi std::cout << " name stop\n"; std::cout << " Check perimeter for spawnable blocks and save spawnable positions to file:\n"; std::cout << " name check_perimeter [x y z (default = player position)] radius (default = 128) [check_lighting (default = true)]\n"; - std::cout << " Disconnect:\n"; - std::cout << " name die\n"; std::cout << " Place a block:\n"; std::cout << " name place_block minecraft:item x y z\n"; std::cout << " Break a block:\n"; @@ -45,6 +45,8 @@ void ChatCommandClient::Handle(ClientboundChatPacket& msg) { ManagersClient::Handle(msg); + printf("[%s] Chat packet: %s\n", network_manager->GetMyName().c_str(), msg.GetMessage().GetText().c_str()); + // Split the message std::istringstream ss{ msg.GetMessage().GetText() }; const std::vector splitted({ std::istream_iterator{ss}, std::istream_iterator{} }); @@ -86,6 +88,8 @@ void ChatCommandClient::Handle(ClientboundSystemChatPacket& msg) void ChatCommandClient::ProcessChatMsg(const std::vector& splitted_msg) { + printf("Making screenshot\n"); + rendering_manager->Screenshot("test.png"); if (splitted_msg.size() < 2 || splitted_msg[0] != network_manager->GetMyName()) { return; @@ -140,6 +144,11 @@ void ChatCommandClient::ProcessChatMsg(const std::vector& splitted_ SetBehaviourTree(tree); } + else if (splitted_msg[1] == "screenshot") + { + printf("Making screenshot\n"); + rendering_manager->Screenshot("test.png"); + } else if (splitted_msg[1] == "stop") { // Stop any running behaviour @@ -177,10 +186,6 @@ void ChatCommandClient::ProcessChatMsg(const std::vector& splitted_ } CheckPerimeter(pos, radius, check_lighting); } - else if (splitted_msg[1] == "die") - { - should_be_closed = true; - } else if (splitted_msg[1] == "place_block") { if (splitted_msg.size() < 6) diff --git a/Examples/2_ChatCommandExample/src/main.cpp b/Examples/2_ChatCommandExample/src/main.cpp index eb0ccab5..bce3f78f 100644 --- a/Examples/2_ChatCommandExample/src/main.cpp +++ b/Examples/2_ChatCommandExample/src/main.cpp @@ -20,6 +20,8 @@ struct Args bool help = false; std::string address = "127.0.0.1:25565"; std::string login = "BCChatCommand"; + int width = 800; + int height = 600; int return_code = 0; }; @@ -56,7 +58,7 @@ int main(int argc, char* argv[]) } } - ChatCommandClient client(true); + ChatCommandClient client(true, { args.width, args.height }); client.SetAutoRespawn(true); LOG_INFO("Starting connection process"); @@ -118,6 +120,27 @@ Args ParseCommandLine(int argc, char* argv[]) return args; } } + else if (arg == "--resolution") + { + if (i + 1 < argc) + { + args.width = atoi(argv[++i]); + char *komma = strchr(argv[i], ','); + if (komma == nullptr) + { + LOG_FATAL("--resolution requires width,height parameter"); + args.return_code = 1; + return args; + } + args.height = atoi(komma + 1); + } + else + { + LOG_FATAL("--resolution requires an argument"); + args.return_code = 1; + return args; + } + } } return args; } diff --git a/botcraft/include/botcraft/AI/BehaviourClient.hpp b/botcraft/include/botcraft/AI/BehaviourClient.hpp index c1af3ff2..36092766 100644 --- a/botcraft/include/botcraft/AI/BehaviourClient.hpp +++ b/botcraft/include/botcraft/AI/BehaviourClient.hpp @@ -12,7 +12,7 @@ namespace Botcraft class BehaviourClient : public ManagersClient, private BlackboardObserver { public: - BehaviourClient(const bool use_renderer_); + BehaviourClient(const bool use_renderer_, std::optional> resolution); virtual ~BehaviourClient(); virtual void Yield() = 0; diff --git a/botcraft/include/botcraft/AI/SimpleBehaviourClient.hpp b/botcraft/include/botcraft/AI/SimpleBehaviourClient.hpp index 6df9f9b8..a3df5cfb 100644 --- a/botcraft/include/botcraft/AI/SimpleBehaviourClient.hpp +++ b/botcraft/include/botcraft/AI/SimpleBehaviourClient.hpp @@ -10,7 +10,7 @@ namespace Botcraft class SimpleBehaviourClient : public TemplatedBehaviourClient { public: - SimpleBehaviourClient(const bool use_renderer_); + SimpleBehaviourClient(const bool use_renderer_, std::optional> resolution = { }); virtual ~SimpleBehaviourClient(); }; diff --git a/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp b/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp index 6dc373e3..69a80a4e 100644 --- a/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp +++ b/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp @@ -37,8 +37,8 @@ namespace Botcraft }; public: - TemplatedBehaviourClient(const bool use_renderer_) : - BehaviourClient(use_renderer_) + TemplatedBehaviourClient(const bool use_renderer_, std::optional> resolution) : + BehaviourClient(use_renderer_, resolution) { swap_tree = false; } diff --git a/botcraft/include/botcraft/Game/ManagersClient.hpp b/botcraft/include/botcraft/Game/ManagersClient.hpp index 281be01f..df3adcf7 100644 --- a/botcraft/include/botcraft/Game/ManagersClient.hpp +++ b/botcraft/include/botcraft/Game/ManagersClient.hpp @@ -30,7 +30,7 @@ namespace Botcraft class ManagersClient : public ConnectionClient { public: - ManagersClient(const bool use_renderer_); + ManagersClient(const bool use_renderer_, const std::optional> resolution); virtual ~ManagersClient(); virtual void Disconnect() override; @@ -91,6 +91,7 @@ namespace Botcraft // from the bot. Only one renderer can be active // at the same time bool use_renderer; + const std::optional> resolution; std::shared_ptr rendering_manager; #endif diff --git a/botcraft/src/AI/BehaviourClient.cpp b/botcraft/src/AI/BehaviourClient.cpp index e34cdd59..d7961dbb 100644 --- a/botcraft/src/AI/BehaviourClient.cpp +++ b/botcraft/src/AI/BehaviourClient.cpp @@ -5,8 +5,8 @@ namespace Botcraft { - BehaviourClient::BehaviourClient(const bool use_renderer_) : - ManagersClient(use_renderer_) + BehaviourClient::BehaviourClient(const bool use_renderer_, std::optional> resolution) : + ManagersClient(use_renderer_, resolution) { blackboard.Subscribe(this); } diff --git a/botcraft/src/AI/SimpleBehaviourClient.cpp b/botcraft/src/AI/SimpleBehaviourClient.cpp index 20491b2e..a5d1d4aa 100644 --- a/botcraft/src/AI/SimpleBehaviourClient.cpp +++ b/botcraft/src/AI/SimpleBehaviourClient.cpp @@ -2,7 +2,8 @@ namespace Botcraft { - SimpleBehaviourClient::SimpleBehaviourClient(const bool use_renderer_) : TemplatedBehaviourClient(use_renderer_) + SimpleBehaviourClient::SimpleBehaviourClient(const bool use_renderer_, std::optional> resolution) : + TemplatedBehaviourClient(use_renderer_, resolution) { } diff --git a/botcraft/src/Game/ManagersClient.cpp b/botcraft/src/Game/ManagersClient.cpp index de2a56b6..cc979723 100644 --- a/botcraft/src/Game/ManagersClient.cpp +++ b/botcraft/src/Game/ManagersClient.cpp @@ -1,3 +1,5 @@ +#include + #include "botcraft/Game/AssetsManager.hpp" #include "botcraft/Game/Entities/EntityManager.hpp" #include "botcraft/Game/Entities/LocalPlayer.hpp" @@ -20,7 +22,8 @@ using namespace ProtocolCraft; namespace Botcraft { - ManagersClient::ManagersClient(const bool use_renderer_) + ManagersClient::ManagersClient(const bool use_renderer_, std::optional> resolution) : + resolution(resolution) { difficulty = Difficulty::None; is_hardcore = false; @@ -193,7 +196,14 @@ namespace Botcraft #if USE_GUI if (use_renderer) { - rendering_manager = std::make_shared(world, inventory_manager, entity_manager, 800, 600, CHUNK_WIDTH, false); + if (resolution.has_value()) + { + rendering_manager = std::make_shared(world, inventory_manager, entity_manager, resolution.value().first, resolution.value().second, CHUNK_WIDTH, false); + } + else + { + rendering_manager = std::make_shared(world, inventory_manager, entity_manager, 800, 600, CHUNK_WIDTH, false); + } network_manager->AddHandler(rendering_manager.get()); } physics_manager = std::make_shared(rendering_manager, inventory_manager, entity_manager, network_manager, world);