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));
#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(),

View File

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

View File

@ -99,7 +99,7 @@ void LobbyProtocol::configRemoteKart(
// -------------------------------------------------
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();
// 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

View File

@ -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<double> scores_change;
std::vector<double> 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();

View File

@ -22,6 +22,7 @@
#ifndef HEADER_REMOTE_KART_INFO_HPP
#define HEADER_REMOTE_KART_INFO_HPP
#include <memory>
#include <string>
#include <vector>
#include <irrString.h>
@ -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<NetworkPlayerProfile> 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<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
{
return ((m_host_id<other.m_host_id) ||