Skip to content

Commit

Permalink
Ip and port
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjaltesorgenfrei committed Jan 26, 2024
1 parent 2ee4845 commit 02e0f76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
#include "NetworkServerSystem.hpp"
#include "NetworkClientSystem.hpp"

void App::run(bool isClient) {
void App::run(int argc, char* argv[]) {
instance = this;
setupCallBacks(); // We create ImGui in the renderer, so callbacks have to happen before.
device = std::make_unique<BehDevice>(window);
AssetManager manager(device);
renderer = std::make_unique<Renderer>(window, device, manager);
physicsWorld = std::make_unique<PhysicsWorld>(registry);
if (isClient) {
if (argc > 1) {
// TODO: send the ip and port
networkSystem = std::make_unique<NetworkClientSystem>();
} else {
networkSystem = std::make_unique<NetworkServerSystem>();
Expand Down Expand Up @@ -870,7 +871,7 @@ App::App() = default;
int main(int argc, char* argv[]) {
App app;
try {
app.run(argc > 1);
app.run(argc, argv);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion src/client/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class App {
public:
App();

void run(bool isClient);
void run(int argc, char* argv[]);

App inline static* instance = nullptr;

Expand Down
7 changes: 5 additions & 2 deletions src/engine/NetworkClientSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

using namespace yojimbo;

NetworkClientSystem::NetworkClientSystem() {}
NetworkClientSystem::NetworkClientSystem(std::string ip, uint16_t port) {
this->ip = ip;
this->port = port;
}

NetworkClientSystem::~NetworkClientSystem() {
client->Disconnect();
Expand Down Expand Up @@ -56,7 +59,7 @@ void NetworkClientSystem::init(entt::registry &registry) {
adapter = std::make_unique<PhysicsNetworkAdapter>();
client = std::make_unique<Client>(GetDefaultAllocator(), Address("0.0.0.0"), config, *adapter, clientTime);

Address serverAddress("127.0.0.1", ServerPort);
Address serverAddress(ip.data(), port);

client->InsecureConnect(privateKey, clientId, serverAddress);
}
Expand Down
4 changes: 3 additions & 1 deletion src/engine/NetworkClientSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef uint64_t NetworkID;
// TODO: Delete this file. Or at least gut it and rework it a bunch
class NetworkClientSystem : public INetworkSystem {
public:
NetworkClientSystem();
NetworkClientSystem(std::string ip = "127.0.0.1", uint16_t port = ServerPort);
~NetworkClientSystem();

virtual void init(entt::registry& registry) override;
Expand All @@ -29,6 +29,8 @@ class NetworkClientSystem : public INetworkSystem {
uint8_t privateKey[yojimbo::KeyBytes] = {0};
yojimbo::ClientServerConfig config;
yojimbo::NetworkInfo networkInfo;
std::string ip;
uint16_t port;

void onNetworkedConstructed(entt::registry& registry, entt::entity entity);
void onNetworkedDestroyed(entt::registry& registry, entt::entity entity);
Expand Down

0 comments on commit 02e0f76

Please sign in to comment.