[Orxonox-commit 1099] r5820 - in code/branches/core5/src: libraries/network modules/gamestates orxonox
landauf at orxonox.net
landauf at orxonox.net
Mon Sep 28 02:55:48 CEST 2009
Author: landauf
Date: 2009-09-28 02:55:47 +0200 (Mon, 28 Sep 2009)
New Revision: 5820
Modified:
code/branches/core5/src/libraries/network/ClientConnectionListener.cc
code/branches/core5/src/libraries/network/ClientConnectionListener.h
code/branches/core5/src/libraries/network/Server.cc
code/branches/core5/src/modules/gamestates/GSLevel.cc
code/branches/core5/src/orxonox/LevelManager.cc
code/branches/core5/src/orxonox/PlayerManager.cc
code/branches/core5/src/orxonox/PlayerManager.h
Log:
Changes in ClientConnectionListener:
- Added static functions for connect/disconnect which notify all instances
- getConnectedClients() also returned client "0" which is the ID of the server. This is important for the PlayerManager, but other classes (like for example TrafficControl) don't use getConnectedClients(), so I assumed I can safely remove this line. The 0-client gets now connected and disconnected in GSLevel (which also creates and destroys the PlayerManager). If the 0-client is also needed by other classes, I suggest moving it into the network.
The instance of HumanPlayer is now deleted if GSLevel gets deactivated. This also destroys the default HUD.
Modified: code/branches/core5/src/libraries/network/ClientConnectionListener.cc
===================================================================
--- code/branches/core5/src/libraries/network/ClientConnectionListener.cc 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/libraries/network/ClientConnectionListener.cc 2009-09-28 00:55:47 UTC (rev 5820)
@@ -32,23 +32,34 @@
#include "core/GameMode.h"
#include "ClientInformation.h"
-namespace orxonox{
+namespace orxonox
+{
+ ClientConnectionListener::ClientConnectionListener()
+ {
+ RegisterRootObject(ClientConnectionListener);
+ }
- ClientConnectionListener::ClientConnectionListener()
- {
- RegisterRootObject(ClientConnectionListener);
- }
+ void ClientConnectionListener::broadcastClientConnected(unsigned int clientID)
+ {
+ for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
+ it->clientConnected(clientID);
+ }
+
+ void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID)
+ {
+ for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
+ it->clientDisconnected(clientID);
+ }
- void ClientConnectionListener::getConnectedClients(){
- if(GameMode::showsGraphics())
- this->clientConnected(0); //server client id
- ClientInformation *client = ClientInformation::getBegin();
- while(client){
- this->clientConnected(client->getID());
- client=client->next();
+ void ClientConnectionListener::getConnectedClients()
+ {
+ ClientInformation* client = ClientInformation::getBegin();
+ while (client)
+ {
+ this->clientConnected(client->getID());
+ client = client->next();
+ }
}
- }
-
}
Modified: code/branches/core5/src/libraries/network/ClientConnectionListener.h
===================================================================
--- code/branches/core5/src/libraries/network/ClientConnectionListener.h 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/libraries/network/ClientConnectionListener.h 2009-09-28 00:55:47 UTC (rev 5820)
@@ -32,23 +32,23 @@
#include "NetworkPrereqs.h"
#include "core/OrxonoxClass.h"
-namespace orxonox{
+namespace orxonox
+{
+ class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
+ {
+ public:
+ ClientConnectionListener();
+ virtual ~ClientConnectionListener() {}
+
+ static void broadcastClientConnected(unsigned int clientID);
+ static void broadcastClientDisconnected(unsigned int clientID);
- class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
- {
- friend class Server;
+ virtual void clientConnected(unsigned int clientID) = 0;
+ virtual void clientDisconnected(unsigned int clientID) = 0;
- public:
- ClientConnectionListener();
- virtual ~ClientConnectionListener() {}
-
- void getConnectedClients();
-
- protected:
- virtual void clientConnected(unsigned int clientID) = 0;
- virtual void clientDisconnected(unsigned int clientID) = 0;
- };
-
+ protected:
+ void getConnectedClients();
+ };
}
Modified: code/branches/core5/src/libraries/network/Server.cc
===================================================================
--- code/branches/core5/src/libraries/network/Server.cc 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/libraries/network/Server.cc 2009-09-28 00:55:47 UTC (rev 5820)
@@ -278,11 +278,7 @@
temp->setPeer(event->peer);
// inform all the listeners
- ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
- while(listener){
- listener->clientConnected(newid);
- listener++;
- }
+ ClientConnectionListener::broadcastClientConnected(newid);
++newid;
@@ -328,12 +324,9 @@
void Server::disconnectClient( ClientInformation *client ){
ServerConnection::disconnectClient( client );
GamestateManager::removeClient(client);
-// inform all the listeners
- ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
- while(listener){
- listener->clientDisconnected(client->getID());
- ++listener;
- }
+ // inform all the listeners
+ ClientConnectionListener::broadcastClientDisconnected(client->getID());
+
delete client; //remove client from list
}
Modified: code/branches/core5/src/modules/gamestates/GSLevel.cc
===================================================================
--- code/branches/core5/src/modules/gamestates/GSLevel.cc 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/modules/gamestates/GSLevel.cc 2009-09-28 00:55:47 UTC (rev 5820)
@@ -128,6 +128,9 @@
// level is loaded: we can start capturing the input
InputManager::getInstance().enterState("game");
+
+ // connect the HumanPlayer to the game
+ this->playerManager_->clientConnected(0);
}
}
@@ -176,7 +179,12 @@
//Loader::close();
if (GameMode::showsGraphics())
+ {
+ // disconnect the HumanPlayer
+ this->playerManager_->clientDisconnected(0);
+
InputManager::getInstance().leaveState("game");
+ }
if (GameMode::isMaster())
this->unloadLevel();
@@ -233,9 +241,6 @@
void GSLevel::unloadLevel()
{
- for (ObjectList<HumanPlayer>::iterator it = ObjectList<HumanPlayer>::begin(); it; ++it)
- it->setGametype(0);
-
Loader::unload(startFile_s);
delete startFile_s;
Modified: code/branches/core5/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/core5/src/orxonox/LevelManager.cc 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/orxonox/LevelManager.cc 2009-09-28 00:55:47 UTC (rev 5820)
@@ -38,7 +38,6 @@
#include "core/Loader.h"
#include "PlayerManager.h"
#include "Level.h"
-#include "infos/HumanPlayer.h"
namespace orxonox
{
Modified: code/branches/core5/src/orxonox/PlayerManager.cc
===================================================================
--- code/branches/core5/src/orxonox/PlayerManager.cc 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/orxonox/PlayerManager.cc 2009-09-28 00:55:47 UTC (rev 5820)
@@ -73,7 +73,8 @@
{
if (GameMode::isMaster())
{
- COUT(3) << "client disconnected" << std::endl;
+ if (clientID != 0)
+ COUT(3) << "client disconnected" << std::endl;
// remove from clients-map
PlayerInfo* player = this->clients_[clientID];
Modified: code/branches/core5/src/orxonox/PlayerManager.h
===================================================================
--- code/branches/core5/src/orxonox/PlayerManager.h 2009-09-27 23:00:21 UTC (rev 5819)
+++ code/branches/core5/src/orxonox/PlayerManager.h 2009-09-28 00:55:47 UTC (rev 5820)
@@ -49,10 +49,10 @@
inline const std::map<unsigned int, PlayerInfo*>& getClients() const
{ return this->clients_; }
- private:
void clientConnected(unsigned int clientID);
void clientDisconnected(unsigned int clientID);
+ private:
std::map<unsigned int, PlayerInfo*> clients_;
static PlayerManager* singletonPtr_s;
More information about the Orxonox-commit
mailing list