Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2160


Ignore:
Timestamp:
Nov 8, 2008, 10:05:06 PM (16 years ago)
Author:
landauf
Message:

respawn of late joined clients works now

Location:
code/branches/objecthierarchy/src/orxonox/objects
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r2112 r2160  
    6767        if (!this->bStarted_)
    6868            this->checkStart();
     69        else
     70            this->spawnDeadPlayersIfRequested();
    6971
    7072        this->assignDefaultPawnsIfNeeded();
    71         this->spawnDeadPlayersIfRequested();
    7273    }
    7374
     
    8889    void Gametype::playerEntered(PlayerInfo* player)
    8990    {
    90         this->players_.insert(player);
     91        this->players_[player] = PlayerState::Joined;
    9192
    9293        std::string message = player->getName() + " entered the game";
     
    9798    void Gametype::playerLeft(PlayerInfo* player)
    9899    {
    99         std::set<PlayerInfo*>::iterator it = this->players_.find(player);
     100        std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(player);
    100101        if (it != this->players_.end())
    101102        {
     
    165166    }
    166167
    167     void Gametype::assignDefaultPawnsIfNeeded() const
    168     {
    169         for (std::set<PlayerInfo*>::const_iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    170         {
    171             if (!(*it)->getControllableEntity() && (!(*it)->isReadyToSpawn() || !this->bStarted_))
    172             {
    173                 SpawnPoint* spawn = this->getBestSpawnPoint(*it);
     168    void Gametype::assignDefaultPawnsIfNeeded()
     169    {
     170        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     171        {
     172            if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_))
     173            {
     174                SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
    174175                if (spawn)
    175176                {
     
    177178                    ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
    178179                    spawn->spawn(entity);
    179                     (*it)->startControl(entity);
     180                    it->first->startControl(entity);
     181                    it->second = PlayerState::Dead;
    180182                }
    181183                else
     
    210212                {
    211213                    bool allplayersready = true;
    212                     for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     214                    for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    213215                    {
    214                         if (!(*it)->isReadyToSpawn())
     216                        if (!it->first->isReadyToSpawn())
    215217                            allplayersready = false;
    216218                    }
     
    227229    void Gametype::spawnPlayersIfRequested()
    228230    {
    229         for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    230             if ((*it)->isReadyToSpawn() || this->bForceSpawn_)
    231                 this->spawnPlayer(*it);
     231        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     232            if (it->first->isReadyToSpawn() || this->bForceSpawn_)
     233                this->spawnPlayer(it->first);
    232234    }
    233235
    234236    void Gametype::spawnDeadPlayersIfRequested()
    235237    {
    236         for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    237             if (!(*it)->getControllableEntity())
    238                 if ((*it)->isReadyToSpawn() || this->bForceSpawn_)
    239                     this->spawnPlayer(*it);
     238        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     239            if (it->second == PlayerState::Dead)
     240                if (it->first->isReadyToSpawn() || this->bForceSpawn_)
     241                    this->spawnPlayer(it->first);
    240242    }
    241243
     
    246248        {
    247249            player->startControl(spawnpoint->spawn());
     250            this->players_[player] = PlayerState::Alive;
    248251        }
    249252        else
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h

    r2072 r2160  
    4141namespace orxonox
    4242{
     43    namespace PlayerState
     44    {
     45        enum Enum
     46        {
     47            Uninitialized,
     48            Joined,
     49            Alive,
     50            Dead
     51        };
     52    }
     53
    4354    class _OrxonoxExport Gametype : public BaseObject, public Tickable
    4455    {
     
    7081            virtual void pawnPostSpawn(Pawn* pawn);
    7182
    72             inline const std::set<PlayerInfo*>& getPlayers() const
     83            inline const std::map<PlayerInfo*, PlayerState::Enum>& getPlayers() const
    7384                { return this->players_; }
    7485
     
    8798            void removePlayer(PlayerInfo* player);
    8899
    89             void assignDefaultPawnsIfNeeded() const;
     100            void assignDefaultPawnsIfNeeded();
    90101            void checkStart();
    91102            void spawnPlayer(PlayerInfo* player);
     
    102113            bool bStartCountdownRunning_;
    103114
    104             std::set<PlayerInfo*> players_;
     115            std::map<PlayerInfo*, PlayerState::Enum> players_;
    105116            std::set<SpawnPoint*> spawnpoints_;
    106117            SubclassIdentifier<ControllableEntity> defaultControllableEntity_;
  • code/branches/objecthierarchy/src/orxonox/objects/infos/HumanPlayer.cc

    r2112 r2160  
    4646        RegisterObject(HumanPlayer);
    4747
    48         this->server_ready_ = Core::isMaster();
    49         this->client_ready_ = false;
     48        this->server_initialized_ = Core::isMaster();
     49        this->client_initialized_ = false;
    5050
    5151        this->bHumanPlayer_ = true;
     
    7070
    7171        REGISTERDATA(this->clientID_,     direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
    72         REGISTERDATA(this->server_ready_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_ready));
    73         REGISTERDATA(this->client_ready_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_ready));
     72        REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));
     73        REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));
    7474    }
    7575
     
    9696            this->bLocalPlayer_ = true;
    9797            this->synchronize_nick_ = this->nick_;
    98             this->client_ready_ = true;
     98            this->client_initialized_ = true;
    9999
    100100            if (!Core::isMaster())
     
    107107    }
    108108
    109     void HumanPlayer::networkcallback_server_ready()
     109    void HumanPlayer::networkcallback_server_initialized()
    110110    {
    111         this->client_ready_ = true;
     111        this->client_initialized_ = true;
    112112    }
    113113
    114     void HumanPlayer::networkcallback_client_ready()
     114    void HumanPlayer::networkcallback_client_initialized()
    115115    {
    116116        if (this->getGametype())
     
    118118    }
    119119
    120     bool HumanPlayer::isReady() const
     120    bool HumanPlayer::isInitialized() const
    121121    {
    122         return (this->server_ready_ && this->client_ready_);
     122        return (this->server_initialized_ && this->client_initialized_);
    123123    }
    124124
  • code/branches/objecthierarchy/src/orxonox/objects/infos/HumanPlayer.h

    r2072 r2160  
    4747            void setConfigValues();
    4848
    49             bool isReady() const;
     49            bool isInitialized() const;
    5050            float getPing() const;
    5151            float getPacketLossRatio() const;
     
    5757            void networkcallback_changednick();
    5858            void networkcallback_clientIDchanged();
    59             void networkcallback_server_ready();
    60             void networkcallback_client_ready();
     59            void networkcallback_server_initialized();
     60            void networkcallback_client_initialized();
    6161
    6262            std::string nick_;
    6363            std::string synchronize_nick_;
    64             bool server_ready_;
    65             bool client_ready_;
     64            bool server_initialized_;
     65            bool client_initialized_;
    6666    };
    6767}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r2112 r2160  
    5555    PlayerInfo::~PlayerInfo()
    5656    {
    57         if (this->isInitialized())
     57        if (this->BaseObject::isInitialized())
    5858        {
    5959            this->stopControl(this->controllableEntity_);
     
    7676    void PlayerInfo::changedName()
    7777    {
    78         if (this->isReady() && this->getGametype())
     78        if (this->isInitialized() && this->getGametype())
    7979            this->getGametype()->playerChangedName(this);
    8080    }
     
    8282    void PlayerInfo::changedGametype()
    8383    {
    84         if (this->isReady())
     84        if (this->isInitialized())
    8585        {
    8686            if (this->getOldGametype())
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r2072 r2160  
    5555            inline unsigned int getClientID() const
    5656                { return this->clientID_; }
    57             inline bool isReadyToSpawn() const
    58                 { return this->bReadyToSpawn_; }
    5957
    60             virtual bool isReady() const = 0;
     58            virtual bool isInitialized() const = 0;
    6159            virtual float getPing() const = 0;
    6260            virtual float getPacketLossRatio() const = 0;
     
    6462            inline void setReadyToSpawn(bool bReady)
    6563                { this->bReadyToSpawn_ = bReady; }
     64            inline bool isReadyToSpawn() const
     65                { return this->bReadyToSpawn_; }
    6666
    6767            void startControl(ControllableEntity* entity);
Note: See TracChangeset for help on using the changeset viewer.