Added missing values to race info message, fixed state machine.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2238 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bb894b414d
commit
db75ee21f0
@ -70,22 +70,20 @@ void StartRaceFeedback::update(float delta)
|
||||
return;
|
||||
}
|
||||
|
||||
static bool first=true;
|
||||
if(first)
|
||||
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
||||
{
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
widget_manager->update(delta);
|
||||
|
||||
// Pops this menu
|
||||
race_manager->startNew();
|
||||
|
||||
} // update
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define HEADER_MESSAGE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef HAVE_ENET
|
||||
@ -46,18 +47,26 @@ private:
|
||||
|
||||
protected:
|
||||
bool add(int data);
|
||||
#ifndef WIN32 // on windows size_t is unsigned int
|
||||
bool add(size_t data) { return add((int)data); }
|
||||
#endif
|
||||
bool add(unsigned int data) { return add((int)data); }
|
||||
bool add(float data);
|
||||
bool add(const std::string &data);
|
||||
bool add(const std::vector<std::string>& vs);
|
||||
int getInt();
|
||||
float getFloat();
|
||||
std::string getString();
|
||||
int getLength(const std::string& s) { return s.size()+1; }
|
||||
std::vector<std::string>
|
||||
getStringVector();
|
||||
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); }
|
||||
int getLength(const std::string& s) { return s.size()+1; }
|
||||
int getLength(const std::vector<std::string>& vs);
|
||||
#ifndef WIN32
|
||||
int getLength(size_t n) { return sizeof(int); }
|
||||
#endif
|
||||
|
||||
public:
|
||||
Message(MessageType m); // create from scratch (to send)
|
||||
|
@ -240,6 +240,7 @@ void NetworkManager::handleMessageAtServer(ENetEvent *event)
|
||||
RaceStartMessage m;
|
||||
broadcastToClients(m);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: assert(0); // should not happen
|
||||
} // switch m_state
|
||||
@ -266,6 +267,9 @@ void NetworkManager::handleMessageAtClient(ENetEvent *event)
|
||||
}
|
||||
case NS_READY_SET_GO_BARRIER:
|
||||
{
|
||||
// Not actually needed, but the destructor of RaceStartMessage
|
||||
// will free the memory of the event.
|
||||
RaceStartMessage m(event->packet);
|
||||
m_state = NS_RACING;
|
||||
break;
|
||||
}
|
||||
@ -323,7 +327,7 @@ void NetworkManager::switchToCharacterSelection()
|
||||
// Change state to wait for list of characters from server
|
||||
m_state = NS_WAIT_FOR_AVAILABLE_CHARACTERS;
|
||||
}
|
||||
else
|
||||
else if(m_mode==NW_SERVER)
|
||||
{ // server: create message with all valid characters
|
||||
// ================================================
|
||||
CharacterInfoMessage m;
|
||||
@ -365,14 +369,8 @@ void NetworkManager::worldLoaded()
|
||||
{
|
||||
WorldLoadedMessage m;
|
||||
sendToServer(&m);
|
||||
m_state = NS_READY_SET_GO_BARRIER;
|
||||
}
|
||||
else if(m_mode==NW_SERVER)
|
||||
{
|
||||
assert(m_state=NS_READY_SET_GO_BARRIER);
|
||||
RaceStartMessage m;
|
||||
broadcastToClients(m);
|
||||
}
|
||||
|
||||
} // worldLoaded
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -398,6 +396,7 @@ void NetworkManager::setupPlayerKartInfo()
|
||||
{
|
||||
race_manager->setPlayerKart(i, m_kart_info[i]);
|
||||
}
|
||||
race_manager->computeRandomKartList();
|
||||
} // setupPlayerKartInfo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -405,9 +404,11 @@ void NetworkManager::setupPlayerKartInfo()
|
||||
*/
|
||||
void NetworkManager::sendRaceInformationToClients()
|
||||
{
|
||||
setupPlayerKartInfo();
|
||||
RaceInfoMessage m(m_kart_info);
|
||||
broadcastToClients(m);
|
||||
if(m_mode==NW_SERVER)
|
||||
{
|
||||
RaceInfoMessage m(m_kart_info);
|
||||
broadcastToClients(m);
|
||||
}
|
||||
m_state = NS_READY_SET_GO_BARRIER;
|
||||
m_barrier_count = 0;
|
||||
if(m_num_clients==0) m_state = NS_RACING;
|
||||
|
@ -27,15 +27,18 @@ RaceInfoMessage::RaceInfoMessage(const std::vector<RemoteKartInfo>& kart_info)
|
||||
const GrandPrixData *cup=NULL;
|
||||
int len = getLength(race_manager->getMajorMode() )
|
||||
+ getLength(race_manager->getMinorMode() )
|
||||
+ getLength(race_manager->getDifficulty());
|
||||
+ getLength(race_manager->getDifficulty())
|
||||
+ getLength(race_manager->getNumKarts() );
|
||||
if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX)
|
||||
{
|
||||
cup = race_manager->getGrandPrix();
|
||||
len += getLength(cup->getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
len += getLength(race_manager->getTrackName());
|
||||
|
||||
len += getLength(race_manager->getNumLaps());
|
||||
}
|
||||
len += getLength(kart_info.size());
|
||||
for(unsigned int i=0; i<kart_info.size(); i++)
|
||||
{
|
||||
@ -45,14 +48,21 @@ RaceInfoMessage::RaceInfoMessage(const std::vector<RemoteKartInfo>& kart_info)
|
||||
+ getLength(kart_info[i].getLocalPlayerId())
|
||||
+ getLength(kart_info[i].getPlayerName());
|
||||
}
|
||||
const std::vector<std::string>& rkl=race_manager->getRandomKartList();
|
||||
len += getLength(rkl);
|
||||
|
||||
allocate(len);
|
||||
add(race_manager->getMajorMode() );
|
||||
add(race_manager->getMinorMode() );
|
||||
add(race_manager->getDifficulty());
|
||||
add(race_manager->getNumKarts() );
|
||||
if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX)
|
||||
add(cup->getName());
|
||||
else
|
||||
{
|
||||
add(race_manager->getTrackName());
|
||||
add(race_manager->getNumLaps());
|
||||
}
|
||||
|
||||
add(kart_info.size());
|
||||
for(unsigned int i=0; i<kart_info.size(); i++)
|
||||
@ -63,7 +73,7 @@ RaceInfoMessage::RaceInfoMessage(const std::vector<RemoteKartInfo>& kart_info)
|
||||
add(kart_info[i].getLocalPlayerId());
|
||||
add(kart_info[i].getPlayerName());
|
||||
}
|
||||
|
||||
add(rkl);
|
||||
} // RaceInfoMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -72,6 +82,7 @@ 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()) );
|
||||
race_manager->setNumKarts ( getInt() );
|
||||
if(race_manager->getMajorMode()==RaceManager::RM_GRAND_PRIX)
|
||||
{
|
||||
GrandPrixData cup;
|
||||
@ -79,7 +90,10 @@ RaceInfoMessage::RaceInfoMessage(ENetPacket* pkt):Message(pkt, MT_RACE_INFO)
|
||||
race_manager->setGrandPrix(cup);
|
||||
}
|
||||
else
|
||||
{
|
||||
race_manager->setTrack(getString());
|
||||
race_manager->setNumLaps(getInt());
|
||||
}
|
||||
|
||||
std::vector<RemoteKartInfo> kart_info;
|
||||
kart_info.resize(getInt());
|
||||
@ -99,5 +113,6 @@ RaceInfoMessage::RaceInfoMessage(ENetPacket* pkt):Message(pkt, MT_RACE_INFO)
|
||||
{
|
||||
race_manager->setPlayerKart(i, kart_info[i]);
|
||||
}
|
||||
|
||||
std::vector<std::string> rkl=getStringVector();
|
||||
race_manager->setRandomKartList(rkl);
|
||||
} // RaceInfoMessage
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
allocate(0);
|
||||
} // RaceStartMessage
|
||||
|
||||
RaceStartMessage(ENetPacket* pkt):Message(pkt, MT_RACE_INFO)
|
||||
RaceStartMessage(ENetPacket* pkt):Message(pkt, MT_RACE_START)
|
||||
{
|
||||
}
|
||||
}; // RaceStartMessage
|
||||
|
Loading…
Reference in New Issue
Block a user