Save grand prix scores in server with new method

This commit is contained in:
Benau 2018-12-29 15:53:12 +08:00
parent c6b3fba304
commit 346f763cef
5 changed files with 31 additions and 18 deletions

View File

@ -2960,15 +2960,17 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
m_slipstream.reset(new SlipStream(this)); m_slipstream.reset(new SlipStream(this));
#ifndef SERVER_ONLY
m_skidmarks = nullptr; m_skidmarks = nullptr;
m_shadow = nullptr; m_shadow = nullptr;
#ifndef SERVER_ONLY if (!ProfileWorld::isNoGraphics() &&
if (m_kart_properties->getSkidEnabled() && CVS->isGLSL()) m_kart_properties->getSkidEnabled() && CVS->isGLSL())
{ {
m_skidmarks.reset(new SkidMarks(*this)); 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") ->getShadowMaterial()->getSamplerPath(0) != "unicolor_white")
{ {
m_shadow.reset(new Shadow(m_kart_properties->getShadowMaterial(), m_shadow.reset(new Shadow(m_kart_properties->getShadowMaterial(),

View File

@ -120,18 +120,20 @@ protected:
// Graphical effects // Graphical effects
// ----------------- // -----------------
#ifndef SERVER_ONLY
/** The shadow of a kart. */ /** The shadow of a kart. */
std::unique_ptr<Shadow> m_shadow; std::unique_ptr<Shadow> m_shadow;
/** The skidmarks object for this kart. */
std::unique_ptr<SkidMarks> m_skidmarks;
#endif
/** All particle effects. */ /** All particle effects. */
std::unique_ptr<KartGFX> m_kart_gfx; std::unique_ptr<KartGFX> m_kart_gfx;
/** Handles all slipstreaming. */ /** Handles all slipstreaming. */
std::unique_ptr<SlipStream> m_slipstream; std::unique_ptr<SlipStream> m_slipstream;
/** The skidmarks object for this kart. */
std::unique_ptr<SkidMarks> m_skidmarks;
// Bullet physics parameters // Bullet physics parameters
// ------------------------- // -------------------------
struct btCompoundShapeDeleter struct btCompoundShapeDeleter

View File

@ -99,7 +99,7 @@ void LobbyProtocol::configRemoteKart(
// ------------------------------------------------- // -------------------------------------------------
for (unsigned int i = 0; i < players.size(); i++) for (unsigned int i = 0; i < players.size(); i++)
{ {
std::shared_ptr<NetworkPlayerProfile> profile = players[i]; const std::shared_ptr<NetworkPlayerProfile>& profile = players[i];
bool is_local = profile->isLocalPlayer(); bool is_local = profile->isLocalPlayer();
// All non-local players are created here. This means all players // All non-local players are created here. This means all players
@ -128,6 +128,7 @@ void LobbyProtocol::configRemoteKart(
rki.setOnlineId(profile->getOnlineId()); rki.setOnlineId(profile->getOnlineId());
if (race_manager->teamEnabled()) if (race_manager->teamEnabled())
rki.setKartTeam(profile->getTeam()); rki.setKartTeam(profile->getTeam());
rki.setNetworkPlayerProfile(profile);
// Inform the race manager about the data for this kart. // Inform the race manager about the data for this kart.
race_manager->setPlayerKart(i, rki); race_manager->setPlayerKart(i, rki);
} // for i in players } // for i in players

View File

@ -1225,14 +1225,14 @@ void ServerLobby::checkRaceFinished()
m_result_ns->encodeString(gp_track); m_result_ns->encodeString(gp_track);
// each kart score and total time // each kart score and total time
auto& players = m_game_setup->getPlayers(); m_result_ns->addUInt8((uint8_t)race_manager->getNumPlayers());
m_result_ns->addUInt8((uint8_t)players.size()); for (unsigned i = 0; i < race_manager->getNumPlayers(); i++)
for (unsigned i = 0; i < players.size(); i++)
{ {
int last_score = race_manager->getKartScore(i); int last_score = race_manager->getKartScore(i);
int cur_score = last_score; int cur_score = last_score;
float overall_time = race_manager->getOverallTime(i); 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(); last_score = player->getScore();
cur_score += last_score; cur_score += last_score;
@ -1273,8 +1273,8 @@ void ServerLobby::computeNewRankings()
std::vector<double> scores_change; std::vector<double> scores_change;
std::vector<double> new_scores; std::vector<double> new_scores;
auto players = m_game_setup->getConnectedPlayers(true/*same_offset*/); unsigned player_count = race_manager->getNumPlayers();
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(); const uint32_t id = race_manager->getKartInfo(i).getOnlineId();
new_scores.push_back(m_scores.at(id)); new_scores.push_back(m_scores.at(id));
@ -1282,14 +1282,14 @@ void ServerLobby::computeNewRankings()
} }
// First, update the number of ranked races // 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(); const uint32_t id = race_manager->getKartInfo(i).getOnlineId();
m_num_ranked_races.at(id)++; m_num_ranked_races.at(id)++;
} }
// Now compute points exchanges // 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); scores_change.push_back(0.0);
@ -1302,7 +1302,7 @@ void ServerLobby::computeNewRankings()
double player1_factor = double player1_factor =
computeRankingFactor(race_manager->getKartInfo(i).getOnlineId()); 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 // Don't compare a player with himself
if (i == j) 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 // 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]; new_scores[i] += scores_change[i];
const uint32_t id = race_manager->getKartInfo(i).getOnlineId(); const uint32_t id = race_manager->getKartInfo(i).getOnlineId();

View File

@ -22,6 +22,7 @@
#ifndef HEADER_REMOTE_KART_INFO_HPP #ifndef HEADER_REMOTE_KART_INFO_HPP
#define HEADER_REMOTE_KART_INFO_HPP #define HEADER_REMOTE_KART_INFO_HPP
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <irrString.h> #include <irrString.h>
@ -41,6 +42,8 @@ enum PerPlayerDifficulty : uint8_t
PLAYER_DIFFICULTY_COUNT PLAYER_DIFFICULTY_COUNT
}; };
class NetworkPlayerProfile;
class RemoteKartInfo class RemoteKartInfo
{ {
std::string m_kart_name; std::string m_kart_name;
@ -53,6 +56,7 @@ class RemoteKartInfo
PerPlayerDifficulty m_difficulty; PerPlayerDifficulty m_difficulty;
float m_default_kart_color; float m_default_kart_color;
uint32_t m_online_id; uint32_t m_online_id;
std::weak_ptr<NetworkPlayerProfile> m_profile;
public: public:
RemoteKartInfo(int player_id, const std::string& kart_name, RemoteKartInfo(int player_id, const std::string& kart_name,
const irr::core::stringw& user_name, int host_id, const irr::core::stringw& user_name, int host_id,
@ -99,7 +103,11 @@ public:
PerPlayerDifficulty getDifficulty() const { return m_difficulty; } PerPlayerDifficulty getDifficulty() const { return m_difficulty; }
float getDefaultKartColor() const { return m_default_kart_color; } float getDefaultKartColor() const { return m_default_kart_color; }
uint32_t getOnlineId() const { return m_online_id; } uint32_t getOnlineId() const { return m_online_id; }
void setNetworkPlayerProfile(
std::weak_ptr<NetworkPlayerProfile> npp) { m_profile = npp; }
std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const
{ return m_profile; }
bool disconnected() const { return m_profile.expired(); }
bool operator<(const RemoteKartInfo& other) const bool operator<(const RemoteKartInfo& other) const
{ {
return ((m_host_id<other.m_host_id) || return ((m_host_id<other.m_host_id) ||