Removed earlier end of voting when majority agrees, but instead
start immediately when all votes are in.
This commit is contained in:
parent
0da03e14ca
commit
65dc27a3c8
@ -492,12 +492,8 @@ void ServerLobby::asynchronousUpdate()
|
|||||||
std::string track_name;
|
std::string track_name;
|
||||||
int num_laps;
|
int num_laps;
|
||||||
bool reverse;
|
bool reverse;
|
||||||
auto result = handleVote(&track_name, &num_laps, &reverse);
|
bool all_votes_in = handleAllVotes(&track_name, &num_laps, &reverse);
|
||||||
if (isVotingOver() ||
|
if (isVotingOver() || all_votes_in)
|
||||||
(std::get<0>(result) &&
|
|
||||||
m_timeout.load() -
|
|
||||||
(int64_t)(ServerConfig::m_voting_timeout / 2.0f * 1000.0f) <
|
|
||||||
(int64_t)StkTime::getRealTimeMs()))
|
|
||||||
{
|
{
|
||||||
m_game_setup->setRace(track_name, num_laps, reverse);
|
m_game_setup->setRace(track_name, num_laps, reverse);
|
||||||
// Remove disconnected player (if any) one last time
|
// Remove disconnected player (if any) one last time
|
||||||
@ -1895,13 +1891,14 @@ void ServerLobby::playerVote(Event* event)
|
|||||||
} // playerVote
|
} // playerVote
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Returns the information about a current vote.
|
/** Select the track to be used based on all votes being received.
|
||||||
* \param track_name Name of the track voted for.
|
* \param track_name Name of the track voted for.
|
||||||
* \param num_laps Number of laps.
|
* \param num_laps Number of laps.
|
||||||
* \param reverse If reverse track is to be used.
|
* \param reverse If reverse track is to be used.
|
||||||
|
* \result True if a vote from each player has been received, false otherwise.
|
||||||
*/
|
*/
|
||||||
std::tuple<bool> ServerLobby::handleVote(std::string *track_name,
|
bool ServerLobby::handleAllVotes(std::string *track_name, int *num_laps,
|
||||||
int *num_laps, bool *reverse)
|
bool *reverse)
|
||||||
{
|
{
|
||||||
// Default settings if no votes at all
|
// Default settings if no votes at all
|
||||||
RandomGenerator rg;
|
RandomGenerator rg;
|
||||||
@ -1912,19 +1909,15 @@ std::tuple<bool> ServerLobby::handleVote(std::string *track_name,
|
|||||||
*reverse = track_name->size() % 2 == 0;
|
*reverse = track_name->size() % 2 == 0;
|
||||||
|
|
||||||
|
|
||||||
float cur_players = 0.0f;
|
int cur_players = 0;
|
||||||
auto peers = STKHost::get()->getPeers();
|
auto peers = STKHost::get()->getPeers();
|
||||||
for (auto peer : peers)
|
for (auto peer : peers)
|
||||||
{
|
{
|
||||||
if (peer->hasPlayerProfiles() && !peer->isWaitingForGame())
|
if (peer->hasPlayerProfiles() && !peer->isWaitingForGame())
|
||||||
cur_players += 1.0f;
|
cur_players ++;
|
||||||
}
|
}
|
||||||
if (cur_players == 0.0f)
|
if (cur_players == 0) return false;
|
||||||
return std::make_tuple(false);
|
|
||||||
|
|
||||||
float tracks_rate = 0.0f;
|
|
||||||
float laps_rate = 0.0f;
|
|
||||||
float reverses_rate = 0.0f;
|
|
||||||
std::map<std::string, unsigned> tracks;
|
std::map<std::string, unsigned> tracks;
|
||||||
std::map<unsigned, unsigned> laps;
|
std::map<unsigned, unsigned> laps;
|
||||||
std::map<bool, unsigned> reverses;
|
std::map<bool, unsigned> reverses;
|
||||||
@ -1963,7 +1956,6 @@ std::tuple<bool> ServerLobby::handleVote(std::string *track_name,
|
|||||||
if (track_vote != tracks.end())
|
if (track_vote != tracks.end())
|
||||||
{
|
{
|
||||||
*track_name = track_vote->first;
|
*track_name = track_vote->first;
|
||||||
tracks_rate = float(track_vote->second) / cur_players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vote = 0;
|
vote = 0;
|
||||||
@ -1979,7 +1971,6 @@ std::tuple<bool> ServerLobby::handleVote(std::string *track_name,
|
|||||||
if (lap_vote != laps.end())
|
if (lap_vote != laps.end())
|
||||||
{
|
{
|
||||||
*num_laps = lap_vote->first;
|
*num_laps = lap_vote->first;
|
||||||
laps_rate = float(lap_vote->second) / cur_players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vote = 0;
|
vote = 0;
|
||||||
@ -1995,12 +1986,10 @@ std::tuple<bool> ServerLobby::handleVote(std::string *track_name,
|
|||||||
if (reverse_vote != reverses.end())
|
if (reverse_vote != reverses.end())
|
||||||
{
|
{
|
||||||
*reverse = reverse_vote->first;
|
*reverse = reverse_vote->first;
|
||||||
reverses_rate = float(reverse_vote->second) / cur_players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_tuple(tracks_rate > 0.5f &&
|
return m_peers_votes.size() == cur_players;
|
||||||
laps_rate > 0.5f && reverses_rate > 0.5f );
|
} // handleAllVotes
|
||||||
} // handleVote
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::pair<int, float> ServerLobby::getHitCaptureLimit(float num_karts)
|
std::pair<int, float> ServerLobby::getHitCaptureLimit(float num_karts)
|
||||||
|
@ -238,8 +238,8 @@ private:
|
|||||||
const std::string& iv,
|
const std::string& iv,
|
||||||
uint32_t online_id,
|
uint32_t online_id,
|
||||||
const irr::core::stringw& online_name);
|
const irr::core::stringw& online_name);
|
||||||
std::tuple<bool> handleVote(std::string *track_name,
|
bool handleAllVotes(std::string *track_name, int *num_laps,
|
||||||
int *num_laps, bool *reverse);
|
bool *reverse);
|
||||||
void getRankingForPlayer(std::shared_ptr<NetworkPlayerProfile> p);
|
void getRankingForPlayer(std::shared_ptr<NetworkPlayerProfile> p);
|
||||||
void submitRankingsToAddons();
|
void submitRankingsToAddons();
|
||||||
void computeNewRankings();
|
void computeNewRankings();
|
||||||
|
Loading…
Reference in New Issue
Block a user