Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1950


Ignore:
Timestamp:
Oct 19, 2008, 5:32:58 PM (11 years ago)
Author:
landauf
Message:

small update to do further network tests

Location:
code/branches/objecthierarchy/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/core/BaseObject.h

    r1940 r1950  
    5959
    6060            /** @brief Sets the name of the object. @param name The name */
    61             inline void setName(const std::string& name) { this->name_ = name; this->changedName(); }
    62             /** @brief Returns the name of the object. @return The name */
     61            inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); }
     62            /** @brief Returns the name of the object. */
    6363            inline const std::string& getName() const { return this->name_; }
     64            /** @brief Returns the old name of the object. */
     65            inline const std::string& getOldName() const { return this->oldName_; }
    6466            /** @brief This function gets called if the name of the object changes. */
    6567            virtual void changedName() {}
     
    9597        protected:
    9698            std::string name_;                          //!< The name of the object
     99            std::string oldName_;                       //!< The old name of the object
    97100            bool bActive_;                              //!< True = the object is active
    98101            bool bVisible_;                             //!< True = the object is visible
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r1947 r1950  
    3131
    3232#include "core/CoreIncludes.h"
     33#include "core/ConsoleCommand.h"
    3334#include "objects/infos/PlayerInfo.h"
    3435
    3536namespace orxonox
    3637{
     38    SetConsoleCommand(Gametype, listPlayers, true);
     39
    3740    CreateUnloadableFactory(Gametype);
    3841
     
    5457    }
    5558
     59    void Gametype::listPlayers()
     60    {
     61        Gametype* gametype = Gametype::getCurrentGametype();
     62
     63        if (gametype)
     64        {
     65            for (std::set<PlayerInfo*>::const_iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
     66                COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;
     67        }
     68        else
     69        {
     70            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
     71                COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;
     72        }
     73    }
     74
    5675    void Gametype::clientConnected(unsigned int clientID)
    5776    {
    5877        COUT(0) << "client connected" << std::endl;
    5978
     79        // create new PlayerInfo instance
    6080        PlayerInfo* player = new PlayerInfo();
    6181        player->setClientID(clientID);
     82
     83        // add to clients-map
     84        assert(!this->clients_[clientID]);
     85        this->clients_[clientID] = player;
    6286    }
    6387
     
    6589    {
    6690        COUT(0) << "client disconnected" << std::endl;
     91
     92        // remove from clients-map
     93        PlayerInfo* player = this->clients_[clientID];
     94        this->clients_.erase(clientID);
     95
     96        // delete PlayerInfo instance
     97        delete player;
    6798    }
    6899
     
    88119        COUT(0) << "player " << player->getName() << " left" << std::endl;
    89120    }
     121
     122    void Gametype::playerChangedName(PlayerInfo* player)
     123    {
     124        if (this->players_.find(player) != this->players_.end())
     125        {
     126            if (player->getName() != player->getOldName())
     127            {
     128                COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl;
     129            }
     130        }
     131    }
    90132}
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h

    r1940 r1950  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include <map>
     35
    3436#include "core/BaseObject.h"
    3537#include "network/ClientConnectionListener.h"
     
    3941    class _OrxonoxExport Gametype : public BaseObject, public network::ClientConnectionListener
    4042    {
     43        friend class PlayerInfo;
     44
    4145        public:
    4246            Gametype();
     
    4448
    4549            static Gametype* getCurrentGametype();
    46             void addPlayer(PlayerInfo* player);
    47             void removePlayer(PlayerInfo* player);
     50            static void listPlayers();
    4851
    4952        protected:
     
    5457            virtual void playerLeft(PlayerInfo* player);
    5558
     59            virtual void playerChangedName(PlayerInfo* player);
     60
    5661        private:
     62            void addPlayer(PlayerInfo* player);
     63            void removePlayer(PlayerInfo* player);
     64
    5765            std::set<PlayerInfo*> players_;
     66            std::map<unsigned int, PlayerInfo*> clients_;
    5867    };
    5968}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1949 r1950  
    5151
    5252        this->ping_ = -1;
     53        this->clientID_ = (unsigned int)-1;
    5354        this->bLocalPlayer_ = Core::isStandalone();
    5455        this->bLocalPlayer_ = false;
     
    8586    {
    8687std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
     88        Gametype* gametype = Gametype::getCurrentGametype();
     89        if (gametype)
     90            gametype->playerChangedName(this);
    8791    }
    8892
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h

    r1940 r1950  
    4444
    4545            inline void setPosition(const Vector3& position)
    46                 { this->node_->setPosition(position); std::cout << "set position to " << position << std::endl; }
     46                { this->node_->setPosition(position); }
    4747            inline void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    4848                { this->node_->translate(distance, relativeTo); }
Note: See TracChangeset for help on using the changeset viewer.