diff --git a/ExampleModules.nix b/ExampleModules.nix index 0fa0cd8..d3610c0 100644 --- a/ExampleModules.nix +++ b/ExampleModules.nix @@ -58,6 +58,7 @@ ''; }; + Print = pkgs.stdenvNoCC.mkDerivation { name = "Print"; @@ -168,7 +169,6 @@ $imgui/*.cpp \ -DRENDERER_OPENGL \ -DWINDOW_GLFW \ - -DGUIMODULE \ -DTESTIMGUI_DYNAMIC \ -fpic -shared \ -I src -I include -I $imgui -I . \ @@ -214,4 +214,83 @@ ''; }; + + ChatServer = pkgs.stdenvNoCC.mkDerivation { + + name = "ChatServer"; + + src = ./.; + + nativeBuildInputs = with pkgs; [ + clang + ]; + + buildInputs = with pkgs; [ + gamenetworkingsockets + ]; + + buildPhase = '' + clang++ \ + modules/examples/ChatServer/src/*.cpp \ + modules/ServerModule/src/*.cpp \ + -fpic -shared \ + -I src -I include \ + -I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \ + -lGameNetworkingSockets \ + -DCHATSERVER_DYNAMIC \ + -Wall \ + -o $name + ''; + + installPhase = '' + mkdir -p $out/bin + cp $name $out/bin + ''; + + }; + + ChatClient = pkgs.stdenvNoCC.mkDerivation { + + name = "ChatClient"; + + src = ./.; + + imgui = inputs.imgui; + + nativeBuildInputs = with pkgs; [ + clang + ]; + + buildInputs = with pkgs; [ + gamenetworkingsockets + ]; + + buildPhase = '' + clang++ \ + modules/examples/ChatClient/src/*.cpp \ + modules/ClientModule/src/*.cpp \ + -I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \ + -lGameNetworkingSockets \ + -DCLIENTMODULE_DYNAMIC \ + modules/WindowModule/src/*.cpp \ + modules/ImguiModule/src/*.cpp \ + $imgui/backends/imgui_impl_glfw.cpp \ + $imgui/backends/imgui_impl_opengl3.cpp \ + $imgui/misc/cpp/*.cpp \ + $imgui/*.cpp \ + -DRENDERER_OPENGL \ + -DWINDOW_GLFW \ + -fpic -shared \ + -I src -I include -I $imgui -I . \ + -lGL -lglfw -lGLEW \ + -Wall \ + -o $name + ''; + + installPhase = '' + mkdir -p $out/bin + cp $name $out/bin + ''; + + }; } diff --git a/flake.nix b/flake.nix index 6a874eb..ea95946 100755 --- a/flake.nix +++ b/flake.nix @@ -90,6 +90,7 @@ ''; }; + WindowModule = pkgs.stdenvNoCC.mkDerivation { name = "WindowModule"; diff --git a/modules/ClientModule/src/ClientModule.h b/modules/ClientModule/src/ClientModule.h index baa6115..249a241 100644 --- a/modules/ClientModule/src/ClientModule.h +++ b/modules/ClientModule/src/ClientModule.h @@ -28,6 +28,8 @@ class ClientModule : public Archimedes::Module { } + bool isRunning() const { return running; } + void pollIncomingData(); void shouldHandleEvents(unsigned int events) { eventsToHandle = events; } diff --git a/modules/ServerModule/src/ServerModule.cpp b/modules/ServerModule/src/ServerModule.cpp index 84364a5..d716c09 100644 --- a/modules/ServerModule/src/ServerModule.cpp +++ b/modules/ServerModule/src/ServerModule.cpp @@ -48,7 +48,7 @@ void ServerModule::startServer(int p) { pollGroup = interface->CreatePollGroup(); if ( pollGroup == k_HSteamNetPollGroup_Invalid ) std::cerr << "Failed to listen on port " << port << std::endl; - //Printf( "Server listening on port %d\n", port ); + std::cerr << "Server listening on port " << port << std::endl; running = true; } diff --git a/modules/ServerModule/src/ServerModule.h b/modules/ServerModule/src/ServerModule.h index e85e4d9..1b7d44f 100644 --- a/modules/ServerModule/src/ServerModule.h +++ b/modules/ServerModule/src/ServerModule.h @@ -30,6 +30,8 @@ class ServerModule : public Archimedes::Module { DataSent = 1 << 2 }; + bool isRunning() const { return running; } + void shouldHandleEvents(unsigned int events) { eventsToHandle = events; } void sendReliable(HSteamNetConnection client, const void* data, uint32 byteCount) { diff --git a/modules/examples/ChatClient/src/ChatClient.cpp b/modules/examples/ChatClient/src/ChatClient.cpp index 8e89023..e564521 100644 --- a/modules/examples/ChatClient/src/ChatClient.cpp +++ b/modules/examples/ChatClient/src/ChatClient.cpp @@ -23,7 +23,43 @@ void ChatClient::run() { static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; } - (void)cm; + if(open) { + static std::string s, addr; + + ImGui::Begin("ChatClient Module", &open); + + ImGui::InputText("Server Address: ", &addr); + + if(cm->isRunning()) { + + if(ImGui::Button("Disconnect") && cm->isRunning()) { + cm->stopClient(); + } + + } else { + + if(ImGui::Button("Connect") && !cm->isRunning()) { + static SteamNetworkingIPAddr serverAddr; + serverAddr.ParseString(addr.c_str()); + cm->startClient(serverAddr); + } + } + + + ImGui::Text("%s", messages.c_str()); + + ImGui::InputText("Message: ", &s); + + ImGui::SameLine(); + + if(ImGui::Button("send")) { + cm->sendReliable(s.c_str(), (uint32) s.length()); + } + + ImGui::End(); + } else { + app->stopModule(name); + } } bool ChatClient::onEvent(const Archimedes::Event& event) { diff --git a/modules/examples/ChatClient/src/ChatClient.h b/modules/examples/ChatClient/src/ChatClient.h index 3abfff0..2e2255e 100644 --- a/modules/examples/ChatClient/src/ChatClient.h +++ b/modules/examples/ChatClient/src/ChatClient.h @@ -23,5 +23,11 @@ class ChatClient : public Archimedes::Module { bool onEvent(const Archimedes::Event&); private: - std::string messages; + std::string messages = ""; + bool open = true; }; + +#ifdef CHATCLIENT_DYNAMIC +#define MODULE_TYPE ChatClient +#include "endModule.h" +#endif diff --git a/modules/examples/ChatServer/src/ChatServer.h b/modules/examples/ChatServer/src/ChatServer.h index 8df1ec0..2a9b513 100644 --- a/modules/examples/ChatServer/src/ChatServer.h +++ b/modules/examples/ChatServer/src/ChatServer.h @@ -27,3 +27,8 @@ class ChatServer : public Archimedes::Module { bool onEvent(const Archimedes::Event&); }; + +#ifdef CHATSERVER_DYNAMIC +#define MODULE_TYPE ChatServer +#include "endModule.h" +#endif