diff --git a/src/camera.cpp b/src/camera.cpp index e86eaf845..c09b22019 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -22,11 +22,11 @@ #include "coord.hpp" #include "world.hpp" #include "player_kart.hpp" -#include "track_manager.hpp" #include "track.hpp" #include "camera.hpp" #include "user_config.hpp" #include "constants.hpp" +#include "race_manager.hpp" Camera::Camera(int camera_index, const Kart* kart) { diff --git a/src/gui/char_sel.cpp b/src/gui/char_sel.cpp index d454bd73e..c59ce8e00 100644 --- a/src/gui/char_sel.cpp +++ b/src/gui/char_sel.cpp @@ -357,7 +357,7 @@ void CharSel::select() const KartProperties* KP = kart_properties_manager->getKartById(kart_id); if (KP != NULL) { - race_manager->setLocalPlayerKart(m_player_index, KP->getIdent()); + race_manager->setLocalKartInfo(m_player_index, KP->getIdent()); user_config->m_player[m_player_index].setLastKartId(kart_id); // Add selected kart (token) to selected karts vector so it cannot be // selected again diff --git a/src/kart_properties_manager.cpp b/src/kart_properties_manager.cpp index edde6f953..a305c8656 100644 --- a/src/kart_properties_manager.cpp +++ b/src/kart_properties_manager.cpp @@ -1,233 +1,233 @@ -// $Id$ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2004-2006 Ingo Ruhnke -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include -#include -#include -#include "file_manager.hpp" -#include "string_utils.hpp" -#include "kart_properties_manager.hpp" -#include "kart_properties.hpp" -#include "translation.hpp" -#include "user_config.hpp" -#if defined(WIN32) && !defined(__CYGWIN__) -# define snprintf _snprintf -#endif - -KartPropertiesManager *kart_properties_manager=0; - -KartPropertiesManager::KartPropertiesManager() -{ - m_all_groups.clear(); -} // KartPropertiesManager - -//----------------------------------------------------------------------------- -KartPropertiesManager::~KartPropertiesManager() -{ - for(KartPropertiesVector::iterator i = m_karts_properties.begin(); - i != m_karts_properties.end(); ++i) - delete *i; -} // ~KartPropertiesManager - -//----------------------------------------------------------------------------- -void KartPropertiesManager::removeTextures() -{ - for(KartPropertiesVector::iterator i = m_karts_properties.begin(); - i != m_karts_properties.end(); ++i) - { - delete *i; - } - m_karts_properties.clear(); - callback_manager->clear(CB_KART); -} // removeTextures - -//----------------------------------------------------------------------------- -void KartPropertiesManager::loadKartData(bool dont_load_models) -{ - m_max_steer_angle = -1.0f; - std::set result; - file_manager->listFiles(result, file_manager->getKartDir(), - /*is_full_path*/ true); - - // Find out which characters are available and load them - for(std::set::iterator i = result.begin(); - i != result.end(); ++i) - { - std::string kart_file; - try - { - kart_file = file_manager->getKartFile((*i)+".kart"); - } - catch (std::exception& e) - { - (void)e; // remove warning about unused variable - continue; - } - FILE *f=fopen(kart_file.c_str(),"r"); - if(!f) continue; - fclose(f); - KartProperties* kp = new KartProperties(); - kp->load(kart_file, "tuxkart-kart", dont_load_models); - m_karts_properties.push_back(kp); - if(kp->getMaxSteerAngle(0) > m_max_steer_angle) - { - m_max_steer_angle = kp->getMaxSteerAngle(0); - } - const std::vector& groups=kp->getGroups(); - for(unsigned int g=0; ggetIdent() == IDENT) - return j; - ++j; - } - - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg), "KartPropertiesManager: Couldn't find kart: '%s'", - IDENT.c_str()); - throw std::runtime_error(msg); -} // getKartId - -//----------------------------------------------------------------------------- -const KartProperties* KartPropertiesManager::getKart(const std::string IDENT) const -{ - for(KartPropertiesVector::const_iterator i = m_karts_properties.begin(); - i != m_karts_properties.end(); ++i) - { - if ((*i)->getIdent() == IDENT) - return *i; - } - - return NULL; -} // getKart - -//----------------------------------------------------------------------------- -const KartProperties* KartPropertiesManager::getKartById(int i) const -{ - if (i < 0 || i >= int(m_karts_properties.size())) - return NULL; - - return m_karts_properties[i]; -} - -//----------------------------------------------------------------------------- -/** Returns the (global) index of the n-th kart of a given group. If there is - * no such kart, -1 is returned - */ -int KartPropertiesManager::getKartByGroup(const std::string& group, int n) const -{ - int count=0; - for(KartPropertiesVector::const_iterator i = m_karts_properties.begin(); - i != m_karts_properties.end(); ++i) - { - std::vector groups=(*i)->getGroups(); - if (std::find(groups.begin(), groups.end(), group)==groups.end()) continue; - if(count==n) return (int)(i-m_karts_properties.begin()); - count=count+1; - } - return -1; -} // getKartByGroup - -//----------------------------------------------------------------------------- -void KartPropertiesManager::fillWithRandomKarts(std::vector& vec) -{ - // First: set up flags (based on global kart - // index) for which karts are already used - // ----------------------------------------- - std::vector used; - used.resize(getNumberOfKarts(), false); - - int count=vec.size(); - std::vector all_karts; - for(unsigned int i=0; i karts = getKartsInGroup(user_config->m_kart_group); - std::vector::iterator k; - // Remove karts that are already used - for(unsigned int i=0; i0 && karts.size()>0; i++) - { - if(vec[i].empty()) - { - used[karts.back()] = true; - vec[i] = m_karts_properties[karts.back()]->getIdent(); - karts.pop_back(); - count --; - } - } - if(count==0) return; - - // Not enough karts in chosen group, so fill the rest with arbitrary karts - // ----------------------------------------------------------------------- - // First create an index list with all unused karts. - karts.clear(); - for(unsigned int i=0; i0 && karts.size()>0; i++) - { - if(vec[i].empty()) - { - vec[i] = m_karts_properties[karts.back()]->getIdent(); - karts.pop_back(); - count --; - } - } - // There should never be more karts to be selected than there are. - assert(count==0); -} // fillWithRandomKarts - -/* EOF */ +// $Id$ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2004-2006 Ingo Ruhnke +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include +#include +#include "file_manager.hpp" +#include "string_utils.hpp" +#include "kart_properties_manager.hpp" +#include "kart_properties.hpp" +#include "translation.hpp" +#include "user_config.hpp" +#if defined(WIN32) && !defined(__CYGWIN__) +# define snprintf _snprintf +#endif + +KartPropertiesManager *kart_properties_manager=0; + +KartPropertiesManager::KartPropertiesManager() +{ + m_all_groups.clear(); +} // KartPropertiesManager + +//----------------------------------------------------------------------------- +KartPropertiesManager::~KartPropertiesManager() +{ + for(KartPropertiesVector::iterator i = m_karts_properties.begin(); + i != m_karts_properties.end(); ++i) + delete *i; +} // ~KartPropertiesManager + +//----------------------------------------------------------------------------- +void KartPropertiesManager::removeTextures() +{ + for(KartPropertiesVector::iterator i = m_karts_properties.begin(); + i != m_karts_properties.end(); ++i) + { + delete *i; + } + m_karts_properties.clear(); + callback_manager->clear(CB_KART); +} // removeTextures + +//----------------------------------------------------------------------------- +void KartPropertiesManager::loadKartData(bool dont_load_models) +{ + m_max_steer_angle = -1.0f; + std::set result; + file_manager->listFiles(result, file_manager->getKartDir(), + /*is_full_path*/ true); + + // Find out which characters are available and load them + for(std::set::iterator i = result.begin(); + i != result.end(); ++i) + { + std::string kart_file; + try + { + kart_file = file_manager->getKartFile((*i)+".kart"); + } + catch (std::exception& e) + { + (void)e; // remove warning about unused variable + continue; + } + FILE *f=fopen(kart_file.c_str(),"r"); + if(!f) continue; + fclose(f); + KartProperties* kp = new KartProperties(); + kp->load(kart_file, "tuxkart-kart", dont_load_models); + m_karts_properties.push_back(kp); + if(kp->getMaxSteerAngle(0) > m_max_steer_angle) + { + m_max_steer_angle = kp->getMaxSteerAngle(0); + } + const std::vector& groups=kp->getGroups(); + for(unsigned int g=0; ggetIdent() == IDENT) + return j; + ++j; + } + + char msg[MAX_ERROR_MESSAGE_LENGTH]; + snprintf(msg, sizeof(msg), "KartPropertiesManager: Couldn't find kart: '%s'", + IDENT.c_str()); + throw std::runtime_error(msg); +} // getKartId + +//----------------------------------------------------------------------------- +const KartProperties* KartPropertiesManager::getKart(const std::string IDENT) const +{ + for(KartPropertiesVector::const_iterator i = m_karts_properties.begin(); + i != m_karts_properties.end(); ++i) + { + if ((*i)->getIdent() == IDENT) + return *i; + } + + return NULL; +} // getKart + +//----------------------------------------------------------------------------- +const KartProperties* KartPropertiesManager::getKartById(int i) const +{ + if (i < 0 || i >= int(m_karts_properties.size())) + return NULL; + + return m_karts_properties[i]; +} + +//----------------------------------------------------------------------------- +/** Returns the (global) index of the n-th kart of a given group. If there is + * no such kart, -1 is returned + */ +int KartPropertiesManager::getKartByGroup(const std::string& group, int n) const +{ + int count=0; + for(KartPropertiesVector::const_iterator i = m_karts_properties.begin(); + i != m_karts_properties.end(); ++i) + { + std::vector groups=(*i)->getGroups(); + if (std::find(groups.begin(), groups.end(), group)==groups.end()) continue; + if(count==n) return (int)(i-m_karts_properties.begin()); + count=count+1; + } + return -1; +} // getKartByGroup + +//----------------------------------------------------------------------------- +void KartPropertiesManager::fillWithRandomKarts(std::vector& vec) +{ + // First: set up flags (based on global kart + // index) for which karts are already used + // ----------------------------------------- + std::vector used; + used.resize(getNumberOfKarts(), false); + + int count=vec.size(); + std::vector all_karts; + for(unsigned int i=0; i karts = getKartsInGroup(user_config->m_kart_group); + std::vector::iterator k; + // Remove karts that are already used + for(unsigned int i=0; i0 && karts.size()>0; i++) + { + if(vec[i].getKartName()=="") + { + used[karts.back()] = true; + vec[i] = RemoteKartInfo(m_karts_properties[karts.back()]->getIdent()); + karts.pop_back(); + count --; + } + } + if(count==0) return; + + // Not enough karts in chosen group, so fill the rest with arbitrary karts + // ----------------------------------------------------------------------- + // First create an index list with all unused karts. + karts.clear(); + for(unsigned int i=0; i0 && karts.size()>0; i++) + { + if(vec[i].getKartName()=="") + { + vec[i] = RemoteKartInfo(m_karts_properties[karts.back()]->getIdent()); + karts.pop_back(); + count --; + } + } + // There should never be more karts to be selected than there are. + assert(count==0); +} // fillWithRandomKarts + +/* EOF */ diff --git a/src/kart_properties_manager.hpp b/src/kart_properties_manager.hpp index 202af9d2a..cb498df28 100644 --- a/src/kart_properties_manager.hpp +++ b/src/kart_properties_manager.hpp @@ -1,70 +1,71 @@ -// $Id$ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2004-2006 Ingo Ruhnke -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef HEADER_KARTPROPERTIESMANAGER_H -#define HEADER_KARTPROPERTIESMANAGER_H - -#include -#include - -class KartProperties; - -class KartPropertiesManager -{ -private: - std::vector m_all_groups; - std::map > m_groups; -protected: - float m_max_steer_angle; - - typedef std::vector KartPropertiesVector; - /** All available kart configurations */ - KartPropertiesVector m_karts_properties; - -public: - KartPropertiesManager(); - ~KartPropertiesManager(); - - // vector containing kart numbers that have been selected in multiplayer - // games. This it used to ensure the same kart can not be selected more - // than once. - std::vector m_selected_karts; - - const KartProperties* getKartById (int i) const; - const KartProperties* getKart (const std::string IDENT) const; - const int getKartId (const std::string IDENT) const; - int getKartByGroup (const std::string& group, int i) const; - void loadKartData (bool dont_load_models=false); - const float getMaximumSteeringAngle() const {return m_max_steer_angle;} - const unsigned int getNumberOfKarts () const {return (unsigned int)m_karts_properties.size();} - const std::vector& - getAllGroups () const {return m_all_groups; } - const std::vector& getKartsInGroup (const std::string& g) - {return m_groups[g]; } - - /** Fill the empty positions in the given vector with random karts */ - void fillWithRandomKarts (std::vector& vec); - void removeTextures (); -}; - -extern KartPropertiesManager *kart_properties_manager; - -#endif - -/* EOF */ +// $Id$ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2004-2006 Ingo Ruhnke +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_KARTPROPERTIESMANAGER_H +#define HEADER_KARTPROPERTIESMANAGER_H + +#include +#include +#include "network/remote_kart_info.hpp" + +class KartProperties; + +class KartPropertiesManager +{ +private: + std::vector m_all_groups; + std::map > m_groups; +protected: + float m_max_steer_angle; + + typedef std::vector KartPropertiesVector; + /** All available kart configurations */ + KartPropertiesVector m_karts_properties; + +public: + KartPropertiesManager(); + ~KartPropertiesManager(); + + // vector containing kart numbers that have been selected in multiplayer + // games. This it used to ensure the same kart can not be selected more + // than once. + std::vector m_selected_karts; + + const KartProperties* getKartById (int i) const; + const KartProperties* getKart (const std::string IDENT) const; + const int getKartId (const std::string IDENT) const; + int getKartByGroup (const std::string& group, int i) const; + void loadKartData (bool dont_load_models=false); + const float getMaximumSteeringAngle() const {return m_max_steer_angle;} + const unsigned int getNumberOfKarts () const {return (unsigned int)m_karts_properties.size();} + const std::vector& + getAllGroups () const {return m_all_groups; } + const std::vector& getKartsInGroup (const std::string& g) + {return m_groups[g]; } + + /** Fill the empty positions in the given vector with random karts */ + void fillWithRandomKarts (std::vector& vec); + void removeTextures (); +}; + +extern KartPropertiesManager *kart_properties_manager; + +#endif + +/* EOF */ diff --git a/src/main.cpp b/src/main.cpp index 149d2eb5b..680d5138c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -184,7 +184,7 @@ int handleCmdLine(int argc, char **argv) std::string filename=file_manager->getKartFile(std::string(argv[i+1])+".tkkf"); if(filename!="") { - race_manager->setLocalPlayerKart(0, argv[i+1]); + race_manager->setLocalKartInfo(0, argv[i+1]); fprintf ( stdout, "You choose to use kart '%s'.\n", argv[i+1] ) ; } else @@ -555,7 +555,7 @@ int main(int argc, char *argv[] ) // Profiling // ========= race_manager->setNumPlayers(1); - race_manager->setLocalPlayerKart(0, kart_properties_manager->getKart("tuxkart")->getIdent()); + race_manager->setLocalKartInfo(0, kart_properties_manager->getKart("tuxkart")->getIdent()); race_manager->setMajorMode (RaceManager::RM_SINGLE); race_manager->setMinorMode (RaceManager::RM_QUICK_RACE); race_manager->setDifficulty(RaceManager::RD_HARD); diff --git a/src/network/network_manager.cpp b/src/network/network_manager.cpp index 5683fe0e9..22dfaafbc 100644 --- a/src/network/network_manager.cpp +++ b/src/network/network_manager.cpp @@ -38,9 +38,6 @@ NetworkManager::NetworkManager() fprintf (stderr, "An error occurred while initializing ENet.\n"); exit(-1); } - // FIXME: debugging - m_kart_info.push_back(RemoteKartInfo("tuxkart","xx", 1)); - m_kart_info.push_back(RemoteKartInfo("yeti", "yy", 1)); #endif } // NetworkManager @@ -211,6 +208,7 @@ void NetworkManager::update(float dt) } } // update + // ---------------------------------------------------------------------------- /** Send race_manager->getNumPlayers(), the kart and the name of each player to the server. @@ -220,7 +218,7 @@ void NetworkManager::sendKartsInformationToServer() for(int i=0; i<(int)race_manager->getNumLocalPlayers(); i++) { fprintf(stderr, "Sending name '%s', ",user_config->m_player[i].getName().c_str()); - fprintf(stderr, "kart name '%s'\n", race_manager->getLocalPlayerKart(i).getKartName().c_str()); + fprintf(stderr, "kart name '%s'\n", race_manager->getLocalKartInfo(i).getKartName().c_str()); } // for igetNumLocalPlayers(); i++) + m_kart_info.push_back(race_manager->getLocalKartInfo(i)); - for(unsigned int i=0; i<(int)race_manager->getNumLocalPlayers(); i++) - { - //FIXME race_manager->setPlayerKart(i, race_manager->getLocalPlayerKart(i), - // m_host_id); - } - int offset=race_manager->getNumLocalPlayers(); + // Now sort by (hostid, playerid) + std::sort(m_kart_info.begin(), m_kart_info.end()); + + // Set the global player ID for each player + for(unsigned int i=0; isetNumPlayers(m_kart_info.size()); for(unsigned int i=0; isetPlayerKart(offset+i, m_kart_info[i].m_kart_name, - // m_kart_info[i].m_client_id); - } // for i + race_manager->setPlayerKart(i, m_kart_info[i]); + } } // waitForKartsInformation // ---------------------------------------------------------------------------- @@ -255,10 +262,11 @@ void NetworkManager::waitForKartsInformation() void NetworkManager::sendRaceInformationToClients() { fprintf(stderr, "server sending race_manager information to all clients\n"); - for(unsigned i=0; igetNumPlayers(); i++) + for(unsigned i=0; igetNumLocalPlayers(); i++) { -// fprintf(stderr, "Sending kart '%s' host %d\n", -//FIXME race_manager->getKartName(i), race_manager->getHostId(i)); + const RemoteKartInfo& ki=race_manager->getLocalKartInfo(i); + fprintf(stderr, "Sending kart '%s' playerid %d host %d\n", + ki.getKartName(), ki.getLocalPlayerId(), ki.getHostId()); } // for i } // sendRaceInformationToClients diff --git a/src/network/network_manager.hpp b/src/network/network_manager.hpp index 0c0a83dd8..3ded85b49 100644 --- a/src/network/network_manager.hpp +++ b/src/network/network_manager.hpp @@ -59,14 +59,16 @@ private: public: NetworkManager(); ~NetworkManager(); - void setMode(NetworkMode m) {m_mode = m; } - NetworkMode getMode() const {return m_mode; } - void setState(NetworkState s) {m_state = s; } - NetworkState getState() const {return m_state; } - int getClientId() const {return m_host_id; } - int getNumClients() const {return m_num_clients;} - void setPort(int p) {m_port=p; } - void setServerIP(const std::string &s) {m_server_address=s; } + void setMode(NetworkMode m) {m_mode = m; } + NetworkMode getMode() const {return m_mode; } + void setState(NetworkState s) {m_state = s; } + NetworkState getState() const {return m_state; } + int getHostId() const {return m_host_id; } + int getNumClients() const {return m_num_clients; } + void setPort(int p) {m_port=p; } + void setServerIP(const std::string &s) {m_server_address=s; } + void setKartInfo(int player_id, const std::string& kart, + const std::string& user="", int hostid=-1); bool initialiseConnections(); void update(float dt); void sendKartsInformationToServer(); diff --git a/src/network/remote_kart_info.hpp b/src/network/remote_kart_info.hpp index f7a6495e5..5831bba65 100644 --- a/src/network/remote_kart_info.hpp +++ b/src/network/remote_kart_info.hpp @@ -26,19 +26,36 @@ class RemoteKartInfo { std::string m_kart_name; std::string m_user_name; - int m_client_id; - int m_player_id; + int m_host_id; + int m_local_player_id; + int m_global_player_id; public: - RemoteKartInfo(std::string kart_name, std::string user_name, int id) - : m_kart_name(kart_name), m_user_name(user_name), m_client_id(id) - {}; - RemoteKartInfo() {m_kart_name=""; m_user_name=""; m_client_id=-1; m_player_id=-1;} - void setKartName(const std::string& n) { m_kart_name = n; } - void setUserName(const std::string& u) { m_user_name = u; } - void setClientId(int id) { m_client_id = id; } - void setPlayerId(int id) { m_player_id = id; } - const std::string& getKartName() const {return m_kart_name; } + RemoteKartInfo(int player_id, const std::string& kart_name, + const std::string& user_name, int host_id) + : m_kart_name(kart_name), m_user_name(user_name), + m_local_player_id(player_id), m_host_id(host_id) + {}; + RemoteKartInfo(const std::string& kart_name) + {m_kart_name=kart_name; m_user_name=""; + m_host_id=-1; m_local_player_id=-1;} + RemoteKartInfo() {m_kart_name=""; m_user_name=""; + m_host_id=-1; m_local_player_id=-1;} + void setKartName(const std::string& n) { m_kart_name = n; } + void setUserName(const std::string& u) { m_user_name = u; } + void setHostId(int id) { m_host_id = id; } + void setLocalPlayerId(int id) { m_local_player_id = id; } + void setGlobalPlayerId(int id) { m_global_player_id = id; } + int getHostId() const { return m_host_id; } + int getLocalPlayerId() const { return m_local_player_id; } + int getGlobalPlayerId() const { return m_global_player_id; } + const std::string& getKartName() const {return m_kart_name; } + const std::string& getPlayerName() const{return m_user_name; } + bool operator<(const RemoteKartInfo& other) + { + return (m_host_id PlayerKarts; - PlayerKarts m_player_karts; - std::vector m_local_player_karts; + std::vector m_player_karts; + std::vector m_local_kart_info; std::vector m_tracks; std::vector m_host_ids; std::vector m_num_laps; @@ -90,7 +92,7 @@ private: unsigned int m_num_finished_karts; unsigned int m_num_finished_players; int m_coin_target; - + void startNextRace(); // start a next race friend bool operator< (const KartStatus& left, const KartStatus& right) @@ -102,20 +104,19 @@ public: bool m_active_race; //True if there is a race public: - - RaceManager(); - ~RaceManager(); - - void setPlayerKart(unsigned int player, const std::string& kart, - const std::string& player_name, int hostid); - void setLocalPlayerKart(unsigned int player, const std::string& kart); - const RemoteKartInfo& - getLocalPlayerKart(unsigned int p) const {return m_local_player_karts[p]; } + RaceManager(); + ~RaceManager(); void reset(); + void setLocalKartInfo(unsigned int player_id, const std::string& kart); + const RemoteKartInfo& + getLocalKartInfo(unsigned int n) const {return m_local_kart_info[n];} + void setNumLocalPlayers(unsigned int n); + unsigned int getNumLocalPlayers() const {return m_local_kart_info.size(); }; + + void setNumPlayers(int num); + void setPlayerKart(unsigned int player_id, const RemoteKartInfo& ki); void RaceFinished(const Kart* kart, float time); void setTrack(const std::string& track); - void setNumPlayers(int num); - void setNumLocalPlayers(int num) {m_local_player_karts.resize(num); } void setGrandPrix(const GrandPrixData &gp){ m_grand_prix = gp; } void setDifficulty(Difficulty diff); void setNumLaps(int num) { m_num_laps.clear(); @@ -127,8 +128,7 @@ public: RaceModeType getMajorMode() const { return m_major_mode; } RaceModeType getMinorMode() const { return m_minor_mode; } unsigned int getNumKarts() const { return m_num_karts; } - unsigned int getNumPlayers() const { return (int)m_player_karts.size();} - unsigned int getNumLocalPlayers() const { return (int)m_local_player_karts.size();} + unsigned int getNumPlayers() const { return m_player_karts.size(); } int getNumLaps() const { return m_num_laps[m_track_number];} Difficulty getDifficulty() const { return m_difficulty; } const std::string& @@ -137,21 +137,22 @@ public: *getGrandPrix() const { return &m_grand_prix; } unsigned int getFinishedKarts() const { return m_num_finished_karts; } unsigned int getFinishedPlayers() const { return m_num_finished_players; } + const std::string& + getHerringStyle() const { return m_grand_prix.getHerringStyle(); } const std::string& getKartName(int kart) const { return m_kart_status[kart].m_ident;} - const std::string& - getHerringStyle() const { return m_grand_prix.getHerringStyle();} - int getKartScore(int krt) const { return m_kart_status[krt].m_score;} + int getKartScore(int krt) const { return m_kart_status[krt].m_score; } int getKartPrevScore(int krt)const { return m_kart_status[krt].m_last_score;} - int getKartPlayerId(int krt) const { return m_kart_status[krt].m_player_id;} - int getPositionScore(int p) const { return m_score_for_position[p-1]; } + int getKartLocalPlayerId(int k) const { return m_kart_status[k].m_local_player_id; } + int getKartGlobalPlayerId(int k) const { return m_kart_status[k].m_global_player_id; } double getOverallTime(int kart) const { return m_kart_status[kart].m_overall_time;} - int getCoinTarget() const { return m_coin_target; } - bool raceHasLaps() const { return m_minor_mode!=RM_FOLLOW_LEADER;} + KartType getKartType(int kart) const { return m_kart_status[kart].m_kart_type;} + int getCoinTarget() const { return m_coin_target; } + bool raceHasLaps() const { return m_minor_mode!=RM_FOLLOW_LEADER; } + int getPositionScore(int p) const { return m_score_for_position[p-1]; } int allPlayerFinished() const {return - m_num_finished_players==m_player_karts.size(); } + m_num_finished_players==m_player_karts.size();} int raceIsActive() const { return m_active_race; } - KartType getKartType(int kart) const {return m_kart_status[kart].m_kart_type; } void setMirror() {/*FIXME*/} void setReverse(){/*FIXME*/} diff --git a/src/world.cpp b/src/world.cpp index b38345910..3ed85fe41 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -45,6 +45,8 @@ #include "camera.hpp" #include "robots/default_robot.hpp" #include "unlock_manager.hpp" +#include "network/network_kart.hpp" +#include "network/network_manager.hpp" #ifdef HAVE_GHOST_REPLAY # include "replay_player.hpp" #endif @@ -103,8 +105,9 @@ World::World() int position = i+1; // position start with 1 btTransform init_pos=m_track->getStartTransform(position); Kart* newkart; - const std::string& kart_name=race_manager->getKartName(i); - int player_id = race_manager->getKartPlayerId(i); + const std::string& kart_name = race_manager->getKartName(i); + int local_player_id = race_manager->getKartLocalPlayerId(i); + int global_player_id = race_manager->getKartGlobalPlayerId(i); if(user_config->m_profile) { // In profile mode, load only the old kart @@ -113,7 +116,7 @@ World::World() // karts can be seen. if(i==race_manager->getNumKarts()-1) { - scene->createCamera(player_id, newkart); + scene->createCamera(local_player_id, newkart); } } else @@ -122,11 +125,22 @@ World::World() { case RaceManager::KT_PLAYER: newkart = new PlayerKart(kart_name, position, - &(user_config->m_player[player_id]), - init_pos, player_id); - m_player_karts[player_id] = (PlayerKart*)newkart; + &(user_config->m_player[local_player_id]), + init_pos, local_player_id); + m_player_karts[global_player_id] = (PlayerKart*)newkart; + m_local_player_karts[local_player_id] = static_cast(newkart); break; case RaceManager::KT_NETWORK_PLAYER: + if(network_manager->getMode()==NetworkManager::NW_SERVER) + { + newkart = new NetworkKart(kart_name, position, init_pos, + global_player_id); + } + else + { + newkart = new NetworkKart(kart_name, position, init_pos, + global_player_id); + } break; case RaceManager::KT_AI: newkart = loadRobot(kart_name, position, init_pos); diff --git a/src/world.hpp b/src/world.hpp index 6e1020314..f52b00b29 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -21,6 +21,7 @@ #define HEADER_WORLD_H #include +#define _WINSOCKAPI_ #include #include "track.hpp" #include "player_kart.hpp"