Changeset 496
- Timestamp:
- Dec 12, 2007, 10:37:30 PM (17 years ago)
- Location:
- code/branches/FICN/src
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/loader/LevelLoader.cc
r480 r496 4 4 #include "LevelLoader.h" 5 5 #include "tinyxml/tinyxml.h" 6 #include "orxonox/core/ IdentifierIncludes.h"6 #include "orxonox/core/CoreIncludes.h" 7 7 #include "orxonox/core/Error.h" 8 8 #include "orxonox/objects/BaseObject.h" … … 111 111 { 112 112 tElem = tNode->ToElement(); 113 orxonox::BaseObject* obj = orxonox::ID(tElem->Value())->fabricate();113 orxonox::BaseObject* obj = ID(tElem->Value())->fabricate(); 114 114 obj->loadParams(tElem); 115 115 } -
code/branches/FICN/src/network/Client.cc
r459 r496 170 170 void Client::processClassid(classid *clid){ 171 171 orxonox::Identifier *id; 172 id= orxonox::ID(std::string(clid->message));172 id=ID(std::string(clid->message)); 173 173 if(id!=NULL) 174 174 id->setNetworkID(clid->clid); -
code/branches/FICN/src/network/Client.h
r459 r496 19 19 #include "PacketManager.h" 20 20 #include "GameStateClient.h" 21 #include "orxonox/core/ IdentifierIncludes.h"21 #include "orxonox/core/CoreIncludes.h" 22 22 //#include "NetworkFrameListener.h" 23 23 -
code/branches/FICN/src/network/ConnectionManager.cc
r446 r496 224 224 orxonox::Identifier *id; 225 225 while(!abort){ 226 id = orxonox::ID(i);226 id = ID(i); 227 227 if(id == NULL) 228 228 abort=true; -
code/branches/FICN/src/network/ConnectionManager.h
r475 r496 24 24 #include "PacketBuffer.h" 25 25 #include "PacketManager.h" 26 #include "orxonox/core/ IdentifierIncludes.h"26 #include "orxonox/core/CoreIncludes.h" 27 27 28 28 namespace std{ -
code/branches/FICN/src/network/GameStateClient.h
r436 r496 15 15 #include "zlib.h" 16 16 #include "Synchronisable.h" 17 #include "orxonox/core/ IdentifierIncludes.h"17 #include "orxonox/core/CoreIncludes.h" 18 18 #include "GameStateManager.h" 19 19 -
code/branches/FICN/src/network/GameStateManager.h
r436 r496 19 19 #include "ClientInformation.h" 20 20 #include "Synchronisable.h" 21 #include "orxonox/core/ IdentifierIncludes.h"21 #include "orxonox/core/CoreIncludes.h" 22 22 #include "orxonox/core/Iterator.h" 23 23 #include "PacketTypes.h" -
code/branches/FICN/src/network/Synchronisable.h
r459 r496 16 16 #include <iostream> 17 17 18 #include "orxonox/core/ IdentifierIncludes.h"18 #include "orxonox/core/CoreIncludes.h" 19 19 #include "orxonox/core/OrxonoxClass.h" 20 20 -
code/branches/FICN/src/orxonox/core/CMakeLists.txt
r420 r496 7 7 MetaObjectList.cc 8 8 OrxonoxClass.cc 9 ConfigValueContainer.cc 9 10 Error.cc 11 SignalHandler.cc 10 12 ) 11 13 -
code/branches/FICN/src/orxonox/core/ClassFactory.h
r384 r496 1 1 /*! 2 2 @file ClassFactory.h 3 @brief Definition of the ClassFactory class3 @brief Definition and implementation of the ClassFactory class 4 4 5 5 The ClassFactory is able to create new objects of a specific class. … … 21 21 { 22 22 public: 23 static bool create( );23 static bool create(const std::string& name); 24 24 BaseObject* fabricate(); 25 25 … … 33 33 34 34 /** 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()) 37 37 */ 38 38 template <class T> 39 bool ClassFactory<T>::create( )39 bool ClassFactory<T>::create(const std::string& name) 40 40 { 41 // Add the ClassFactory to the Classidentifier of type T42 41 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()); 52 43 53 44 return true; -
code/branches/FICN/src/orxonox/core/Factory.cc
r384 r496 6 6 #include "Factory.h" 7 7 #include "Identifier.h" 8 #include "Debug.h" 9 #include "../objects/BaseObject.h" 8 10 9 11 namespace orxonox … … 24 26 25 27 /** 26 @returns the Identifier with a given network ID.27 @param id The network ID of the wanted Identifier28 @returns the Identifier with a given network ID. 29 @param id The network ID of the wanted Identifier 28 30 */ 29 31 Identifier* Factory::getIdentifier(const unsigned int id) … … 50 52 51 53 /** 52 @brief Removes the entry with the old network ID and adds a new one.54 @brief Removes the entry with the old network ID and adds a new one. 53 55 @param identifier The identifier to change 54 56 @param oldID The old networkID … … 60 62 pointer_s->identifierNetworkIDMap_[newID] = identifier; 61 63 } 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 } 62 86 } -
code/branches/FICN/src/orxonox/core/Factory.h
r384 r496 3 3 @brief Definition of the Factory and the BaseFactory class. 4 4 5 The Factory is a singleton, containing two maps to map either the name or the network ID5 The Factory is a singleton, containing two maps to map either the name or the network ID 6 6 of a class with the corresponding Identifier. 7 7 … … 28 28 // ### Factory ### 29 29 // ############################### 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. 31 31 class Factory 32 32 { … … 36 36 static void add(const std::string& name, Identifier* identifier); 37 37 static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID); 38 static void createClassHierarchy(); 38 39 39 40 private: … … 43 44 44 45 static Factory* pointer_s; //!< The pointer to the singleton 45 std::map<std::string, Identifier*> identifierStringMap_; //!< The map mapping string withIdentifier46 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map mapping networkID withIdentifier46 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 47 48 }; 48 49 -
code/branches/FICN/src/orxonox/core/Identifier.cc
r384 r496 12 12 // ############################### 13 13 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 zero14 unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero 15 15 16 16 /** … … 41 41 void Identifier::initialize(const IdentifierList* parents) 42 42 { 43 #if HIERARCHY_VERBOSE 44 std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; 45 #endif 43 COUT(4) << "*** Initialize " << this->name_ << "-Singleton.\n"; 46 44 this->bCreatedOneObject_ = true; 47 45 … … 72 70 { 73 71 // 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..."; 76 74 abort(); 77 75 } … … 79 77 80 78 /** 81 @brief Sets the network ID to a new value and changes the entry in the Factory.82 @param id The new network ID79 @brief Sets the network ID to a new value and changes the entry in the Factory. 80 @param id The new network ID 83 81 */ 84 82 void Identifier::setNetworkID(unsigned int id) -
code/branches/FICN/src/orxonox/core/Identifier.h
r384 r496 1 1 /*! 2 2 @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. 4 4 5 5 The Identifier contains all needed informations about the class it belongs to: … … 7 7 - a list with all objects 8 8 - parents and childs 9 - the factory , if available9 - the factory (if available) 10 10 - the networkID that can be synchronised with the server 11 - all configurable variables (if available) 11 12 12 13 Every object has a pointer to the Identifier of its class. This allows the use isA(...), … … 18 19 19 20 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. 20 You can only assign Identifiers of the given class ora derivative to a SubclassIdentifier.21 You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier. 21 22 */ 22 23 … … 25 26 26 27 #include <iostream> 28 #include <map> 27 29 28 30 #include "IdentifierList.h" 29 31 #include "ObjectList.h" 30 32 #include "Factory.h" 31 32 #define HIERARCHY_VERBOSE false 33 33 #include "ConfigValueContainer.h" 34 #include "Debug.h" 34 35 35 36 namespace orxonox … … 46 47 - a list with all objects 47 48 - parents and childs 48 - the factory , if available49 - the factory (if available) 49 50 - the networkID that can be synchronised with the server 51 - all configurable variables (if available) 50 52 51 53 Every object has a pointer to the Identifier of its class. This allows the use isA(...), … … 62 64 friend class SubclassIdentifier; // Forward declaration 63 65 64 template <class T> 65 friend class ClassFactory; // Forward declaration 66 friend class Factory; // Forward declaration 66 67 67 68 public: … … 85 86 inline IdentifierList& getChildren() const { return *this->children_; } 86 87 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. */ 88 89 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 89 90 90 /** @returns the NetworkID to identify a class through the network. */91 /** @returns the network ID to identify a class through the network. */ 91 92 inline const unsigned int getNetworkID() const { return this->classID_; } 92 93 94 /** @brief Sets the network ID to a new value. @param id The new value */ 93 95 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; } 94 104 95 105 private: … … 105 115 { 106 116 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"; 110 118 } 111 119 … … 116 124 { 117 125 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 133 140 }; 134 141 … … 164 171 165 172 /** 166 @brief Constructor: Create the ObjectList.173 @brief Constructor: Creates the ObjectList. 167 174 */ 168 175 template <class T> … … 173 180 174 181 /** 175 @brief Destructor: Delete the ObjectList, setthe singleton-pointer to zero.182 @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero. 176 183 */ 177 184 template <class T> … … 186 193 @param parents An IdentifierList, containing the Identifiers of all parents of the class 187 194 @param name A string, containing exactly the name of the class 188 @param bRootClass True if the class is either an Interface or BaseObject itself195 @param bRootClass True if the class is either an Interface or the BaseObject itself 189 196 @return The ClassIdentifier itself 190 197 */ … … 192 199 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass) 193 200 { 194 #if HIERARCHY_VERBOSE 195 std::cout << "*** Register Class in " << name << "-Singleton.\n"; 196 #endif 201 COUT(4) << "*** Register Class in " << name << "-Singleton.\n"; 197 202 198 203 // It's a singleton, so maybe we have to create it first 199 204 if (!pointer_s) 200 205 { 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"; 204 207 pointer_s = new ClassIdentifier(); 205 208 } … … 210 213 // If no: We have to store the informations and initialize the Identifier 211 214 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"; 215 216 pointer_s->name_ = name; 216 Factory::add(name, pointer_s); // Add the Identifier to the Factory217 // Factory::add(name, pointer_s); // Add the Identifier to the Factory 217 218 218 219 if (bRootClass) … … 226 227 227 228 /** 228 @returns the Identifier itself 229 @returns the Identifier itself. 229 230 */ 230 231 template <class T> … … 233 234 if (!pointer_s) 234 235 { 235 #if HIERARCHY_VERBOSE 236 std::cout << "*** Create Singleton.\n"; 237 #endif 236 COUT(4) << "*** Create Singleton.\n"; 238 237 pointer_s = new ClassIdentifier(); 239 238 } … … 249 248 void ClassIdentifier<T>::addObject(T* object) 250 249 { 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"; 254 251 object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object)); 255 252 } … … 261 258 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. 262 259 /** 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>. 264 261 If you assign something else, the program aborts. 265 262 Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object. … … 286 283 if (!identifier->isA(ClassIdentifier<T>::getIdentifier())) 287 284 { 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"; 291 288 abort(); 292 289 } … … 314 311 315 312 /** 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. 317 314 @return The new object 318 315 */ … … 321 318 BaseObject* newObject = this->identifier_->fabricate(); 322 319 323 // Check if the creation w orked320 // Check if the creation was successful 324 321 if (newObject) 325 322 { … … 332 329 if (this->identifier_) 333 330 { 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"; 337 334 } 338 335 else 339 336 { 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"; 342 339 } 343 340 -
code/branches/FICN/src/orxonox/core/IdentifierList.cc
r384 r496 101 101 102 102 /** 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. 104 104 */ 105 105 std::string IdentifierList::toString() const -
code/branches/FICN/src/orxonox/core/Iterator.h
r384 r496 1 1 /*! 2 2 @file Iterator.h 3 @brief Definition of the Iterator class.3 @brief Definition and implementation of the Iterator class. 4 4 5 5 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. 7 7 8 8 Usage: … … 13 13 } 14 14 15 Warning: Don't delete an objectdirectly through the iterator.15 Warning: Don't delete objects directly through the iterator. 16 16 */ 17 17 18 18 #ifndef _Iterator_H__ 19 19 #define _Iterator_H__ 20 21 #include "Debug.h" 20 22 21 23 namespace orxonox … … 27 29 public: 28 30 /** 29 @brief Constructor: Sets the element whereon the iterator pointsto zero.31 @brief Constructor: Sets the element, whereon the iterator points, to zero. 30 32 */ 31 33 Iterator() … … 35 37 36 38 /** 37 @brief Constructor: Sets the element whereon the iterator pointsto a given element.39 @brief Constructor: Sets the element, whereon the iterator points, to a given element. 38 40 @param element The element to start with 39 41 */ … … 44 46 45 47 /** 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. 47 49 @return The Iterator itself 48 50 */ … … 54 56 55 57 /** 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. 57 59 @return The Iterator itself 58 60 */ … … 98 100 bool operator!=(int compare) 99 101 { 100 // Comparing with something except zero makes no sense102 // Comparing with anything except zero makes no sense 101 103 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"; 103 105 104 106 return (this->element_ != 0); … … 106 108 107 109 private: 108 ObjectListElement<T>* element_; //!< The element the Iterator points to110 ObjectListElement<T>* element_; //!< The element the Iterator points at 109 111 }; 110 112 } -
code/branches/FICN/src/orxonox/core/MetaObjectList.h
r384 r496 4 4 5 5 The MetaObjectList is a single-linked list, containing all list-elements and their 6 lists wherein the object that owns the MetaObjectListis registered.7 This allows much faster deleti ng 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. 8 8 */ 9 9 … … 13 13 #include "ObjectList.h" 14 14 #include "Identifier.h" 15 #include "Debug.h" 15 16 16 17 namespace orxonox … … 20 21 { 21 22 public: 22 /** @brief Default destructor */23 /** @brief Default destructor */ 23 24 virtual ~BaseMetaObjectListElement() {}; 24 25 … … 69 70 70 71 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"; 74 73 delete this->element_; 75 74 } … … 83 82 The MetaObjectList is a single-linked list, containing all list-elements and their 84 83 lists wherein the object that owns the MetaObjectList is registered. 85 This allows much faster deleti ng of objects.84 This allows much faster deletion of objects because no iteration is needed. 86 85 */ 87 86 class MetaObjectList -
code/branches/FICN/src/orxonox/core/ObjectList.h
r384 r496 1 1 /*! 2 2 @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. 7 7 Use Iterator<class> to iterate through all objects of the class. 8 8 */ … … 32 32 /** 33 33 @brief Constructor: Creates the list-element with an object. 34 @param Object The object to store34 @param object The object to store 35 35 */ 36 36 template <class T> … … 49 49 class Iterator; // Forward declaration 50 50 51 //! The ObjectList contains all objects of a specificclass.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. 54 54 Use Iterator<class> to iterate through all objects in the list. 55 55 */ … … 82 82 83 83 /** 84 @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_84 @brief Constructor: Sets default values. 85 85 */ 86 86 template <class T> -
code/branches/FICN/src/orxonox/core/OrxonoxClass.h
r480 r496 3 3 @brief Definition of the OrxonoxClass Class. 4 4 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. 7 7 */ 8 8 … … 15 15 #include "MetaObjectList.h" 16 16 17 #include "../../tinyxml/tinyxml.h"18 19 20 17 namespace orxonox 21 18 { 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. 23 20 /** 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. 25 22 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 26 23 */ … … 30 27 OrxonoxClass(); 31 28 virtual ~OrxonoxClass(); 29 30 void setConfigValues() {}; 32 31 33 32 /** @returns the Identifier of the object */ … … 46 45 inline MetaObjectList& getMetaList() { return this->metaList_; } 47 46 47 48 /** @returns true if the objects class is of the given type or a derivative. */ 48 49 inline bool isA(const Identifier* identifier) 49 50 { return this->getIdentifier()->isA(identifier); } 51 /** @returns true if the objects class is exactly of the given type. */ 50 52 inline bool isDirectlyA(const Identifier* identifier) 51 53 { return this->getIdentifier()->isDirectlyA(identifier); } 54 /** @returns true if the objects class is a child of the given type. */ 52 55 inline bool isChildOf(const Identifier* identifier) 53 56 { return this->getIdentifier()->isChildOf(identifier); } 57 /** @returns true if the objects class is a parent of the given type. */ 54 58 inline bool isParentOf(const Identifier* identifier) 55 59 { return this->getIdentifier()->isParentOf(identifier); } 56 60 61 62 /** @returns true if the objects class is of the given type or a derivative. */ 57 63 inline bool isA(const SubclassIdentifier<class B>* identifier) 58 64 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 65 /** @returns true if the objects class is exactly of the given type. */ 59 66 inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier) 60 67 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); } 68 /** @returns true if the objects class is a child of the given type. */ 61 69 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 62 70 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 71 /** @returns true if the objects class is a parent of the given type. */ 63 72 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 64 73 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 65 74 75 76 /** @returns true if the objects class is of the given type or a derivative. */ 66 77 inline bool isA(const SubclassIdentifier<class B> identifier) 67 78 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 79 /** @returns true if the objects class is exactly of the given type. */ 68 80 inline bool isDirectlyA(const SubclassIdentifier<class B> identifier) 69 81 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); } 82 /** @returns true if the objects class is a child of the given type. */ 70 83 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 71 84 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 85 /** @returns true if the objects class is a parent of the given type. */ 72 86 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 73 87 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 74 88 89 90 /** @returns true if the objects class is of the given type or a derivative. */ 75 91 inline bool isA(const OrxonoxClass* object) 76 92 { return this->getIdentifier()->isA(object->getIdentifier()); } 93 /** @returns true if the objects class is exactly of the given type. */ 77 94 inline bool isDirectlyA(const OrxonoxClass* object) 78 95 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); } 96 /** @returns true if the objects class is a child of the given type. */ 79 97 inline bool isChildOf(const OrxonoxClass* object) 80 98 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 99 /** @returns true if the objects class is a parent of the given type. */ 81 100 inline bool isParentOf(const OrxonoxClass* object) 82 101 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 83 102 84 103 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. */ 86 108 inline const std::string& getName() const { return this->name_; } 87 109 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. */ 89 114 inline const bool isActive() const { return this->bActive_; } 90 115 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. */ 92 120 inline const bool isVisible() const { return this->bVisible_; } 93 94 121 95 122 private: … … 98 125 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 99 126 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 103 130 }; 104 131 } -
code/branches/FICN/src/orxonox/main.cc
r473 r496 35 35 36 36 37 #include "core/SignalHandler.h" 37 38 #include "orxonox.h" 38 39 … … 66 67 #endif 67 68 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 69 int main(int argc, char **argv) 77 70 { 78 71 try 79 72 { 73 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 80 74 Orxonox* orx = Orxonox::getSingleton(); 81 75 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE … … 90 84 catch(Ogre::Exception& e) 91 85 { 92 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN3293 MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);94 #else95 86 fprintf(stderr, "An exception has occurred: %s\n", 96 87 e.getFullDescription().c_str()); 97 88 return 1; 98 #endif99 89 } 100 90 -
code/branches/FICN/src/orxonox/objects/BaseObject.cc
r480 r496 1 /*! 2 @file BaseObject.cc 3 @brief Implementation of the BaseObject class. 4 */ 5 1 6 #include "BaseObject.h" 2 7 … … 5 10 CreateFactory(BaseObject); 6 11 12 /** 13 @brief Constructor: Registers the object in the BaseObject-list. 14 */ 7 15 BaseObject::BaseObject() 8 16 { … … 10 18 } 11 19 20 /** 21 @brief Destructor 22 */ 12 23 BaseObject::~BaseObject() 13 24 { 14 25 } 15 16 26 } -
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 1 8 #ifndef _BaseObject_H__ 2 9 #define _BaseObject_H__ 3 10 4 #include "../core/IdentifierIncludes.h" 11 #include "../core/CoreIncludes.h" 12 #include "tinyxml/tinyxml.h" 5 13 6 14 namespace orxonox 7 15 { 16 //! The BaseObject is the parent of all classes representing an instance in the game. 8 17 class BaseObject : virtual public OrxonoxClass 9 18 { … … 11 20 BaseObject(); 12 21 virtual ~BaseObject(); 13 virtual void loadParams(TiXmlElement* xmlElem) {} 14 22 virtual void loadParams(TiXmlElement* xmlElem) {} 15 23 }; 16 24 } -
code/branches/FICN/src/orxonox/objects/CMakeLists.txt
r482 r496 3 3 SET( OBJECTS_SRC_FILES 4 4 BaseObject.cc 5 WorldEntity.cc 5 6 test1.cc 6 7 test2.cc -
code/branches/FICN/src/orxonox/objects/Test.h
r258 r496 3 3 4 4 #include "BaseObject.h" 5 #include "../core/ IdentifierIncludes.h"5 #include "../core/CoreIncludes.h" 6 6 7 7 namespace 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 1 13 #ifndef _Tickable_H__ 2 14 #define _Tickable_H__ 3 15 4 #include <OgreFrameListener.h>5 #include " ../core/IdentifierIncludes.h"16 #include "../core/CoreIncludes.h" 17 #include "OgreFrameListener.h" 6 18 7 19 namespace orxonox 8 20 { 9 class TickFrameListener; 21 class TickFrameListener; // Forward declaration 10 22 23 //! The Tickable interface provides a tick(dt) function, that gets called every frame. 11 24 class Tickable : virtual public OrxonoxClass 12 25 { 13 26 public: 27 /** 28 @brief Gets called every frame. 29 @param dt The time since the last frame 30 */ 14 31 virtual void tick(float dt) = 0; 15 32 16 33 protected: 34 /** 35 @brief Constructor: Registers the object in the Tickable-list 36 */ 17 37 Tickable() { RegisterRootObject(Tickable); } 18 38 }; 19 39 40 //! The TickFrameListener calls the tick(dt) function of all Tickables every frame. 20 41 class TickFrameListener : public Ogre::FrameListener 21 42 { 22 43 private: 44 /** @brief Gets called before a frame gets rendered. */ 23 45 bool frameStarted(const Ogre::FrameEvent &evt) 24 46 { 47 // Iterate through all Tickables and call their tick(dt) function 25 48 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 26 49 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 1 30 #ifndef _Timer_H__ 2 31 #define _Timer_H__ 3 32 4 #include <OgreFrameListener.h>5 #include " ../core/IdentifierIncludes.h"33 #include "../core/CoreIncludes.h" 34 #include "OgreFrameListener.h" 6 35 7 36 namespace orxonox 8 37 { 38 //! TimerBase is the parent of the Timer class. 9 39 class TimerBase : public OrxonoxClass 10 40 { … … 12 42 13 43 public: 44 /** @brief Constructor: Sets the default-values. */ 14 45 TimerBase() 15 46 { … … 25 56 virtual void run() const = 0; 26 57 58 /** @brief Starts the Timer: Function-call after 'interval' seconds. */ 27 59 inline void startTimer() { this->bActive_ = true; this->time_ = this->interval_; } 60 /** @brief Stops the Timer. */ 28 61 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. */ 29 63 inline void pauseTimer() { this->bActive_ = false; } 64 /** @brief Unpauses the Timer - continues with the given state. */ 30 65 inline void unpauseTimer() { this->bActive_ = true; } 66 /** @returns true if the Timer is active (= not stoped, not paused). */ 31 67 inline bool isActive() const { return this->bActive_; } 32 68 33 69 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 37 73 38 float time_; 74 float time_; //!< Internal variable, counting the time till the next function-call 39 75 }; 40 76 77 //! The Timer is a callback-object, calling a given function after a given time-interval. 41 78 template <class T = BaseObject> 42 79 class Timer : public TimerBase 43 80 { 44 81 public: 82 /** @brief Constructor: Sets the default-values. */ 45 83 Timer() 46 84 { … … 49 87 } 50 88 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 */ 51 96 Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)()) 52 97 { … … 54 99 } 55 100 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 */ 56 108 void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)()) 57 109 { … … 65 117 } 66 118 119 /** @brief Calls the given function of the given object. */ 67 120 void run() const 68 121 { … … 75 128 }; 76 129 130 //! The TimerFrameListener manages all Timers in the game. 77 131 class TimerFrameListener : public Ogre::FrameListener 78 132 { 79 133 private: 134 /** @brief Gets called before a frame gets rendered. */ 80 135 bool frameStarted(const Ogre::FrameEvent &evt) 81 136 { 137 // Iterate through all Timers 82 138 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; ++it) 83 139 { 84 140 if (it->isActive()) 85 141 { 142 // If active: Decrease the timer by the duration of the last frame 86 143 it->time_ -= evt.timeSinceLastFrame; 87 144 88 145 if (it->time_ <= 0) 89 146 { 147 // It's time to call the function 90 148 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. 92 150 else 93 it->stopTimer(); 151 it->stopTimer(); // Stop the timer if we don't want to loop 94 152 95 153 it->run(); -
code/branches/FICN/src/orxonox/objects/test3.cc
r356 r496 10 10 { 11 11 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)); 12 25 } 13 26 … … 15 28 { 16 29 } 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 17 43 #define testandcout(code) \ 18 44 std::cout << #code << " " << code << "\n" -
code/branches/FICN/src/orxonox/objects/test3.h
r356 r496 15 15 virtual ~Test3(); 16 16 17 void setConfigValues(); 18 17 19 void usefullClassesIsATest(Test1* test1); 18 20 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_; 19 32 }; 20 33 } -
code/branches/FICN/src/orxonox/orxonox.cc
r487 r496 51 51 #include <string> 52 52 #include <iostream> 53 54 #include "objects/Tickable.h" 55 #include "objects/Timer.h" 56 #include "core/Factory.h" 53 57 54 58 #include "../xml/xmlParser.h" … … 255 259 setupInputSystem(); 256 260 createFrameListener(); 261 Factory::createClassHierarchy(); 257 262 startRenderLoop(); 258 263 } … … 416 421 void Orxonox::createFrameListener() 417 422 { 423 TickFrameListener* TickFL = new TickFrameListener(); 424 ogre_->getRoot()->addFrameListener(TickFL); 425 426 TimerFrameListener* TimerFL = new TimerFrameListener(); 427 ogre_->getRoot()->addFrameListener(TimerFL); 428 418 429 frameListener_ = new OrxListener(keyboard_, mouse_, auMan_); 419 430 ogre_->getRoot()->addFrameListener(frameListener_);
Note: See TracChangeset
for help on using the changeset viewer.