From 9191f89333f1022d7b619f4f679a0593ae2179ad Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 7 Sep 2008 14:09:52 +0000 Subject: [PATCH] Added most of the messages, menu's are mostly synchronised now. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2236 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/gui/network_gui.cpp | 3 +- src/gui/race_options.cpp | 17 +-- src/gui/start_race_feedback.cpp | 78 ++++++------- src/gui/start_race_feedback.hpp | 6 +- src/ide/vc9/supertuxkart.vcproj | 12 +- src/network/character_info_message.hpp | 32 ++++++ src/network/character_selected_message.hpp | 61 ++++++++++ src/network/connect_message.hpp | 53 +++++++++ src/network/message.cpp | 124 +++++++++++++++++++++ src/network/message.hpp | 77 +++++++++++++ src/network/num_players_message.hpp | 43 +++++++ src/network/race_info_message.cpp | 103 +++++++++++++++++ src/network/race_info_message.hpp | 34 ++++++ src/network/race_start_message.hpp | 41 +++++++ src/network/remote_kart_info.hpp | 30 ++--- src/network/world_loaded_message.hpp | 32 ++++++ src/player.hpp | 2 +- src/widget.cpp | 5 +- src/world.cpp | 4 +- 19 files changed, 673 insertions(+), 84 deletions(-) create mode 100644 src/network/character_info_message.hpp create mode 100644 src/network/character_selected_message.hpp create mode 100644 src/network/connect_message.hpp create mode 100644 src/network/message.cpp create mode 100644 src/network/message.hpp create mode 100644 src/network/num_players_message.hpp create mode 100644 src/network/race_info_message.cpp create mode 100644 src/network/race_info_message.hpp create mode 100644 src/network/race_start_message.hpp create mode 100644 src/network/world_loaded_message.hpp diff --git a/src/gui/network_gui.cpp b/src/gui/network_gui.cpp index 3f98bb066..3e8b8b58a 100644 --- a/src/gui/network_gui.cpp +++ b/src/gui/network_gui.cpp @@ -181,6 +181,7 @@ void NetworkGUI::update(float dt) } else { + network_manager->sendConnectMessage(); menu_manager->popMenu(); } m_state=NGS_NONE; @@ -237,7 +238,7 @@ void NetworkGUI::inputKeyboard(SDLKey key, int unicode) // For this menu only unicode translation is enabled. // So we use the unicode character here, since this will // take care of upper/lower case etc. - if (unicode && m_server_address.size() <= SERVER_NAME_MAX) + if (unicode && (int)m_server_address.size() <= SERVER_NAME_MAX) m_server_address += (char) unicode; widget_manager->setWgtText(WTOK_SERVER_ADDRESS, (m_server_address + "<").c_str()); break; diff --git a/src/gui/race_options.cpp b/src/gui/race_options.cpp index bc9a4c8fb..51964c292 100644 --- a/src/gui/race_options.cpp +++ b/src/gui/race_options.cpp @@ -23,7 +23,6 @@ #include "material_manager.hpp" #include "unlock_manager.hpp" #include "translation.hpp" -#include "network/network_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf @@ -55,11 +54,6 @@ enum WidgetTokens RaceOptions::RaceOptions() { - // First update the server's race_manager with the number of players - if(network_manager->getMode()==NetworkManager::NW_SERVER) - { - network_manager->switchToReceiveKartInfo(); // NS_WAIT_FOR_KART_INFO - } m_difficulty=race_manager->getDifficulty(); // FIXME: no medium AI atm @@ -142,8 +136,7 @@ RaceOptions::RaceOptions() widget_manager->setWgtBorderPercentage( WTOK_START, 20 ); widget_manager->setWgtBorderColor( WTOK_START, WGT_TRANS_BLUE ); widget_manager->showWgtBorder( WTOK_START ); - // Disable till all messages from the clients have arrived - widget_manager->deactivateWgt(WTOK_START); + widget_manager->breakLine(); widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 10); @@ -164,10 +157,6 @@ RaceOptions::~RaceOptions() //----------------------------------------------------------------------------- void RaceOptions::update(float dt) { - if(network_manager->getState()!=NetworkManager::NS_WAIT_FOR_KART_INFO) - { - widget_manager->activateWgt(WTOK_START); - } BaseGUI::update(dt); } // update //----------------------------------------------------------------------------- @@ -288,10 +277,6 @@ void RaceOptions::select() } menu_manager->pushMenu(MENUID_START_RACE_FEEDBACK); - if(network_manager->getMode()==NetworkManager::NW_SERVER) - { - network_manager->sendRaceInformationToClients(); // NS_READY_SET_GO_BARRIER - } break; case WTOK_QUIT: menu_manager->popMenu(); diff --git a/src/gui/start_race_feedback.cpp b/src/gui/start_race_feedback.cpp index 51e63a940..48c1040b5 100644 --- a/src/gui/start_race_feedback.cpp +++ b/src/gui/start_race_feedback.cpp @@ -30,14 +30,16 @@ enum WidgetTokens StartRaceFeedback::StartRaceFeedback() { - m_state = SRF_NETWORK; - //Add some feedback so people know they are going to start the race widget_manager->reset(); - if(network_manager->getMode()!=NetworkManager::NW_NONE) - widget_manager->addTextWgt( WTOK_MSG, 60, 7, _("Synchronising network...") ); - else - widget_manager->addTextWgt( WTOK_MSG, 60, 7, _("Loading race...") ); + widget_manager->addTextWgt( WTOK_MSG, 60, 7, "" ); + m_loading_text = _("Loading race..."); + m_synchronising_text = _("Synchronising network..."); + if(network_manager->getMode()==NetworkManager::NW_NONE) + widget_manager->setWgtText(WTOK_MSG, m_loading_text); + else // networking + // the state and mode are checked in update() + widget_manager->setWgtText(WTOK_MSG, m_synchronising_text); widget_manager->layout(WGT_AREA_ALL); } @@ -50,41 +52,41 @@ StartRaceFeedback::~StartRaceFeedback() //----------------------------------------------------------------------------- -void StartRaceFeedback::update(float DELTA) +void StartRaceFeedback::update(float delta) { - widget_manager->update(0.0f); - // We need one call to update to display the current text. So we use a - // simple finite state machine to take care of one additional call: - switch(m_state) + // If the server hasn't received all client information, keep on waiting + if(network_manager->getMode()==NetworkManager::NW_SERVER && + network_manager->getState()!=NetworkManager::NS_ALL_REMOTE_CHARACTERS_DONE) { - case SRF_LOADING_DISPLAY: - m_state=SRF_LOADING; - break; - case SRF_NETWORK_DISPLAY: - m_state = SRF_NETWORK; - break; - case SRF_NETWORK: - // The server only waits for one frame: - if(network_manager->getMode()!=NetworkManager::NW_CLIENT) - { - // Server or stand alone: - network_manager->sendRaceInformationToClients(); - network_manager->setupPlayerKartInfo(); - m_state = SRF_LOADING_DISPLAY; - widget_manager->setWgtText(WTOK_MSG, _("Loading race...") ); - return; - } - // The client have to be busy waiting till the race data has arrived: - if(network_manager->getState()==NetworkManager::NS_WAIT_FOR_RACE_DATA) - return; - m_state = SRF_LOADING_DISPLAY; - widget_manager->setWgtText(WTOK_MSG, _("Loading race...") ); - break; - case SRF_LOADING: - race_manager->startNew(); - break; - } // switch m_state + widget_manager->update(delta); + return; + } + // If the client hasn't received the race data yet, keep on waiting + if(network_manager->getMode()==NetworkManager::NW_CLIENT && + network_manager->getState()==NetworkManager::NS_WAIT_FOR_RACE_DATA) + { + widget_manager->update(delta); + return; + } + + static bool first=true; + if(first) + { + if(network_manager->getMode()==NetworkManager::NW_SERVER) + { + network_manager->sendRaceInformationToClients(); + widget_manager->setWgtText(WTOK_MSG, m_loading_text); + } + else if(network_manager->getMode()==NetworkManager::NW_CLIENT) + { + // Client received race information + widget_manager->setWgtText(WTOK_MSG, m_loading_text); + } + first=false; + } + widget_manager->update(delta); + race_manager->startNew(); } // update diff --git a/src/gui/start_race_feedback.hpp b/src/gui/start_race_feedback.hpp index 325537feb..ef8cacf2f 100644 --- a/src/gui/start_race_feedback.hpp +++ b/src/gui/start_race_feedback.hpp @@ -22,8 +22,10 @@ class StartRaceFeedback: public BaseGUI { - enum {SRF_NETWORK_DISPLAY, SRF_NETWORK, - SRF_LOADING_DISPLAY, SRF_LOADING} m_state; +private: + char *m_loading_text; // Used to have the actual text in only + char *m_synchronising_text; // one place (easier to change, avoids + // multiple translations in case of typos) public: StartRaceFeedback(); ~StartRaceFeedback(); diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index a880e7232..d9809acd6 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -1010,10 +1010,6 @@ RelativePath="..\..\gui\network_gui.cpp" > - - @@ -1090,6 +1086,10 @@ RelativePath="..\..\challenges\challenge_data.cpp" > + + - - diff --git a/src/network/character_info_message.hpp b/src/network/character_info_message.hpp new file mode 100644 index 000000000..d273986fc --- /dev/null +++ b/src/network/character_info_message.hpp @@ -0,0 +1,32 @@ +// $Id: character_info_message.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_CHARACTER_INFO_MESSAGE_H +#define HEADER_CHARACTER_INFO_MESSAGE_H + +#include "network/message.hpp" + +class CharacterInfoMessage : public Message +{ +// For now this is an empty message +public: + CharacterInfoMessage() :Message(Message::MT_CHARACTER_INFO) {allocate(0);} + CharacterInfoMessage(ENetPacket* pkt):Message(pkt, MT_CHARACTER_INFO) {} +}; // CharacterInfoMessage +#endif diff --git a/src/network/character_selected_message.hpp b/src/network/character_selected_message.hpp new file mode 100644 index 000000000..3ff6ddb15 --- /dev/null +++ b/src/network/character_selected_message.hpp @@ -0,0 +1,61 @@ +// $Id: character_selected_message.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_CHARACTER_SELECTED_MESSAGE_H +#define HEADER_CHARACTER_SELECTED_MESSAGE_H + +#include "network/message.hpp" +#include "user_config.hpp" +#include "race_manager.hpp" +#include "network/remote_kart_info.hpp" + +class CharacterSelectedMessage : public Message +{ +private: + int m_num_local_players; + RemoteKartInfo m_kart_info; +// For now this is an empty message +public: + CharacterSelectedMessage(int player_id) :Message(Message::MT_CHARACTER_INFO) + { + m_kart_info = race_manager->getLocalKartInfo(player_id); + m_num_local_players = race_manager->getNumLocalPlayers(); + + allocate(getLength(m_kart_info.getLocalPlayerId()) + +getLength(m_kart_info.getKartName()) + +getLength(m_kart_info.getPlayerName()) + +getLength(m_num_local_players) ); + add(m_kart_info.getLocalPlayerId()); + add(m_kart_info.getKartName()); + add(m_kart_info.getPlayerName()); + // Piggy backing this information saves sending it as a separate + // message. It is actually only required in the first message + add(race_manager->getNumLocalPlayers()); + } + CharacterSelectedMessage(ENetPacket* pkt):Message(pkt, MT_CHARACTER_INFO) + { + m_kart_info.setLocalPlayerId(getInt()); + m_kart_info.setKartName(getString()); + m_kart_info.setPlayerName(getString()); + m_num_local_players = getInt(); + } + const RemoteKartInfo& getKartInfo () const { return m_kart_info; } + int getNumPlayers() const { return m_num_local_players; } +}; // CharacterInfoMessage +#endif diff --git a/src/network/connect_message.hpp b/src/network/connect_message.hpp new file mode 100644 index 000000000..7d1c13a8b --- /dev/null +++ b/src/network/connect_message.hpp @@ -0,0 +1,53 @@ +// $Id: connect_message.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_CONNECT_MESSAGE_H +#define HEADER_CONNECT_MESSAGE_H + +#include +#include +#ifndef WIN32 +# include +#endif + +#include "network/message.hpp" +#include "user_config.hpp" + +class ConnectMessage : public Message +{ +private: + std::string m_id; + void setId() + { + char hostname[256]; + gethostname(hostname, 255); + const std::string& id=user_config->m_player[0].getName(); + std::ostringstream o; + o << id << '@' << hostname; + allocate(getLength(o.str())); + add(o.str()); + } +public: + ConnectMessage():Message(Message::MT_CONNECT) { setId(); } + ConnectMessage(ENetPacket* pkt):Message(pkt, MT_CONNECT) + { m_id=getString(); } + const std::string& + getId() { return m_id; } +}; // ConnectMessage +#endif diff --git a/src/network/message.cpp b/src/network/message.cpp new file mode 100644 index 000000000..bdd553dcf --- /dev/null +++ b/src/network/message.cpp @@ -0,0 +1,124 @@ +// $Id: message.cpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs, Stephen Leak +// +// 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 "message.hpp" +#include +#include +#include + + +// need a more elegant way of setting the data_size, esp when strings are being used + +// also, looking at how the packets are actually used, we can probably serialise as +// part of the constructor, it seems packets to be sent are always created in a +// single line +#include + +Message::Message(MessageType type) +{ + assert(sizeof(int)==4); + m_type = type; + m_pos = 0; + m_data_size = -1; + m_data = NULL; + m_needs_destroy = 0; // enet destroys message after send +} // Message + +// ---------------------------------------------------------------------------- +Message::Message(ENetPacket* pkt, MessageType m) +{ + assert(sizeof(int)==4); + m_pkt = pkt; + m_data_size = pkt->dataLength; + m_data = (char*)pkt->data; + m_type = (MessageType)m_data[0]; + assert(m_type==m); + m_pos = 1; + m_needs_destroy = true; +} // Message + +// ---------------------------------------------------------------------------- +Message::~Message() +{ + if(m_needs_destroy) + enet_packet_destroy(m_pkt); +} // ~Message + +// ---------------------------------------------------------------------------- +void Message::allocate(int size) +{ + m_data_size = size+1; + m_pkt = enet_packet_create (NULL, m_data_size, ENET_PACKET_FLAG_RELIABLE); + m_data = (char*)m_pkt->data; + m_data[0] = m_type; + m_pos = 1; +} // allocate + +// ---------------------------------------------------------------------------- +bool Message::add(int data) +{ + if (m_pos > m_data_size) + return false; + int l=htonl(data); + memcpy(m_data+m_pos, &l, sizeof(int)); + m_pos+=sizeof(int); + return true; +} // add + +// ---------------------------------------------------------------------------- +int Message::getInt() +{ + m_pos+=sizeof(int); + return ntohl(*(int*)(&m_data[m_pos-sizeof(int)])); +} // getInt + +// ---------------------------------------------------------------------------- +bool Message::add(float data) +{ + int *dcast = (int*) &data; + return add(*dcast); +} // add + +// ---------------------------------------------------------------------------- +float Message::getFloat() +{ // ugly... + int i = getInt(); + float *f = (float*) &i; + return *f; +} // getFloat + +// ---------------------------------------------------------------------------- +bool Message::add(const std::string &data) +{ + int len = data.size()+1; // copy 0 end byte + assert(m_pos+len <=m_data_size); + memcpy (&(m_data[m_pos]), data.c_str(), len); + m_pos += len; + return true; +} // add + +// ---------------------------------------------------------------------------- +std::string Message::getString() +{ + char *str = (char*) &(m_data[m_pos]); + int len = strlen(str)+1; + m_pos += len; + return std::string(str); +} // getString + diff --git a/src/network/message.hpp b/src/network/message.hpp new file mode 100644 index 000000000..b8c1ace0c --- /dev/null +++ b/src/network/message.hpp @@ -0,0 +1,77 @@ +// $Id: network_manager.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs, Stephen Leak +// +// 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_MESSAGE_H +#define HEADER_MESSAGE_H + +#include +#include + +#ifdef HAVE_ENET +# include "enet/enet.h" +#endif + +// sjl: when a message is received, need to work out what kind of message it +// is and therefore what to do with it + +// Collects and serialises/deserialises kart info to send +class Message +{ +public: + enum MessageType {MT_CONNECT=1, MT_CHARACTER_INFO, + MT_RACE_INFO, MT_RACE_START, MT_WORLD_LOADED}; +private: + ENetPacket *m_pkt; + char *m_data; + MessageType m_type; + int m_data_size; + int m_pos; // simple stack counter for constructing packet data + bool m_needs_destroy; // only received messages need to be destroyed + +protected: + bool add(int data); + bool add(size_t data) { return add((int)data); } + bool add(unsigned int data) { return add((int)data); } + bool add(float data); + bool add(const std::string &data); + int getInt(); + float getFloat(); + std::string getString(); + int getLength(const std::string& s) { return s.size()+1; } + int getLength(int n) { return sizeof(int); } + int getLength(unsigned int n) { return sizeof(int); } + int getLength(size_t n) { return sizeof(int); } + int getLength(float f) { return sizeof(float); } + +public: + Message(MessageType m); // create from scratch (to send) + Message(ENetPacket *pkt, MessageType m); // create from (received) packet + ~Message(); + void allocate(int size); + MessageType getType() const { return m_type; } + ENetPacket* getPacket() const { assert(m_data_size>-1); return m_pkt; } + // Return the type of a message without unserialising the message + static MessageType peekType(ENetPacket *pkt) + { return (MessageType)pkt->data[0];} + +}; // Message + + +#endif + diff --git a/src/network/num_players_message.hpp b/src/network/num_players_message.hpp new file mode 100644 index 000000000..fb4d14661 --- /dev/null +++ b/src/network/num_players_message.hpp @@ -0,0 +1,43 @@ +// $Id: num_players.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_NUM_PLAYERS_MESSAGE_H +#define HEADER_NUM_PLAYERS_MESSAGE_H + +#include +#include +#ifndef WIN32 +# include +#endif + +#include "network/message.hpp" +#include "race_manager.hpp" + +class NumPlayersMessage : public Message +{ +private: + int m_num_players +public: + NumPlayersMessage():Message(Message::MT_CONNECT) { m_num_players=race } + NumPlayersMessage(ENetPacket* pkt):Message(pkt) + { m_id=getString(); } + const std::string& + getNumPlayers() { return m_num_players; } +}; // ConnectMessage +#endif \ No newline at end of file diff --git a/src/network/race_info_message.cpp b/src/network/race_info_message.cpp new file mode 100644 index 000000000..f98e5a1e9 --- /dev/null +++ b/src/network/race_info_message.cpp @@ -0,0 +1,103 @@ +// $Id: race_info_message.cpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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 "race_info_message.hpp" +#include "grand_prix_manager.hpp" +#include "race_manager.hpp" + +RaceInfoMessage::RaceInfoMessage(const std::vector& kart_info) + : Message(Message::MT_RACE_INFO) +{ + const GrandPrixData *cup=NULL; + int len = getLength(race_manager->getMajorMode() ) + + getLength(race_manager->getMinorMode() ) + + getLength(race_manager->getDifficulty()); + if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX) + { + cup = race_manager->getGrandPrix(); + len += getLength(cup->getId()); + } + else + len += getLength(race_manager->getTrackName()); + + len += getLength(kart_info.size()); + for(unsigned int i=0; igetMajorMode() ); + add(race_manager->getMinorMode() ); + add(race_manager->getDifficulty()); + if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX) + add(cup->getName()); + else + add(race_manager->getTrackName()); + + add(kart_info.size()); + for(unsigned int i=0; isetMajorMode ( RaceManager::RaceModeType(getInt()) ); + race_manager->setMinorMode ( RaceManager::RaceModeType(getInt()) ); + race_manager->setDifficulty( RaceManager::Difficulty (getInt()) ); + if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX) + { + GrandPrixData cup; + grand_prix_manager->getGrandPrix(getString()); + race_manager->setGrandPrix(cup); + } + else + race_manager->setTrack(getString()); + + std::vector kart_info; + kart_info.resize(getInt()); + + for(unsigned int i=0; isetNumPlayers(kart_info.size()); + for(unsigned int i=0; isetPlayerKart(i, kart_info[i]); + } + +} // RaceInfoMessage diff --git a/src/network/race_info_message.hpp b/src/network/race_info_message.hpp new file mode 100644 index 000000000..f74b6d4e6 --- /dev/null +++ b/src/network/race_info_message.hpp @@ -0,0 +1,34 @@ +// $Id: race_info_message.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_RACE_INFO_MESSAGE_H +#define HEADER_RACE_INFO_MESSAGE_H + +#include + +#include "network/message.hpp" +#include "network/remote_kart_info.hpp" + +class RaceInfoMessage : public Message +{ +public: + RaceInfoMessage(const std::vector& kart_info); + RaceInfoMessage(ENetPacket* pkt); +}; // RaceInfoMessage +#endif diff --git a/src/network/race_start_message.hpp b/src/network/race_start_message.hpp new file mode 100644 index 000000000..76530d822 --- /dev/null +++ b/src/network/race_start_message.hpp @@ -0,0 +1,41 @@ +// $Id: race_start_message.hpp 2128 2008-06-13 00:53:52Z cosmosninja $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2008 Joerg Henrichs +// +// 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_RACE_START_MESSAGE_H +#define HEADER_RACE_START_MESSAGE_H + +#include "network/message.hpp" +#include "race_manager.hpp" +#include "network/remote_kart_info.hpp" + +class RaceStartMessage : public Message +{ +private: +// For now this is an empty message +public: + RaceStartMessage() : Message(Message::MT_RACE_START) + { + allocate(0); + } // RaceStartMessage + + RaceStartMessage(ENetPacket* pkt):Message(pkt, MT_RACE_INFO) + { + } +}; // RaceStartMessage +#endif diff --git a/src/network/remote_kart_info.hpp b/src/network/remote_kart_info.hpp index fadc152d6..3e3733f65 100644 --- a/src/network/remote_kart_info.hpp +++ b/src/network/remote_kart_info.hpp @@ -35,22 +35,22 @@ public: 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; } + {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 setPlayerName(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) const { return (m_host_idm_x - m_width; break; case WGT_DIR_RIGHT_WIDGET: - m_x = m_widget_horizontal->m_x+m_widget_horizontal->m_width; break; + m_x = m_widget_horizontal->m_x+m_widget_horizontal->m_width + + (int)(user_config->m_width*m_percentage_x); break; default: break; } // switch diff --git a/src/world.cpp b/src/world.cpp index 7f5ac5247..743e575ee 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -147,6 +147,8 @@ World::World() break; case RaceManager::KT_GHOST: break; + case RaceManager::KT_LEADER: + break; } } // if !user_config->m_profile if(user_config->m_replay_history) @@ -189,7 +191,7 @@ World::World() } if( m_p_replay_player ) m_p_replay_player->showReplayAt( 0.0 ); #endif - network_manager->switchToReadySetGoBarrier(); + network_manager->worldLoaded(); } // World //-----------------------------------------------------------------------------