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