Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1940


Ignore:
Timestamp:
Oct 18, 2008, 10:58:46 PM (16 years ago)
Author:
landauf
Message:

did some first (and very unfinished) steps to deal with different players on server and client

Location:
code/branches/objecthierarchy/src
Files:
15 added
22 edited

Legend:

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

    r1841 r1940  
    9393            inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }
    9494
    95         private:
     95        protected:
    9696            std::string name_;                          //!< The name of the object
    97             bool bInitialized_;                         //!< True if the object was initialized (passed the object registration)
    9897            bool bActive_;                              //!< True = the object is active
    9998            bool bVisible_;                             //!< True = the object is visible
     99
     100        private:
     101            bool bInitialized_;                         //!< True if the object was initialized (passed the object registration)
    100102            const Level* level_;                        //!< The level that loaded this object
    101103            std::string loaderIndentation_;             //!< Indentation of the debug output in the Loader
  • code/branches/objecthierarchy/src/core/ClassFactory.h

    r1747 r1940  
    5555    {
    5656        public:
    57             static bool create(const std::string& name);
     57            static bool create(const std::string& name, bool bLoadable = true);
    5858            BaseObject* fabricate();
    5959
     
    6868    /**
    6969        @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
     70        @param name The name of the class
     71        @param bLoadable True if the class can be loaded through XML
    7072        @return Always true (this is needed because the compiler only allows assignments before main())
    7173    */
    7274    template <class T>
    73     bool ClassFactory<T>::create(const std::string& name)
     75    bool ClassFactory<T>::create(const std::string& name, bool bLoadable)
    7476    {
    7577        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    7678        ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
     79        ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
    7780        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    7881
  • code/branches/objecthierarchy/src/core/CoreIncludes.h

    r1856 r1940  
    9898*/
    9999#define CreateFactory(ClassName) \
    100     bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
     100    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true)
     101
     102/**
     103    @brief Creates the entry in the Factory for classes which should not be loaded through XML.
     104    @param ClassName The name of the class
     105*/
     106#define CreateUnloadableFactory(ClassName) \
     107    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false)
    101108
    102109/**
     
    111118    @param String The name of the class
    112119*/
    113 #define ClassByName(String) \
     120#define ClassByString(String) \
    114121    orxonox::Factory::getIdentifier(String)
    115122
  • code/branches/objecthierarchy/src/core/Factory.cc

    r1856 r1940  
    4646    Identifier* Factory::getIdentifier(const std::string& name)
    4747    {
    48         return getFactoryPointer()->identifierStringMap_[name];
     48        std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name);
     49        if (it != getFactoryPointer()->identifierStringMap_.end())
     50            return it->second;
     51        else
     52            return 0;
    4953    }
    5054
     
    5660    Identifier* Factory::getIdentifier(const unsigned int id)
    5761    {
    58         return getFactoryPointer()->identifierNetworkIDMap_[id];
     62        std::map<unsigned int, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id);
     63        if (it != getFactoryPointer()->identifierNetworkIDMap_.end())
     64            return it->second;
     65        else
     66            return 0;
    5967    }
    6068
     
    6876        getFactoryPointer()->identifierStringMap_[name] = identifier;
    6977        getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
     78std::cout << identifier->getName() << ": " << identifier->getNetworkID() << std::endl;
    7079    }
    7180
     
    8089        getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
    8190        getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier;
     91std::cout << identifier->getName() << ": " << oldID << " -> " << newID << std::endl;
    8292    }
    8393
  • code/branches/objecthierarchy/src/core/Identifier.cc

    r1856 r1940  
    5959        this->bSetName_ = false;
    6060        this->factory_ = 0;
     61        this->bLoadable_ = true;
    6162
    6263        this->bHasConfigValues_ = false;
  • code/branches/objecthierarchy/src/core/Identifier.h

    r1856 r1940  
    107107            bool isDirectParentOf(const Identifier* identifier) const;
    108108
     109            /** @brief Returns true if the class can be loaded through XML. */
     110            inline bool isLoadable() const { return this->bLoadable_; }
     111            /** @brief Set the class to be loadable through XML or not. */
     112            inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
     113
    109114            /** @brief Returns the list of all existing objects of this class. @return The list */
    110115            inline ObjectListBase* getObjects() const
     
    285290            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    286291            bool bSetName_;                                                //!< True if the name is set
     292            bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    287293            std::string name_;                                             //!< The name of the class the Identifier belongs to
    288294            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
  • code/branches/objecthierarchy/src/core/XMLPort.h

    r1889 r1940  
    468468                            for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
    469469                            {
    470                                 Identifier* identifier = ClassByName(child->Value());
     470                                Identifier* identifier = ClassByString(child->Value());
    471471                                if (identifier)
    472472                                {
    473473                                    if (identifier->isA(Class(O)))
    474474                                    {
    475                                         if (this->identifierIsIncludedInLoaderMask(identifier))
     475                                        if (identifier->isLoadable())
    476476                                        {
    477                                             COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
    478 
    479                                             BaseObject* newObject = identifier->fabricate();
    480                                             newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + "  ");
    481                                             newObject->setLevel(((BaseObject*)object)->getLevel());
    482                                             newObject->setNamespace(((BaseObject*)object)->getNamespace());
    483 
    484                                             if (this->bLoadBefore_)
     477                                            if (this->identifierIsIncludedInLoaderMask(identifier))
    485478                                            {
    486                                                 newObject->XMLPort(*child, XMLPort::LoadObject);
    487                                                 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
     479                                                COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
     480
     481                                                BaseObject* newObject = identifier->fabricate();
     482                                                newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + "  ");
     483                                                newObject->setLevel(((BaseObject*)object)->getLevel());
     484                                                newObject->setNamespace(((BaseObject*)object)->getNamespace());
     485
     486                                                if (this->bLoadBefore_)
     487                                                {
     488                                                    newObject->XMLPort(*child, XMLPort::LoadObject);
     489                                                    COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
     490                                                }
     491                                                else
     492                                                {
     493                                                    COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
     494                                                }
     495
     496                                                COUT(5) << ((BaseObject*)object)->getLoaderIndentation();
     497                                                (*this->loadexecutor_)(object, newObject);
     498
     499                                                if (!this->bLoadBefore_)
     500                                                    newObject->XMLPort(*child, XMLPort::LoadObject);
     501
     502                                                COUT(5) << ((BaseObject*)object)->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
    488503                                            }
    489                                             else
    490                                             {
    491                                                 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
    492                                             }
    493 
    494                                             COUT(5) << ((BaseObject*)object)->getLoaderIndentation();
    495                                             (*this->loadexecutor_)(object, newObject);
    496 
    497                                             if (!this->bLoadBefore_)
    498                                                 newObject->XMLPort(*child, XMLPort::LoadObject);
    499 
    500                                             COUT(5) << ((BaseObject*)object)->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
     504                                        }
     505                                        else
     506                                        {
     507                                            COUT(2) << ((BaseObject*)object)->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl;
    501508                                        }
    502509                                    }
  • code/branches/objecthierarchy/src/network/CMakeLists.txt

    r1938 r1940  
    2222
    2323IF(WIN32)
    24   ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES} )
     24  ADD_LIBRARY( network ${NETWORK_SRC_FILES} )
    2525ELSE(WIN32)
    2626  ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES} )
  • code/branches/objecthierarchy/src/network/ClientConnectionListener.h

    r1939 r1940  
    88namespace network{
    99
    10   class _NetworkExport ClientConnectionListener : public orxonox::OrxonoxClass
     10  class _NetworkExport ClientConnectionListener : virtual public orxonox::OrxonoxClass
    1111  {
     12    friend class Server;
     13
    1214  public:
    1315    ClientConnectionListener();
     16    virtual ~ClientConnectionListener() {}
    1417
    1518    void getConnectedClients();
    1619
     20  protected:
    1721    virtual void clientConnected(unsigned int clientID) = 0;
    1822    virtual void clientDisconnected(unsigned int clientID) = 0;
  • code/branches/objecthierarchy/src/network/GamestateClient.cc

    r1917 r1940  
    7777    packet::Gamestate *processed = processGamestate(tempGamestate_);
    7878//    assert(processed);
     79    if (!processed)
     80        return false;
    7981    //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
    8082    tempGamestate_=NULL;
  • code/branches/objecthierarchy/src/network/Synchronisable.cc

    r1907 r1940  
    5151namespace network
    5252{
    53  
     53
    5454
    5555  std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_;
     
    6868    objectMode_=0x1; // by default do not send data to server
    6969    objectID=idCounter++;
     70    classID = (unsigned int)-1;
    7071    syncList = new std::list<synchronisableVariable *>;
    7172  }
    7273
    7374  /**
    74    * Destructor: 
     75   * Destructor:
    7576   * Delete all callback objects and remove objectID from the objectMap_
    7677   */
     
    9697    this->classID = this->getIdentifier()->getNetworkID();
    9798//     COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
    98    
     99
    99100//     COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl;
    100101//     objectMap_[objectID]=this;
     
    145146  }
    146147
    147  
     148
    148149  /**
    149150   * Finds and deletes the Synchronisable with the appropriate objectID
     
    164165    return true;
    165166  }
    166  
     167
    167168  /**
    168169   * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
     
    185186  }
    186187
    187  
     188
    188189  /**
    189190  * This function is used to register a variable to be synchronized
     
    240241    if(classID==0)
    241242      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     243
     244    if (this->classID == (unsigned int)-1)
     245        this->classID = this->getIdentifier()->getNetworkID();
     246
    242247    assert(this->classID==this->getIdentifier()->getNetworkID());
    243248//     this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
     
    314319    assert(this->objectID==syncHeader->objectID);
    315320//    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
    316    
     321
    317322    COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
    318323    for(i=syncList->begin(); i!=syncList->end() && mem <= data+syncHeader->size; i++){
  • code/branches/objecthierarchy/src/network/Synchronisable.h

    r1916 r1940  
    4141#include "util/Integers.h"
    4242
    43 #define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA)
    44 #define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode)
    45 #define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING)
    46 #define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode)
     43#define REGISTERDATA(varname, ...) \
     44    registerVar((void*)&varname, sizeof(varname), network::DATA, __VA_ARGS__)
     45#define REGISTERSTRING(stringname, ...) \
     46    registerVar(&stringname, stringname.length()+1, network::STRING, __VA_ARGS__)
    4747
    4848namespace network
     
    112112    void setObjectMode(int mode);
    113113    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
    114     virtual void registerAllVariables()=0;
    115114
    116115
  • code/branches/objecthierarchy/src/network/packet/Packet.cc

    r1907 r1940  
    4949
    5050namespace packet{
    51  
     51
    5252#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
    5353#define _PACKETID           0
    54  
     54
    5555std::map<ENetPacket *, Packet *> Packet::packetMap_;
    56  
     56
    5757Packet::Packet(){
    5858  flags_ = PACKET_FLAG_DEFAULT;
     
    112112    packetMap_[enetPacket_] = this;
    113113  }
    114 #ifndef NDEBUG 
     114#ifndef NDEBUG
    115115  switch( *(ENUM::Type *)(data_ + _PACKETID) )
    116116  {
  • code/branches/objecthierarchy/src/orxonox/CMakeLists.txt

    r1916 r1940  
    4242  tools/WindowEventListener.cc
    4343
     44  objects/worldentities/WorldEntity.cc
     45  objects/worldentities/PositionableEntity.cc
    4446#  objects/Backlight.cc
    4547  objects/Camera.cc
     
    5052  objects/RadarViewable.cc
    5153  objects/Tickable.cc
     54
     55  objects/infos/Info.cc
     56  objects/infos/LevelInfo.cc
     57  objects/infos/PlayerInfo.cc
     58
     59  objects/gametypes/Gametype.cc
    5260
    5361  tolua/tolua_bind.cc
  • code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h

    r1916 r1940  
    8181
    8282    // objects
     83    class WorldEntity;
     84    class PositionableEntity;
     85    class MovableEntity;
     86    class ControllableEntity;
     87
    8388    class Backlight;
    8489    class Camera;
    8590    class ParticleSpawner;
     91
     92    class Info;
     93    class LevelInfo;
     94    class PlayerInfo;
     95
     96    class Gametype;
    8697
    8798    // tools
  • code/branches/objecthierarchy/src/orxonox/Settings.cc

    r1907 r1940  
    5252        , bHasServer_(false)
    5353        , bIsClient_(false)
     54        , bIsStandalone_(false)
     55        , bIsMaster_(false)
    5456    {
    5557        RegisterRootObject(Settings);
  • code/branches/objecthierarchy/src/orxonox/Settings.h

    r1907 r1940  
    5454        friend class GSClient;
    5555        friend class GSDedicated;
     56        friend class GSStandalone;
    5657
    5758    public:
     
    6566        static bool hasServer()     { assert(singletonRef_s); return singletonRef_s->bHasServer_; }
    6667        static bool isClient()      { assert(singletonRef_s); return singletonRef_s->bIsClient_; }
     68        static bool isStandalone()  { assert(singletonRef_s); return singletonRef_s->bIsStandalone_; }
     69        static bool isMaster()      { assert(singletonRef_s); return singletonRef_s->bIsMaster_; }
    6770
    6871    private:
    6972        // GSRoot has access to these
    70         static void setShowsGraphics(bool val) { assert(singletonRef_s); singletonRef_s->bShowsGraphics_ = val; }
    71         static void setHasServer    (bool val) { assert(singletonRef_s); singletonRef_s->bHasServer_     = val; }
    72         static void setIsClient     (bool val) { assert(singletonRef_s); singletonRef_s->bIsClient_      = val; }
     73        static void setShowsGraphics(bool val) { assert(singletonRef_s); singletonRef_s->bShowsGraphics_ = val; singletonRef_s->updateIsMaster(); }
     74        static void setHasServer    (bool val) { assert(singletonRef_s); singletonRef_s->bHasServer_     = val; singletonRef_s->updateIsMaster(); }
     75        static void setIsClient     (bool val) { assert(singletonRef_s); singletonRef_s->bIsClient_      = val; singletonRef_s->updateIsMaster(); }
     76        static void setIsStandalone (bool val) { assert(singletonRef_s); singletonRef_s->bIsStandalone_  = val; singletonRef_s->updateIsMaster(); }
     77        static void updateIsMaster  ()         { assert(singletonRef_s); singletonRef_s->bIsMaster_ = (singletonRef_s->bHasServer_ || singletonRef_s->bIsStandalone_); }
    7378
    7479        Settings();
     
    8590        bool bHasServer_;                                      //!< global variable that tells whether this is a server
    8691        bool bIsClient_;
     92        bool bIsStandalone_;
     93        bool bIsMaster_;
    8794
    8895        std::string dataPath_;                                 //!< Path to the game data
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSClient.cc

    r1907 r1940  
    5151    void GSClient::enter()
    5252    {
    53         Settings::_getInstance().bIsClient_ = true;
     53        Settings::_getInstance().setIsClient(true);
    5454
    5555        GSLevel::enter();
     
    8181        GSLevel::leave();
    8282
    83         Settings::_getInstance().bIsClient_ = false;
     83        Settings::_getInstance().setIsClient(false);
    8484    }
    8585
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSDedicated.cc

    r1790 r1940  
    5757    void GSDedicated::enter()
    5858    {
    59         Settings::_getInstance().bHasServer_ = true;
     59        Settings::_getInstance().setHasServer(true);
    6060
    6161        // create Ogre SceneManager for the level
     
    9797        Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
    9898
    99         Settings::_getInstance().bHasServer_ = false;
     99        Settings::_getInstance().setHasServer(false);
    100100    }
    101101
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSGraphics.cc

    r1891 r1940  
    101101    void GSGraphics::enter()
    102102    {
    103         Settings::_getInstance().bShowsGraphics_ = true;
     103        Settings::_getInstance().setShowsGraphics(true);
    104104
    105105        // initialise graphics engine. Doesn't load the render window yet!
     
    196196        delete graphicsEngine_;
    197197
    198         Settings::_getInstance().bShowsGraphics_ = false;
     198        Settings::_getInstance().setShowsGraphics(false);
    199199    }
    200200
     
    221221        this->console_->tick(dt);
    222222        this->tickChild(time);
    223        
     223
    224224        unsigned long long timeAfterTick = time.getRealMicroseconds();
    225225
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSServer.cc

    r1910 r1940  
    5252    void GSServer::enter()
    5353    {
    54         Settings::_getInstance().bHasServer_ = true;
     54        Settings::_getInstance().setHasServer(true);
    5555
    5656        GSLevel::enter();
     
    8585
    8686        GSLevel::leave();
    87        
    88         Settings::_getInstance().bHasServer_ = false;
     87
     88        Settings::_getInstance().setHasServer(false);
    8989    }
    9090
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSStandalone.cc

    r1755 r1940  
    3232#include "core/input/InputManager.h"
    3333#include "core/ConsoleCommand.h"
     34#include "Settings.h"
    3435
    3536namespace orxonox
     
    5758        // level is loaded: we can start capturing the input
    5859        InputManager::getInstance().requestEnterState("game");
     60
     61        Settings::_getInstance().setIsStandalone(true);
    5962    }
    6063
     
    6871
    6972        GSLevel::leave();
     73
     74        Settings::_getInstance().setIsStandalone(false);
    7075    }
    7176
Note: See TracChangeset for help on using the changeset viewer.