Compare commits
2 Commits
9e93c1a1de
...
81a0407880
| Author | SHA1 | Date | |
|---|---|---|---|
| 81a0407880 | |||
| 8c61eb06ad |
@@ -7,6 +7,10 @@ namespace blitz {
|
||||
|
||||
class Client;
|
||||
|
||||
namespace game {
|
||||
class Player;
|
||||
} // namespace game
|
||||
|
||||
namespace gui {
|
||||
class Hud : public GuiWidget {
|
||||
private:
|
||||
@@ -21,8 +25,9 @@ class Hud : public GuiWidget {
|
||||
private:
|
||||
std::string FormatString();
|
||||
void Draw(const char* title, bool* p_open);
|
||||
void DrawFinishScreen();
|
||||
void DrawFinishScreen(bool win);
|
||||
void RenderTime(float, float);
|
||||
game::Player* GetWinner();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
#include "blitz/network/Network.h"
|
||||
|
||||
#include "blitz/misc/Log.h"
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
namespace blitz {
|
||||
namespace network {
|
||||
|
||||
/* Catch Signal Handler function */
|
||||
void signal_callback_handler(int signum) {
|
||||
utils::LOGD("[Network] Caught a SIGPIPE !");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
NetworkInitializer::NetworkInitializer() {
|
||||
WSADATA wsaData;
|
||||
@@ -18,7 +25,10 @@ NetworkInitializer::~NetworkInitializer() {
|
||||
WSACleanup();
|
||||
}
|
||||
#else
|
||||
NetworkInitializer::NetworkInitializer() {}
|
||||
NetworkInitializer::NetworkInitializer() {
|
||||
/* Prevents the game for crashing when socket closes on the other side */
|
||||
signal(SIGPIPE, signal_callback_handler);
|
||||
}
|
||||
NetworkInitializer::~NetworkInitializer() {}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -121,13 +121,14 @@ size_t TCPSocket::Send(const unsigned char* data, size_t size) {
|
||||
|
||||
while (sent < size) {
|
||||
int cur = send(m_Handle, reinterpret_cast<const char*>(data + sent), static_cast<int>(size - sent), 0);
|
||||
|
||||
if (cur <= 0) {
|
||||
m_Status = Status::Error;
|
||||
Disconnect();
|
||||
return 0;
|
||||
}
|
||||
sent += static_cast<std::size_t>(cur);
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ void ClientGame::HandlePacket(const protocol::PlayerListPacket* packet) {
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::PlayerStatsPacket* packet) {
|
||||
game::Player* player = m_Client->GetGame()->GetPlayerById(packet->GetPlayerID());
|
||||
assert(player);
|
||||
if (!player)
|
||||
return;
|
||||
player->SetStats(packet->GetPlayerStats());
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ void Hud::RenderTime(float positionX, float positionY) {
|
||||
ImGui::Text("%s", timeFormated.c_str());
|
||||
}
|
||||
|
||||
void Hud::DrawFinishScreen() {
|
||||
void Hud::DrawFinishScreen(bool win) {
|
||||
SetNextWindowFullScreen();
|
||||
ImGui::Begin("FinishScreen", nullptr, GetWindowFullScreenFlags() | ImGuiWindowFlags_NoInputs);
|
||||
{
|
||||
@@ -119,8 +119,6 @@ void Hud::DrawFinishScreen() {
|
||||
std::string victoryString = "VICTOIRE";
|
||||
std::string defeatString = "DEFAITE";
|
||||
|
||||
bool win = true;
|
||||
|
||||
ImGui::SetCursorPos({center.x - nextPartyTextWidth / 2, (8.5f / 10.0f) * ImGui::GetIO().DisplaySize.y});
|
||||
ImGui::Text("%s", nextPartyString.c_str());
|
||||
|
||||
@@ -144,16 +142,34 @@ void Hud::DrawFinishScreen() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
game::Player* Hud::GetWinner() {
|
||||
game::PlayerID winnerID = 0;
|
||||
int kills = -1;
|
||||
for (auto [id, player] : m_Client->GetGame()->GetPlayers()) {
|
||||
if (player.GetStats().m_Kills > kills) {
|
||||
winnerID = id;
|
||||
kills = player.GetStats().m_Kills;
|
||||
}
|
||||
}
|
||||
return m_Client->GetGame()->GetPlayerById(winnerID);
|
||||
}
|
||||
|
||||
void Hud::Render() {
|
||||
if (!m_Client->IsConnected())
|
||||
return;
|
||||
|
||||
static game::Player* winner = nullptr;
|
||||
|
||||
switch (m_Client->GetGame()->GetGameState()) {
|
||||
case game::GameState::gsEnd:
|
||||
DrawFinishScreen();
|
||||
if (!winner) {
|
||||
winner = GetWinner();
|
||||
}
|
||||
DrawFinishScreen(winner->GetID() == m_Client->GetPlayerID());
|
||||
break;
|
||||
default:
|
||||
Draw("Hud Blitz", nullptr);
|
||||
winner = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,10 @@ void ServerGame::UpdateHP(game::Player& player, float newHP) {
|
||||
return;
|
||||
|
||||
protocol::UpdateHealthPacket packet(player.GetHP());
|
||||
m_Server->GetConnexions().at(player.GetID())->SendPacket(&packet);
|
||||
|
||||
auto it = m_Server->GetConnexions().find(player.GetID());
|
||||
if (it != m_Server->GetConnexions().end())
|
||||
it->second->SendPacket(&packet);
|
||||
}
|
||||
|
||||
void ServerGame::UpdatePlayerStats() {
|
||||
|
||||
Reference in New Issue
Block a user