Renamed getPlayerID() to getGlobalPlayerId(); started to refactor
StartGameProtocol.
This commit is contained in:
parent
801f6961cf
commit
c1560ddb02
@ -52,7 +52,7 @@ void GameSetup::addPlayer(NetworkPlayerProfile* profile)
|
||||
{
|
||||
m_players.push_back(profile);
|
||||
Log::info("GameSetup", "New player in the game setup. Race id : %d.",
|
||||
profile->getPlayerID());
|
||||
profile->getGlobalPlayerId());
|
||||
} // addPlayer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -106,7 +106,7 @@ void GameSetup::setPlayerKart(uint8_t player_id, const std::string &kart_name)
|
||||
bool found = false;
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->getPlayerID() == player_id)
|
||||
if (m_players[i]->getGlobalPlayerId() == player_id)
|
||||
{
|
||||
m_players[i]->setKartName(kart_name);
|
||||
Log::info("GameSetup::setPlayerKart", "Player %d took kart %s",
|
||||
@ -130,7 +130,8 @@ void GameSetup::bindKartsToProfiles()
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
Log::info("GameSetup", "Player %d has id %d and kart %s", i,
|
||||
m_players[i]->getPlayerID(), m_players[i]->getKartName().c_str());
|
||||
m_players[i]->getGlobalPlayerId(),
|
||||
m_players[i]->getKartName().c_str());
|
||||
}
|
||||
for (unsigned int i = 0; i < karts.size(); i++)
|
||||
{
|
||||
@ -166,7 +167,7 @@ const NetworkPlayerProfile* GameSetup::getProfile(uint8_t player_id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
if (m_players[i]->getPlayerID()== player_id)
|
||||
if (m_players[i]->getGlobalPlayerId()== player_id)
|
||||
{
|
||||
return m_players[i];
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
NetworkPlayerProfile::NetworkPlayerProfile(int race_player_id,
|
||||
const irr::core::stringw &name)
|
||||
{
|
||||
m_race_player_id = race_player_id;
|
||||
m_global_player_id = race_player_id;
|
||||
m_kart_name = "";
|
||||
m_world_kart_id = 0;
|
||||
m_per_player_difficulty = PLAYER_DIFFICULTY_NORMAL;
|
||||
|
@ -40,7 +40,7 @@ private:
|
||||
/** The unique id of the player for this race. The number is assigned
|
||||
* by the server (and it might not be the index of this player in the
|
||||
* peer list. */
|
||||
uint8_t m_race_player_id;
|
||||
uint8_t m_global_player_id;
|
||||
|
||||
/** The selected kart id. */
|
||||
std::string m_kart_name;
|
||||
@ -59,11 +59,11 @@ public:
|
||||
~NetworkPlayerProfile();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the player id of this player. */
|
||||
void setPlayerID(int player_id) { m_race_player_id = player_id; }
|
||||
/** Sets the global player id of this player. */
|
||||
void setGlobalPlayerId(int player_id) { m_global_player_id = player_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the loca ID of this player in this race. */
|
||||
int getPlayerID() const { return m_race_player_id; }
|
||||
/** Returns the global ID of this player in this race. */
|
||||
int getGlobalPlayerId() const { return m_global_player_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the kart name for this player. */
|
||||
void setKartName(const std::string &kart_name) { m_kart_name = kart_name; }
|
||||
|
@ -105,7 +105,7 @@ void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
||||
+ (kart->getPowerup()->getNum() & 0x0f);
|
||||
|
||||
ns.ai8(0x01).ai32(item->getItemId()).ai8(powerup)
|
||||
.ai8(player_profile->getPlayerID());
|
||||
.ai8(player_profile->getGlobalPlayerId());
|
||||
ProtocolManager::getInstance()->sendMessage(this, peers[i], ns,
|
||||
/*reliable*/true);
|
||||
Log::info("GameEventsProtocol",
|
||||
|
@ -396,10 +396,10 @@ void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
|
||||
{
|
||||
NetworkString msg(3);
|
||||
msg.ai8(LE_PLAYER_DISCONNECTED).ai8(1)
|
||||
.ai8(peer->getPlayerProfile()->getPlayerID());
|
||||
.ai8(peer->getPlayerProfile()->getGlobalPlayerId());
|
||||
sendMessage(msg);
|
||||
Log::info("ServerLobbyRoomProtocol", "Player disconnected : id %d",
|
||||
peer->getPlayerProfile()->getPlayerID());
|
||||
peer->getPlayerProfile()->getGlobalPlayerId());
|
||||
m_setup->removePlayer(peer->getPlayerProfile());
|
||||
// Remove the profile from the peer (to avoid double free)
|
||||
peer->setPlayerProfile(NULL);
|
||||
@ -483,7 +483,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
// to the list of players later, so the new player's info is not included)
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
message_ack.ai8(1).ai8(players[i]->getPlayerID())
|
||||
message_ack.ai8(1).ai8(players[i]->getGlobalPlayerId())
|
||||
.encodeString(players[i]->getName());
|
||||
}
|
||||
sendMessage(peer, message_ack);
|
||||
@ -555,7 +555,7 @@ void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
|
||||
// send a kart update to everyone
|
||||
NetworkString answer(3+1+kart_name.size());
|
||||
// kart update (3), 1, race id
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
answer.ai8(LE_KART_SELECTION_UPDATE).ai8(1).ai8(player_id)
|
||||
.encodeString(kart_name);
|
||||
sendMessage(answer);
|
||||
@ -582,7 +582,7 @@ void ServerLobbyRoomProtocol::playerMajorVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 4))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
uint32_t major = data.getUInt32(6);
|
||||
m_setup->getRaceConfig()->setPlayerMajorVote(player_id, major);
|
||||
// Send the vote to everybody (including the sender)
|
||||
@ -615,7 +615,7 @@ void ServerLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
m_setup->getRaceConfig()->setPlayerRaceCountVote(player_id, data[6]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -647,7 +647,7 @@ void ServerLobbyRoomProtocol::playerMinorVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 5, 4))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
uint32_t minor = data.getUInt32(6);
|
||||
m_setup->getRaceConfig()->setPlayerMinorVote(player_id, minor);
|
||||
// Send the vote to everybody (including the sender)
|
||||
@ -682,7 +682,7 @@ void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
|
||||
int N = data.decodeString(5, &track_name);
|
||||
if (!isByteCorrect(event, N+5, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
m_setup->getRaceConfig()->setPlayerTrackVote(player_id, track_name, data[N+6]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
@ -718,7 +718,7 @@ void ServerLobbyRoomProtocol::playerReversedVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 7, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
m_setup->getRaceConfig()->setPlayerReversedVote(player_id,
|
||||
data[6]!=0, data[8]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
@ -753,7 +753,7 @@ void ServerLobbyRoomProtocol::playerLapsVote(Event* event)
|
||||
return;
|
||||
if (!isByteCorrect(event, 7, 1))
|
||||
return;
|
||||
uint8_t player_id = peer->getPlayerProfile()->getPlayerID();
|
||||
uint8_t player_id = peer->getPlayerProfile()->getGlobalPlayerId();
|
||||
m_setup->getRaceConfig()->setPlayerLapsVote(player_id, data[6], data[8]);
|
||||
// Send the vote to everybody (including the sender)
|
||||
data.removeFront(5); // remove the token
|
||||
|
@ -41,12 +41,28 @@ StartGameProtocol::~StartGameProtocol()
|
||||
} // ~StartGameProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Setup the actual game. It first starts the SynchronisationProtocol,
|
||||
* and then
|
||||
*/
|
||||
void StartGameProtocol::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
m_ready_count = 0;
|
||||
m_ready = false;
|
||||
Log::info("SynchronizationProtocol", "Ready !");
|
||||
|
||||
Protocol *p = new SynchronizationProtocol();
|
||||
p->requestStart();
|
||||
Log::info("StartGameProtocol", "SynchronizationProtocol started.");
|
||||
|
||||
// Race startup sequence
|
||||
// ---------------------
|
||||
// builds it and starts
|
||||
NetworkWorld::getInstance<NetworkWorld>()->start();
|
||||
race_manager->setNumKarts(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumPlayers(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumLocalPlayers(1);
|
||||
|
||||
} // setup
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -101,7 +117,7 @@ bool StartGameProtocol::notifyEventAsynchronous(Event* event)
|
||||
// ----------------------------------------------------------------------------
|
||||
bool compareKarts(NetworkPlayerProfile* a, NetworkPlayerProfile* b)
|
||||
{
|
||||
return (a->getPlayerID() < b->getPlayerID());
|
||||
return (a->getGlobalPlayerId() < b->getGlobalPlayerId());
|
||||
} // compareKarts
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -109,34 +125,23 @@ void StartGameProtocol::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
Protocol *p = new SynchronizationProtocol();
|
||||
p->requestStart();
|
||||
Log::info("StartGameProtocol", "SynchronizationProtocol started.");
|
||||
|
||||
// Race startup sequence
|
||||
// ---------------------
|
||||
// builds it and starts
|
||||
NetworkWorld::getInstance<NetworkWorld>()->start();
|
||||
race_manager->setNumKarts(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumPlayers(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumLocalPlayers(1);
|
||||
std::vector<NetworkPlayerProfile*> players = m_game_setup->getPlayers();
|
||||
std::sort(players.begin(), players.end(), compareKarts);
|
||||
// have to add self first
|
||||
GameSetup *setup = STKHost::get()->getGameSetup();
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = setup->isLocalMaster(players[i]->getPlayerID());
|
||||
bool is_me = setup->isLocalMaster(players[i]->getGlobalPlayerId());
|
||||
if (is_me)
|
||||
{
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
RemoteKartInfo rki(profile->getGlobalPlayerId(), profile->getKartName(),
|
||||
profile->getName(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
profile->getGlobalPlayerId(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
rki.setGlobalPlayerId(profile->getGlobalPlayerId());
|
||||
rki.setLocalPlayerId(is_me?0:1);
|
||||
rki.setHostId(profile->getPlayerID());
|
||||
rki.setHostId(profile->getGlobalPlayerId());
|
||||
PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer();
|
||||
assert(profile_to_use);
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
@ -165,22 +170,22 @@ void StartGameProtocol::update()
|
||||
}
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
bool is_me = setup->isLocalMaster(players[i]->getPlayerID());
|
||||
bool is_me = setup->isLocalMaster(players[i]->getGlobalPlayerId());
|
||||
NetworkPlayerProfile* profile = players[i];
|
||||
RemoteKartInfo rki(profile->getPlayerID(), profile->getKartName(),
|
||||
RemoteKartInfo rki(profile->getGlobalPlayerId(), profile->getKartName(),
|
||||
profile->getName(),
|
||||
profile->getPlayerID(), !is_me);
|
||||
profile->getGlobalPlayerId(), !is_me);
|
||||
rki.setPerPlayerDifficulty(profile->getPerPlayerDifficulty());
|
||||
rki.setGlobalPlayerId(profile->getPlayerID());
|
||||
rki.setGlobalPlayerId(profile->getGlobalPlayerId());
|
||||
// on the server, the race id must be the local one.
|
||||
rki.setLocalPlayerId(NetworkConfig::get()->isServer()
|
||||
? profile->getPlayerID()
|
||||
? profile->getGlobalPlayerId()
|
||||
: (is_me ? 0 : 1) );
|
||||
rki.setHostId(profile->getPlayerID());
|
||||
rki.setHostId(profile->getGlobalPlayerId());
|
||||
Log::info("StartGameProtocol",
|
||||
"Creating kart %s for Player#%d with race_id %d",
|
||||
profile->getKartName().c_str(), i,
|
||||
profile->getPlayerID());
|
||||
profile->getGlobalPlayerId());
|
||||
if (!is_me)
|
||||
{
|
||||
StateManager::get()->createActivePlayer( NULL, NULL );
|
||||
|
@ -180,7 +180,7 @@ void NetworkingLobby::onDialogClose()
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkingLobby::addPlayer(NetworkPlayerProfile *profile)
|
||||
{
|
||||
m_player_list->addItem(StringUtils::toString(profile->getPlayerID()),
|
||||
m_player_list->addItem(StringUtils::toString(profile->getGlobalPlayerId()),
|
||||
profile->getName());
|
||||
} // addPlayer
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user