Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class UserControlledClient : public Botcraft::ManagersClient
{
public:
UserControlledClient(bool online, bool use_renderer_);
UserControlledClient(bool online, bool use_renderer_, std::pair<int, int> resolution);
~UserControlledClient();

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int> resolution) :
ManagersClient(use_renderer_, { resolution })
{
#if USE_GUI
mouse_sensitivity = 0.1f;
Expand Down
25 changes: 24 additions & 1 deletion Examples/1_UserControlledExample/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ChatCommandClient : public Botcraft::TemplatedBehaviourClient<ChatCommandClient>
{
public:
ChatCommandClient(const bool use_renderer_);
ChatCommandClient(const bool use_renderer_, std::pair<int, int> resolution);
~ChatCommandClient();

protected:
Expand Down
19 changes: 12 additions & 7 deletions Examples/2_ChatCommandExample/src/ChatCommandClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,7 +17,8 @@
using namespace Botcraft;
using namespace ProtocolCraft;

ChatCommandClient::ChatCommandClient(const bool use_renderer_) : TemplatedBehaviourClient<ChatCommandClient>(use_renderer_)
ChatCommandClient::ChatCommandClient(const bool use_renderer_, std::pair<int, int> resolution) :
TemplatedBehaviourClient<ChatCommandClient>(use_renderer_, { resolution })
{
std::cout << "Known commands:\n";
std::cout << " Pathfinding to position:\n";
Expand All @@ -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";
Expand All @@ -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<std::string> splitted({ std::istream_iterator<std::string>{ss}, std::istream_iterator<std::string>{} });
Expand Down Expand Up @@ -86,6 +88,8 @@ void ChatCommandClient::Handle(ClientboundSystemChatPacket& msg)

void ChatCommandClient::ProcessChatMsg(const std::vector<std::string>& splitted_msg)
{
printf("Making screenshot\n");
rendering_manager->Screenshot("test.png");
if (splitted_msg.size() < 2 || splitted_msg[0] != network_manager->GetMyName())
{
return;
Expand Down Expand Up @@ -140,6 +144,11 @@ void ChatCommandClient::ProcessChatMsg(const std::vector<std::string>& 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
Expand Down Expand Up @@ -177,10 +186,6 @@ void ChatCommandClient::ProcessChatMsg(const std::vector<std::string>& 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)
Expand Down
25 changes: 24 additions & 1 deletion Examples/2_ChatCommandExample/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion botcraft/include/botcraft/AI/BehaviourClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<int, int>> resolution);
virtual ~BehaviourClient();

virtual void Yield() = 0;
Expand Down
2 changes: 1 addition & 1 deletion botcraft/include/botcraft/AI/SimpleBehaviourClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Botcraft
class SimpleBehaviourClient : public TemplatedBehaviourClient<SimpleBehaviourClient>
{
public:
SimpleBehaviourClient(const bool use_renderer_);
SimpleBehaviourClient(const bool use_renderer_, std::optional<std::pair<int, int>> resolution = { });

virtual ~SimpleBehaviourClient();
};
Expand Down
4 changes: 2 additions & 2 deletions botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace Botcraft
};

public:
TemplatedBehaviourClient(const bool use_renderer_) :
BehaviourClient(use_renderer_)
TemplatedBehaviourClient(const bool use_renderer_, std::optional<std::pair<int, int>> resolution) :
BehaviourClient(use_renderer_, resolution)
{
swap_tree = false;
}
Expand Down
3 changes: 2 additions & 1 deletion botcraft/include/botcraft/Game/ManagersClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Botcraft
class ManagersClient : public ConnectionClient
{
public:
ManagersClient(const bool use_renderer_);
ManagersClient(const bool use_renderer_, const std::optional<std::pair<int, int>> resolution);
virtual ~ManagersClient();

virtual void Disconnect() override;
Expand Down Expand Up @@ -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<std::pair<int, int>> resolution;
std::shared_ptr<Renderer::RenderingManager> rendering_manager;
#endif

Expand Down
4 changes: 2 additions & 2 deletions botcraft/src/AI/BehaviourClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace Botcraft
{
BehaviourClient::BehaviourClient(const bool use_renderer_) :
ManagersClient(use_renderer_)
BehaviourClient::BehaviourClient(const bool use_renderer_, std::optional<std::pair<int, int>> resolution) :
ManagersClient(use_renderer_, resolution)
{
blackboard.Subscribe(this);
}
Expand Down
3 changes: 2 additions & 1 deletion botcraft/src/AI/SimpleBehaviourClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Botcraft
{
SimpleBehaviourClient::SimpleBehaviourClient(const bool use_renderer_) : TemplatedBehaviourClient<SimpleBehaviourClient>(use_renderer_)
SimpleBehaviourClient::SimpleBehaviourClient(const bool use_renderer_, std::optional<std::pair<int, int>> resolution) :
TemplatedBehaviourClient<SimpleBehaviourClient>(use_renderer_, resolution)
{

}
Expand Down
14 changes: 12 additions & 2 deletions botcraft/src/Game/ManagersClient.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <optional>

#include "botcraft/Game/AssetsManager.hpp"
#include "botcraft/Game/Entities/EntityManager.hpp"
#include "botcraft/Game/Entities/LocalPlayer.hpp"
Expand All @@ -20,7 +22,8 @@ using namespace ProtocolCraft;

namespace Botcraft
{
ManagersClient::ManagersClient(const bool use_renderer_)
ManagersClient::ManagersClient(const bool use_renderer_, std::optional<std::pair<int, int>> resolution) :
resolution(resolution)
{
difficulty = Difficulty::None;
is_hardcore = false;
Expand Down Expand Up @@ -193,7 +196,14 @@ namespace Botcraft
#if USE_GUI
if (use_renderer)
{
rendering_manager = std::make_shared<Renderer::RenderingManager>(world, inventory_manager, entity_manager, 800, 600, CHUNK_WIDTH, false);
if (resolution.has_value())
{
rendering_manager = std::make_shared<Renderer::RenderingManager>(world, inventory_manager, entity_manager, resolution.value().first, resolution.value().second, CHUNK_WIDTH, false);
}
else
{
rendering_manager = std::make_shared<Renderer::RenderingManager>(world, inventory_manager, entity_manager, 800, 600, CHUNK_WIDTH, false);
}
network_manager->AddHandler(rendering_manager.get());
}
physics_manager = std::make_shared<PhysicsManager>(rendering_manager, inventory_manager, entity_manager, network_manager, world);
Expand Down