Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1946


Ignore:
Timestamp:
Oct 19, 2008, 3:23:52 AM (16 years ago)
Author:
landauf
Message:

synchronizes the players name

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

Legend:

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

    r1887 r1946  
    5252#include "util/MultiType.h"
    5353#include "ConfigFileManager.h"
     54#include "Identifier.h"
    5455
    5556namespace orxonox
     
    6970            inline virtual ~ConfigValueCallback() {}
    7071            inline virtual void call(void* object)
    71                 { (((T*)object)->*this->function_)(); }
     72                { if (!Identifier::isCreatingHierarchy()) { (((T*)object)->*this->function_)(); } }
    7273
    7374        private:
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1945 r1946  
    5858        this->registerVariables();
    5959
    60         COUT(0) << "created PlayerInfo" << std::endl;
     60        COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6161    }
    6262
     
    6666        if (gametype)
    6767            gametype->removePlayer(this);
     68        COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6869    }
    6970
     
    7576    void PlayerInfo::checkName()
    7677    {
    77 std::cout << "# PlayerInfo: checkName: " << this->bLocalPlayer_ << std::endl;
    78         if (this->bLocalPlayer_)
     78std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
     79        if (this->bLocalPlayer_ && Settings::isMaster())
    7980            this->setName(this->playerName_);
     81    }
     82
     83    void PlayerInfo::changedName()
     84    {
     85std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
    8086    }
    8187
    8288    void PlayerInfo::registerVariables()
    8389    {
    84         this->setObjectMode(network::direction::bidirectional);
     90        REGISTERSTRING(name_,         network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));
     91        REGISTERSTRING(playerName_,   network::direction::toserver, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::clientChangedName));
     92        REGISTERDATA(clientID_,       network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::checkClientID));
     93        REGISTERDATA(ping_,           network::direction::toclient);
     94        REGISTERDATA(bHumanPlayer_,   network::direction::toclient);
     95        REGISTERDATA(bFinishedSetup_, network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::finishedSetup));
     96    }
    8597
    86         REGISTERSTRING(name_,               network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));
    87         REGISTERDATA(clientID_,             network::direction::toclient,      new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::checkClientID));
    88         REGISTERDATA(ping_,                 network::direction::toclient);
    89         REGISTERDATA(bHumanPlayer_,         network::direction::toclient);
    90         REGISTERDATA(bFinishedSetup_,       network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::finishedSetup));
     98    void PlayerInfo::clientChangedName()
     99    {
     100std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() to " << this->playerName_ << std::endl;
     101        this->setName(this->playerName_);
    91102    }
    92103
    93104    void PlayerInfo::checkClientID()
    94105    {
    95 std::cout << "# PlayerInfo: checkClientID" << std::endl;
     106std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
    96107        this->bHumanPlayer_ = true;
    97108
    98109        if (this->clientID_ == network::Host::getPlayerID())
    99110        {
    100 std::cout << "#             it's the client's ID" << std::endl;
     111std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
    101112            this->bLocalPlayer_ = true;
    102             this->setName(this->playerName_);
    103 std::cout << "#             " << this->getName() << std::endl;
     113//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl;
    104114
    105             if (!Settings::isClient())
     115            if (Settings::isClient())
    106116            {
    107 std::cout << "#             not client: finish setup" << std::endl;
     117std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
     118                this->setObjectMode(network::direction::bidirectional);
     119                this->playerName_ += "blub";
     120std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
     121            }
     122            else
     123            {
     124std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
     125                this->clientChangedName();
    108126                this->bFinishedSetup_ = true;
    109127                this->finishedSetup();
     
    114132    void PlayerInfo::finishedSetup()
    115133    {
    116 std::cout << "# PlayerInfo: finishedSetup: " << this->bFinishedSetup_ << std::endl;
     134std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
    117135        if (Settings::isClient())
    118136        {
    119 std::cout << "#             client: set to true" << std::endl;
     137std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
    120138            this->bFinishedSetup_ = true;
    121139        }
    122140        else if (this->bFinishedSetup_)
    123141        {
    124 std::cout << "#             not client but finished: add player" << std::endl;
     142std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
    125143            Gametype* gametype = Gametype::getCurrentGametype();
    126144            if (gametype)
     
    129147        else
    130148        {
    131 std::cout << "#             not client and not finished" << std::endl;
     149std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
    132150        }
    133151    }
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1940 r1946  
    4545            void registerVariables();
    4646
     47            virtual void changedName();
     48
    4749            inline void setClientID(unsigned int clientID)
    4850                { this->clientID_ = clientID; this->checkClientID(); }
     
    5961            void finishedSetup();
    6062            void checkName();
     63            void clientChangedName();
    6164
    6265            unsigned int clientID_;
Note: See TracChangeset for help on using the changeset viewer.