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
This commit is contained in:
hikerstk 2008-09-07 14:09:52 +00:00
parent 3ccd8500de
commit 9191f89333
19 changed files with 673 additions and 84 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -1010,10 +1010,6 @@
RelativePath="..\..\gui\network_gui.cpp"
>
</File>
<File
RelativePath="..\..\gui\network_info.cpp"
>
</File>
<File
RelativePath="../../../src\gui\num_players.cpp"
>
@ -1090,6 +1086,10 @@
RelativePath="..\..\challenges\challenge_data.cpp"
>
</File>
<File
RelativePath="..\..\network\race_info_message.cpp"
>
</File>
</Filter>
</Filter>
<Filter
@ -1492,10 +1492,6 @@
RelativePath="..\..\gui\network_gui.hpp"
>
</File>
<File
RelativePath="..\..\gui\network_info.hpp"
>
</File>
<File
RelativePath="../../../src\gui\num_players.hpp"
>

View File

@ -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

View File

@ -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

View File

@ -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 <string>
#include <sstream>
#ifndef WIN32
# include <unistd.h>
#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

124
src/network/message.cpp Normal file
View File

@ -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 <string>
#include <math.h>
#include <stdexcept>
// 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 <assert.h>
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>
// ----------------------------------------------------------------------------
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>
// ----------------------------------------------------------------------------
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<string>
// ----------------------------------------------------------------------------
std::string Message::getString()
{
char *str = (char*) &(m_data[m_pos]);
int len = strlen(str)+1;
m_pos += len;
return std::string(str);
} // getString

77
src/network/message.hpp Normal file
View File

@ -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 <string>
#include <assert.h>
#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

View File

@ -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 <string>
#include <sstream>
#ifndef WIN32
# include <unistd.h>
#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

View File

@ -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<RemoteKartInfo>& 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; i<kart_info.size(); i++)
{
len += getLength(kart_info[i].getGlobalPlayerId())
+ getLength(kart_info[i].getHostId())
+ getLength(kart_info[i].getKartName())
+ getLength(kart_info[i].getLocalPlayerId())
+ getLength(kart_info[i].getPlayerName());
}
allocate(len);
add(race_manager->getMajorMode() );
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; i<kart_info.size(); i++)
{
add(kart_info[i].getGlobalPlayerId());
add(kart_info[i].getHostId());
add(kart_info[i].getKartName());
add(kart_info[i].getLocalPlayerId());
add(kart_info[i].getPlayerName());
}
} // RaceInfoMessage
// ----------------------------------------------------------------------------
RaceInfoMessage::RaceInfoMessage(ENetPacket* pkt):Message(pkt, MT_RACE_INFO)
{
race_manager->setMajorMode ( 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<RemoteKartInfo> kart_info;
kart_info.resize(getInt());
for(unsigned int i=0; i<kart_info.size(); i++)
{
kart_info[i].setGlobalPlayerId(getInt());
kart_info[i].setHostId(getInt());
kart_info[i].setKartName(getString());
kart_info[i].setLocalPlayerId(getInt());
kart_info[i].setPlayerName(getString());
}
// Set the player kart information
race_manager->setNumPlayers(kart_info.size());
for(unsigned int i=0; i<kart_info.size(); i++)
{
race_manager->setPlayerKart(i, kart_info[i]);
}
} // RaceInfoMessage

View File

@ -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 <vector>
#include "network/message.hpp"
#include "network/remote_kart_info.hpp"
class RaceInfoMessage : public Message
{
public:
RaceInfoMessage(const std::vector<RemoteKartInfo>& kart_info);
RaceInfoMessage(ENetPacket* pkt);
}; // RaceInfoMessage
#endif

View File

@ -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

View File

@ -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_id<other.m_host_id ||

View File

@ -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_WORLD_LOADED_H
#define HEADER_WORLD_LOADED_H
#include "network/message.hpp"
class WorldLoadedMessage : public Message
{
// For now this is an empty message
public:
WorldLoadedMessage() :Message(MT_WORLD_LOADED) {allocate(0);}
WorldLoadedMessage(ENetPacket* pkt):Message(pkt, MT_WORLD_LOADED) {}
}; // WorldLoadedMessage
#endif

View File

@ -38,7 +38,7 @@ public:
Player(const std::string &name_):m_name(name_),m_last_kart_id(-1){}
void setName(const std::string &name_){m_name = name_;}
std::string getName() {return m_name;}
const std::string& getName() {return m_name;}
int getLastKartId(){ return m_last_kart_id; }
void setLastKartId(int newLastKartId){ m_last_kart_id = newLastKartId; }

View File

@ -111,7 +111,7 @@ void Widget::setPosition(WidgetDirection horizontal, float percentage_horizontal
m_percentage_x = percentage_horizontal;
m_widget_horizontal = w_hori;
// If the direction is left/right of a widget, but that widget is not defined
// use left/right (of screen). This simplified programming, since the e.g.
// use left/right (of screen). This simplifies programming, since the e.g.
// left-most widget will be positioned relative to the side of the screen
if(!w_hori)
{
@ -149,7 +149,8 @@ void Widget::layout()
case WGT_DIR_LEFT_WIDGET:
m_x = m_widget_horizontal->m_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

View File

@ -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
//-----------------------------------------------------------------------------