Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5820 for code/branches/core5


Ignore:
Timestamp:
Sep 28, 2009, 2:55:47 AM (15 years ago)
Author:
landauf
Message:

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.

Location:
code/branches/core5/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/network/ClientConnectionListener.cc

    r5738 r5820  
    3333#include "ClientInformation.h"
    3434
    35 namespace orxonox{
     35namespace orxonox
     36{
     37    ClientConnectionListener::ClientConnectionListener()
     38    {
     39        RegisterRootObject(ClientConnectionListener);
     40    }
    3641
    37   ClientConnectionListener::ClientConnectionListener()
    38   {
    39     RegisterRootObject(ClientConnectionListener);
    40   }
     42    void ClientConnectionListener::broadcastClientConnected(unsigned int clientID)
     43    {
     44        for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
     45            it->clientConnected(clientID);
     46    }
     47   
     48    void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID)
     49    {
     50        for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
     51            it->clientDisconnected(clientID);
     52    }
    4153
    42   void ClientConnectionListener::getConnectedClients(){
    43     if(GameMode::showsGraphics())
    44       this->clientConnected(0); //server client id
    45     ClientInformation *client = ClientInformation::getBegin();
    46     while(client){
    47       this->clientConnected(client->getID());
    48       client=client->next();
     54    void ClientConnectionListener::getConnectedClients()
     55    {
     56        ClientInformation* client = ClientInformation::getBegin();
     57        while (client)
     58        {
     59            this->clientConnected(client->getID());
     60            client = client->next();
     61        }
    4962    }
    50   }
    51 
    5263}
    5364
  • code/branches/core5/src/libraries/network/ClientConnectionListener.h

    r5738 r5820  
    3333#include "core/OrxonoxClass.h"
    3434
    35 namespace orxonox{
     35namespace orxonox
     36{
     37    class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
     38    {
     39        public:
     40            ClientConnectionListener();
     41            virtual ~ClientConnectionListener() {}
     42           
     43            static void broadcastClientConnected(unsigned int clientID);
     44            static void broadcastClientDisconnected(unsigned int clientID);
    3645
    37   class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
    38   {
    39     friend class Server;
     46            virtual void clientConnected(unsigned int clientID) = 0;
     47            virtual void clientDisconnected(unsigned int clientID) = 0;
    4048
    41   public:
    42     ClientConnectionListener();
    43     virtual ~ClientConnectionListener() {}
    44 
    45     void getConnectedClients();
    46 
    47   protected:
    48     virtual void clientConnected(unsigned int clientID) = 0;
    49     virtual void clientDisconnected(unsigned int clientID) = 0;
    50   };
    51 
     49        protected:
     50            void getConnectedClients();
     51    };
    5252}
    5353
  • code/branches/core5/src/libraries/network/Server.cc

    r5749 r5820  
    279279
    280280    // inform all the listeners
    281     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    282     while(listener){
    283       listener->clientConnected(newid);
    284       listener++;
    285     }
     281    ClientConnectionListener::broadcastClientConnected(newid);
    286282
    287283    ++newid;
     
    329325    ServerConnection::disconnectClient( client );
    330326    GamestateManager::removeClient(client);
    331 // inform all the listeners
    332     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    333     while(listener){
    334       listener->clientDisconnected(client->getID());
    335       ++listener;
    336     }
     327    // inform all the listeners
     328    ClientConnectionListener::broadcastClientDisconnected(client->getID());
     329
    337330    delete client; //remove client from list
    338331  }
  • code/branches/core5/src/modules/gamestates/GSLevel.cc

    r5818 r5820  
    129129            // level is loaded: we can start capturing the input
    130130            InputManager::getInstance().enterState("game");
     131           
     132            // connect the HumanPlayer to the game
     133            this->playerManager_->clientConnected(0);
    131134        }
    132135    }
     
    177180
    178181        if (GameMode::showsGraphics())
     182        {
     183            // disconnect the HumanPlayer
     184            this->playerManager_->clientDisconnected(0);
     185           
    179186            InputManager::getInstance().leaveState("game");
     187        }
    180188
    181189        if (GameMode::isMaster())
     
    234242    void GSLevel::unloadLevel()
    235243    {
    236         for (ObjectList<HumanPlayer>::iterator it = ObjectList<HumanPlayer>::begin(); it; ++it)
    237             it->setGametype(0);
    238        
    239244        Loader::unload(startFile_s);
    240245
  • code/branches/core5/src/orxonox/LevelManager.cc

    r5738 r5820  
    3939#include "PlayerManager.h"
    4040#include "Level.h"
    41 #include "infos/HumanPlayer.h"
    4241
    4342namespace orxonox
  • code/branches/core5/src/orxonox/PlayerManager.cc

    r5801 r5820  
    7474        if (GameMode::isMaster())
    7575        {
    76             COUT(3) << "client disconnected" << std::endl;
     76            if (clientID != 0)
     77                COUT(3) << "client disconnected" << std::endl;
    7778
    7879            // remove from clients-map
  • code/branches/core5/src/orxonox/PlayerManager.h

    r3370 r5820  
    5050                { return this->clients_; }
    5151
    52         private:
    5352            void clientConnected(unsigned int clientID);
    5453            void clientDisconnected(unsigned int clientID);
    5554
     55        private:
    5656            std::map<unsigned int, PlayerInfo*> clients_;
    5757
Note: See TracChangeset for help on using the changeset viewer.