Skip to content

Commit

Permalink
fix (./ImGui): ImGui Draw Internet debug stat
Browse files Browse the repository at this point in the history
  • Loading branch information
PharaEthan committed Jan 13, 2024
2 parents 3448595 + 0a31f96 commit 7b42ca5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
27 changes: 12 additions & 15 deletions Client/src/Layer/RTypeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ namespace RType {
Scenes[GAME]->OnViewportResize(Application::Get().GetWindow().GetWidth(),
Application::Get().GetWindow().GetHeight());

_Network->SetWorld(Scenes[CurrentScene]->GetWorldPtr());

// TODO: Temp code

// Create the camera entity
Expand All @@ -123,10 +121,10 @@ namespace RType {
star.AddComponent<ScriptComponent>().Bind("Star");
}

// PrefabsImporter::LoadPrefabs("Assets/Prefabs/Player.prefab", Scenes[CurrentScene]);

Scenes[CurrentScene]->OnRuntimeStart();

_Network->SetWorld(Scenes[CurrentScene]->GetWorldPtr());

ConnectToServer(port, ip, serverPort);
}

Expand Down Expand Up @@ -166,6 +164,8 @@ namespace RType {
EXODIA_PROFILE_FUNCTION();

#ifdef EXODIA_DEBUG
NetworkInfo info = _Network->GetNetworkInfo();

ImGui::Begin("R-Type Statistics");
ImGui::Text("FPS: %.1f", Application::Get().GetStatistics().FPS);
ImGui::Text("Frame Time: %.3f ms", Application::Get().GetStatistics().FrameTime);
Expand All @@ -177,6 +177,14 @@ namespace RType {
ImGui::Text("Vertex Count: %d", Renderer2D::GetStats().GetTotalVertexCount());
ImGui::Text("Index Count: %d", Renderer2D::GetStats().GetTotalIndexCount());
ImGui::Separator();
ImGui::Text("PACKET info");
ImGui::Text("Send packet: %d", info.sendPacket);
ImGui::Text("Received packet: %d", info.receivedPacket);
ImGui::Text("KiloByte sent: %.2f", info.kiloByteSent);
ImGui::Text("KiloByte received: %.2f", info.kiloByteReceived);
ImGui::Text("Packet loss sent: %d", info.sendPacketLost);
ImGui::Text("Packet loss received: %d", info.receivePacketLost);
ImGui::Text("PING sent: %d", info.ping);
ImGui::End();
#endif
}
Expand Down Expand Up @@ -210,17 +218,6 @@ namespace RType {
}
(void)entity;
});
if (key == Key::ESCAPE) {
NetworkInfo info = _Network->GetNetworkInfo();
EXODIA_CORE_ERROR("PACKET info");
EXODIA_CORE_ERROR("Send packet: {0}", info.sendPacket);
EXODIA_CORE_ERROR("Received packet: {0}", info.receivedPacket);
EXODIA_CORE_ERROR("KiloByte sent: {0}", info.kiloByteSent);
EXODIA_CORE_ERROR("KiloByte received: {0}", info.kiloByteReceived);
EXODIA_CORE_ERROR("Packet loss sent: {0}", info.sendPacketLost);
EXODIA_CORE_ERROR("Packet loss received: {0}", info.receivePacketLost);
EXODIA_CORE_ERROR("PING sent: {0}", info.ping);
}
Scenes[CurrentScene]->GetWorld().UnlockMutex();

return true;
Expand Down
2 changes: 1 addition & 1 deletion Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

set(GAME_ENGINE_DIR ${CMAKE_SOURCE_DIR}/GameEngine)
Expand Down
6 changes: 3 additions & 3 deletions Server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace Exodia {

if (count % 200 == 0) {
EXODIA_CORE_WARN("Syncing components");
Scenes[CurrentScene]->GetWorld().ForEach<TransformComponent>(
Scenes[CurrentScene]->ForEach<TransformComponent>(
[&](Entity *entity, ComponentHandle<TransformComponent> transform) {
(void)transform;
_Network.SendComponentOf(false, entity, "TransformComponent");
Expand Down Expand Up @@ -318,7 +318,7 @@ namespace Exodia {
}

void Server::SendComponents(SceneType scene) {
Scenes[scene]->GetWorld().ForEach<TagComponent>([&](Entity *entity, ComponentHandle<TagComponent> tag) {
Scenes[scene]->ForEach<TagComponent>([&](Entity *entity, ComponentHandle<TagComponent> tag) {
if (tag.Get().Tag.rfind("Player_") != std::string::npos) {
_Network.SendComponentOf(true, entity, "TagComponent");
_Network.SendComponentOf(true, entity, "TransformComponent");
Expand Down Expand Up @@ -364,7 +364,7 @@ namespace Exodia {

player = Scenes[GAME]->GetEntityByName("Player_" + std::to_string(userID));

_Users.push_back(User(connection.second, player));
_Users.push_back(User(connection.second, player.GetEntity()));

SendComponents(GAME);

Expand Down
2 changes: 1 addition & 1 deletion Server/src/User/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Exodia {
_Pawn = nullptr;
}

User::User(std::shared_ptr<Connection> connection, GameObject pawn) {
User::User(std::shared_ptr<Connection> connection, Entity *pawn) {
_Connection = connection;
_Pawn = pawn;
}
Expand Down
8 changes: 4 additions & 4 deletions Server/src/User/User.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ namespace Exodia {

public:
User(std::shared_ptr<Connection> connection);
User(std::shared_ptr<Connection> connection, GameObject pawn = GameObject());
User(std::shared_ptr<Connection> connection, Entity *pawn = nullptr);
~User();

std::shared_ptr<Connection> GetConnection() const { return _Connection; }

void SetConnection(std::shared_ptr<Connection> connection) { _Connection = connection; }

GameObject GetPawn() const { return _Pawn; }
Entity *GetPawn() const { return _Pawn; }

void SetPawn(GameObject pawn) { _Pawn = pawn; }
void SetPawn(Entity *pawn) { _Pawn = pawn; }

private:
std::shared_ptr<Connection> _Connection;
GameObject _Pawn;
Entity *_Pawn;
};
}; // namespace Exodia

Expand Down
5 changes: 5 additions & 0 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ Pos=60,60
Size=400,400
Collapsed=0

[Window][R-Type Statistics]
Pos=18,17
Size=189,218
Collapsed=0

[Docking][Data]

0 comments on commit 7b42ca5

Please sign in to comment.