Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 9, 2008, 7:11:53 PM (16 years ago)
Author:
landauf
Message:

Split up LevelManager into LevelManager and PlayerManager where LevelManager handles all levels and is only active on the server, while PlayerManager handles client connections and passes new players to the LevelManager (if running on a server). If running on a client, PlayerManager just maps PlayerInfos with clientIDs.

Also added a small hack in Level.cc to show the ChatOverlay on clients.

Location:
code/branches/objecthierarchy/src
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/network/Synchronisable.cc

    r2156 r2168  
    7979    classID = (unsigned int)-1;
    8080    syncList = new std::list<synchronisableVariable *>;
    81    
    82    
     81
     82
    8383#ifndef NDEBUG
    8484    ObjectList<Synchronisable>::iterator it;
     
    173173      return 0;
    174174    }
    175    
     175
    176176    COUT(4) << "fabricating object with id: " << header->objectID << std::endl;
    177177
     
    240240    if (it1 != objectMap_.end())
    241241      return it1->second;
    242    
     242
    243243    ObjectList<Synchronisable>::iterator it;
    244244    for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     
    295295#endif
    296296  }
    297  
     297
    298298  void Synchronisable::unregisterVariable(void *var){
    299299    std::list<synchronisableVariable *>::iterator it = syncList->begin();
     
    311311    // the variable has not been registered before
    312312  }
    313  
     313
    314314
    315315  /**
     
    366366        continue;  // this variable should only be received
    367367      }
    368      
     368
    369369      // =========== start bidirectional stuff =============
    370370      // if the variable gets synchronised bidirectional, then add the reference to the bytestream
     
    397397      }
    398398      // ================== end bidirectional stuff
    399        
     399
    400400      switch((*i)->type){
    401401        case DATA:
     
    461461      bool callback=false;
    462462      bool master=false;
    463      
     463
    464464      if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
    465465      {
     
    505505        mem += sizeof((*i)->varReference);
    506506      }
    507      
     507
    508508      switch((*i)->type){
    509509        case DATA:
     
    525525          (*i)->size = *(size_t *)mem;
    526526          mem += sizeof(size_t);
    527          
     527
    528528          if( (*i)->callback) // check whether this string changed
    529529            if( *static_cast<std::string*>((*i)->var) != std::string((char *)mem) )
     
    535535              *static_cast<std::string*>((*i)->varBuffer)=*static_cast<std::string*>( (void*)(mem+sizeof(size_t)) );
    536536          }
    537          
     537
    538538          *((std::string *)((*i)->var)) = std::string((const char*)mem);
    539539          COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl;
  • code/branches/objecthierarchy/src/orxonox/CMakeLists.txt

    r2074 r2168  
    44  LevelManager.cc
    55  Main.cc
     6  PlayerManager.cc
    67  Settings.cc
    78
  • code/branches/objecthierarchy/src/orxonox/LevelManager.cc

    r2086 r2168  
    2828
    2929#include "OrxonoxStableHeaders.h"
    30 
    3130#include "LevelManager.h"
    3231
    33 #include "core/CoreIncludes.h"
    34 
     32#include "PlayerManager.h"
    3533#include "objects/infos/Level.h"
    3634#include "objects/infos/HumanPlayer.h"
     
    4240    LevelManager::LevelManager()
    4341    {
    44         RegisterRootObject(LevelManager);
    45 
    4642        assert(singletonRef_s == 0);
    4743        singletonRef_s = this;
    48 
    49         this->getConnectedClients();
    5044    }
    5145
     
    9589        {
    9690            this->levels_s.front()->setActive(true);
    97             for (std::map<unsigned int, PlayerInfo*>::iterator it = this->clients_.begin(); it != this->clients_.end(); ++it)
     91            for (std::map<unsigned int, PlayerInfo*>::const_iterator it = PlayerManager::getInstance().getClients().begin(); it != PlayerManager::getInstance().getClients().end(); ++it)
    9892                this->levels_s.front()->playerEntered(it->second);
    9993        }
    10094    }
    101 
    102 
    103     void LevelManager::clientConnected(unsigned int clientID)
    104     {
    105         COUT(3) << "client connected" << std::endl;
    106 
    107         // create new HumanPlayer instance
    108         HumanPlayer* player = new HumanPlayer(0);
    109         player->setClientID(clientID);
    110 
    111         // add to clients-map
    112         assert(!this->clients_[clientID]);
    113         this->clients_[clientID] = player;
    114 
    115         if (this->getActiveLevel())
    116             this->getActiveLevel()->playerEntered(player);
    117     }
    118 
    119     void LevelManager::clientDisconnected(unsigned int clientID)
    120     {
    121         COUT(3) << "client disconnected" << std::endl;
    122 
    123         // remove from clients-map
    124         PlayerInfo* player = this->clients_[clientID];
    125         this->clients_.erase(clientID);
    126 
    127         if (this->getActiveLevel())
    128             this->getActiveLevel()->playerLeft(player);
    129 
    130         // delete PlayerInfo instance
    131         if (player)
    132             delete player;
    133     }
    134 
    135 
    136     PlayerInfo* LevelManager::getClient(unsigned int clientID) const
    137     {
    138         std::map<unsigned int, PlayerInfo*>::const_iterator it = this->clients_.find(clientID);
    139         if (it != this->clients_.end())
    140             return it->second;
    141         else
    142             return 0;
    143     }
    14495}
  • code/branches/objecthierarchy/src/orxonox/LevelManager.h

    r2112 r2168  
    3636#include <cassert>
    3737
    38 #include "network/ClientConnectionListener.h"
    39 
    4038namespace orxonox
    4139{
    42     class _OrxonoxExport LevelManager : public ClientConnectionListener
     40    class _OrxonoxExport LevelManager
    4341    {
    4442        public:
     
    5048            Level* getActiveLevel();
    5149
    52             PlayerInfo* getClient(unsigned int clientID) const;
    53             inline const std::map<unsigned int, PlayerInfo*>& getClients() const
    54                 { return this->clients_; }
    55 
     50            static LevelManager* getInstancePtr() { return singletonRef_s; }
    5651            static LevelManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    5752
     
    5954            LevelManager(const LevelManager&);
    6055
    61             void clientConnected(unsigned int clientID);
    62             void clientDisconnected(unsigned int clientID);
    63 
    6456            void activateNextLevel();
    6557
    6658            std::list<Level*> levels_s;
    67             std::map<unsigned int, PlayerInfo*> clients_;
    68 
    6959            static LevelManager* singletonRef_s;
    7060    };
  • code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h

    r2074 r2168  
    8282    class CameraManager;
    8383    class LevelManager;
     84    class PlayerManager;
    8485
    8586    // objects
  • code/branches/objecthierarchy/src/orxonox/objects/infos/Level.cc

    r2112 r2168  
    4040#include "PlayerInfo.h"
    4141#include "objects/gametypes/Gametype.h"
     42#include "overlays/OverlayGroup.h"
    4243
    4344#include "util/Math.h"
     
    6263        if (this->isInitialized())
    6364        {
    64             LevelManager::getInstance().releaseActivity(this);
     65            if (LevelManager::getInstancePtr())
     66                LevelManager::getInstance().releaseActivity(this);
    6567
    6668            if (this->xmlfile_)
     
    9395        mask.exclude(Class(BaseObject));
    9496        mask.include(Class(Template));
     97        mask.include(Class(OverlayGroup)); // HACK to include the ChatOverlay
    9598
    9699        this->xmlfile_ = new XMLFile(Settings::getDataPath() + this->xmlfilename_, mask);
     
    112115                (*it)->setGametype(rootgametype);
    113116
    114             LevelManager::getInstance().requestActivity(this);
     117            if (LevelManager::getInstancePtr())
     118                LevelManager::getInstance().requestActivity(this);
    115119        }
    116120    }
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.cc

    r2112 r2168  
    3838#include "network/ClientInformation.h"
    3939
    40 #include "LevelManager.h"
     40#include "PlayerManager.h"
    4141#include "objects/infos/PlayerInfo.h"
    4242#include "overlays/console/InGameConsole.h"
     
    7676            std::string name = "unknown";
    7777
    78             PlayerInfo* player = LevelManager::getInstance().getClient(senderID);
     78            PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
    7979            if (player)
    8080                name = player->getName();
Note: See TracChangeset for help on using the changeset viewer.