Replaced setLocalKartInfo with setPlayerKart. Updated some docs.

This commit is contained in:
hiker 2016-01-12 13:00:45 +11:00
parent 6816b08af1
commit e7dd7f4d1a
16 changed files with 54 additions and 66 deletions

View File

@ -466,12 +466,13 @@ void setupRaceStart()
Log::warn("main", "Kart '%s' is unknown so will use the " Log::warn("main", "Kart '%s' is unknown so will use the "
"default kart.", "default kart.",
UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.c_str());
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart.getDefaultValue()); race_manager->setPlayerKart(0,
UserConfigParams::m_default_kart.getDefaultValue());
} }
else else
{ {
// Set up race manager appropriately // Set up race manager appropriately
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
} }
// ASSIGN should make sure that only input from assigned devices // ASSIGN should make sure that only input from assigned devices
@ -836,7 +837,7 @@ int handleCmdLine()
// up upon player creation. // up upon player creation.
if (StateManager::get()->activePlayerCount() > 0) if (StateManager::get()->activePlayerCount() > 0)
{ {
race_manager->setLocalKartInfo(0, s); race_manager->setPlayerKart(0, s);
} }
Log::verbose("main", "You chose to use kart '%s'.", Log::verbose("main", "You chose to use kart '%s'.",
s.c_str()); s.c_str());

View File

@ -51,7 +51,7 @@ DemoWorld::DemoWorld()
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD); race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
race_manager->setNumKarts(m_num_karts); race_manager->setNumKarts(m_num_karts);
race_manager->setNumPlayers(1); race_manager->setNumPlayers(1);
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
} // DemoWorld } // DemoWorld
@ -150,7 +150,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt)
m_do_demo = true; m_do_demo = true;
race_manager->setNumKarts(m_num_karts); race_manager->setNumKarts(m_num_karts);
race_manager->setLocalKartInfo(0, "tux"); race_manager->setPlayerKart(0, "tux");
race_manager->setupPlayerKartInfo(); race_manager->setupPlayerKartInfo();
race_manager->startSingleRace(m_demo_tracks[0], m_num_laps, false); race_manager->startSingleRace(m_demo_tracks[0], m_num_laps, false);
m_demo_tracks.push_back(m_demo_tracks[0]); m_demo_tracks.push_back(m_demo_tracks[0]);

View File

@ -78,7 +78,7 @@ void OverWorld::enterOverWorld()
UserConfigParams::m_default_kart.revertToDefaults(); UserConfigParams::m_default_kart.revertToDefaults();
} }
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
// ASSIGN should make sure that only input from assigned devices // ASSIGN should make sure that only input from assigned devices
// is read. // is read.

View File

@ -883,7 +883,7 @@ void World::updateWorld(float dt)
UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults(); UserConfigParams::m_default_kart.revertToDefaults();
} }
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
// ASSIGN should make sure that only input from assigned devices // ASSIGN should make sure that only input from assigned devices
// is read. // is read.

View File

@ -30,6 +30,7 @@
GameSetup::GameSetup() GameSetup::GameSetup()
{ {
m_race_config = new RaceConfig(); m_race_config = new RaceConfig();
m_num_local_players = 0;
m_local_master = 0; m_local_master = 0;
} // GameSetup } // GameSetup

View File

@ -46,6 +46,9 @@ private:
/** The race configuration. */ /** The race configuration. */
RaceConfig* m_race_config; RaceConfig* m_race_config;
/** Stores the number of local players. */
int m_num_local_players;
/** The player id of the local game master, used in /** The player id of the local game master, used in
* kart selection screen. */ * kart selection screen. */
uint8_t m_local_master; uint8_t m_local_master;
@ -69,6 +72,12 @@ public:
*/ */
bool isKartAvailable(std::string kart_name); bool isKartAvailable(std::string kart_name);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Sets the number of local players. */
void setNumLocalPlayers(int n) { m_num_local_players = n; }
// ------------------------------------------------------------------------
/** Returns the nunber of local players. */
int getNumLocalPlayers() const { return m_num_local_players; }
// ------------------------------------------------------------------------
/*! \brief Used to know if a kart is playable. /*! \brief Used to know if a kart is playable.
* \param kart_name : Name of the kart to check. * \param kart_name : Name of the kart to check.
* \return True if the kart is playable (standard kart). * \return True if the kart is playable (standard kart).

View File

@ -412,6 +412,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
NetworkPlayerProfile* profile = new NetworkPlayerProfile(my_player_id, name); NetworkPlayerProfile* profile = new NetworkPlayerProfile(my_player_id, name);
profile->setHostId(my_host_id); profile->setHostId(my_host_id);
STKHost::get()->getGameSetup()->setLocalMaster(my_player_id); STKHost::get()->getGameSetup()->setLocalMaster(my_player_id);
m_setup->setNumLocalPlayers(1);
m_setup->addPlayer(profile); m_setup->addPlayer(profile);
// connection token // connection token
uint32_t token = data.gui32(3); uint32_t token = data.gui32(3);

View File

@ -58,6 +58,7 @@ ServerLobbyRoomProtocol::~ServerLobbyRoomProtocol()
void ServerLobbyRoomProtocol::setup() void ServerLobbyRoomProtocol::setup()
{ {
m_setup = STKHost::get()->setupNewGame(); m_setup = STKHost::get()->setupNewGame();
m_setup->setNumLocalPlayers(0); // no local players on a server
m_next_player_id.setAtomic(0); m_next_player_id.setAtomic(0);
// In case of LAN we don't need our public address or register with the // In case of LAN we don't need our public address or register with the

View File

@ -59,12 +59,13 @@ void StartGameProtocol::setup()
// --------------------- // ---------------------
// builds it and starts // builds it and starts
NetworkWorld::getInstance<NetworkWorld>()->start(); NetworkWorld::getInstance<NetworkWorld>()->start();
// The number of karts includes the AI karts, which are not supported atn
race_manager->setNumKarts(m_game_setup->getPlayerCount()); race_manager->setNumKarts(m_game_setup->getPlayerCount());
race_manager->setNumPlayers(m_game_setup->getPlayerCount());
// setNumPlayers by default sets number of local players to // Set number of global and local players.
// number of players - so avoid this to keep the original number: race_manager->setNumPlayers(m_game_setup->getPlayerCount(),
race_manager->setNumPlayers(1, m_game_setup->getNumLocalPlayers());
/*local players*/race_manager->getNumLocalPlayers());
// Create the kart information for the race manager: // Create the kart information for the race manager:
// ------------------------------------------------- // -------------------------------------------------
@ -105,7 +106,7 @@ void StartGameProtocol::setup()
StateManager::get()->getActivePlayer(new_player_id); StateManager::get()->getActivePlayer(new_player_id);
device->setPlayer(ap); device->setPlayer(ap);
input_manager->getDeviceManager()->setSinglePlayer(ap); input_manager->getDeviceManager()->setSinglePlayer(ap);
race_manager->setLocalKartInfo(new_player_id, race_manager->setPlayerKart(new_player_id,
profile->getKartName()); profile->getKartName());
NetworkWorld::getInstance()->setSelfKart(profile->getKartName()); NetworkWorld::getInstance()->setSelfKart(profile->getKartName());
} // if is_local } // if is_local

View File

@ -297,7 +297,7 @@ void History::Load()
m_kart_ident.push_back(s1); m_kart_ident.push_back(s1);
if(i<race_manager->getNumPlayers()) if(i<race_manager->getNumPlayers())
{ {
race_manager->setLocalKartInfo(i, s1); race_manager->setPlayerKart(i, s1);
} }
} // for i<nKarts } // for i<nKarts
// FIXME: The model information is currently ignored // FIXME: The model information is currently ignored

View File

@ -138,22 +138,14 @@ void RaceManager::setPlayerKart(unsigned int player_id, const RemoteKartInfo& ki
} // setPlayerKart } // setPlayerKart
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Sets information about a kart used by a local player (i.e. on this void RaceManager::setPlayerKart(unsigned int player_id,
* computer). const std::string &kart_name)
* \param player_id Id of this player.
* \param kart The kart this player uses.
*/
void RaceManager::setLocalKartInfo(unsigned int player_id,
const std::string& kart)
{ {
assert(kart.size() > 0); const PlayerProfile* profile =
assert(player_id <getNumLocalPlayers()); StateManager::get()->getActivePlayerProfile(player_id);
assert(kart_properties_manager->getKart(kart) != NULL); RemoteKartInfo rki(player_id, kart_name, profile->getName(), 0, false);
m_player_karts[player_id] = rki;
const PlayerProfile* profile = StateManager::get()->getActivePlayerProfile(player_id); } // setPlayerKart
m_player_karts[player_id] = RemoteKartInfo(player_id, kart, profile->getName(),
0, false);
} // setLocalKartInfo
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Sets additional information for a player to indicate which soccer team it /** Sets additional information for a player to indicate which soccer team it
@ -209,7 +201,7 @@ int RaceManager::getLocalPlayerGPRank(const int player_id) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Sets the number of players and optional the number of local players. /** Sets the number of players and optional the number of local players.
* \param num Number of players. * \param num Number of players.
* \param local_players * \param local_players Number of local players, only used from networking.
*/ */
void RaceManager::setNumPlayers(int players, int local_players) void RaceManager::setNumPlayers(int players, int local_players)
{ {
@ -390,8 +382,8 @@ void RaceManager::startNew(bool from_overworld)
} }
} }
// Then the players, which start behind the AI karts // Then add the players, which start behind the AI karts
// ------------------------------------------------- // -----------------------------------------------------
for(unsigned int i = 0; i < m_player_karts.size(); i++) for(unsigned int i = 0; i < m_player_karts.size(); i++)
{ {
KartType kt= m_player_karts[i].isNetworkPlayer() ? KT_NETWORK_PLAYER KartType kt= m_player_karts[i].isNetworkPlayer() ? KT_NETWORK_PLAYER
@ -906,26 +898,10 @@ void RaceManager::startSingleRace(const std::string &track_ident,
} // startSingleRace } // startSingleRace
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Receive and store the information from sendKartsInformation() /** Fills up the remaining kart slots with AI karts.
*/ v*/
void RaceManager::setupPlayerKartInfo() void RaceManager::setupPlayerKartInfo()
{ {
std::vector<RemoteKartInfo> kart_info;
// Get the local kart info
for(unsigned int i=0; i<getNumPlayers(); i++)
kart_info.push_back(getKartInfo(i));
// Now sort by (hostid, playerid)
std::sort(kart_info.begin(), kart_info.end());
// Set the global player ID for each player
for(unsigned int i=0; i<kart_info.size(); i++)
{
kart_info[i].setGlobalPlayerId(i);
setPlayerKart(i, kart_info[i]);
}
computeRandomKartList(); computeRandomKartList();
} // setupPlayerKartInfo } // setupPlayerKartInfo

View File

@ -56,14 +56,12 @@ static const std::string IDENT_CUTSCENE ("CUTSCENE" );
* manager stores the GP information, but World queries only track * manager stores the GP information, but World queries only track
* and number of laps, so in case of GP this information is taken from * and number of laps, so in case of GP this information is taken from
* the GrandPrix object), and local player information (number of local * the GrandPrix object), and local player information (number of local
* players, and selected karts). The local player information is read * players, and selected karts).
* from the NetworkManager, gathered on the server (from all clients and * Information about player karts (which player selected which kart,
* the server, see NetworkManager::setupPlayerKartInfo), and then the * player ids) is stored in a RemoteKartInfo structure and used later
* combined information distributed to all RaceManagers in all clients * to initialise the KartStatus array (startNew()). The KartStatus array
* and server. Even in no networking mode, the data flow is the same: * stores information about all karts (player and AI), and is used to
* information about local players is stored here, then processed by * determine the order in which karts are started (see startNextRace()).
* NetworkManager::setupPlayerKartInfo and the 'global' information about
* player karts is set in the RaceManager, to be used by World later on.
* 2) when a race is started, it creates the world, and keeps track of * 2) when a race is started, it creates the world, and keeps track of
* score during the race. When a race is finished, it deletes the world, * score during the race. When a race is finished, it deletes the world,
* and (depending on race mode) starts the next race by creating a new * and (depending on race mode) starts the next race by creating a new
@ -357,7 +355,7 @@ public:
~RaceManager(); ~RaceManager();
void reset(); void reset();
void setLocalKartInfo(unsigned int player_id, const std::string& kart); void setPlayerKart(unsigned int player_id, const std::string &kart_name);
void setPlayerKart(unsigned int player_id, void setPlayerKart(unsigned int player_id,
const RemoteKartInfo& ki); const RemoteKartInfo& ki);

View File

@ -191,7 +191,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin
// Set up race manager appropriately // Set up race manager appropriately
race_manager->setNumPlayers(1); race_manager->setNumPlayers(1);
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
race_manager->setReverseTrack(false); race_manager->setReverseTrack(false);
//int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device ); //int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device );

View File

@ -76,7 +76,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i
UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults(); UserConfigParams::m_default_kart.revertToDefaults();
} }
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
// ASSIGN should make sure that only input from assigned devices // ASSIGN should make sure that only input from assigned devices
// is read. // is read.

View File

@ -1194,7 +1194,7 @@ void KartSelectionScreen::allPlayersDone()
} }
} }
race_manager->setLocalKartInfo(n, selected_kart); race_manager->setPlayerKart(n, selected_kart);
// Set per player difficulty if needed // Set per player difficulty if needed
if (m_multiplayer && UserConfigParams::m_per_player_difficulty && if (m_multiplayer && UserConfigParams::m_per_player_difficulty &&

View File

@ -435,7 +435,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults(); UserConfigParams::m_default_kart.revertToDefaults();
} }
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); race_manager->setPlayerKart(0, UserConfigParams::m_default_kart);
// ASSIGN should make sure that only input from assigned devices // ASSIGN should make sure that only input from assigned devices
// is read. // is read.