show integrated server stats
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class ServerGui;
|
||||
|
||||
class MainMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_TriedToConnect = false;
|
||||
@@ -22,6 +24,7 @@ private:
|
||||
imgui_addons::ImGuiFileBrowser m_FileDialog;
|
||||
|
||||
std::unique_ptr<server::Server> m_Server;
|
||||
std::unique_ptr<ServerGui> m_ServerGui;
|
||||
public:
|
||||
MainMenu(client::Client* client);
|
||||
~MainMenu();
|
||||
|
||||
19
include/client/render/gui/ServerGui.h
Normal file
19
include/client/render/gui/ServerGui.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
#include "server/Server.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class ServerGui : public GuiWidget {
|
||||
private:
|
||||
server::Server* m_Server;
|
||||
public:
|
||||
ServerGui(client::Client* client, server::Server* server);
|
||||
|
||||
virtual void Render();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
|
||||
void BroadcastPacket(const protocol::Packet* packet);
|
||||
|
||||
float GetMSPT() const { return m_TickCounter.GetMSPT(); }
|
||||
float GetTPS() const { return m_TickCounter.GetTPS(); }
|
||||
|
||||
bool IsRunning() { return m_ServerRunning; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "client/render/gui/MainMenu.h"
|
||||
#include "client/render/gui/ServerGui.h"
|
||||
|
||||
#include "client/Client.h"
|
||||
|
||||
@@ -19,7 +20,12 @@ MainMenu::~MainMenu() {
|
||||
|
||||
void MainMenu::Render() {
|
||||
if (m_Server != nullptr && !m_Server->IsRunning()) {
|
||||
m_Server.reset(0); // destroying server if it stoped
|
||||
m_Server.reset(); // destroying server if it stoped
|
||||
m_ServerGui.reset();
|
||||
}
|
||||
|
||||
if(m_Server != nullptr){
|
||||
m_ServerGui->Render();
|
||||
}
|
||||
|
||||
if (m_Client->IsConnected()) return;
|
||||
@@ -83,8 +89,10 @@ bool MainMenu::StartServer() {
|
||||
m_Server = std::make_unique<td::server::Server>();
|
||||
m_Server->LoadMap(m_WorldFilePath);
|
||||
if (!m_Server->Start(m_ServerPort, false)) {
|
||||
m_Server.reset();
|
||||
return false;
|
||||
}
|
||||
m_ServerGui = std::make_unique<ServerGui>(m_Client, m_Server.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
27
src/client/render/gui/ServerGui.cpp
Normal file
27
src/client/render/gui/ServerGui.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "client/render/gui/ServerGui.h"
|
||||
|
||||
#include "client/render/gui/imgui/imgui.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
ServerGui::ServerGui(client::Client* client, server::Server* server) : GuiWidget(client), m_Server(server) {}
|
||||
|
||||
|
||||
void ServerGui::Render() {
|
||||
ImGui::Begin("Integrated Server");
|
||||
ImGui::Text("Server TPS : %.1f", m_Server->GetTPS());
|
||||
ImGui::Text("Server MSPT : %i", (int)m_Server->GetMSPT());
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Restart")) {
|
||||
m_Server->Restart();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Stop")) {
|
||||
m_Server->Stop();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user