Remove old method in GameSetup
This commit is contained in:
parent
50aa334912
commit
bd6264b3b0
@ -20,9 +20,9 @@
|
||||
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "modes/capture_the_flag.hpp"
|
||||
#ifdef DEBUG
|
||||
#include "network/network_config.hpp"
|
||||
#endif
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/peer_vote.hpp"
|
||||
#include "network/protocols/server_lobby.hpp"
|
||||
@ -61,79 +61,11 @@ GameSetup::GameSetup()
|
||||
const std::string& server_name = ServerConfig::m_server_name;
|
||||
m_server_name_utf8 = StringUtils::wideToUtf8
|
||||
(StringUtils::xmlDecode(server_name));
|
||||
m_connected_players_count.store(0);
|
||||
m_extra_server_info = -1;
|
||||
m_is_grand_prix.store(false);
|
||||
reset();
|
||||
} // GameSetup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Update and see if any player disconnects.
|
||||
* \param remove_disconnected_players remove the disconnected players,
|
||||
* otherwise eliminate the kart in world, so this function must be called
|
||||
* in main thread.
|
||||
*/
|
||||
void GameSetup::update(bool remove_disconnected_players)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_players_mutex);
|
||||
if (remove_disconnected_players)
|
||||
{
|
||||
m_players.erase(std::remove_if(m_players.begin(), m_players.end(), []
|
||||
(const std::weak_ptr<NetworkPlayerProfile> npp)->bool
|
||||
{
|
||||
return npp.expired();
|
||||
}), m_players.end());
|
||||
m_connected_players_count.store((uint32_t)m_players.size());
|
||||
return;
|
||||
}
|
||||
if (!World::getWorld() ||
|
||||
World::getWorld()->getPhase() < WorldStatus::MUSIC_PHASE)
|
||||
{
|
||||
m_connected_players_count.store((uint32_t)m_players.size());
|
||||
return;
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
int red_count = 0;
|
||||
int blue_count = 0;
|
||||
unsigned total = 0;
|
||||
for (uint8_t i = 0; i < (uint8_t)m_players.size(); i++)
|
||||
{
|
||||
bool disconnected = m_players[i].expired();
|
||||
if (race_manager->getKartInfo(i).getKartTeam() == KART_TEAM_RED &&
|
||||
!disconnected)
|
||||
red_count++;
|
||||
else if (race_manager->getKartInfo(i).getKartTeam() ==
|
||||
KART_TEAM_BLUE && !disconnected)
|
||||
blue_count++;
|
||||
|
||||
if (!disconnected)
|
||||
{
|
||||
total++;
|
||||
continue;
|
||||
}
|
||||
AbstractKart* k = World::getWorld()->getKart(i);
|
||||
if (!k->isEliminated() && !k->hasFinishedRace())
|
||||
{
|
||||
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>
|
||||
(World::getWorld());
|
||||
if (ctf)
|
||||
ctf->loseFlagForKart(k->getWorldKartId());
|
||||
|
||||
World::getWorld()->eliminateKart(i,
|
||||
false/*notify_of_elimination*/);
|
||||
k->setPosition(
|
||||
World::getWorld()->getCurrentNumKarts() + 1);
|
||||
k->finishedRace(World::getWorld()->getTime(), true/*from_server*/);
|
||||
}
|
||||
}
|
||||
m_connected_players_count.store(total);
|
||||
|
||||
if (m_players.size() != 1 && World::getWorld()->hasTeam() &&
|
||||
(red_count == 0 || blue_count == 0))
|
||||
World::getWorld()->setUnfairTeam(true);
|
||||
} // removePlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void GameSetup::loadWorld()
|
||||
{
|
||||
@ -183,7 +115,9 @@ void GameSetup::loadWorld()
|
||||
//-----------------------------------------------------------------------------
|
||||
void GameSetup::addServerInfo(NetworkString* ns)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
assert(NetworkConfig::get()->isServer());
|
||||
#endif
|
||||
ns->encodeString(m_server_name_utf8);
|
||||
auto sl = LobbyProtocol::get<ServerLobby>();
|
||||
assert(sl);
|
||||
@ -271,25 +205,6 @@ void GameSetup::sortPlayersForGame(
|
||||
}
|
||||
} // sortPlayersForGame
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::pair<int, int> GameSetup::getPlayerTeamInfo() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||
int red_count = 0;
|
||||
int blue_count = 0;
|
||||
for (auto& p : m_players)
|
||||
{
|
||||
auto player = p.lock();
|
||||
if (!player)
|
||||
continue;
|
||||
if (player->getTeam() == KART_TEAM_RED)
|
||||
red_count++;
|
||||
else if (player->getTeam() == KART_TEAM_BLUE)
|
||||
blue_count++;
|
||||
}
|
||||
return std::make_pair(red_count, blue_count);
|
||||
} // getPlayerTeamInfo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GameSetup::setRace(const PeerVote &vote)
|
||||
{
|
||||
|
@ -22,14 +22,12 @@
|
||||
#ifndef GAME_SETUP_HPP
|
||||
#define GAME_SETUP_HPP
|
||||
|
||||
#include "network/remote_kart_info.hpp"
|
||||
#include <irrString.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class NetworkPlayerProfile;
|
||||
@ -44,11 +42,6 @@ class PeerVote;
|
||||
class GameSetup
|
||||
{
|
||||
private:
|
||||
mutable std::mutex m_players_mutex;
|
||||
|
||||
/** Information about all connected players. */
|
||||
std::vector<std::weak_ptr<NetworkPlayerProfile> > m_players;
|
||||
|
||||
std::vector<std::string> m_tracks;
|
||||
|
||||
unsigned m_laps;
|
||||
@ -63,8 +56,6 @@ private:
|
||||
|
||||
std::atomic_bool m_is_grand_prix;
|
||||
|
||||
std::atomic<uint32_t> m_connected_players_count;
|
||||
|
||||
irr::core::stringw m_message_of_today;
|
||||
|
||||
/** Utf8 server name (with xml decoded) */
|
||||
@ -76,39 +67,6 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
~GameSetup() {}
|
||||
// ------------------------------------------------------------------------
|
||||
void addPlayer(std::shared_ptr<NetworkPlayerProfile> profile)
|
||||
{ m_players.push_back(profile); }
|
||||
// ------------------------------------------------------------------------
|
||||
void update(bool remove_disconnected_players);
|
||||
// ------------------------------------------------------------------------
|
||||
/** \brief Get the players that are / were in the game
|
||||
* \return A vector containing pointers on the players profiles. */
|
||||
const std::vector<std::weak_ptr<NetworkPlayerProfile> >& getPlayers() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||
return m_players;
|
||||
} // getPlayers
|
||||
// ------------------------------------------------------------------------
|
||||
/** \brief Get the players that are in the game
|
||||
* \return A vector containing pointers on the players profiles. */
|
||||
std::vector<std::shared_ptr<NetworkPlayerProfile> >
|
||||
getConnectedPlayers(bool same_offset = false) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||
std::vector<std::shared_ptr<NetworkPlayerProfile> > players;
|
||||
for (auto player_weak : m_players)
|
||||
{
|
||||
if (auto player_connected = player_weak.lock())
|
||||
players.push_back(player_connected);
|
||||
else if (same_offset)
|
||||
players.push_back(nullptr);
|
||||
}
|
||||
return players;
|
||||
} // getConnectedPlayers
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of connected players. */
|
||||
unsigned getPlayerCount() { return m_connected_players_count.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void setRace(const PeerVote &vote);
|
||||
// ------------------------------------------------------------------------
|
||||
void reset()
|
||||
@ -183,8 +141,6 @@ public:
|
||||
m_battle_time_limit = time;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
std::pair<int, int> getPlayerTeamInfo() const;
|
||||
// ------------------------------------------------------------------------
|
||||
const std::string& getServerNameUtf8() const { return m_server_name_utf8; }
|
||||
};
|
||||
|
||||
|
@ -237,7 +237,6 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
|
||||
std::shared_ptr<STKPeer> peer = event->getPeerSP();
|
||||
peer->cleanPlayerProfiles();
|
||||
m_game_setup->update(true/*remove_disconnected_players*/);
|
||||
std::vector<std::shared_ptr<NetworkPlayerProfile> > players;
|
||||
unsigned player_count = data.getUInt8();
|
||||
|
||||
@ -256,8 +255,6 @@ void ClientLobby::addAllPlayers(Event* event)
|
||||
std::string kart_name;
|
||||
data.decodeString(&kart_name);
|
||||
player->setKartName(kart_name);
|
||||
peer->addPlayer(player);
|
||||
m_game_setup->addPlayer(player);
|
||||
players.push_back(player);
|
||||
}
|
||||
uint32_t random_seed = data.getUInt32();
|
||||
|
@ -490,8 +490,8 @@ void ServerLobby::asynchronousUpdate()
|
||||
{
|
||||
if (ServerConfig::m_owner_less)
|
||||
{
|
||||
m_game_setup->update(true/*remove_disconnected_players*/);
|
||||
int player_size = STKHost::get()->getPlayersInGame();
|
||||
int player_size =
|
||||
(int)STKHost::get()->updateConnectedPlayersInGame();
|
||||
if ((player_size >= ServerConfig::m_min_start_game_players ||
|
||||
m_game_setup->isGrandPrixStarted()) &&
|
||||
m_timeout.load() == std::numeric_limits<int64_t>::max())
|
||||
@ -1835,7 +1835,6 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
|
||||
for (std::shared_ptr<NetworkPlayerProfile>& npp :
|
||||
peer->getPlayerProfiles())
|
||||
{
|
||||
m_game_setup->addPlayer(npp);
|
||||
Log::info("ServerLobby",
|
||||
"New player %s with online id %u from %s with %s.",
|
||||
StringUtils::wideToUtf8(npp->getName()).c_str(),
|
||||
@ -2701,7 +2700,6 @@ void ServerLobby::addWaitingPlayersToGame()
|
||||
|
||||
peer->setWaitingForGame(false);
|
||||
m_peers_ready[peer] = false;
|
||||
m_game_setup->addPlayer(npp);
|
||||
Log::info("ServerLobby", "New player %s with online id %u from %s.",
|
||||
StringUtils::wideToUtf8(npp->getName()).c_str(),
|
||||
npp->getOnlineId(), peer->getAddress().toString().c_str());
|
||||
|
@ -1340,7 +1340,7 @@ std::vector<std::shared_ptr<NetworkPlayerProfile> >
|
||||
} // getPlayersForNewGame
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKHost::updateConnectedPlayersInGame()
|
||||
uint32_t STKHost::updateConnectedPlayersInGame()
|
||||
{
|
||||
uint32_t total = 0;
|
||||
std::lock_guard<std::mutex> lock(m_peers_mutex);
|
||||
@ -1352,4 +1352,5 @@ void STKHost::updateConnectedPlayersInGame()
|
||||
total += (uint32_t)stk_peer->getPlayerProfiles().size();
|
||||
}
|
||||
m_players_in_game.store(total);
|
||||
return total;
|
||||
} // updateConnectedPlayersInGame
|
||||
|
@ -352,7 +352,7 @@ public:
|
||||
/* Return download speed in bytes per second. */
|
||||
unsigned getDownloadSpeed() const { return m_download_speed.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void updateConnectedPlayersInGame();
|
||||
uint32_t updateConnectedPlayersInGame();
|
||||
// ------------------------------------------------------------------------
|
||||
uint32_t getPlayersInGame() const { return m_players_in_game.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user