Moved network related code into network subdir.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2226 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
d3b4fcf8e7
commit
44f5691bab
@ -30,7 +30,8 @@ supertuxkart_SOURCES = main.cpp \
|
||||
coord.hpp \
|
||||
actionmap.cpp actionmap.hpp \
|
||||
material.cpp material.hpp \
|
||||
network_manager.cpp network_manager.hpp \
|
||||
network/network_manager.cpp network/network_manager.hpp \
|
||||
network/remote_kart_info.hpp \
|
||||
material_manager.cpp material_manager.hpp \
|
||||
grand_prix_manager.cpp grand_prix_manager.hpp \
|
||||
attachment.cpp attachment.hpp \
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "user_config.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "history.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
GameManager* game_manager = 0;
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "material.hpp"
|
||||
#include "unlock_manager.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define snprintf _snprintf
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "translation.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "unlock_manager.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
enum WidgetTokens
|
||||
{
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "widget_manager.hpp"
|
||||
#include "menu_manager.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
enum WidgetTokens
|
||||
{
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "material_manager.hpp"
|
||||
#include "unlock_manager.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define snprintf _snprintf
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "widget_manager.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
|
||||
enum WidgetTokens
|
||||
{
|
||||
|
@ -39,8 +39,8 @@ NetworkManager::NetworkManager()
|
||||
exit(-1);
|
||||
}
|
||||
// FIXME: debugging
|
||||
m_kart_info.push_back(KartInfo("tuxkart","xx", 1));
|
||||
m_kart_info.push_back(KartInfo("yeti", "yy", 1));
|
||||
m_kart_info.push_back(RemoteKartInfo("tuxkart","xx", 1));
|
||||
m_kart_info.push_back(RemoteKartInfo("yeti", "yy", 1));
|
||||
#endif
|
||||
} // NetworkManager
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "network/remote_kart_info.hpp"
|
||||
|
||||
#ifdef HAVE_ENET
|
||||
# include "enet/enet.h"
|
||||
#endif
|
||||
@ -37,28 +39,15 @@ public:
|
||||
enum NetworkState {NS_SYNCHRONISING, NS_RACING};
|
||||
private:
|
||||
|
||||
// A simple struct to store information
|
||||
class KartInfo
|
||||
{
|
||||
public:
|
||||
std::string m_kart_name;
|
||||
std::string m_user_name;
|
||||
int m_client_id;
|
||||
int m_player_id;
|
||||
KartInfo(std::string kart_name, std::string user_name, int id)
|
||||
: m_kart_name(kart_name), m_user_name(user_name), m_client_id(id)
|
||||
{};
|
||||
}; // KartInfo
|
||||
|
||||
NetworkMode m_mode;
|
||||
NetworkState m_state;
|
||||
int m_port;
|
||||
std::string m_server_address;
|
||||
int m_num_clients;
|
||||
std::vector<KartInfo> m_kart_info;
|
||||
int m_host_id;
|
||||
NetworkMode m_mode;
|
||||
NetworkState m_state;
|
||||
int m_port;
|
||||
std::string m_server_address;
|
||||
int m_num_clients;
|
||||
std::vector<RemoteKartInfo> m_kart_info;
|
||||
int m_host_id;
|
||||
#ifdef HAVE_ENET
|
||||
ENetHost *m_host;
|
||||
ENetHost *m_host;
|
||||
#endif
|
||||
|
||||
bool initServer();
|
||||
@ -74,7 +63,7 @@ public:
|
||||
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 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; }
|
43
src/network/remote_kart_info.hpp
Normal file
43
src/network/remote_kart_info.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
// $Id: remote_kart_information.hpp 2190 2008-07-29 05:38:30Z hikerstk $
|
||||
//
|
||||
// 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_REMOTE_KART_INFO_H
|
||||
#define HEADER_REMOTE_KART_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class RemoteKartInfo
|
||||
{
|
||||
std::string m_kart_name;
|
||||
std::string m_user_name;
|
||||
int m_client_id;
|
||||
int m_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 setHostId(int id) { m_client_id = id; }
|
||||
void setPlayerId(int id) { m_player_id = id; }
|
||||
}; // RemoteKartInfo
|
||||
|
||||
#endif
|
@ -29,7 +29,7 @@
|
||||
#include "scene.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "stk_config.hpp"
|
||||
|
||||
#include "network_manager.hpp"
|
||||
|
||||
RaceManager* race_manager= NULL;
|
||||
|
||||
@ -67,8 +67,9 @@ void RaceManager::setLocalPlayerKart(unsigned int player, const std::string& kar
|
||||
{
|
||||
if (player >= getNumLocalPlayers())
|
||||
setNumLocalPlayers(player+1);
|
||||
m_local_player_karts[player] = kart;
|
||||
|
||||
m_local_player_karts[player].setPlayerId(player);
|
||||
m_local_player_karts[player].setKartName(kart);
|
||||
m_local_player_karts[player].setHostId(network_manager->getHostId());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -82,18 +83,14 @@ void RaceManager::setPlayerKart(unsigned int player, const std::string& kart,
|
||||
if (player >= getNumPlayers())
|
||||
setNumPlayers(player+1);
|
||||
m_player_karts[player] = kart;
|
||||
m_player_names[player] = player_name;
|
||||
} // setPlayerKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void RaceManager::setNumPlayers(int num)
|
||||
{
|
||||
m_player_karts.resize(num);
|
||||
m_player_names.resize(num);
|
||||
for(PlayerKarts::iterator i = m_player_karts.begin(); i != m_player_karts.end(); ++i)
|
||||
if (i->empty()) *i = "tuxkart";
|
||||
for(PlayerKarts::iterator i = m_player_names.begin(); i != m_player_names.end(); ++i)
|
||||
if (i->empty()) *i = "guest";
|
||||
|
||||
} // setNumPlayers
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "grand_prix_data.hpp"
|
||||
#include "network/remote_kart_info.hpp"
|
||||
|
||||
/** The race manager has two functions:
|
||||
1) it stores information about the race the user selected (e.g. number
|
||||
@ -78,8 +79,7 @@ private:
|
||||
RaceModeType m_major_mode, m_minor_mode;
|
||||
typedef std::vector<std::string> PlayerKarts;
|
||||
PlayerKarts m_player_karts;
|
||||
PlayerKarts m_local_player_karts;
|
||||
std::vector<std::string> m_player_names;
|
||||
std::vector<RemoteKartInfo> m_local_player_karts;
|
||||
std::vector<std::string> m_tracks;
|
||||
std::vector<int> m_host_ids;
|
||||
std::vector<int> m_num_laps;
|
||||
@ -109,8 +109,8 @@ public:
|
||||
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 std::string&
|
||||
getLocalPlayerKart(unsigned int p) const {return m_local_player_karts[p];}
|
||||
const RemoteKartInfo&
|
||||
getLocalPlayerKart(unsigned int p) const {return m_local_player_karts[p]; }
|
||||
void reset();
|
||||
void RaceFinished(const Kart* kart, float time);
|
||||
void setTrack(const std::string& track);
|
||||
|
Loading…
x
Reference in New Issue
Block a user