From 176204375772985ecb9d2078c3d027f095f7c8bd Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 6 Dec 2023 13:23:33 -0500 Subject: [PATCH] =?UTF-8?q?Bonne=20id=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQCSim-common/player.h | 2 +- SQCSim-srv/connection.cpp | 5 +++++ SQCSim-srv/server.cpp | 26 +++++++++++++++++--------- SQCSim2021/engine.cpp | 19 +++++++++---------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index ece5699..7503105 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -40,6 +40,7 @@ public: int getScore() const; void addPoint(); uint64_t Killer = 0; + std::string m_username; private: uint64_t getId() const; @@ -49,7 +50,6 @@ protected: Vector3f m_velocity; Vector3f m_direction; - std::string m_username; uint64_t id = 0; int m_score = 0; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index b41dff2..bf33ddd 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -118,6 +118,11 @@ Timestamp Connection::Run(World* world) { if (m_input_manifest.size() < 2) return tstamp; + if (player->AmIDead()) { + m_input_manifest.clear(); + return tstamp; + } + while (m_last_in < m_input_vector.size() - 1) { in = m_input_vector.at(m_last_in + 1); last = m_input_vector.at(m_last_in); diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index f277f12..bc33f34 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -203,6 +203,7 @@ void Server::Run() { int x = 0,// (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)),// -(CHUNK_SIZE_X * WORLD_SIZE_X / 2), y = 0;// (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1));// -(CHUNK_SIZE_Y * WORLD_SIZE_Y / 2); conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); + conn->player->m_username = conn->GetName(); m_players[key] = conn->player; Sync sync; sync.position = conn->player->GetPositionAbs(); @@ -230,7 +231,8 @@ void Server::Run() { last = tstamp; sync_acc += tstamp - last; if (sync_acc >= 1000) { - sync_acc -= 1000; + while (sync_acc >= 1000) + sync_acc -= 1000; --timer; std::string str = "Timer: "; Log(str.append(std::to_string(timer).append(" SyncAcc: ").append(std::to_string(sync_acc))), false, false); @@ -269,18 +271,18 @@ void Server::Run() { if (conn->m_nsync) { Timestamp tstamp = conn->Run(m_world); - if (conn->player->AmIDead()) { + if (conn->player->AmIDead() && tstamp) { Chat chat; chat.dest_id = chat.dest_team_id = chat.src_id = 0; std::string killer = m_conns.at(key)->player->GetUsername(); std::string mess = getDeathMessage(conn->player->GetUsername(), killer); - - strcpy(chat.mess, mess.c_str()); + + strcpy(chat.mess, 140, mess.c_str()); + Log("You is dead", false, false); m_chatlog[tstamp] = chat; - ++deadplayers; conn->m_nsync == false; } @@ -434,13 +436,19 @@ std::string Server::getDeathMessage(std::string username, std::string killer) co std::string temp = DEATHMESSAGES.at(rand() % DEATHMESSAGES.size()); size_t ind = temp.find('@'); size_t indk = temp.find('$'); + bool bypass = false; - if (ind < indk) { + if (indk == std::string::npos) + bypass = true; + + if (ind < indk || bypass) { mess.append(temp.substr(0, ind)); mess.append(username); - mess.append(temp.substr(ind + 1, indk)); - mess.append(killer); - mess.append(temp.substr(indk + 1)); + if (!bypass) { + mess.append(temp.substr(ind + 1, indk)); + mess.append(killer); + mess.append(temp.substr(indk + 1)); + } } else { mess.append(temp.substr(0, indk)); diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 4db7aa5..cec5c3a 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -431,6 +431,8 @@ void Engine::DisplayHud(int timer) { // HP Bar float playerHp = m_player.GetHP(); + if (playerHp < 0.) + playerHp == 0; float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f; float hpBarWidthProportion = 0.25f; @@ -720,11 +722,11 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { ss.str(""); fPosY -= charSize; - ss << " Block : "; - if (bloc == BTYPE_LAST) - ss << "Weapon"; - else - ss << (int)bloc; + //ss << " Block : "; + //if (bloc == BTYPE_LAST) + // ss << "Weapon"; + //else + // ss << (int)bloc; PrintText(fPosX, fPosYJump, ss.str()); } @@ -1341,10 +1343,6 @@ void Engine::Render(float elapsedTime) { m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f); fell = true; } - else if (m_player.GetPosition().y < -20.f) { - m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde. - fell = false; - } if (m_networkgame) { // Pour se gerer le paquet. static bool has_synced = false; @@ -1381,7 +1379,8 @@ void Engine::Render(float elapsedTime) { } if (cmod_acc >= 1000) { - cmod_acc -= 1000; + while (cmod_acc >= 1000) + cmod_acc -= 1000; if (!m_chunkmod_manifest.empty()) { ChunkMod* cmod = m_chunkmod_manifest.front(); m_chunkmod_manifest.pop_front();