Moved GameSetup handling from NetworkManager to STKHost.
This commit is contained in:
parent
34f0d1b349
commit
85cca69113
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
NetworkManager::NetworkManager()
|
NetworkManager::NetworkManager()
|
||||||
{
|
{
|
||||||
m_game_setup = NULL;
|
|
||||||
} // NetworkManager
|
} // NetworkManager
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -156,27 +155,12 @@ void NetworkManager::sendPacketExcept(STKPeer* peer, const NetworkString& data,
|
|||||||
}
|
}
|
||||||
} // sendPacketExcept
|
} // sendPacketExcept
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/** A previous GameSetup is deletea and a new one is created.
|
|
||||||
* \return Newly create GameSetup object.
|
|
||||||
*/
|
|
||||||
GameSetup* NetworkManager::setupNewGame()
|
|
||||||
{
|
|
||||||
if (m_game_setup)
|
|
||||||
delete m_game_setup;
|
|
||||||
m_game_setup = new GameSetup();
|
|
||||||
return m_game_setup;
|
|
||||||
} // setupNewGame
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Called when you leave a server.
|
/** Called when you leave a server.
|
||||||
*/
|
*/
|
||||||
void NetworkManager::disconnected()
|
void NetworkManager::disconnected()
|
||||||
{
|
{
|
||||||
// delete the game setup
|
|
||||||
if (m_game_setup)
|
|
||||||
delete m_game_setup;
|
|
||||||
m_game_setup = NULL;
|
|
||||||
|
|
||||||
// remove all peers
|
// remove all peers
|
||||||
for (unsigned int i = 0; i < m_peers.size(); i++)
|
for (unsigned int i = 0; i < m_peers.size(); i++)
|
||||||
|
@ -55,7 +55,6 @@ protected:
|
|||||||
std::vector<STKPeer*> m_peers;
|
std::vector<STKPeer*> m_peers;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameSetup* m_game_setup;
|
|
||||||
|
|
||||||
PlayerLogin m_player_login;
|
PlayerLogin m_player_login;
|
||||||
|
|
||||||
@ -77,7 +76,6 @@ public:
|
|||||||
bool reliable = true);
|
bool reliable = true);
|
||||||
|
|
||||||
// Game related functions
|
// Game related functions
|
||||||
virtual GameSetup* setupNewGame();
|
|
||||||
virtual void disconnected();
|
virtual void disconnected();
|
||||||
virtual bool isServer() = 0;
|
virtual bool isServer() = 0;
|
||||||
|
|
||||||
@ -105,9 +103,6 @@ public:
|
|||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
unsigned int getPeerCount() { return (int)m_peers.size(); }
|
unsigned int getPeerCount() { return (int)m_peers.size(); }
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
|
||||||
/** Returns the current game setup. */
|
|
||||||
GameSetup* getGameSetup() { return m_game_setup; }
|
|
||||||
|
|
||||||
}; // class NetworkManager
|
}; // class NetworkManager
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ ClientLobbyRoomProtocol::~ClientLobbyRoomProtocol()
|
|||||||
|
|
||||||
void ClientLobbyRoomProtocol::setup()
|
void ClientLobbyRoomProtocol::setup()
|
||||||
{
|
{
|
||||||
m_setup = NetworkManager::getInstance()->setupNewGame(); // create a new setup
|
m_setup = STKHost::get()->setupNewGame(); // create a new setup
|
||||||
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be changed when logging into the server
|
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be changed when logging into the server
|
||||||
m_state = NONE;
|
m_state = NONE;
|
||||||
} // setup
|
} // setup
|
||||||
|
@ -51,7 +51,7 @@ bool GameEventsProtocol::notifyEvent(Event* event)
|
|||||||
uint8_t kart_race_id = data.gui8(5);
|
uint8_t kart_race_id = data.gui8(5);
|
||||||
// now set the kart powerup
|
// now set the kart powerup
|
||||||
AbstractKart* kart = World::getWorld()->getKart(
|
AbstractKart* kart = World::getWorld()->getKart(
|
||||||
NetworkManager::getInstance()->getGameSetup()->getProfile(kart_race_id)->world_kart_id);
|
STKHost::get()->getGameSetup()->getProfile(kart_race_id)->world_kart_id);
|
||||||
ItemManager::get()->collectedItem(
|
ItemManager::get()->collectedItem(
|
||||||
ItemManager::get()->getItem(item_id),
|
ItemManager::get()->getItem(item_id),
|
||||||
kart,
|
kart,
|
||||||
@ -75,7 +75,7 @@ void GameEventsProtocol::update()
|
|||||||
|
|
||||||
void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
||||||
{
|
{
|
||||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||||
assert(setup);
|
assert(setup);
|
||||||
const NetworkPlayerProfile* player_profile = setup->getProfile(kart->getIdent()); // use kart name
|
const NetworkPlayerProfile* player_profile = setup->getProfile(kart->getIdent()); // use kart name
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ ServerLobbyRoomProtocol::~ServerLobbyRoomProtocol()
|
|||||||
|
|
||||||
void ServerLobbyRoomProtocol::setup()
|
void ServerLobbyRoomProtocol::setup()
|
||||||
{
|
{
|
||||||
m_setup = NetworkManager::getInstance()->setupNewGame(); // create a new setup
|
m_setup = STKHost::get()->setupNewGame(); // create a new setup
|
||||||
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be moved to when logging into the server
|
m_setup->getRaceConfig()->setPlayerCount(16); //FIXME : this has to be moved to when logging into the server
|
||||||
m_next_id = 0;
|
m_next_id = 0;
|
||||||
m_state = NONE;
|
m_state = NONE;
|
||||||
|
@ -197,7 +197,7 @@ void StartGameProtocol::update()
|
|||||||
else if (m_state == READY)
|
else if (m_state == READY)
|
||||||
{
|
{
|
||||||
// set karts into the network game setup
|
// set karts into the network game setup
|
||||||
NetworkManager::getInstance()->getGameSetup()->bindKartsToProfiles();
|
STKHost::get()->getGameSetup()->bindKartsToProfiles();
|
||||||
m_state = EXITING;
|
m_state = EXITING;
|
||||||
requestTerminate();
|
requestTerminate();
|
||||||
}
|
}
|
||||||
|
@ -104,12 +104,12 @@ void* ServerConsole::mainLoop(void* data)
|
|||||||
}
|
}
|
||||||
else if (str == "compute_race")
|
else if (str == "compute_race")
|
||||||
{
|
{
|
||||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||||
setup->getRaceConfig()->computeRaceMode();
|
setup->getRaceConfig()->computeRaceMode();
|
||||||
}
|
}
|
||||||
else if (str == "compute_track")
|
else if (str == "compute_track")
|
||||||
{
|
{
|
||||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||||
setup->getRaceConfig()->computeNextTrack();
|
setup->getRaceConfig()->computeNextTrack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ STKHost::STKHost()
|
|||||||
{
|
{
|
||||||
m_network = NULL;
|
m_network = NULL;
|
||||||
m_listening_thread = NULL;
|
m_listening_thread = NULL;
|
||||||
|
m_game_setup = NULL;
|
||||||
|
|
||||||
m_public_address.lock();
|
m_public_address.lock();
|
||||||
m_public_address.getData().clear();
|
m_public_address.getData().clear();
|
||||||
@ -77,6 +78,11 @@ STKHost::STKHost()
|
|||||||
*/
|
*/
|
||||||
STKHost::~STKHost()
|
STKHost::~STKHost()
|
||||||
{
|
{
|
||||||
|
// delete the game setup
|
||||||
|
if (m_game_setup)
|
||||||
|
delete m_game_setup;
|
||||||
|
m_game_setup = NULL;
|
||||||
|
|
||||||
Network::closeLog();
|
Network::closeLog();
|
||||||
stopListening();
|
stopListening();
|
||||||
delete m_network;
|
delete m_network;
|
||||||
@ -90,6 +96,18 @@ void STKHost::setPublicAddress(const TransportAddress& addr)
|
|||||||
m_public_address.unlock();
|
m_public_address.unlock();
|
||||||
} // setPublicAddress
|
} // setPublicAddress
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** A previous GameSetup is deletea and a new one is created.
|
||||||
|
* \return Newly create GameSetup object.
|
||||||
|
*/
|
||||||
|
GameSetup* STKHost::setupNewGame()
|
||||||
|
{
|
||||||
|
if (m_game_setup)
|
||||||
|
delete m_game_setup;
|
||||||
|
m_game_setup = new GameSetup();
|
||||||
|
return m_game_setup;
|
||||||
|
} // setupNewGame
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** \brief Starts the listening of events from ENet.
|
/** \brief Starts the listening of events from ENet.
|
||||||
* Starts a thread for receiveData that updates it as often as possible.
|
* Starts a thread for receiveData that updates it as often as possible.
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
class GameSetup;
|
||||||
|
|
||||||
/*! \class STKHost
|
/*! \class STKHost
|
||||||
* \brief Represents the local host.
|
* \brief Represents the local host.
|
||||||
* This host is either a server host or a client host. A client host is in
|
* This host is either a server host or a client host. A client host is in
|
||||||
@ -75,6 +77,8 @@ private:
|
|||||||
* be updated from a separate thread. */
|
* be updated from a separate thread. */
|
||||||
Synchronised<TransportAddress> m_public_address;
|
Synchronised<TransportAddress> m_public_address;
|
||||||
|
|
||||||
|
GameSetup* m_game_setup;
|
||||||
|
|
||||||
/** Id of thread listening to enet events. */
|
/** Id of thread listening to enet events. */
|
||||||
pthread_t* m_listening_thread;
|
pthread_t* m_listening_thread;
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ public:
|
|||||||
|
|
||||||
static void* mainLoop(void* self);
|
static void* mainLoop(void* self);
|
||||||
|
|
||||||
|
virtual GameSetup* setupNewGame();
|
||||||
void setPublicAddress(const TransportAddress& addr);
|
void setPublicAddress(const TransportAddress& addr);
|
||||||
|
|
||||||
void setupServer(uint32_t address, uint16_t port,
|
void setupServer(uint32_t address, uint16_t port,
|
||||||
@ -138,6 +143,9 @@ public:
|
|||||||
return m_network->connectTo(address);
|
return m_network->connectTo(address);
|
||||||
} // connectTo
|
} // connectTo
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
/** Returns the current game setup. */
|
||||||
|
GameSetup* getGameSetup() { return m_game_setup; }
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
uint8_t* receiveRawPacket(TransportAddress* sender)
|
uint8_t* receiveRawPacket(TransportAddress* sender)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@ void NetworkKartSelectionScreen::init()
|
|||||||
m_multiplayer = false;
|
m_multiplayer = false;
|
||||||
|
|
||||||
// add a widget for each player except self (already exists):
|
// add a widget for each player except self (already exists):
|
||||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||||
if (!setup)
|
if (!setup)
|
||||||
{
|
{
|
||||||
Log::error("NetworkKartSelectionScreen", "No network game setup registered.");
|
Log::error("NetworkKartSelectionScreen", "No network game setup registered.");
|
||||||
|
Loading…
Reference in New Issue
Block a user