Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 496 for code/branches


Ignore:
Timestamp:
Dec 12, 2007, 10:37:30 PM (17 years ago)
Author:
landauf
Message:

added files from objecthierarchy, changed includes

Location:
code/branches/FICN/src
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/loader/LevelLoader.cc

    r480 r496  
    44#include "LevelLoader.h"
    55#include "tinyxml/tinyxml.h"
    6 #include "orxonox/core/IdentifierIncludes.h"
     6#include "orxonox/core/CoreIncludes.h"
    77#include "orxonox/core/Error.h"
    88#include "orxonox/objects/BaseObject.h"
     
    111111                                {
    112112                                        tElem = tNode->ToElement();
    113                                         orxonox::BaseObject* obj = orxonox::ID(tElem->Value())->fabricate();
     113                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
    114114                                        obj->loadParams(tElem);
    115115                                }                       
  • code/branches/FICN/src/network/Client.cc

    r459 r496  
    170170  void Client::processClassid(classid *clid){
    171171    orxonox::Identifier *id;
    172     id=orxonox::ID(std::string(clid->message));
     172    id=ID(std::string(clid->message));
    173173    if(id!=NULL)
    174174      id->setNetworkID(clid->clid);
  • code/branches/FICN/src/network/Client.h

    r459 r496  
    1919#include "PacketManager.h"
    2020#include "GameStateClient.h"
    21 #include "orxonox/core/IdentifierIncludes.h"
     21#include "orxonox/core/CoreIncludes.h"
    2222//#include "NetworkFrameListener.h"
    2323
  • code/branches/FICN/src/network/ConnectionManager.cc

    r446 r496  
    224224    orxonox::Identifier *id;
    225225    while(!abort){
    226       id = orxonox::ID(i);
     226      id = ID(i);
    227227      if(id == NULL)
    228228        abort=true;
  • code/branches/FICN/src/network/ConnectionManager.h

    r475 r496  
    2424#include "PacketBuffer.h"
    2525#include "PacketManager.h"
    26 #include "orxonox/core/IdentifierIncludes.h"
     26#include "orxonox/core/CoreIncludes.h"
    2727
    2828namespace std{
  • code/branches/FICN/src/network/GameStateClient.h

    r436 r496  
    1515#include "zlib.h"
    1616#include "Synchronisable.h"
    17 #include "orxonox/core/IdentifierIncludes.h"
     17#include "orxonox/core/CoreIncludes.h"
    1818#include "GameStateManager.h"
    1919
  • code/branches/FICN/src/network/GameStateManager.h

    r436 r496  
    1919#include "ClientInformation.h"
    2020#include "Synchronisable.h"
    21 #include "orxonox/core/IdentifierIncludes.h"
     21#include "orxonox/core/CoreIncludes.h"
    2222#include "orxonox/core/Iterator.h"
    2323#include "PacketTypes.h"
  • code/branches/FICN/src/network/Synchronisable.h

    r459 r496  
    1616#include <iostream>
    1717
    18 #include "orxonox/core/IdentifierIncludes.h"
     18#include "orxonox/core/CoreIncludes.h"
    1919#include "orxonox/core/OrxonoxClass.h"
    2020
  • code/branches/FICN/src/orxonox/core/CMakeLists.txt

    r420 r496  
    77  MetaObjectList.cc
    88  OrxonoxClass.cc
     9  ConfigValueContainer.cc
    910  Error.cc
     11  SignalHandler.cc
    1012)
    1113
  • code/branches/FICN/src/orxonox/core/ClassFactory.h

    r384 r496  
    11/*!
    22    @file ClassFactory.h
    3     @brief Definition of the ClassFactory class
     3    @brief Definition and implementation of the ClassFactory class
    44
    55    The ClassFactory is able to create new objects of a specific class.
     
    2121    {
    2222        public:
    23             static bool create();
     23            static bool create(const std::string& name);
    2424            BaseObject* fabricate();
    2525
     
    3333
    3434    /**
    35         @brief Adds the ClassFactory to the Identifier of the same type and creates a new object to retrieve the parents.
    36         @return True, because the compiler only allows assignments before main()
     35        @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
     36        @return Always true (this is needed because the compiler only allows assignments before main())
    3737    */
    3838    template <class T>
    39     bool ClassFactory<T>::create()
     39    bool ClassFactory<T>::create(const std::string& name)
    4040    {
    41         // Add the ClassFactory to the Classidentifier of type T
    4241        ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
    43 
    44         // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
    45         ClassIdentifier<T>::getIdentifier()->startCreatingHierarchy();
    46 #if HIERARCHY_VERBOSE
    47         std::cout << "*** Create Factory -> Create Class\n";
    48 #endif
    49         BaseObject* temp = ClassIdentifier<T>::getIdentifier()->fabricate();
    50         delete temp;
    51         ClassIdentifier<T>::getIdentifier()->stopCreatingHierarchy();
     42        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    5243
    5344        return true;
  • code/branches/FICN/src/orxonox/core/Factory.cc

    r384 r496  
    66#include "Factory.h"
    77#include "Identifier.h"
     8#include "Debug.h"
     9#include "../objects/BaseObject.h"
    810
    911namespace orxonox
     
    2426
    2527    /**
    26         @returns the Identifier with a given networkID.
    27         @param id The networkID of the wanted Identifier
     28        @returns the Identifier with a given network ID.
     29        @param id The network ID of the wanted Identifier
    2830    */
    2931    Identifier* Factory::getIdentifier(const unsigned int id)
     
    5052
    5153    /**
    52         @brief Removes the entry with the old networkID and adds a new one.
     54        @brief Removes the entry with the old network ID and adds a new one.
    5355        @param identifier The identifier to change
    5456        @param oldID The old networkID
     
    6062        pointer_s->identifierNetworkIDMap_[newID] = identifier;
    6163    }
     64
     65    /**
     66        @brief Creates the class-hierarchy by creating and destroying one object of each type.
     67    */
     68    void Factory::createClassHierarchy()
     69    {
     70        if (!pointer_s)
     71            pointer_s = new Factory;
     72
     73        COUT(4) << "*** Factory -> Create class-hierarchy\n";
     74        std::map<std::string, Identifier*>::iterator it;
     75        it = pointer_s->identifierStringMap_.begin();
     76        (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
     77        for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it)
     78        {
     79            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     80            BaseObject* temp = (*it).second->fabricate();
     81            delete temp;
     82        }
     83        (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     84        COUT(4) << "*** Factory -> Finished class-hierarchy creation\n";
     85    }
    6286}
  • code/branches/FICN/src/orxonox/core/Factory.h

    r384 r496  
    33    @brief Definition of the Factory and the BaseFactory class.
    44
    5     The Factory is a singleton, containing two maps to map either the name or the networkID
     5    The Factory is a singleton, containing two maps to map either the name or the network ID
    66    of a class with the corresponding Identifier.
    77
     
    2828    // ###         Factory         ###
    2929    // ###############################
    30     //! The Factory is used to map name or networkID of a class with its Identifier.
     30    //! The Factory is used to map the name or the network ID of a class with its Identifier.
    3131    class Factory
    3232    {
     
    3636            static void add(const std::string& name, Identifier* identifier);
    3737            static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID);
     38            static void createClassHierarchy();
    3839
    3940        private:
     
    4344
    4445            static Factory* pointer_s;                                          //!< The pointer to the singleton
    45             std::map<std::string, Identifier*> identifierStringMap_;            //!< The map mapping string with Identifier
    46             std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map mapping networkID with Identifier
     46            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
     47            std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
    4748    };
    4849
  • code/branches/FICN/src/orxonox/core/Identifier.cc

    r384 r496  
    1212    // ###############################
    1313    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero
    14     unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero
     14    unsigned int Identifier::classIDcounter_s = 0;  // Set the static member variable classIDcounter_s to zero
    1515
    1616    /**
     
    4141    void Identifier::initialize(const IdentifierList* parents)
    4242    {
    43 #if HIERARCHY_VERBOSE
    44         std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";
    45 #endif
     43        COUT(4) << "*** Initialize " << this->name_ << "-Singleton.\n";
    4644        this->bCreatedOneObject_ = true;
    4745
     
    7270        {
    7371            // Abstract classes don't have a factory and therefore can't create new objects
    74             std::cout << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
    75             std::cout << "Aborting...";
     72            COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n";
     73            COUT(1) << "Aborting...";
    7674            abort();
    7775        }
     
    7977
    8078    /**
    81         @brief Sets the networkID to a new value and changes the entry in the Factory.
    82         @param id The new networkID
     79        @brief Sets the network ID to a new value and changes the entry in the Factory.
     80        @param id The new network ID
    8381    */
    8482    void Identifier::setNetworkID(unsigned int id)
  • code/branches/FICN/src/orxonox/core/Identifier.h

    r384 r496  
    11/*!
    22    @file Identifier.h
    3     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes.
     3    @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
    44
    55    The Identifier contains all needed informations about the class it belongs to:
     
    77     - a list with all objects
    88     - parents and childs
    9      - the factory, if available
     9     - the factory (if available)
    1010     - the networkID that can be synchronised with the server
     11     - all configurable variables (if available)
    1112
    1213    Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    1819
    1920    SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
    20     You can only assign Identifiers of the given class or a derivative to a SubclassIdentifier.
     21    You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
    2122*/
    2223
     
    2526
    2627#include <iostream>
     28#include <map>
    2729
    2830#include "IdentifierList.h"
    2931#include "ObjectList.h"
    3032#include "Factory.h"
    31 
    32 #define HIERARCHY_VERBOSE false
    33 
     33#include "ConfigValueContainer.h"
     34#include "Debug.h"
    3435
    3536namespace orxonox
     
    4647         - a list with all objects
    4748         - parents and childs
    48          - the factory, if available
     49         - the factory (if available)
    4950         - the networkID that can be synchronised with the server
     51         - all configurable variables (if available)
    5052
    5153        Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    6264        friend class SubclassIdentifier; // Forward declaration
    6365
    64         template <class T>
    65         friend class ClassFactory; // Forward declaration
     66        friend class Factory; // Forward declaration
    6667
    6768        public:
     
    8586            inline IdentifierList& getChildren() const { return *this->children_; }
    8687
    87             /** @returns true, if a branch of the class-hierarchy is getting created, causing all new objects to store their parents. */
     88            /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */
    8889            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    8990
    90             /** @returns the NetworkID to identify a class through the network. */
     91            /** @returns the network ID to identify a class through the network. */
    9192            inline const unsigned int getNetworkID() const { return this->classID_; }
    9293
     94            /** @brief Sets the network ID to a new value. @param id The new value */
    9395            void setNetworkID(unsigned int id);
     96
     97            /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */
     98            inline ConfigValueContainer* getConfigValueContainer(const std::string& varname)
     99                { return this->configValues_[varname]; }
     100
     101            /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */
     102            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
     103                { this->configValues_[varname] = container; }
    94104
    95105        private:
     
    105115            {
    106116                hierarchyCreatingCounter_s++;
    107 #if HIERARCHY_VERBOSE
    108                 std::cout << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    109 #endif
     117                COUT(4) << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    110118            }
    111119
     
    116124            {
    117125                hierarchyCreatingCounter_s--;
    118 #if HIERARCHY_VERBOSE
    119                 std::cout << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    120 #endif
    121             }
    122 
    123             IdentifierList parents_;                    //!< The Parents of the class the Identifier belongs to
    124             IdentifierList* children_;                  //!< The Children of the class the Identifier belongs to
    125 
    126             std::string name_;                          //!< The name of the class the Identifier belongs to
    127 
    128             BaseFactory* factory_;                      //!< The Factory, able to create new objects of the given class
    129             bool bCreatedOneObject_;                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    130             static int hierarchyCreatingCounter_s;      //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
    131             static unsigned int classIDcounter_s;       //!< The number of unique Identifiers
    132             unsigned int classID_;                      //!< The networkID to identify a class through the network
     126                COUT(4) << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
     127            }
     128
     129            IdentifierList parents_;                                    //!< The Parents of the class the Identifier belongs to
     130            IdentifierList* children_;                                  //!< The Children of the class the Identifier belongs to
     131
     132            std::string name_;                                          //!< The name of the class the Identifier belongs to
     133
     134            BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class (if available)
     135            bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     136            static int hierarchyCreatingCounter_s;                      //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
     137            static unsigned int classIDcounter_s;                       //!< The number of existing Identifiers
     138            unsigned int classID_;                                      //!< The network ID to identify a class through the network
     139            std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
    133140    };
    134141
     
    164171
    165172    /**
    166         @brief Constructor: Create the ObjectList.
     173        @brief Constructor: Creates the ObjectList.
    167174    */
    168175    template <class T>
     
    173180
    174181    /**
    175         @brief Destructor: Delete the ObjectList, set the singleton-pointer to zero.
     182        @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero.
    176183    */
    177184    template <class T>
     
    186193        @param parents An IdentifierList, containing the Identifiers of all parents of the class
    187194        @param name A string, containing exactly the name of the class
    188         @param bRootClass True if the class is either an Interface or BaseObject itself
     195        @param bRootClass True if the class is either an Interface or the BaseObject itself
    189196        @return The ClassIdentifier itself
    190197    */
     
    192199    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass)
    193200    {
    194 #if HIERARCHY_VERBOSE
    195         std::cout << "*** Register Class in " << name << "-Singleton.\n";
    196 #endif
     201        COUT(4) << "*** Register Class in " << name << "-Singleton.\n";
    197202
    198203        // It's a singleton, so maybe we have to create it first
    199204        if (!pointer_s)
    200205        {
    201 #if HIERARCHY_VERBOSE
    202             std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";
    203 #endif
     206            COUT(4) << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";
    204207            pointer_s = new ClassIdentifier();
    205208        }
     
    210213            // If no: We have to store the informations and initialize the Identifier
    211214
    212 #if HIERARCHY_VERBOSE
    213             std::cout << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n";
    214 #endif
     215            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n";
    215216            pointer_s->name_ = name;
    216             Factory::add(name, pointer_s); // Add the Identifier to the Factory
     217//            Factory::add(name, pointer_s); // Add the Identifier to the Factory
    217218
    218219            if (bRootClass)
     
    226227
    227228    /**
    228         @returns the Identifier itself
     229        @returns the Identifier itself.
    229230    */
    230231    template <class T>
     
    233234        if (!pointer_s)
    234235        {
    235 #if HIERARCHY_VERBOSE
    236             std::cout << "*** Create Singleton.\n";
    237 #endif
     236            COUT(4) << "*** Create Singleton.\n";
    238237            pointer_s = new ClassIdentifier();
    239238        }
     
    249248    void ClassIdentifier<T>::addObject(T* object)
    250249    {
    251 #if HIERARCHY_VERBOSE
    252         std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    253 #endif
     250        COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    254251        object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));
    255252    }
     
    261258    //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
    262259    /**
    263         You can only assign Identifiers that belong to a class of at least B (or derived) to a SubclassIdentifier<T>.
     260        You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
    264261        If you assign something else, the program aborts.
    265262        Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object.
     
    286283                if (!identifier->isA(ClassIdentifier<T>::getIdentifier()))
    287284                {
    288                     std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
    289                     std::cout << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";
    290                     std::cout << "Aborting...\n";
     285                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
     286                    COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";
     287                    COUT(1) << "Aborting...\n";
    291288                    abort();
    292289                }
     
    314311
    315312            /**
    316                 @brief Creates a new object of the type of the assigned identifier and dynamic_casts it to the minimal type given by the SubclassIdentifier.
     313                @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    317314                @return The new object
    318315            */
     
    321318                BaseObject* newObject = this->identifier_->fabricate();
    322319
    323                 // Check if the creation worked
     320                // Check if the creation was successful
    324321                if (newObject)
    325322                {
     
    332329                    if (this->identifier_)
    333330                    {
    334                         std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
    335                         std::cout << "Error: Couldn't fabricate a new Object.\n";
    336                         std::cout << "Aborting...\n";
     331                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
     332                        COUT(1) << "Error: Couldn't fabricate a new Object.\n";
     333                        COUT(1) << "Aborting...\n";
    337334                    }
    338335                    else
    339336                    {
    340                         std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";
    341                         std::cout << "Aborting...\n";
     337                        COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";
     338                        COUT(1) << "Aborting...\n";
    342339                    }
    343340
  • code/branches/FICN/src/orxonox/core/IdentifierList.cc

    r384 r496  
    101101
    102102    /**
    103         @returns a string, containing the names of all Identifiers in the list.
     103        @returns a string, containing a list of the names of all Identifiers in the list.
    104104    */
    105105    std::string IdentifierList::toString() const
  • code/branches/FICN/src/orxonox/core/Iterator.h

    r384 r496  
    11/*!
    22    @file Iterator.h
    3     @brief Definition of the Iterator class.
     3    @brief Definition and implementation of the Iterator class.
    44
    55    The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type.
    6     This is the only way to access the objects in an ObjectList.
     6    This is the only way to access the objects stored in an ObjectList.
    77
    88    Usage:
     
    1313    }
    1414
    15     Warning: Don't delete an object directly through the iterator.
     15    Warning: Don't delete objects directly through the iterator.
    1616*/
    1717
    1818#ifndef _Iterator_H__
    1919#define _Iterator_H__
     20
     21#include "Debug.h"
    2022
    2123namespace orxonox
     
    2729        public:
    2830            /**
    29                 @brief Constructor: Sets the element whereon the iterator points to zero.
     31                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    3032            */
    3133            Iterator()
     
    3537
    3638            /**
    37                 @brief Constructor: Sets the element whereon the iterator points to a given element.
     39                @brief Constructor: Sets the element, whereon the iterator points, to a given element.
    3840                @param element The element to start with
    3941            */
     
    4446
    4547            /**
    46                 @brief Overloading of the ++it operator: Iterator iterates to the next object in the list.
     48                @brief Overloading of the ++it operator: Iterator points to the next object in the list.
    4749                @return The Iterator itself
    4850            */
     
    5456
    5557            /**
    56                 @brief Overloading of the --it operator: Iterator iterates to the previous object in the list.
     58                @brief Overloading of the --it operator: Iterator points to the previous object in the list.
    5759                @return The Iterator itself
    5860            */
     
    98100            bool operator!=(int compare)
    99101            {
    100                 // Comparing with something except zero makes no sense
     102                // Comparing with anything except zero makes no sense
    101103                if (compare != 0)
    102                     std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";
     104                    COUT(2) << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";
    103105
    104106                return (this->element_ != 0);
     
    106108
    107109        private:
    108             ObjectListElement<T>* element_;     //!< The element the Iterator points to
     110            ObjectListElement<T>* element_;     //!< The element the Iterator points at
    109111    };
    110112}
  • code/branches/FICN/src/orxonox/core/MetaObjectList.h

    r384 r496  
    44
    55    The MetaObjectList is a single-linked list, containing all list-elements and their
    6     lists wherein the object that owns the MetaObjectList is registered.
    7     This allows much faster deleting of objects.
     6    lists wherein the object, owning the MetaObjectList, is registered.
     7    This allows much faster deletion of objects because no iteration is needed.
    88*/
    99
     
    1313#include "ObjectList.h"
    1414#include "Identifier.h"
     15#include "Debug.h"
    1516
    1617namespace orxonox
     
    2021    {
    2122        public:
    22             /** @brief Defaultdestructor */
     23            /** @brief Default destructor */
    2324            virtual ~BaseMetaObjectListElement() {};
    2425
     
    6970
    7071
    71 #if HIERARCHY_VERBOSE
    72         std::cout << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    73 #endif
     72        COUT(4) << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    7473        delete this->element_;
    7574    }
     
    8382        The MetaObjectList is a single-linked list, containing all list-elements and their
    8483        lists wherein the object that owns the MetaObjectList is registered.
    85         This allows much faster deleting of objects.
     84        This allows much faster deletion of objects because no iteration is needed.
    8685    */
    8786    class MetaObjectList
  • code/branches/FICN/src/orxonox/core/ObjectList.h

    r384 r496  
    11/*!
    22    @file ObjectList.h
    3     @brief Definition of the ObjectList class.
    4 
    5     The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it.
    6     Created objects are added through the RegisterObject-macro in its constructor.
     3    @brief Definition and implementation of the ObjectList class.
     4
     5    The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class.
     6    Newly created objects are added through the RegisterObject-macro in its constructor.
    77    Use Iterator<class> to iterate through all objects of the class.
    88*/
     
    3232    /**
    3333        @brief Constructor: Creates the list-element with an object.
    34         @param Object The object to store
     34        @param object The object to store
    3535    */
    3636    template <class T>
     
    4949    class Iterator; // Forward declaration
    5050
    51     //! The ObjectList contains all objects of a specific class.
    52     /**
    53         The ObjectList is used by Identifiers to store all objects of a specific class in it.
     51    //! The ObjectList contains all objects of a given class.
     52    /**
     53        The ObjectList is used by Identifiers to store all objects of a given class.
    5454        Use Iterator<class> to iterate through all objects in the list.
    5555    */
     
    8282
    8383    /**
    84         @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_
     84        @brief Constructor: Sets default values.
    8585    */
    8686    template <class T>
  • code/branches/FICN/src/orxonox/core/OrxonoxClass.h

    r480 r496  
    33    @brief Definition of the OrxonoxClass Class.
    44
    5     All objects and interfaces of the game-logic are derived from OrxonoxClass.
    6     It stores the Identifier and the MetaObjectList and has all needed functions to create the class-hierarchy.
     5    All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
     6    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
    77*/
    88
     
    1515#include "MetaObjectList.h"
    1616
    17 #include "../../tinyxml/tinyxml.h"
    18 
    19 
    2017namespace orxonox
    2118{
    22     //! The class all objects and interfaces of the game-logic are derived from.
     19    //! The class all objects and interfaces of the game-logic (not the engine) are derived from.
    2320    /**
    24         BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
     21        The BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
    2522        OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
    2623    */
     
    3027            OrxonoxClass();
    3128            virtual ~OrxonoxClass();
     29
     30            void setConfigValues() {};
    3231
    3332            /** @returns the Identifier of the object */
     
    4645            inline MetaObjectList& getMetaList() { return this->metaList_; }
    4746
     47
     48            /** @returns true if the objects class is of the given type or a derivative. */
    4849            inline bool isA(const Identifier* identifier)
    4950                { return this->getIdentifier()->isA(identifier); }
     51            /** @returns true if the objects class is exactly of the given type. */
    5052            inline bool isDirectlyA(const Identifier* identifier)
    5153                { return this->getIdentifier()->isDirectlyA(identifier); }
     54            /** @returns true if the objects class is a child of the given type. */
    5255            inline bool isChildOf(const Identifier* identifier)
    5356                { return this->getIdentifier()->isChildOf(identifier); }
     57            /** @returns true if the objects class is a parent of the given type. */
    5458            inline bool isParentOf(const Identifier* identifier)
    5559                { return this->getIdentifier()->isParentOf(identifier); }
    5660
     61
     62            /** @returns true if the objects class is of the given type or a derivative. */
    5763            inline bool isA(const SubclassIdentifier<class B>* identifier)
    5864                { return this->getIdentifier()->isA(identifier->getIdentifier()); }
     65            /** @returns true if the objects class is exactly of the given type. */
    5966            inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier)
    6067                { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); }
     68            /** @returns true if the objects class is a child of the given type. */
    6169            inline bool isChildOf(const SubclassIdentifier<class B>* identifier)
    6270                { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
     71            /** @returns true if the objects class is a parent of the given type. */
    6372            inline bool isParentOf(const SubclassIdentifier<class B>* identifier)
    6473                { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
    6574
     75
     76            /** @returns true if the objects class is of the given type or a derivative. */
    6677            inline bool isA(const SubclassIdentifier<class B> identifier)
    6778                { return this->getIdentifier()->isA(identifier.getIdentifier()); }
     79            /** @returns true if the objects class is exactly of the given type. */
    6880            inline bool isDirectlyA(const SubclassIdentifier<class B> identifier)
    6981                { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); }
     82            /** @returns true if the objects class is a child of the given type. */
    7083            inline bool isChildOf(const SubclassIdentifier<class B> identifier)
    7184                { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
     85            /** @returns true if the objects class is a parent of the given type. */
    7286            inline bool isParentOf(const SubclassIdentifier<class B> identifier)
    7387                { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
    7488
     89
     90            /** @returns true if the objects class is of the given type or a derivative. */
    7591            inline bool isA(const OrxonoxClass* object)
    7692                { return this->getIdentifier()->isA(object->getIdentifier()); }
     93            /** @returns true if the objects class is exactly of the given type. */
    7794            inline bool isDirectlyA(const OrxonoxClass* object)
    7895                { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); }
     96            /** @returns true if the objects class is a child of the given type. */
    7997            inline bool isChildOf(const OrxonoxClass* object)
    8098                { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
     99            /** @returns true if the objects class is a parent of the given type. */
    81100            inline bool isParentOf(const OrxonoxClass* object)
    82101                { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
    83102
    84103
    85             inline void setName(const std::string& name) { this->name_ = name; }
     104            /** @brief Sets the name of the object. @param name The name */
     105            inline virtual void setName(const std::string& name) { this->name_ = name; }
     106
     107            /** @returns the name of the object. */
    86108            inline const std::string& getName() const { return this->name_; }
    87109
    88             inline void setActive(bool bActive) { this->bActive_ = bActive; }
     110            /** @brief Sets the state of the objects activity. @param bActive True = active */
     111            inline virtual void setActive(bool bActive) { this->bActive_ = bActive; }
     112
     113            /** @returns the state of the objects activity. */
    89114            inline const bool isActive() const { return this->bActive_; }
    90115
    91             inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; }
     116            /** @brief Sets the state of the objects visibility. @param bVisible True = visible */
     117            inline virtual void setVisible(bool bVisible) { this->bVisible_ = bVisible; }
     118
     119            /** @returns the state of the objects visibility. */
    92120            inline const bool isVisible() const { return this->bVisible_; }
    93 
    94121
    95122        private:
     
    98125            MetaObjectList metaList_;       //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    99126
    100             std::string name_;
    101             bool bActive_;
    102             bool bVisible_;
     127            std::string name_;              //!< The name of the object
     128            bool bActive_;                  //!< True = the object is active
     129            bool bVisible_;                 //!< True = the object is visible
    103130    };
    104131}
  • code/branches/FICN/src/orxonox/main.cc

    r473 r496  
    3535
    3636
     37#include "core/SignalHandler.h"
    3738#include "orxonox.h"
    3839
     
    6667#endif
    6768
    68 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    69 #define WIN32_LEAN_AND_MEAN
    70 #include "windows.h"
    71 
    72              INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
    73 #else
    74 
    75              int main(int argc, char **argv)
    76 #endif
     69int main(int argc, char **argv)
    7770{
    7871  try
    7972  {
     73    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
    8074    Orxonox* orx = Orxonox::getSingleton();
    8175#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     
    9084  catch(Ogre::Exception& e)
    9185  {
    92 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    93     MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    94 #else
    9586    fprintf(stderr, "An exception has occurred: %s\n",
    9687            e.getFullDescription().c_str());
    9788    return 1;
    98 #endif
    9989  }
    10090
  • code/branches/FICN/src/orxonox/objects/BaseObject.cc

    r480 r496  
     1/*!
     2    @file BaseObject.cc
     3    @brief Implementation of the BaseObject class.
     4*/
     5
    16#include "BaseObject.h"
    27
     
    510    CreateFactory(BaseObject);
    611
     12    /**
     13        @brief Constructor: Registers the object in the BaseObject-list.
     14    */
    715    BaseObject::BaseObject()
    816    {
     
    1018    }
    1119
     20    /**
     21        @brief Destructor
     22    */
    1223    BaseObject::~BaseObject()
    1324    {
    1425    }
    15    
    1626}
  • code/branches/FICN/src/orxonox/objects/BaseObject.h

    r480 r496  
     1/*!
     2    @file BaseObject.h
     3    @brief Definition of the BaseObject class.
     4
     5    The BaseObject is the parent of all classes representing an instance in the game.
     6*/
     7
    18#ifndef _BaseObject_H__
    29#define _BaseObject_H__
    310
    4 #include "../core/IdentifierIncludes.h"
     11#include "../core/CoreIncludes.h"
     12#include "tinyxml/tinyxml.h"
    513
    614namespace orxonox
    715{
     16    //! The BaseObject is the parent of all classes representing an instance in the game.
    817    class BaseObject : virtual public OrxonoxClass
    918    {
     
    1120            BaseObject();
    1221            virtual ~BaseObject();
    13                         virtual void loadParams(TiXmlElement* xmlElem) {}
    14            
     22            virtual void loadParams(TiXmlElement* xmlElem) {}
    1523    };
    1624}
  • code/branches/FICN/src/orxonox/objects/CMakeLists.txt

    r482 r496  
    33SET( OBJECTS_SRC_FILES
    44  BaseObject.cc
     5  WorldEntity.cc
    56  test1.cc
    67  test2.cc
  • code/branches/FICN/src/orxonox/objects/Test.h

    r258 r496  
    33
    44#include "BaseObject.h"
    5 #include "../core/IdentifierIncludes.h"
     5#include "../core/CoreIncludes.h"
    66
    77namespace orxonox
  • code/branches/FICN/src/orxonox/objects/Tickable.h

    r433 r496  
     1/*!
     2    @file Tickable.h
     3    @brief Definition of the Tickable interface.
     4
     5    The Tickable interface provides a tick(dt) function, that gets called every frame.
     6    float dt is the time since the last frame.
     7
     8    Attention:
     9    Classes derived from a Tickable that want to have a tick(dt) function on their part, MUST call the
     10    parent::tick(dt) function explicit in their implementation of tick(dt) because it's a virtual function.
     11*/
     12
    113#ifndef _Tickable_H__
    214#define _Tickable_H__
    315
    4 #include <OgreFrameListener.h>
    5 #include "../core/IdentifierIncludes.h"
     16#include "../core/CoreIncludes.h"
     17#include "OgreFrameListener.h"
    618
    719namespace orxonox
    820{
    9     class TickFrameListener;
     21    class TickFrameListener; // Forward declaration
    1022
     23    //! The Tickable interface provides a tick(dt) function, that gets called every frame.
    1124    class Tickable : virtual public OrxonoxClass
    1225    {
    1326        public:
     27            /**
     28                @brief Gets called every frame.
     29                @param dt The time since the last frame
     30            */
    1431            virtual void tick(float dt) = 0;
    1532
    1633        protected:
     34            /**
     35                @brief Constructor: Registers the object in the Tickable-list
     36            */
    1737            Tickable() { RegisterRootObject(Tickable); }
    1838    };
    1939
     40    //! The TickFrameListener calls the tick(dt) function of all Tickables every frame.
    2041    class TickFrameListener : public Ogre::FrameListener
    2142    {
    2243        private:
     44            /** @brief Gets called before a frame gets rendered. */
    2345            bool frameStarted(const Ogre::FrameEvent &evt)
    2446            {
     47                // Iterate through all Tickables and call their tick(dt) function
    2548                for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    2649                    it->tick(evt.timeSinceLastFrame);
  • code/branches/FICN/src/orxonox/objects/Timer.h

    r433 r496  
     1/*!
     2    @file Timer.h
     3    @brief Definition and Implementation of the Timer class.
     4
     5    The Timer is a callback-object, calling a given function after a given time-interval.
     6
     7    Usage:
     8    header.h:
     9        class ClassName
     10        {
     11            public:
     12                ClassName();
     13                void functionName();
     14                Timer myTimer;
     15        };
     16
     17    source.cc:
     18        ClassName::ClassName()
     19        {
     20            myTimer.setTimer(interval_in_seconds, bLoop, this, &ClassName::functionName);
     21        }
     22
     23        void ClassName::functionName()
     24        {
     25            whateveryouwant();
     26            something(else);
     27        }
     28*/
     29
    130#ifndef _Timer_H__
    231#define _Timer_H__
    332
    4 #include <OgreFrameListener.h>
    5 #include "../core/IdentifierIncludes.h"
     33#include "../core/CoreIncludes.h"
     34#include "OgreFrameListener.h"
    635
    736namespace orxonox
    837{
     38    //! TimerBase is the parent of the Timer class.
    939    class TimerBase : public OrxonoxClass
    1040    {
     
    1242
    1343        public:
     44            /** @brief Constructor: Sets the default-values. */
    1445            TimerBase()
    1546            {
     
    2556            virtual void run() const = 0;
    2657
     58            /** @brief Starts the Timer: Function-call after 'interval' seconds. */
    2759            inline void startTimer() { this->bActive_ = true; this->time_ = this->interval_; }
     60            /** @brief Stops the Timer. */
    2861            inline void stopTimer() { this->bActive_ = false; this->time_ = this->interval_; }
     62            /** @brief Pauses the Timer - it will continue with the actual state if you unpause it. */
    2963            inline void pauseTimer() { this->bActive_ = false; }
     64            /** @brief Unpauses the Timer - continues with the given state. */
    3065            inline void unpauseTimer() { this->bActive_ = true; }
     66            /** @returns true if the Timer is active (= not stoped, not paused). */
    3167            inline bool isActive() const { return this->bActive_; }
    3268
    3369        protected:
    34             float interval_;
    35             bool bLoop_;
    36             bool bActive_;
     70            float interval_;    //!< The time-interval in seconds
     71            bool bLoop_;        //!< If true, the function gets called every 'interval' seconds
     72            bool bActive_;      //!< If true, the Timer ticks and calls the function if the time's up
    3773
    38             float time_;
     74            float time_;        //!< Internal variable, counting the time till the next function-call
    3975    };
    4076
     77    //! The Timer is a callback-object, calling a given function after a given time-interval.
    4178    template <class T = BaseObject>
    4279    class Timer : public TimerBase
    4380    {
    4481        public:
     82            /** @brief Constructor: Sets the default-values. */
    4583            Timer()
    4684            {
     
    4987            }
    5088
     89            /**
     90                @brief Constructor: Initializes the Timer with given values.
     91                @param interval The timer-interval in seconds
     92                @param bLoop If true, the function gets called every 'interval' seconds
     93                @param object The object owning the timer and the function
     94                @param timerFunction A function pointer to the function to call
     95            */
    5196            Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
    5297            {
     
    5499            }
    55100
     101            /**
     102                @brief Initializes the Timer with given values.
     103                @param interval The timer-interval in seconds
     104                @param bLoop If true, the function gets called every 'interval' seconds
     105                @param object The object owning the timer and the function
     106                @param timerFunction A function pointer to the function to call
     107            */
    56108            void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
    57109            {
     
    65117            }
    66118
     119            /** @brief Calls the given function of the given object. */
    67120            void run() const
    68121            {
     
    75128    };
    76129
     130    //! The TimerFrameListener manages all Timers in the game.
    77131    class TimerFrameListener : public Ogre::FrameListener
    78132    {
    79133        private:
     134            /** @brief Gets called before a frame gets rendered. */
    80135            bool frameStarted(const Ogre::FrameEvent &evt)
    81136            {
     137                // Iterate through all Timers
    82138                for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; ++it)
    83139                {
    84140                    if (it->isActive())
    85141                    {
     142                        // If active: Decrease the timer by the duration of the last frame
    86143                        it->time_ -= evt.timeSinceLastFrame;
    87144
    88145                        if (it->time_ <= 0)
    89146                        {
     147                            // It's time to call the function
    90148                            if (it->bLoop_)
    91                                 it->time_ += it->interval_;
     149                                it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
    92150                            else
    93                                 it->stopTimer();
     151                                it->stopTimer(); // Stop the timer if we don't want to loop
    94152
    95153                            it->run();
  • code/branches/FICN/src/orxonox/objects/test3.cc

    r356 r496  
    1010    {
    1111        RegisterObject(Test3);
     12
     13        this->setConfigValues();
     14    }
     15
     16    void Test3::setConfigValues()
     17    {
     18        SetConfigValue(value_int_, -100);
     19        SetConfigValue(value_double_, 10.555678);
     20        SetConfigValue(value_bool_, true);
     21        SetConfigValue(value_string_, "Dies ist ein Test");
     22        SetConfigValue(value_vector2_, Vector2(101, 202));
     23        SetConfigValue(value_vector3_, Vector3(13, 26, 39));
     24        SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887));
    1225    }
    1326
     
    1528    {
    1629    }
     30
     31        #include <fstream>
     32    void Test3::configOutput()
     33    {
     34        std::cout << this->value_int_ << std::endl;
     35        std::cout << this->value_double_ << std::endl;
     36        std::cout << this->value_bool_ << std::endl;
     37        std::cout << this->value_string_ << std::endl;
     38        std::cout << this->value_vector2_ << std::endl;
     39        std::cout << this->value_vector3_ << std::endl;
     40        std::cout << this->value_colourvalue_ << std::endl;
     41    }
     42
    1743        #define testandcout(code) \
    1844          std::cout << #code << " " << code << "\n"
  • code/branches/FICN/src/orxonox/objects/test3.h

    r356 r496  
    1515            virtual ~Test3();
    1616
     17            void setConfigValues();
     18
    1719            void usefullClassesIsATest(Test1* test1);
    1820            void usefullClassesIsATest(Test2* test2);
     21
     22            void configOutput();
     23
     24        private:
     25            int                 value_int_;
     26            double              value_double_;
     27            bool                value_bool_;
     28            std::string         value_string_;
     29            Vector2             value_vector2_;
     30            Vector3             value_vector3_;
     31            ColourValue         value_colourvalue_;
    1932    };
    2033}
  • code/branches/FICN/src/orxonox/orxonox.cc

    r487 r496  
    5151#include <string>
    5252#include <iostream>
     53
     54#include "objects/Tickable.h"
     55#include "objects/Timer.h"
     56#include "core/Factory.h"
    5357
    5458#include "../xml/xmlParser.h"
     
    255259    setupInputSystem();
    256260    createFrameListener();
     261    Factory::createClassHierarchy();
    257262    startRenderLoop();
    258263  }
     
    416421  void Orxonox::createFrameListener()
    417422  {
     423    TickFrameListener* TickFL = new TickFrameListener();
     424    ogre_->getRoot()->addFrameListener(TickFL);
     425
     426    TimerFrameListener* TimerFL = new TimerFrameListener();
     427    ogre_->getRoot()->addFrameListener(TimerFL);
     428
    418429    frameListener_ = new OrxListener(keyboard_, mouse_, auMan_);
    419430    ogre_->getRoot()->addFrameListener(frameListener_);
Note: See TracChangeset for help on using the changeset viewer.