From 346f763cef0ffc51980042fa78a4329efa945304 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 29 Dec 2018 15:53:12 +0800 Subject: [PATCH] Save grand prix scores in server with new method --- src/karts/kart.cpp | 8 +++++--- src/karts/kart.hpp | 8 +++++--- src/network/protocols/lobby_protocol.cpp | 3 ++- src/network/protocols/server_lobby.cpp | 20 ++++++++++---------- src/network/remote_kart_info.hpp | 10 +++++++++- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 93c5d1cc9..be39241e3 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2960,15 +2960,17 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model) m_slipstream.reset(new SlipStream(this)); +#ifndef SERVER_ONLY m_skidmarks = nullptr; m_shadow = nullptr; -#ifndef SERVER_ONLY - if (m_kart_properties->getSkidEnabled() && CVS->isGLSL()) + if (!ProfileWorld::isNoGraphics() && + m_kart_properties->getSkidEnabled() && CVS->isGLSL()) { m_skidmarks.reset(new SkidMarks(*this)); } - if (CVS->isGLSL() && !CVS->isShadowEnabled() && m_kart_properties + if (!ProfileWorld::isNoGraphics() && + CVS->isGLSL() && !CVS->isShadowEnabled() && m_kart_properties ->getShadowMaterial()->getSamplerPath(0) != "unicolor_white") { m_shadow.reset(new Shadow(m_kart_properties->getShadowMaterial(), diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 144e198ae..2cffd7dc3 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -120,18 +120,20 @@ protected: // Graphical effects // ----------------- +#ifndef SERVER_ONLY /** The shadow of a kart. */ std::unique_ptr m_shadow; + /** The skidmarks object for this kart. */ + std::unique_ptr m_skidmarks; +#endif + /** All particle effects. */ std::unique_ptr m_kart_gfx; /** Handles all slipstreaming. */ std::unique_ptr m_slipstream; - /** The skidmarks object for this kart. */ - std::unique_ptr m_skidmarks; - // Bullet physics parameters // ------------------------- struct btCompoundShapeDeleter diff --git a/src/network/protocols/lobby_protocol.cpp b/src/network/protocols/lobby_protocol.cpp index a849ae4c9..ffe5f821c 100644 --- a/src/network/protocols/lobby_protocol.cpp +++ b/src/network/protocols/lobby_protocol.cpp @@ -99,7 +99,7 @@ void LobbyProtocol::configRemoteKart( // ------------------------------------------------- for (unsigned int i = 0; i < players.size(); i++) { - std::shared_ptr profile = players[i]; + const std::shared_ptr& profile = players[i]; bool is_local = profile->isLocalPlayer(); // All non-local players are created here. This means all players @@ -128,6 +128,7 @@ void LobbyProtocol::configRemoteKart( rki.setOnlineId(profile->getOnlineId()); if (race_manager->teamEnabled()) rki.setKartTeam(profile->getTeam()); + rki.setNetworkPlayerProfile(profile); // Inform the race manager about the data for this kart. race_manager->setPlayerKart(i, rki); } // for i in players diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 1dab67303..2de95d453 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -1225,14 +1225,14 @@ void ServerLobby::checkRaceFinished() m_result_ns->encodeString(gp_track); // each kart score and total time - auto& players = m_game_setup->getPlayers(); - m_result_ns->addUInt8((uint8_t)players.size()); - for (unsigned i = 0; i < players.size(); i++) + m_result_ns->addUInt8((uint8_t)race_manager->getNumPlayers()); + for (unsigned i = 0; i < race_manager->getNumPlayers(); i++) { int last_score = race_manager->getKartScore(i); int cur_score = last_score; float overall_time = race_manager->getOverallTime(i); - if (auto player = players[i].lock()) + if (auto player = + race_manager->getKartInfo(i).getNetworkPlayerProfile().lock()) { last_score = player->getScore(); cur_score += last_score; @@ -1273,8 +1273,8 @@ void ServerLobby::computeNewRankings() std::vector scores_change; std::vector new_scores; - auto players = m_game_setup->getConnectedPlayers(true/*same_offset*/); - for (unsigned i = 0; i < players.size(); i++) + unsigned player_count = race_manager->getNumPlayers(); + for (unsigned i = 0; i < player_count; i++) { const uint32_t id = race_manager->getKartInfo(i).getOnlineId(); new_scores.push_back(m_scores.at(id)); @@ -1282,14 +1282,14 @@ void ServerLobby::computeNewRankings() } // First, update the number of ranked races - for (unsigned i = 0; i < players.size(); i++) + for (unsigned i = 0; i < player_count; i++) { const uint32_t id = race_manager->getKartInfo(i).getOnlineId(); m_num_ranked_races.at(id)++; } // Now compute points exchanges - for (unsigned i = 0; i < players.size(); i++) + for (unsigned i = 0; i < player_count; i++) { scores_change.push_back(0.0); @@ -1302,7 +1302,7 @@ void ServerLobby::computeNewRankings() double player1_factor = computeRankingFactor(race_manager->getKartInfo(i).getOnlineId()); - for (unsigned j = 0; j < players.size(); j++) + for (unsigned j = 0; j < player_count; j++) { // Don't compare a player with himself if (i == j) @@ -1373,7 +1373,7 @@ void ServerLobby::computeNewRankings() } // Don't merge it in the main loop as new_scores value are used there - for (unsigned i = 0; i < players.size(); i++) + for (unsigned i = 0; i < player_count; i++) { new_scores[i] += scores_change[i]; const uint32_t id = race_manager->getKartInfo(i).getOnlineId(); diff --git a/src/network/remote_kart_info.hpp b/src/network/remote_kart_info.hpp index 4c0e4b1ee..c688dfb09 100644 --- a/src/network/remote_kart_info.hpp +++ b/src/network/remote_kart_info.hpp @@ -22,6 +22,7 @@ #ifndef HEADER_REMOTE_KART_INFO_HPP #define HEADER_REMOTE_KART_INFO_HPP +#include #include #include #include @@ -41,6 +42,8 @@ enum PerPlayerDifficulty : uint8_t PLAYER_DIFFICULTY_COUNT }; +class NetworkPlayerProfile; + class RemoteKartInfo { std::string m_kart_name; @@ -53,6 +56,7 @@ class RemoteKartInfo PerPlayerDifficulty m_difficulty; float m_default_kart_color; uint32_t m_online_id; + std::weak_ptr m_profile; public: RemoteKartInfo(int player_id, const std::string& kart_name, const irr::core::stringw& user_name, int host_id, @@ -99,7 +103,11 @@ public: PerPlayerDifficulty getDifficulty() const { return m_difficulty; } float getDefaultKartColor() const { return m_default_kart_color; } uint32_t getOnlineId() const { return m_online_id; } - + void setNetworkPlayerProfile( + std::weak_ptr npp) { m_profile = npp; } + std::weak_ptr getNetworkPlayerProfile() const + { return m_profile; } + bool disconnected() const { return m_profile.expired(); } bool operator<(const RemoteKartInfo& other) const { return ((m_host_id